gif_lib.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 * In order to make life a little bit easier when using the GIF file format,   *
00003 * this library was written, and which does all the dirty work...              *
00004 *                                                                             *
00005 *                                        Written by Gershon Elber,  Jun. 1989 *
00006 *                                        Hacks by Eric S. Raymond,  Sep. 1992 *
00007 *******************************************************************************
00008 * History:                                                                    *
00009 * 14 Jun 89 - Version 1.0 by Gershon Elber.                                   *
00010 *  3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names)  *
00011 * 15 Sep 90 - Version 2.0 by Eric S. Raymond (Changes to suoport GIF slurp)   *
00012 * 26 Jun 96 - Version 3.0 by Eric S. Raymond (Full GIF89 support)             * 
00013 * 17 Dec 98 - Version 4.0 by Toshio Kuratomi (Fix extension writing code)     *
00014 ******************************************************************************/
00015 
00016 #ifndef _GIF_LIB_H
00017 #define _GIF_LIB_H
00018 
00019 #define GIF_LIB_VERSION " Version 4.0, "
00020 
00021 #define GIF_ERROR       0
00022 #define GIF_OK          1
00023 
00024 #ifndef TRUE
00025 #define TRUE            1
00026 #define FALSE           0
00027 #endif
00028 
00029 #ifndef NULL
00030 #define NULL            0
00031 #endif /* NULL */
00032 
00033 #define GIF_STAMP "GIFVER"          /* First chars in file - GIF stamp.  */
00034 #define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1
00035 #define GIF_VERSION_POS 3           /* Version first character in stamp. */
00036 #define GIF87_STAMP     "GIF87a"        /* First chars in file - GIF stamp.  */
00037 #define GIF89_STAMP     "GIF89a"        /* First chars in file - GIF stamp.  */
00038 
00039 #define GIF_FILE_BUFFER_SIZE 16384  /* Files uses bigger buffers than usual. */
00040 
00041 typedef int             GifBooleanType;
00042 typedef unsigned char   GifPixelType;
00043 typedef unsigned char * GifRowType;
00044 typedef unsigned char   GifByteType;
00045 
00046 #define GIF_MESSAGE(Msg) fprintf(stderr, "\n%s: %s\n", PROGRAM_NAME, Msg)
00047 #define GIF_EXIT(Msg)   { GIF_MESSAGE(Msg); exit(-3); }
00048 
00049 #ifdef SYSV
00050 #define VoidPtr char *
00051 #else
00052 #define VoidPtr void *
00053 #endif /* SYSV */
00054 
00055 typedef struct GifColorType {
00056     GifByteType Red, Green, Blue;
00057 } GifColorType;
00058 
00059 typedef struct ColorMapObject
00060 {
00061     int ColorCount;
00062     int BitsPerPixel;
00063     GifColorType *Colors;               /* on malloc(3) heap */
00064 }
00065 ColorMapObject;
00066 
00067 typedef struct GifImageDesc {
00068     int Left, Top, Width, Height,       /* Current image dimensions. */
00069         Interlace;                      /* Sequential/Interlaced lines. */
00070     ColorMapObject *ColorMap;           /* The local color map */
00071 } GifImageDesc;
00072 
00073 typedef struct GifFileType {
00074     int SWidth, SHeight,                /* Screen dimensions. */
00075         SColorResolution,               /* How many colors can we generate? */
00076         SBackGroundColor;               /* I hope you understand this one... */
00077     ColorMapObject *SColorMap;          /* NULL if not exists. */
00078     int ImageCount;                     /* Number of current image */
00079     GifImageDesc Image;                 /* Block describing current image */
00080     struct SavedImage *SavedImages;     /* Use this to accumulate file state */
00081     VoidPtr UserData;           /* hook to attach user data (TVT) */
00082     VoidPtr Private;                    /* Don't mess with this! */
00083 } GifFileType;
00084 
00085 typedef enum {
00086     UNDEFINED_RECORD_TYPE,
00087     SCREEN_DESC_RECORD_TYPE,
00088     IMAGE_DESC_RECORD_TYPE,             /* Begin with ',' */
00089     EXTENSION_RECORD_TYPE,              /* Begin with '!' */
00090     TERMINATE_RECORD_TYPE               /* Begin with ';' */
00091 } GifRecordType;
00092 
00093 /* DumpScreen2Gif routine constants identify type of window/screen to dump.  */
00094 /* Note all values below 1000 are reserved for the IBMPC different display   */
00095 /* devices (it has many!) and are compatible with the numbering TC2.0        */
00096 /* (Turbo C 2.0 compiler for IBM PC) gives to these devices.                 */
00097 typedef enum {
00098     GIF_DUMP_SGI_WINDOW = 1000,
00099     GIF_DUMP_X_WINDOW = 1001
00100 } GifScreenDumpType;
00101 
00102 /* func type to read gif data from arbitrary sources (TVT) */
00103 typedef int (*InputFunc)(GifFileType*,GifByteType*,int);
00104 
00105 /* func type to write gif data ro arbitrary targets.
00106  * Returns count of bytes written. (MRB)
00107  */
00108 typedef int (*OutputFunc)(GifFileType *, const GifByteType *, int);
00109 /******************************************************************************
00110 *  GIF89 extension function codes                                             *
00111 ******************************************************************************/
00112 
00113 #define COMMENT_EXT_FUNC_CODE           0xfe    /* comment */
00114 #define GRAPHICS_EXT_FUNC_CODE          0xf9    /* graphics control */
00115 #define PLAINTEXT_EXT_FUNC_CODE         0x01    /* plaintext */
00116 #define APPLICATION_EXT_FUNC_CODE       0xff    /* application block */
00117 
00118 /******************************************************************************
00119 * O.K., here are the routines one can access in order to encode GIF file:     *
00120 * (GIF_LIB file EGIF_LIB.C).                                                  *
00121 ******************************************************************************/
00122 
00123 GifFileType *EGifOpenFileName(const char *GifFileName, int GifTestExistance);
00124 GifFileType *EGifOpenFileHandle(int GifFileHandle);
00125 GifFileType *EgifOpen(void *userPtr, OutputFunc writeFunc);
00126 int EGifSpew(GifFileType *GifFile);
00127 void EGifSetGifVersion(const char *Version);
00128 int EGifPutScreenDesc(GifFileType *GifFile,
00129         int GifWidth, int GifHeight, int GifColorRes, int GifBackGround,
00130         const ColorMapObject *GifColorMap);
00131 int EGifPutImageDesc(GifFileType *GifFile,
00132         int GifLeft, int GifTop, int Width, int GifHeight, int GifInterlace,
00133         const ColorMapObject *GifColorMap);
00134 int EGifPutLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);
00135 int EGifPutPixel(GifFileType *GifFile, GifPixelType GifPixel);
00136 int EGifPutComment(GifFileType *GifFile, const char *GifComment);
00137 int EGifPutExtensionFirst(GifFileType *GifFile, int GifExtCode, int GifExtLen,
00138                            const VoidPtr GifExtension);
00139 int EGifPutExtensionNext(GifFileType *GifFile, int GifExtCode, int GifExtLen,
00140                            const VoidPtr GifExtension);
00141 int EGifPutExtensionLast(GifFileType *GifFile, int GifExtCode, int GifExtLen,
00142                            const VoidPtr GifExtension);
00143 int EGifPutExtension(GifFileType *GifFile, int GifExtCode, int GifExtLen,
00144                                                         const VoidPtr GifExtension);
00145 int EGifPutCode(GifFileType *GifFile, int GifCodeSize,
00146                                           const GifByteType *GifCodeBlock);
00147 int EGifPutCodeNext(GifFileType *GifFile, const GifByteType *GifCodeBlock);
00148 int EGifCloseFile(GifFileType *GifFile);
00149 
00150 #define E_GIF_ERR_OPEN_FAILED   1               /* And EGif possible errors. */
00151 #define E_GIF_ERR_WRITE_FAILED  2
00152 #define E_GIF_ERR_HAS_SCRN_DSCR 3
00153 #define E_GIF_ERR_HAS_IMAG_DSCR 4
00154 #define E_GIF_ERR_NO_COLOR_MAP  5
00155 #define E_GIF_ERR_DATA_TOO_BIG  6
00156 #define E_GIF_ERR_NOT_ENOUGH_MEM 7
00157 #define E_GIF_ERR_DISK_IS_FULL  8
00158 #define E_GIF_ERR_CLOSE_FAILED  9
00159 #define E_GIF_ERR_NOT_WRITEABLE 10
00160 
00161 /******************************************************************************
00162 * O.K., here are the routines one can access in order to decode GIF file:     *
00163 * (GIF_LIB file DGIF_LIB.C).                                                  *
00164 ******************************************************************************/
00165 
00166 GifFileType *DGifOpenFileName(const char *GifFileName);
00167 GifFileType *DGifOpenFileHandle(int GifFileHandle);
00168 GifFileType *DGifOpen( void* userPtr, InputFunc readFunc );  /* new one (TVT) */
00169 int DGifSlurp(GifFileType *GifFile);
00170 int DGifGetScreenDesc(GifFileType *GifFile);
00171 int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType);
00172 int DGifGetImageDesc(GifFileType *GifFile);
00173 int DGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);
00174 int DGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel);
00175 int DGifGetComment(GifFileType *GifFile, char *GifComment);
00176 int DGifGetExtension(GifFileType *GifFile, int *GifExtCode,
00177                                                 GifByteType **GifExtension);
00178 int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension);
00179 int DGifGetCode(GifFileType *GifFile, int *GifCodeSize,
00180                                                 GifByteType **GifCodeBlock);
00181 int DGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock);
00182 int DGifGetLZCodes(GifFileType *GifFile, int *GifCode);
00183 int DGifCloseFile(GifFileType *GifFile);
00184 
00185 #define D_GIF_ERR_OPEN_FAILED   101             /* And DGif possible errors. */
00186 #define D_GIF_ERR_READ_FAILED   102
00187 #define D_GIF_ERR_NOT_GIF_FILE  103
00188 #define D_GIF_ERR_NO_SCRN_DSCR  104
00189 #define D_GIF_ERR_NO_IMAG_DSCR  105
00190 #define D_GIF_ERR_NO_COLOR_MAP  106
00191 #define D_GIF_ERR_WRONG_RECORD  107
00192 #define D_GIF_ERR_DATA_TOO_BIG  108
00193 #define D_GIF_ERR_NOT_ENOUGH_MEM 109
00194 #define D_GIF_ERR_CLOSE_FAILED  110
00195 #define D_GIF_ERR_NOT_READABLE  111
00196 #define D_GIF_ERR_IMAGE_DEFECT  112
00197 #define D_GIF_ERR_EOF_TOO_SOON  113
00198 
00199 /******************************************************************************
00200 * O.K., here are the routines from GIF_LIB file QUANTIZE.C.                   *
00201 ******************************************************************************/
00202 int QuantizeBuffer(unsigned int Width, unsigned int Height, int *ColorMapSize,
00203         GifByteType *RedInput, GifByteType *GreenInput, GifByteType *BlueInput,
00204         GifByteType *OutputBuffer, GifColorType *OutputColorMap);
00205 
00206 
00207 /******************************************************************************
00208 * O.K., here are the routines from GIF_LIB file QPRINTF.C.                    *
00209 ******************************************************************************/
00210 extern int GifQuietPrint;
00211 
00212 #ifdef HAVE_VARARGS_H
00213 extern void GifQprintf();
00214 #else
00215 extern void GifQprintf(char *Format, ...);
00216 #endif /* HAVE_VARARGS_H */
00217 
00218 /******************************************************************************
00219 * O.K., here are the routines from GIF_LIB file GIF_ERR.C.                    *
00220 ******************************************************************************/
00221 extern void PrintGifError(void);
00222 extern int GifLastError(void);
00223 
00224 /******************************************************************************
00225 * O.K., here are the routines from GIF_LIB file DEV2GIF.C.                    *
00226 ******************************************************************************/
00227 extern int DumpScreen2Gif(const char *FileName,
00228                           int ReqGraphDriver,
00229                           int ReqGraphMode1,
00230                           int ReqGraphMode2,
00231                           int ReqGraphMode3);
00232 
00233 /*****************************************************************************
00234  *
00235  * Everything below this point is new after version 1.2, supporting `slurp
00236  * mode' for doing I/O in two big belts with all the image-bashing in core.
00237  *
00238  *****************************************************************************/
00239 
00240 /******************************************************************************
00241 * Color Map handling from ALLOCGIF.C                                          *
00242 ******************************************************************************/
00243 
00244 extern ColorMapObject *MakeMapObject(int ColorCount, const GifColorType *ColorMap);
00245 extern void FreeMapObject(ColorMapObject *Object);
00246 extern ColorMapObject *UnionColorMap(
00247                                 const ColorMapObject *ColorIn1,
00248                                 const ColorMapObject *ColorIn2,
00249                                 GifPixelType ColorTransIn2[]);
00250 extern int BitSize(int n);
00251 
00252 /******************************************************************************
00253 * Support for the in-core structures allocation (slurp mode).                 *
00254 ******************************************************************************/
00255 
00256 /* This is the in-core version of an extension record */
00257 typedef struct {
00258     int         ByteCount;
00259     char        *Bytes;         /* on malloc(3) heap */
00260     int Function;       /* Holds the type of the Extension block. */
00261 } ExtensionBlock;
00262 
00263 /* This holds an image header, its unpacked raster bits, and extensions */
00264 typedef struct SavedImage {
00265     GifImageDesc        ImageDesc;
00266 
00267     char                *RasterBits;            /* on malloc(3) heap */
00268 
00269     int                 Function; /* DEPRECATED: Use ExtensionBlocks[x].Function
00270                            * instead */
00271     int                 ExtensionBlockCount;
00272     ExtensionBlock      *ExtensionBlocks;       /* on malloc(3) heap */
00273 } SavedImage;
00274 
00275 extern void ApplyTranslation(SavedImage *Image, GifPixelType Translation[]);
00276 
00277 extern void MakeExtension(SavedImage *New, int Function);
00278 extern int AddExtensionBlock(SavedImage *New, int Len, char ExtData[]);
00279 extern void FreeExtension(SavedImage *Image);
00280 
00281 extern SavedImage *MakeSavedImage(GifFileType *GifFile, const SavedImage *CopyFrom);
00282 extern void FreeSavedImages(GifFileType *GifFile);
00283 
00284 /******************************************************************************
00285 * The library's internal utility font                                         *
00286 ******************************************************************************/
00287 
00288 #define GIF_FONT_WIDTH  8
00289 #define GIF_FONT_HEIGHT 8
00290 extern unsigned char AsciiTable[][GIF_FONT_WIDTH];
00291 
00292 extern void DrawText(SavedImage *Image,
00293                      const int x, const int y,
00294                      const char *legend,
00295                      const int color);
00296 
00297 extern void DrawBox(SavedImage *Image,
00298                      const int x, const int y,
00299                      const int w, const int d,
00300                      const int color);
00301 
00302 void DrawRectangle(SavedImage *Image,
00303                      const int x, const int y,
00304                      const int w, const int d,
00305                      const int color);
00306 
00307 extern void DrawBoxedText(SavedImage *Image,
00308                      const int x, const int y,
00309                      const char *legend,
00310                      const int border,
00311                      const int bg,
00312                      const int fg);
00313 
00314 #endif /* _GIF_LIB_H */

Generated on Tue Jul 5 14:13:32 2011 for ROOT_528-00b_version by  doxygen 1.5.1