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