1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.  Oracle designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * by Oracle in the LICENSE file that accompanied this code.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /******************************************************************************
  26  * In order to make life a little bit easier when using the GIF file format,
  27  * this library was written, and which does all the dirty work...
  28  *
  29  *                                        Written by Gershon Elber,  Jun. 1989
  30  *                                        Hacks by Eric S. Raymond,  Sep. 1992
  31  ******************************************************************************
  32  * History:
  33  * 14 Jun 89 - Version 1.0 by Gershon Elber.
  34  *  3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names)
  35  * 15 Sep 90 - Version 2.0 by Eric S. Raymond (Changes to suoport GIF slurp)
  36  * 26 Jun 96 - Version 3.0 by Eric S. Raymond (Full GIF89 support)
  37  * 17 Dec 98 - Version 4.0 by Toshio Kuratomi (Fix extension writing code)
  38  *****************************************************************************/
  39 
  40 /* all encoding functionality stripped */
  41 
  42 #ifndef _GIF_LIB_H_
  43 #define _GIF_LIB_H_ 1
  44 
  45 #ifdef __cplusplus
  46 extern "C" {
  47 #endif /* __cplusplus */
  48 
  49 #define GIF_LIB_VERSION " Version 4.1, "
  50 
  51 #define GIF_ERROR   0
  52 #define GIF_OK      1
  53 
  54 #ifndef TRUE
  55 #define TRUE        1
  56 #endif /* TRUE */
  57 #ifndef FALSE
  58 #define FALSE       0
  59 #endif /* FALSE */
  60 
  61 #ifndef NULL
  62 #define NULL        0
  63 #endif /* NULL */
  64 
  65 #define GIF_STAMP "GIFVER"          /* First chars in file - GIF stamp.  */
  66 #define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1
  67 #define GIF_VERSION_POS 3           /* Version first character in stamp. */
  68 #define GIF87_STAMP "GIF87a"        /* First chars in file - GIF stamp.  */
  69 #define GIF89_STAMP "GIF89a"        /* First chars in file - GIF stamp.  */
  70 
  71 #define GIF_FILE_BUFFER_SIZE 16384  /* Files uses bigger buffers than usual. */
  72 
  73 typedef int GifBooleanType;
  74 typedef unsigned char GifPixelType;
  75 typedef unsigned char *GifRowType;
  76 typedef unsigned char GifByteType;
  77 
  78 #define GIF_MESSAGE(Msg) fprintf(stderr, "\n%s: %s\n", PROGRAM_NAME, Msg)
  79 #define GIF_EXIT(Msg)    { GIF_MESSAGE(Msg); exit(-3); }
  80 
  81 #ifdef SYSV
  82 #define VoidPtr char *
  83 #else
  84 #define VoidPtr void *
  85 #endif /* SYSV */
  86 
  87 typedef struct GifColorType {
  88     GifByteType Red, Green, Blue;
  89 } GifColorType;
  90 
  91 typedef struct ColorMapObject {
  92     int ColorCount;
  93     int BitsPerPixel;
  94     GifColorType *Colors;    /* on malloc(3) heap */
  95 } ColorMapObject;
  96 
  97 typedef struct GifImageDesc {
  98     int Left, Top, Width, Height,   /* Current image dimensions. */
  99       Interlace;                    /* Sequential/Interlaced lines. */
 100     ColorMapObject *ColorMap;       /* The local color map */
 101 } GifImageDesc;
 102 
 103 typedef struct GifFileType {
 104     int SWidth, SHeight,        /* Screen dimensions. */
 105       SColorResolution,         /* How many colors can we generate? */
 106       SBackGroundColor;         /* I hope you understand this one... */
 107     ColorMapObject *SColorMap;  /* NULL if not exists. */
 108     int ImageCount;             /* Number of current image */
 109     GifImageDesc Image;         /* Block describing current image */
 110     struct SavedImage *SavedImages; /* Use this to accumulate file state */
 111     VoidPtr UserData;           /* hook to attach user data (TVT) */
 112     VoidPtr Private;            /* Don't mess with this! */
 113 } GifFileType;
 114 
 115 typedef enum {
 116     UNDEFINED_RECORD_TYPE,
 117     SCREEN_DESC_RECORD_TYPE,
 118     IMAGE_DESC_RECORD_TYPE, /* Begin with ',' */
 119     EXTENSION_RECORD_TYPE,  /* Begin with '!' */
 120     TERMINATE_RECORD_TYPE   /* Begin with ';' */
 121 } GifRecordType;
 122 
 123 /* DumpScreen2Gif routine constants identify type of window/screen to dump.
 124  * Note all values below 1000 are reserved for the IBMPC different display
 125  * devices (it has many!) and are compatible with the numbering TC2.0
 126  * (Turbo C 2.0 compiler for IBM PC) gives to these devices.
 127  */
 128 typedef enum {
 129     GIF_DUMP_SGI_WINDOW = 1000,
 130     GIF_DUMP_X_WINDOW = 1001
 131 } GifScreenDumpType;
 132 
 133 /* func type to read gif data from arbitrary sources (TVT) */
 134 typedef int (*InputFunc) (GifFileType *, GifByteType *, int);
 135 
 136 /* func type to write gif data ro arbitrary targets.
 137  * Returns count of bytes written. (MRB)
 138  */
 139 typedef int (*OutputFunc) (GifFileType *, const GifByteType *, int);
 140 
 141 /******************************************************************************
 142  *  GIF89 extension function codes
 143 ******************************************************************************/
 144 
 145 #define COMMENT_EXT_FUNC_CODE     0xfe    /* comment */
 146 #define GRAPHICS_EXT_FUNC_CODE    0xf9    /* graphics control */
 147 #define PLAINTEXT_EXT_FUNC_CODE   0x01    /* plaintext */
 148 #define APPLICATION_EXT_FUNC_CODE 0xff    /* application block */
 149 
 150 /******************************************************************************
 151  * O.K., here are the routines one can access in order to decode GIF file:
 152  * (GIF_LIB file DGIF_LIB.C).
 153  *****************************************************************************/
 154 
 155 GifFileType *DGifOpenFileName(const char *GifFileName);
 156 GifFileType *DGifOpenFileHandle(int GifFileHandle);
 157 GifFileType *DGifOpen(void *userPtr, InputFunc readFunc);    /* new one
 158                                                              * (TVT) */
 159 int DGifSlurp(GifFileType * GifFile);
 160 int DGifGetScreenDesc(GifFileType * GifFile);
 161 int DGifGetRecordType(GifFileType * GifFile, GifRecordType * GifType);
 162 int DGifGetImageDesc(GifFileType * GifFile);
 163 int DGifGetLine(GifFileType * GifFile, GifPixelType * GifLine, int GifLineLen);
 164 int DGifGetPixel(GifFileType * GifFile, GifPixelType GifPixel);
 165 int DGifGetComment(GifFileType * GifFile, char *GifComment);
 166 int DGifGetExtension(GifFileType * GifFile, int *GifExtCode,
 167                      GifByteType ** GifExtension);
 168 int DGifGetExtensionNext(GifFileType * GifFile, GifByteType ** GifExtension);
 169 int DGifGetCode(GifFileType * GifFile, int *GifCodeSize,
 170                 GifByteType ** GifCodeBlock);
 171 int DGifGetCodeNext(GifFileType * GifFile, GifByteType ** GifCodeBlock);
 172 int DGifGetLZCodes(GifFileType * GifFile, int *GifCode);
 173 int DGifCloseFile(GifFileType * GifFile);
 174 
 175 #define D_GIF_ERR_OPEN_FAILED    101    /* And DGif possible errors. */
 176 #define D_GIF_ERR_READ_FAILED    102
 177 #define D_GIF_ERR_NOT_GIF_FILE   103
 178 #define D_GIF_ERR_NO_SCRN_DSCR   104
 179 #define D_GIF_ERR_NO_IMAG_DSCR   105
 180 #define D_GIF_ERR_NO_COLOR_MAP   106
 181 #define D_GIF_ERR_WRONG_RECORD   107
 182 #define D_GIF_ERR_DATA_TOO_BIG   108
 183 #define D_GIF_ERR_NOT_ENOUGH_MEM 109
 184 #define D_GIF_ERR_CLOSE_FAILED   110
 185 #define D_GIF_ERR_NOT_READABLE   111
 186 #define D_GIF_ERR_IMAGE_DEFECT   112
 187 #define D_GIF_ERR_EOF_TOO_SOON   113
 188 
 189 
 190 /******************************************************************************
 191  * O.K., here are the routines from GIF_LIB file GIF_ERR.C.
 192 ******************************************************************************/
 193 extern void PrintGifError(void);
 194 extern int GifLastError(void);
 195 
 196 /******************************************************************************
 197  * O.K., here are the routines from GIF_LIB file DEV2GIF.C.
 198 ******************************************************************************/
 199 extern int DumpScreen2Gif(const char *FileName,
 200                           int ReqGraphDriver,
 201                           long ReqGraphMode1,
 202                           long ReqGraphMode2,
 203                           long ReqGraphMode3);
 204 
 205 /*****************************************************************************
 206  *
 207  * Everything below this point is new after version 1.2, supporting `slurp
 208  * mode' for doing I/O in two big belts with all the image-bashing in core.
 209  *
 210  *****************************************************************************/
 211 
 212 /******************************************************************************
 213  * Color Map handling from ALLOCGIF.C
 214  *****************************************************************************/
 215 
 216 extern ColorMapObject *MakeMapObject(int ColorCount,
 217                                      const GifColorType * ColorMap);
 218 extern void FreeMapObject(ColorMapObject * Object);
 219 extern int BitSize(int n);
 220 
 221 /******************************************************************************
 222  * Support for the in-core structures allocation (slurp mode).
 223  *****************************************************************************/
 224 
 225 /* This is the in-core version of an extension record */
 226 typedef struct {
 227     int ByteCount;
 228     char *Bytes;    /* on malloc(3) heap */
 229     int Function;   /* Holds the type of the Extension block. */
 230 } ExtensionBlock;
 231 
 232 /* This holds an image header, its unpacked raster bits, and extensions */
 233 typedef struct SavedImage {
 234     GifImageDesc ImageDesc;
 235     unsigned char *RasterBits;  /* on malloc(3) heap */
 236     int Function;   /* DEPRECATED: Use ExtensionBlocks[x].Function instead */
 237     int ExtensionBlockCount;
 238     ExtensionBlock *ExtensionBlocks;    /* on malloc(3) heap */
 239 } SavedImage;
 240 
 241 extern void MakeExtension(SavedImage * New, int Function);
 242 extern int AddExtensionBlock(SavedImage * New, int Len,
 243                              unsigned char ExtData[]);
 244 extern void FreeExtension(SavedImage * Image);
 245 extern SavedImage *MakeSavedImage(GifFileType * GifFile,
 246                                   const SavedImage * CopyFrom);
 247 extern void FreeSavedImages(GifFileType * GifFile);
 248 
 249 
 250 #ifdef __cplusplus
 251 }
 252 #endif /* __cplusplus */
 253 #endif /* _GIF_LIB_H */