Annotation of parser3/src/classes/gd/gif.h, revision 1.2

1.1       paf         1: /** @file
                      2:        gd.h: declarations file for the gifdraw module.
                      3: 
                      4:        Written by Tom Boutell, 5/94.
                      5:        Copyright 1994, Cold Spring Harbor Labs.
                      6:        Permission granted to use this code in any fashion provided
                      7:        that this notice is retained and any alterations are
                      8:        labeled as such. It is requested, but not required, that
                      9:        you share extensions to this module with us so that we
1.2     ! paf        10:        can incorporate them into new versions. 
        !            11: */
1.1       paf        12: 
                     13: #ifndef GIF_H
                     14: #define GIF_H 1
                     15: 
1.2     ! paf        16: #include "pa_pool.h"
        !            17: 
1.1       paf        18: #include <stdio.h>
                     19: #include <string.h>
                     20: #define gdMaxColors 0x100
1.2     ! paf        21: #define HSIZE  5003            /* 80% occupancy */
        !            22: 
        !            23: /* For backwards compatibility only. Use gdImageSetStyle() for MUCH more flexible line drawing. Also see gdImageSetBrush(). */
        !            24: #define gdDashSize 4
        !            25: 
1.1       paf        26: 
1.2     ! paf        27: /** Image type. 
        !            28:        See functions below; you will not need to change
1.1       paf        29:        the elements directly. Use the provided macros to
                     30:        access sx, sy, the color table, and colorsTotal for 
1.2     ! paf        31:        read-only purposes. 
        !            32: */
        !            33: class gdImage : public Pooled {
        !            34: 
        !            35: public: /* Functions to manipulate images. */
        !            36: 
        !            37:        gdImage(Pool& pool) : Pooled(pool) {}
        !            38:        void Create(int asx, int asy);
        !            39:        bool CreateFromGif(FILE *fd);
        !            40:        void SetPixel(int x, int y, int color);
        !            41:        int GetPixel(int x, int y);
        !            42:        void Line(int x1, int y1, int x2, int y2, int color);
        !            43:        void DashedLine(int x1, int y1, int x2, int y2, int color);
        !            44:        void Rectangle(int x1, int y1, int x2, int y2, int color);
        !            45:        void LineReplaceColor(int x1, int y1, int x2, int y2, int a, int b);
        !            46:        void FilledRectangle(int x1, int y1, int x2, int y2, int color);
        !            47: 
        !            48:        /* Point type for use in polygon drawing. */
        !            49:        
        !            50:        struct Point {
        !            51:                int x, y;
        !            52:        };
        !            53:        
        !            54:        void Polygon(Point *p, int n, int c);
        !            55:        void FilledPolygon(Point *p, int n, int c);
        !            56:        void FilledPolygonReplaceColor(Point *p, int n, int a, int b);
        !            57: 
        !            58:        int ColorAllocate(int r, int g, int b);
        !            59:        int ColorClosest(int r, int g, int b);
        !            60:        int ColorExact(int r, int g, int b);
        !            61:        int ColorRGB(int r, int g, int b);
        !            62:        int Color(unsigned int rgb);
        !            63:        void ColorDeallocate(int color);
        !            64:        void SetColorTransparent(int color);
        !            65:        
        !            66:        int BoundsSafe(int x, int y);
        !            67:        void DoSetPixel(int x, int y, int color);
        !            68:        
        !            69:        void Gif(FILE *out);
        !            70:        void Arc(int cx, int cy, int w, int h, int s, int e, int color);
        !            71:        void FillToBorder(int x, int y, int border, int color);
        !            72:        void Fill(int x, int y, int color);
        !            73:        void Copy(gdImage& dst, int dstX, int dstY, int srcX, int srcY, int w, int h);
        !            74:        void CopyResized(gdImage& dst, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH);
        !            75:        void SetStyle(int width);
        !            76:        void SetInterlace(int interlaceArg); /* On or off(1 or 0) */
        !            77:        
        !            78: public: /* information about image. READ ONLY */
        !            79: 
        !            80:        int SX() { return sx; }
        !            81:        int SY() { return sy; }
        !            82:        int ColorsTotal() { return colorsTotal; }
        !            83:        int Red(int c) { return red[c]; }
        !            84:        int Green(int c) { return green[c]; }
        !            85:        int Blue(int c) { return blue[c]; }
        !            86:        int GetTransparent() { return transparent; }
        !            87:        int GetInterlaced() { return interlace; }
        !            88: 
        !            89: private:
1.1       paf        90: 
                     91:        unsigned char ** pixels;
                     92:        int sx;
                     93:        int sy;
                     94:        int colorsTotal;
                     95:        int red[gdMaxColors];
                     96:        int green[gdMaxColors];
                     97:        int blue[gdMaxColors]; 
                     98:        int open[gdMaxColors];
                     99:        int transparent;
                    100:        int *polyInts;
                    101:        int polyAllocated;
                    102:        int styleWidth;
                    103:        int interlace;
                    104: 
1.2     ! paf       105: private: // read gif
1.1       paf       106: 
1.2     ! paf       107:        int GetDataBlock(FILE *fd, unsigned char *buf);
        !           108:        int LWZReadByte(FILE *fd, int flag, int input_code_size);
        !           109:        void ReadImage(FILE *fd, int len, int height, unsigned char(*cmap)[256], int interlace, int ignore);
        !           110:        int DoExtension(FILE *fd, int label, int *Transparent);
        !           111:        int GetCode(FILE *fd, int code_size, int flag);
        !           112: 
        !           113: private: // read gif
        !           114: 
        !           115:        int ZeroDataBlock;
        !           116:        
        !           117: };
        !           118: 
        !           119: class gdGifEncoder : public Pooled {
        !           120: public:
        !           121: 
        !           122:        gdGifEncoder(Pool& pool, gdImage& aim);
        !           123: 
        !           124:        void encode(FILE *fp, 
        !           125:                int GWidth, int GHeight, 
        !           126:                int GInterlace, int Background, 
        !           127:                int Transparent, int BitsPerPixel, 
        !           128:                int *Red, int *Green, int *Blue);
        !           129: 
        !           130: private:
        !           131: 
        !           132:        /*
        !           133:         * a code_int must be able to hold 2**GIFBITS values of type int, and also -1
        !           134:         */
        !           135:        typedef int             code_int;
        !           136:        #ifdef SIGNED_COMPARE_SLOW
        !           137:        typedef unsigned long int count_int;
        !           138:        typedef unsigned short int count_short;
        !           139:        #else /*SIGNED_COMPARE_SLOW*/
        !           140:        typedef long int          count_int;
        !           141:        #endif /*SIGNED_COMPARE_SLOW*/
        !           142: 
        !           143: private:
        !           144: 
        !           145:        void prepare_encoder(void);
        !           146:        void BumpPixel(void);
        !           147:        int GIFNextPixel();
        !           148:        void compress(int init_bits, FILE *outfile);
        !           149:        void output(code_int code);
        !           150:        void cl_block(void);
        !           151:        void cl_hash(count_int hsize);
        !           152:        void char_init(void);
        !           153:        void char_out(int c);
        !           154:        void flush_char(void);
        !           155: 
        !           156: private:
        !           157:        
        !           158:        gdImage& im;
        !           159: 
        !           160:        int Width, Height;
        !           161:        int curx, cury;
        !           162:        long CountDown;
        !           163:        int Pass;
        !           164:        int Interlace;
        !           165: 
        !           166:        int g_init_bits;
        !           167:        FILE* g_outfile;
        !           168: 
        !           169:        int ClearCode;
        !           170:        int EOFCode;
        !           171: 
        !           172:        int n_bits;                        /* number of bits/code */
        !           173:        int maxbits;                /* user settable max # bits/code */
        !           174:        
        !           175:        code_int maxcode;                  /* maximum code, given n_bits */
        !           176:        code_int maxmaxcode; /* should NEVER generate this code */
        !           177: 
        !           178:        count_int htab [HSIZE];
        !           179:        unsigned short codetab [HSIZE];
        !           180:        code_int hsize;                 /* for dynamic table sizing */
        !           181:        
        !           182:        code_int free_ent;                  /* first unused entry */
        !           183:        
        !           184:        /*
        !           185:        * block compression parameters -- after all codes are used up,
        !           186:        * and compression rate changes, start over.
        !           187:        */
        !           188:        int clear_flg;
        !           189:        
        !           190:        int offset;
        !           191:        long int in_count;            /* length of input */
        !           192:        long int out_count;           /* # of codes output(for debugging) */
        !           193:        
        !           194:        unsigned long cur_accum;
        !           195:        int cur_bits;
        !           196: 
        !           197:        /*
        !           198:         * Number of characters so far in this 'packet'
        !           199:         */
        !           200:        int a_count;
        !           201: 
        !           202:        /*
        !           203:         * Define the storage for the packet accumulator
        !           204:         */
        !           205:        char accum[ 256 ];
        !           206: 
        !           207: };
        !           208: 
        !           209: inline int gdImage::BoundsSafe(int x, int y){
        !           210:     return(!(((y < 0) ||(y >= sy)) ||((x < 0) ||(x >= sx))));
        !           211: }
        !           212: 
        !           213: inline /*paf int*/void gdImage::DoSetPixel(int x, int y, int color){
        !           214:     if(BoundsSafe(x, y)) pixels[x][y] = color;
        !           215: }
1.1       paf       216: 
                    217: 
                    218: 
                    219: #endif

E-mail: