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