From 02036ee643e70442eccc2129eee9cdae001436fa 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
(cherry picked from commit 36fc1c2c9c280a47fc4412a90bb17488b20592d5)
---
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 60024b85b74ff..7920a120212e9 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -1658,8 +1658,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)) {
@@ -1721,6 +1719,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)) {