changeset 5184:d2652aafafbb

The format detection code works better with 555 and 565 pixel formats
author Sam Lantinga <slouken@libsdl.org>
date Fri, 04 Feb 2011 16:55:50 -0800
parents 4d098d286794
children 073b86030262
files src/video/SDL_pixels.c src/video/windows/SDL_windowsframebuffer.c
diffstat 2 files changed, 21 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/SDL_pixels.c	Sat Feb 05 00:32:04 2011 -0800
+++ b/src/video/SDL_pixels.c	Fri Feb 04 16:55:50 2011 -0800
@@ -256,11 +256,11 @@
         }
         break;
     case 15:
-        switch (Rmask) {
-        case 0x001F:
+        if (Rmask == 0x7C00 && Bmask == 0x001F) {
+            return SDL_PIXELFORMAT_RGB555;
+        }
+        if (Rmask == 0x001F && Bmask == 0x7C00) {
             return SDL_PIXELFORMAT_BGR555;
-        case 0x7C00:
-            return SDL_PIXELFORMAT_RGB555;
         }
         break;
     case 16:
@@ -273,18 +273,24 @@
             return SDL_PIXELFORMAT_BGRA4444;
         case 0x000F:
             return SDL_PIXELFORMAT_ABGR4444;
+        case 0xF800:
+            if (Bmask == 0x001F) {
+                return SDL_PIXELFORMAT_RGB565;
+            }
+            break;
+        case 0x7C00:
+            if (Bmask == 0x001F) {
+                return SDL_PIXELFORMAT_RGB555;
+            }
+            break;
         case 0x001F:
-            if (Gmask == 0x07E0) {
+            if (Bmask == 0xF800) {
                 return SDL_PIXELFORMAT_BGR565;
             }
-            return SDL_PIXELFORMAT_ABGR1555;
-        case 0x7C00:
-            return SDL_PIXELFORMAT_ARGB1555;
-        case 0xF800:
-            if (Gmask == 0x07E0) {
-                return SDL_PIXELFORMAT_RGB565;
+            if (Bmask == 0x7C00) {
+                return SDL_PIXELFORMAT_BGR555;
             }
-            return SDL_PIXELFORMAT_RGBA5551;
+            break;
         }
         break;
     case 24:
--- a/src/video/windows/SDL_windowsframebuffer.c	Sat Feb 05 00:32:04 2011 -0800
+++ b/src/video/windows/SDL_windowsframebuffer.c	Fri Feb 04 16:55:50 2011 -0800
@@ -60,22 +60,12 @@
 
     *format = SDL_PIXELFORMAT_UNKNOWN;
     if (info->bmiHeader.biCompression == BI_BITFIELDS) {
+        int bpp;
         Uint32 *masks;
 
+        bpp = info->bmiHeader.biPlanes * info->bmiHeader.biBitCount;
         masks = (Uint32*)((Uint8*)info + info->bmiHeader.biSize);
-        if (masks[0] == 0x00FF0000 && masks[2] == 0x000000FF) {
-            *format = SDL_PIXELFORMAT_RGB888;
-        } else if (masks[0] == 0x000000FF && masks[2] == 0x00FF0000) {
-            *format = SDL_PIXELFORMAT_BGR888;
-        } else if (masks[0] == 0xF800 && masks[2] == 0x001F) {
-            *format = SDL_PIXELFORMAT_RGB565;
-        } else if (masks[0] == 0x001F && masks[2] == 0xF800) {
-            *format = SDL_PIXELFORMAT_BGR565;
-        } else if (masks[0] == 0x7C00 && masks[2] == 0x001F) {
-            *format = SDL_PIXELFORMAT_RGB555;
-        } else if (masks[0] == 0x001F && masks[2] == 0x7C00) {
-            *format = SDL_PIXELFORMAT_BGR555;
-        }
+        *format = SDL_MasksToPixelFormatEnum(bpp, masks[0], masks[1], masks[2], 0);
     }
     if (*format == SDL_PIXELFORMAT_UNKNOWN)
 #endif