nothings/stb — pull request #45 by ocornut (2014-09-25 18:42:48+00:00)
Title: Support for 1/2/4-bit palettized PNG

Support for 1/2/4-bit palettized PNG

I was using pngout.exe to crunch down PNG to optimal size and ended up with data that stb_image wouldn't load. Using the data suite from http://www.schaik.com/pngsuite/pngsuite_bas_png.html, the proposed change allow to load basn3p01, basn3p02 and basn3p04.

The resulting loaded data is always converted to 8-bpp which I thought made sense (and simplify implementation).

I haven't thoroughly tested the changes against a bunch of corner cases (you may have a better test suite).

The additional ops are making the common case (8 bpp) slower so my assumption is that you might want to expand the code for each bit depth (1/2/4/8) or at least separate 1/2/4 from 8, considering the later is most common? If you would like me to rework the PR in this way I can do that. Additionally I'm not happy with the name of the 4 local variables I added in stbi__create_png_image_raw() maybe you'd have a better idea. If the code is expanding for all supported depths those variables can be folded into constants and won't need the confusing names.