Mercurial > hg > xemacs-beta
comparison src/gif_lib.h @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | 850242ba4a81 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 /* Synched up with: Not in FSF. */ | |
2 | |
3 /****************************************************************************** | |
4 * In order to make life a little bit easier when using the GIF file format, * | |
5 * this library was written, and which does all the dirty work... * | |
6 * * | |
7 * Written by Gershon Elber, Jun. 1989 * | |
8 * Hacks by Eric S. Raymond, Sep. 1992 * | |
9 ******************************************************************************* | |
10 * History: * | |
11 * 14 Jun 89 - Version 1.0 by Gershon Elber. * | |
12 * 3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names). * | |
13 * 15 Sep 90 - Version 2.0 by Eric S. Raymond (Changes to suoport GIF slurp) * | |
14 ******************************************************************************/ | |
15 | |
16 #ifndef GIF_LIB_H | |
17 #define GIF_LIB_H | |
18 | |
19 #define GIF_LIB_VERSION " Version 2.0, " | |
20 | |
21 #define GIF_ERROR 0 | |
22 #define GIF_OK 1 | |
23 | |
24 #ifndef TRUE | |
25 #define TRUE 1 | |
26 #define FALSE 0 | |
27 #endif | |
28 | |
29 #ifndef NULL | |
30 #define NULL 0 | |
31 #endif /* NULL */ | |
32 | |
33 #define GIF_FILE_BUFFER_SIZE 16384 /* Files uses bigger buffers than usual. */ | |
34 | |
35 typedef int GifBooleanType; | |
36 typedef unsigned char GifPixelType; | |
37 typedef unsigned char * GifRowType; | |
38 typedef unsigned char GifByteType; | |
39 | |
40 #define GIF_MESSAGE(Msg) fprintf(stderr, "\n%s: %s\n", PROGRAM_NAME, Msg) | |
41 #define GIF_EXIT(Msg) { GIF_MESSAGE(Msg); exit(-3); } | |
42 | |
43 #ifdef SYSV | |
44 #define VoidPtr char * | |
45 #else | |
46 #define VoidPtr void * | |
47 #endif /* SYSV */ | |
48 | |
49 typedef struct GifColorType { | |
50 GifByteType Red, Green, Blue; | |
51 } GifColorType; | |
52 | |
53 typedef struct ColorMapObject | |
54 { | |
55 int ColorCount; | |
56 int BitsPerPixel; | |
57 GifColorType *Colors; /* on malloc(3) heap */ | |
58 } | |
59 ColorMapObject; | |
60 | |
61 typedef struct GifImageDesc { | |
62 int Left, Top, Width, Height, /* Current image dimensions. */ | |
63 Interlace; /* Sequential/Interlaced lines. */ | |
64 ColorMapObject *ColorMap; /* The local color map */ | |
65 } GifImageDesc; | |
66 | |
67 typedef struct GifFileType { | |
68 int SWidth, SHeight, /* Screen dimensions. */ | |
69 SColorResolution, /* How many colors can we generate? */ | |
70 SBackGroundColor; /* I hope you understand this one... */ | |
71 ColorMapObject *SColorMap; /* NULL if not exists. */ | |
72 int ImageCount; /* Number of current image */ | |
73 GifImageDesc Image; /* Block describing current image */ | |
74 struct SavedImage *SavedImages; /* Use this to accumulate file state */ | |
75 VoidPtr Private; /* Don't mess with this! */ | |
76 } GifFileType; | |
77 | |
78 typedef enum { | |
79 UNDEFINED_RECORD_TYPE, | |
80 SCREEN_DESC_RECORD_TYPE, | |
81 IMAGE_DESC_RECORD_TYPE, /* Begin with ',' */ | |
82 EXTENSION_RECORD_TYPE, /* Begin with '!' */ | |
83 TERMINATE_RECORD_TYPE /* Begin with ';' */ | |
84 } GifRecordType; | |
85 | |
86 /* DumpScreen2Gif routine constants identify type of window/screen to dump. */ | |
87 /* Note all values below 1000 are reserved for the IBMPC different display */ | |
88 /* devices (it has many!) and are compatible with the numbering TC2.0 */ | |
89 /* (Turbo C 2.0 compiler for IBM PC) gives to these devices. */ | |
90 typedef enum { | |
91 GIF_DUMP_SGI_WINDOW = 1000, | |
92 GIF_DUMP_X_WINDOW = 1001 | |
93 } GifScreenDumpType; | |
94 | |
95 /****************************************************************************** | |
96 * O.K., here are the routines one can access in order to encode GIF file: * | |
97 * (GIF_LIB file EGIF_LIB.C). * | |
98 ******************************************************************************/ | |
99 | |
100 GifFileType *EGifOpenFileName(char *GifFileName, int GifTestExistance); | |
101 GifFileType *EGifOpenFileHandle(int GifFileHandle); | |
102 int EGifSpew(GifFileType *GifFile); | |
103 void EGifSetGifVersion(char *Version); | |
104 int EGifPutScreenDesc(GifFileType *GifFile, | |
105 int GifWidth, int GifHeight, int GifColorRes, int GifBackGround, | |
106 ColorMapObject *GifColorMap); | |
107 int EGifPutImageDesc(GifFileType *GifFile, | |
108 int GifLeft, int GifTop, int Width, int GifHeight, int GifInterlace, | |
109 ColorMapObject *GifColorMap); | |
110 int EGifPutLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen); | |
111 int EGifPutPixel(GifFileType *GifFile, GifPixelType GifPixel); | |
112 int EGifPutComment(GifFileType *GifFile, char *GifComment); | |
113 int EGifPutExtension(GifFileType *GifFile, int GifExtCode, int GifExtLen, | |
114 VoidPtr GifExtension); | |
115 int EGifPutCode(GifFileType *GifFile, int GifCodeSize, | |
116 GifByteType *GifCodeBlock); | |
117 int EGifPutCodeNext(GifFileType *GifFile, GifByteType *GifCodeBlock); | |
118 int EGifCloseFile(GifFileType *GifFile); | |
119 | |
120 #define E_GIF_ERR_OPEN_FAILED 1 /* And EGif possible errors. */ | |
121 #define E_GIF_ERR_WRITE_FAILED 2 | |
122 #define E_GIF_ERR_HAS_SCRN_DSCR 3 | |
123 #define E_GIF_ERR_HAS_IMAG_DSCR 4 | |
124 #define E_GIF_ERR_NO_COLOR_MAP 5 | |
125 #define E_GIF_ERR_DATA_TOO_BIG 6 | |
126 #define E_GIF_ERR_NOT_ENOUGH_MEM 7 | |
127 #define E_GIF_ERR_DISK_IS_FULL 8 | |
128 #define E_GIF_ERR_CLOSE_FAILED 9 | |
129 #define E_GIF_ERR_NOT_WRITEABLE 10 | |
130 | |
131 /****************************************************************************** | |
132 * O.K., here are the routines one can access in order to decode GIF file: * | |
133 * (GIF_LIB file DGIF_LIB.C). * | |
134 ******************************************************************************/ | |
135 | |
136 GifFileType *DGifOpenFileName(const char *GifFileName); | |
137 GifFileType *DGifOpenFileHandle(int GifFileHandle); | |
138 int DGifSlurp(GifFileType *GifFile); | |
139 int DGifGetScreenDesc(GifFileType *GifFile); | |
140 int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType); | |
141 int DGifGetImageDesc(GifFileType *GifFile); | |
142 int DGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen); | |
143 int DGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel); | |
144 int DGifGetComment(GifFileType *GifFile, char *GifComment); | |
145 int DGifGetExtension(GifFileType *GifFile, int *GifExtCode, | |
146 GifByteType **GifExtension); | |
147 int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension); | |
148 int DGifGetCode(GifFileType *GifFile, int *GifCodeSize, | |
149 GifByteType **GifCodeBlock); | |
150 int DGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock); | |
151 int DGifGetLZCodes(GifFileType *GifFile, int *GifCode); | |
152 int DGifCloseFile(GifFileType *GifFile); | |
153 | |
154 #define D_GIF_ERR_OPEN_FAILED 101 /* And DGif possible errors. */ | |
155 #define D_GIF_ERR_READ_FAILED 102 | |
156 #define D_GIF_ERR_NOT_GIF_FILE 103 | |
157 #define D_GIF_ERR_NO_SCRN_DSCR 104 | |
158 #define D_GIF_ERR_NO_IMAG_DSCR 105 | |
159 #define D_GIF_ERR_NO_COLOR_MAP 106 | |
160 #define D_GIF_ERR_WRONG_RECORD 107 | |
161 #define D_GIF_ERR_DATA_TOO_BIG 108 | |
162 #define D_GIF_ERR_NOT_ENOUGH_MEM 109 | |
163 #define D_GIF_ERR_CLOSE_FAILED 110 | |
164 #define D_GIF_ERR_NOT_READABLE 111 | |
165 #define D_GIF_ERR_IMAGE_DEFECT 112 | |
166 #define D_GIF_ERR_EOF_TOO_SOON 113 | |
167 | |
168 /****************************************************************************** | |
169 * O.K., here are the routines from GIF_LIB file QUANTIZE.C. * | |
170 ******************************************************************************/ | |
171 int QuantizeBuffer(unsigned int Width, unsigned int Height, int *ColorMapSize, | |
172 GifByteType *RedInput, GifByteType *GreenInput, GifByteType *BlueInput, | |
173 GifByteType *OutputBuffer, GifColorType *OutputColorMap); | |
174 | |
175 | |
176 /****************************************************************************** | |
177 * O.K., here are the routines from GIF_LIB file QPRINTF.C. * | |
178 ******************************************************************************/ | |
179 extern int GifQuietPrint; | |
180 | |
181 #ifdef USE_VARARGS | |
182 extern void GifQprintf(); | |
183 #else | |
184 extern void GifQprintf(char *Format, ...); | |
185 #endif /* USE_VARARGS */ | |
186 | |
187 /****************************************************************************** | |
188 * O.K., here are the routines from GIF_LIB file GIF_ERR.C. * | |
189 ******************************************************************************/ | |
190 #ifdef emacs | |
191 extern CONST char *EmacsPrintGifError(void); | |
192 #else | |
193 extern void PrintGifError(void); | |
194 #endif | |
195 extern int GifLastError(void); | |
196 | |
197 /****************************************************************************** | |
198 * O.K., here are the routines from GIF_LIB file DEV2GIF.C. * | |
199 ******************************************************************************/ | |
200 extern int DumpScreen2Gif(char *FileName, | |
201 int ReqGraphDriver, | |
202 int ReqGraphMode1, | |
203 int ReqGraphMode2, | |
204 int ReqGraphMode3); | |
205 | |
206 /***************************************************************************** | |
207 * | |
208 * Everything below this point is new after version 1.2, supporting `slurp | |
209 * mode' for doing I/O in two big belts with all the image-bashing in core. | |
210 * | |
211 *****************************************************************************/ | |
212 | |
213 /****************************************************************************** | |
214 * Color Map handling from ALLOCGIF.C * | |
215 ******************************************************************************/ | |
216 | |
217 extern ColorMapObject *MakeMapObject(int ColorCount, GifColorType *ColorMap); | |
218 extern void FreeMapObject(ColorMapObject *Objet); | |
219 extern ColorMapObject *UnionColorMap(ColorMapObject *ColorIn1, | |
220 ColorMapObject *ColorIn2, | |
221 GifPixelType ColorTransIn2[]); | |
222 extern int BitSize(int n); | |
223 | |
224 /****************************************************************************** | |
225 * Support for the in-core structures allocation (slurp mode). * | |
226 ******************************************************************************/ | |
227 | |
228 /* This is the in-core version of an extension record */ | |
229 typedef struct { | |
230 int ByteCount; | |
231 GifByteType *Bytes; /* on malloc(3) heap */ | |
232 } ExtensionBlock; | |
233 | |
234 /* This holds an image header, its unpacked raster bits, and extensions */ | |
235 typedef struct SavedImage { | |
236 GifImageDesc ImageDesc; | |
237 | |
238 GifPixelType *RasterBits; /* on malloc(3) heap */ | |
239 | |
240 int Function; | |
241 int ExtensionBlockCount; | |
242 ExtensionBlock *ExtensionBlocks; /* on malloc(3) heap */ | |
243 } SavedImage; | |
244 | |
245 extern void ApplyTranslation(SavedImage *Image, GifPixelType Translation[]); | |
246 | |
247 extern void MakeExtension(SavedImage *New, int Function); | |
248 extern int AddExtensionBlock(SavedImage *New, int Len, char ExtData[]); | |
249 extern void FreeExtension(SavedImage *Image); | |
250 | |
251 extern SavedImage *MakeSavedImage(GifFileType *GifFile, SavedImage *CopyFrom); | |
252 extern void FreeSavedImages(GifFileType *GifFile); | |
253 | |
254 /****************************************************************************** | |
255 * The library's internal utility font * | |
256 ******************************************************************************/ | |
257 | |
258 #define GIF_FONT_WIDTH 8 | |
259 #define GIF_FONT_HEIGHT 8 | |
260 extern unsigned char AsciiTable[][GIF_FONT_WIDTH]; | |
261 | |
262 extern void DrawText(SavedImage *Image, | |
263 const int x, const int y, | |
264 const char *legend, | |
265 const int color); | |
266 | |
267 extern void DrawBox(SavedImage *Image, | |
268 const int x, const int y, | |
269 const int w, const int d, | |
270 const int color); | |
271 | |
272 void DrawRectangle(SavedImage *Image, | |
273 const int x, const int y, | |
274 const int w, const int d, | |
275 const int color); | |
276 | |
277 extern void DrawBoxedText(SavedImage *Image, | |
278 const int x, const int y, | |
279 const char *legend, | |
280 const int border, | |
281 const int bg, | |
282 const int fg); | |
283 | |
284 #endif /* GIF_LIB_H */ |