I am currently implementing a png reader, but I am a confused about the bit order of the data and the format in general.
I don't have access to libpng, zlib or similar.
Please note that any bitstrings I write are most-significant bit first.
According to RFC1951, "Data elements are packed [...] starting with the least significant bit"
The first byte of my sample image is: 11101101
To read the header, I reverse the bit order and get: 10110111
The first bit is saying that this is last block, which makes sense. The next 2 bits are "01", does this mean static or dynamic huffman encoding? The RFC only mentions them as bits, but not in which order they are or their numerical value.
Assuming dynamic huffman encoding, the header is followed by the 2 huffman alphabets. These are, however, also encoded. 0-15 serve as literals, 16 repeats the code before by (3 + following 2 bits) times. Am I correct in assuming that 17 and 18 repeat the literal 0?
Further questions are:
- Did I understand all of this correctly?
- How do I know the alphabet encoding ends and the next starts?
- In which bit order are the alphabets and the actual compressed data in comparison to the header bits?
I think I don't understand most of chapter 3.2.7...