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 3497 74d2f44a85de
parent 3496 78fc8ea578b2
child 3498 a4ce84c4f211
Added support for 32-bit BMP files with an alpha channel
src/video/SDL_bmp.c
--- a/src/video/SDL_bmp.c	Fri Nov 27 19:29:27 2009 +0000
+++ b/src/video/SDL_bmp.c	Mon Nov 30 17:57:12 2009 +0000
@@ -57,6 +57,7 @@
     Uint32 Rmask;
     Uint32 Gmask;
     Uint32 Bmask;
+    Uint32 Amask;
     SDL_Palette *palette;
     Uint8 *bits;
     Uint8 *top, *end;
@@ -160,7 +161,7 @@
     }
 
     /* We don't support any BMP compression right now */
-    Rmask = Gmask = Bmask = 0;
+    Rmask = Gmask = Bmask = Amask = 0;
     switch (biCompression) {
     case BI_RGB:
         /* If there are no masks, use the defaults */
@@ -178,9 +179,14 @@
                 Rmask = 0x000000FF;
                 Gmask = 0x0000FF00;
                 Bmask = 0x00FF0000;
-                break;
+#else
+                Rmask = 0x00FF0000;
+                Gmask = 0x0000FF00;
+                Bmask = 0x000000FF;
 #endif
+                break;
             case 32:
+                Amask = 0xFF000000;
                 Rmask = 0x00FF0000;
                 Gmask = 0x0000FF00;
                 Bmask = 0x000000FF;
@@ -196,10 +202,15 @@
         switch (biBitCount) {
         case 15:
         case 16:
+            Rmask = SDL_ReadLE32(src);
+            Gmask = SDL_ReadLE32(src);
+            Bmask = SDL_ReadLE32(src);
+            break;
         case 32:
             Rmask = SDL_ReadLE32(src);
             Gmask = SDL_ReadLE32(src);
             Bmask = SDL_ReadLE32(src);
+            Amask = SDL_ReadLE32(src);
             break;
         default:
             break;
@@ -214,7 +225,7 @@
     /* Create a compatible surface, note that the colors are RGB ordered */
     surface =
         SDL_CreateRGBSurface(0, biWidth, biHeight, biBitCount, Rmask, Gmask,
-                             Bmask, 0);
+                             Bmask, Amask);
     if (surface == NULL) {
         was_error = SDL_TRUE;
         goto done;