http://giflib.sourceforge.net/whatsinagif/lzw_image_data.html
我正在阅读这个页面来理解Giff的LZW压缩。它显示了示例图像中的编码代码:
#4 #1 #6 #6 #2 #9 #9
在可变长度压缩成字节后,它变成:
8C 2D 99.
这意味着:
#4 -3位
#1 -3位
#6 -3位
#6 -3位
#2 -4位
#9 -4位
这个压缩的图像数据是正确的,因为我使用Photoshop和验证的二进制内容生成了giff样本图像。
它清楚地表明,当输出代码#2时,位大小增加
然而,页面是这样谈论位大小增加的:When you are encoding the data, you increase your code size as soon as your write out the code equal to 2^(current code size)-1
Jumping back to our sample image, we see that we have a minimum code size value of 2 which means out first code size will be 3 bits long. Out first three codes, #1 #6 and #6, would be coded as 001 110 and 110. If you see at Step 6 of the encoding, we added a code of #7 to our code table. This is our clue to increase our code size because 7 is equal to 2^3-1 (where 3 is our current code size). Thus, the next code we write out, #2, will use the new code size of 4 and therefore look like 0010.
但是在它的编码表中,第六步是将条目#7添加到LZW字典中,但是为输出添加的代码是第一个#6,根据算法,两个#6应该是每个4位,但为什么它们实际上是3位?
根据此页面https://www.eecis.udel.edu/~amer/CISC651/lzw.and.gif.explained.html
它对比特大小If you're encoding, you start with a compression size of (N+1) bits, and, whenever you output the code (2**(compression size)-1), you bump the compression size up one bit也是如此
那么到底出了什么问题??
发布于 2017-08-06 02:02:28
再次查看您链接到的页面上给出的示例:图像只有4种颜色,即LZW压缩器以3位代码开始。到目前为止,字典包含6个条目:文字0..3、明码4和EOI码5。输出的前两个码是明码4和文字1。这是所有GIF LZW流的开始方式。现在开始压缩,因为图像以1开始。在向流中写入另外2个代码后,8个字典槽被耗尽,代码大小增加到4。因此,下一个代码-文字2-被写成一个4位数字。
如您所见,没有任何错误。这就是GIF处理4色图像的方式。
https://stackoverflow.com/questions/43458715
复制相似问题