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... * 4 * * 5 * Written by Gershon Elber, Jun. 1989 * 6 * Hacks by Eric S. Raymond, Sep. 1992 * 7 ******************************************************************************* 8 * History: * 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 * 26 Jun 96 - Version 3.0 by Eric S. Raymond (Full GIF89 support) * 13 * 17 Dec 98 - Version 4.0 by Toshio Kuratomi (Fix extension writing code) * 14 ******************************************************************************/ 15 16 #ifndef _GIF_LIB_H 17 #define _GIF_LIB_H 18 19 #define GIF_LIB_VERSION " Version 4.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_STAMP "GIFVER" /* First chars in file - GIF stamp. */ 34 #define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1 35 #define GIF_VERSION_POS 3 /* Version first character in stamp. */ 36 #define GIF87_STAMP "GIF87a" /* First chars in file - GIF stamp. */ 37 #define GIF89_STAMP "GIF89a" /* First chars in file - GIF stamp. */ 38 39 #define GIF_FILE_BUFFER_SIZE 16384 /* Files uses bigger buffers than usual. */ 40 41 typedef int GifBooleanType; 42 typedef unsigned char GifPixelType; 43 typedef unsigned char * GifRowType; 44 typedef unsigned char GifByteType; 45 46 #define GIF_MESSAGE(Msg) fprintf(stderr, "\n%s: %s\n", PROGRAM_NAME, Msg) 47 #define GIF_EXIT(Msg) { GIF_MESSAGE(Msg); exit(-3); } 48 49 #ifdef SYSV 50 #define VoidPtr char * 51 #else 52 #define VoidPtr void * 53 #endif /* SYSV */ 54 55 typedef struct GifColorType { 56 GifByteType Red, Green, Blue; 57 } GifColorType; 58 59 typedef struct ColorMapObject 60 { 61 int ColorCount; 62 int BitsPerPixel; 63 GifColorType *Colors; /* on malloc(3) heap */ 64 } 65 ColorMapObject; 66 67 typedef struct GifImageDesc { 68 int Left, Top, Width, Height, /* Current image dimensions. */ 69 Interlace; /* Sequential/Interlaced lines. */ 70 ColorMapObject *ColorMap; /* The local color map */ 71 } GifImageDesc; 72 73 typedef struct GifFileType { 74 int SWidth, SHeight, /* Screen dimensions. */ 75 SColorResolution, /* How many colors can we generate? */ 76 SBackGroundColor; /* I hope you understand this one... */ 77 ColorMapObject *SColorMap; /* NULL if not exists. */ 78 int ImageCount; /* Number of current image */ 79 GifImageDesc Image; /* Block describing current image */ 80 struct SavedImage *SavedImages; /* Use this to accumulate file state */ 81 VoidPtr UserData; /* hook to attach user data (TVT) */ 82 VoidPtr Private; /* Don't mess with this! */ 83 } GifFileType; 84 85 typedef enum { 86 UNDEFINED_RECORD_TYPE, 87 SCREEN_DESC_RECORD_TYPE, 88 IMAGE_DESC_RECORD_TYPE, /* Begin with ',' */ 89 EXTENSION_RECORD_TYPE, /* Begin with '!' */ 90 TERMINATE_RECORD_TYPE /* Begin with ';' */ 91 } GifRecordType; 92 93 /* DumpScreen2Gif routine constants identify type of window/screen to dump. */ 94 /* Note all values below 1000 are reserved for the IBMPC different display */ 95 /* devices (it has many!) and are compatible with the numbering TC2.0 */ 96 /* (Turbo C 2.0 compiler for IBM PC) gives to these devices. */ 97 typedef enum { 98 GIF_DUMP_SGI_WINDOW = 1000, 99 GIF_DUMP_X_WINDOW = 1001 100 } GifScreenDumpType; 101 102 /* func type to read gif data from arbitrary sources (TVT) */ 103 typedef int (*InputFunc)(GifFileType*,GifByteType*,int); 104 105 /* func type to write gif data ro arbitrary targets. 106 * Returns count of bytes written. (MRB) 107 */ 108 typedef int (*OutputFunc)(GifFileType *, const GifByteType *, int); 109 /****************************************************************************** 110 * GIF89 extension function codes * 111 ******************************************************************************/ 112 113 #define COMMENT_EXT_FUNC_CODE 0xfe /* comment */ 114 #define GRAPHICS_EXT_FUNC_CODE 0xf9 /* graphics control */ 115 #define PLAINTEXT_EXT_FUNC_CODE 0x01 /* plaintext */ 116 #define APPLICATION_EXT_FUNC_CODE 0xff /* application block */ 117 118 /****************************************************************************** 119 * O.K., here are the routines one can access in order to encode GIF file: * 120 * (GIF_LIB file EGIF_LIB.C). * 121 ******************************************************************************/ 122 123 GifFileType *EGifOpenFileName(const char *GifFileName, int GifTestExistance); 124 GifFileType *EGifOpenFileHandle(int GifFileHandle); 125 GifFileType *EgifOpen(void *userPtr, OutputFunc writeFunc); 126 int EGifSpew(GifFileType *GifFile); 127 void EGifSetGifVersion(const char *Version); 128 int EGifPutScreenDesc(GifFileType *GifFile, 129 int GifWidth, int GifHeight, int GifColorRes, int GifBackGround, 130 const ColorMapObject *GifColorMap); 131 int EGifPutImageDesc(GifFileType *GifFile, 132 int GifLeft, int GifTop, int Width, int GifHeight, int GifInterlace, 133 const ColorMapObject *GifColorMap); 134 int EGifPutLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen); 135 int EGifPutPixel(GifFileType *GifFile, GifPixelType GifPixel); 136 int EGifPutComment(GifFileType *GifFile, const char *GifComment); 137 int EGifPutExtensionFirst(GifFileType *GifFile, int GifExtCode, int GifExtLen, 138 const VoidPtr GifExtension); 139 int EGifPutExtensionNext(GifFileType *GifFile, int GifExtCode, int GifExtLen, 140 const VoidPtr GifExtension); 141 int EGifPutExtensionLast(GifFileType *GifFile, int GifExtCode, int GifExtLen, 142 const VoidPtr GifExtension); 143 int EGifPutExtension(GifFileType *GifFile, int GifExtCode, int GifExtLen, 144 const VoidPtr GifExtension); 145 int EGifPutCode(GifFileType *GifFile, int GifCodeSize, 146 const GifByteType *GifCodeBlock); 147 int EGifPutCodeNext(GifFileType *GifFile, const GifByteType *GifCodeBlock); 148 int EGifCloseFile(GifFileType *GifFile); 149 150 #define E_GIF_ERR_OPEN_FAILED 1 /* And EGif possible errors. */ 151 #define E_GIF_ERR_WRITE_FAILED 2 152 #define E_GIF_ERR_HAS_SCRN_DSCR 3 153 #define E_GIF_ERR_HAS_IMAG_DSCR 4 154 #define E_GIF_ERR_NO_COLOR_MAP 5 155 #define E_GIF_ERR_DATA_TOO_BIG 6 156 #define E_GIF_ERR_NOT_ENOUGH_MEM 7 157 #define E_GIF_ERR_DISK_IS_FULL 8 158 #define E_GIF_ERR_CLOSE_FAILED 9 159 #define E_GIF_ERR_NOT_WRITEABLE 10 160 161 /****************************************************************************** 162 * O.K., here are the routines one can access in order to decode GIF file: * 163 * (GIF_LIB file DGIF_LIB.C). * 164 ******************************************************************************/ 165 166 GifFileType *DGifOpenFileName(const char *GifFileName); 167 GifFileType *DGifOpenFileHandle(int GifFileHandle); 168 GifFileType *DGifOpen( void* userPtr, InputFunc readFunc ); /* new one (TVT) */ 169 int DGifSlurp(GifFileType *GifFile); 170 int DGifGetScreenDesc(GifFileType *GifFile); 171 int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType); 172 int DGifGetImageDesc(GifFileType *GifFile); 173 int DGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen); 174 int DGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel); 175 int DGifGetComment(GifFileType *GifFile, char *GifComment); 176 int DGifGetExtension(GifFileType *GifFile, int *GifExtCode, 177 GifByteType **GifExtension); 178 int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension); 179 int DGifGetCode(GifFileType *GifFile, int *GifCodeSize, 180 GifByteType **GifCodeBlock); 181 int DGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock); 182 int DGifGetLZCodes(GifFileType *GifFile, int *GifCode); 183 int DGifCloseFile(GifFileType *GifFile); 184 185 #define D_GIF_ERR_OPEN_FAILED 101 /* And DGif possible errors. */ 186 #define D_GIF_ERR_READ_FAILED 102 187 #define D_GIF_ERR_NOT_GIF_FILE 103 188 #define D_GIF_ERR_NO_SCRN_DSCR 104 189 #define D_GIF_ERR_NO_IMAG_DSCR 105 190 #define D_GIF_ERR_NO_COLOR_MAP 106 191 #define D_GIF_ERR_WRONG_RECORD 107 192 #define D_GIF_ERR_DATA_TOO_BIG 108 193 #define D_GIF_ERR_NOT_ENOUGH_MEM 109 194 #define D_GIF_ERR_CLOSE_FAILED 110 195 #define D_GIF_ERR_NOT_READABLE 111 196 #define D_GIF_ERR_IMAGE_DEFECT 112 197 #define D_GIF_ERR_EOF_TOO_SOON 113 198 199 /****************************************************************************** 200 * O.K., here are the routines from GIF_LIB file QUANTIZE.C. * 201 ******************************************************************************/ 202 int QuantizeBuffer(unsigned int Width, unsigned int Height, int *ColorMapSize, 203 GifByteType *RedInput, GifByteType *GreenInput, GifByteType *BlueInput, 204 GifByteType *OutputBuffer, GifColorType *OutputColorMap); 205 206 207 /****************************************************************************** 208 * O.K., here are the routines from GIF_LIB file QPRINTF.C. * 209 ******************************************************************************/ 210 extern int GifQuietPrint; 211 212 #ifdef HAVE_VARARGS_H 213 extern void GifQprintf(); 214 #else 215 extern void GifQprintf(char *Format, ...); 216 #endif /* HAVE_VARARGS_H */ 217 218 /****************************************************************************** 219 * O.K., here are the routines from GIF_LIB file GIF_ERR.C. * 220 ******************************************************************************/ 221 extern void PrintGifError(void); 222 extern int GifLastError(void); 223 224 /****************************************************************************** 225 * O.K., here are the routines from GIF_LIB file DEV2GIF.C. * 226 ******************************************************************************/ 227 extern int DumpScreen2Gif(const char *FileName, 228 int ReqGraphDriver, 229 int ReqGraphMode1, 230 int ReqGraphMode2, 231 int ReqGraphMode3); 232 233 /***************************************************************************** 234 * 235 * Everything below this point is new after version 1.2, supporting `slurp 236 * mode' for doing I/O in two big belts with all the image-bashing in core. 237 * 238 *****************************************************************************/ 239 240 /****************************************************************************** 241 * Color Map handling from ALLOCGIF.C * 242 ******************************************************************************/ 243 244 extern ColorMapObject *MakeMapObject(int ColorCount, const GifColorType *ColorMap); 245 extern void FreeMapObject(ColorMapObject *Object); 246 extern ColorMapObject *UnionColorMap( 247 const ColorMapObject *ColorIn1, 248 const ColorMapObject *ColorIn2, 249 GifPixelType ColorTransIn2[]); 250 extern int BitSize(int n); 251 252 /****************************************************************************** 253 * Support for the in-core structures allocation (slurp mode). * 254 ******************************************************************************/ 255 256 /* This is the in-core version of an extension record */ 257 typedef struct { 258 int ByteCount; 259 char *Bytes; /* on malloc(3) heap */ 260 int Function; /* Holds the type of the Extension block. */ 261 } ExtensionBlock; 262 263 /* This holds an image header, its unpacked raster bits, and extensions */ 264 typedef struct SavedImage { 265 GifImageDesc ImageDesc; 266 267 char *RasterBits; /* on malloc(3) heap */ 268 269 int Function; /* DEPRECATED: Use ExtensionBlocks[x].Function 270 * instead */ 271 int ExtensionBlockCount; 272 ExtensionBlock *ExtensionBlocks; /* on malloc(3) heap */ 273 } SavedImage; 274 275 extern void ApplyTranslation(SavedImage *Image, GifPixelType Translation[]); 276 277 extern void MakeExtension(SavedImage *New, int Function); 278 extern int AddExtensionBlock(SavedImage *New, int Len, char ExtData[]); 279 extern void FreeExtension(SavedImage *Image); 280 281 extern SavedImage *MakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom); 282 extern void FreeSavedImages(GifFileType *GifFile); 283 284 /****************************************************************************** 285 * The library's internal utility font * 286 ******************************************************************************/ 287 288 #define GIF_FONT_WIDTH 8 289 #define GIF_FONT_HEIGHT 8 290 extern unsigned char AsciiTable[][GIF_FONT_WIDTH]; 291 292 extern void DrawText(SavedImage *Image, 293 const int x, const int y, 294 const char *legend, 295 const int color); 296 297 extern void DrawBox(SavedImage *Image, 298 const int x, const int y, 299 const int w, const int d, 300 const int color); 301 302 void DrawRectangle(SavedImage *Image, 303 const int x, const int y, 304 const int w, const int d, 305 const int color); 306 307 extern void DrawBoxedText(SavedImage *Image, 308 const int x, const int y, 309 const char *legend, 310 const int border, 311 const int bg, 312 const int fg); 313 314 #endif /* _GIF_LIB_H */ 315