Fixed bug 1943 - Wrong handling of legacy 32bpp BMP files
authorSam Lantinga <slouken@libsdl.org>
Sun, 07 Jul 2013 12:53:21 -0700
changeset 7375c8b16b3a3c9b
parent 7374 29ace61fca99
child 7376 a2ea9757bfa0
Fixed bug 1943 - Wrong handling of legacy 32bpp BMP files

Kang Seonghoon

While BMP format supports alpha channel, it is enabled only when the header is at least 56 bytes long (BITMAPV3INFOHEADER and later). For very common 40-byte-long header (BITMAPINFOHEADER) 32bpp format should be interpreted as BGRX format, but currently SDL interprets them as BGRA format and causes a significant compatibility problem as many 32bpp files use a padding byte of 0 ("transparent" in BGRA interpretation).
src/video/SDL_bmp.c
     1.1 --- a/src/video/SDL_bmp.c	Sun Jul 07 12:34:26 2013 -0700
     1.2 +++ b/src/video/SDL_bmp.c	Sun Jul 07 12:53:21 2013 -0700
     1.3 @@ -182,7 +182,7 @@
     1.4  #endif
     1.5                  break;
     1.6              case 32:
     1.7 -                Amask = 0xFF000000;
     1.8 +                Amask = (biSize < 56 ? 0 : 0xFF000000); /* no alpha before BITMAPV3INFOHEADER */
     1.9                  Rmask = 0x00FF0000;
    1.10                  Gmask = 0x0000FF00;
    1.11                  Bmask = 0x000000FF;