home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / 3DTOSHI2.ZIP / mpgfx / include / gfxgif.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-23  |  4.3 KB  |  193 lines

  1.  
  2. // gfxgif.h
  3. //
  4. // Copyright (c) 1995 by Toshiaki Tsuji, all rights reserved.
  5.  
  6. #ifndef __GFXGIFFILE_h__
  7. #define __GFXGIFFILE_h__
  8.  
  9. #include "stdgfx.h"
  10. #include "gfxifile.h"
  11.  
  12. #define scdGCT       0x80
  13. #define scdRES       0x70
  14. #define scdSORT      0x08
  15. #define scdSIZE      0x07
  16.  
  17. #define imdLCT       0x80
  18. #define imdINTERLACE 0x40
  19. #define imdSORT      0x20
  20. #define imdRESV      0x18
  21. #define imdSIZE      0x07
  22.  
  23. #define HASHSIZE  5011
  24. #define NULLCODE  -1
  25.  
  26. struct GIFHEADER
  27.   {
  28.     CHAR ID[3];
  29.     CHAR Version[3];
  30.   }; // End of GIFHEADER
  31.  
  32. struct GIFSCRDSC
  33.   {
  34.     SHORT Width;
  35.     SHORT Height;
  36.     BYTE  Flags;
  37.     BYTE  BGColor;
  38.     BYTE  AspectRatio;
  39.  
  40.     BOOLEAN IsGCT ()
  41.       {
  42.         if (Flags&scdGCT)
  43.           return TRUE;
  44.         return FALSE;
  45.       }; // End of IsGCT
  46.  
  47.     BOOLEAN IsSorted ()
  48.       {
  49.         if (Flags&scdSORT)
  50.           return TRUE;
  51.         return FALSE;
  52.       }; // End of IsSorted
  53.  
  54.     INT ColorDepth ()
  55.       {
  56.         INT Depth = Flags&scdRES;
  57.         return (Depth >> 4) + 1;
  58.       }; // End of ColorDepth
  59.  
  60.     INT NumColors ()
  61.       {
  62.         if (IsGCT())
  63.           return 1 << ((Flags&scdSIZE)+1);
  64.         return 0;
  65.       }; // End of NumColors
  66.   }; // End of GIFSCRDSC
  67.  
  68. struct GIFIMGDSC
  69.   {
  70.     BYTE  ID;
  71.     SHORT xLeft;
  72.     SHORT yLeft;
  73.     SHORT Width;
  74.     SHORT Height;
  75.     BYTE  Flags;
  76.  
  77.     BOOLEAN IsLCT ()
  78.       {
  79.         if (Flags&imdLCT)
  80.           return TRUE;
  81.         return FALSE;
  82.       };
  83.  
  84.     BOOLEAN IsSorted ()
  85.       {
  86.         if (Flags&imdSORT)
  87.           return TRUE;
  88.         return FALSE;
  89.       };
  90.  
  91.     BOOLEAN IsInterlaced ()
  92.       {
  93.         if (Flags&imdINTERLACE)
  94.           return TRUE;
  95.         return FALSE;
  96.       };
  97.  
  98.     INT NumColors ()
  99.       {
  100.         if (IsLCT ())
  101.           return 1 << ((Flags&imdSIZE)+1);
  102.         return 0;
  103.       };
  104.   }; // End of GIFIMGDSC
  105.  
  106. class GIFFILETOOL : public IMAGEFILETOOL
  107.   {
  108.     protected :
  109.       GIFHEADER GIFHeader;
  110.       GIFSCRDSC ScrDSC;
  111.       GIFIMGDSC ImgDSC;
  112.  
  113.       // Data for Decoding, Encoding
  114.       SHORT Capacity;
  115.       SHORT *CodeTable;
  116.       SHORT *Prefix;
  117.       SHORT *Suffix;
  118.  
  119.       SHORT *CodeStack;
  120.       SHORT StackPtr;
  121.  
  122.       SHORT CurBits,MinBits;
  123.       SHORT NextAvailCode,MaxCode;
  124.       SHORT CurCode;
  125.       SHORT PreCode;
  126.       SHORT FirstCh;
  127.  
  128.       SHORT RootSize;
  129.       SHORT ClearCode;
  130.       SHORT EndCode;
  131.  
  132.       SHORT NumBytes;
  133.       SHORT ByteCount;
  134.       SHORT CurByte;
  135.       SHORT CurByteMask;
  136.       BYTE  *DataBlock;
  137.       // End of Data for Decoding
  138.  
  139.       void DeInit ();
  140.  
  141.       // For LZW Decoding
  142.       BOOLEAN Decode ( IMAGE *Image );
  143.       BOOLEAN InitDecoding ();
  144.       BOOLEAN FindStr ( SHORT Code );
  145.       void ClearTable ();
  146.       INT GetCodeSize ();
  147.       BOOLEAN ReadRow ( IMAGE *Image, INT Row );
  148.       void PushCode ( SHORT Code );
  149.       SHORT PopCode ( );
  150.       SHORT GetCode ();
  151.       BYTE  GetByte ();
  152.       SHORT GetFirstCh ();
  153.       void AddNewString ( SHORT PreCode, SHORT NewCode );
  154.       // End of LZW Decoding
  155.  
  156.       // For LZW Encoding
  157.       void PutCode ( SHORT Code );
  158.       void AddNewString ( INT Pre, INT Cur, INT Index );
  159.       void FlushAll ();
  160.       void PutByte ();
  161.       BOOLEAN Encode ( IMAGE *Image, INT Sx, INT Sy, INT Wd, INT Ht );
  162.       BOOLEAN WriteRow ( IMAGE *Image, INT Row, INT Sx, INT Wd );
  163.       void InitTable ();
  164.       INT FindStr ( INT Pre, INT Cur );
  165.       BOOLEAN InitEncoding ();
  166.       void PutCodeSize ( BYTE CodeSize );
  167.       // End of LZW Encoding
  168.  
  169.       BOOLEAN ReadHeader ();
  170.       BOOLEAN ReadScrDSC ();
  171.       BOOLEAN ReadGCT ( RGBPALETTE *Pal );
  172.       BOOLEAN ReadImgDSC ();
  173.       BOOLEAN ReadLCT ( RGBPALETTE *Pal );
  174.       BOOLEAN ReadImage ( IMAGE *Image, RGBPALETTE *Pal );
  175.  
  176.       BOOLEAN WriteHeader ();
  177.       BOOLEAN WriteScrDSC ( INT Wd, INT Ht );
  178.       BOOLEAN WriteGCT ( RGBPALETTE *Pal );
  179.       BOOLEAN WriteImgDSC ( INT Wd, INT Ht );
  180.       BOOLEAN WriteImage ( IMAGE *Image, INT Sx, INT Sy, INT Wd, INT Ht );
  181.  
  182.     public :
  183.       GIFFILETOOL ( FILEHANDLE f );
  184.       virtual ~GIFFILETOOL ();
  185.  
  186.       virtual BOOLEAN LoadImage ( IMAGE *Image, RGBPALETTE *Pal );
  187.       virtual BOOLEAN SaveImage ( IMAGE *Image, LONG Sx, LONG Sy,
  188.                                   LONG Wd, LONG Ht, RGBPALETTE *Pal );
  189.   }; // End of GIFFILETOOL
  190.  
  191. #endif
  192.  
  193.