diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index 9c24d559a4..4d21bade89 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -5006,8 +5006,22 @@ SDL_Surface *SDL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect) SDL_PropertiesID props = SDL_GetSurfaceProperties(surface); if (renderer->target) { - SDL_SetFloatProperty(props, SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT, renderer->target->SDR_white_point); - SDL_SetFloatProperty(props, SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT, renderer->target->HDR_headroom); + SDL_Texture *target = renderer->target; + SDL_Texture *parent = SDL_GetPointerProperty(SDL_GetTextureProperties(target), SDL_PROP_TEXTURE_PARENT_POINTER, NULL); + SDL_PixelFormat expected_format = (parent ? parent->format : target->format); + + SDL_SetFloatProperty(props, SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT, target->SDR_white_point); + SDL_SetFloatProperty(props, SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT, target->HDR_headroom); + + // Set the expected surface format + if ((surface->format == SDL_PIXELFORMAT_ARGB8888 && expected_format == SDL_PIXELFORMAT_XRGB8888) || + (surface->format == SDL_PIXELFORMAT_RGBA8888 && expected_format == SDL_PIXELFORMAT_RGBX8888) || + (surface->format == SDL_PIXELFORMAT_ABGR8888 && expected_format == SDL_PIXELFORMAT_XBGR8888) || + (surface->format == SDL_PIXELFORMAT_BGRA8888 && expected_format == SDL_PIXELFORMAT_BGRX8888)) { +printf("changing format\n"); + surface->format = expected_format; + surface->fmt = SDL_GetPixelFormatDetails(expected_format); + } } else { SDL_SetFloatProperty(props, SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT, renderer->SDR_white_point); SDL_SetFloatProperty(props, SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT, renderer->HDR_headroom); diff --git a/test/testautomation_render.c b/test/testautomation_render.c index 0b85cfd3b8..25572ee001 100644 --- a/test/testautomation_render.c +++ b/test/testautomation_render.c @@ -897,12 +897,7 @@ static void testBlendModeOperation(TestRenderOperation op, int mode, SDL_PixelFo deltaR = SDL_abs((int)actualR - expectedR); deltaG = SDL_abs((int)actualG - expectedG); deltaB = SDL_abs((int)actualB - expectedB); - if (SDL_ISPIXELFORMAT_ALPHA(dst_format)) { - deltaA = SDL_abs((int)actualA - expectedA); - } else { - // The alpha channel is ignored in non-alpha formats, so don't validate it - deltaA = 0; - } + deltaA = SDL_abs((int)actualA - expectedA); SDLTest_AssertCheck( deltaR <= MAXIMUM_ERROR && deltaG <= MAXIMUM_ERROR &&