MrD
MrD

Reputation: 2481

Huffman Coding in JPEG

This is my JPEG picture hex content (I marked FFC4 marker on picture). As you can see, after the byte 0x01 there is value 0xA2! How that can be possible, because the standard says that the next 16 bytes after the 0x10 tell us how many codes of each length? It is impossible to have that number of codes with 1 bit. Am I wrong? JPEG hex content

Upvotes: 0

Views: 1794

Answers (1)

Jimmy
Jimmy

Reputation: 6171

What you are seeing is the length of the huffman block (in big endian order) in bytes (subtract 2 to include length of length field).

The huffman block is 0x1a2 bytes long. Following the length there is a single byte representing the huffman table information (table number and also whether or not the table is for AC or DC coefficients)

Start reading the length codes after the information value:

    Information Byte = 0x00    
    Number of length 1 codes = 0
    Number of length 2 codes = 0
    Number of length 3 codes = 7
    ...

Upvotes: 2

Related Questions