如何解码GIF的应用程序扩展块? [英] How to decode the application extension block of GIF?

查看:18
本文介绍了如何解码GIF的应用程序扩展块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to decode the application extension block of 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  !.......,.......

这个

21 ff0b  s..9.........!..
    0000310: 4e45 5453 4341 5045 322e 30

"是已知的,但什么是03 0100 0000"?

" is known, but what is "03 0100 0000"?

推荐答案

以下介绍 GIF Netscape Application 扩展,取从这里.

The following describes GIF Netscape Application extension, taken from here.

该块有 19 个字节长.前14个字节属于通用Application Extension格式,语法在GIF89a中有说明规范,26. 应用程序扩展"部分.

The block is 19 bytes long. First 14 bytes belongs to general Application Extension format, syntax is described in GIF89a Specification, section "26. Application Extension".

语法

 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

您已经知道NETSCAPE2.0 之前的数据.下一个字节 0x03 告诉我们下一个数据子块的长度,它总是 3 个字节.下面的0x01是子块ID.对于 Netscape 块,只有一个数据子块,ID 为 1.

You already know the data up to NETSCAPE2.0. The next byte 0x03 tells us the next data sub-block length which is always 3 bytes. The following 0x01 is the sub-block ID. For Netscape block, there is only one data sub-block and the ID is 1.

接下来的 2 个字节指定了循环次数(以小端为单位)——图像帧应该循环多少次,即 0,0 表示循环永远.

The following 2 bytes specifies the loop count in little endian — how many times the image frames should be looped, which is 0, and 0 means loop forever.

最后一个字节0x00用于终止数据块.因此,当我们遇到 0x00 数据子块长度应该是,我们知道没有子块剩余,我们需要停止读取块.

The last byte 0x00 is used to terminate the data block. So when we meet a 0x00 where data sub-block length should be, we know there are no sub-blocks left and we need to stop reading the block.

这篇关于如何解码GIF的应用程序扩展块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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