https://www.w3.org/TR/PNG-Chunks.html

PNG画像でIDATを複数に分けることができる理由がよくわからなかったけど、今わかった。

PNGのチャンクは先にデータの長さを記録する必要があるので、(前から順にファイルを書いていく場合)もし分割を許さない場合、エンコーダが用意するメモリの量が定まらないということだ。

もちろん、最後まで読んだ後でデータの長さのところだけ書き換えるというやりかたもできるけど、チャンクのまとまりごとに出力していくほうが便利なケースもあるだろう。

Reply to this note

Please Login to reply.

Discussion

たとえば、画像データを圧縮しつつ、並行して送信するような場合。

https://www.w3.org/TR/png-3/#11IDAT

Some images have unused trailing bytes at the end of the final IDAT chunk. This could happen when an entire buffer is stored rather than just the portion of the buffer which is used. This is undesirable. Preferably, an encoder would not include these unused bytes. If it must, setting the bytes to zero will prevent accidental data sharing. A decoder should ignore these trailing bytes.

IDATチャンク内に画像データの後ろに余計なバイト列が続く場合があって、それはencoderとしては望ましい動作ではないけど、decoderはもしあったならそれを無視する必要がある。

これも、encoderが頭から順に画像を圧縮していくことを想定した規格なのだろう。