SDL: Fixed texture colorspace when creating a texture from a surface

From 36fc1c2c9c280a47fc4412a90bb17488b20592d5 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 31 Mar 2025 18:49:58 -0700
Subject: [PATCH] Fixed texture colorspace when creating a texture from a
 surface

Fixes https://github.com/libsdl-org/SDL/issues/12691
---
 src/render/SDL_render.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index ca23ce5714ce8..80b0cfd295844 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -1677,8 +1677,6 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
         }
     }
 
-    surface_colorspace = SDL_GetSurfaceColorspace(surface);
-
     // Try to have the best pixel format for the texture
     // No alpha, but a colorkey => promote to alpha
     if (!SDL_ISPIXELFORMAT_ALPHA(surface->format) && SDL_SurfaceHasColorKey(surface)) {
@@ -1740,6 +1738,9 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
         }
     }
 
+    surface_colorspace = SDL_GetSurfaceColorspace(surface);
+    texture_colorspace = surface_colorspace;
+
     if (surface_colorspace == SDL_COLORSPACE_SRGB_LINEAR ||
         SDL_COLORSPACETRANSFER(surface_colorspace) == SDL_TRANSFER_CHARACTERISTICS_PQ) {
         if (SDL_ISPIXELFORMAT_FLOAT(format)) {