[comp.graphics] GIF decoding info

dulimart@cpsvax.cps.msu.edu (Hansye S. Dulimarta) (07/10/89)

Hi folks, I need some help from you.
I'm writing a program for decoding a picture in GIF format and now I'm bumped
into the problem of "uncompressing" the LZW-coded raster data.
My problem is : I don't understand what I'm supposed to do when the <EOI>
code is read ? Should I re-initilize the string table as well, like when we
get the <CC> code ? Should I discard the rest of raster data ?

Any idea will be appreciated. THanks a lot.


Hans.

wiml@blake.acs.washington.edu (William Lewis) (07/10/89)

In article <3718@cps3xx.UUCP> dulimart@cpsvax.UUCP (Hansye S. Dulimarta) writes:
>My problem is : I don't understand what I'm supposed to do when the <EOI>
>code is read ? Should I re-initilize the string table as well, like when we

     In my copy of Compu$erve's .gif documentation, it states that "any
characters encountered between the end of a previous image and the image
separator character [which is a comma] are to be ignored."
  
  Obviously once you get the EOI code you're done with that image. It doesn't
really matter what you do with your string table at this point: if this
was the last image in the file (the usual case) you'll be deallocating the
whole thing anyway, and not using it any more. If there's another image,
it will probably start with a CC code (the standard suggests this..) and if
it doesn't, it should. Every image in a .gif file starts anew with respect
to the LZW tables.

    --- phelliax
        "Trust me, I Know"

dulimart@cpsvax.cps.msu.edu (Hansye S. Dulimarta) (07/10/89)

In article <2716@blake.acs.washington.edu> wiml@blake.acs.washington.edu (William Lewis) writes:
>In article <3718@cps3xx.UUCP> dulimart@cpsvax.UUCP (Hansye S. Dulimarta) writes:
>>My problem is : I don't understand what I'm supposed to do when the <EOI>
>>code is read ? Should I re-initilize the string table as well, like when we

>  Obviously once you get the EOI code you're done with that image. It doesn't
>really matter what you do with your string table at this point: if this
>was the last image in the file (the usual case) you'll be deallocating the
>whole thing anyway, and not using it any more. If there's another image,
>it will probably start with a CC code (the standard suggests this..) and if
>it doesn't, it should. Every image in a .gif file starts anew with respect
>to the LZW tables.
>
>    --- phelliax

Thank for your reply,

Unfortunately, I got the <EOI> when the image is not complete and at about the
end of the _first_ raster block (there are at least four raster blocks, I knwo
this because I develop my program in "debugging" mode by printing out 
information I got from the file).
You said that when I get the <EOI> code I'm done with the image. DO you mean
that I'm done with the current raster block or done with the entire image ?

I also follow the documentation which says that whenever the string table is
filled up I have to increase the "compression size" by one bit. When I do 
this, is it necessary to recalculate the <CC> and <EOI> code ?

wiml@blake.acs.washington.edu (William Lewis) (07/11/89)

In article <3726@cps3xx.UUCP> dulimart@cpsvax.UUCP (Hansye S. Dulimarta) writes:
>Unfortunately, I got the <EOI> when the image is not complete and at about the
>end of the _first_ raster block (there are at least four raster blocks, I knwo
>this because I develop my program in "debugging" mode by printing out 
>information I got from the file).
>You said that when I get the <EOI> code I'm done with the image. DO you mean
>that I'm done with the current raster block or done with the entire image ?

   I'm not sure we're using the same terminology. My .gif docs refer to
an "image" as a rectangualr block of pixels. A .gif file can contain
more than one image, though. (Most contain only one, I have found...) 
Is this what you mean by a "raster block"? If you stopped the program
at the end of the first raster block, would you have a square bitmap
onscreen, or an unfinished bitmap with a possibly incomplete line..?

   When you increase the compression size, the CC and EOI and such codes should
remain constant, because they are always the first empty values above the
"primitive" values... Consider the following string table:
  (Four-color image)

  Code    Value
   0       A
   1       B
   2       C
   3       D
   4       <CC>
   5       <EOI>
   6       (first LZW code, possibly CB)
   7       (next LZW code...)

  When you increase the code size, you do not alter the table in any way. You
merely output one more bit per code, because the code values are getting
large enough that it takes more bits to represent them. For a good discussion
on LZW coding in general, see ieee COMPUTER June 1984 (Vol. 17, Number 6)
"A Technique for High-Performance Data Compression", by Terry A. Welch.
(The name sound familiar? =8) =8) )

   --- phelliax
       "I'm not a GIF decoder, but I play one on Usenet"

>
>I also follow the documentation which says that whenever the string table is
>filled up I have to increase the "compression size" by one bit. When I do 
>this, is it necessary to recalculate the <CC> and <EOI> code ?