Commit 36e40d30fc93eef6f0bdf167ae9f522485595bc2

Sam Lantinga 2016-10-11T23:19:05

Fixed bug 2923 - Add SDL_PIXELFORMAT_RGBA32 for byte-wise 32bit RGBA data Daniel Gibson Ok, I followed the simple approach of just making SDL_PIXELFORMAT_RGBA32 an alias of SDL_PIXELFORMAT_RGBA8888/SDL_PIXELFORMAT_ABGR8888, depending on endianess. And I did the same for SDL_PIXELFORMAT_ARGB32, .._BGRA, .._ABGR. SDL_GetPixelFormatName() will of course return SDL_PIXELFORMAT_RGBA8888 (or SDL_PIXELFORMAT_ABGR8888) instead of SDL_PIXELFORMAT_RGBA32, but as long as that's mentioned in the docs it shouldn't be a problem.

diff --git a/include/SDL_pixels.h b/include/SDL_pixels.h
index 8499c32..2e22b32 100644
--- a/include/SDL_pixels.h
+++ b/include/SDL_pixels.h
@@ -29,6 +29,7 @@
 #define _SDL_pixels_h
 
 #include "SDL_stdinc.h"
+#include "SDL_endian.h"
 
 #include "begin_code.h"
 /* Set up for C function definitions, even when using C++ */
@@ -260,6 +261,19 @@ enum
         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
                                SDL_PACKEDLAYOUT_2101010, 32, 4),
 
+    /* Aliases for RGBA array of color formats for the current platform */
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+    SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_RGBA8888, /**< endianess-specific alias for byte-wise 32bit RGBA data */
+    SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_ARGB8888,
+    SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_BGRA8888,
+    SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_ABGR8888,
+#else
+    SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_ABGR8888,
+    SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_BGRA8888,
+    SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_ARGB8888,
+    SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_RGBA8888,
+#endif
+
     SDL_PIXELFORMAT_YV12 =      /**< Planar mode: Y + V + U  (3 planes) */
         SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
     SDL_PIXELFORMAT_IYUV =      /**< Planar mode: Y + U + V  (3 planes) */
diff --git a/src/render/software/SDL_rotate.c b/src/render/software/SDL_rotate.c
index b93454d..0141d17 100644
--- a/src/render/software/SDL_rotate.c
+++ b/src/render/software/SDL_rotate.c
@@ -444,14 +444,7 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, 
         */
         rz_src = src;
     } else {
-        Uint32 format = SDL_MasksToPixelFormatEnum(32,
-#if SDL_BYTEORDER == SDL_LIL_ENDIAN
-            0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
-#else
-            0xff000000,  0x00ff0000, 0x0000ff00, 0x000000ff
-#endif
-        );
-        rz_src = SDL_ConvertSurfaceFormat(src, format, src->flags);
+        rz_src = SDL_ConvertSurfaceFormat(src, SDL_PIXELFORMAT_ARGB32, src->flags);
         if (rz_src == NULL) {
             return NULL;
         }
diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c
index 8b72489..2d9cf24 100644
--- a/src/video/SDL_bmp.c
+++ b/src/video/SDL_bmp.c
@@ -533,13 +533,7 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
             /* If the surface has a colorkey or alpha channel we'll save a
                32-bit BMP with alpha channel, otherwise save a 24-bit BMP. */
             if (save32bit) {
-                SDL_InitFormat(&format,
-#if SDL_BYTEORDER == SDL_LIL_ENDIAN
-                               SDL_PIXELFORMAT_ARGB8888
-#else
-                               SDL_PIXELFORMAT_BGRA8888
-#endif
-                               );
+                SDL_InitFormat(&format, SDL_PIXELFORMAT_BGRA32);
             } else {
                 SDL_InitFormat(&format, SDL_PIXELFORMAT_BGR24);
             }
diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m
index 92805f5..e436e65 100644
--- a/src/video/cocoa/SDL_cocoavideo.m
+++ b/src/video/cocoa/SDL_cocoavideo.m
@@ -176,13 +176,7 @@ Cocoa_CreateImage(SDL_Surface * surface)
     int i;
     NSImage *img;
 
-    converted = SDL_ConvertSurfaceFormat(surface,
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-                                         SDL_PIXELFORMAT_RGBA8888,
-#else
-                                         SDL_PIXELFORMAT_ABGR8888,
-#endif
-                                         0);
+    converted = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA32, 0);
     if (!converted) {
         return nil;
     }