Back to index

wims  3.65+svn20090927
whirlgif.h
Go to the documentation of this file.
00001 /*
00002  * whirlgif.h
00003  *
00004  * Copyright (c) 1997,1998,1999 by Hans Dinsen-Hansen
00005  * Copyright (c) 1995,1996 by Kevin Kadow
00006  * Copyright (c) 1990,1991,1992 by Mark Podlipec.
00007  * All rights reserved.
00008  *
00009  * This software may be freely copied, modified and redistributed
00010  * without fee provided that this copyright notice is preserved
00011  * intact on all copies and modified copies.
00012  *
00013  * There is no warranty or other guarantee of fitness of this software.
00014  * It is provided solely "as is". The author(s) disclaim(s) all
00015  * responsibility and liability with respect to this software's usage
00016  * or its effect upon hardware or computer systems.
00017  *
00018  * The Graphics Interchange format (c) is the Copyright property of
00019  * Compuserve Incorporated.  Gif(sm) is a Service Mark property of
00020  * Compuserve Incorporated.
00021  *
00022  */
00023 
00024 #define DA_REV  3.04
00025 
00026 /* common includes */
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 
00030 #ifdef _USE_STRINGS_H
00031 #include <strings.h>
00032 #else
00033 #include <string.h>
00034 #endif
00035 
00036 #ifdef _FOPEN_TXT_OR_BIN
00037 #define WRIBIN       "wb"
00038 #define REATXT       "rt"
00039 #define REABIN       "rb"
00040 #else
00041 /* Usually there is no need to distinguish between binary and txt */
00042 #define WRIBIN       "w"
00043 #define REATXT       "r"
00044 #define REABIN       "r"
00045 #endif
00046 
00047 #ifndef TRUE
00048 #define TRUE 1
00049 #endif
00050 #ifndef FALSE
00051 #define FALSE 0
00052 #endif
00053 
00054 /* define constants and defaults */
00055     /* Default amount of inter-frame time */
00056 #define DEFAULT_TIME 10
00057     /* If set to 1, Netscape 'loop' code will be added by default */
00058 #define DEFAULT_LOOP 0
00059     /* If set to 1, use the colormaps from all images, not just the first */
00060 #define DEFAULT_USE_COLORMAP 0
00061 
00062     /* Used in calculating the transparent color */
00063 #define TRANS_NONE 1
00064 #define TRANS_RGB 2
00065 #define TRANS_MAP 3
00066 
00067 #define DISP_NONE 0
00068 #define DISP_NOT  1
00069 #define DISP_BACK 2
00070 #define DISP_PREV 3
00071 #define DEFAULT_DISPOSAL DISP_NONE
00072     /* set default disposal method here to any of the DISP_XXXX values */
00073 
00074 #define BIGSTRING 256
00075 #define MAXVAL  4096        /* maxval of lzw coding size */
00076 #define MAXVALP 4096
00077 #define TERMIN 'T'
00078 #define LOOKUP 'L'
00079 #define SEARCH 'S'
00080 #define noOfArrays 20
00081 /* defines the amount of memory set aside in the encoding for the
00082  * LOOKUP type nodes; for a 256 color GIF, the number of LOOKUP
00083  * nodes will be <= noOfArrays, for a 128 color GIF the number of
00084  * LOOKUP nodes will be <= 2 * noOfArrays, etc.  */
00085 
00086 /* define shorthand for various types */
00087 #define LONG int
00088 #define ULONG unsigned int
00089 #define BYTE char
00090 #define UBYTE unsigned char
00091 #define SHORT short
00092 #define USHORT unsigned short
00093 #define WORD short int
00094 #define UWORD unsigned short int
00095 
00096 
00097 /* definition of various structures */
00098 typedef struct Transparency {
00099   int type;
00100   UBYTE valid;
00101   UBYTE map;
00102   UBYTE red;
00103   UBYTE green;
00104   UBYTE blue;
00105   } Transparency;
00106 
00107 typedef struct Global {
00108   Transparency trans;
00109   int left;
00110   int top;
00111   unsigned int time;
00112   unsigned short disposal;
00113   } Global;
00114 
00115 typedef struct GifScreenHdr {
00116   int width;
00117   int height;
00118   UBYTE m;
00119   UBYTE cres;
00120   UBYTE pixbits;
00121   UBYTE bc;
00122   UBYTE aspect;
00123  } GifScreenHdr;
00124 
00125 typedef union GifColor {
00126   struct cmap {
00127     UBYTE red;
00128     UBYTE green;
00129     UBYTE blue;
00130     UBYTE pad;
00131    } cmap;
00132   ULONG pixel;
00133  } GifColor;
00134 
00135 typedef struct GifImageHdr {
00136   int left;
00137   int top;
00138   int width;
00139   int height;
00140   UBYTE m;
00141   UBYTE i;
00142   UBYTE pixbits;
00143   UBYTE reserved;
00144  } GifImageHdr;
00145 
00146 typedef struct GifTree {
00147   char typ;             /* terminating, lookup, or search */
00148   int code;             /* the code to be output */
00149   UBYTE ix;             /* the color map index */
00150   struct GifTree **node, *nxt, *alt;
00151 } GifTree;
00152 
00153 /* define inline functions */
00154 #define GifPutShort(i, fout)    {fputc(i&0xff, fout); fputc(i>>8, fout);}
00155 #define GifGetShort(fin)        (Xgetc(fin) | Xgetc(fin)<<8)
00156 
00157 /* forward declaration of the functions  */
00158 char *AddCodeToBuffer(int, short, char *);
00159 void CalcTrans(char *);
00160 void ClearTree(int, GifTree *);
00161 void GifClearTable();
00162 void GifComment(FILE *, char *);
00163 void GifDecode(FILE *, UBYTE *, GifImageHdr);
00164 void GifEncode(FILE *, UBYTE *, int, int);
00165 void GifLoop(FILE *, unsigned int);
00166 void GifReadFile(FILE *, char *, int);
00167 void GifScreenHeader(FILE *, FILE *, int);
00168 UBYTE *GifSendData(UBYTE *, int, UBYTE *);
00169 void ReadImageHeader(FILE *);
00170 void SetOffset(char *);
00171 long sq(UBYTE, UBYTE);
00172 void TheEnd();
00173 void TheEnd1(char *);
00174 void Usage();
00175 void WriteImageHeader(FILE *);
00176 UBYTE Xgetc(FILE *);