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