【问题标题】:decompressor for deflate comprssed-data with fixed Huffman codes使用固定霍夫曼代码对压缩数据进行压缩的解压缩器
【发布时间】:2013-09-05 04:59:13
【问题描述】:

我想编写一个解压缩器,用于使用固定的 Huffman 代码对压缩数据进行压缩。 形成规范:

     BTYPE specifies how the data are compressed, as follows:

        00 - no compression
        01 - compressed with fixed Huffman codes
        10 - compressed with dynamic Huffman codes
        11 - reserved (error)

     The only difference between the two compressed cases is how the
     Huffman codes for the literal/length and distance alphabets are
     defined.

我希望解压器在 BTYPE=01 时解压数据 我知道我必须首先解码霍夫曼代码,然后解压缩 lz77 但是当 BTYPE=01 时,霍夫曼树不与压缩数据一起存储

那么我如何在没有树的情况下解码 Huffman 代码?

已编辑

所以霍夫曼代码将是这样的:

0 110000
1 110001
2 110010
144 110010000
145 110010001
255 111111111
256 0
257 1
258 10
259 11
260 100
279 10111
280 11000000
287 11000111

我不明白的是,如果我遇到代码 10,我如何区分距离代码中的值 2 和值 258 因为值 0-23256-297 具有相同的代码

【问题讨论】:

  • 不,霍夫曼代码不会是这样的。长度/文字的代码长度均为 7、8 或 9 位。看我的回答。

标签: compression huffman-code deflate


【解决方案1】:

固定的霍夫曼码是预定义的。来自RFC 1951

3.2.6. Compression with fixed Huffman codes (BTYPE=01)

     The Huffman codes for the two alphabets are fixed, and are not
     represented explicitly in the data.  The Huffman code lengths
     for the literal/length alphabet are:

               Lit Value    Bits        Codes
               ---------    ----        -----
                 0 - 143     8          00110000 through
                                        10111111
               144 - 255     9          110010000 through
                                        111111111
               256 - 279     7          0000000 through
                                        0010111
               280 - 287     8          11000000 through
                                        11000111

     The code lengths are sufficient to generate the actual codes,
     as described above; we show the codes in the table for added
     clarity.  Literal/length values 286-287 will never actually
     occur in the compressed data, but participate in the code
     construction.

     Distance codes 0-31 are represented by (fixed-length) 5-bit
     codes, with possible additional bits as shown in the table
     shown in Paragraph 3.2.5, above.  Note that distance codes 30-
     31 will never actually occur in the compressed data.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多