00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef INC_GIFUTIL
00022 #define INC_GIFUTIL
00023
00024 #include "ccfile.h"
00025 #include "dibconv.h"
00026 #include "dibutil.h"
00027
00028
00029 typedef struct tagGIFINFOHEADER
00030 {
00031 char giName[6];
00032 WORD giWidth;
00033 WORD giHeight;
00034 BYTE giFlags;
00035 BYTE giBackground;
00036 BYTE giAspect;
00037 } GIFINFOHEADER, FAR *LPGIFINFOHEADER;
00038
00039 typedef struct tagGIFIMAGEBLOCK
00040 {
00041 WORD gibLeft;
00042 WORD gibTop;
00043 WORD gibWidth;
00044 WORD gibDepth;
00045 BYTE gibFlags;
00046 } GIFIMAGEBLOCK, FAR *LPGIFIMAGEBLOCK;
00047
00048
00049 #define INTERLACE 0x40
00050 #define LOCALCOLOURMAP 0x80
00051 #define GLOBALCOLOURMAP 0x80
00052
00053
00054 #define EXTENSIONBLOCK 0x21
00055 #define TRANSPARENTBLOCK 0xf9
00056
00057 typedef struct tagGIFTRANSBLOCK
00058 {
00059 BYTE gtbBlockStart;
00060 BYTE gtbIdentifier;
00061 BYTE gtbBlockSize;
00062 BYTE gtbFlags;
00063 WORD gtbDelay;
00064 BYTE gtbTransparency;
00065 BYTE gtbTerminator;
00066 } GIFTRANSBLOCK, FAR *LPGIFTRANSBLOCK;
00067
00068 #define COMMENTBLOCK 0xfe
00069
00070 typedef struct tagGIFCOMMENTBLOCK
00071 {
00072 BYTE gcbBlockStart;
00073 BYTE gcbIdentifier;
00074 BYTE gcbTextSize;
00075 } GIFCOMMENTBLOCK, FAR *LPGIFCOMMENTBLOCK;
00076
00077 #define APPLICATIONBLOCK 0xff
00078
00079 typedef struct tagGIFAPPLICATIONBLOCK
00080 {
00081 BYTE gabBlockStart;
00082 BYTE gabIdentifier;
00083 BYTE gabBlockSize;
00084 CHAR gabString[8];
00085 BYTE gabAuthentication;
00086 } GIFAPPLICATIONBLOCK, FAR *LPGIFAPPLICATIONBLOCK;
00087
00088 #define PLAINTEXTBLOCK 0x01
00089
00090 typedef struct tagGIFRGBTRIPLE
00091 {
00092 BYTE grgbtRed;
00093 BYTE grgbtGreen;
00094 BYTE grgbtBlue;
00095 } GIFRGBTRIPLE, FAR *LPGIFRGBTRIPLE;
00096
00097
00098 const unsigned long masks[] = {
00099 0x0000, 0x0001, 0x0003, 0x0007, 0x000F,
00100 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF,
00101 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF,
00102 0x7FFF, 0xFFFF
00103 };
00104
00105
00106 #define GIFBITS 12
00107 #define MAX_LWZ_BITS 12
00108 #define HSIZE 5003 // 80% occupancy
00109
00110 typedef int code_int;
00111 typedef long int count_int;
00112
00113 const int maxbits = GIFBITS;
00114 const code_int maxmaxcode = (code_int)1 << GIFBITS;
00115
00116 const code_int hsize = HSIZE;
00117
00118 enum GIFDisposalMethod
00119 {
00120 GDM_NONE = 0,
00121 GDM_LEAVE = 1,
00122 GDM_BACKTOBACK = 2,
00123 GDM_PREVIOUS = 3
00124 };
00125
00126
00127
00128 class BaseCamelotFilter;
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 class PaletteIterator
00141 {
00142 public:
00143 PaletteIterator(): m_pPalette(NULL) {}
00144
00145 void SetRed(const UINT32 nRed)
00146 { m_pPalette->rgbRed = nRed; }
00147
00148 void SetGreen(const UINT32 nGreen)
00149 { m_pPalette->rgbGreen = nGreen; }
00150
00151 void SetBlue(const UINT32 nBlue)
00152 { m_pPalette->rgbBlue = nBlue; }
00153
00154 void SetTransparent(const UINT32 nTransparent)
00155 { m_pPalette->rgbReserved = nTransparent; }
00156
00157 BOOL operator< (const PaletteIterator& rhsIterator)
00158 { return m_pPalette < rhsIterator.m_pPalette; }
00159
00160 PaletteIterator& operator++()
00161 {
00162 ++m_pPalette;
00163 return *this;
00164 }
00165
00166 protected:
00167 LPRGBQUAD m_pPalette;
00168 };
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 class Palette : public CC_CLASS_MEMDUMP
00182 {
00183
00184 CC_DECLARE_MEMDUMP(Palette);
00185 public:
00186 Palette() : m_pColours(NULL), m_nSize(0) {}
00187 ~Palette();
00188
00189
00190
00191 BOOL SetSize(const UINT32 nSize);
00192
00193
00194 BOOL IsConstructedOK() const
00195 { return m_bInitOK; }
00196
00197
00198 const PaletteIterator& Start() const
00199 { return m_StartIterator; }
00200
00201 const PaletteIterator& End() const
00202 { return m_EndIterator; }
00203
00204 protected:
00205 Palette(const Palette& otherPalette);
00206
00207 protected:
00208 LPRGBQUAD m_pColours;
00209 UINT32 m_nSize;
00210
00211 PaletteIterator m_StartIterator;
00212 PaletteIterator m_EndIterator;
00213
00214 private:
00215 BOOL m_bInitOK;
00216 };
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 class GIFUtil
00231 {
00232 public:
00233
00234
00235
00236
00237 static BOOL ReadFromFile( CCLexFile *File, LPBITMAPINFO *Info, LPBYTE *Bits,
00238 int *TransColour, String_64 *ProgressString = NULL,
00239 BaseCamelotFilter *pFilter = NULL );
00240 static BOOL ReadFromFile( CCLexFile *File, LPBITMAPINFO *Info, LPBYTE *Bits,
00241 int *TransColour, int& nBitmapToRead, String_64 *ProgressString = NULL,
00242 BaseCamelotFilter *pFilter = NULL, UINT32* Delay=NULL,
00243 GIFDisposalMethod *Restore=NULL,
00244 UINT32 * pLeftOffset = NULL, UINT32* pTopOffset = NULL,
00245 BOOL * pLocalPalette = NULL);
00246
00247
00248
00249
00250 static UINT32 GetGlobalWidth() { return m_GlobalWidth; }
00251 static UINT32 GetGlobalHeight() { return m_GlobalHeight; }
00252
00253 protected:
00254 BOOL ProcessHeader();
00255 static BOOL ProcessExtension(CCLexFile *fd);
00256 static BOOL ProcessImageBlock(CCLexFile* File, LPBITMAPINFO *Info, LPBYTE *Bits,
00257 UINT32 * pLeftOffset = NULL, UINT32 * pTopOffset = NULL,
00258 BOOL * pLocalPalette = NULL);
00259
00260 static BOOL ReadColourMap(CCLexFile *fd, int number, LPRGBQUAD lpPalette);
00261 static int GetDataBlock( CCLexFile *fd, unsigned char *buf );
00262 static int GetCode( CCLexFile *fd, int code_size, int flag );
00263 static int LWZReadByte( CCLexFile *fd, int flag, int input_code_size );
00264 static BOOL ReadImage( CCLexFile *fd, LPBYTE pBitsData, int width, int height, int bpp,
00265 BOOL interlace, BaseCamelotFilter *pFilter = NULL );
00266
00267 private:
00268
00269
00270
00271 static WORD m_GlobalWidth;
00272 static WORD m_GlobalHeight;
00273
00274 static BOOL Interlace;
00275 static int Transparent;
00276 static UINT32 m_Delay;
00277 static GIFDisposalMethod m_Restore;
00278
00279 static int m_nCurrentBitmap;
00280
00281
00282
00283
00284
00285
00286 static BOOL ZeroDataBlock;
00287
00288 Palette m_GlobalPalette;
00289
00290
00291 static LPRGBQUAD lpGlobalPalette;
00292 static int GlobalPaletteSize;
00293
00294 static BOOL m_bImageRead;
00295
00296 static FilePos m_NextImageStartPosition;
00297 };
00298
00299 #endif // INC_GIFUTIL