IMG_SavePNG does not preserve the image format


#1

I’ve got a utility that opens an 8-bit PNG file, slices it up into several smaller files, and saves them for later use.? When they’re used later, the files are loaded and read into an SDL_Surface, and the code locates palette index 0, if it can, to set as a color key before loading them to textures.? Unfortunately, I just discovered that I’ve got no color key because I’ve got no palette, because IMG_SavePNG is saving them as a 32-bit image rather than an 8-bit image!? I looked at the source, and sure enough,?it checks to make sure that the image is a 32-bit RGBA image, or forcibly converts it before saving if it isn’t.

This is really not acceptable.? What would be the simplest way to fix this so that 8-bit images stay 8-bit images?
Mason


#2

I am having the same issue. I am using greyscale 8bit arrays from binary files and would like to save them as PNG. Unfortunately the IMG_savePNG saves them as 32bit.
I am reluctantly looking for another library to write PNG files, because I really like SDL2, and I use it already for other parts in my application.
I would really appreciate it if SDL2 would implement 8-bit PNGs in IMG_savePNG.

BRgds
Carlos


#3

I recall there being some thing on Mac OS X where SDL_image would use the system APIs for this and they didn’t do anything but 32-bit (and maybe a workaround for that got applied?) But I don’t know if that’s what happened here and this is all very vague in my head at the moment.