lvandeve / lodepng

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

lodepng_can_have_alpha gives incorrect result for 8-bit images which haven't yet been decoded #37

Open Dwedit opened 8 years ago

Dwedit commented 8 years ago

After using "lodepng_state_init", then "lodepng_inspect", there is not enough information to know if an 8-bit image has alpha or not. For 8-bit images, "lodepng_can_have_alpha" will only give correct results after the image has been completely decoded, which is usually too late for when you want to see if it needs an alpha channel or not.

"lodepng_has_palette_alpha" should have features added to it. It should check if the image is palettized, then check if the palette has been loaded or not, and if it hasn't been loaded, load the "PLTE" and "tRNS" chunks so it will have a palette available with possible alpha channel. That would fix the issue with "lodepng_can_have_alpha" yielding incorrect results.

Edit: Looks like lodepng_has_palette_alpha doesn't have any handles to the input file, so it can't load it. I guess there needs to be another function to preload a palette if it exists. Possibly stick this into the Inspect function if you don't want to add anything new to the API.