如何解码GIF的应用程序扩展块?

Vic*_*r S 1 decode gif animated-gif

如何解码GIF的应用程序扩展块?

0000300: 73e7 d639 bdad 10ad 9c08 b5a5 0021 ff0b  s..9.........!..
0000310: 4e45 5453 4341 5045 322e 3003 0100 0000  NETSCAPE2.0.....
0000320: 21f9 0409 1900 f600 2c00 0000 0016 01b7  !.......,.......
Run Code Online (Sandbox Code Playgroud)

这个 ”

21 ff0b  s..9.........!..
    0000310: 4e45 5453 4341 5045 322e 30
Run Code Online (Sandbox Code Playgroud)

“是已知的,但是”“是什么03 0100 0000

dra*_*n66 5

下面介绍从此处获取的GIF Netscape Application扩展。

该块长19个字节。前14个字节属于通用应用程序扩展格式,语法在GIF89a规范的“ 26.应用程序扩展”部分中进行了描述。

句法

 0  |     0x21      |  Extension Label
    +---------------+
 1  |     0xFF      |  Application Extension Label
    +---------------+
 2  |     0x0B      |  Block Size
    +---------------+
 3  |               | 
    +-             -+
 4  |               | 
    +-             -+
 5  |               | 
    +-             -+
 6  |               | 
    +-  NETSCAPE   -+  Application Identifier (8 bytes)
 7  |               | 
    +-             -+
 8  |               | 
    +-             -+
 9  |               | 
    +-             -+
10  |               | 
    +---------------+
11  |               | 
    +-             -+
12  |      2.0      |  Application Authentication Code (3 bytes)
    +-             -+
13  |               | 
    +===============+                      --+
14  |     0x03      |  Sub-block Data Size   |
    +---------------+                        |
15  |     0x01      |  Sub-block ID          |
    +---------------+                        | Application Data Sub-block
16  |               |                        |
    +-             -+  Loop Count (2 bytes)  |
17  |               |                        |
    +===============+                      --+
18  |     0x00      |  Block Terminator
Run Code Online (Sandbox Code Playgroud)

您已经知道截至的数据NETSCAPE2.0。下一个字节0x03告诉我们下一个数据子块的长度,该长度始终为3个字节。以下0x01是子块ID。对于Netscape块,只有一个数据子块,ID为1

接下来的2个字节以小字节序指定循环计数-图像帧应循环循环的次数,为0,0表示永远循环。

最后一个字节0x00用于终止数据块。因此,当我们遇到0x00数据子块长度应该在哪里时,我们知道没有子块了,我们需要停止读取该块。