SDL_image: qoi: Fix channel order on big-endian platforms

From 7bc6c7ef4bd1fb7d2d6bc2a2ec34d927fdf4c16d Mon Sep 17 00:00:00 2001
From: Simon McVittie <[EMAIL REDACTED]>
Date: Wed, 25 May 2022 13:30:03 +0100
Subject: [PATCH] qoi: Fix channel order on big-endian platforms

qoi.h always decodes the red channel of the first pixel into the first
byte of the buffer, regardless of whether interpreting the buffer as
a sequence of 32-bit words would consider that to be the most or least
significant byte of the first word. In SDL terminology that's
SDL_PIXELFORMAT_RGBA32.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 IMG_qoi.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/IMG_qoi.c b/IMG_qoi.c
index fbefe6cc..6533bab7 100644
--- a/IMG_qoi.c
+++ b/IMG_qoi.c
@@ -81,20 +81,19 @@ SDL_Surface *IMG_LoadQOI_RW(SDL_RWops *src)
     }
 
     pixel_data = qoi_decode(data, (int)size, &image_info, 4);
+    /* pixel_data is in R,G,B,A order regardless of endianness */
     SDL_free(data);
     if ( !pixel_data ) {
         IMG_SetError("Couldn't parse QOI image");
         return NULL;
     }
 
-    surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
-                                   image_info.width,
-                                   image_info.height,
-                                   32,
-                                   0x000000FF,
-                                   0x0000FF00,
-                                   0x00FF0000,
-                                   0xFF000000);
+    surface = SDL_CreateRGBSurfaceWithFormat(0,
+                                             image_info.width,
+                                             image_info.height,
+                                             32,
+                                             SDL_PIXELFORMAT_RGBA32);
+
     if ( !surface ) {
         SDL_free(pixel_data);
         IMG_SetError("Couldn't create SDL_Surface");