10 typedef unsigned char byte;
 
   12 static int      Prefix[TSIZE];          
 
   13 static byte     Suffix[TSIZE];          
 
   14 static byte     OutCode[TSIZE];         
 
   19 static int      CurCodeSize,            
 
   29   static long   b3[3], CurByte;
 
   39   CurBit += CurCodeSize;
 
   42   nbyte   = CurByte - OldByte;
 
   43   shift   = 17 + (CurBit%8) - CurCodeSize;
 
   47       if (lblk == 0) 
return -1;
 
   54   return (((b3[0]+0x100*b3[1]+0x10000*b3[2])>>shift) & (CurMaxCode-1));
 
   60 static void OutPixel(byte pix)
 
   80 int GIFinfo(byte *GIFarr, 
int *Width, 
int *Height, 
int *Ncols)
 
   88   if (strncmp((
char *)GIFarr,
"GIF87a",6) && strncmp((
char *)GIFarr,
"GIF89a",6))
 
   90     fprintf(stderr,
"\nGIFinfo: not a GIF\n");
 
  100   *Ncols    = 1 << ((b & 7) + 1);
 
  101   if ((b & 0x80) == 0) {                
 
  102     fprintf(stderr,
"\nGIFinfo: warning! no color map\n");
 
  109     fprintf(stderr,
"\nGIFdecode: bad screen descriptor\n");
 
  113   ptr1 += (*Ncols) * 3;                 
 
  117     fprintf(stderr,
"\nGIFinfo: no image separator\n");
 
  124   *Width  = b + 0x100*(*ptr1++);
 
  126   *Height = b + 0x100*(*ptr1++);
 
  149 int GIFdecode(byte *GIFarr, byte *PIXarr, 
int *Width, 
int *Height, 
int *Ncols, byte *R, byte *G, byte *B)
 
  174   if (strncmp((
char *)GIFarr,
"GIF87a",6) && strncmp((
char *)GIFarr,
"GIF89a",6))
 
  176     fprintf(stderr,
"\nGIFinfo: not a GIF\n");
 
  186   BitsPixel = (b & 7) + 1;              
 
  187   *Ncols    = 1 << BitsPixel;
 
  188   PixMask   = (*Ncols) - 1;             
 
  189   if ((b & 0x80) == 0) {                
 
  190     fprintf(stderr,
"\nGIFdecode: warning! no color map\n");
 
  197     fprintf(stderr,
"\nGIFdecode: bad screen descriptor\n");
 
  201   for (i=0; i<(*Ncols); i++) {          
 
  209     fprintf(stderr,
"\nGIFdecode: no image separator\n");
 
  216   *Width  = b + 0x100*(*ptr1++);
 
  218   *Height = b + 0x100*(*ptr1++);
 
  221   if ((b & 0xc0) != 0) {
 
  223             "\nGIFdecode: unexpected item (local colors or interlace)\n");
 
  227   IniCodeSize = *ptr1++;
 
  228   CurCodeSize = ++IniCodeSize;
 
  229   CurMaxCode  = (1 << IniCodeSize);
 
  230   ClearCode   = (1 << (IniCodeSize - 1));
 
  231   EOFCode     = ClearCode + 1;
 
  232   FreeCode    = ClearCode + 2;
 
  236   Npix     =(long) (*Width) * (*Height);
 
  239   CurCode  = ReadCode();
 
  243       fprintf(stderr,
"\nGIFdecode: corrupted GIF (zero block length)\n");
 
  247     if (CurCode == EOFCode) {
 
  248       fprintf(stderr,
"\nGIFdecode: corrupted GIF (unexpected EOF)\n");
 
  252     if (CurCode == ClearCode) {         
 
  254       CurCodeSize = IniCodeSize;
 
  255       CurMaxCode  = (1 << IniCodeSize);
 
  256       FreeCode    = ClearCode + 2;
 
  257       OldCode     = CurCode = ReadCode();
 
  265       if (CurCode >= FreeCode) {
 
  267         OutCode[OutCount++] = FinChar;
 
  269       while (CurCode > PixMask) {       
 
  270         if (OutCount >= TSIZE) {
 
  271           fprintf(stderr,
"\nGIFdecode: corrupted GIF (big output count)\n");
 
  274       OutCode[OutCount++] = Suffix[CurCode];
 
  275       CurCode = Prefix[CurCode];
 
  278       OutCode[OutCount++] = FinChar;
 
  280       for (i=OutCount-1; i>=0; i--) {   
 
  281         OutPixel(OutCode[i]);
 
  286       Prefix[FreeCode] = OldCode;       
 
  287       Suffix[FreeCode] = FinChar;
 
  291       if (FreeCode >= CurMaxCode) {
 
  292         if (CurCodeSize < BITS) {
 
  298     CurCode = ReadCode();