summaryrefslogtreecommitdiffstats
path: root/gif_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'gif_lib.h')
-rw-r--r--gif_lib.h373
1 files changed, 159 insertions, 214 deletions
diff --git a/gif_lib.h b/gif_lib.h
index f0cf858..23df861 100644
--- a/gif_lib.h
+++ b/gif_lib.h
@@ -1,17 +1,8 @@
/******************************************************************************
- * In order to make life a little bit easier when using the GIF file format,
- * this library was written, and which does all the dirty work...
- *
- * Written by Gershon Elber, Jun. 1989
- * Hacks by Eric S. Raymond, Sep. 1992
- ******************************************************************************
- * History:
- * 14 Jun 89 - Version 1.0 by Gershon Elber.
- * 3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names)
- * 15 Sep 90 - Version 2.0 by Eric S. Raymond (Changes to suoport GIF slurp)
- * 26 Jun 96 - Version 3.0 by Eric S. Raymond (Full GIF89 support)
- * 17 Dec 98 - Version 4.0 by Toshio Kuratomi (Fix extension writing code)
- *****************************************************************************/
+
+gif_lib.h - service library for decoding and encoding GIF images
+
+*****************************************************************************/
#ifndef _GIF_LIB_H_
#define _GIF_LIB_H_ 1
@@ -20,21 +11,14 @@
extern "C" {
#endif /* __cplusplus */
-#define GIF_LIB_VERSION " Version 4.1, "
+#define GIFLIB_MAJOR 5
+#define GIFLIB_MINOR 0
+#define GIFLIB_RELEASE 4
#define GIF_ERROR 0
#define GIF_OK 1
-#ifndef TRUE
-#define TRUE 1
-#endif /* TRUE */
-#ifndef FALSE
-#define FALSE 0
-#endif /* FALSE */
-
-#ifndef NULL
-#define NULL 0
-#endif /* NULL */
+#include <stdbool.h>
#define GIF_STAMP "GIFVER" /* First chars in file - GIF stamp. */
#define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1
@@ -42,28 +26,11 @@ extern "C" {
#define GIF87_STAMP "GIF87a" /* First chars in file - GIF stamp. */
#define GIF89_STAMP "GIF89a" /* First chars in file - GIF stamp. */
-#define GIF_FILE_BUFFER_SIZE 16384 /* Files uses bigger buffers than usual. */
-
-typedef int GifBooleanType;
typedef unsigned char GifPixelType;
typedef unsigned char *GifRowType;
typedef unsigned char GifByteType;
-#ifdef _GBA_OPTMEM
- typedef unsigned short GifPrefixType;
- typedef short GifWord;
-#else
- typedef unsigned int GifPrefixType;
- typedef int GifWord;
-#endif
-
-#define GIF_MESSAGE(Msg) fprintf(stderr, "\n%s: %s\n", PROGRAM_NAME, Msg)
-#define GIF_EXIT(Msg) { GIF_MESSAGE(Msg); exit(-3); }
-
-#ifdef SYSV
-#define VoidPtr char *
-#else
-#define VoidPtr void *
-#endif /* SYSV */
+typedef unsigned int GifPrefixType;
+typedef int GifWord;
typedef struct GifColorType {
GifByteType Red, Green, Blue;
@@ -72,27 +39,52 @@ typedef struct GifColorType {
typedef struct ColorMapObject {
int ColorCount;
int BitsPerPixel;
+ bool SortFlag;
GifColorType *Colors; /* on malloc(3) heap */
} ColorMapObject;
typedef struct GifImageDesc {
- GifWord Left, Top, Width, Height, /* Current image dimensions. */
- Interlace; /* Sequential/Interlaced lines. */
- ColorMapObject *ColorMap; /* The local color map */
+ GifWord Left, Top, Width, Height; /* Current image dimensions. */
+ bool Interlace; /* Sequential/Interlaced lines. */
+ ColorMapObject *ColorMap; /* The local color map */
} GifImageDesc;
+typedef struct ExtensionBlock {
+ int ByteCount;
+ GifByteType *Bytes; /* on malloc(3) heap */
+ int Function; /* The block function code */
+#define CONTINUE_EXT_FUNC_CODE 0x00 /* continuation subblock */
+#define COMMENT_EXT_FUNC_CODE 0xfe /* comment */
+#define GRAPHICS_EXT_FUNC_CODE 0xf9 /* graphics control (GIF89) */
+#define PLAINTEXT_EXT_FUNC_CODE 0x01 /* plaintext */
+#define APPLICATION_EXT_FUNC_CODE 0xff /* application block */
+} ExtensionBlock;
+
+typedef struct SavedImage {
+ GifImageDesc ImageDesc;
+ GifByteType *RasterBits; /* on malloc(3) heap */
+ int ExtensionBlockCount; /* Count of extensions before image */
+ ExtensionBlock *ExtensionBlocks; /* Extensions before image */
+} SavedImage;
+
typedef struct GifFileType {
- GifWord SWidth, SHeight, /* Screen dimensions. */
- SColorResolution, /* How many colors can we generate? */
- SBackGroundColor; /* I hope you understand this one... */
- ColorMapObject *SColorMap; /* NULL if not exists. */
- int ImageCount; /* Number of current image */
- GifImageDesc Image; /* Block describing current image */
- struct SavedImage *SavedImages; /* Use this to accumulate file state */
- VoidPtr UserData; /* hook to attach user data (TVT) */
- VoidPtr Private; /* Don't mess with this! */
+ GifWord SWidth, SHeight; /* Size of virtual canvas */
+ GifWord SColorResolution; /* How many colors can we generate? */
+ GifWord SBackGroundColor; /* Background color for virtual canvas */
+ GifByteType AspectByte; /* Used to compute pixel aspect ratio */
+ ColorMapObject *SColorMap; /* Global colormap, NULL if nonexistent. */
+ int ImageCount; /* Number of current image (both APIs) */
+ GifImageDesc Image; /* Current image (low-level API) */
+ SavedImage *SavedImages; /* Image sequence (high-level API) */
+ int ExtensionBlockCount; /* Count extensions past last image */
+ ExtensionBlock *ExtensionBlocks; /* Extensions past last image */
+ int Error; /* Last error condition reported */
+ void *UserData; /* hook to attach user data (TVT) */
+ void *Private; /* Don't mess with this! */
} GifFileType;
+#define GIF_ASPECT_RATIO(n) ((n)+15.0/64.0)
+
typedef enum {
UNDEFINED_RECORD_TYPE,
SCREEN_DESC_RECORD_TYPE,
@@ -101,68 +93,41 @@ typedef enum {
TERMINATE_RECORD_TYPE /* Begin with ';' */
} GifRecordType;
-/* DumpScreen2Gif routine constants identify type of window/screen to dump.
- * Note all values below 1000 are reserved for the IBMPC different display
- * devices (it has many!) and are compatible with the numbering TC2.0
- * (Turbo C 2.0 compiler for IBM PC) gives to these devices.
- */
-typedef enum {
- GIF_DUMP_SGI_WINDOW = 1000,
- GIF_DUMP_X_WINDOW = 1001
-} GifScreenDumpType;
-
/* func type to read gif data from arbitrary sources (TVT) */
typedef int (*InputFunc) (GifFileType *, GifByteType *, int);
-/* func type to write gif data ro arbitrary targets.
+/* func type to write gif data to arbitrary targets.
* Returns count of bytes written. (MRB)
*/
typedef int (*OutputFunc) (GifFileType *, const GifByteType *, int);
/******************************************************************************
- * GIF89 extension function codes
+ GIF89 structures
******************************************************************************/
-#define COMMENT_EXT_FUNC_CODE 0xfe /* comment */
-#define GRAPHICS_EXT_FUNC_CODE 0xf9 /* graphics control */
-#define PLAINTEXT_EXT_FUNC_CODE 0x01 /* plaintext */
-#define APPLICATION_EXT_FUNC_CODE 0xff /* application block */
+typedef struct GraphicsControlBlock {
+ int DisposalMode;
+#define DISPOSAL_UNSPECIFIED 0 /* No disposal specified. */
+#define DISPOSE_DO_NOT 1 /* Leave image in place */
+#define DISPOSE_BACKGROUND 2 /* Set area too background color */
+#define DISPOSE_PREVIOUS 3 /* Restore to previous content */
+ bool UserInputFlag; /* User confirmation required before disposal */
+ int DelayTime; /* pre-display delay in 0.01sec units */
+ int TransparentColor; /* Palette index for transparency, -1 if none */
+#define NO_TRANSPARENT_COLOR -1
+} GraphicsControlBlock;
/******************************************************************************
- * O.K., here are the routines one can access in order to encode GIF file:
- * (GIF_LIB file EGIF_LIB.C).
+ GIF encoding routines
******************************************************************************/
+/* Main entry points */
GifFileType *EGifOpenFileName(const char *GifFileName,
- int GifTestExistance);
-GifFileType *EGifOpenFileHandle(int GifFileHandle);
-GifFileType *EGifOpen(void *userPtr, OutputFunc writeFunc);
-
+ const bool GifTestExistence, int *Error);
+GifFileType *EGifOpenFileHandle(const int GifFileHandle, int *Error);
+GifFileType *EGifOpen(void *userPtr, OutputFunc writeFunc, int *Error);
int EGifSpew(GifFileType * GifFile);
-void EGifSetGifVersion(const char *Version);
-int EGifPutScreenDesc(GifFileType * GifFile,
- int GifWidth, int GifHeight, int GifColorRes,
- int GifBackGround,
- const ColorMapObject * GifColorMap);
-int EGifPutImageDesc(GifFileType * GifFile, int GifLeft, int GifTop,
- int Width, int GifHeight, int GifInterlace,
- const ColorMapObject * GifColorMap);
-int EGifPutLine(GifFileType * GifFile, GifPixelType * GifLine,
- int GifLineLen);
-int EGifPutPixel(GifFileType * GifFile, GifPixelType GifPixel);
-int EGifPutComment(GifFileType * GifFile, const char *GifComment);
-int EGifPutExtensionFirst(GifFileType * GifFile, int GifExtCode,
- int GifExtLen, const VoidPtr GifExtension);
-int EGifPutExtensionNext(GifFileType * GifFile, int GifExtCode,
- int GifExtLen, const VoidPtr GifExtension);
-int EGifPutExtensionLast(GifFileType * GifFile, int GifExtCode,
- int GifExtLen, const VoidPtr GifExtension);
-int EGifPutExtension(GifFileType * GifFile, int GifExtCode, int GifExtLen,
- const VoidPtr GifExtension);
-int EGifPutCode(GifFileType * GifFile, int GifCodeSize,
- const GifByteType * GifCodeBlock);
-int EGifPutCodeNext(GifFileType * GifFile,
- const GifByteType * GifCodeBlock);
+char *EGifGetGifVersion(GifFileType *GifFile); /* new in 5.x */
int EGifCloseFile(GifFileType * GifFile);
#define E_GIF_ERR_OPEN_FAILED 1 /* And EGif possible errors. */
@@ -176,30 +141,43 @@ int EGifCloseFile(GifFileType * GifFile);
#define E_GIF_ERR_CLOSE_FAILED 9
#define E_GIF_ERR_NOT_WRITEABLE 10
+/* These are legacy. You probably do not want to call them directly */
+int EGifPutScreenDesc(GifFileType *GifFile,
+ const int GifWidth, const int GifHeight,
+ const int GifColorRes,
+ const int GifBackGround,
+ const ColorMapObject *GifColorMap);
+int EGifPutImageDesc(GifFileType *GifFile,
+ const int GifLeft, const int GifTop,
+ const int GifWidth, const int GifHeight,
+ const bool GifInterlace,
+ const ColorMapObject *GifColorMap);
+void EGifSetGifVersion(GifFileType *GifFile, const bool gif89);
+int EGifPutLine(GifFileType *GifFile, GifPixelType *GifLine,
+ int GifLineLen);
+int EGifPutPixel(GifFileType *GifFile, const GifPixelType GifPixel);
+int EGifPutComment(GifFileType *GifFile, const char *GifComment);
+int EGifPutExtensionLeader(GifFileType *GifFile, const int GifExtCode);
+int EGifPutExtensionBlock(GifFileType *GifFile,
+ const int GifExtLen, const void *GifExtension);
+int EGifPutExtensionTrailer(GifFileType *GifFile);
+int EGifPutExtension(GifFileType *GifFile, const int GifExtCode,
+ const int GifExtLen,
+ const void *GifExtension);
+int EGifPutCode(GifFileType *GifFile, int GifCodeSize,
+ const GifByteType *GifCodeBlock);
+int EGifPutCodeNext(GifFileType *GifFile,
+ const GifByteType *GifCodeBlock);
+
/******************************************************************************
- * O.K., here are the routines one can access in order to decode GIF file:
- * (GIF_LIB file DGIF_LIB.C).
- *****************************************************************************/
-#ifndef _GBA_NO_FILEIO
-GifFileType *DGifOpenFileName(const char *GifFileName);
-GifFileType *DGifOpenFileHandle(int GifFileHandle);
+ GIF decoding routines
+******************************************************************************/
+
+/* Main entry points */
+GifFileType *DGifOpenFileName(const char *GifFileName, int *Error);
+GifFileType *DGifOpenFileHandle(int GifFileHandle, int *Error);
int DGifSlurp(GifFileType * GifFile);
-#endif /* _GBA_NO_FILEIO */
-GifFileType *DGifOpen(void *userPtr, InputFunc readFunc); /* new one
- * (TVT) */
-int DGifGetScreenDesc(GifFileType * GifFile);
-int DGifGetRecordType(GifFileType * GifFile, GifRecordType * GifType);
-int DGifGetImageDesc(GifFileType * GifFile);
-int DGifGetLine(GifFileType * GifFile, GifPixelType * GifLine, int GifLineLen);
-int DGifGetPixel(GifFileType * GifFile, GifPixelType GifPixel);
-int DGifGetComment(GifFileType * GifFile, char *GifComment);
-int DGifGetExtension(GifFileType * GifFile, int *GifExtCode,
- GifByteType ** GifExtension);
-int DGifGetExtensionNext(GifFileType * GifFile, GifByteType ** GifExtension);
-int DGifGetCode(GifFileType * GifFile, int *GifCodeSize,
- GifByteType ** GifCodeBlock);
-int DGifGetCodeNext(GifFileType * GifFile, GifByteType ** GifCodeBlock);
-int DGifGetLZCodes(GifFileType * GifFile, int *GifCode);
+GifFileType *DGifOpen(void *userPtr, InputFunc readFunc, int *Error); /* new one (TVT) */
int DGifCloseFile(GifFileType * GifFile);
#define D_GIF_ERR_OPEN_FAILED 101 /* And DGif possible errors. */
@@ -216,121 +194,88 @@ int DGifCloseFile(GifFileType * GifFile);
#define D_GIF_ERR_IMAGE_DEFECT 112
#define D_GIF_ERR_EOF_TOO_SOON 113
+/* These are legacy. You probably do not want to call them directly */
+int DGifGetScreenDesc(GifFileType *GifFile);
+int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType);
+int DGifGetImageDesc(GifFileType *GifFile);
+int DGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);
+int DGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel);
+int DGifGetComment(GifFileType *GifFile, char *GifComment);
+int DGifGetExtension(GifFileType *GifFile, int *GifExtCode,
+ GifByteType **GifExtension);
+int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension);
+int DGifGetCode(GifFileType *GifFile, int *GifCodeSize,
+ GifByteType **GifCodeBlock);
+int DGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock);
+int DGifGetLZCodes(GifFileType *GifFile, int *GifCode);
+
+
/******************************************************************************
- * O.K., here are the routines from GIF_LIB file QUANTIZE.C.
+ Color table quantization (deprecated)
******************************************************************************/
-int QuantizeBuffer(unsigned int Width, unsigned int Height,
+int GifQuantizeBuffer(unsigned int Width, unsigned int Height,
int *ColorMapSize, GifByteType * RedInput,
GifByteType * GreenInput, GifByteType * BlueInput,
GifByteType * OutputBuffer,
GifColorType * OutputColorMap);
/******************************************************************************
- * O.K., here are the routines from GIF_LIB file QPRINTF.C.
+ Error handling and reporting.
******************************************************************************/
-extern int GifQuietPrint;
-
-#ifdef HAVE_STDARG_H
- extern void GifQprintf(char *Format, ...);
-#elif defined (HAVE_VARARGS_H)
- extern void GifQprintf();
-#endif /* HAVE_STDARG_H */
+extern char *GifErrorString(int ErrorCode); /* new in 2012 - ESR */
-/******************************************************************************
- * O.K., here are the routines from GIF_LIB file GIF_ERR.C.
+/*****************************************************************************
+ Everything below this point is new after version 1.2, supporting `slurp
+ mode' for doing I/O in two big belts with all the image-bashing in core.
******************************************************************************/
-#ifndef _GBA_NO_FILEIO
-extern void PrintGifError(void);
-#endif /* _GBA_NO_FILEIO */
-extern int GifLastError(void);
/******************************************************************************
- * O.K., here are the routines from GIF_LIB file DEV2GIF.C.
+ Color map handling from gif_alloc.c
******************************************************************************/
-extern int DumpScreen2Gif(const char *FileName,
- int ReqGraphDriver,
- long ReqGraphMode1,
- long ReqGraphMode2,
- long ReqGraphMode3);
-/*****************************************************************************
- *
- * Everything below this point is new after version 1.2, supporting `slurp
- * mode' for doing I/O in two big belts with all the image-bashing in core.
- *
- *****************************************************************************/
-
-/******************************************************************************
- * Color Map handling from ALLOCGIF.C
- *****************************************************************************/
-
-extern ColorMapObject *MakeMapObject(int ColorCount,
- const GifColorType * ColorMap);
-extern void FreeMapObject(ColorMapObject * Object);
-extern ColorMapObject *UnionColorMap(const ColorMapObject * ColorIn1,
- const ColorMapObject * ColorIn2,
+extern ColorMapObject *GifMakeMapObject(int ColorCount,
+ const GifColorType *ColorMap);
+extern void GifFreeMapObject(ColorMapObject *Object);
+extern ColorMapObject *GifUnionColorMap(const ColorMapObject *ColorIn1,
+ const ColorMapObject *ColorIn2,
GifPixelType ColorTransIn2[]);
-extern int BitSize(int n);
+extern int GifBitSize(int n);
/******************************************************************************
- * Support for the in-core structures allocation (slurp mode).
- *****************************************************************************/
+ Support for the in-core structures allocation (slurp mode).
+******************************************************************************/
-/* This is the in-core version of an extension record */
-typedef struct {
- int ByteCount;
- char *Bytes; /* on malloc(3) heap */
- int Function; /* Holds the type of the Extension block. */
-} ExtensionBlock;
+extern void GifApplyTranslation(SavedImage *Image, GifPixelType Translation[]);
+extern int GifAddExtensionBlock(int *ExtensionBlock_Count,
+ ExtensionBlock **ExtensionBlocks,
+ int Function,
+ unsigned int Len, unsigned char ExtData[]);
+extern void GifFreeExtensions(int *ExtensionBlock_Count,
+ ExtensionBlock **ExtensionBlocks);
+extern SavedImage *GifMakeSavedImage(GifFileType *GifFile,
+ const SavedImage *CopyFrom);
+extern void GifFreeSavedImages(GifFileType *GifFile);
-/* This holds an image header, its unpacked raster bits, and extensions */
-typedef struct SavedImage {
- GifImageDesc ImageDesc;
- unsigned char *RasterBits; /* on malloc(3) heap */
- int Function; /* DEPRECATED: Use ExtensionBlocks[x].Function instead */
- int ExtensionBlockCount;
- ExtensionBlock *ExtensionBlocks; /* on malloc(3) heap */
-} SavedImage;
+/******************************************************************************
+ 5.x functions for GIF89 graphics control blocks
+******************************************************************************/
-extern void ApplyTranslation(SavedImage * Image, GifPixelType Translation[]);
-extern void MakeExtension(SavedImage * New, int Function);
-extern int AddExtensionBlock(SavedImage * New, int Len,
- unsigned char ExtData[]);
-extern void FreeExtension(SavedImage * Image);
-extern SavedImage *MakeSavedImage(GifFileType * GifFile,
- const SavedImage * CopyFrom);
-extern void FreeSavedImages(GifFileType * GifFile);
+int DGifExtensionToGCB(const size_t GifExtensionLength,
+ const GifByteType *GifExtension,
+ GraphicsControlBlock *GCB);
+size_t EGifGCBToExtension(const GraphicsControlBlock *GCB,
+ GifByteType *GifExtension);
-/******************************************************************************
- * The library's internal utility font
- *****************************************************************************/
-
-#define GIF_FONT_WIDTH 8
-#define GIF_FONT_HEIGHT 8
-extern unsigned char AsciiTable[][GIF_FONT_WIDTH];
-
-#ifdef _WIN32
- extern void DrawGifText(SavedImage * Image,
-#else
- extern void DrawGifText(SavedImage * Image,
-#endif
- const int x, const int y,
- const char *legend, const int color);
-
-extern void DrawBox(SavedImage * Image,
- const int x, const int y,
- const int w, const int d, const int color);
-
-void DrawRectangle(SavedImage * Image,
- const int x, const int y,
- const int w, const int d, const int color);
-
-extern void DrawBoxedText(SavedImage * Image,
- const int x, const int y,
- const char *legend,
- const int border, const int bg, const int fg);
+int DGifSavedExtensionToGCB(GifFileType *GifFile,
+ int ImageIndex,
+ GraphicsControlBlock *GCB);
+int EGifGCBToSavedExtension(const GraphicsControlBlock *GCB,
+ GifFileType *GifFile,
+ int ImageIndex);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _GIF_LIB_H */
+
+/* end */