diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index d00257fa0..1f757cdd1 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -1453,7 +1453,7 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { #if SDL_HAVE_YUV - texture->yuv = SDL_SW_CreateYUVTexture(format, w, h); + texture->yuv = SDL_SW_CreateYUVTexture(texture->format, texture->colorspace, w, h); #else SDL_SetError("SDL not built with YUV support"); #endif diff --git a/src/render/SDL_yuv_sw.c b/src/render/SDL_yuv_sw.c index 18eaba20b..2b08df219 100644 --- a/src/render/SDL_yuv_sw.c +++ b/src/render/SDL_yuv_sw.c @@ -28,7 +28,7 @@ #include "../video/SDL_blit.h" #include "../video/SDL_yuv_c.h" -SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormat format, int w, int h) +SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormat format, SDL_Colorspace colorspace, int w, int h) { SDL_SW_YUVTexture *swdata; @@ -52,6 +52,7 @@ SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormat format, int w, int h) } swdata->format = format; + swdata->colorspace = colorspace; swdata->target_format = SDL_PIXELFORMAT_UNKNOWN; swdata->w = w; swdata->h = h; @@ -368,6 +369,7 @@ bool SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, SDL if (!swdata->display) { return false; } + swdata->target_format = target_format; } if (!swdata->stretch) { swdata->stretch = SDL_CreateSurface(swdata->w, swdata->h, target_format); @@ -378,7 +380,7 @@ bool SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, SDL pixels = swdata->stretch->pixels; pitch = swdata->stretch->pitch; } - if (!SDL_ConvertPixels(swdata->w, swdata->h, swdata->format, swdata->planes[0], swdata->pitches[0], target_format, pixels, pitch)) { + if (!SDL_ConvertPixelsAndColorspace(swdata->w, swdata->h, swdata->format, swdata->colorspace, 0, swdata->planes[0], swdata->pitches[0], target_format, SDL_COLORSPACE_SRGB, 0, pixels, pitch)) { return false; } if (stretch) { diff --git a/src/render/SDL_yuv_sw_c.h b/src/render/SDL_yuv_sw_c.h index 026989983..76f2e5708 100644 --- a/src/render/SDL_yuv_sw_c.h +++ b/src/render/SDL_yuv_sw_c.h @@ -29,6 +29,7 @@ struct SDL_SW_YUVTexture { SDL_PixelFormat format; + SDL_Colorspace colorspace; SDL_PixelFormat target_format; int w, h; Uint8 *pixels; @@ -44,7 +45,7 @@ struct SDL_SW_YUVTexture typedef struct SDL_SW_YUVTexture SDL_SW_YUVTexture; -extern SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormat format, int w, int h); +extern SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormat format, SDL_Colorspace colorspace, int w, int h); extern bool SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture *swdata, void **pixels, int *pitch); extern bool SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, const void *pixels, int pitch); extern bool SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,