| 6 |
| 7 | #ifndef _GIF_LIB_H_ |
| 8 | #define _GIF_LIB_H_ 1 |
| 9 |
| 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif /* __cplusplus */ |
| 13 |
| 14 | #define GIFLIB_MAJOR 5 |
| 15 | #define GIFLIB_MINOR 0 |
| 16 | #define GIFLIB_RELEASE 5 |
| 17 |
| 18 | #define GIF_ERROR 0 |
| 19 | #define GIF_OK 1 |
| 20 |
| 21 | #include <stddef.h> |
| 22 | #include <stdbool.h> |
| 23 |
| 24 | #define GIF_STAMP "GIFVER" /* First chars in file - GIF stamp. */ |
| 25 | #define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1 |
| 26 | #define GIF_VERSION_POS 3 /* Version first character in stamp. */ |
| 27 | #define GIF87_STAMP "GIF87a" /* First chars in file - GIF stamp. */ |
| 28 | #define GIF89_STAMP "GIF89a" /* First chars in file - GIF stamp. */ |
| 29 |
| 30 | typedef unsigned char GifPixelType; |
| 31 | typedef unsigned char *GifRowType; |
| 32 | typedef unsigned char GifByteType; |
| 33 | typedef unsigned int GifPrefixType; |
| 34 | typedef int GifWord; |
| 35 |
| 36 | typedef struct GifColorType { |
| 37 | GifByteType Red, Green, Blue; |
| 38 | } GifColorType; |
| 39 |
| 40 | typedef struct ColorMapObject { |
| 41 | int ColorCount; |
| 42 | int BitsPerPixel; |
| 43 | bool SortFlag; |
| 44 | GifColorType *Colors; /* on malloc(3) heap */ |
| 45 | } ColorMapObject; |
| 46 |
| 47 | typedef struct GifImageDesc { |
| 48 | GifWord Left, Top, Width, Height; /* Current image dimensions. */ |
| 49 | bool Interlace; /* Sequential/Interlaced lines. */ |
| 50 | ColorMapObject *ColorMap; /* The local color map */ |
| 51 | } GifImageDesc; |
| 52 |
| 53 | typedef struct ExtensionBlock { |
| 54 | int ByteCount; |
| 55 | GifByteType *Bytes; /* on malloc(3) heap */ |
| 56 | int Function; /* The block function code */ |
| 57 | #define CONTINUE_EXT_FUNC_CODE 0x00 /* continuation subblock */ |
| 58 | #define COMMENT_EXT_FUNC_CODE 0xfe /* comment */ |
| 59 | #define GRAPHICS_EXT_FUNC_CODE 0xf9 /* graphics control (GIF89) */ |
| 60 | #define PLAINTEXT_EXT_FUNC_CODE 0x01 /* plaintext */ |
| 61 | #define APPLICATION_EXT_FUNC_CODE 0xff /* application block */ |
| 62 | } ExtensionBlock; |
| 63 |
| 64 | typedef struct SavedImage { |
| 65 | GifImageDesc ImageDesc; |
| 66 | GifByteType *RasterBits; /* on malloc(3) heap */ |
| 67 | int ExtensionBlockCount; /* Count of extensions before image */ |
| 68 | ExtensionBlock *ExtensionBlocks; /* Extensions before image */ |
| 69 | } SavedImage; |
| 70 |
| 71 | typedef struct GifFileType { |
| 72 | GifWord SWidth, SHeight; /* Size of virtual canvas */ |
| 73 | GifWord SColorResolution; /* How many colors can we generate? */ |
| 74 | GifWord SBackGroundColor; /* Background color for virtual canvas */ |
| 75 | GifByteType AspectByte; /* Used to compute pixel aspect ratio */ |
| 76 | ColorMapObject *SColorMap; /* Global colormap, NULL if nonexistent. */ |
| 77 | int ImageCount; /* Number of current image (both APIs) */ |
| 78 | GifImageDesc Image; /* Current image (low-level API) */ |
| 79 | SavedImage *SavedImages; /* Image sequence (high-level API) */ |
| 80 | int ExtensionBlockCount; /* Count extensions past last image */ |
| 81 | ExtensionBlock *ExtensionBlocks; /* Extensions past last image */ |
| 82 | int Error; /* Last error condition reported */ |
| 83 | void *UserData; /* hook to attach user data (TVT) */ |
| 84 | void *Private; /* Don't mess with this! */ |
| 85 | } GifFileType; |
| 86 |
| 87 | #define GIF_ASPECT_RATIO(n) ((n)+15.0/64.0) |
| 88 |
| 89 | typedef enum { |
| 90 | UNDEFINED_RECORD_TYPE, |
| 91 | SCREEN_DESC_RECORD_TYPE, |
| 92 | IMAGE_DESC_RECORD_TYPE, /* Begin with ',' */ |
| 93 | EXTENSION_RECORD_TYPE, /* Begin with '!' */ |
| 94 | TERMINATE_RECORD_TYPE /* Begin with ';' */ |
| 95 | } GifRecordType; |
| 96 |
| 97 | /* func type to read gif data from arbitrary sources (TVT) */ |
| 98 | typedef int (*InputFunc) (GifFileType *, GifByteType *, int); |
| 99 |
| 100 | /* func type to write gif data to arbitrary targets. |
| 101 | * Returns count of bytes written. (MRB) |
| 102 | */ |
| 103 | typedef int (*OutputFunc) (GifFileType *, const GifByteType *, int); |
| 104 |
| 105 | /****************************************************************************** |
| 106 | GIF89 structures |
| 107 | ******************************************************************************/ |
| 108 |
| 109 | typedef struct GraphicsControlBlock { |
| 110 | int DisposalMode; |
| 111 | #define DISPOSAL_UNSPECIFIED 0 /* No disposal specified. */ |
| 112 | #define DISPOSE_DO_NOT 1 /* Leave image in place */ |
| 113 | #define DISPOSE_BACKGROUND 2 /* Set area too background color */ |
| 114 | #define DISPOSE_PREVIOUS 3 /* Restore to previous content */ |
| 115 | bool UserInputFlag; /* User confirmation required before disposal */ |
| 116 | int DelayTime; /* pre-display delay in 0.01sec units */ |
| 117 | int TransparentColor; /* Palette index for transparency, -1 if none */ |
| 118 | #define NO_TRANSPARENT_COLOR -1 |
| 119 | } GraphicsControlBlock; |
| 120 |
| 121 | /****************************************************************************** |
| 122 | GIF encoding routines |
| 123 | ******************************************************************************/ |
| 124 |
| 125 | /* Main entry points */ |
| 126 | GifFileType *EGifOpenFileName(const char *GifFileName, |
| 127 | const bool GifTestExistence, int *Error); |
| 128 | GifFileType *EGifOpenFileHandle(const int GifFileHandle, int *Error); |
| 129 | GifFileType *EGifOpen(void *userPtr, OutputFunc writeFunc, int *Error); |
| 130 | int EGifSpew(GifFileType * GifFile); |
| 131 | char *EGifGetGifVersion(GifFileType *GifFile); /* new in 5.x */ |
| 132 | int EGifCloseFile(GifFileType * GifFile); |
| 133 |
| 134 | #define E_GIF_ERR_OPEN_FAILED 1 /* And EGif possible errors. */ |
| 135 | #define E_GIF_ERR_WRITE_FAILED 2 |
| 136 | #define E_GIF_ERR_HAS_SCRN_DSCR 3 |
| 137 | #define E_GIF_ERR_HAS_IMAG_DSCR 4 |
| 138 | #define E_GIF_ERR_NO_COLOR_MAP 5 |
| 139 | #define E_GIF_ERR_DATA_TOO_BIG 6 |
| 140 | #define E_GIF_ERR_NOT_ENOUGH_MEM 7 |
| 141 | #define E_GIF_ERR_DISK_IS_FULL 8 |
| 142 | #define E_GIF_ERR_CLOSE_FAILED 9 |
| 143 | #define E_GIF_ERR_NOT_WRITEABLE 10 |
| 144 |
| 145 | /* These are legacy. You probably do not want to call them directly */ |
| 146 | int EGifPutScreenDesc(GifFileType *GifFile, |
| 147 | const int GifWidth, const int GifHeight, |
| 148 | const int GifColorRes, |
| 149 | const int GifBackGround, |
| 150 | const ColorMapObject *GifColorMap); |
| 151 | int EGifPutImageDesc(GifFileType *GifFile, |
| 152 | const int GifLeft, const int GifTop, |
| 153 | const int GifWidth, const int GifHeight, |
| 154 | const bool GifInterlace, |
| 155 | const ColorMapObject *GifColorMap); |
| 156 | void EGifSetGifVersion(GifFileType *GifFile, const bool gif89); |
| 157 | int EGifPutLine(GifFileType *GifFile, GifPixelType *GifLine, |
| 158 | int GifLineLen); |
| 159 | int EGifPutPixel(GifFileType *GifFile, const GifPixelType GifPixel); |
| 160 | int EGifPutComment(GifFileType *GifFile, const char *GifComment); |
| 161 | int EGifPutExtensionLeader(GifFileType *GifFile, const int GifExtCode); |
| 162 | int EGifPutExtensionBlock(GifFileType *GifFile, |
| 163 | const int GifExtLen, const void *GifExtension); |
| 164 | int EGifPutExtensionTrailer(GifFileType *GifFile); |
| 165 | int EGifPutExtension(GifFileType *GifFile, const int GifExtCode, |
| 166 | const int GifExtLen, |
| 167 | const void *GifExtension); |
| 168 | int EGifPutCode(GifFileType *GifFile, int GifCodeSize, |
| 169 | const GifByteType *GifCodeBlock); |
| 170 | int EGifPutCodeNext(GifFileType *GifFile, |
| 171 | const GifByteType *GifCodeBlock); |
| 172 |
| 173 | /****************************************************************************** |
| 174 | GIF decoding routines |
| 175 | ******************************************************************************/ |
| 176 |
| 177 | /* Main entry points */ |
| 178 | GifFileType *DGifOpenFileName(const char *GifFileName, int *Error); |
| 179 | GifFileType *DGifOpenFileHandle(int GifFileHandle, int *Error); |
| 180 | int DGifSlurp(GifFileType * GifFile); |
| 181 | GifFileType *DGifOpen(void *userPtr, InputFunc readFunc, int *Error); /* new one (TVT) */ |
| 182 | int DGifCloseFile(GifFileType * GifFile); |
| 183 |
| 184 | #define D_GIF_ERR_OPEN_FAILED 101 /* And DGif possible errors. */ |
| 185 | #define D_GIF_ERR_READ_FAILED 102 |
| 186 | #define D_GIF_ERR_NOT_GIF_FILE 103 |
| 187 | #define D_GIF_ERR_NO_SCRN_DSCR 104 |
| 188 | #define D_GIF_ERR_NO_IMAG_DSCR 105 |
| 189 | #define D_GIF_ERR_NO_COLOR_MAP 106 |
| 190 | #define D_GIF_ERR_WRONG_RECORD 107 |
| 191 | #define D_GIF_ERR_DATA_TOO_BIG 108 |
| 192 | #define D_GIF_ERR_NOT_ENOUGH_MEM 109 |
| 193 | #define D_GIF_ERR_CLOSE_FAILED 110 |
| 194 | #define D_GIF_ERR_NOT_READABLE 111 |
| 195 | #define D_GIF_ERR_IMAGE_DEFECT 112 |
| 196 | #define D_GIF_ERR_EOF_TOO_SOON 113 |
| 197 |
| 198 | /* These are legacy. You probably do not want to call them directly */ |
| 199 | int DGifGetScreenDesc(GifFileType *GifFile); |
| 200 | int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType); |
| 201 | int DGifGetImageDesc(GifFileType *GifFile, bool changeImageCount); |
| 202 | int DGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen); |
| 203 | int DGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel); |
| 204 | int DGifGetComment(GifFileType *GifFile, char *GifComment); |
| 205 | int DGifGetExtension(GifFileType *GifFile, int *GifExtCode, |
| 206 | GifByteType **GifExtension); |
| 207 | int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension,int* ExtCode); |
| 208 | int DGifGetCode(GifFileType *GifFile, int *GifCodeSize, |
| 209 | GifByteType **GifCodeBlock); |
| 210 | int DGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock); |
| 211 | int DGifGetLZCodes(GifFileType *GifFile, int *GifCode); |
| 212 |
| 213 |
| 214 | /****************************************************************************** |
| 215 | Color table quantization (deprecated) |
| 216 | ******************************************************************************/ |
| 217 | int GifQuantizeBuffer(unsigned int Width, unsigned int Height, |
| 218 | int *ColorMapSize, GifByteType * RedInput, |
| 219 | GifByteType * GreenInput, GifByteType * BlueInput, |
| 220 | GifByteType * OutputBuffer, |
| 221 | GifColorType * OutputColorMap); |
| 222 |
| 223 | /****************************************************************************** |
| 224 | Error handling and reporting. |
| 225 | ******************************************************************************/ |
| 226 | extern char *GifErrorString(int ErrorCode); /* new in 2012 - ESR */ |
| 227 |
| 228 | /***************************************************************************** |
| 229 | Everything below this point is new after version 1.2, supporting `slurp |
| 230 | mode' for doing I/O in two big belts with all the image-bashing in core. |
| 231 | ******************************************************************************/ |
| 232 |
| 233 | /****************************************************************************** |
| 234 | Color map handling from gif_alloc.c |
| 235 | ******************************************************************************/ |
| 236 |
| 237 | extern ColorMapObject *GifMakeMapObject(int ColorCount, |
| 238 | const GifColorType *ColorMap); |
| 239 | extern void GifFreeMapObject(ColorMapObject *Object); |
| 240 | extern ColorMapObject *GifUnionColorMap(const ColorMapObject *ColorIn1, |
| 241 | const ColorMapObject *ColorIn2, |
| 242 | GifPixelType ColorTransIn2[]); |
| 243 | extern int GifBitSize(int n); |
| 244 |
| 245 | /****************************************************************************** |
| 246 | Support for the in-core structures allocation (slurp mode). |
| 247 | ******************************************************************************/ |
| 248 |
| 249 | extern void GifApplyTranslation(SavedImage *Image, GifPixelType Translation[]); |
| 250 | extern int GifAddExtensionBlock(int *ExtensionBlock_Count, |
| 251 | ExtensionBlock **ExtensionBlocks, |
| 252 | int Function, |
| 253 | unsigned int Len, unsigned char ExtData[]); |
| 254 | extern void GifFreeExtensions(int *ExtensionBlock_Count, |
| 255 | ExtensionBlock **ExtensionBlocks); |
| 256 | extern SavedImage *GifMakeSavedImage(GifFileType *GifFile, |
| 257 | const SavedImage *CopyFrom); |
| 258 | extern void GifFreeSavedImages(GifFileType *GifFile); |
| 259 |
| 260 | /****************************************************************************** |
| 261 | 5.x functions for GIF89 graphics control blocks |
| 262 | ******************************************************************************/ |
| 263 |
| 264 | int DGifExtensionToGCB(const size_t GifExtensionLength, |
| 265 | const GifByteType *GifExtension, |
| 266 | GraphicsControlBlock *GCB); |
| 267 | size_t EGifGCBToExtension(const GraphicsControlBlock *GCB, |
| 268 | GifByteType *GifExtension); |
| 269 |
| 270 | int DGifSavedExtensionToGCB(GifFileType *GifFile, |
| 271 | int ImageIndex, |
| 272 | GraphicsControlBlock *GCB); |
| 273 | int EGifGCBToSavedExtension(const GraphicsControlBlock *GCB, |
| 274 | GifFileType *GifFile, |
| 275 | int ImageIndex); |
| 276 |
| 277 | /****************************************************************************** |
| 278 | The library's internal utility font |
| 279 | ******************************************************************************/ |
| 280 |
| 281 | #define GIF_FONT_WIDTH 8 |
| 282 | #define GIF_FONT_HEIGHT 8 |
| 283 | extern const unsigned char GifAsciiTable8x8[][GIF_FONT_WIDTH]; |
| 284 |
| 285 | extern void GifDrawText8x8(SavedImage *Image, |
| 286 | const int x, const int y, |
| 287 | const char *legend, const int color); |
| 288 |
| 289 | extern void GifDrawBox(SavedImage *Image, |
| 290 | const int x, const int y, |
| 291 | const int w, const int d, const int color); |
| 292 |
| 293 | extern void GifDrawRectangle(SavedImage *Image, |
| 294 | const int x, const int y, |
| 295 | const int w, const int d, const int color); |
| 296 |
| 297 | extern void GifDrawBoxedText8x8(SavedImage *Image, |
| 298 | const int x, const int y, |
| 299 | const char *legend, |
| 300 | const int border, const int bg, const int fg); |
| 301 |
| 302 | #ifdef __cplusplus |
| 303 | } |
| 304 | #endif /* __cplusplus */ |
| 305 | #endif /* _GIF_LIB_H */ |
| 306 |
| 307 | /* end */ |
| 308 |