Use a reasonable default for unspecified YUV colorspace

This commit is contained in:
Sam Lantinga
2024-02-05 11:20:14 -08:00
parent 240158f3e8
commit c3e4481d56
8 changed files with 138 additions and 87 deletions

View File

@@ -558,7 +558,7 @@ static int D3D_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P
}
texturedata->shader = SHADER_YUV;
texturedata->shader_params = SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace);
texturedata->shader_params = SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace, texture->w, texture->h, 8);
if (texturedata->shader_params == NULL) {
return SDL_SetError("Unsupported YUV colorspace");
}

View File

@@ -1297,7 +1297,7 @@ static int D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL
SDL_SetProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_D3D11_TEXTURE_V_POINTER, textureData->mainTextureV);
textureData->shader = SHADER_YUV;
textureData->shader_params = SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace);
textureData->shader_params = SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace, texture->w, texture->h, 8);
if (!textureData->shader_params) {
return SDL_SetError("Unsupported YUV colorspace");
}
@@ -1306,6 +1306,8 @@ static int D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL
texture->format == SDL_PIXELFORMAT_NV21 ||
texture->format == SDL_PIXELFORMAT_P010 ||
texture->format == SDL_PIXELFORMAT_P016) {
int bits_per_pixel;
textureData->nv12 = SDL_TRUE;
switch (texture->format) {
@@ -1328,7 +1330,18 @@ static int D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL
/* This should never happen because of the check above */
return SDL_SetError("Unsupported YUV colorspace");
}
textureData->shader_params = SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace);
switch (texture->format) {
case SDL_PIXELFORMAT_P010:
bits_per_pixel = 10;
break;
case SDL_PIXELFORMAT_P016:
bits_per_pixel = 16;
break;
default:
bits_per_pixel = 8;
break;
}
textureData->shader_params = SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace, texture->w, texture->h, bits_per_pixel);
if (!textureData->shader_params) {
return SDL_SetError("Unsupported YUV colorspace");
}

View File

@@ -1641,7 +1641,7 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL
SDL_SetProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_D3D12_TEXTURE_V_POINTER, textureData->mainTextureV);
textureData->shader = SHADER_YUV;
textureData->shader_params = SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace);
textureData->shader_params = SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace, texture->w, texture->h, 8);
if (!textureData->shader_params) {
return SDL_SetError("Unsupported YUV colorspace");
}
@@ -1652,7 +1652,7 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL
textureData->nv12 = SDL_TRUE;
textureData->shader = (texture->format == SDL_PIXELFORMAT_NV12 ? SHADER_NV12 : SHADER_NV21);
textureData->shader_params = SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace);
textureData->shader_params = SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace, texture->w, texture->h, 8);
if (!textureData->shader_params) {
return SDL_SetError("Unsupported YUV colorspace");
}

View File

@@ -1822,10 +1822,10 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window *window, SDL_PropertiesID c
constantdata = [mtlbufconstantstaging contents];
SDL_memcpy(constantdata + CONSTANTS_OFFSET_IDENTITY, identitytransform, sizeof(identitytransform));
SDL_memcpy(constantdata + CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM, halfpixeltransform, sizeof(halfpixeltransform));
SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_BT601_LIMITED, SDL_GetYCbCRtoRGBConversionMatrix(SDL_COLORSPACE_BT601_LIMITED), YCbCr_shader_matrix_size);
SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_BT601_FULL, SDL_GetYCbCRtoRGBConversionMatrix(SDL_COLORSPACE_BT601_FULL), YCbCr_shader_matrix_size);
SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_BT709_LIMITED, SDL_GetYCbCRtoRGBConversionMatrix(SDL_COLORSPACE_BT709_LIMITED), YCbCr_shader_matrix_size);
SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_BT709_FULL, SDL_GetYCbCRtoRGBConversionMatrix(SDL_COLORSPACE_BT709_FULL), YCbCr_shader_matrix_size);
SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_BT601_LIMITED, SDL_GetYCbCRtoRGBConversionMatrix(SDL_COLORSPACE_BT601_LIMITED, 0, 0, 8), YCbCr_shader_matrix_size);
SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_BT601_FULL, SDL_GetYCbCRtoRGBConversionMatrix(SDL_COLORSPACE_BT601_FULL, 0, 0, 8), YCbCr_shader_matrix_size);
SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_BT709_LIMITED, SDL_GetYCbCRtoRGBConversionMatrix(SDL_COLORSPACE_BT709_LIMITED, 0, 0, 8), YCbCr_shader_matrix_size);
SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_BT709_FULL, SDL_GetYCbCRtoRGBConversionMatrix(SDL_COLORSPACE_BT709_FULL, 0, 0, 8), YCbCr_shader_matrix_size);
mtlbufquadindicesstaging = [data.mtldevice newBufferWithLength:indicessize options:MTLResourceStorageModeShared];

View File

@@ -680,7 +680,7 @@ static int GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Pr
data->shader = SHADER_NV21_RA;
}
}
data->shader_params = SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace);
data->shader_params = SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace, texture->w, texture->h, 8);
if (!data->shader_params) {
return SDL_SetError("Unsupported YUV colorspace");
}

View File

@@ -629,7 +629,7 @@ static int GLES2_SelectProgram(GLES2_RenderData *data, GLES2_ImageSource source,
#if SDL_HAVE_YUV
case GLES2_IMAGESOURCE_TEXTURE_YUV:
ftype = GLES2_SHADER_FRAGMENT_TEXTURE_YUV;
shader_params = SDL_GetYCbCRtoRGBConversionMatrix(colorspace);
shader_params = SDL_GetYCbCRtoRGBConversionMatrix(colorspace, 0, 0, 8);
if (!shader_params) {
SDL_SetError("Unsupported YUV colorspace");
goto fault;
@@ -641,7 +641,7 @@ static int GLES2_SelectProgram(GLES2_RenderData *data, GLES2_ImageSource source,
} else {
ftype = GLES2_SHADER_FRAGMENT_TEXTURE_NV12_RA;
}
shader_params = SDL_GetYCbCRtoRGBConversionMatrix(colorspace);
shader_params = SDL_GetYCbCRtoRGBConversionMatrix(colorspace, 0, 0, 8);
if (!shader_params) {
SDL_SetError("Unsupported YUV colorspace");
goto fault;
@@ -653,7 +653,7 @@ static int GLES2_SelectProgram(GLES2_RenderData *data, GLES2_ImageSource source,
} else {
ftype = GLES2_SHADER_FRAGMENT_TEXTURE_NV21_RA;
}
shader_params = SDL_GetYCbCRtoRGBConversionMatrix(colorspace);
shader_params = SDL_GetYCbCRtoRGBConversionMatrix(colorspace, 0, 0, 8);
if (!shader_params) {
SDL_SetError("Unsupported YUV colorspace");
goto fault;
@@ -1548,7 +1548,7 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL
}
SDL_SetNumberProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_U_NUMBER, data->texture_u);
if (!SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace)) {
if (!SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace, texture->w, texture->h, 8)) {
return SDL_SetError("Unsupported YUV colorspace");
}
} else if (data->nv12) {
@@ -1573,7 +1573,7 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL
}
SDL_SetNumberProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_UV_NUMBER, data->texture_u);
if (!SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace)) {
if (!SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace, texture->w, texture->h, 8)) {
return SDL_SetError("Unsupported YUV colorspace");
}
}