SDL_image save image to file |
dandago
|
Am I missing something, or does SDL_image not provide any facility to save an image to file?
|
|||||||||||
|
dandago
|
Many thanks for the suggestion. I will check it out.
|
|||||||||||
|
SDL_image save image to file |
Daniel Gibson
Guest
|
On 01/13/2016 06:16 PM, dandago wrote:
No idea why this is not documented, but /* Individual saving functions */ extern DECLSPEC int SDLCALL IMG_SavePNG(SDL_Surface *surface, const char *file); extern DECLSPEC int SDLCALL IMG_SavePNG_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst); See: https://hg.libsdl.org/SDL_image/file/9a970a20248b/SDL_image.h#l132 (And in SDL itself there's SDL_SaveBMP()) Cheers, Daniel _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|
SDL_image save image to file |
Mason Wheeler
Guest
|
IMG_SavePNG is badly broken, unfortunately. It will always convert your surface to a 32-bit image if it's not one already, and if what you have is a paletted image with a colorkey, it doesn't handle the alpha correctly. Since 8-bit images are very common for PNGs, this is a very serious problem. Sadly, I raised the issue on here a few months ago and no one replied.
Mason From: Daniel Gibson To: Sent: Thursday, January 14, 2016 12:44 PM Subject: Re: [SDL] SDL_image save image to file On 01/13/2016 06:16 PM, dandago wrote:> Am I missing something, or does SDL_image not provide any facility to> save an image to file?>No idea why this is not documented, but/* Individual saving functions */extern DECLSPEC int SDLCALL IMG_SavePNG(SDL_Surface *surface, const char *file);extern DECLSPEC int SDLCALL IMG_SavePNG_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst);See:http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||
|
SDL_image save image to file |
Alexander Sabourenkov
Guest
|
On Tue, Jan 26, 2016 at 5:28 AM, Mason Wheeler wrote:
Well, you see, PNG format doesn't support colorkeyed palletted images. It only supports colorkey transparency for truecolor or grayscale images. PNG supports optional transparency for palletted images in the form of an array of alpha values for each palette entry. As you can now see, while colorkeyed paletted SDL_Surface can be saved in that format, loading it presents a problem - if such PNG image contains something other than exacly one fully transparent entry in this transparency table, while all other entries are fully opaque, data loss will occur. That is why most PNG loaders upconvert palletted PNG images to RGBA8888 or something like it. Are you only interested in saving images, or the requirement to get exactly same pixel format on load is in fact there, just not mentioned? --Â ./lxnt |
|||||||||||||
|
SDL_image save image to file |
Alexander Sabourenkov
Guest
|
You can try the untested indexed PNG save/load here: https://github.com/lxnt/SDL_pnglite/tree/indexed-save
It should save colorkeyed paletted SDL_Surface as a paletted PNG with only that color set to transparent (all others opaque). It should load such file to a paletted surface, and set the colorkey the right way. Not tested in any way. Will appeciate test-cases, images, SDL_Surface dumps, etc. This lib is in dire need of tests. Once it's tested and known to work I'm sure porting the support to SDL_image won't be a problem. -- ./lxnt |
|||||||||||
|