Use the default colorspace if we have to convert texture pixels

main
Sam Lantinga 2024-01-30 23:11:18 -08:00
parent c1f97c8e07
commit 49cc4c14e9
1 changed files with 22 additions and 17 deletions

View File

@ -1334,7 +1334,7 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
Uint32 format = SDL_PIXELFORMAT_UNKNOWN;
SDL_Texture *texture;
SDL_PropertiesID props;
Uint32 default_colorspace, colorspace;
SDL_Colorspace default_colorspace, colorspace;
CHECK_RENDERER_MAGIC(renderer, NULL);
@ -1400,8 +1400,27 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
}
}
default_colorspace = SDL_GetDefaultTextureColorspace(format);
colorspace = (Uint32)SDL_GetNumberProperty(SDL_GetSurfaceProperties(surface), SDL_PROP_SURFACE_COLORSPACE_NUMBER, default_colorspace);
if (format == surface->format->format) {
if (surface->format->Amask && SDL_SurfaceHasColorKey(surface)) {
/* Surface and Renderer formats are identical.
* Intermediate conversion is needed to convert color key to alpha (SDL_ConvertColorkeyToAlpha()). */
direct_update = SDL_FALSE;
} else {
/* Update Texture directly */
direct_update = SDL_TRUE;
}
} else {
/* Surface and Renderer formats are different, it needs an intermediate conversion. */
direct_update = SDL_FALSE;
}
if (direct_update) {
default_colorspace = SDL_GetDefaultTextureColorspace(format);
colorspace = (SDL_Colorspace)SDL_GetNumberProperty(SDL_GetSurfaceProperties(surface), SDL_PROP_SURFACE_COLORSPACE_NUMBER, default_colorspace);
} else {
/* We're updating through an intermediate surface, so we lose colorspace information */
colorspace = SDL_COLORSPACE_RGB_DEFAULT;
}
props = SDL_CreateProperties();
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER, colorspace);
@ -1414,20 +1433,6 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
return NULL;
}
if (format == surface->format->format) {
if (surface->format->Amask && SDL_SurfaceHasColorKey(surface)) {
/* Surface and Renderer formats are identicals.
* Intermediate conversion is needed to convert color key to alpha (SDL_ConvertColorkeyToAlpha()). */
direct_update = SDL_FALSE;
} else {
/* Update Texture directly */
direct_update = SDL_TRUE;
}
} else {
/* Surface and Renderer formats are different, it needs an intermediate conversion. */
direct_update = SDL_FALSE;
}
if (direct_update) {
if (SDL_MUSTLOCK(surface)) {
SDL_LockSurface(surface);