Reputation: 21
I have a JPEG file that contains more than one DHT marker. Is it allowed according to specification? If it is allowed, then which DHT marker should I use to define huffman table?
Upvotes: 0
Views: 1331
Reputation: 21627
Look at the definition of the DHT marker. It starts with a length for the marker. This is followed by 4-bit fields that identifies whether the table is an AC or DC table and a numeric identifier for the table. That is followed by the number of symbols in the table and then the symbols.
If you read the symbols and have not used up the length, you loop and read the next table in the same format. It is more common to put all the tables in one DHT marker but the choice is up to the encoder.
The Start of Frame marker maps the component to the Huffman table by number. Pick the tables specified by the SOF marker. For a color image, you could have to use as many as 6 Huffman tables to decode.
If the table is corrupt, the stream is corrupt and you are SOL.
Upvotes: 2