Back to index

wims  3.65+svn20090927
Functions | Variables
gifdecod.c File Reference
#include <stdio.h>
#include "whirlgif.h"

Go to the source code of this file.

Functions

void GifDecode (FILE *fp, UBYTE *pix, GifImageHdr gifimage)
UBYTEGifSendData (UBYTE *pix, int bytes, UBYTE source[])
void GifClearTable ()

Variables

unsigned int debugFlag
unsigned int verbose
int count
ULONG codeSize
ULONG expected
ULONG imgsize
ULONG mask
ULONG old
ULONG picI
ULONG rootCodeSize
ULONG first [MAXVAL]
UBYTEtopGifBuff
UBYTEpicture
UBYTE gifBuff [MAXVAL]
UBYTE last [MAXVAL]
int imgheight
int imgwidth
int interlaced
int pass
int step [5] = {7,7,3,1,0}
int start [5] = {0,4,2,1,0}

Function Documentation

void GifClearTable ( )

Definition at line 148 of file gifdecod.c.

{ int i, maxi;
  maxi = 1 << rootCodeSize;
  expected = maxi + 2;
  if (debugFlag > 1 ) fprintf(stderr, "Initing Table...");
  old = MAXVAL;
  codeSize = rootCodeSize + 1;
  mask = (1<<codeSize) - 1;

  for(i = 0; i < maxi; i++) {
    first[i] = MAXVAL;
    last[i] = i & 0xff;
  }
  topGifBuff = gifBuff;
}

Here is the caller graph for this function:

void GifDecode ( FILE *  fp,
UBYTE pix,
GifImageHdr  gifimage 
)

Definition at line 36 of file gifdecod.c.

{ UBYTE *chPos, firstCodeOut = 0, charBuff[256];
  ULONG CLEAR, EOI, bits = 0, code = 0, codeFeched, buffCount = 0;
  int need = 0;

  interlaced = gifimage.i;
  imgwidth = gifimage.width;
  imgheight = gifimage.height;
  imgsize = imgwidth * imgheight;
  picture = pix;
  pass = picI = 0;
  if ( debugFlag > 1 )
     fprintf(stderr, "(interlaced,imgwidth,imgheight,imgsize)=(%d,%d,%d,%d)\n",
              interlaced, imgwidth, imgheight, imgsize);

  rootCodeSize = Xgetc(fp);
  CLEAR = 1 << rootCodeSize;
  EOI = CLEAR + 1;

  GifClearTable();

  if ( (buffCount = Xgetc(fp)) == 0 ) {
    sprintf(charBuff, "End of image # %d before it began!\n", count);
    TheEnd1(charBuff);
  }

  while(buffCount > 0) {
    if ( fread(charBuff, 1, buffCount, fp) != buffCount ) { 
      sprintf(charBuff, "Premature end of file; Image # %d\n", count);
      TheEnd1(charBuff);
    }
    for(chPos = charBuff; buffCount-- > 0; chPos++) {
      need += (int) *chPos << bits;
      bits += 8;
      while (bits >= codeSize) {
       code = need & mask;
       need >>= codeSize;
       bits -= codeSize;
       if(code > expected)
          TheEnd1("Neither LZW nor RunLength (new code != expected)\n");
       if (code == EOI) {
         if (debugFlag > 1) fprintf(stderr, "Image # %d ends; buffCount=%d\n",
                     count, buffCount);
         goto skipRest;
       }

       if(code == CLEAR) {
       GifClearTable();
       continue;
       }
       if(old == MAXVAL) {  /* i.e. first code after clear table */
         pix = GifSendData(pix, 1, &last[code]);
         firstCodeOut = last[code];
         old = code;
         continue;
       }
       codeFeched = code;
       if(code == expected) {
         *topGifBuff++ = firstCodeOut;
         code = old;
       }
       while(code > CLEAR) {
         *topGifBuff++ = last[code];
         code = first[code];
       }

       *topGifBuff++ = firstCodeOut = last[code];
       first[expected] = old;
       last[expected] = firstCodeOut;
       if(expected < MAXVAL) expected++;
       if(((expected & mask) == 0) && (expected < MAXVAL)) {
         codeSize++;
         mask += expected;
       }
       old = codeFeched;
       pix = GifSendData(pix, topGifBuff - gifBuff, gifBuff);
       topGifBuff = gifBuff;

      }   /* end of extracting codes */
    }   /* end of reading a block of data */
    if ( (buffCount = Xgetc(fp)) == 0 ) {
      sprintf(charBuff, "End of image # %d without EOI\n", count);
      TheEnd1(charBuff);
    }
  }

skipRest: 
  if (debugFlag) fprintf(stderr, "Ending GifDecode, written: %d=%d\n",
         interlaced && (pix-picture == 0) ? imgsize : pix - picture, imgsize);
  return ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

UBYTE* GifSendData ( UBYTE pix,
int  bytes,
UBYTE  source[] 
)

Definition at line 128 of file gifdecod.c.

{ int j=0;
  for(j = bytes - 1; j >= 0; j--) {
    picI++;
    *pix = source[j]; pix++;
    if ( interlaced && (picI % imgwidth == 0) ) {
      picI += ( imgwidth * step[pass]);
      if (picI >= imgsize) {
       picI = start[++pass] * imgwidth;
       if ( debugFlag > 1 )
       fprintf(stderr, "De-interlacing: (picI,pass,start[pass])=(%d,%d,%d)\n",
                            picI, pass, start[pass]);
      }
      pix = &picture[picI];
    }
  }
  return(pix);
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 31 of file gifdecod.c.

int count

Definition at line 36 of file modstat.c.

unsigned int debugFlag

Definition at line 71 of file whirlgif.c.

Definition at line 31 of file gifdecod.c.

Definition at line 31 of file gifdecod.c.

Definition at line 32 of file gifdecod.c.

int imgheight

Definition at line 33 of file gifdecod.c.

Definition at line 31 of file gifdecod.c.

int imgwidth

Definition at line 33 of file gifdecod.c.

Definition at line 33 of file gifdecod.c.

Definition at line 32 of file gifdecod.c.

Definition at line 31 of file gifdecod.c.

Definition at line 31 of file gifdecod.c.

int pass

Definition at line 33 of file gifdecod.c.

Definition at line 31 of file gifdecod.c.

Definition at line 32 of file gifdecod.c.

Definition at line 31 of file gifdecod.c.

int start[5] = {0,4,2,1,0}

Definition at line 34 of file gifdecod.c.

int step[5] = {7,7,3,1,0}

Definition at line 34 of file gifdecod.c.

Definition at line 32 of file gifdecod.c.

unsigned int verbose