From e0a2472fb34eccd830fa5693bc342fecf10c3204 Mon Sep 17 00:00:00 2001 From: "fbarchard@google.com" Date: Tue, 13 Jan 2015 23:47:25 +0000 Subject: [PATCH] Move color space tests into its own source file. BUG=391 TESTED=TestI420 R=harryjin@google.com Review URL: https://webrtc-codereview.appspot.com/35769004 git-svn-id: http://libyuv.googlecode.com/svn/trunk@1227 16f28f9a-4ce2-e073-06de-1de4eb20be90 --- CMakeLists.txt | 1 + README.chromium | 2 +- include/libyuv/version.h | 2 +- libyuv_test.gyp | 1 + unit_test/color_test.cc | 116 +++++++++++++++++++++++++ unit_test/convert_test.cc | 176 -------------------------------------- 6 files changed, 120 insertions(+), 178 deletions(-) create mode 100644 unit_test/color_test.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 43e79a03b..5b3de1e25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ set(ly_source_files set(ly_unittest_sources ${ly_base_dir}/unit_test/basictypes_test.cc + ${ly_base_dir}/unit_test/color_test.cc ${ly_base_dir}/unit_test/compare_test.cc ${ly_base_dir}/unit_test/convert_test.cc ${ly_base_dir}/unit_test/cpu_test.cc diff --git a/README.chromium b/README.chromium index d838fded4..aae1c621a 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 1225 +Version: 1227 License: BSD License File: LICENSE diff --git a/include/libyuv/version.h b/include/libyuv/version.h index 328e3cb2a..628764b29 100644 --- a/include/libyuv/version.h +++ b/include/libyuv/version.h @@ -11,6 +11,6 @@ #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #define INCLUDE_LIBYUV_VERSION_H_ -#define LIBYUV_VERSION 1225 +#define LIBYUV_VERSION 1227 #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT diff --git a/libyuv_test.gyp b/libyuv_test.gyp index 4965b560c..54d2790f5 100644 --- a/libyuv_test.gyp +++ b/libyuv_test.gyp @@ -36,6 +36,7 @@ # sources 'unit_test/basictypes_test.cc', 'unit_test/compare_test.cc', + 'unit_test/color_test.cc', 'unit_test/convert_test.cc', 'unit_test/cpu_test.cc', 'unit_test/math_test.cc', diff --git a/unit_test/color_test.cc b/unit_test/color_test.cc new file mode 100644 index 000000000..9aa9e836e --- /dev/null +++ b/unit_test/color_test.cc @@ -0,0 +1,116 @@ +/* + * Copyright 2015 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "libyuv/convert.h" +#include "libyuv/convert_argb.h" +#include "libyuv/convert_from.h" +#include "libyuv/convert_from_argb.h" +#include "libyuv/cpu_id.h" +#include "libyuv/row.h" // For Sobel +#include "../unit_test/unit_test.h" + +namespace libyuv { + +#define TESTCS(TESTNAME, YUVTOARGB, ARGBTOYUV, HS1, HS, HN, DIFF) \ +TEST_F(libyuvTest, TESTNAME) { \ + const int kPixels = benchmark_width_ * benchmark_height_; \ + const int kHalfPixels = ((benchmark_width_ + 1) / 2) * \ + ((benchmark_height_ + HS1) / HS); \ + align_buffer_64(orig_y, kPixels); \ + align_buffer_64(orig_u, kHalfPixels); \ + align_buffer_64(orig_v, kHalfPixels); \ + align_buffer_64(orig_pixels, kPixels * 4); \ + align_buffer_64(temp_y, kPixels); \ + align_buffer_64(temp_u, kHalfPixels); \ + align_buffer_64(temp_v, kHalfPixels); \ + align_buffer_64(dst_pixels_opt, kPixels * 4); \ + align_buffer_64(dst_pixels_c, kPixels * 4); \ + \ + MemRandomize(orig_pixels, kPixels * 4); \ + MemRandomize(orig_y, kPixels); \ + MemRandomize(orig_u, kHalfPixels); \ + MemRandomize(orig_v, kHalfPixels); \ + MemRandomize(temp_y, kPixels); \ + MemRandomize(temp_u, kHalfPixels); \ + MemRandomize(temp_v, kHalfPixels); \ + MemRandomize(dst_pixels_opt, kPixels * 4); \ + MemRandomize(dst_pixels_c, kPixels * 4); \ + \ + /* The test is overall for color conversion matrix being reversible, so */ \ + /* this initializes the pixel with 2x2 blocks to eliminate subsampling. */ \ + uint8* p = orig_y; \ + for (int y = 0; y < benchmark_height_ - HS1; y += HS) { \ + for (int x = 0; x < benchmark_width_ - 1; x += 2) { \ + uint8 r = static_cast(random()); \ + p[0] = r; \ + p[1] = r; \ + p[HN] = r; \ + p[HN + 1] = r; \ + p += 2; \ + } \ + p += HN; \ + } \ + \ + /* Start with YUV converted to ARGB. */ \ + YUVTOARGB(orig_y, benchmark_width_, \ + orig_u, (benchmark_width_ + 1) / 2, \ + orig_v, (benchmark_width_ + 1) / 2, \ + orig_pixels, benchmark_width_ * 4, \ + benchmark_width_, benchmark_height_); \ + \ + ARGBTOYUV(orig_pixels, benchmark_width_ * 4, \ + temp_y, benchmark_width_, \ + temp_u, (benchmark_width_ + 1) / 2, \ + temp_v, (benchmark_width_ + 1) / 2, \ + benchmark_width_, benchmark_height_); \ + \ + MaskCpuFlags(0); \ + YUVTOARGB(temp_y, benchmark_width_, \ + temp_u, (benchmark_width_ + 1) / 2, \ + temp_v, (benchmark_width_ + 1) / 2, \ + dst_pixels_c, benchmark_width_ * 4, \ + benchmark_width_, benchmark_height_); \ + MaskCpuFlags(-1); \ + \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + YUVTOARGB(temp_y, benchmark_width_, \ + temp_u, (benchmark_width_ + 1) / 2, \ + temp_v, (benchmark_width_ + 1) / 2, \ + dst_pixels_opt, benchmark_width_ * 4, \ + benchmark_width_, benchmark_height_); \ + } \ + /* Test C and SIMD match. */ \ + for (int i = 0; i < kPixels * 4; ++i) { \ + EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); \ + } \ + /* Test SIMD is close to original. */ \ + for (int i = 0; i < kPixels * 4; ++i) { \ + EXPECT_NEAR(static_cast(orig_pixels[i]), \ + static_cast(dst_pixels_opt[i]), DIFF); \ + } \ + \ + free_aligned_buffer_64(orig_pixels); \ + free_aligned_buffer_64(orig_y); \ + free_aligned_buffer_64(orig_u); \ + free_aligned_buffer_64(orig_v); \ + free_aligned_buffer_64(temp_y); \ + free_aligned_buffer_64(temp_u); \ + free_aligned_buffer_64(temp_v); \ + free_aligned_buffer_64(dst_pixels_opt); \ + free_aligned_buffer_64(dst_pixels_c); \ +} \ + +TESTCS(TestJ420, J420ToARGB, ARGBToJ420, 1, 2, benchmark_width_, 3) +TESTCS(TestI420, I420ToARGB, ARGBToI420, 1, 2, benchmark_width_, 6) +TESTCS(TestI422, I422ToARGB, ARGBToI422, 0, 1, 0, 6) + +} // namespace libyuv diff --git a/unit_test/convert_test.cc b/unit_test/convert_test.cc index 1f70a06f0..8fd9c123e 100644 --- a/unit_test/convert_test.cc +++ b/unit_test/convert_test.cc @@ -1242,180 +1242,4 @@ TEST_F(libyuvTest, HaveJPEG) { #endif } -TEST_F(libyuvTest, TestI420) { - const int kPixels = benchmark_width_ * benchmark_height_; - const int kHalfPixels = ((benchmark_width_ + 1) / 2) * - ((benchmark_height_ + 1) / 2); - align_buffer_64(orig_y, kPixels); - align_buffer_64(orig_u, kHalfPixels); - align_buffer_64(orig_v, kHalfPixels); - align_buffer_64(orig_pixels, kPixels * 4); - align_buffer_64(temp_y, kPixels); - align_buffer_64(temp_u, kHalfPixels); - align_buffer_64(temp_v, kHalfPixels); - align_buffer_64(dst_pixels_opt, kPixels * 4); - align_buffer_64(dst_pixels_c, kPixels * 4); - - MemRandomize(orig_pixels, kPixels * 4); - MemRandomize(orig_y, kPixels); - MemRandomize(orig_u, kHalfPixels); - MemRandomize(orig_v, kHalfPixels); - MemRandomize(temp_y, kPixels); - MemRandomize(temp_u, kHalfPixels); - MemRandomize(temp_v, kHalfPixels); - MemRandomize(dst_pixels_opt, kPixels * 4); - MemRandomize(dst_pixels_c, kPixels * 4); - - // The test is overall for color conversion matrix being reversible, so - // this initializes the pixel with 2x2 blocks to eliminate subsampling. - uint8* p = orig_y; - for (int y = 0; y < benchmark_height_ - 1; y += 2) { - for (int x = 0; x < benchmark_width_ - 1; x += 2) { - uint8 r = static_cast(random()); - p[0] = r; - p[1] = r; - p[benchmark_width_] = r; - p[benchmark_width_ + 1] = r; - p += 2; - } - p += benchmark_width_; - } - - // Start with YUV converted to ARGB. - I420ToARGB(orig_y, benchmark_width_, - orig_u, (benchmark_width_ + 1) / 2, - orig_v, (benchmark_width_ + 1) / 2, - orig_pixels, benchmark_width_ * 4, - benchmark_width_, benchmark_height_); - - ARGBToI420(orig_pixels, benchmark_width_ * 4, - temp_y, benchmark_width_, - temp_u, (benchmark_width_ + 1) / 2, - temp_v, (benchmark_width_ + 1) / 2, - benchmark_width_, benchmark_height_); - - MaskCpuFlags(0); - I420ToARGB(temp_y, benchmark_width_, - temp_u, (benchmark_width_ + 1) / 2, - temp_v, (benchmark_width_ + 1) / 2, - dst_pixels_c, benchmark_width_ * 4, - benchmark_width_, benchmark_height_); - MaskCpuFlags(-1); - - for (int i = 0; i < benchmark_iterations_; ++i) { - I420ToARGB(temp_y, benchmark_width_, - temp_u, (benchmark_width_ + 1) / 2, - temp_v, (benchmark_width_ + 1) / 2, - dst_pixels_opt, benchmark_width_ * 4, - benchmark_width_, benchmark_height_); - } - // Test C and SIMD match. - for (int i = 0; i < kPixels * 4; ++i) { - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); - } - // Test SIMD is close to original. - for (int i = 0; i < kPixels * 4; ++i) { - EXPECT_NEAR(static_cast(orig_pixels[i]), - static_cast(dst_pixels_opt[i]), 6); - } - - free_aligned_buffer_64(orig_pixels); - free_aligned_buffer_64(orig_y); - free_aligned_buffer_64(orig_u); - free_aligned_buffer_64(orig_v); - free_aligned_buffer_64(temp_y); - free_aligned_buffer_64(temp_u); - free_aligned_buffer_64(temp_v); - free_aligned_buffer_64(dst_pixels_opt); - free_aligned_buffer_64(dst_pixels_c); -} - -TEST_F(libyuvTest, TestJ420) { - const int kPixels = benchmark_width_ * benchmark_height_; - const int kHalfPixels = ((benchmark_width_ + 1) / 2) * - ((benchmark_height_ + 1) / 2); - align_buffer_64(orig_y, kPixels); - align_buffer_64(orig_u, kHalfPixels); - align_buffer_64(orig_v, kHalfPixels); - align_buffer_64(orig_pixels, kPixels * 4); - align_buffer_64(temp_y, kPixels); - align_buffer_64(temp_u, kHalfPixels); - align_buffer_64(temp_v, kHalfPixels); - align_buffer_64(dst_pixels_opt, kPixels * 4); - align_buffer_64(dst_pixels_c, kPixels * 4); - - MemRandomize(orig_pixels, kPixels * 4); - MemRandomize(orig_y, kPixels); - MemRandomize(orig_u, kHalfPixels); - MemRandomize(orig_v, kHalfPixels); - MemRandomize(temp_y, kPixels); - MemRandomize(temp_u, kHalfPixels); - MemRandomize(temp_v, kHalfPixels); - MemRandomize(dst_pixels_opt, kPixels * 4); - MemRandomize(dst_pixels_c, kPixels * 4); - - // The test is overall for color conversion matrix being reversible, so - // this initializes the pixel with 2x2 blocks to eliminate subsampling. - uint8* p = orig_y; - for (int y = 0; y < benchmark_height_ - 1; y += 2) { - for (int x = 0; x < benchmark_width_ - 1; x += 2) { - uint8 r = static_cast(random()); - p[0] = r; - p[1] = r; - p[benchmark_width_] = r; - p[benchmark_width_ + 1] = r; - p += 2; - } - p += benchmark_width_; - } - - // Start with YUV converted to ARGB. - J420ToARGB(orig_y, benchmark_width_, - orig_u, (benchmark_width_ + 1) / 2, - orig_v, (benchmark_width_ + 1) / 2, - orig_pixels, benchmark_width_ * 4, - benchmark_width_, benchmark_height_); - - ARGBToJ420(orig_pixels, benchmark_width_ * 4, - temp_y, benchmark_width_, - temp_u, (benchmark_width_ + 1) / 2, - temp_v, (benchmark_width_ + 1) / 2, - benchmark_width_, benchmark_height_); - - MaskCpuFlags(0); - J420ToARGB(temp_y, benchmark_width_, - temp_u, (benchmark_width_ + 1) / 2, - temp_v, (benchmark_width_ + 1) / 2, - dst_pixels_c, benchmark_width_ * 4, - benchmark_width_, benchmark_height_); - MaskCpuFlags(-1); - - for (int i = 0; i < benchmark_iterations_; ++i) { - J420ToARGB(temp_y, benchmark_width_, - temp_u, (benchmark_width_ + 1) / 2, - temp_v, (benchmark_width_ + 1) / 2, - dst_pixels_opt, benchmark_width_ * 4, - benchmark_width_, benchmark_height_); - } - // Test C and SIMD match. - for (int i = 0; i < kPixels * 4; ++i) { - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); - } - // Test SIMD is close to original. - for (int i = 0; i < kPixels * 4; ++i) { - EXPECT_NEAR(static_cast(orig_pixels[i]), - static_cast(dst_pixels_opt[i]), 3); - } - - free_aligned_buffer_64(orig_pixels); - free_aligned_buffer_64(orig_y); - free_aligned_buffer_64(orig_u); - free_aligned_buffer_64(orig_v); - free_aligned_buffer_64(temp_y); - free_aligned_buffer_64(temp_u); - free_aligned_buffer_64(temp_v); - free_aligned_buffer_64(dst_pixels_opt); - free_aligned_buffer_64(dst_pixels_c); -} - } // namespace libyuv