From 914624f0b8b92986ef385e9650ee7b5fb07099e9 Mon Sep 17 00:00:00 2001 From: Frank Barchard Date: Fri, 19 Jan 2024 10:40:56 -0800 Subject: [PATCH] YUY2ToARGBMatrix and UYVYToARGBMatrix added to allow any color matrix Bug: libyuv:971 Change-Id: If15d4598d75500a3717f07d02c0c295fdc58254e Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/5214453 Reviewed-by: richard winterton Commit-Queue: Frank Barchard --- README.chromium | 2 +- include/libyuv/convert_argb.h | 20 +++++++++++++ include/libyuv/version.h | 2 +- source/convert_argb.cc | 51 ++++++++++++++++++++++++++-------- unit_test/convert_argb_test.cc | 36 +++++++++++++++++++++--- 5 files changed, 93 insertions(+), 18 deletions(-) diff --git a/README.chromium b/README.chromium index 648858823..c2579027c 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: https://chromium.googlesource.com/libyuv/libyuv/ -Version: 1884 +Version: 1885 License: BSD License File: LICENSE Shipped: yes diff --git a/include/libyuv/convert_argb.h b/include/libyuv/convert_argb.h index 35eeac9b2..5b5056744 100644 --- a/include/libyuv/convert_argb.h +++ b/include/libyuv/convert_argb.h @@ -1904,6 +1904,26 @@ int NV21ToRGB24Matrix(const uint8_t* src_y, int width, int height); +// Convert YUY2 to ARGB with matrix. +LIBYUV_API +int YUY2ToARGBMatrix(const uint8_t* src_yuy2, + int src_stride_yuy2, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert UYVY to ARGB with matrix. +LIBYUV_API +int UYVYToARGBMatrix(const uint8_t* src_uyvy, + int src_stride_uyvy, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + // Convert Android420 to ARGB with matrix. LIBYUV_API int Android420ToARGBMatrix(const uint8_t* src_y, diff --git a/include/libyuv/version.h b/include/libyuv/version.h index 0de054cc6..76108e644 100644 --- a/include/libyuv/version.h +++ b/include/libyuv/version.h @@ -11,6 +11,6 @@ #ifndef INCLUDE_LIBYUV_VERSION_H_ #define INCLUDE_LIBYUV_VERSION_H_ -#define LIBYUV_VERSION 1884 +#define LIBYUV_VERSION 1885 #endif // INCLUDE_LIBYUV_VERSION_H_ diff --git a/source/convert_argb.cc b/source/convert_argb.cc index 871fea599..3655e30a2 100644 --- a/source/convert_argb.cc +++ b/source/convert_argb.cc @@ -4455,14 +4455,15 @@ int NV21ToYUV24(const uint8_t* src_y, return 0; } -// Convert YUY2 to ARGB. +// Convert YUY2 to ARGB with matrix. LIBYUV_API -int YUY2ToARGB(const uint8_t* src_yuy2, - int src_stride_yuy2, - uint8_t* dst_argb, - int dst_stride_argb, - int width, - int height) { +int YUY2ToARGBMatrix(const uint8_t* src_yuy2, + int src_stride_yuy2, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { int y; void (*YUY2ToARGBRow)(const uint8_t* src_yuy2, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) = @@ -4523,21 +4524,34 @@ int YUY2ToARGB(const uint8_t* src_yuy2, } #endif for (y = 0; y < height; ++y) { - YUY2ToARGBRow(src_yuy2, dst_argb, &kYuvI601Constants, width); + YUY2ToARGBRow(src_yuy2, dst_argb, yuvconstants, width); src_yuy2 += src_stride_yuy2; dst_argb += dst_stride_argb; } return 0; } -// Convert UYVY to ARGB. +// Convert YUY2 to ARGB. LIBYUV_API -int UYVYToARGB(const uint8_t* src_uyvy, - int src_stride_uyvy, +int YUY2ToARGB(const uint8_t* src_yuy2, + int src_stride_yuy2, uint8_t* dst_argb, int dst_stride_argb, int width, int height) { + return YUY2ToARGBMatrix(src_yuy2, src_stride_yuy2, dst_argb, dst_stride_argb, + &kYuvI601Constants, width, height); +} + +// Convert UYVY to ARGB with matrix. +LIBYUV_API +int UYVYToARGBMatrix(const uint8_t* src_uyvy, + int src_stride_uyvy, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { int y; void (*UYVYToARGBRow)(const uint8_t* src_uyvy, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) = @@ -4598,12 +4612,25 @@ int UYVYToARGB(const uint8_t* src_uyvy, } #endif for (y = 0; y < height; ++y) { - UYVYToARGBRow(src_uyvy, dst_argb, &kYuvI601Constants, width); + UYVYToARGBRow(src_uyvy, dst_argb, yuvconstants, width); src_uyvy += src_stride_uyvy; dst_argb += dst_stride_argb; } return 0; } + +// Convert UYVY to ARGB. +LIBYUV_API +int UYVYToARGB(const uint8_t* src_uyvy, + int src_stride_uyvy, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + return UYVYToARGBMatrix(src_uyvy, src_stride_uyvy, dst_argb, dst_stride_argb, + &kYuvI601Constants, width, height); +} + static void WeavePixels(const uint8_t* src_u, const uint8_t* src_v, int src_pixel_stride_uv, diff --git a/unit_test/convert_argb_test.cc b/unit_test/convert_argb_test.cc index aeee8a7fc..6074c8204 100644 --- a/unit_test/convert_argb_test.cc +++ b/unit_test/convert_argb_test.cc @@ -2682,19 +2682,47 @@ TEST_F(LibYUVConvertTest, TestARGBToRGB24) { free_aligned_buffer_page_end(dest_rgb24); } -TEST_F(LibYUVConvertTest, Test565) { +TEST_F(LibYUVConvertTest, TestARGBToRGB565) { SIMD_ALIGNED(uint8_t orig_pixels[256][4]); - SIMD_ALIGNED(uint8_t pixels565[256][2]); + SIMD_ALIGNED(uint8_t dest_rgb565[256][2]); for (int i = 0; i < 256; ++i) { for (int j = 0; j < 4; ++j) { orig_pixels[i][j] = i; } } - ARGBToRGB565(&orig_pixels[0][0], 0, &pixels565[0][0], 0, 256, 1); - uint32_t checksum = HashDjb2(&pixels565[0][0], sizeof(pixels565), 5381); + ARGBToRGB565(&orig_pixels[0][0], 0, &dest_rgb565[0][0], 0, 256, 1); + uint32_t checksum = HashDjb2(&dest_rgb565[0][0], sizeof(dest_rgb565), 5381); EXPECT_EQ(610919429u, checksum); } + +TEST_F(LibYUVConvertTest, TestYUY2ToARGB) { + SIMD_ALIGNED(uint8_t orig_pixels[256][2]); + SIMD_ALIGNED(uint8_t dest_argb[256][4]); + + for (int i = 0; i < 256; ++i) { + for (int j = 0; j < 2; ++j) { + orig_pixels[i][j] = i; + } + } + YUY2ToARGB(&orig_pixels[0][0], 0, &dest_argb[0][0], 0, 256, 1); + uint32_t checksum = HashDjb2(&dest_argb[0][0], sizeof(dest_argb), 5381); + EXPECT_EQ(3486643515u, checksum); +} + +TEST_F(LibYUVConvertTest, TestUYVYToARGB) { + SIMD_ALIGNED(uint8_t orig_pixels[256][2]); + SIMD_ALIGNED(uint8_t dest_argb[256][4]); + + for (int i = 0; i < 256; ++i) { + for (int j = 0; j < 2; ++j) { + orig_pixels[i][j] = i; + } + } + UYVYToARGB(&orig_pixels[0][0], 0, &dest_argb[0][0], 0, 256, 1); + uint32_t checksum = HashDjb2(&dest_argb[0][0], sizeof(dest_argb), 5381); + EXPECT_EQ(3486643515u, checksum); +} #endif // !defined(LEAN_TESTS) } // namespace libyuv