An efficient LZW implementation
Return to the main page.
6. Making a gif codec
The LZW compression used in the GIF format is dynamic LZW as described
here, with these details:
- There's a field in the GIF format header called "code size" which tells
the minimum bitsize for the dictionary. In other words, GIF always uses
a dictionary sized as a multiple of 2, up to 256 elements.
- The maximum bitsize is fixed to 12 (although in theory there shouldn't
be any reason why higher bitsizes couldn't be used...)
- The first index after the minimum dictionary size is a clear code.
When encoding, whenever you reset the dictionary you should write this
value to the output, and when decoding, you should reset the dictionary
when this value is read. (Theoretically there shouldn't be any need for
such code, but GIF uses it anyways.)
- The second index after the minimum dictionary size is an end-of-input
code.
Return to the main page.
Copyright 2007: Juha Nieminen