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