blob: 078930c625f5d901e505d75c8ca5fceab035c814 [file] [log] [blame]
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -08001/******************************************************************************
Chris Craik9aef3ea2013-06-24 19:34:25 -07002
3gif_lib.h - service library for decoding and encoding GIF images
4
5*****************************************************************************/
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -08006
7#ifndef _GIF_LIB_H_
8#define _GIF_LIB_H_ 1
9
10#ifdef __cplusplus
11extern "C" {
12#endif /* __cplusplus */
13
Chris Craik9aef3ea2013-06-24 19:34:25 -070014#define GIFLIB_MAJOR 5
Leon Scroggins IIIdf596d32017-03-13 14:03:21 -040015#define GIFLIB_MINOR 1
Chris Craik9aef3ea2013-06-24 19:34:25 -070016#define GIFLIB_RELEASE 4
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -080017
18#define GIF_ERROR 0
19#define GIF_OK 1
20
Leon Scroggins IIIdf596d32017-03-13 14:03:21 -040021#include <stddef.h>
Chris Craik9aef3ea2013-06-24 19:34:25 -070022#include <stdbool.h>
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -080023
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
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -080030typedef unsigned char GifPixelType;
31typedef unsigned char *GifRowType;
32typedef unsigned char GifByteType;
Chris Craik9aef3ea2013-06-24 19:34:25 -070033typedef unsigned int GifPrefixType;
34typedef int GifWord;
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -080035
36typedef struct GifColorType {
37 GifByteType Red, Green, Blue;
38} GifColorType;
39
40typedef struct ColorMapObject {
41 int ColorCount;
42 int BitsPerPixel;
Chris Craik9aef3ea2013-06-24 19:34:25 -070043 bool SortFlag;
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -080044 GifColorType *Colors; /* on malloc(3) heap */
45} ColorMapObject;
46
47typedef struct GifImageDesc {
Chris Craik9aef3ea2013-06-24 19:34:25 -070048 GifWord Left, Top, Width, Height; /* Current image dimensions. */
49 bool Interlace; /* Sequential/Interlaced lines. */
50 ColorMapObject *ColorMap; /* The local color map */
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -080051} GifImageDesc;
52
Chris Craik9aef3ea2013-06-24 19:34:25 -070053typedef 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
64typedef 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
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -080071typedef struct GifFileType {
Chris Craik9aef3ea2013-06-24 19:34:25 -070072 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! */
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -080085} GifFileType;
86
Chris Craik9aef3ea2013-06-24 19:34:25 -070087#define GIF_ASPECT_RATIO(n) ((n)+15.0/64.0)
88
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -080089typedef 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
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -080097/* func type to read gif data from arbitrary sources (TVT) */
98typedef int (*InputFunc) (GifFileType *, GifByteType *, int);
99
Chris Craik9aef3ea2013-06-24 19:34:25 -0700100/* func type to write gif data to arbitrary targets.
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800101 * Returns count of bytes written. (MRB)
102 */
103typedef int (*OutputFunc) (GifFileType *, const GifByteType *, int);
104
105/******************************************************************************
Chris Craik9aef3ea2013-06-24 19:34:25 -0700106 GIF89 structures
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800107******************************************************************************/
108
Chris Craik9aef3ea2013-06-24 19:34:25 -0700109typedef 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;
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800120
121/******************************************************************************
Chris Craik9aef3ea2013-06-24 19:34:25 -0700122 GIF encoding routines
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800123******************************************************************************/
124
Chris Craik9aef3ea2013-06-24 19:34:25 -0700125/* Main entry points */
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800126GifFileType *EGifOpenFileName(const char *GifFileName,
Chris Craik9aef3ea2013-06-24 19:34:25 -0700127 const bool GifTestExistence, int *Error);
128GifFileType *EGifOpenFileHandle(const int GifFileHandle, int *Error);
129GifFileType *EGifOpen(void *userPtr, OutputFunc writeFunc, int *Error);
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800130int EGifSpew(GifFileType * GifFile);
Leon Scroggins IIIdf596d32017-03-13 14:03:21 -0400131const char *EGifGetGifVersion(GifFileType *GifFile); /* new in 5.x */
132int EGifCloseFile(GifFileType *GifFile, int *ErrorCode);
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800133
Leon Scroggins IIIdf596d32017-03-13 14:03:21 -0400134#define E_GIF_SUCCEEDED 0
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800135#define E_GIF_ERR_OPEN_FAILED 1 /* And EGif possible errors. */
136#define E_GIF_ERR_WRITE_FAILED 2
137#define E_GIF_ERR_HAS_SCRN_DSCR 3
138#define E_GIF_ERR_HAS_IMAG_DSCR 4
139#define E_GIF_ERR_NO_COLOR_MAP 5
140#define E_GIF_ERR_DATA_TOO_BIG 6
141#define E_GIF_ERR_NOT_ENOUGH_MEM 7
142#define E_GIF_ERR_DISK_IS_FULL 8
143#define E_GIF_ERR_CLOSE_FAILED 9
144#define E_GIF_ERR_NOT_WRITEABLE 10
145
Chris Craik9aef3ea2013-06-24 19:34:25 -0700146/* These are legacy. You probably do not want to call them directly */
147int EGifPutScreenDesc(GifFileType *GifFile,
148 const int GifWidth, const int GifHeight,
149 const int GifColorRes,
150 const int GifBackGround,
151 const ColorMapObject *GifColorMap);
152int EGifPutImageDesc(GifFileType *GifFile,
153 const int GifLeft, const int GifTop,
154 const int GifWidth, const int GifHeight,
155 const bool GifInterlace,
156 const ColorMapObject *GifColorMap);
157void EGifSetGifVersion(GifFileType *GifFile, const bool gif89);
158int EGifPutLine(GifFileType *GifFile, GifPixelType *GifLine,
159 int GifLineLen);
160int EGifPutPixel(GifFileType *GifFile, const GifPixelType GifPixel);
161int EGifPutComment(GifFileType *GifFile, const char *GifComment);
162int EGifPutExtensionLeader(GifFileType *GifFile, const int GifExtCode);
163int EGifPutExtensionBlock(GifFileType *GifFile,
164 const int GifExtLen, const void *GifExtension);
165int EGifPutExtensionTrailer(GifFileType *GifFile);
166int EGifPutExtension(GifFileType *GifFile, const int GifExtCode,
167 const int GifExtLen,
168 const void *GifExtension);
169int EGifPutCode(GifFileType *GifFile, int GifCodeSize,
170 const GifByteType *GifCodeBlock);
171int EGifPutCodeNext(GifFileType *GifFile,
172 const GifByteType *GifCodeBlock);
173
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800174/******************************************************************************
Chris Craik9aef3ea2013-06-24 19:34:25 -0700175 GIF decoding routines
176******************************************************************************/
177
178/* Main entry points */
179GifFileType *DGifOpenFileName(const char *GifFileName, int *Error);
180GifFileType *DGifOpenFileHandle(int GifFileHandle, int *Error);
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800181int DGifSlurp(GifFileType * GifFile);
Chris Craik9aef3ea2013-06-24 19:34:25 -0700182GifFileType *DGifOpen(void *userPtr, InputFunc readFunc, int *Error); /* new one (TVT) */
Leon Scroggins IIIdf596d32017-03-13 14:03:21 -0400183 int DGifCloseFile(GifFileType * GifFile, int *ErrorCode);
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800184
Leon Scroggins IIIdf596d32017-03-13 14:03:21 -0400185#define D_GIF_SUCCEEDED 0
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800186#define D_GIF_ERR_OPEN_FAILED 101 /* And DGif possible errors. */
187#define D_GIF_ERR_READ_FAILED 102
188#define D_GIF_ERR_NOT_GIF_FILE 103
189#define D_GIF_ERR_NO_SCRN_DSCR 104
190#define D_GIF_ERR_NO_IMAG_DSCR 105
191#define D_GIF_ERR_NO_COLOR_MAP 106
192#define D_GIF_ERR_WRONG_RECORD 107
193#define D_GIF_ERR_DATA_TOO_BIG 108
194#define D_GIF_ERR_NOT_ENOUGH_MEM 109
195#define D_GIF_ERR_CLOSE_FAILED 110
196#define D_GIF_ERR_NOT_READABLE 111
197#define D_GIF_ERR_IMAGE_DEFECT 112
198#define D_GIF_ERR_EOF_TOO_SOON 113
199
Chris Craik9aef3ea2013-06-24 19:34:25 -0700200/* These are legacy. You probably do not want to call them directly */
201int DGifGetScreenDesc(GifFileType *GifFile);
202int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType);
203int DGifGetImageDesc(GifFileType *GifFile);
204int DGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);
205int DGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel);
206int DGifGetComment(GifFileType *GifFile, char *GifComment);
207int DGifGetExtension(GifFileType *GifFile, int *GifExtCode,
208 GifByteType **GifExtension);
209int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension);
210int DGifGetCode(GifFileType *GifFile, int *GifCodeSize,
211 GifByteType **GifCodeBlock);
212int DGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock);
213int DGifGetLZCodes(GifFileType *GifFile, int *GifCode);
214
215
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800216/******************************************************************************
Chris Craik9aef3ea2013-06-24 19:34:25 -0700217 Color table quantization (deprecated)
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800218******************************************************************************/
Chris Craik9aef3ea2013-06-24 19:34:25 -0700219int GifQuantizeBuffer(unsigned int Width, unsigned int Height,
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800220 int *ColorMapSize, GifByteType * RedInput,
221 GifByteType * GreenInput, GifByteType * BlueInput,
222 GifByteType * OutputBuffer,
223 GifColorType * OutputColorMap);
224
225/******************************************************************************
Chris Craik9aef3ea2013-06-24 19:34:25 -0700226 Error handling and reporting.
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800227******************************************************************************/
Leon Scroggins IIIdf596d32017-03-13 14:03:21 -0400228extern const char *GifErrorString(int ErrorCode); /* new in 2012 - ESR */
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800229
230/*****************************************************************************
Chris Craik9aef3ea2013-06-24 19:34:25 -0700231 Everything below this point is new after version 1.2, supporting `slurp
232 mode' for doing I/O in two big belts with all the image-bashing in core.
233******************************************************************************/
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800234
235/******************************************************************************
Chris Craik9aef3ea2013-06-24 19:34:25 -0700236 Color map handling from gif_alloc.c
237******************************************************************************/
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800238
Chris Craik9aef3ea2013-06-24 19:34:25 -0700239extern ColorMapObject *GifMakeMapObject(int ColorCount,
240 const GifColorType *ColorMap);
241extern void GifFreeMapObject(ColorMapObject *Object);
242extern ColorMapObject *GifUnionColorMap(const ColorMapObject *ColorIn1,
243 const ColorMapObject *ColorIn2,
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800244 GifPixelType ColorTransIn2[]);
Chris Craik9aef3ea2013-06-24 19:34:25 -0700245extern int GifBitSize(int n);
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800246
Leon Scroggins IIIdf596d32017-03-13 14:03:21 -0400247extern void *
248reallocarray(void *optr, size_t nmemb, size_t size);
249
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800250/******************************************************************************
Chris Craik9aef3ea2013-06-24 19:34:25 -0700251 Support for the in-core structures allocation (slurp mode).
252******************************************************************************/
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800253
Chris Craik9aef3ea2013-06-24 19:34:25 -0700254extern void GifApplyTranslation(SavedImage *Image, GifPixelType Translation[]);
255extern int GifAddExtensionBlock(int *ExtensionBlock_Count,
256 ExtensionBlock **ExtensionBlocks,
257 int Function,
258 unsigned int Len, unsigned char ExtData[]);
259extern void GifFreeExtensions(int *ExtensionBlock_Count,
260 ExtensionBlock **ExtensionBlocks);
261extern SavedImage *GifMakeSavedImage(GifFileType *GifFile,
262 const SavedImage *CopyFrom);
263extern void GifFreeSavedImages(GifFileType *GifFile);
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800264
265/******************************************************************************
Chris Craik9aef3ea2013-06-24 19:34:25 -0700266 5.x functions for GIF89 graphics control blocks
267******************************************************************************/
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800268
Chris Craik9aef3ea2013-06-24 19:34:25 -0700269int DGifExtensionToGCB(const size_t GifExtensionLength,
270 const GifByteType *GifExtension,
271 GraphicsControlBlock *GCB);
272size_t EGifGCBToExtension(const GraphicsControlBlock *GCB,
273 GifByteType *GifExtension);
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800274
Chris Craik9aef3ea2013-06-24 19:34:25 -0700275int DGifSavedExtensionToGCB(GifFileType *GifFile,
276 int ImageIndex,
277 GraphicsControlBlock *GCB);
278int EGifGCBToSavedExtension(const GraphicsControlBlock *GCB,
279 GifFileType *GifFile,
280 int ImageIndex);
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800281
Leon Scroggins IIIdf596d32017-03-13 14:03:21 -0400282/******************************************************************************
283 The library's internal utility font
284******************************************************************************/
285
286#define GIF_FONT_WIDTH 8
287#define GIF_FONT_HEIGHT 8
288extern const unsigned char GifAsciiTable8x8[][GIF_FONT_WIDTH];
289
290extern void GifDrawText8x8(SavedImage *Image,
291 const int x, const int y,
292 const char *legend, const int color);
293
294extern void GifDrawBox(SavedImage *Image,
295 const int x, const int y,
296 const int w, const int d, const int color);
297
298extern void GifDrawRectangle(SavedImage *Image,
299 const int x, const int y,
300 const int w, const int d, const int color);
301
302extern void GifDrawBoxedText8x8(SavedImage *Image,
303 const int x, const int y,
304 const char *legend,
305 const int border, const int bg, const int fg);
306
The Android Open Source Projectc2eacae2009-03-03 19:29:32 -0800307#ifdef __cplusplus
308}
309#endif /* __cplusplus */
310#endif /* _GIF_LIB_H */
Chris Craik9aef3ea2013-06-24 19:34:25 -0700311
312/* end */