lvandeve / lodepng

PNG encoder and decoder in C and C++.
zlib License
2.07k stars 422 forks source link

Chunked output #20

Open LinusU opened 8 years ago

LinusU commented 8 years ago

Would it be possible to add a streaming api where you load the source data in (my understanding of png compression is that you need the whole image do the compression) and then get chunks of data back.

Somehow incrementally calling a function that returns a bit more of the output, and at last returns that it's done.

Would this be feasible or am I overlooking something in how png works that would make this bad?

lvandeve commented 8 years ago

Hi,

The PNG file format itself supports this (see *), but the LodePNG encoder and decoder don't support streaming, LodePNG requires full data available. Adding support for this will require a drastic code change, so is not likely to happen soon.

If a streaming API is required, then probably the official libpng library (http://www.libpng.org/pub/png/libpng.html) will be more suitable.

(*) The PNG file format supports streaming, because PNG filters on pixels depend only on past pixels. The deflate compression used also only depends on past data, it just requires working on blocks of data at a time. PNG supports interlacing, which is designed to load the PNG in a streaming fashion, from low resolution to higher, which is done in web browsers. LodePNG can read those, but all at once, no streaming.