簡要
兼容png格式,在png格式的基礎(chǔ)上加入額外的信息描述動畫序列扮念,在不支持apng的地方可以顯示第一幀內(nèi)容损搬。幀間無損壓縮,有效降低存儲大小柜与。
結(jié)構(gòu)
APNG與PNG相同巧勤,由若干個Chunk組成。每個Chunk的結(jié)構(gòu)如下:
Length(4B) + Type(4B) + Data + CRC(4B)
(refs: https://www.w3.org/TR/PNG/#5Chunk-layout)
Type 的四個字節(jié)弄匕,分別為四個英文字母颅悉,大小寫分別代表不同的意義,除文檔已定義名字外可以自由命名(如 oRIg)
- 1字母:大寫/小寫 重要數(shù)據(jù)/附加數(shù)據(jù)
- 2字母:大寫/小寫 標(biāo)準(zhǔn)有定義的類型/自定義類型
- 3字母:大寫/小寫 未使用
- 4字母:大寫/小寫 非復(fù)制安全/復(fù)制安全 (對于編輯器來說復(fù)制安全的數(shù)據(jù)可以直接復(fù)制)
Data 長度為 Length
一般的PNG結(jié)構(gòu)形如:
PNGSignature(8B) + IHDR(25B) + IDAT + IEND(12B)
PNGSignature
:固定值 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0aIHDR
:PNG信息IDAT
:圖像數(shù)據(jù)IEND
:結(jié)束標(biāo)識迁匠,數(shù)據(jù)長度為0
`IHDR數(shù)據(jù)結(jié)構(gòu)`
Width 4 bytes
Height 4 bytes
Bit depth 1 byte
Colour type 1 byte
Compression method 1 byte
Filter method 1 byte
Interlace method 1 byte
(refs: https://www.w3.org/TR/PNG/#11IHDR)
png例子-頭部
png例子-尾部
一般的APNG結(jié)構(gòu)形如:
PNGSignature(8B) + IHDR(25B) + acTL + fcTL + IDAT + [ fcTL + fdAT ... ] + IEND(12B)
其中
第一幀:fcTL + IDAT
后續(xù)幀:fcTL + fdAT
acTL
:動畫控制塊(Animation Control Chunk)签舞,記錄總幀數(shù)和循環(huán)次數(shù),其中循環(huán)次數(shù)0表示無限循環(huán)fcTL
:幀控制塊(Frame Control Chunk)柒瓣,記錄每一幀的信息儒搭,fdAT
:幀數(shù)據(jù)塊(Frame Data Chunk),每幀圖像數(shù)據(jù)
`acTL數(shù)據(jù)結(jié)構(gòu)`
byte
0 num_frames (unsigned int) Number of frames
4 num_plays (unsigned int) Number of times to loop this APNG. 0 indicates infinite looping.
`fcTL數(shù)據(jù)結(jié)構(gòu)`
byte
0 sequence_number (unsigned int) Sequence number of the animation chunk, starting from 0
4 width (unsigned int) Width of the following frame
8 height (unsigned int) Height of the following frame
12 x_offset (unsigned int) X position at which to render the following frame
16 y_offset (unsigned int) Y position at which to render the following frame
20 delay_num (unsigned short) Frame delay fraction numerator
22 delay_den (unsigned short) Frame delay fraction denominator
24 dispose_op (byte) Type of frame area disposal to be done after rendering this frame
25 blend_op (byte) Type of frame area rendering for this frame
`fdAT數(shù)據(jù)結(jié)構(gòu)`
0 sequence_number unsigned int Sequence number of the animation chunk, starting from 0.
4 frame_data X bytes Frame data for this frame.
(refs: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/APNG)
apng例子-acTL(num_frames=8, num_plays=0)
相關(guān)資料
https://www.w3.org/TR/PNG - png格式文檔
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/APNG - apng格式文檔
https://wiki.mozilla.org/APNG_Specification - apng格式文檔
https://en.wikipedia.org/wiki/APNG
https://baike.baidu.com/item/APNG/3582613
https://aotu.io/notes/2016/11/07/apng/index.html - 寫得不錯的apng介紹文章