PNG:使用多个 IDAT-Chunk 有什么好处?

标签 png

我想知道在 PNG 图像中使用多个 IDAT-Chunk 的好处是什么。

PNG 文档说

There may be multiple IDAT chunks; if so, they shall appear consecutively with no other intervening chunks. The compressed datastream is then the concatenation of the contents of the data fields of all the IDAT chunks.



我无法想象这是因为块内数据块的最大大小(2^32 字节)。

最佳答案

回想一下,所有 PNG 块(包括 IDAT 块)都有一个带块长度的前缀。将所有压缩流放在一个巨大的 IDAT 块中会导致以下两个不便:

  • 在编码器方面:压缩器在完成压缩之前不知道总压缩数据大小。然后,它需要在写入块前缀之前在内存中缓冲完整的压缩数据。
  • 在解码器端:取决于如何实现块解码;如果它在内存中缓冲每个块(分配由块长度前缀给出的空间),并且在填充它并检查 CRC 之后,它将内容传递给解压缩器,那么,同样,拥有一个巨大的 IDAT 块将是一个内存 pig 。

  • 考虑到这一点,我认为应该推荐使用较小的 IDAT 块(例如 16KB 或 64KB)。开销(每块 12 字节,如果 len=64KB,则小于 1/5000)可以忽略不计。

    关于PNG:使用多个 IDAT-Chunk 有什么好处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29513549/

    相关文章:

    javascript - SVG 到 PNG 不带宽度属性

    png - 如何知道 TPNGObject 是否具有有效的 header ?

    php - 从客户端 DOM 序列化 SVG 的最佳方式是什么?

    html - 通过 CSS 更改 PNG 图像的颜色?

    node.js - OpenCV 断言失败类型不匹配

    python - 使用 Python 将元数据添加到图像上传到 S3

    javascript - 将 png 转换为张量 tensorflow.js

    python - 加快 numpy 过滤速度

    python-3.x - 在 matplotlib 图形中插入 png 图像

    r - R中的png()函数无法创建尺寸大于3000x3000px的png文件