Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 解码JPEG哈夫曼块(表)_C_Compression_Jpeg_Huffman Code - Fatal编程技术网

C 解码JPEG哈夫曼块(表)

C 解码JPEG哈夫曼块(表),c,compression,jpeg,huffman-code,C,Compression,Jpeg,Huffman Code,以下块由Huffman块标记嵌套 -HUFF---------------------------------------------------------------------0084- 10 0 1 2 4 3 4 6 5 6 8 a 9 4 2 3 0 1 2 11 0 3 4 21 5 12 31 6 41 51 6

以下块由Huffman块标记嵌套

-HUFF---------------------------------------------------------------------0084-
  10    0    1    2    4    3    4    6    5    6    8    a    9    4    2    3
   0    1    2   11    0    3    4   21    5   12   31    6   41   51   61   13
  22   71   81   91   a1   14   32   b1   d1   f0   15   23   35   42   b2   c1
   7   16   24   33   52   72   73   e1   25   34   43   53   62   74   82   94
  a2   f1   26   44   54   63   64   92   93   c2   d2   55   56   84   b3   45
  83   46   a3   e2
-------------------------------------------------------------------------------
0084是表的整数长度,不包括在这里的块中

根据JPEG标准,第一个地址在目的地0(0x10)处单独成为AC表

从那以后,它就成了一张哈夫曼桌子


那么,它是如何解码的呢?

0x10之后的接下来16个字节告诉您每个长度有多少个代码。在您的示例中,有0个长度为1位的代码、1个长度为2位的代码、2个长度为3位的代码、4个长度为4位的代码、3个长度为5位的代码,依此类推

然后,这些值依次由这些代码编码。再次以您的示例为例:

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
然后自上而下构建一个二叉树,按顺序分配符号。在本例中,您可以得到:

Symbol | Code 
-------+------
0x01   | 00
0x02   | 010
0x11   | 011
0x00   | 1000
0x03   | 1001
0x04   | 1010
0x21   | 1011
...etc

这对我的理解有很大帮助:)编辑:重读答案,首先是代码长度,然后是代码字!(总是16个码字吗?),那我就知道问题的答案了!Thx——原始注释:如何从符号数量到实际符号。我如何知道一个2比特的符号是0x01,而不是0x00、0x10或0x11。。。