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