【问题标题】:Dynamic Huffman: Bit Packing Clarity动态霍夫曼:位打包清晰度
【发布时间】:2020-06-08 17:15:01
【问题描述】:

我只是想知道是否有任何动态霍夫曼位打包的好例子。我不太了解有关位打包的 RFC 材料。我在 Stack Overflow 中找到了很多很好的静态霍夫曼示例,但似乎缺少动态示例。

在 RFC 1951 第 3.1.1 节中

             * Data elements are packed into bytes in order of
               increasing bit number within the byte, i.e., starting
               with the least-significant bit of the byte.
             * Data elements other than Huffman codes are packed
               starting with the least-significant bit of the data
               element.
             * Huffman codes are packed starting with the most-
               significant bit of the code.

我对@9​​87654322@ 和Data Elements other than Huffman Codes. 之间的数据打包反转感到困惑什么构成Huffman CodesData Elements other than Huffman Codescodelengths, hlit, hclen, hdist, actual compressed data 属于哪个组?谢谢。

【问题讨论】:

    标签: compression gzip zlib deflate inflate


    【解决方案1】:

    这只是我对https://www.rfc-editor.org/rfc/rfc1951 的解释。 按照我的理解,第一个要点描述了位缓冲区输出;位缓冲区被清空到位流中的方式。第二个和第三个处理位与缓冲区输入。

    示例:5 位数据元素 11110 后跟一个 4 位霍夫曼代码 0001

    存储在位缓冲区中: 01111 0001

    存储在反向位缓冲区中(这更有意义): 1000 11110

    打包成字节: 00011110 xxxxxxx1

    编辑:如果这是不清楚的部分,“霍夫曼代码”在 CS 中具有特殊含义,指的是/可以从树中读取的实际代码。任何其他名为 Huffman 的内容,例如“Huffman 代码长度”都是元数据而不是代码。

    显然,这种打包位的顺序是为了使用逻辑和移位操作进行最简单的解码。元数据以正确的位顺序进行消费。霍夫曼码是相反的。这样就可以在构成代码的所有位都进入位缓冲区之前开始解码。

    【讨论】:

      【解决方案2】:

      压缩数据中的文字/长度和距离代码以及动态标头中的代码长度代码都是霍夫曼代码并且被反转(代码的最高有效位进入正在组装的当前字节的最低有效未使用位,等等)。这三个都是deflate格式的霍夫曼代码。格式中的所有其他内容,包括其中一些代码后面的额外位,都按其自然顺序打包(最低有效位进入下一个最低有效未使用位)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-23
        • 1970-01-01
        • 1970-01-01
        • 2018-04-19
        • 2010-10-17
        相关资源
        最近更新 更多