解码GIF87a栅格数据流的数据字节 [英] Decode data bytes of GIF87a raster data stream

查看:316
本文介绍了解码GIF87a栅格数据流的数据字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解码GIF87a栅格数据流中的数据字节。我不确定如何读取LZW可变长度代码(以及LSB ......最低有效字节如何首先适用于此)。栅格数据流如下所示(十六进制):

I'm trying to decode the data bytes from a GIF87a raster data stream. I'm unsure of how to read the LZW variable length codes (and how LSB...least significant byte first fits in this). The raster data stream starts as follows (in hex):

06 6b 40 86 70 48 2c 1a 8f 44 4b 44 22 89 58 8e 10 c7 e1 80




  • 06 - >代码大小为6

  • 6b - >块字节数107

  • 40 - >清除代码(2 ^ 6),十进制64或十六进制40

  • 86 - >开始实际数据

    • 06 ->code size of 6
    • 6b ->block byte count of 107
    • 40 ->clear code (2^6) which is 64 in decimal or 40 in hex
    • 86 -> start of actual data
    • GIF87a规格: http://www.w3.org/Graphics/GIF/spec-gif87.txt

      GIF87a spec: http://www.w3.org/Graphics/GIF/spec-gif87.txt

      栅格流应该有指向全局地图的索引(或指向LZW树中的父级)...但我不知道如何阅读它。

      The raster stream should have indexes that point to the global map (or to a parent in the LZW tree)...but I'm not sure how to read it.

      有人可以转换前几个字节(从86开始)作为示例吗?

      Could someone convert the first few bytes (starting at 86) as an example?

      推荐答案

      阅读 3MF Project GIF ,所有小节都有一切您需要使用步进示例,其余部分位于spec文件中。

      read this 3MF Project GIF and all subsections there is everything you need with stepping examples and the rest is in the spec file.

      现在图像数据

      流数据以1字节块大小开始,然后进入比特流。最后是另一个块大小。它会在您绘制整个帧然后在最后一个重读块之后设置指针时停止。

      Stream data starts with 1 Byte block size and then goes the bit stream. At the end goes another block size. It stops when you draw entire frame then set pointer after the last readed block.

      如果您发现块大小 0 那么它意味着帧数据的结束。如果有终结符 0x3b 之后到达文件末尾。

      if you found block size 0 then it means the end of frame data. If there is terminator 0x3b after then the end of file is reached.

      本地颜色位告诉你有多少开始时流中每个代码的位数。

      The local color bits tells you how many bits you have per code in the stream at start.

      我读取实际处理过的BYTE的LSB,然后向右移动然后向右移动代码并将此位添加为MSB。通过LZW解压缩到达所需的索引处理位数后,还可以将新代码添加到字典中。

      I read LSB of actual processed BYTE, then shift it right then shift the code right and add this bit as MSB of it. After you reach the needed bit count of index process it by LZW decompressing and also add new code to dictionary.

      如果字典交叉2 ^位边界增加代码bitsize并继续。不要忘记处理清除和结束特殊代码...

      if dictionary cross 2^bits boundary increase the code bitsize and continue. Do not forget to handle the clear and end special codes ...

      所以你有: 06 6b 40 86 70 48 2c 1a


      • 06h 是初始位大小 - 1所以实际位大小 7 !!!

      • 6bh 是块大小,以字节为单位

      • 40h 是清晰代码(表示 color [] 表中的64种颜色,第一个免费索引是66)

      • 86 70 48 2c 1a [hex] = | 1 0000110 | 01 110000 | 010 01000 | 0010 1100 | 00011 010 | [bin]

      • 06h is initial bit size - 1 so the real bit size is 7 !!!
      • 6bh is block size in bytes
      • 40h is clear code (meaning 64 colors present in color[] table, and first free index is 66)
      • 86 70 48 2c 1a [hex]= |1 0000110|01 110000|010 01000|0010 1100|00011 010| [bin]

      因此代码为:


      • | 0000110 | 110000 1 | 01000 01 | 1100 010 | 010 0010 | [bin]

      • | 0000110 | 1100001 | 0100001 | 11000010 | 0100010 | [bin]

      • 06,61,21,c2,22 [hex]

      • |0000110|110000 1|01000 01|1100 010|010 0010| [bin]
      • |0000110|1100001 |0100001 |11000010|0100010 | [bin]
      • 06,61,21,c2,22 [hex]

      61h 建议数据错误是图像数据的真正开始(或者我做了一个错误某处)?代码只能是字典中的一个大于最大索引的代码。除了第一个代码之外,每个代码都增加了字典,因此在处理 61h 时,字典的大小仅为 42h 。试试他们工作的链接页面中的示例...

      the 61h suggest error in data is this really start of image data (or I made a mistake somewhere)? The code can be only one bigger then max index in dictionary. The dictionary is increased by each code except the first so while processing 61h the dictionary is only 42h in size. Try the example in the linked page they works ...

      这篇关于解码GIF87a栅格数据流的数据字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆