Orb/Doxygen/src/gifenc.h
changeset 0 42188c7ea2d9
equal deleted inserted replaced
-1:000000000000 0:42188c7ea2d9
       
     1 /******************************************************************************
       
     2  *
       
     3  * $Id$
       
     4  *
       
     5  *
       
     6  * Copyright (C) 1997-2009 by Dimitri van Heesch.
       
     7  *
       
     8  * Permission to use, copy, modify, and distribute this software and its
       
     9  * documentation under the terms of the GNU General Public License is hereby 
       
    10  * granted. No representations are made about the suitability of this software 
       
    11  * for any purpose. It is provided "as is" without express or implied warranty.
       
    12  * See the GNU General Public License for more details.
       
    13  *
       
    14  * All output generated with Doxygen is not covered by this license.
       
    15  *
       
    16  */
       
    17 
       
    18 #ifndef _GIFENC_H
       
    19 #define _GIFENC_H
       
    20 #include <qfile.h>
       
    21 
       
    22 typedef unsigned char  Byte;
       
    23 typedef unsigned short Word;
       
    24 
       
    25 struct Color
       
    26 {
       
    27   Byte red;
       
    28   Byte green;
       
    29   Byte blue;
       
    30 };
       
    31 
       
    32 const int hashTableSize=5003;     // size of the hash table 
       
    33 
       
    34 class GifEncoder
       
    35 {
       
    36   public:
       
    37     GifEncoder(Byte *rawBytes,Color *p,int w,int h,Byte d,int t);
       
    38    ~GifEncoder();
       
    39     void writeGIF(QFile &fp);
       
    40    
       
    41   protected:
       
    42     void putWord( Word w, QFile &fp );
       
    43     void putByte( Byte b, QFile &fp );
       
    44     void compress(int csize, QFile &fp);
       
    45     void writeCode(int code, QFile &fp);
       
    46     void writeChar( Byte c, QFile &fp );
       
    47     void writePacket(QFile &fp);
       
    48     void clearHashTable();
       
    49     int nextPixel()
       
    50     {
       
    51       if ( --numPixels < 0) return EOF;
       
    52       return *dataPtr++;
       
    53     }
       
    54 
       
    55     
       
    56   private:
       
    57     const int colorResolution;      // 8 bit for Red, Green and Blue;
       
    58     const int globalPaletteFlag;
       
    59     const int bits;
       
    60     const int maxMaxCode; 
       
    61 
       
    62     // image variables
       
    63     int width;             // image width 
       
    64     int height;            // image height 
       
    65     Byte depth;            // bits per CLUT entry 
       
    66     int transIndex;        // index of the transparant color; -1 = none 
       
    67     Color *palette;        // pointer to the color palette 
       
    68     int numPixels;         // total number of pixel (i.e. width * height)
       
    69     Byte *data;            // pointer to the image data (one byte per pixel) 
       
    70     Byte *dataPtr;         // pointer located at the current pixel.
       
    71     
       
    72     // compression variables
       
    73     bool clearFlag;        // clear hash table flag
       
    74     int  freeEntry;        // first free entry in the hash table
       
    75     unsigned int curAccum; // encoded bit accumulator
       
    76     int curBits;           // number of bits in curAccum
       
    77     Byte accum[256];       // Buffer for a packet
       
    78     int aCount;            // Number of characters so far in this 'packet'
       
    79     int nBits;             // number of bits/code
       
    80     int maxCode;           // maximum code, given n_bits
       
    81     int initBits;          // initial number of bits
       
    82     int EOFCode;           // code for signaling the end of the file
       
    83     int ClearCode;         // the clear code for the decompressor
       
    84     
       
    85     // tables
       
    86     int htab[hashTableSize];       // the hash table
       
    87     Word codetab[hashTableSize];   // the code table
       
    88 };
       
    89 
       
    90 #endif