从字节数组读取可变长度代码 [c#]
我有一些数字,使用可变长度代码编码在字节数组中。 实际上它是 GIF89a 图像数据,我必须对其进行解码。
由于用于 GIF 的 LZW 压缩创建了一系列可变长度代码(每个代码在 3 到 12 位之间),因此这些代码必须重新构造为一系列 8 位字节,这将是实际存储或传输的字符。这些代码形成一个位流,就好像它们从右到左打包一样,然后一次选取 8 位进行输出。 假设每个字符 8 位的字符数组并使用 5 位代码 包装,示例布局将类似于:
+---------------+
0 | | bbbaaaaa
+---------------+
1 | | dcccccbb
+---------------+
2 | | eeeedddd
+---------------+
3 | | ggfffffe
+---------------+
4 | | hhhhhggg
+---------------+
. . .
+---------------+
N | |
+---------------+
如何将其转换为常见的[例如。使用 C# 的整数] 格式。一些功能?
另外,我不明白如何识别 - 当这个数字的大小(以位为单位)增加(大小+1)时?我只知道第一个数字的大小?
I have some numbers, encoded in byte array using variable-length code.
Actually it's GIF89a image data, whith I have to decode.
Because the LZW compression used for GIF creates a series of variable length codes, of between 3 and 12 bits each, these codes must be reformed into a series of 8-bit bytes that will be the characters actually stored or transmitted. The codes are formed into a stream of bits as if they were packed right to left and then picked off 8 bits at a time to be output.
Assuming a character array of 8 bits per character and using 5 bit codes to be
packed, an example layout would be similar to:
+---------------+
0 | | bbbaaaaa
+---------------+
1 | | dcccccbb
+---------------+
2 | | eeeedddd
+---------------+
3 | | ggfffffe
+---------------+
4 | | hhhhhggg
+---------------+
. . .
+---------------+
N | |
+---------------+
How I can convert it to common [ex. integer] format using c#. Some features?
Also, I can't understand how to recognize - when size(in bits) of this numbers is increasing (+1 to size)? I just know size of the first number?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想使用比特流。请参阅http://www.codeproject.com/KB/cs/bitstream.aspx 举一个很好的例子。
You want to use a BitStream. See http://www.codeproject.com/KB/cs/bitstream.aspx for a good example.