Decoding a JPEG Huffman block (table)

前端 未结 1 1635
南旧
南旧 2021-02-02 17:23

The following block is nested by Huffman block markers

-HUFF---------------------------------------------------------------------0084-
  10    0    1    2    4           


        
相关标签:
1条回答
  • 2021-02-02 17:54

    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      | 0x01
    3 bits      | 2      | 0x02 0x11
    4 bits      | 4      | 0x00 0x03 0x04 0x21
    5 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   | 00
    0x02   | 010
    0x11   | 011
    0x00   | 1000
    0x03   | 1001
    0x04   | 1010
    0x21   | 1011
    ...etc
    
    0 讨论(0)
提交回复
热议问题