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