Skip to content

Commit

Permalink
Fixed bug 2923 - Add SDL_PIXELFORMAT_RGBA32 for byte-wise 32bit RGBA …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
slouken committed Oct 12, 2016
1 parent 8a0704d commit 36e40d3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
14 changes: 14 additions & 0 deletions include/SDL_pixels.h
Expand Up @@ -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++ */
Expand Down Expand Up @@ -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) */
Expand Down
9 changes: 1 addition & 8 deletions src/render/software/SDL_rotate.c
Expand Up @@ -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;
}
Expand Down
8 changes: 1 addition & 7 deletions src/video/SDL_bmp.c
Expand Up @@ -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);
}
Expand Down
8 changes: 1 addition & 7 deletions src/video/cocoa/SDL_cocoavideo.m
Expand Up @@ -176,13 +176,7 @@
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;
}
Expand Down

0 comments on commit 36e40d3

Please sign in to comment.