diff options
author | Yuan Tong <tongyuan200097@gmail.com> | 2021-01-27 08:55:58 +0800 |
---|---|---|
committer | Frank Barchard <fbarchard@chromium.org> | 2021-01-27 19:33:51 +0000 |
commit | a85cc26fde68699f95eceb4ca93c5eb70278787e (patch) | |
tree | 20b7fc40b2d60c528e69fae9c9d6f70b0ae1ed67 /unit_test/planar_test.cc | |
parent | f7c0a73a3ea796e9b1c2a4cf2de319eafe6d1226 (diff) | |
download | libyuv-a85cc26fde68699f95eceb4ca93c5eb70278787e.tar.gz |
Add MergeARGBPlane and SplitARGBPlane
These functions convert between planar and interleaved ARGB,
optionally fill 255 to alpha / discard alpha.
This can help handle YUV(A) with Identity matrix, which is
basically planar ARGB.
libyuv_unittest --gtest_filter=LibYUVPlanarTest.*ARGBPlane*:LibYUVPlanarTest.*XRGBPlane*
R=fbarchard@google.com
Change-Id: I522a189b434f490ba1723ce51317727e7c5eb112
Bug: libyuv:877
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/2649887
Commit-Queue: Frank Barchard <fbarchard@chromium.org>
Reviewed-by: Frank Barchard <fbarchard@chromium.org>
Diffstat (limited to 'unit_test/planar_test.cc')
-rw-r--r-- | unit_test/planar_test.cc | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/unit_test/planar_test.cc b/unit_test/planar_test.cc index e05ff156..fd1755cd 100644 --- a/unit_test/planar_test.cc +++ b/unit_test/planar_test.cc @@ -2776,6 +2776,217 @@ TEST_F(LibYUVPlanarTest, SplitRGBPlane_Opt) { free_aligned_buffer_page_end(dst_pixels_c); } +TEST_F(LibYUVPlanarTest, MergeARGBPlane_Opt) { + // Round count up to multiple of 16 + const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15; + align_buffer_page_end(src_pixels, kPixels * 4); + align_buffer_page_end(tmp_pixels_r, kPixels); + align_buffer_page_end(tmp_pixels_g, kPixels); + align_buffer_page_end(tmp_pixels_b, kPixels); + align_buffer_page_end(tmp_pixels_a, kPixels); + align_buffer_page_end(dst_pixels_opt, kPixels * 4); + align_buffer_page_end(dst_pixels_c, kPixels * 4); + + MemRandomize(src_pixels, kPixels * 4); + MemRandomize(tmp_pixels_r, kPixels); + MemRandomize(tmp_pixels_g, kPixels); + MemRandomize(tmp_pixels_b, kPixels); + MemRandomize(tmp_pixels_a, kPixels); + MemRandomize(dst_pixels_opt, kPixels * 4); + MemRandomize(dst_pixels_c, kPixels * 4); + + MaskCpuFlags(disable_cpu_flags_); + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_r, + benchmark_width_, tmp_pixels_g, benchmark_width_, tmp_pixels_b, + benchmark_width_, tmp_pixels_a, benchmark_width_, + benchmark_width_, benchmark_height_); + MergeARGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g, benchmark_width_, + tmp_pixels_b, benchmark_width_, tmp_pixels_a, benchmark_width_, + dst_pixels_c, benchmark_width_ * 4, benchmark_width_, + benchmark_height_); + + MaskCpuFlags(benchmark_cpu_info_); + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_r, + benchmark_width_, tmp_pixels_g, benchmark_width_, tmp_pixels_b, + benchmark_width_, tmp_pixels_a, benchmark_width_, + benchmark_width_, benchmark_height_); + + for (int i = 0; i < benchmark_iterations_; ++i) { + MergeARGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g, + benchmark_width_, tmp_pixels_b, benchmark_width_, + tmp_pixels_a, benchmark_width_, dst_pixels_opt, + benchmark_width_ * 4, benchmark_width_, benchmark_height_); + } + + for (int i = 0; i < kPixels * 4; ++i) { + EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(tmp_pixels_r); + free_aligned_buffer_page_end(tmp_pixels_g); + free_aligned_buffer_page_end(tmp_pixels_b); + free_aligned_buffer_page_end(tmp_pixels_a); + free_aligned_buffer_page_end(dst_pixels_opt); + free_aligned_buffer_page_end(dst_pixels_c); +} + +TEST_F(LibYUVPlanarTest, SplitARGBPlane_Opt) { + // Round count up to multiple of 16 + const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15; + align_buffer_page_end(src_pixels, kPixels * 4); + align_buffer_page_end(tmp_pixels_r, kPixels); + align_buffer_page_end(tmp_pixels_g, kPixels); + align_buffer_page_end(tmp_pixels_b, kPixels); + align_buffer_page_end(tmp_pixels_a, kPixels); + align_buffer_page_end(dst_pixels_opt, kPixels * 4); + align_buffer_page_end(dst_pixels_c, kPixels * 4); + + MemRandomize(src_pixels, kPixels * 4); + MemRandomize(tmp_pixels_r, kPixels); + MemRandomize(tmp_pixels_g, kPixels); + MemRandomize(tmp_pixels_b, kPixels); + MemRandomize(tmp_pixels_a, kPixels); + MemRandomize(dst_pixels_opt, kPixels * 4); + MemRandomize(dst_pixels_c, kPixels * 4); + + MaskCpuFlags(disable_cpu_flags_); + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_r, + benchmark_width_, tmp_pixels_g, benchmark_width_, tmp_pixels_b, + benchmark_width_, tmp_pixels_a, benchmark_width_, + benchmark_width_, benchmark_height_); + MergeARGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g, benchmark_width_, + tmp_pixels_b, benchmark_width_, tmp_pixels_a, benchmark_width_, + dst_pixels_c, benchmark_width_ * 4, benchmark_width_, + benchmark_height_); + + MaskCpuFlags(benchmark_cpu_info_); + for (int i = 0; i < benchmark_iterations_; ++i) { + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_r, + benchmark_width_, tmp_pixels_g, benchmark_width_, + tmp_pixels_b, benchmark_width_, tmp_pixels_a, + benchmark_width_, benchmark_width_, benchmark_height_); + } + + MergeARGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g, benchmark_width_, + tmp_pixels_b, benchmark_width_, tmp_pixels_a, benchmark_width_, + dst_pixels_opt, benchmark_width_ * 4, benchmark_width_, + benchmark_height_); + + for (int i = 0; i < kPixels * 4; ++i) { + EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(tmp_pixels_r); + free_aligned_buffer_page_end(tmp_pixels_g); + free_aligned_buffer_page_end(tmp_pixels_b); + free_aligned_buffer_page_end(tmp_pixels_a); + free_aligned_buffer_page_end(dst_pixels_opt); + free_aligned_buffer_page_end(dst_pixels_c); +} + +TEST_F(LibYUVPlanarTest, MergeXRGBPlane_Opt) { + // Round count up to multiple of 16 + const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15; + align_buffer_page_end(src_pixels, kPixels * 4); + align_buffer_page_end(tmp_pixels_r, kPixels); + align_buffer_page_end(tmp_pixels_g, kPixels); + align_buffer_page_end(tmp_pixels_b, kPixels); + align_buffer_page_end(dst_pixels_opt, kPixels * 4); + align_buffer_page_end(dst_pixels_c, kPixels * 4); + + MemRandomize(src_pixels, kPixels * 4); + MemRandomize(tmp_pixels_r, kPixels); + MemRandomize(tmp_pixels_g, kPixels); + MemRandomize(tmp_pixels_b, kPixels); + MemRandomize(dst_pixels_opt, kPixels * 4); + MemRandomize(dst_pixels_c, kPixels * 4); + + MaskCpuFlags(disable_cpu_flags_); + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_r, + benchmark_width_, tmp_pixels_g, benchmark_width_, tmp_pixels_b, + benchmark_width_, NULL, 0, benchmark_width_, + benchmark_height_); + MergeARGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g, benchmark_width_, + tmp_pixels_b, benchmark_width_, NULL, 0, dst_pixels_c, + benchmark_width_ * 4, benchmark_width_, benchmark_height_); + + MaskCpuFlags(benchmark_cpu_info_); + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_r, + benchmark_width_, tmp_pixels_g, benchmark_width_, tmp_pixels_b, + benchmark_width_, NULL, 0, benchmark_width_, + benchmark_height_); + + for (int i = 0; i < benchmark_iterations_; ++i) { + MergeARGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g, + benchmark_width_, tmp_pixels_b, benchmark_width_, NULL, 0, + dst_pixels_opt, benchmark_width_ * 4, benchmark_width_, + benchmark_height_); + } + + for (int i = 0; i < kPixels * 4; ++i) { + EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(tmp_pixels_r); + free_aligned_buffer_page_end(tmp_pixels_g); + free_aligned_buffer_page_end(tmp_pixels_b); + free_aligned_buffer_page_end(dst_pixels_opt); + free_aligned_buffer_page_end(dst_pixels_c); +} + +TEST_F(LibYUVPlanarTest, SplitXRGBPlane_Opt) { + // Round count up to multiple of 16 + const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15; + align_buffer_page_end(src_pixels, kPixels * 4); + align_buffer_page_end(tmp_pixels_r, kPixels); + align_buffer_page_end(tmp_pixels_g, kPixels); + align_buffer_page_end(tmp_pixels_b, kPixels); + align_buffer_page_end(dst_pixels_opt, kPixels * 4); + align_buffer_page_end(dst_pixels_c, kPixels * 4); + + MemRandomize(src_pixels, kPixels * 4); + MemRandomize(tmp_pixels_r, kPixels); + MemRandomize(tmp_pixels_g, kPixels); + MemRandomize(tmp_pixels_b, kPixels); + MemRandomize(dst_pixels_opt, kPixels * 4); + MemRandomize(dst_pixels_c, kPixels * 4); + + MaskCpuFlags(disable_cpu_flags_); + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_r, + benchmark_width_, tmp_pixels_g, benchmark_width_, tmp_pixels_b, + benchmark_width_, NULL, 0, benchmark_width_, + benchmark_height_); + MergeARGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g, benchmark_width_, + tmp_pixels_b, benchmark_width_, NULL, 0, dst_pixels_c, + benchmark_width_ * 4, benchmark_width_, benchmark_height_); + + MaskCpuFlags(benchmark_cpu_info_); + for (int i = 0; i < benchmark_iterations_; ++i) { + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_r, + benchmark_width_, tmp_pixels_g, benchmark_width_, + tmp_pixels_b, benchmark_width_, NULL, 0, benchmark_width_, + benchmark_height_); + } + + MergeARGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g, benchmark_width_, + tmp_pixels_b, benchmark_width_, NULL, 0, dst_pixels_opt, + benchmark_width_ * 4, benchmark_width_, benchmark_height_); + + for (int i = 0; i < kPixels * 4; ++i) { + EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(tmp_pixels_r); + free_aligned_buffer_page_end(tmp_pixels_g); + free_aligned_buffer_page_end(tmp_pixels_b); + free_aligned_buffer_page_end(dst_pixels_opt); + free_aligned_buffer_page_end(dst_pixels_c); +} + // TODO(fbarchard): improve test for platforms and cpu detect #ifdef HAS_MERGEUVROW_16_AVX2 TEST_F(LibYUVPlanarTest, MergeUVRow_16_Opt) { |