lvandeve / lodepng

PNG encoder and decoder in C and C++.
zlib License
2.08k stars 425 forks source link

lodepng could supply a helper for bit-depth from PNG header. #141

Closed alecazam closed 3 years ago

alecazam commented 3 years ago

I noticed that stbi_image and lodepng don't provide any helper calls that I saw to determine whether incoming png data is 8- or 16-bit from parsing the png header. What ends up happening is callers then to rely on the default argument (8-bit), or pass 8-bit, and then loaders can't load 16-bit data.

Since lodepng is already typically reading the png from memory, this traversal is fairly simple. I think this would help callers pick the right load type. 8 for images, and 16-bit for heightmaps for example.

This is just the bitdepth field of the IHDR block which must occur first in the block stream of the PNG. 1/2/4/8/16 are all possibilities.

lvandeve commented 3 years ago

Hi, it's actually possible with lodepng_inspect: that function only looks at the start of the file and dumps the information in the state object

Does that work?

alecazam commented 3 years ago

Ah, that's what I needed. Thanks.