PNG 文件中的 Adler-32 校验和

Adler-32 checksum(s) in a PNG file

我目前正在编写一个 C 程序,该程序从另一个生成的数据文件构建 PNG 图像。图像是调色板类型。

Adler-32 校验和是根据未压缩数据计算的...

a) IDAT 数据块中的每个压缩块?

b) IDAT 数据块中的所有压缩块?

c) 跨越所有 IDAT 数据块的所有压缩块?

http://www.w3.org/TR/PNG/, https://www.rfc-editor.org/rfc/rfc1950 和 rfc1951 的文档(与 previuos 在同一地址)我认为是上面的 'c'为每个块压缩数据,忽略压缩块如何在连续的 IDAT 块之间拆分。

这是正确的吗?

PNG IDAT 块独立于压缩块。 Adler-32 校验和是 zlib 压缩的一部分,与 PNG 的整体元结构无关。

来自the PNG Specification

There can be multiple IDAT chunks; if so, they must appear consecutively with no other intervening chunks. The compressed datastream is then the concatenation of the contents of all the IDAT chunks. The encoder can divide the compressed datastream into IDAT chunks however it wishes. (Multiple IDAT chunks are allowed so that encoders can work in a fixed amount of memory; typically the chunk size will correspond to the encoder's buffer size.) It is important to emphasize that IDAT chunk boundaries have no semantic significance and can occur at any point in the compressed datastream.

(强调我的)

一个PNG文件中只能有一个压缩图像数据流,即一个zlib流,最后有一个Adler-32检查,即所有未压缩 数据(由过滤器和隔行扫描预处理)。该 zlib 流可能会也可能不会被分解成多个 IDAT 块。每个IDAT chunk都有自己的CRC-32,就是chunk type code "IDAT"和compressed里面数据的CRC-32。

我不确定 "allowing one's deflate implementation to chop and change how the data are compressed for each block" 是什么意思。有效 PNG 文件的 deflate 实现必须将所有过滤后的图像数据压缩为单个 zlib 流。

将其压缩为单个 zlib 流之后,您可以根据需要将该流分解为一系列 IDAT 块,或作为单个 IDAT 块。