Archived

This topic is now archived and is closed to further replies.

PNG Decoding Question

This topic is 5375 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Does anybody know the correct way to read in bit strings from a PNG file? I can sucessfully read in chunks - I run into difficulty when decompressing in the compressed data blocks. The specification says Huffman codes are packed starting with the most-significant bit of the code. All other data elements are packed beginning with their least-significant bit. This explanation, however, can mean many different things... Question 1 - does this mean: A) I should read bits from each packed byte from lsb to msb and reverse the bits for Huffman codes, or B) I should read bits from each packed byte from msb to lsb and reverse the bits for data elements (non-Huffman codes)? Example: if the next 2 bytes in a data block "11011101 00000110" contain two consecutive Huffman codes of length 6 each, do I read A) HC1 = first 6 bits from byte 1 reversed = reverse of 011101 = 101110 = 32+8+4+2 = 46 HC2 = last 2 bits from byte 1 and first 4 bits from byte 2 reversed = reverse of 011011 = 110110 = 32+16+4+2 = 54 B) HC1 = most significant 6 bits from byte 1 = 110111 = 32+16+4+2+1 = 55 HC2 = last 2 bits from byte 1 and 4 most sig bits from byte 2 = 010000 = 16 Question 2 - Is the data block header: A) Organized with BFINAL (1 bit - final block indicator) and BTYPE (2 bits - compression type) preceding the bits that follow, or B) Organized with BFINAL and BTYPE always located at the 3 least-significant bits of the first byte of the data block? Example: Given the first byte of the next data block is "11011010" do I read A) BFINAL = 1 (TRUE) (bit 7) BTYPE = 10 (Dynamic Huffman coded) (bits 5 & 6) bits 0 - 4 and the remaining bytes of this block are in the dynamic format (HLIT, HDIST, etc..) B) BFINAL = 0 (FALSE) (bit 0) BTYPE = 01 (Fixed Huffman coded) (bits 1 & 2) bits 3 - 7 and the remaining bytes of this block are in the fixed format (fixed huffman-coded lz77 codes) Question 3 - Are the Huffman code length codes and the length/literal and distance tables: A) packed in msb to lsb order as well as the Huffman-coded lz77 compressed data in the dynamic Huffman compresed data blocks? B) Or are they packed in lsb to msb order, just the Huffman-coded lz77 compressed data is in msb to lsb order? I have tried a few of these variations with no success. Please help before I lose my mind!!! Thanks. [edited by - BrianMJC on March 25, 2003 6:22:04 PM]

Share this post


Link to post
Share on other sites