DLGIFImage.h

Go to the documentation of this file.
00001 #ifndef _DLGIFIMAGE_H_
00002 #define _DLGIFIMAGE_H_
00003 
00004 #include "DLImage.h" 
00005 #include "DLBaseImage.h"
00006 #include "DLBitsPerPixelConverter.h"
00007 #include "DLSingletonDestroyer.h"
00009 //All of the following 8 #defines should not be changed without changing the code
00010 static const char DLGIF_GLOBAL_HEADER[] = "GIF87a";
00011 static const int DLGIF_GLOBAL_COLOR_TABLE_SIZE = 0;        //never use global color table
00012 static const int DLGIF_GLOBAL_COLOR_TABLE_SORT_FLAG = 0;   //never use global color table
00013 static const int DLGIF_GLOBAL_COLOR_TABLE_FLAG = 0;        //never use global color table
00014 static const int DLGIF_BACKGROUND_COLOR = 0;               //no background, always draw with image
00015 static const int DLGIF_PIXEL_ASPECT_RATIO = 0;             //no aspect ratio 1x1
00016 
00017 static const int DLGIF_EXTRA_COLOR_ENTRY_RGB = 0;
00018 //The following #defines should not be changed without changing the code
00019 static const int DLGIF_DATA_WIDTH = 3;
00020 static const int DLGIF_FINISHED_PROCESSING = -8;
00027 template<class T >
00028 class DLGIFArray{
00029    private:
00033    void defaultConstruct(){
00034       size=0;
00035       array=NULL;
00036    };
00037    public:
00039    long size;
00041    T* array;
00042 
00046    DLGIFArray(){ defaultConstruct(); };
00051    DLGIFArray(const DLGIFArray<T>& dLGIFArray_in){
00052       defaultConstruct();
00053       reallocate(dLGIFArray_in.size);
00054       addDLGIFArray(dLGIFArray_in);
00055    };
00060    DLGIFArray(const long size_in){
00061       defaultConstruct();
00062       reallocate(size_in);
00063    };
00067    virtual ~DLGIFArray(void){
00068       if(array!=NULL){
00069          delete [] array;
00070          array = NULL;
00071       }
00072    };
00077    void reallocate(const long size_in){
00078       if(array!=NULL){
00079          delete [] array;
00080          array = NULL;
00081       }
00082       size=0;
00083       array=(T*) new T[size_in*sizeof (T)];
00084    };
00089    inline void add(const T& entry){
00090       array[size++]=entry;
00091    };
00096    inline void addDLGIFArray(const DLGIFArray<T>& dLGIFArray){
00097       addDLGIFArray(dLGIFArray,0,dLGIFArray.size);
00098    };
00105    inline void addDLGIFArray(const DLGIFArray<T>& dLGIFArray_in,const long &position,const long &size_in){
00106       memcpy(&array[size],&dLGIFArray_in.array[position],size_in*sizeof (T));
00107       size+=size_in;
00108    };
00112    inline void reset(){ size=0; };
00113 };//end class DLGIFArray
00114 
00122 class DLGIFImage : public DLBaseImage
00123 {
00124    template <class SINGLETON> friend class DLSingletonDestroyer;
00125 
00126    private:
00130    DLGIFImage(void);
00131    static DLGIFImage* gifImageReader;
00134    static DLSingletonDestroyer<DLGIFImage> _destroyer;
00135 
00136    protected:
00140    virtual ~DLGIFImage(void);
00141 
00142    public:
00143 
00145    static DLGIFImage * createImageReader();
00146 
00153    void dlLoadImage(const char* filename, DLImage& image);
00154 
00160    void dlConvertStructToDLImage(struct DLGifImageFormat *oimage, DLImage& dLImage);
00161 
00162 
00169    DLImage dlLoadImage(const void* pMemLoc, int nSize);
00170 
00176    DLImage dlLoadImage(const char* filename);
00177 
00185    DLImage dlLoadImageAtPage(const char* filename, int pageNumber);
00186 
00195    DLImage dlLoadImageAtPage(const void* pMemLoc, int nSize, int pageNumber);
00196 
00202    void dlSaveImage(const char* filename, const DLImage& image_in);
00203 
00211    void* dlSaveImageToMem( int& nSize, const DLImage& dlimage);
00212 
00219    bool dlSupportImageFile(const char* filename);
00220 
00229    bool dlSupportImageBuffer(const void* pMemLoc, int size);
00230 
00237    int dlGetTotalPages(void* pMemLoc, int nSize);
00238 
00244    int dlGetTotalPages(const char* filename);
00245 
00246    private:
00247 
00248    class DLLocalGIFImage;
00249    class DLGlobalGIFImage;
00250 
00255    class DLLocalGIFImage
00256       {
00260          friend class DLGlobalGIFImage;
00261          public:
00265          DLLocalGIFImage(){};
00269          virtual ~DLLocalGIFImage(void){};
00270 
00275          void set(const DLGlobalGIFImage* globalGIFImage_in);
00280          int getMinimumCodeSize(void) const {return minimumCodeSize;};
00285          DLGIFArray<DL_BYTE> getImageData() const;
00289          void initStaticData(void);
00290 
00291          private:
00295          void makeLocalImage(void);
00299          void buildHeader(void);
00303          void encodeData(void);
00304 
00305          int leftPosition;
00306          int topPosition;
00307          int width;
00308          int height;
00309 
00310          static int minimumCodeSize;
00311          static int clearCode;
00312          static int endCode;
00313          static int localColorTableSize;
00314 
00315          static const DL_BYTE *imagedata_24;
00316          static long global_numpics;
00317          static long global_total_size;
00318          static int global_width;
00319          static int global_height;
00320 
00321          DLGIFArray<DL_BYTE> header;
00322          DLGIFArray<long> colorTable;
00323          DLGIFArray<DL_BYTE> byteData;
00324          DLGIFArray<DL_BYTE> encodedData;
00325 
00326          //The following #defines should not be changed without changing the code
00327          static const int DLGIF_LOCAL_COLOR_TABLE_SORT_FLAG = 0; //do not sort local color table
00328          static const int DLGIF_INTERLACE_FLAG = 0;//do not interlace
00329          static const int DLGIF_LOCAL_COLOR_TABLE_FLAG = 1;//always use local color table
00330          static const int DLGIF_ENTRY_NOT_FOUND = -8;
00331 
00332          static const int DLGIF_MAX_COLOR_TABLE_SIZE=256;  // >0 and <=256
00333          static const int DLGIF_HASH_TABLE_SIZE=DLGIF_MAX_COLOR_TABLE_SIZE+8;
00334 
00335       };//end class DLLocalGIFImage
00336 
00341    class DLGlobalGIFImage
00342       {
00343          public:
00348          DLGlobalGIFImage(const DLImage* image);
00352          virtual ~DLGlobalGIFImage(void){};
00357          DLGIFArray<DL_BYTE> getGIFImageData(void);
00362          int getWidth() const {return width;};
00367          int getHeight()const {return height;};
00372          long getNumpics()const {return numpics;};
00377          long getTotalSize()const {return totalSize;};
00382          const DL_BYTE* getDLImageData() const {return globalDLImage->dlGetImageData();};
00383 
00384          private:
00388          void buildScreenDescriptor(void);
00389          const DLImage* globalDLImage;
00390          DLGIFArray<DL_BYTE> screenDescriptor;
00391          DLLocalGIFImage dLLocalGIFImage;
00392 
00393          bool quantized;
00394          int width;
00395          int height;
00396          long numpics;
00397          long totalSize;
00398          long currentPosition;
00399 
00400          int bitsPerPixel;  //minimum code size always equals this
00401 
00402          //All of the following 8 #defines should not be changed without changing the code
00403          static const int DLGIF_IMAGE_BLOCK_CODE =0x2C;
00404          static const int DLGIF_TERMINATOR_BLOCK_CODE = 0x3B;
00405 
00406       };//end class DLGlobalGIFImage
00407 };//end class DLGIFImage
00408 
00409 static DLGIFImage * dlGifProcessor = DLGIFImage::createImageReader();
00410 
00411 #endif //_DLGIFIMAGE_H_

DOCLIB is being developed under contract by a collaboration between:
The Laboratory for Language and Media Processing
Unviersity of Maryland, College Park
and
Booz | Allen | Hamilton

All Rights Reserved, 2003-2007