1 /******************************************************************************
2 * In order to make life a little bit easier when using the GIF file format, *
3 * this library was written, and which does all the dirty work... *
5 * Written by Gershon Elber, Jun. 1989 *
6 * Hacks by Eric S. Raymond, Sep. 1992 *
7 *******************************************************************************
9 * 14 Jun 89 - Version 1.0 by Gershon Elber. *
10 * 3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names). *
11 * 15 Sep 90 - Version 2.0 by Eric S. Raymond (Changes to suoport GIF slurp) *
12 ******************************************************************************/
17 #define GIF_LIB_VERSION " Version 2.0, "
31 #define GIF_FILE_BUFFER_SIZE 16384 /* Files uses bigger buffers than usual. */
33 typedef int GifBooleanType;
34 typedef unsigned char GifPixelType;
35 typedef unsigned char * GifRowType;
36 typedef unsigned char GifByteType;
38 #define GIF_MESSAGE(Msg) fprintf(stderr, "\n%s: %s\n", PROGRAM_NAME, Msg)
39 #define GIF_EXIT(Msg) { GIF_MESSAGE(Msg); exit(-3); }
42 #define VoidPtr char *
44 #define VoidPtr void *
47 typedef struct GifColorType {
48 GifByteType Red, Green, Blue;
51 typedef struct ColorMapObject
55 GifColorType *Colors; /* on malloc(3) heap */
59 typedef struct GifImageDesc {
60 int Left, Top, Width, Height, /* Current image dimensions. */
61 Interlace; /* Sequential/Interlaced lines. */
62 ColorMapObject *ColorMap; /* The local color map */
65 typedef struct GifFileType {
66 int SWidth, SHeight, /* Screen dimensions. */
67 SColorResolution, /* How many colors can we generate? */
68 SBackGroundColor; /* I hope you understand this one... */
69 ColorMapObject *SColorMap; /* NULL if not exists. */
70 int ImageCount; /* Number of current image */
71 GifImageDesc Image; /* Block describing current image */
72 struct SavedImage *SavedImages; /* Use this to accumulate file state */
73 VoidPtr Private; /* Don't mess with this! */
77 UNDEFINED_RECORD_TYPE,
78 SCREEN_DESC_RECORD_TYPE,
79 IMAGE_DESC_RECORD_TYPE, /* Begin with ',' */
80 EXTENSION_RECORD_TYPE, /* Begin with '!' */
81 TERMINATE_RECORD_TYPE /* Begin with ';' */
84 /* DumpScreen2Gif routine constants identify type of window/screen to dump. */
85 /* Note all values below 1000 are reserved for the IBMPC different display */
86 /* devices (it has many!) and are compatible with the numbering TC2.0 */
87 /* (Turbo C 2.0 compiler for IBM PC) gives to these devices. */
89 GIF_DUMP_SGI_WINDOW = 1000,
90 GIF_DUMP_X_WINDOW = 1001
93 /******************************************************************************
94 * O.K., here are the routines one can access in order to encode GIF file: *
95 * (GIF_LIB file EGIF_LIB.C). *
96 ******************************************************************************/
98 GifFileType *EGifOpenFileName(char *GifFileName, int GifTestExistance);
99 GifFileType *EGifOpenFileHandle(int GifFileHandle);
100 int EGifSpew(GifFileType *GifFile);
101 void EGifSetGifVersion(char *Version);
102 int EGifPutScreenDesc(GifFileType *GifFile,
103 int GifWidth, int GifHeight, int GifColorRes, int GifBackGround,
104 ColorMapObject *GifColorMap);
105 int EGifPutImageDesc(GifFileType *GifFile,
106 int GifLeft, int GifTop, int Width, int GifHeight, int GifInterlace,
107 ColorMapObject *GifColorMap);
108 int EGifPutLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);
109 int EGifPutPixel(GifFileType *GifFile, GifPixelType GifPixel);
110 int EGifPutComment(GifFileType *GifFile, char *GifComment);
111 int EGifPutExtension(GifFileType *GifFile, int GifExtCode, int GifExtLen,
112 VoidPtr GifExtension);
113 int EGifPutCode(GifFileType *GifFile, int GifCodeSize,
114 GifByteType *GifCodeBlock);
115 int EGifPutCodeNext(GifFileType *GifFile, GifByteType *GifCodeBlock);
116 int EGifCloseFile(GifFileType *GifFile);
118 #define E_GIF_ERR_OPEN_FAILED 1 /* And EGif possible errors. */
119 #define E_GIF_ERR_WRITE_FAILED 2
120 #define E_GIF_ERR_HAS_SCRN_DSCR 3
121 #define E_GIF_ERR_HAS_IMAG_DSCR 4
122 #define E_GIF_ERR_NO_COLOR_MAP 5
123 #define E_GIF_ERR_DATA_TOO_BIG 6
124 #define E_GIF_ERR_NOT_ENOUGH_MEM 7
125 #define E_GIF_ERR_DISK_IS_FULL 8
126 #define E_GIF_ERR_CLOSE_FAILED 9
127 #define E_GIF_ERR_NOT_WRITEABLE 10
129 /******************************************************************************
130 * O.K., here are the routines one can access in order to decode GIF file: *
131 * (GIF_LIB file DGIF_LIB.C). *
132 ******************************************************************************/
134 GifFileType *DGifOpenFileName(const char *GifFileName);
135 GifFileType *DGifOpenFileHandle(int GifFileHandle);
136 int DGifSlurp(GifFileType *GifFile);
137 int DGifGetScreenDesc(GifFileType *GifFile);
138 int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType);
139 int DGifGetImageDesc(GifFileType *GifFile);
140 int DGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);
141 int DGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel);
142 int DGifGetComment(GifFileType *GifFile, char *GifComment);
143 int DGifGetExtension(GifFileType *GifFile, int *GifExtCode,
144 GifByteType **GifExtension);
145 int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension);
146 int DGifGetCode(GifFileType *GifFile, int *GifCodeSize,
147 GifByteType **GifCodeBlock);
148 int DGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock);
149 int DGifGetLZCodes(GifFileType *GifFile, int *GifCode);
150 int DGifCloseFile(GifFileType *GifFile);
152 #define D_GIF_ERR_OPEN_FAILED 101 /* And DGif possible errors. */
153 #define D_GIF_ERR_READ_FAILED 102
154 #define D_GIF_ERR_NOT_GIF_FILE 103
155 #define D_GIF_ERR_NO_SCRN_DSCR 104
156 #define D_GIF_ERR_NO_IMAG_DSCR 105
157 #define D_GIF_ERR_NO_COLOR_MAP 106
158 #define D_GIF_ERR_WRONG_RECORD 107
159 #define D_GIF_ERR_DATA_TOO_BIG 108
160 #define D_GIF_ERR_NOT_ENOUGH_MEM 109
161 #define D_GIF_ERR_CLOSE_FAILED 110
162 #define D_GIF_ERR_NOT_READABLE 111
163 #define D_GIF_ERR_IMAGE_DEFECT 112
164 #define D_GIF_ERR_EOF_TOO_SOON 113
166 /******************************************************************************
167 * O.K., here are the routines from GIF_LIB file QUANTIZE.C. *
168 ******************************************************************************/
169 int QuantizeBuffer(unsigned int Width, unsigned int Height, int *ColorMapSize,
170 GifByteType *RedInput, GifByteType *GreenInput, GifByteType *BlueInput,
171 GifByteType *OutputBuffer, GifColorType *OutputColorMap);
174 /******************************************************************************
175 * O.K., here are the routines from GIF_LIB file QPRINTF.C. *
176 ******************************************************************************/
177 extern int GifQuietPrint;
180 extern void GifQprintf();
182 extern void GifQprintf(char *Format, ...);
183 #endif /* USE_VARARGS */
185 /******************************************************************************
186 * O.K., here are the routines from GIF_LIB file GIF_ERR.C. *
187 ******************************************************************************/
188 extern void PrintGifError(void);
189 extern int GifLastError(void);
191 /******************************************************************************
192 * O.K., here are the routines from GIF_LIB file DEV2GIF.C. *
193 ******************************************************************************/
194 extern int DumpScreen2Gif(char *FileName,
200 /*****************************************************************************
202 * Everything below this point is new after version 1.2, supporting `slurp
203 * mode' for doing I/O in two big belts with all the image-bashing in core.
205 *****************************************************************************/
207 /******************************************************************************
208 * Color Map handling from ALLOCGIF.C *
209 ******************************************************************************/
211 extern ColorMapObject *MakeMapObject(int ColorCount, GifColorType *ColorMap);
212 extern void FreeMapObject(ColorMapObject *Object);
213 extern ColorMapObject *UnionColorMap(ColorMapObject *ColorIn1,
214 ColorMapObject *ColorIn2,
215 GifPixelType ColorTransIn2[]);
216 extern int BitSize(int n);
218 /******************************************************************************
219 * Support for the in-core structures allocation (slurp mode). *
220 ******************************************************************************/
222 /* This is the in-core version of an extension record */
225 char *Bytes; /* on malloc(3) heap */
228 /* This holds an image header, its unpacked raster bits, and extensions */
229 typedef struct SavedImage {
230 GifImageDesc ImageDesc;
232 char *RasterBits; /* on malloc(3) heap */
235 int ExtensionBlockCount;
236 ExtensionBlock *ExtensionBlocks; /* on malloc(3) heap */
239 extern void ApplyTranslation(SavedImage *Image, GifPixelType Translation[]);
241 extern void MakeExtension(SavedImage *New, int Function);
242 extern int AddExtensionBlock(SavedImage *New, int Len, char ExtData[]);
243 extern void FreeExtension(SavedImage *Image);
245 extern SavedImage *MakeSavedImage(GifFileType *GifFile, SavedImage *CopyFrom);
246 extern void FreeSavedImages(GifFileType *GifFile);
248 /******************************************************************************
249 * The library's internal utility font *
250 ******************************************************************************/
252 #define GIF_FONT_WIDTH 8
253 #define GIF_FONT_HEIGHT 8
254 extern unsigned char AsciiTable[][GIF_FONT_WIDTH];
256 extern void DrawText(SavedImage *Image,
257 const int x, const int y,
261 extern void DrawBox(SavedImage *Image,
262 const int x, const int y,
263 const int w, const int d,
266 void DrawRectangle(SavedImage *Image,
267 const int x, const int y,
268 const int w, const int d,
271 extern void DrawBoxedText(SavedImage *Image,
272 const int x, const int y,
278 #endif /* GIF_LIB_H */