I'm writing my own image file loader as a personal exercise. I managed bitmap and targa just fine. I've moved onto png. I'm having a bit of trouble with the deflate compression. I've read through the spec( http://www.ietf.org/rfc/rfc1951.txt ). I understand the concepts involved but having a bit of trouble implementing them. I'll go through the steps I'm using to decode a test image and if someone could point out where I'm going wrong that would be great.
I created a test image (4x4px, solid (255,192,64). The compressed result in the IDAT chunk is ( xÚbüßàÀ..L.H.7....ÿÿ..Y..Çr.è3 )
Starting the parsing...
Bytes 0 and 1 are xÚ ( 0x78 and 0xDA ) which is the zlib info and exactly what they should be.
We move onto the actual image data.
Bytes 2 and 3 are bü ( 0x62 and 0xFC )
Deflate encodes using bits so the binary for those bytes are 0110 0010 1111 1100
The first bit ( 8th character) is 0 so that means this is not the final block. The next two bits ( 6th and 7th characters) are 01. That means that it uses fixed huffman code tree.
Read the first code. Start with 7bits as that is the smallest code in the fixed tree. 0001100 . Huffman codes are stored in reverse order so that becomes 0011000. That code is not in the fixed tree so we add one more bit. 00110001. That one is in the tree. The lit value is 1. My understanding is that anything less than 256 is the actual value. So the first byte of data for my image should be 1. Except there is no 1 value in the test image (should be 255). So either I'm getting off track somewhere or I misinterupting the output.
Any help is appreciated.