Skip to content

Commit

Permalink
Make sure fast path RGB <-> YUV conversions are using the same color …
Browse files Browse the repository at this point in the history
…primaries
  • Loading branch information
slouken committed Mar 6, 2024
1 parent 4545c77 commit ee87132
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/video/SDL_yuv.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,26 +593,29 @@ 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 (GetYUVConversionType(src_colorspace, &yuv_type) < 0) {
return -1;
}
if (SDL_COLORSPACEPRIMARIES(src_colorspace) == SDL_COLORSPACEPRIMARIES(dst_colorspace)) {
YCbCrType yuv_type = YCBCR_601_LIMITED;

if (yuv_rgb_sse(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8 *)dst, dst_pitch, yuv_type)) {
return 0;
}
if (GetYUVConversionType(src_colorspace, &yuv_type) < 0) {
return -1;
}

if (yuv_rgb_lsx(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8 *)dst, dst_pitch, yuv_type)) {
return 0;
}
if (yuv_rgb_sse(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8 *)dst, dst_pitch, yuv_type)) {
return 0;
}

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;
if (yuv_rgb_lsx(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8 *)dst, dst_pitch, yuv_type)) {
return 0;
}

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 */
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit ee87132

Please sign in to comment.