Hi,
I am in the process of working on a new Amiga game, but I have the
graphics saved in .PNG format. I could convert them to the much
easier to decompress .IFF format, but .PNG image save many more
bytes (e.g image is 15KB saved as an .IFF vs. 9KB as a .PNG).
I have sucessfully decoded all the easy stuff, but am currently trying
to decode the IDAT chunk (where the image data is stored).
The format of the data is defined as follows (straight out of the RFC1951
Deflate Compression document available online):
??? 5 Bits: HLIT, # of Literal/Length codes - 257 (257 - 286)
??? 5 Bits: HDIST, # of Distance codes - 1 (1 - 32)
??? 4 Bits: HCLEN, # of Code Length codes - 4 (4 - 19)
??? (HCLEN + 4) x 3 bits: code lengths for the code length
??? alphabet given just above, in the order: 16, 17, 18,
??? 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
??? These code lengths are interpreted as 3-bit integers
??? (0-7); as above, a code length of 0 means the
??? corresponding symbol (literal/length or distance code
??? length) is not used.
??? HLIT + 257 code lengths for the literal/length alphabet,
??? encoded using the code length Huffman code
??? HDIST + 1 code lengths for the distance alphabet,
??? encoded using the code length Huffman code
??? The actual compressed data of the block,
??? encoded using the literal/length and distance Huffman
??? codes
??? The literal/length symbol 256 (end of data),
??? encoded using the literal/length Huffman code.
All the documents I found online either say use the zlib library or point to
the RFC1951 document :(
Does anyone know how to decode the literal / length (HLIT) and distance
codes (HDIST)?
Huffman compression was always something I found hard, but it seemed
much easier after finding this page online:
http://www.cs.duke.edu/csed/poop/huff/info/
Regards,
Andrew B
aliensrcooluk at yahoo.co.uk