From 80614b27e410f49433e6bf65e5a209d67902d68d Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 31 May 2015 11:38:10 -0400 Subject: [PATCH] Fixed swizzle of SDL_FillRect() on 24-bit surface (thanks, "nagydavid91"!). Fixes Bugzilla #2986. --- src/video/SDL_fillrect.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/video/SDL_fillrect.c b/src/video/SDL_fillrect.c index cf7e86d17539b..2282d2b1991ef 100644 --- a/src/video/SDL_fillrect.c +++ b/src/video/SDL_fillrect.c @@ -196,9 +196,15 @@ SDL_FillRect2(Uint8 * pixels, int pitch, Uint32 color, int w, int h) static void SDL_FillRect3(Uint8 * pixels, int pitch, Uint32 color, int w, int h) { - Uint8 r = (Uint8) ((color >> 16) & 0xFF); - Uint8 g = (Uint8) ((color >> 8) & 0xFF); - Uint8 b = (Uint8) (color & 0xFF); +#if SDL_BYTEORDER == SDL_LIL_ENDIAN + Uint8 b1 = (Uint8) (color & 0xFF); + Uint8 b2 = (Uint8) ((color >> 8) & 0xFF); + Uint8 b3 = (Uint8) ((color >> 16) & 0xFF); +#elif SDL_BYTEORDER == SDL_BIG_ENDIAN + Uint8 b1 = (Uint8) ((color >> 16) & 0xFF); + Uint8 b2 = (Uint8) ((color >> 8) & 0xFF); + Uint8 b3 = (Uint8) (color & 0xFF); +#endif int n; Uint8 *p = NULL; @@ -207,9 +213,9 @@ SDL_FillRect3(Uint8 * pixels, int pitch, Uint32 color, int w, int h) p = pixels; while (n--) { - *p++ = r; - *p++ = g; - *p++ = b; + *p++ = b1; + *p++ = b2; + *p++ = b3; } pixels += pitch; }