Decoding a JPEG Huffman block (table) Decoding a JPEG Huffman block (table) c c

Decoding a JPEG Huffman block (table)


The next 16 bytes after the 0x10 tell you how many codes of each length. In your example, there are 0 codes of length 1 bit, 1 code of length 2 bits, 2 codes of length 3 bits, 4 codes of length 4 bits, 3 codes of length 5 bits, and so on.

These are then followed by the values that are encoded by those codes, in order. Again from your example:

Code length | Number | Symbol(s)------------+--------+----------1 bit       | 0      |2 bits      | 1      | 0x013 bits      | 2      | 0x02 0x114 bits      | 4      | 0x00 0x03 0x04 0x215 bits      | 3      | 0x05 0x12 0x31... etc

You then build a binary tree from the top down, assigning the symbols in order. In this example, you get:

Symbol | Code -------+------0x01   | 000x02   | 0100x11   | 0110x00   | 10000x03   | 10010x04   | 10100x21   | 1011...etc