Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added support for saving 32-bit BMP with alpha channel (disabled by d…
Browse files Browse the repository at this point in the history
…efault)
  • Loading branch information
slouken committed Jan 3, 2009
1 parent 708c1e4 commit 3824eb9
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/video/SDL_bmp.c
Expand Up @@ -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 {
Expand All @@ -399,17 +408,23 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
} else {
SDL_PixelFormat format;

/* Convert to 24 bits per pixel */
SDL_InitFormat(&format, 24,
/* 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,
0x00FF0000, 0x0000FF00, 0x000000FF,
#else
0x000000FF, 0x0000FF00, 0x00FF0000,
0x000000FF, 0x0000FF00, 0x00FF0000,
#endif
0);
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);
}
}
}
Expand Down

0 comments on commit 3824eb9

Please sign in to comment.