Commit 1ba6e560 authored by Sam Lantinga's avatar Sam Lantinga

Added support for saving 32-bit BMP with alpha channel (disabled by default)

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403431
parent cd6f7dd7
......@@ -377,7 +377,16 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
/* Make sure we have somewhere to save */
surface = NULL;
if (dst) {
if (saveme->format->palette) {
SDL_bool save32bit = SDL_FALSE;
#ifdef SAVE_32BIT_BMP
/* We can save alpha information in a 32-bit BMP */
if (saveme->map->info.flags & SDL_COPY_COLORKEY ||
saveme->format->Amask) {
save32bit = SDL_TRUE;
}
#endif /* SAVE_32BIT_BMP */
if (saveme->format->palette && !save32bit) {
if (saveme->format->BitsPerPixel == 8) {
surface = saveme;
} else {
......@@ -399,7 +408,12 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
} else {
SDL_PixelFormat format;
/* Convert to 24 bits per pixel */
/* If the surface has a colorkey or alpha channel we'll save a
32-bit BMP with alpha channel, otherwise save a 24-bit BMP. */
if (save32bit) {
SDL_InitFormat(&format, 32,
0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
} else {
SDL_InitFormat(&format, 24,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x00FF0000, 0x0000FF00, 0x000000FF,
......@@ -407,9 +421,10 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
0x000000FF, 0x0000FF00, 0x00FF0000,
#endif
0);
}
surface = SDL_ConvertSurface(saveme, &format, 0);
if (!surface) {
SDL_SetError("Couldn't convert image to 24 bpp");
SDL_SetError("Couldn't convert image to %d bpp", format.BitsPerPixel);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment