Make sure fast path RGB <-> YUV conversions are using the same color primaries

main
Sam Lantinga 2024-03-05 17:43:08 -08:00
parent 4545c77c9e
commit ee87132385
1 changed files with 19 additions and 14 deletions

View File

@ -593,12 +593,14 @@ int SDL_ConvertPixels_YUV_to_RGB(int width, int height,
const Uint8 *v = NULL;
Uint32 y_stride = 0;
Uint32 uv_stride = 0;
YCbCrType yuv_type = YCBCR_601_LIMITED;
if (GetYUVPlanes(width, height, src_format, src, src_pitch, &y, &u, &v, &y_stride, &uv_stride) < 0) {
return -1;
}
if (SDL_COLORSPACEPRIMARIES(src_colorspace) == SDL_COLORSPACEPRIMARIES(dst_colorspace)) {
YCbCrType yuv_type = YCBCR_601_LIMITED;
if (GetYUVConversionType(src_colorspace, &yuv_type) < 0) {
return -1;
}
@ -614,6 +616,7 @@ int SDL_ConvertPixels_YUV_to_RGB(int width, int height,
if (yuv_rgb_std(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8 *)dst, dst_pitch, yuv_type)) {
return 0;
}
}
/* No fast path for the RGB format, instead convert using an intermediate buffer */
if (src_format == SDL_PIXELFORMAT_P010 && dst_format != SDL_PIXELFORMAT_XBGR2101010) {
@ -1146,12 +1149,14 @@ int SDL_ConvertPixels_RGB_to_YUV(int width, int height,
#endif
/* ARGB8888 to FOURCC */
if (src_format == SDL_PIXELFORMAT_ARGB8888) {
if (src_format == SDL_PIXELFORMAT_ARGB8888 &&
SDL_COLORSPACEPRIMARIES(src_colorspace) == SDL_COLORSPACEPRIMARIES(dst_colorspace)) {
return SDL_ConvertPixels_ARGB8888_to_YUV(width, height, src, src_pitch, dst_format, dst, dst_pitch, yuv_type);
}
if (dst_format == SDL_PIXELFORMAT_P010) {
if (src_format == SDL_PIXELFORMAT_XBGR2101010) {
if (src_format == SDL_PIXELFORMAT_XBGR2101010 &&
SDL_COLORSPACEPRIMARIES(src_colorspace) == SDL_COLORSPACEPRIMARIES(dst_colorspace)) {
return SDL_ConvertPixels_XBGR2101010_to_P010(width, height, src, src_pitch, dst_format, dst, dst_pitch, yuv_type);
}