Added support for 32-bit BMP files with an alpha channel
authorSam Lantinga <slouken@libsdl.org>
Mon, 30 Nov 2009 17:57:12 +0000
changeset 349774d2f44a85de
parent 3496 78fc8ea578b2
child 3498 a4ce84c4f211
Added support for 32-bit BMP files with an alpha channel
src/video/SDL_bmp.c
     1.1 --- a/src/video/SDL_bmp.c	Fri Nov 27 19:29:27 2009 +0000
     1.2 +++ b/src/video/SDL_bmp.c	Mon Nov 30 17:57:12 2009 +0000
     1.3 @@ -57,6 +57,7 @@
     1.4      Uint32 Rmask;
     1.5      Uint32 Gmask;
     1.6      Uint32 Bmask;
     1.7 +    Uint32 Amask;
     1.8      SDL_Palette *palette;
     1.9      Uint8 *bits;
    1.10      Uint8 *top, *end;
    1.11 @@ -160,7 +161,7 @@
    1.12      }
    1.13  
    1.14      /* We don't support any BMP compression right now */
    1.15 -    Rmask = Gmask = Bmask = 0;
    1.16 +    Rmask = Gmask = Bmask = Amask = 0;
    1.17      switch (biCompression) {
    1.18      case BI_RGB:
    1.19          /* If there are no masks, use the defaults */
    1.20 @@ -178,9 +179,14 @@
    1.21                  Rmask = 0x000000FF;
    1.22                  Gmask = 0x0000FF00;
    1.23                  Bmask = 0x00FF0000;
    1.24 +#else
    1.25 +                Rmask = 0x00FF0000;
    1.26 +                Gmask = 0x0000FF00;
    1.27 +                Bmask = 0x000000FF;
    1.28 +#endif
    1.29                  break;
    1.30 -#endif
    1.31              case 32:
    1.32 +                Amask = 0xFF000000;
    1.33                  Rmask = 0x00FF0000;
    1.34                  Gmask = 0x0000FF00;
    1.35                  Bmask = 0x000000FF;
    1.36 @@ -196,10 +202,15 @@
    1.37          switch (biBitCount) {
    1.38          case 15:
    1.39          case 16:
    1.40 +            Rmask = SDL_ReadLE32(src);
    1.41 +            Gmask = SDL_ReadLE32(src);
    1.42 +            Bmask = SDL_ReadLE32(src);
    1.43 +            break;
    1.44          case 32:
    1.45              Rmask = SDL_ReadLE32(src);
    1.46              Gmask = SDL_ReadLE32(src);
    1.47              Bmask = SDL_ReadLE32(src);
    1.48 +            Amask = SDL_ReadLE32(src);
    1.49              break;
    1.50          default:
    1.51              break;
    1.52 @@ -214,7 +225,7 @@
    1.53      /* Create a compatible surface, note that the colors are RGB ordered */
    1.54      surface =
    1.55          SDL_CreateRGBSurface(0, biWidth, biHeight, biBitCount, Rmask, Gmask,
    1.56 -                             Bmask, 0);
    1.57 +                             Bmask, Amask);
    1.58      if (surface == NULL) {
    1.59          was_error = SDL_TRUE;
    1.60          goto done;