Fixed bug 2923 - Add SDL_PIXELFORMAT_RGBA32 for byte-wise 32bit RGBA data
authorSam Lantinga <slouken@libsdl.org>
Tue, 11 Oct 2016 23:19:05 -0700
changeset 10512c6d79a1bec47
parent 10511 8e646a2d1929
child 10513 929a96567efa
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.
include/SDL_pixels.h
src/render/software/SDL_rotate.c
src/video/SDL_bmp.c
src/video/cocoa/SDL_cocoavideo.m
     1.1 --- a/include/SDL_pixels.h	Tue Oct 11 16:36:40 2016 -0400
     1.2 +++ b/include/SDL_pixels.h	Tue Oct 11 23:19:05 2016 -0700
     1.3 @@ -29,6 +29,7 @@
     1.4  #define _SDL_pixels_h
     1.5  
     1.6  #include "SDL_stdinc.h"
     1.7 +#include "SDL_endian.h"
     1.8  
     1.9  #include "begin_code.h"
    1.10  /* Set up for C function definitions, even when using C++ */
    1.11 @@ -260,6 +261,19 @@
    1.12          SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
    1.13                                 SDL_PACKEDLAYOUT_2101010, 32, 4),
    1.14  
    1.15 +    /* Aliases for RGBA array of color formats for the current platform */
    1.16 +#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    1.17 +    SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_RGBA8888, /**< endianess-specific alias for byte-wise 32bit RGBA data */
    1.18 +    SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_ARGB8888,
    1.19 +    SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_BGRA8888,
    1.20 +    SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_ABGR8888,
    1.21 +#else
    1.22 +    SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_ABGR8888,
    1.23 +    SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_BGRA8888,
    1.24 +    SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_ARGB8888,
    1.25 +    SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_RGBA8888,
    1.26 +#endif
    1.27 +
    1.28      SDL_PIXELFORMAT_YV12 =      /**< Planar mode: Y + V + U  (3 planes) */
    1.29          SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
    1.30      SDL_PIXELFORMAT_IYUV =      /**< Planar mode: Y + U + V  (3 planes) */
     2.1 --- a/src/render/software/SDL_rotate.c	Tue Oct 11 16:36:40 2016 -0400
     2.2 +++ b/src/render/software/SDL_rotate.c	Tue Oct 11 23:19:05 2016 -0700
     2.3 @@ -444,14 +444,7 @@
     2.4          */
     2.5          rz_src = src;
     2.6      } else {
     2.7 -        Uint32 format = SDL_MasksToPixelFormatEnum(32,
     2.8 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
     2.9 -            0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
    2.10 -#else
    2.11 -            0xff000000,  0x00ff0000, 0x0000ff00, 0x000000ff
    2.12 -#endif
    2.13 -        );
    2.14 -        rz_src = SDL_ConvertSurfaceFormat(src, format, src->flags);
    2.15 +        rz_src = SDL_ConvertSurfaceFormat(src, SDL_PIXELFORMAT_ARGB32, src->flags);
    2.16          if (rz_src == NULL) {
    2.17              return NULL;
    2.18          }
     3.1 --- a/src/video/SDL_bmp.c	Tue Oct 11 16:36:40 2016 -0400
     3.2 +++ b/src/video/SDL_bmp.c	Tue Oct 11 23:19:05 2016 -0700
     3.3 @@ -533,13 +533,7 @@
     3.4              /* If the surface has a colorkey or alpha channel we'll save a
     3.5                 32-bit BMP with alpha channel, otherwise save a 24-bit BMP. */
     3.6              if (save32bit) {
     3.7 -                SDL_InitFormat(&format,
     3.8 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
     3.9 -                               SDL_PIXELFORMAT_ARGB8888
    3.10 -#else
    3.11 -                               SDL_PIXELFORMAT_BGRA8888
    3.12 -#endif
    3.13 -                               );
    3.14 +                SDL_InitFormat(&format, SDL_PIXELFORMAT_BGRA32);
    3.15              } else {
    3.16                  SDL_InitFormat(&format, SDL_PIXELFORMAT_BGR24);
    3.17              }
     4.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Tue Oct 11 16:36:40 2016 -0400
     4.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Tue Oct 11 23:19:05 2016 -0700
     4.3 @@ -176,13 +176,7 @@
     4.4      int i;
     4.5      NSImage *img;
     4.6  
     4.7 -    converted = SDL_ConvertSurfaceFormat(surface,
     4.8 -#if SDL_BYTEORDER == SDL_BIG_ENDIAN
     4.9 -                                         SDL_PIXELFORMAT_RGBA8888,
    4.10 -#else
    4.11 -                                         SDL_PIXELFORMAT_ABGR8888,
    4.12 -#endif
    4.13 -                                         0);
    4.14 +    converted = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA32, 0);
    4.15      if (!converted) {
    4.16          return nil;
    4.17      }