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 <rrwinterton@gmail.com>
Commit-Queue: Frank Barchard <fbarchard@chromium.org>
This commit is contained in:
Frank Barchard 2024-01-19 10:40:56 -08:00 committed by libyuv LUCI CQ
parent 5625f42424
commit 914624f0b8
5 changed files with 93 additions and 18 deletions

View File

@ -1,6 +1,6 @@
Name: libyuv Name: libyuv
URL: https://chromium.googlesource.com/libyuv/libyuv/ URL: https://chromium.googlesource.com/libyuv/libyuv/
Version: 1884 Version: 1885
License: BSD License: BSD
License File: LICENSE License File: LICENSE
Shipped: yes Shipped: yes

View File

@ -1904,6 +1904,26 @@ int NV21ToRGB24Matrix(const uint8_t* src_y,
int width, int width,
int height); 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. // Convert Android420 to ARGB with matrix.
LIBYUV_API LIBYUV_API
int Android420ToARGBMatrix(const uint8_t* src_y, int Android420ToARGBMatrix(const uint8_t* src_y,

View File

@ -11,6 +11,6 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_ #ifndef INCLUDE_LIBYUV_VERSION_H_
#define INCLUDE_LIBYUV_VERSION_H_ #define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 1884 #define LIBYUV_VERSION 1885
#endif // INCLUDE_LIBYUV_VERSION_H_ #endif // INCLUDE_LIBYUV_VERSION_H_

View File

@ -4455,12 +4455,13 @@ int NV21ToYUV24(const uint8_t* src_y,
return 0; return 0;
} }
// Convert YUY2 to ARGB. // Convert YUY2 to ARGB with matrix.
LIBYUV_API LIBYUV_API
int YUY2ToARGB(const uint8_t* src_yuy2, int YUY2ToARGBMatrix(const uint8_t* src_yuy2,
int src_stride_yuy2, int src_stride_yuy2,
uint8_t* dst_argb, uint8_t* dst_argb,
int dst_stride_argb, int dst_stride_argb,
const struct YuvConstants* yuvconstants,
int width, int width,
int height) { int height) {
int y; int y;
@ -4523,19 +4524,32 @@ int YUY2ToARGB(const uint8_t* src_yuy2,
} }
#endif #endif
for (y = 0; y < height; ++y) { 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; src_yuy2 += src_stride_yuy2;
dst_argb += dst_stride_argb; dst_argb += dst_stride_argb;
} }
return 0; return 0;
} }
// Convert UYVY to ARGB. // Convert YUY2 to ARGB.
LIBYUV_API LIBYUV_API
int UYVYToARGB(const uint8_t* src_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, int src_stride_uyvy,
uint8_t* dst_argb, uint8_t* dst_argb,
int dst_stride_argb, int dst_stride_argb,
const struct YuvConstants* yuvconstants,
int width, int width,
int height) { int height) {
int y; int y;
@ -4598,12 +4612,25 @@ int UYVYToARGB(const uint8_t* src_uyvy,
} }
#endif #endif
for (y = 0; y < height; ++y) { 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; src_uyvy += src_stride_uyvy;
dst_argb += dst_stride_argb; dst_argb += dst_stride_argb;
} }
return 0; 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, static void WeavePixels(const uint8_t* src_u,
const uint8_t* src_v, const uint8_t* src_v,
int src_pixel_stride_uv, int src_pixel_stride_uv,

View File

@ -2682,19 +2682,47 @@ TEST_F(LibYUVConvertTest, TestARGBToRGB24) {
free_aligned_buffer_page_end(dest_rgb24); 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 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 i = 0; i < 256; ++i) {
for (int j = 0; j < 4; ++j) { for (int j = 0; j < 4; ++j) {
orig_pixels[i][j] = i; orig_pixels[i][j] = i;
} }
} }
ARGBToRGB565(&orig_pixels[0][0], 0, &pixels565[0][0], 0, 256, 1); ARGBToRGB565(&orig_pixels[0][0], 0, &dest_rgb565[0][0], 0, 256, 1);
uint32_t checksum = HashDjb2(&pixels565[0][0], sizeof(pixels565), 5381); uint32_t checksum = HashDjb2(&dest_rgb565[0][0], sizeof(dest_rgb565), 5381);
EXPECT_EQ(610919429u, checksum); 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) #endif // !defined(LEAN_TESTS)
} // namespace libyuv } // namespace libyuv