Decode data bytes of GIF87a raster data stream

穿精又带淫゛_ 提交于 2019-11-28 14:10:22

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

now the image data

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.

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.

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.

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

So you have: 06 6b 40 86 70 48 2c 1a

  • 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]

so the codes are:

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

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 ...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!