src/video/SDL_bmp.c
changeset 2969 1ee69e7e7cea
parent 2967 e4a469d6ddab
child 2990 502adab079a4
     1.1 --- a/src/video/SDL_bmp.c	Fri Jan 02 23:47:16 2009 +0000
     1.2 +++ b/src/video/SDL_bmp.c	Sat Jan 03 01:00:38 2009 +0000
     1.3 @@ -377,7 +377,16 @@
     1.4      /* Make sure we have somewhere to save */
     1.5      surface = NULL;
     1.6      if (dst) {
     1.7 -        if (saveme->format->palette) {
     1.8 +        SDL_bool save32bit = SDL_FALSE;
     1.9 +#ifdef SAVE_32BIT_BMP
    1.10 +        /* We can save alpha information in a 32-bit BMP */
    1.11 +        if (saveme->map->info.flags & SDL_COPY_COLORKEY ||
    1.12 +            saveme->format->Amask) {
    1.13 +            save32bit = SDL_TRUE;
    1.14 +        }
    1.15 +#endif /* SAVE_32BIT_BMP */
    1.16 +
    1.17 +        if (saveme->format->palette && !save32bit) {
    1.18              if (saveme->format->BitsPerPixel == 8) {
    1.19                  surface = saveme;
    1.20              } else {
    1.21 @@ -399,17 +408,23 @@
    1.22          } else {
    1.23              SDL_PixelFormat format;
    1.24  
    1.25 -            /* Convert to 24 bits per pixel */
    1.26 -            SDL_InitFormat(&format, 24,
    1.27 +            /* If the surface has a colorkey or alpha channel we'll save a
    1.28 +               32-bit BMP with alpha channel, otherwise save a 24-bit BMP. */
    1.29 +            if (save32bit) {
    1.30 +                SDL_InitFormat(&format, 32,
    1.31 +                               0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
    1.32 +            } else {
    1.33 +                SDL_InitFormat(&format, 24,
    1.34  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
    1.35 -                           0x00FF0000, 0x0000FF00, 0x000000FF,
    1.36 +                               0x00FF0000, 0x0000FF00, 0x000000FF,
    1.37  #else
    1.38 -                           0x000000FF, 0x0000FF00, 0x00FF0000,
    1.39 +                               0x000000FF, 0x0000FF00, 0x00FF0000,
    1.40  #endif
    1.41 -                           0);
    1.42 +                               0);
    1.43 +            }
    1.44              surface = SDL_ConvertSurface(saveme, &format, 0);
    1.45              if (!surface) {
    1.46 -                SDL_SetError("Couldn't convert image to 24 bpp");
    1.47 +                SDL_SetError("Couldn't convert image to %d bpp", format.BitsPerPixel);
    1.48              }
    1.49          }
    1.50      }