Back to index

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