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