Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple IDAT chunks ? #153

Open
Raphael-Boichot opened this issue Nov 2, 2021 · 2 comments
Open

Support for multiple IDAT chunks ? #153

Raphael-Boichot opened this issue Nov 2, 2021 · 2 comments

Comments

@Raphael-Boichot
Copy link

Raphael-Boichot commented Nov 2, 2021

Hello.

I'm trying to embed lodepng in this project: https://github.com/zenaro147/NeoGB-Printer
It's working great apart that the ESP32 I'm using have a very limited memory, so that I can convert very small images only (typically 160*144 pixels, 2bbp).

I've tried to cut bigger images into small parts to pass them to lodepng encode function and get the IDAT packets to reconstitute a "franken" png. I discovered that it is not allowed by the PNG format where several IDAT chunks must originate from the same unique compressed stream. So the image I got with this method shows only the first IDAT chunks and black pixels elsewhere.

So my question: is there a way to use the lodepng functions to generate a stream of IDAT chunks from a unique stream of pixels (but without storing the whole stream in memory) so that I can pass big images line by line and get each IDAT chunk from a single compressed stream ? I can then make the other chunks without any difficulty to reconstitute my image.

Thanks by advance for your response and amazing library !

Raphael.

@lvandeve
Copy link
Owner

lvandeve commented Nov 4, 2021

That does look difficult since streaming functionality is not added to the library. Indeed, if you have multiple IDAT chunks in a single PNG, there is a zlib header in the first one only, and other interdependencies between the IDAT chunks. Unfortunately I can't think of any simple hack using the current functionality, not even something like disabling compression, since creating the IDAT chunks yourself would require rewriting quite a lot of the PNG functionality. This currently is most suited for a library that supports streaming.

@Raphael-Boichot
Copy link
Author

Thanks for your response. I finally came to thank conclusion too.
I'm now trying to adapt this project for ESP32: https://github.com/bitbank2/PNGenc
It seems to work with some quirks but I know how to correct them.

Raphael

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants