diff options
author | Hendrik Dahlkamp <hendrik@google.com> | 2013-01-23 18:27:37 -0800 |
---|---|---|
committer | Adam Hampson <ahampson@google.com> | 2013-01-28 15:39:41 -0800 |
commit | 33cfdeb7b267ab635413797fffb046b73272f7ec (patch) | |
tree | 8ff16b765a83ba911233a1d7bfa27cce9cee3b7c /files/unit_test | |
parent | a88a10a6ed9f9801852929bac34bdf10510116f4 (diff) | |
download | libyuv-33cfdeb7b267ab635413797fffb046b73272f7ec.tar.gz |
Update libyuv to r397
Change-Id: I70f5a527de52ae8ae80b189873c9a094035dfa2c
Signed-off-by: Hendrik Dahlkamp <hendrik@google.com>
Diffstat (limited to 'files/unit_test')
-rw-r--r-- | files/unit_test/compare_test.cc | 450 | ||||
-rw-r--r-- | files/unit_test/cpu_test.cc | 100 | ||||
-rw-r--r-- | files/unit_test/planar_test.cc | 1005 | ||||
-rw-r--r-- | files/unit_test/rotate_argb_test.cc | 195 | ||||
-rw-r--r-- | files/unit_test/rotate_test.cc | 1194 | ||||
-rw-r--r-- | files/unit_test/scale_argb_test.cc | 255 | ||||
-rw-r--r-- | files/unit_test/scale_test.cc | 447 | ||||
-rw-r--r-- | files/unit_test/testdata/arm_v7.txt | 12 | ||||
-rw-r--r-- | files/unit_test/testdata/tegra3.txt | 23 | ||||
-rw-r--r-- | files/unit_test/unit_test.cc | 39 | ||||
-rw-r--r-- | files/unit_test/unit_test.h | 63 | ||||
-rw-r--r-- | files/unit_test/version_test.cc | 42 |
12 files changed, 3097 insertions, 728 deletions
diff --git a/files/unit_test/compare_test.cc b/files/unit_test/compare_test.cc new file mode 100644 index 00000000..8a49a612 --- /dev/null +++ b/files/unit_test/compare_test.cc @@ -0,0 +1,450 @@ +/* + * Copyright 2011 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 <stdlib.h> +#include <string.h> +#include <time.h> + +#include "../unit_test/unit_test.h" +#include "libyuv/basic_types.h" +#include "libyuv/compare.h" +#include "libyuv/cpu_id.h" + +namespace libyuv { + +// hash seed of 5381 recommended. +static uint32 ReferenceHashDjb2(const uint8* src, uint64 count, uint32 seed) { + uint32 hash = seed; + if (count > 0) { + do { + hash = hash * 33 + *src++; + } while (--count); + } + return hash; +} + +TEST_F(libyuvTest, TestDjb2) { + const int kMaxTest = 2049; + align_buffer_16(src_a, kMaxTest) + + for (int i = 0; i < kMaxTest; ++i) { + src_a[i] = i; + } + for (int i = 0; i < kMaxTest; ++i) { + uint32 h1 = HashDjb2(src_a, kMaxTest, 5381); + uint32 h2 = ReferenceHashDjb2(src_a, kMaxTest, 5381); + EXPECT_EQ(h1, h2); + } + // Hash constant generator using for tables in compare + int h = 1; + for (int i = 0; i <= 16 ; ++i) { + printf("%08x ", h); + h *= 33; + } + printf("\n"); + + free_aligned_buffer_16(src_a) +} + +TEST_F(libyuvTest, BenchmakDjb2_C) { + const int kMaxTest = 1280 * 720; + align_buffer_16(src_a, kMaxTest) + + for (int i = 0; i < kMaxTest; ++i) { + src_a[i] = i; + } + uint32 h2 = ReferenceHashDjb2(src_a, kMaxTest, 5381); + uint32 h1; + MaskCpuFlags(kCpuInitialized); + for (int i = 0; i < benchmark_iterations_; ++i) { + h1 = HashDjb2(src_a, kMaxTest, 5381); + } + MaskCpuFlags(-1); + EXPECT_EQ(h1, h2); + free_aligned_buffer_16(src_a) +} + +TEST_F(libyuvTest, BenchmakDjb2_OPT) { + const int kMaxTest = 1280 * 720; + align_buffer_16(src_a, kMaxTest) + + for (int i = 0; i < kMaxTest; ++i) { + src_a[i] = i; + } + uint32 h2 = ReferenceHashDjb2(src_a, kMaxTest, 5381); + uint32 h1; + for (int i = 0; i < benchmark_iterations_; ++i) { + h1 = HashDjb2(src_a, kMaxTest, 5381); + } + EXPECT_EQ(h1, h2); + free_aligned_buffer_16(src_a) +} + +TEST_F(libyuvTest, BenchmakDjb2_Unaligned_OPT) { + const int kMaxTest = 1280 * 720; + align_buffer_16(src_a, kMaxTest + 1) + + for (int i = 0; i < kMaxTest; ++i) { + src_a[i + 1] = i; + } + uint32 h2 = ReferenceHashDjb2(src_a + 1, kMaxTest, 5381); + uint32 h1; + for (int i = 0; i < benchmark_iterations_; ++i) { + h1 = HashDjb2(src_a + 1, kMaxTest, 5381); + } + EXPECT_EQ(h1, h2); + free_aligned_buffer_16(src_a) +} + +TEST_F(libyuvTest, BenchmarkSumSquareError_C) { + const int kMaxWidth = 4096 * 3; + align_buffer_16(src_a, kMaxWidth) + align_buffer_16(src_b, kMaxWidth) + + for (int i = 0; i < kMaxWidth; ++i) { + src_a[i] = i; + src_b[i] = i; + } + + MaskCpuFlags(kCpuInitialized); + for (int i = 0; i < benchmark_iterations_; ++i) { + ComputeSumSquareError(src_a, src_b, kMaxWidth); + } + + MaskCpuFlags(-1); + + EXPECT_EQ(0, 0); + + free_aligned_buffer_16(src_a) + free_aligned_buffer_16(src_b) +} + +TEST_F(libyuvTest, BenchmarkSumSquareError_OPT) { + const int kMaxWidth = 4096 * 3; + align_buffer_16(src_a, kMaxWidth) + align_buffer_16(src_b, kMaxWidth) + + for (int i = 0; i < kMaxWidth; ++i) { + src_a[i] = i; + src_b[i] = i; + } + + for (int i = 0; i < benchmark_iterations_; ++i) { + ComputeSumSquareError(src_a, src_b, kMaxWidth); + } + + EXPECT_EQ(0, 0); + + free_aligned_buffer_16(src_a) + free_aligned_buffer_16(src_b) +} + +TEST_F(libyuvTest, SumSquareError) { + const int kMaxWidth = 4096 * 3; + align_buffer_16(src_a, kMaxWidth) + align_buffer_16(src_b, kMaxWidth) + + memset(src_a, 0, kMaxWidth); + memset(src_b, 0, kMaxWidth); + + uint64 err; + err = ComputeSumSquareError(src_a, src_b, kMaxWidth); + + EXPECT_EQ(err, 0); + + memset(src_a, 1, kMaxWidth); + err = ComputeSumSquareError(src_a, src_b, kMaxWidth); + + EXPECT_EQ(err, kMaxWidth); + + memset(src_a, 190, kMaxWidth); + memset(src_b, 193, kMaxWidth); + err = ComputeSumSquareError(src_a, src_b, kMaxWidth); + + EXPECT_EQ(err, (kMaxWidth * 3 * 3)); + + srandom(time(NULL)); + + for (int i = 0; i < kMaxWidth; ++i) { + src_a[i] = (random() & 0xff); + src_b[i] = (random() & 0xff); + } + + MaskCpuFlags(kCpuInitialized); + uint64 c_err = ComputeSumSquareError(src_a, src_b, kMaxWidth); + + MaskCpuFlags(-1); + uint64 opt_err = ComputeSumSquareError(src_a, src_b, kMaxWidth); + + EXPECT_EQ(c_err, opt_err); + + free_aligned_buffer_16(src_a) + free_aligned_buffer_16(src_b) +} + +TEST_F(libyuvTest, BenchmarkPsnr_C) { + align_buffer_16(src_a, benchmark_width_ * benchmark_height_) + align_buffer_16(src_b, benchmark_width_ * benchmark_height_) + + for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) { + src_a[i] = i; + src_b[i] = i; + } + + MaskCpuFlags(kCpuInitialized); + + double c_time = get_time(); + for (int i = 0; i < benchmark_iterations_; ++i) + CalcFramePsnr(src_a, benchmark_width_, + src_b, benchmark_width_, + benchmark_width_, benchmark_height_); + + c_time = (get_time() - c_time) / benchmark_iterations_; + printf("BenchmarkPsnr_C - %8.2f us c\n", c_time * 1e6); + + MaskCpuFlags(-1); + + EXPECT_EQ(0, 0); + + free_aligned_buffer_16(src_a) + free_aligned_buffer_16(src_b) +} + +TEST_F(libyuvTest, BenchmarkPsnr_OPT) { + align_buffer_16(src_a, benchmark_width_ * benchmark_height_) + align_buffer_16(src_b, benchmark_width_ * benchmark_height_) + + for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) { + src_a[i] = i; + src_b[i] = i; + } + + MaskCpuFlags(-1); + + double opt_time = get_time(); + for (int i = 0; i < benchmark_iterations_; ++i) + CalcFramePsnr(src_a, benchmark_width_, + src_b, benchmark_width_, + benchmark_width_, benchmark_height_); + + opt_time = (get_time() - opt_time) / benchmark_iterations_; + printf("BenchmarkPsnr_OPT - %8.2f us opt\n", opt_time * 1e6); + + EXPECT_EQ(0, 0); + + free_aligned_buffer_16(src_a) + free_aligned_buffer_16(src_b) +} + +TEST_F(libyuvTest, Psnr) { + const int kSrcWidth = 1280; + const int kSrcHeight = 720; + const int b = 128; + const int kSrcPlaneSize = (kSrcWidth + b * 2) * (kSrcHeight + b * 2); + const int kSrcStride = 2 * b + kSrcWidth; + align_buffer_16(src_a, kSrcPlaneSize) + align_buffer_16(src_b, kSrcPlaneSize) + + memset(src_a, 0, kSrcPlaneSize); + memset(src_b, 0, kSrcPlaneSize); + + double err; + err = CalcFramePsnr(src_a + kSrcStride * b + b, kSrcStride, + src_b + kSrcStride * b + b, kSrcStride, + kSrcWidth, kSrcHeight); + + EXPECT_EQ(err, kMaxPsnr); + + memset(src_a, 255, kSrcPlaneSize); + + err = CalcFramePsnr(src_a + kSrcStride * b + b, kSrcStride, + src_b + kSrcStride * b + b, kSrcStride, + kSrcWidth, kSrcHeight); + + EXPECT_EQ(err, 0.0); + + memset(src_a, 1, kSrcPlaneSize); + + err = CalcFramePsnr(src_a + kSrcStride * b + b, kSrcStride, + src_b + kSrcStride * b + b, kSrcStride, + kSrcWidth, kSrcHeight); + + EXPECT_GT(err, 48.0); + EXPECT_LT(err, 49.0); + + for (int i = 0; i < kSrcPlaneSize; ++i) + src_a[i] = i; + + err = CalcFramePsnr(src_a + kSrcStride * b + b, kSrcStride, + src_b + kSrcStride * b + b, kSrcStride, + kSrcWidth, kSrcHeight); + + EXPECT_GT(err, 4.0); + EXPECT_LT(err, 5.0); + + srandom(time(NULL)); + + memset(src_a, 0, kSrcPlaneSize); + memset(src_b, 0, kSrcPlaneSize); + + for (int i = b; i < (kSrcHeight + b); ++i) { + for (int j = b; j < (kSrcWidth + b); ++j) { + src_a[(i * kSrcStride) + j] = (random() & 0xff); + src_b[(i * kSrcStride) + j] = (random() & 0xff); + } + } + + MaskCpuFlags(kCpuInitialized); + double c_err, opt_err; + + c_err = CalcFramePsnr(src_a + kSrcStride * b + b, kSrcStride, + src_b + kSrcStride * b + b, kSrcStride, + kSrcWidth, kSrcHeight); + + MaskCpuFlags(-1); + + opt_err = CalcFramePsnr(src_a + kSrcStride * b + b, kSrcStride, + src_b + kSrcStride * b + b, kSrcStride, + kSrcWidth, kSrcHeight); + + EXPECT_EQ(opt_err, c_err); + + free_aligned_buffer_16(src_a) + free_aligned_buffer_16(src_b) +} + +TEST_F(libyuvTest, BenchmarkSsim_C) { + align_buffer_16(src_a, benchmark_width_ * benchmark_height_) + align_buffer_16(src_b, benchmark_width_ * benchmark_height_) + + for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) { + src_a[i] = i; + src_b[i] = i; + } + + MaskCpuFlags(kCpuInitialized); + + double c_time = get_time(); + for (int i = 0; i < benchmark_iterations_; ++i) + CalcFrameSsim(src_a, benchmark_width_, + src_b, benchmark_width_, + benchmark_width_, benchmark_height_); + + c_time = (get_time() - c_time) / benchmark_iterations_; + printf("BenchmarkSsim_C - %8.2f us c\n", c_time * 1e6); + + MaskCpuFlags(-1); + + EXPECT_EQ(0, 0); + + free_aligned_buffer_16(src_a) + free_aligned_buffer_16(src_b) +} + +TEST_F(libyuvTest, BenchmarkSsim_OPT) { + align_buffer_16(src_a, benchmark_width_ * benchmark_height_) + align_buffer_16(src_b, benchmark_width_ * benchmark_height_) + + for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) { + src_a[i] = i; + src_b[i] = i; + } + + MaskCpuFlags(-1); + + double opt_time = get_time(); + for (int i = 0; i < benchmark_iterations_; ++i) + CalcFrameSsim(src_a, benchmark_width_, + src_b, benchmark_width_, + benchmark_width_, benchmark_height_); + + opt_time = (get_time() - opt_time) / benchmark_iterations_; + printf("BenchmarkPsnr_OPT - %8.2f us opt\n", opt_time * 1e6); + + EXPECT_EQ(0, 0); + + free_aligned_buffer_16(src_a) + free_aligned_buffer_16(src_b) +} + +TEST_F(libyuvTest, Ssim) { + const int kSrcWidth = 1280; + const int kSrcHeight = 720; + const int b = 128; + const int kSrcPlaneSize = (kSrcWidth + b * 2) * (kSrcHeight + b * 2); + const int kSrcStride = 2 * b + kSrcWidth; + align_buffer_16(src_a, kSrcPlaneSize) + align_buffer_16(src_b, kSrcPlaneSize) + + memset(src_a, 0, kSrcPlaneSize); + memset(src_b, 0, kSrcPlaneSize); + + double err; + err = CalcFrameSsim(src_a + kSrcStride * b + b, kSrcStride, + src_b + kSrcStride * b + b, kSrcStride, + kSrcWidth, kSrcHeight); + + EXPECT_EQ(err, 1.0); + + memset(src_a, 255, kSrcPlaneSize); + + err = CalcFrameSsim(src_a + kSrcStride * b + b, kSrcStride, + src_b + kSrcStride * b + b, kSrcStride, + kSrcWidth, kSrcHeight); + + EXPECT_LT(err, 0.0001); + + memset(src_a, 1, kSrcPlaneSize); + + err = CalcFrameSsim(src_a + kSrcStride * b + b, kSrcStride, + src_b + kSrcStride * b + b, kSrcStride, + kSrcWidth, kSrcHeight); + + EXPECT_GT(err, 0.8); + EXPECT_LT(err, 0.9); + + for (int i = 0; i < kSrcPlaneSize; ++i) + src_a[i] = i; + + err = CalcFrameSsim(src_a + kSrcStride * b + b, kSrcStride, + src_b + kSrcStride * b + b, kSrcStride, + kSrcWidth, kSrcHeight); + + EXPECT_GT(err, 0.008); + EXPECT_LT(err, 0.009); + + srandom(time(NULL)); + for (int i = b; i < (kSrcHeight + b); ++i) { + for (int j = b; j < (kSrcWidth + b); ++j) { + src_a[(i * kSrcStride) + j] = (random() & 0xff); + src_b[(i * kSrcStride) + j] = (random() & 0xff); + } + } + + MaskCpuFlags(kCpuInitialized); + double c_err, opt_err; + + c_err = CalcFrameSsim(src_a + kSrcStride * b + b, kSrcStride, + src_b + kSrcStride * b + b, kSrcStride, + kSrcWidth, kSrcHeight); + + MaskCpuFlags(-1); + + opt_err = CalcFrameSsim(src_a + kSrcStride * b + b, kSrcStride, + src_b + kSrcStride * b + b, kSrcStride, + kSrcWidth, kSrcHeight); + + EXPECT_EQ(opt_err, c_err); + + free_aligned_buffer_16(src_a) + free_aligned_buffer_16(src_b) +} + +} // namespace libyuv diff --git a/files/unit_test/cpu_test.cc b/files/unit_test/cpu_test.cc new file mode 100644 index 00000000..52810e80 --- /dev/null +++ b/files/unit_test/cpu_test.cc @@ -0,0 +1,100 @@ +/* + * Copyright 2012 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 <stdlib.h> +#include <string.h> + +#include "libyuv/basic_types.h" +#include "libyuv/cpu_id.h" +#include "libyuv/version.h" +#include "../unit_test/unit_test.h" + +namespace libyuv { + +TEST_F(libyuvTest, TestCpuHas) { + int cpu_flags = TestCpuFlag(~kCpuInitialized); + printf("Cpu Flags %x\n", cpu_flags); + int has_arm = TestCpuFlag(kCpuHasARM); + printf("Has ARM %x\n", has_arm); + int has_neon = TestCpuFlag(kCpuHasNEON); + printf("Has NEON %x\n", has_neon); + int has_x86 = TestCpuFlag(kCpuHasX86); + printf("Has X86 %x\n", has_x86); + int has_sse2 = TestCpuFlag(kCpuHasSSE2); + printf("Has SSE2 %x\n", has_sse2); + int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); + printf("Has SSSE3 %x\n", has_ssse3); + int has_sse41 = TestCpuFlag(kCpuHasSSE41); + printf("Has SSE4.1 %x\n", has_sse41); + int has_sse42 = TestCpuFlag(kCpuHasSSE42); + printf("Has SSE4.2 %x\n", has_sse42); + int has_avx = TestCpuFlag(kCpuHasAVX); + printf("Has AVX %x\n", has_avx); + int has_avx2 = TestCpuFlag(kCpuHasAVX2); + printf("Has AVX2 %x\n", has_avx2); +} + +#if defined(__i386__) || defined(__x86_64__) || \ + defined(_M_IX86) || defined(_M_X64) +TEST_F(libyuvTest, TestCpuId) { + int has_x86 = TestCpuFlag(kCpuHasX86); + if (has_x86) { + int cpu_info[4]; + // Vendor ID: + // AuthenticAMD AMD processor + // CentaurHauls Centaur processor + // CyrixInstead Cyrix processor + // GenuineIntel Intel processor + // GenuineTMx86 Transmeta processor + // Geode by NSC National Semiconductor processor + // NexGenDriven NexGen processor + // RiseRiseRise Rise Technology processor + // SiS SiS SiS SiS processor + // UMC UMC UMC UMC processor + CpuId(cpu_info, 0); + cpu_info[0] = cpu_info[1]; // Reorder output + cpu_info[1] = cpu_info[3]; + cpu_info[3] = 0; + printf("Cpu Vendor: %s %x %x %x\n", reinterpret_cast<char*>(&cpu_info[0]), + cpu_info[0], cpu_info[1], cpu_info[2]); + EXPECT_EQ(12, strlen(reinterpret_cast<char*>(&cpu_info[0]))); + + // CPU Family and Model + // 3:0 - Stepping + // 7:4 - Model + // 11:8 - Family + // 13:12 - Processor Type + // 19:16 - Extended Model + // 27:20 - Extended Family + CpuId(cpu_info, 1); + int family = ((cpu_info[0] >> 8) & 0x0f) | ((cpu_info[0] >> 16) & 0xff0); + int model = ((cpu_info[0] >> 4) & 0x0f) | ((cpu_info[0] >> 12) & 0xf0); + printf("Cpu Family %d (0x%x), Model %d (0x%x)\n", family, family, + model, model); + } +} +#endif + +TEST_F(libyuvTest, TestLinuxNeon) { + int testdata = ArmCpuCaps("unit_test/testdata/arm_v7.txt"); + if (testdata) { + EXPECT_EQ(kCpuInitialized, + ArmCpuCaps("unit_test/testdata/arm_v7.txt")); + EXPECT_EQ((kCpuInitialized | kCpuHasNEON), + ArmCpuCaps("unit_test/testdata/tegra3.txt")); + } else { + printf("WARNING: unable to load \"unit_test/testdata/arm_v7.txt\"\n"); + } +#if defined(__linux__) && defined(__ARM_NEON__) + EXPECT_NE(0, ArmCpuCaps("/proc/cpuinfo")); +#endif +} + +} // namespace libyuv diff --git a/files/unit_test/planar_test.cc b/files/unit_test/planar_test.cc new file mode 100644 index 00000000..e9053a35 --- /dev/null +++ b/files/unit_test/planar_test.cc @@ -0,0 +1,1005 @@ +/* + * Copyright 2011 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 <stdlib.h> +#include <time.h> + +#include "libyuv/convert_argb.h" +#include "libyuv/convert_from.h" +#include "libyuv/compare.h" +#include "libyuv/cpu_id.h" +#include "libyuv/format_conversion.h" +#include "libyuv/planar_functions.h" +#include "libyuv/rotate.h" +#include "../unit_test/unit_test.h" + +#if defined(_MSC_VER) +#define SIMD_ALIGNED(var) __declspec(align(16)) var +#else // __GNUC__ +#define SIMD_ALIGNED(var) var __attribute__((aligned(16))) +#endif + +namespace libyuv { + +#define TESTPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, N, NEG) \ +TEST_F(libyuvTest, FMT_PLANAR##To##FMT_B##N##_OptVsC) { \ + const int kWidth = 1280; \ + const int kHeight = 720; \ + const int kStride = (kWidth * 8 * BPP_B + 7) / 8; \ + align_buffer_16(src_y, kWidth * kHeight); \ + align_buffer_16(src_u, kWidth / SUBSAMP_X * kHeight / SUBSAMP_Y); \ + align_buffer_16(src_v, kWidth / SUBSAMP_X * kHeight / SUBSAMP_Y); \ + align_buffer_16(dst_argb_c, kStride * kHeight); \ + align_buffer_16(dst_argb_opt, kStride * kHeight); \ + srandom(time(NULL)); \ + for (int i = 0; i < kHeight; ++i) \ + for (int j = 0; j < kWidth; ++j) \ + src_y[(i * kWidth) + j] = (random() & 0xff); \ + for (int i = 0; i < kHeight / SUBSAMP_Y; ++i) \ + for (int j = 0; j < kWidth / SUBSAMP_X; ++j) { \ + src_u[(i * kWidth / SUBSAMP_X) + j] = (random() & 0xff); \ + src_v[(i * kWidth / SUBSAMP_X) + j] = (random() & 0xff); \ + } \ + MaskCpuFlags(kCpuInitialized); \ + FMT_PLANAR##To##FMT_B(src_y, kWidth, \ + src_u, kWidth / SUBSAMP_X, \ + src_v, kWidth / SUBSAMP_X, \ + dst_argb_c, kStride, \ + kWidth, NEG kHeight); \ + MaskCpuFlags(-1); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_PLANAR##To##FMT_B(src_y, kWidth, \ + src_u, kWidth / SUBSAMP_X, \ + src_v, kWidth / SUBSAMP_X, \ + dst_argb_opt, kStride, \ + kWidth, NEG kHeight); \ + } \ + int max_diff = 0; \ + for (int i = 0; i < kHeight; ++i) { \ + for (int j = 0; j < kWidth * BPP_B; ++j) { \ + int abs_diff = \ + abs(static_cast<int>(dst_argb_c[i * kWidth * BPP_B + j]) - \ + static_cast<int>(dst_argb_opt[i * kWidth * BPP_B + j])); \ + if (abs_diff > max_diff) { \ + max_diff = abs_diff; \ + } \ + } \ + } \ + EXPECT_LE(max_diff, 2); \ + free_aligned_buffer_16(src_y) \ + free_aligned_buffer_16(src_u) \ + free_aligned_buffer_16(src_v) \ + free_aligned_buffer_16(dst_argb_c) \ + free_aligned_buffer_16(dst_argb_opt) \ +} + +#define TESTPLANARTOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B) \ + TESTPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, , +) \ + TESTPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, Invert, -) + +TESTPLANARTOB(I420, 2, 2, ARGB, 4) +TESTPLANARTOB(I420, 2, 2, BGRA, 4) +TESTPLANARTOB(I420, 2, 2, ABGR, 4) +TESTPLANARTOB(I420, 2, 2, RGBA, 4) +TESTPLANARTOB(I420, 2, 2, RAW, 3) +TESTPLANARTOB(I420, 2, 2, RGB24, 3) +TESTPLANARTOB(I420, 2, 2, RGB565, 2) +TESTPLANARTOB(I420, 2, 2, ARGB1555, 2) +TESTPLANARTOB(I420, 2, 2, ARGB4444, 2) +TESTPLANARTOB(I422, 2, 1, ARGB, 4) +TESTPLANARTOB(I422, 2, 1, BGRA, 4) +TESTPLANARTOB(I422, 2, 1, ABGR, 4) +TESTPLANARTOB(I422, 2, 1, RGBA, 4) +TESTPLANARTOB(I411, 4, 1, ARGB, 4) +TESTPLANARTOB(I444, 1, 1, ARGB, 4) +TESTPLANARTOB(I420, 2, 2, YUY2, 2) +TESTPLANARTOB(I420, 2, 2, UYVY, 2) +// TODO(fbarchard): Re-enable test and fix valgrind. +// TESTPLANARTOB(I420, 2, 2, V210, 16 / 6) +TESTPLANARTOB(I420, 2, 2, I400, 1) +TESTPLANARTOB(I420, 2, 2, BayerBGGR, 1) +TESTPLANARTOB(I420, 2, 2, BayerRGGB, 1) +TESTPLANARTOB(I420, 2, 2, BayerGBRG, 1) +TESTPLANARTOB(I420, 2, 2, BayerGRBG, 1) + +#define TESTBIPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, \ + N, NEG) \ +TEST_F(libyuvTest, FMT_PLANAR##To##FMT_B##N##_OptVsC) { \ + const int kWidth = 1280; \ + const int kHeight = 720; \ + align_buffer_16(src_y, kWidth * kHeight); \ + align_buffer_16(src_uv, kWidth / SUBSAMP_X * kHeight / SUBSAMP_Y * 2); \ + align_buffer_16(dst_argb_c, (kWidth * BPP_B) * kHeight); \ + align_buffer_16(dst_argb_opt, (kWidth * BPP_B) * kHeight); \ + srandom(time(NULL)); \ + for (int i = 0; i < kHeight; ++i) \ + for (int j = 0; j < kWidth; ++j) \ + src_y[(i * kWidth) + j] = (random() & 0xff); \ + for (int i = 0; i < kHeight / SUBSAMP_Y; ++i) \ + for (int j = 0; j < kWidth / SUBSAMP_X * 2; ++j) { \ + src_uv[(i * kWidth / SUBSAMP_X) * 2 + j] = (random() & 0xff); \ + } \ + MaskCpuFlags(kCpuInitialized); \ + FMT_PLANAR##To##FMT_B(src_y, kWidth, \ + src_uv, kWidth / SUBSAMP_X * 2, \ + dst_argb_c, kWidth * BPP_B, \ + kWidth, NEG kHeight); \ + MaskCpuFlags(-1); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_PLANAR##To##FMT_B(src_y, kWidth, \ + src_uv, kWidth / SUBSAMP_X * 2, \ + dst_argb_opt, kWidth * BPP_B, \ + kWidth, NEG kHeight); \ + } \ + int max_diff = 0; \ + for (int i = 0; i < kHeight; ++i) { \ + for (int j = 0; j < kWidth * BPP_B; ++j) { \ + int abs_diff = \ + abs(static_cast<int>(dst_argb_c[i * kWidth * BPP_B + j]) - \ + static_cast<int>(dst_argb_opt[i * kWidth * BPP_B + j])); \ + if (abs_diff > max_diff) { \ + max_diff = abs_diff; \ + } \ + } \ + } \ + EXPECT_LE(max_diff, 3); \ + free_aligned_buffer_16(src_y) \ + free_aligned_buffer_16(src_uv) \ + free_aligned_buffer_16(dst_argb_c) \ + free_aligned_buffer_16(dst_argb_opt) \ +} + +#define TESTBIPLANARTOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B) \ + TESTBIPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, , +) \ + TESTBIPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, Invert, -) + +TESTBIPLANARTOB(NV12, 2, 2, ARGB, 4) +TESTBIPLANARTOB(NV21, 2, 2, ARGB, 4) +TESTBIPLANARTOB(NV12, 2, 2, RGB565, 2) +TESTBIPLANARTOB(NV21, 2, 2, RGB565, 2) + +#define TESTATOPLANARI(FMT_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, N, NEG) \ +TEST_F(libyuvTest, FMT_A##To##FMT_PLANAR##N##_OptVsC) { \ + const int kWidth = 1280; \ + const int kHeight = 720; \ + const int kStride = (kWidth * 8 * BPP_A + 7) / 8; \ + align_buffer_16(src_argb, kStride * kHeight); \ + align_buffer_16(dst_y_c, kWidth * kHeight); \ + align_buffer_16(dst_u_c, kWidth / SUBSAMP_X * kHeight / SUBSAMP_Y); \ + align_buffer_16(dst_v_c, kWidth / SUBSAMP_X * kHeight / SUBSAMP_Y); \ + align_buffer_16(dst_y_opt, kWidth * kHeight); \ + align_buffer_16(dst_u_opt, kWidth / SUBSAMP_X * kHeight / SUBSAMP_Y); \ + align_buffer_16(dst_v_opt, kWidth / SUBSAMP_X * kHeight / SUBSAMP_Y); \ + srandom(time(NULL)); \ + for (int i = 0; i < kHeight; ++i) \ + for (int j = 0; j < kStride; ++j) \ + src_argb[(i * kStride) + j] = (random() & 0xff); \ + MaskCpuFlags(kCpuInitialized); \ + FMT_A##To##FMT_PLANAR(src_argb, kStride, \ + dst_y_c, kWidth, \ + dst_u_c, kWidth / SUBSAMP_X, \ + dst_v_c, kWidth / SUBSAMP_X, \ + kWidth, NEG kHeight); \ + MaskCpuFlags(-1); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_A##To##FMT_PLANAR(src_argb, kStride, \ + dst_y_opt, kWidth, \ + dst_u_opt, kWidth / SUBSAMP_X, \ + dst_v_opt, kWidth / SUBSAMP_X, \ + kWidth, NEG kHeight); \ + } \ + int max_diff = 0; \ + for (int i = 0; i < kHeight; ++i) { \ + for (int j = 0; j < kWidth; ++j) { \ + int abs_diff = \ + abs(static_cast<int>(dst_y_c[i * kWidth + j]) - \ + static_cast<int>(dst_y_opt[i * kWidth + j])); \ + if (abs_diff > max_diff) { \ + max_diff = abs_diff; \ + } \ + } \ + } \ + EXPECT_LE(max_diff, 2); \ + for (int i = 0; i < kHeight / SUBSAMP_Y; ++i) { \ + for (int j = 0; j < kWidth / SUBSAMP_X; ++j) { \ + int abs_diff = \ + abs(static_cast<int>(dst_u_c[i * kWidth / SUBSAMP_X + j]) - \ + static_cast<int>(dst_u_opt[i * kWidth / SUBSAMP_X + j])); \ + if (abs_diff > max_diff) { \ + max_diff = abs_diff; \ + } \ + } \ + } \ + EXPECT_LE(max_diff, 2); \ + for (int i = 0; i < kHeight / SUBSAMP_Y; ++i) { \ + for (int j = 0; j < kWidth / SUBSAMP_X; ++j) { \ + int abs_diff = \ + abs(static_cast<int>(dst_v_c[i * kWidth / SUBSAMP_X + j]) - \ + static_cast<int>(dst_v_opt[i * kWidth / SUBSAMP_X + j])); \ + if (abs_diff > max_diff) { \ + max_diff = abs_diff; \ + } \ + } \ + } \ + EXPECT_LE(max_diff, 2); \ + free_aligned_buffer_16(dst_y_c) \ + free_aligned_buffer_16(dst_u_c) \ + free_aligned_buffer_16(dst_v_c) \ + free_aligned_buffer_16(dst_y_opt) \ + free_aligned_buffer_16(dst_u_opt) \ + free_aligned_buffer_16(dst_v_opt) \ + free_aligned_buffer_16(src_argb) \ +} + +#define TESTATOPLANAR(FMT_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y) \ + TESTATOPLANARI(FMT_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, , +) \ + TESTATOPLANARI(FMT_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, Invert, -) + +TESTATOPLANAR(ARGB, 4, I420, 2, 2) +TESTATOPLANAR(BGRA, 4, I420, 2, 2) +TESTATOPLANAR(ABGR, 4, I420, 2, 2) +TESTATOPLANAR(RGBA, 4, I420, 2, 2) +TESTATOPLANAR(RAW, 3, I420, 2, 2) +TESTATOPLANAR(RGB24, 3, I420, 2, 2) +TESTATOPLANAR(RGB565, 2, I420, 2, 2) +TESTATOPLANAR(ARGB1555, 2, I420, 2, 2) +TESTATOPLANAR(ARGB4444, 2, I420, 2, 2) +// TESTATOPLANAR(ARGB, 4, I411, 4, 1) +TESTATOPLANAR(ARGB, 4, I422, 2, 1) +// TESTATOPLANAR(ARGB, 4, I444, 1, 1) +// TODO(fbarchard): Implement and test 411 and 444 +TESTATOPLANAR(YUY2, 2, I420, 2, 2) +TESTATOPLANAR(UYVY, 2, I420, 2, 2) +TESTATOPLANAR(YUY2, 2, I422, 2, 1) +TESTATOPLANAR(UYVY, 2, I422, 2, 1) +TESTATOPLANAR(V210, 16 / 6, I420, 2, 2) +TESTATOPLANAR(I400, 1, I420, 2, 2) +TESTATOPLANAR(BayerBGGR, 1, I420, 2, 2) +TESTATOPLANAR(BayerRGGB, 1, I420, 2, 2) +TESTATOPLANAR(BayerGBRG, 1, I420, 2, 2) +TESTATOPLANAR(BayerGRBG, 1, I420, 2, 2) + +#define TESTATOBI(FMT_A, BPP_A, STRIDE_A, FMT_B, BPP_B, N, NEG) \ +TEST_F(libyuvTest, FMT_A##To##FMT_B##N##_OptVsC) { \ + const int kWidth = 1280; \ + const int kHeight = 720; \ + align_buffer_16(src_argb, (kWidth * BPP_A) * kHeight); \ + align_buffer_16(dst_argb_c, (kWidth * BPP_B) * kHeight); \ + align_buffer_16(dst_argb_opt, (kWidth * BPP_B) * kHeight); \ + srandom(time(NULL)); \ + for (int i = 0; i < kHeight * kWidth * BPP_A; ++i) { \ + src_argb[i] = (random() & 0xff); \ + } \ + MaskCpuFlags(kCpuInitialized); \ + FMT_A##To##FMT_B(src_argb, kWidth * STRIDE_A, \ + dst_argb_c, kWidth * BPP_B, \ + kWidth, NEG kHeight); \ + MaskCpuFlags(-1); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_A##To##FMT_B(src_argb, kWidth * STRIDE_A, \ + dst_argb_opt, kWidth * BPP_B, \ + kWidth, NEG kHeight); \ + } \ + int max_diff = 0; \ + for (int i = 0; i < kHeight * kWidth * BPP_B; ++i) { \ + int abs_diff = \ + abs(static_cast<int>(dst_argb_c[i]) - \ + static_cast<int>(dst_argb_opt[i])); \ + if (abs_diff > max_diff) { \ + max_diff = abs_diff; \ + } \ + } \ + EXPECT_LE(max_diff, 2); \ + free_aligned_buffer_16(src_argb) \ + free_aligned_buffer_16(dst_argb_c) \ + free_aligned_buffer_16(dst_argb_opt) \ +} +#define TESTATOB(FMT_A, BPP_A, STRIDE_A, FMT_B, BPP_B) \ + TESTATOBI(FMT_A, BPP_A, STRIDE_A, FMT_B, BPP_B, , +) \ + TESTATOBI(FMT_A, BPP_A, STRIDE_A, FMT_B, BPP_B, Invert, -) + +TESTATOB(I400, 1, 1, I400, 1) +TESTATOB(ARGB, 4, 4, ARGB, 4) +TESTATOB(ARGB, 4, 4, BGRA, 4) +TESTATOB(ARGB, 4, 4, ABGR, 4) +TESTATOB(ARGB, 4, 4, RGBA, 4) +TESTATOB(ARGB, 4, 4, RAW, 3) +TESTATOB(ARGB, 4, 4, RGB24, 3) +TESTATOB(ARGB, 4, 4, RGB565, 2) +TESTATOB(ARGB, 4, 4, ARGB1555, 2) +TESTATOB(ARGB, 4, 4, ARGB4444, 2) +TESTATOB(BGRA, 4, 4, ARGB, 4) +TESTATOB(ABGR, 4, 4, ARGB, 4) +TESTATOB(RGBA, 4, 4, ARGB, 4) +TESTATOB(RAW, 3, 3, ARGB, 4) +TESTATOB(RGB24, 3, 3, ARGB, 4) +TESTATOB(RGB565, 2, 2, ARGB, 4) +TESTATOB(ARGB1555, 2, 2, ARGB, 4) +TESTATOB(ARGB4444, 2, 2, ARGB, 4) +TESTATOB(YUY2, 2, 2, ARGB, 4) +TESTATOB(UYVY, 2, 2, ARGB, 4) +TESTATOB(M420, 3 / 2, 1, ARGB, 4) + +static const int kReadPad = 16; // Allow overread of 16 bytes. +#define TESTATOBRANDOM(FMT_A, BPP_A, STRIDE_A, FMT_B, BPP_B) \ +TEST_F(libyuvTest, FMT_A##To##FMT_B##_Random) { \ + srandom(time(NULL)); \ + for (int times = 0; times < benchmark_iterations_; ++times) { \ + const int kWidth = (random() & 63) + 1; \ + const int kHeight = (random() & 31) + 1; \ + align_buffer_page_end(src_argb, (kWidth * BPP_A) * kHeight + kReadPad); \ + align_buffer_page_end(dst_argb_c, (kWidth * BPP_B) * kHeight); \ + align_buffer_page_end(dst_argb_opt, (kWidth * BPP_B) * kHeight); \ + for (int i = 0; i < kHeight * kWidth * BPP_A; ++i) { \ + src_argb[i] = (random() & 0xff); \ + } \ + MaskCpuFlags(kCpuInitialized); \ + FMT_A##To##FMT_B(src_argb, kWidth * STRIDE_A, \ + dst_argb_c, kWidth * BPP_B, \ + kWidth, kHeight); \ + MaskCpuFlags(-1); \ + FMT_A##To##FMT_B(src_argb, kWidth * STRIDE_A, \ + dst_argb_opt, kWidth * BPP_B, \ + kWidth, kHeight); \ + int max_diff = 0; \ + for (int i = 0; i < kHeight * kWidth * BPP_B; ++i) { \ + int abs_diff = \ + abs(static_cast<int>(dst_argb_c[i]) - \ + static_cast<int>(dst_argb_opt[i])); \ + if (abs_diff > max_diff) { \ + max_diff = abs_diff; \ + } \ + } \ + EXPECT_LE(max_diff, 2); \ + free_aligned_buffer_page_end(src_argb) \ + free_aligned_buffer_page_end(dst_argb_c) \ + free_aligned_buffer_page_end(dst_argb_opt) \ + } \ +} + +TESTATOBRANDOM(ARGB, 4, 4, ARGB, 4) +TESTATOBRANDOM(ARGB, 4, 4, BGRA, 4) +TESTATOBRANDOM(ARGB, 4, 4, ABGR, 4) +TESTATOBRANDOM(ARGB, 4, 4, RGBA, 4) +TESTATOBRANDOM(ARGB, 4, 4, RAW, 3) +TESTATOBRANDOM(ARGB, 4, 4, RGB24, 3) +TESTATOBRANDOM(ARGB, 4, 4, RGB565, 2) +TESTATOBRANDOM(ARGB, 4, 4, ARGB1555, 2) +TESTATOBRANDOM(ARGB, 4, 4, ARGB4444, 2) + +TESTATOBRANDOM(BGRA, 4, 4, ARGB, 4) +TESTATOBRANDOM(ABGR, 4, 4, ARGB, 4) +TESTATOBRANDOM(RGBA, 4, 4, ARGB, 4) +TESTATOBRANDOM(RAW, 3, 3, ARGB, 4) +TESTATOBRANDOM(RGB24, 3, 3, ARGB, 4) +TESTATOBRANDOM(RGB565, 2, 2, ARGB, 4) +TESTATOBRANDOM(ARGB1555, 2, 2, ARGB, 4) +TESTATOBRANDOM(ARGB4444, 2, 2, ARGB, 4) + +TEST_F(libyuvTest, TestAttenuate) { + SIMD_ALIGNED(uint8 orig_pixels[256][4]); + SIMD_ALIGNED(uint8 atten_pixels[256][4]); + SIMD_ALIGNED(uint8 unatten_pixels[256][4]); + SIMD_ALIGNED(uint8 atten2_pixels[256][4]); + + // Test unattenuation clamps + orig_pixels[0][0] = 200u; + orig_pixels[0][1] = 129u; + orig_pixels[0][2] = 127u; + orig_pixels[0][3] = 128u; + // Test unattenuation transparent and opaque are unaffected + orig_pixels[1][0] = 16u; + orig_pixels[1][1] = 64u; + orig_pixels[1][2] = 192u; + orig_pixels[1][3] = 0u; + orig_pixels[2][0] = 16u; + orig_pixels[2][1] = 64u; + orig_pixels[2][2] = 192u; + orig_pixels[2][3] = 255u; + orig_pixels[3][0] = 16u; + orig_pixels[3][1] = 64u; + orig_pixels[3][2] = 192u; + orig_pixels[3][3] = 128u; + ARGBUnattenuate(&orig_pixels[0][0], 0, &unatten_pixels[0][0], 0, 4, 1); + EXPECT_EQ(255u, unatten_pixels[0][0]); + EXPECT_EQ(255u, unatten_pixels[0][1]); + EXPECT_EQ(254u, unatten_pixels[0][2]); + EXPECT_EQ(128u, unatten_pixels[0][3]); + EXPECT_EQ(16u, unatten_pixels[1][0]); + EXPECT_EQ(64u, unatten_pixels[1][1]); + EXPECT_EQ(192u, unatten_pixels[1][2]); + EXPECT_EQ(0u, unatten_pixels[1][3]); + EXPECT_EQ(16u, unatten_pixels[2][0]); + EXPECT_EQ(64u, unatten_pixels[2][1]); + EXPECT_EQ(192u, unatten_pixels[2][2]); + EXPECT_EQ(255u, unatten_pixels[2][3]); + EXPECT_EQ(32u, unatten_pixels[3][0]); + EXPECT_EQ(128u, unatten_pixels[3][1]); + EXPECT_EQ(255u, unatten_pixels[3][2]); + EXPECT_EQ(128u, unatten_pixels[3][3]); + + for (int i = 0; i < 256; ++i) { + orig_pixels[i][0] = i; + orig_pixels[i][1] = i / 2; + orig_pixels[i][2] = i / 3; + orig_pixels[i][3] = i; + } + ARGBAttenuate(&orig_pixels[0][0], 0, &atten_pixels[0][0], 0, 256, 1); + ARGBUnattenuate(&atten_pixels[0][0], 0, &unatten_pixels[0][0], 0, 256, 1); + for (int i = 0; i < benchmark_iterations_ * 1280 * 720 / 256; ++i) { + ARGBAttenuate(&unatten_pixels[0][0], 0, &atten2_pixels[0][0], 0, 256, 1); + } + for (int i = 0; i < 256; ++i) { + EXPECT_NEAR(atten_pixels[i][0], atten2_pixels[i][0], 2); + EXPECT_NEAR(atten_pixels[i][1], atten2_pixels[i][1], 2); + EXPECT_NEAR(atten_pixels[i][2], atten2_pixels[i][2], 2); + EXPECT_NEAR(atten_pixels[i][3], atten2_pixels[i][3], 2); + } + // Make sure transparent, 50% and opaque are fully accurate. + EXPECT_EQ(0, atten_pixels[0][0]); + EXPECT_EQ(0, atten_pixels[0][1]); + EXPECT_EQ(0, atten_pixels[0][2]); + EXPECT_EQ(0, atten_pixels[0][3]); + EXPECT_EQ(64, atten_pixels[128][0]); + EXPECT_EQ(32, atten_pixels[128][1]); + EXPECT_EQ(21, atten_pixels[128][2]); + EXPECT_EQ(128, atten_pixels[128][3]); + EXPECT_EQ(255, atten_pixels[255][0]); + EXPECT_EQ(127, atten_pixels[255][1]); + EXPECT_EQ(85, atten_pixels[255][2]); + EXPECT_EQ(255, atten_pixels[255][3]); +} + +TEST_F(libyuvTest, TestARGBComputeCumulativeSum) { + SIMD_ALIGNED(uint8 orig_pixels[16][16][4]); + SIMD_ALIGNED(int32 added_pixels[16][16][4]); + + for (int y = 0; y < 16; ++y) { + for (int x = 0; x < 16; ++x) { + orig_pixels[y][x][0] = 1u; + orig_pixels[y][x][1] = 2u; + orig_pixels[y][x][2] = 3u; + orig_pixels[y][x][3] = 255u; + } + } + + ARGBComputeCumulativeSum(&orig_pixels[0][0][0], 16 * 4, + &added_pixels[0][0][0], 16 * 4, + 16, 16); + + for (int y = 0; y < 16; ++y) { + for (int x = 0; x < 16; ++x) { + EXPECT_EQ((x + 1) * (y + 1), added_pixels[y][x][0]); + EXPECT_EQ((x + 1) * (y + 1) * 2, added_pixels[y][x][1]); + EXPECT_EQ((x + 1) * (y + 1) * 3, added_pixels[y][x][2]); + EXPECT_EQ((x + 1) * (y + 1) * 255, added_pixels[y][x][3]); + } + } +} + +TEST_F(libyuvTest, TestARGBGray) { + SIMD_ALIGNED(uint8 orig_pixels[256][4]); + + // Test blue + orig_pixels[0][0] = 255u; + orig_pixels[0][1] = 0u; + orig_pixels[0][2] = 0u; + orig_pixels[0][3] = 128u; + // Test green + orig_pixels[1][0] = 0u; + orig_pixels[1][1] = 255u; + orig_pixels[1][2] = 0u; + orig_pixels[1][3] = 0u; + // Test red + orig_pixels[2][0] = 0u; + orig_pixels[2][1] = 0u; + orig_pixels[2][2] = 255u; + orig_pixels[2][3] = 255u; + // Test color + orig_pixels[3][0] = 16u; + orig_pixels[3][1] = 64u; + orig_pixels[3][2] = 192u; + orig_pixels[3][3] = 224u; + // Do 16 to test asm version. + ARGBGray(&orig_pixels[0][0], 0, 0, 0, 16, 1); + EXPECT_EQ(27u, orig_pixels[0][0]); + EXPECT_EQ(27u, orig_pixels[0][1]); + EXPECT_EQ(27u, orig_pixels[0][2]); + EXPECT_EQ(128u, orig_pixels[0][3]); + EXPECT_EQ(151u, orig_pixels[1][0]); + EXPECT_EQ(151u, orig_pixels[1][1]); + EXPECT_EQ(151u, orig_pixels[1][2]); + EXPECT_EQ(0u, orig_pixels[1][3]); + EXPECT_EQ(75u, orig_pixels[2][0]); + EXPECT_EQ(75u, orig_pixels[2][1]); + EXPECT_EQ(75u, orig_pixels[2][2]); + EXPECT_EQ(255u, orig_pixels[2][3]); + EXPECT_EQ(96u, orig_pixels[3][0]); + EXPECT_EQ(96u, orig_pixels[3][1]); + EXPECT_EQ(96u, orig_pixels[3][2]); + EXPECT_EQ(224u, orig_pixels[3][3]); + + for (int i = 0; i < 256; ++i) { + orig_pixels[i][0] = i; + orig_pixels[i][1] = i / 2; + orig_pixels[i][2] = i / 3; + orig_pixels[i][3] = i; + } + + for (int i = 0; i < benchmark_iterations_ * 1280 * 720 / 256; ++i) { + ARGBGray(&orig_pixels[0][0], 0, 0, 0, 256, 1); + } +} + +TEST_F(libyuvTest, TestARGBGrayTo) { + SIMD_ALIGNED(uint8 orig_pixels[256][4]); + SIMD_ALIGNED(uint8 gray_pixels[256][4]); + + // Test blue + orig_pixels[0][0] = 255u; + orig_pixels[0][1] = 0u; + orig_pixels[0][2] = 0u; + orig_pixels[0][3] = 128u; + // Test green + orig_pixels[1][0] = 0u; + orig_pixels[1][1] = 255u; + orig_pixels[1][2] = 0u; + orig_pixels[1][3] = 0u; + // Test red + orig_pixels[2][0] = 0u; + orig_pixels[2][1] = 0u; + orig_pixels[2][2] = 255u; + orig_pixels[2][3] = 255u; + // Test color + orig_pixels[3][0] = 16u; + orig_pixels[3][1] = 64u; + orig_pixels[3][2] = 192u; + orig_pixels[3][3] = 224u; + // Do 16 to test asm version. + ARGBGrayTo(&orig_pixels[0][0], 0, &gray_pixels[0][0], 0, 16, 1); + EXPECT_EQ(27u, gray_pixels[0][0]); + EXPECT_EQ(27u, gray_pixels[0][1]); + EXPECT_EQ(27u, gray_pixels[0][2]); + EXPECT_EQ(128u, gray_pixels[0][3]); + EXPECT_EQ(151u, gray_pixels[1][0]); + EXPECT_EQ(151u, gray_pixels[1][1]); + EXPECT_EQ(151u, gray_pixels[1][2]); + EXPECT_EQ(0u, gray_pixels[1][3]); + EXPECT_EQ(75u, gray_pixels[2][0]); + EXPECT_EQ(75u, gray_pixels[2][1]); + EXPECT_EQ(75u, gray_pixels[2][2]); + EXPECT_EQ(255u, gray_pixels[2][3]); + EXPECT_EQ(96u, gray_pixels[3][0]); + EXPECT_EQ(96u, gray_pixels[3][1]); + EXPECT_EQ(96u, gray_pixels[3][2]); + EXPECT_EQ(224u, gray_pixels[3][3]); + + for (int i = 0; i < 256; ++i) { + orig_pixels[i][0] = i; + orig_pixels[i][1] = i / 2; + orig_pixels[i][2] = i / 3; + orig_pixels[i][3] = i; + } + + for (int i = 0; i < benchmark_iterations_ * 1280 * 720 / 256; ++i) { + ARGBGrayTo(&orig_pixels[0][0], 0, &gray_pixels[0][0], 0, 256, 1); + } +} + +TEST_F(libyuvTest, TestARGBSepia) { + SIMD_ALIGNED(uint8 orig_pixels[256][4]); + + // Test blue + orig_pixels[0][0] = 255u; + orig_pixels[0][1] = 0u; + orig_pixels[0][2] = 0u; + orig_pixels[0][3] = 128u; + // Test green + orig_pixels[1][0] = 0u; + orig_pixels[1][1] = 255u; + orig_pixels[1][2] = 0u; + orig_pixels[1][3] = 0u; + // Test red + orig_pixels[2][0] = 0u; + orig_pixels[2][1] = 0u; + orig_pixels[2][2] = 255u; + orig_pixels[2][3] = 255u; + // Test color + orig_pixels[3][0] = 16u; + orig_pixels[3][1] = 64u; + orig_pixels[3][2] = 192u; + orig_pixels[3][3] = 224u; + // Do 16 to test asm version. + ARGBSepia(&orig_pixels[0][0], 0, 0, 0, 16, 1); + EXPECT_EQ(33u, orig_pixels[0][0]); + EXPECT_EQ(43u, orig_pixels[0][1]); + EXPECT_EQ(47u, orig_pixels[0][2]); + EXPECT_EQ(128u, orig_pixels[0][3]); + EXPECT_EQ(135u, orig_pixels[1][0]); + EXPECT_EQ(175u, orig_pixels[1][1]); + EXPECT_EQ(195u, orig_pixels[1][2]); + EXPECT_EQ(0u, orig_pixels[1][3]); + EXPECT_EQ(69u, orig_pixels[2][0]); + EXPECT_EQ(89u, orig_pixels[2][1]); + EXPECT_EQ(99u, orig_pixels[2][2]); + EXPECT_EQ(255u, orig_pixels[2][3]); + EXPECT_EQ(88u, orig_pixels[3][0]); + EXPECT_EQ(114u, orig_pixels[3][1]); + EXPECT_EQ(127u, orig_pixels[3][2]); + EXPECT_EQ(224u, orig_pixels[3][3]); + + for (int i = 0; i < 256; ++i) { + orig_pixels[i][0] = i; + orig_pixels[i][1] = i / 2; + orig_pixels[i][2] = i / 3; + orig_pixels[i][3] = i; + } + + for (int i = 0; i < benchmark_iterations_ * 1280 * 720 / 256; ++i) { + ARGBSepia(&orig_pixels[0][0], 0, 0, 0, 256, 1); + } +} + +TEST_F(libyuvTest, TestARGBColorMatrix) { + SIMD_ALIGNED(uint8 orig_pixels[256][4]); + + // Matrix for Sepia. + static const int8 kARGBToSepia[] = { + 17, 68, 35, 0, + 22, 88, 45, 0, + 24, 98, 50, 0, + }; + + // Test blue + orig_pixels[0][0] = 255u; + orig_pixels[0][1] = 0u; + orig_pixels[0][2] = 0u; + orig_pixels[0][3] = 128u; + // Test green + orig_pixels[1][0] = 0u; + orig_pixels[1][1] = 255u; + orig_pixels[1][2] = 0u; + orig_pixels[1][3] = 0u; + // Test red + orig_pixels[2][0] = 0u; + orig_pixels[2][1] = 0u; + orig_pixels[2][2] = 255u; + orig_pixels[2][3] = 255u; + // Test color + orig_pixels[3][0] = 16u; + orig_pixels[3][1] = 64u; + orig_pixels[3][2] = 192u; + orig_pixels[3][3] = 224u; + // Do 16 to test asm version. + ARGBColorMatrix(&orig_pixels[0][0], 0, &kARGBToSepia[0], 0, 0, 16, 1); + EXPECT_EQ(33u, orig_pixels[0][0]); + EXPECT_EQ(43u, orig_pixels[0][1]); + EXPECT_EQ(47u, orig_pixels[0][2]); + EXPECT_EQ(128u, orig_pixels[0][3]); + EXPECT_EQ(135u, orig_pixels[1][0]); + EXPECT_EQ(175u, orig_pixels[1][1]); + EXPECT_EQ(195u, orig_pixels[1][2]); + EXPECT_EQ(0u, orig_pixels[1][3]); + EXPECT_EQ(69u, orig_pixels[2][0]); + EXPECT_EQ(89u, orig_pixels[2][1]); + EXPECT_EQ(99u, orig_pixels[2][2]); + EXPECT_EQ(255u, orig_pixels[2][3]); + EXPECT_EQ(88u, orig_pixels[3][0]); + EXPECT_EQ(114u, orig_pixels[3][1]); + EXPECT_EQ(127u, orig_pixels[3][2]); + EXPECT_EQ(224u, orig_pixels[3][3]); + + for (int i = 0; i < 256; ++i) { + orig_pixels[i][0] = i; + orig_pixels[i][1] = i / 2; + orig_pixels[i][2] = i / 3; + orig_pixels[i][3] = i; + } + + for (int i = 0; i < benchmark_iterations_ * 1280 * 720 / 256; ++i) { + ARGBColorMatrix(&orig_pixels[0][0], 0, &kARGBToSepia[0], 0, 0, 256, 1); + } +} + +TEST_F(libyuvTest, TestARGBColorTable) { + SIMD_ALIGNED(uint8 orig_pixels[256][4]); + memset(orig_pixels, 0, sizeof(orig_pixels)); + + // Matrix for Sepia. + static const uint8 kARGBTable[256 * 4] = { + 1u, 2u, 3u, 4u, + 5u, 6u, 7u, 8u, + 9u, 10u, 11u, 12u, + 13u, 14u, 15u, 16u, + }; + + orig_pixels[0][0] = 0u; + orig_pixels[0][1] = 0u; + orig_pixels[0][2] = 0u; + orig_pixels[0][3] = 0u; + orig_pixels[1][0] = 1u; + orig_pixels[1][1] = 1u; + orig_pixels[1][2] = 1u; + orig_pixels[1][3] = 1u; + orig_pixels[2][0] = 2u; + orig_pixels[2][1] = 2u; + orig_pixels[2][2] = 2u; + orig_pixels[2][3] = 2u; + orig_pixels[3][0] = 0u; + orig_pixels[3][1] = 1u; + orig_pixels[3][2] = 2u; + orig_pixels[3][3] = 3u; + // Do 16 to test asm version. + ARGBColorTable(&orig_pixels[0][0], 0, &kARGBTable[0], 0, 0, 16, 1); + EXPECT_EQ(1u, orig_pixels[0][0]); + EXPECT_EQ(2u, orig_pixels[0][1]); + EXPECT_EQ(3u, orig_pixels[0][2]); + EXPECT_EQ(4u, orig_pixels[0][3]); + EXPECT_EQ(5u, orig_pixels[1][0]); + EXPECT_EQ(6u, orig_pixels[1][1]); + EXPECT_EQ(7u, orig_pixels[1][2]); + EXPECT_EQ(8u, orig_pixels[1][3]); + EXPECT_EQ(9u, orig_pixels[2][0]); + EXPECT_EQ(10u, orig_pixels[2][1]); + EXPECT_EQ(11u, orig_pixels[2][2]); + EXPECT_EQ(12u, orig_pixels[2][3]); + EXPECT_EQ(1u, orig_pixels[3][0]); + EXPECT_EQ(6u, orig_pixels[3][1]); + EXPECT_EQ(11u, orig_pixels[3][2]); + EXPECT_EQ(16u, orig_pixels[3][3]); + + for (int i = 0; i < 256; ++i) { + orig_pixels[i][0] = i; + orig_pixels[i][1] = i / 2; + orig_pixels[i][2] = i / 3; + orig_pixels[i][3] = i; + } + + for (int i = 0; i < benchmark_iterations_ * 1280 * 720 / 256; ++i) { + ARGBColorTable(&orig_pixels[0][0], 0, &kARGBTable[0], 0, 0, 256, 1); + } +} + +TEST_F(libyuvTest, TestARGBQuantize) { + SIMD_ALIGNED(uint8 orig_pixels[256][4]); + + for (int i = 0; i < 256; ++i) { + orig_pixels[i][0] = i; + orig_pixels[i][1] = i / 2; + orig_pixels[i][2] = i / 3; + orig_pixels[i][3] = i; + } + ARGBQuantize(&orig_pixels[0][0], 0, + (65536 + (8 / 2)) / 8, 8, 8 / 2, 0, 0, 256, 1); + + for (int i = 0; i < 256; ++i) { + EXPECT_EQ(i / 8 * 8 + 8 / 2, orig_pixels[i][0]); + EXPECT_EQ(i / 2 / 8 * 8 + 8 / 2, orig_pixels[i][1]); + EXPECT_EQ(i / 3 / 8 * 8 + 8 / 2, orig_pixels[i][2]); + EXPECT_EQ(i, orig_pixels[i][3]); + } + for (int i = 0; i < benchmark_iterations_ * 1280 * 720 / 256; ++i) { + ARGBQuantize(&orig_pixels[0][0], 0, + (65536 + (8 / 2)) / 8, 8, 8 / 2, 0, 0, 256, 1); + } +} + +TEST_F(libyuvTest, TestARGBMirror) { + SIMD_ALIGNED(uint8 orig_pixels[256][4]); + SIMD_ALIGNED(uint8 dst_pixels[256][4]); + + for (int i = 0; i < 256; ++i) { + orig_pixels[i][0] = i; + orig_pixels[i][1] = i / 2; + orig_pixels[i][2] = i / 3; + orig_pixels[i][3] = i / 4; + } + ARGBMirror(&orig_pixels[0][0], 0, &dst_pixels[0][0], 0, 256, 1); + + for (int i = 0; i < 256; ++i) { + EXPECT_EQ(i, dst_pixels[255 - i][0]); + EXPECT_EQ(i / 2, dst_pixels[255 - i][1]); + EXPECT_EQ(i / 3, dst_pixels[255 - i][2]); + EXPECT_EQ(i / 4, dst_pixels[255 - i][3]); + } + for (int i = 0; i < benchmark_iterations_ * 1280 * 720 / 256; ++i) { + ARGBMirror(&orig_pixels[0][0], 0, &dst_pixels[0][0], 0, 256, 1); + } +} + +TEST_F(libyuvTest, TestShade) { + SIMD_ALIGNED(uint8 orig_pixels[256][4]); + SIMD_ALIGNED(uint8 shade_pixels[256][4]); + + orig_pixels[0][0] = 10u; + orig_pixels[0][1] = 20u; + orig_pixels[0][2] = 40u; + orig_pixels[0][3] = 80u; + orig_pixels[1][0] = 0u; + orig_pixels[1][1] = 0u; + orig_pixels[1][2] = 0u; + orig_pixels[1][3] = 255u; + orig_pixels[2][0] = 0u; + orig_pixels[2][1] = 0u; + orig_pixels[2][2] = 0u; + orig_pixels[2][3] = 0u; + orig_pixels[3][0] = 0u; + orig_pixels[3][1] = 0u; + orig_pixels[3][2] = 0u; + orig_pixels[3][3] = 0u; + ARGBShade(&orig_pixels[0][0], 0, &shade_pixels[0][0], 0, 4, 1, 0x80ffffff); + EXPECT_EQ(10u, shade_pixels[0][0]); + EXPECT_EQ(20u, shade_pixels[0][1]); + EXPECT_EQ(40u, shade_pixels[0][2]); + EXPECT_EQ(40u, shade_pixels[0][3]); + EXPECT_EQ(0u, shade_pixels[1][0]); + EXPECT_EQ(0u, shade_pixels[1][1]); + EXPECT_EQ(0u, shade_pixels[1][2]); + EXPECT_EQ(128u, shade_pixels[1][3]); + EXPECT_EQ(0u, shade_pixels[2][0]); + EXPECT_EQ(0u, shade_pixels[2][1]); + EXPECT_EQ(0u, shade_pixels[2][2]); + EXPECT_EQ(0u, shade_pixels[2][3]); + EXPECT_EQ(0u, shade_pixels[3][0]); + EXPECT_EQ(0u, shade_pixels[3][1]); + EXPECT_EQ(0u, shade_pixels[3][2]); + EXPECT_EQ(0u, shade_pixels[3][3]); + + ARGBShade(&orig_pixels[0][0], 0, &shade_pixels[0][0], 0, 4, 1, 0x80808080); + EXPECT_EQ(5u, shade_pixels[0][0]); + EXPECT_EQ(10u, shade_pixels[0][1]); + EXPECT_EQ(20u, shade_pixels[0][2]); + EXPECT_EQ(40u, shade_pixels[0][3]); + + for (int i = 0; i < benchmark_iterations_ * 1280 * 720 / 256; ++i) { + ARGBShade(&orig_pixels[0][0], 0, &shade_pixels[0][0], 0, 256, 1, + 0x80808080); + } +} + +TEST_F(libyuvTest, TestInterpolate) { + SIMD_ALIGNED(uint8 orig_pixels_0[256][4]); + SIMD_ALIGNED(uint8 orig_pixels_1[256][4]); + SIMD_ALIGNED(uint8 interpolate_pixels[256][4]); + + orig_pixels_0[0][0] = 16u; + orig_pixels_0[0][1] = 32u; + orig_pixels_0[0][2] = 64u; + orig_pixels_0[0][3] = 128u; + orig_pixels_0[1][0] = 0u; + orig_pixels_0[1][1] = 0u; + orig_pixels_0[1][2] = 0u; + orig_pixels_0[1][3] = 255u; + orig_pixels_0[2][0] = 0u; + orig_pixels_0[2][1] = 0u; + orig_pixels_0[2][2] = 0u; + orig_pixels_0[2][3] = 0u; + orig_pixels_0[3][0] = 0u; + orig_pixels_0[3][1] = 0u; + orig_pixels_0[3][2] = 0u; + orig_pixels_0[3][3] = 0u; + + orig_pixels_1[0][0] = 0u; + orig_pixels_1[0][1] = 0u; + orig_pixels_1[0][2] = 0u; + orig_pixels_1[0][3] = 0u; + orig_pixels_1[1][0] = 0u; + orig_pixels_1[1][1] = 0u; + orig_pixels_1[1][2] = 0u; + orig_pixels_1[1][3] = 0u; + orig_pixels_1[2][0] = 0u; + orig_pixels_1[2][1] = 0u; + orig_pixels_1[2][2] = 0u; + orig_pixels_1[2][3] = 0u; + orig_pixels_1[3][0] = 255u; + orig_pixels_1[3][1] = 255u; + orig_pixels_1[3][2] = 255u; + orig_pixels_1[3][3] = 255u; + + ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0, + &interpolate_pixels[0][0], 0, 4, 1, 128); + EXPECT_EQ(8u, interpolate_pixels[0][0]); + EXPECT_EQ(16u, interpolate_pixels[0][1]); + EXPECT_EQ(32u, interpolate_pixels[0][2]); + EXPECT_EQ(64u, interpolate_pixels[0][3]); + EXPECT_EQ(0u, interpolate_pixels[1][0]); + EXPECT_EQ(0u, interpolate_pixels[1][1]); + EXPECT_EQ(0u, interpolate_pixels[1][2]); + EXPECT_NEAR(128u, interpolate_pixels[1][3], 1); // C = 127, SSE = 128. + EXPECT_EQ(0u, interpolate_pixels[2][0]); + EXPECT_EQ(0u, interpolate_pixels[2][1]); + EXPECT_EQ(0u, interpolate_pixels[2][2]); + EXPECT_EQ(0u, interpolate_pixels[2][3]); + EXPECT_NEAR(128u, interpolate_pixels[3][0], 1); + EXPECT_NEAR(128u, interpolate_pixels[3][1], 1); + EXPECT_NEAR(128u, interpolate_pixels[3][2], 1); + EXPECT_NEAR(128u, interpolate_pixels[3][3], 1); + + ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0, + &interpolate_pixels[0][0], 0, 4, 1, 0); + EXPECT_EQ(16u, interpolate_pixels[0][0]); + EXPECT_EQ(32u, interpolate_pixels[0][1]); + EXPECT_EQ(64u, interpolate_pixels[0][2]); + EXPECT_EQ(128u, interpolate_pixels[0][3]); + + ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0, + &interpolate_pixels[0][0], 0, 4, 1, 192); + + EXPECT_EQ(4u, interpolate_pixels[0][0]); + EXPECT_EQ(8u, interpolate_pixels[0][1]); + EXPECT_EQ(16u, interpolate_pixels[0][2]); + EXPECT_EQ(32u, interpolate_pixels[0][3]); + + for (int i = 0; i < benchmark_iterations_ * (1280 * 720 / 256); ++i) { + ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0, + &interpolate_pixels[0][0], 0, 256, 1, 128); + } +} + +TEST_F(libyuvTest, TestAffine) { + SIMD_ALIGNED(uint8 orig_pixels_0[256][4]); + SIMD_ALIGNED(uint8 interpolate_pixels_C[256][4]); +#if defined(HAS_ARGBAFFINEROW_SSE2) + SIMD_ALIGNED(uint8 interpolate_pixels_Opt[256][4]); +#endif + + for (int i = 0; i < 256; ++i) { + for (int j = 0; j < 4; ++j) { + orig_pixels_0[i][j] = i; + } + } + + float uv_step[4] = { 0.f, 0.f, 0.75f, 0.f }; + + ARGBAffineRow_C(&orig_pixels_0[0][0], 0, &interpolate_pixels_C[0][0], + uv_step, 256); + EXPECT_EQ(0u, interpolate_pixels_C[0][0]); + EXPECT_EQ(96u, interpolate_pixels_C[128][0]); + EXPECT_EQ(191u, interpolate_pixels_C[255][3]); + +#if defined(HAS_ARGBAFFINEROW_SSE2) + ARGBAffineRow_SSE2(&orig_pixels_0[0][0], 0, &interpolate_pixels_Opt[0][0], + uv_step, 256); + EXPECT_EQ(0, memcmp(interpolate_pixels_Opt, interpolate_pixels_C, 256 * 4)); +#endif + +#if defined(HAS_ARGBAFFINEROW_SSE2) + int has_sse2 = TestCpuFlag(kCpuHasSSE2); + if (has_sse2) { + for (int i = 0; i < benchmark_iterations_ * 1280 * 720 / 256; ++i) { + ARGBAffineRow_SSE2(&orig_pixels_0[0][0], 0, &interpolate_pixels_Opt[0][0], + uv_step, 256); + } + } else { +#endif + for (int i = 0; i < benchmark_iterations_ * 1280 * 720 / 256; ++i) { + ARGBAffineRow_C(&orig_pixels_0[0][0], 0, &interpolate_pixels_C[0][0], + uv_step, 256); + } +#if defined(HAS_ARGBAFFINEROW_SSE2) + } +#endif +} + +TEST_F(libyuvTest, Test565) { + SIMD_ALIGNED(uint8 orig_pixels[256][4]); + SIMD_ALIGNED(uint8 pixels565[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 checksum = HashDjb2(&pixels565[0][0], sizeof(pixels565), 5381); + EXPECT_EQ(610919429u, checksum); +} + +} // namespace libyuv diff --git a/files/unit_test/rotate_argb_test.cc b/files/unit_test/rotate_argb_test.cc new file mode 100644 index 00000000..fe8435e1 --- /dev/null +++ b/files/unit_test/rotate_argb_test.cc @@ -0,0 +1,195 @@ +/* + * Copyright 2012 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 <stdlib.h> +#include <time.h> + +#include "libyuv/cpu_id.h" +#include "libyuv/rotate_argb.h" +#include "../unit_test/unit_test.h" + +namespace libyuv { + +static int ARGBTestRotate(int src_width, int src_height, + int dst_width, int dst_height, + libyuv::RotationMode mode, int runs) { + const int b = 128; + int src_argb_plane_size = (src_width + b * 2) * (src_height + b * 2) * 4; + int src_stride_argb = (b * 2 + src_width) * 4; + + align_buffer_16(src_argb, src_argb_plane_size) + memset(src_argb, 1, src_argb_plane_size); + + int dst_argb_plane_size = (dst_width + b * 2) * (dst_height + b * 2) * 4; + int dst_stride_argb = (b * 2 + dst_width) * 4; + + srandom(time(NULL)); + + int i, j; + for (i = b; i < (src_height + b); ++i) { + for (j = b; j < (src_width + b) * 4; ++j) { + src_argb[(i * src_stride_argb) + j] = (random() & 0xff); + } + } + + align_buffer_16(dst_argb_c, dst_argb_plane_size) + align_buffer_16(dst_argb_opt, dst_argb_plane_size) + memset(dst_argb_c, 2, dst_argb_plane_size); + memset(dst_argb_opt, 3, dst_argb_plane_size); + + // Warm up both versions for consistent benchmarks. + MaskCpuFlags(0); // Disable all CPU optimization. + ARGBRotate(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, + dst_argb_c + (dst_stride_argb * b) + b * 4, dst_stride_argb, + src_width, src_height, mode); + MaskCpuFlags(-1); // Enable all CPU optimization. + ARGBRotate(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, + dst_argb_opt + (dst_stride_argb * b) + b * 4, dst_stride_argb, + src_width, src_height, mode); + + MaskCpuFlags(0); // Disable all CPU optimization. + double c_time = get_time(); + for (i = 0; i < runs; ++i) { + ARGBRotate(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, + dst_argb_c + (dst_stride_argb * b) + b * 4, dst_stride_argb, + src_width, src_height, mode); + } + c_time = (get_time() - c_time) / runs; + + MaskCpuFlags(-1); // Enable all CPU optimization. + double opt_time = get_time(); + for (i = 0; i < runs; ++i) { + ARGBRotate(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, + dst_argb_opt + (dst_stride_argb * b) + b * 4, dst_stride_argb, + src_width, src_height, mode); + } + opt_time = (get_time() - opt_time) / runs; + + // Report performance of C vs OPT + printf("filter %d - %8d us C - %8d us OPT\n", + mode, static_cast<int>(c_time*1e6), static_cast<int>(opt_time*1e6)); + + // C version may be a little off from the optimized. Order of + // operations may introduce rounding somewhere. So do a difference + // of the buffers and look to see that the max difference isn't + // over 2. + int max_diff = 0; + for (i = b; i < (dst_height + b); ++i) { + for (j = b * 4; j < (dst_width + b) * 4; ++j) { + int abs_diff = abs(dst_argb_c[(i * dst_stride_argb) + j] - + dst_argb_opt[(i * dst_stride_argb) + j]); + if (abs_diff > max_diff) + max_diff = abs_diff; + } + } + + free_aligned_buffer_16(dst_argb_c) + free_aligned_buffer_16(dst_argb_opt) + free_aligned_buffer_16(src_argb) + return max_diff; +} + +TEST_F(libyuvTest, ARGBRotate0) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = 1280; + const int dst_height = 720; + + int err = ARGBTestRotate(src_width, src_height, + dst_width, dst_height, kRotate0, + benchmark_iterations_); + EXPECT_GE(1, err); +} + +TEST_F(libyuvTest, ARGBRotate90) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = 720; + const int dst_height = 1280; + + int err = ARGBTestRotate(src_width, src_height, + dst_width, dst_height, kRotate90, + benchmark_iterations_); + EXPECT_GE(1, err); +} + +TEST_F(libyuvTest, ARGBRotate180) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = 1280; + const int dst_height = 720; + + int err = ARGBTestRotate(src_width, src_height, + dst_width, dst_height, kRotate180, + benchmark_iterations_); + EXPECT_GE(1, err); +} + +TEST_F(libyuvTest, ARGBRotate270) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = 720; + const int dst_height = 1280; + + int err = ARGBTestRotate(src_width, src_height, + dst_width, dst_height, kRotate270, + benchmark_iterations_); + EXPECT_GE(1, err); +} + +TEST_F(libyuvTest, ARGBRotate0_Odd) { + const int src_width = 1277; + const int src_height = 719; + const int dst_width = 1277; + const int dst_height = 719; + + int err = ARGBTestRotate(src_width, src_height, + dst_width, dst_height, kRotate0, + benchmark_iterations_); + EXPECT_GE(1, err); +} + +TEST_F(libyuvTest, ARGBRotate90_Odd) { + const int src_width = 1277; + const int src_height = 719; + const int dst_width = 719; + const int dst_height = 1277; + + int err = ARGBTestRotate(src_width, src_height, + dst_width, dst_height, kRotate90, + benchmark_iterations_); + EXPECT_GE(1, err); +} + +TEST_F(libyuvTest, ARGBRotate180_Odd) { + const int src_width = 1277; + const int src_height = 719; + const int dst_width = 1277; + const int dst_height = 719; + + int err = ARGBTestRotate(src_width, src_height, + dst_width, dst_height, kRotate180, + benchmark_iterations_); + EXPECT_GE(1, err); +} + +TEST_F(libyuvTest, ARGBRotate270_Odd) { + const int src_width = 1277; + const int src_height = 719; + const int dst_width = 719; + const int dst_height = 1277; + + int err = ARGBTestRotate(src_width, src_height, + dst_width, dst_height, kRotate270, + benchmark_iterations_); + EXPECT_GE(1, err); +} + +} // namespace libyuv diff --git a/files/unit_test/rotate_test.cc b/files/unit_test/rotate_test.cc index 1c295b08..788e511e 100644 --- a/files/unit_test/rotate_test.cc +++ b/files/unit_test/rotate_test.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The LibYuv project authors. All Rights Reserved. + * Copyright 2011 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 @@ -8,21 +8,19 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "libyuv/rotate.h" -#include "../source/rotate_priv.h" -#include "unit_test.h" #include <stdlib.h> #include <time.h> -using namespace libyuv; - -void print_array(uint8 *array, int w, int h) { - int i, j; +#include "libyuv/rotate.h" +#include "../unit_test/unit_test.h" - for (i = 0; i < h; ++i) { - for (j = 0; j < w; ++j) - printf("%4d", (signed char)array[(i * w) + j]); +namespace libyuv { +void PrintArray(uint8 *array, int w, int h) { + for (int i = 0; i < h; ++i) { + for (int j = 0; j < w; ++j) { + printf("%4d", (signed char)array[i * w + j]); + } printf("\n"); } } @@ -31,46 +29,45 @@ TEST_F(libyuvTest, Transpose) { int iw, ih, ow, oh; int err = 0; - for (iw = 8; iw < _rotate_max_w && !err; ++iw) - for (ih = 8; ih < _rotate_max_h && !err; ++ih) { + for (iw = 8; iw < rotate_max_w_ && !err; ++iw) { + for (ih = 8; ih < rotate_max_h_ && !err; ++ih) { int i; - uint8 *input; - uint8 *output_1; - uint8 *output_2; - ow = ih; oh = iw; - input = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_1 = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_2 = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); + align_buffer_16(input, iw * ih) + align_buffer_16(output_1, ow * oh) + align_buffer_16(output_2, iw * ih) - for (i = 0; i < (iw * ih); ++i) + for (i = 0; i < iw * ih; ++i) { input[i] = i; + } TransposePlane(input, iw, output_1, ow, iw, ih); TransposePlane(output_1, ow, output_2, oh, ow, oh); - for (i = 0; i < (iw * ih); ++i) { - if (input[i] != output_2[i]) + for (i = 0; i < iw * ih; ++i) { + if (input[i] != output_2[i]) { err++; + } } if (err) { printf("input %dx%d \n", iw, ih); - print_array(input, iw, ih); + PrintArray(input, iw, ih); printf("transpose 1\n"); - print_array(output_1, ow, oh); + PrintArray(output_1, ow, oh); printf("transpose 2\n"); - print_array(output_2, iw, ih); + PrintArray(output_2, iw, ih); } - free(input); - free(output_1); - free(output_2); + free_aligned_buffer_16(input) + free_aligned_buffer_16(output_1) + free_aligned_buffer_16(output_2) } + } EXPECT_EQ(0, err); } @@ -79,23 +76,20 @@ TEST_F(libyuvTest, TransposeUV) { int iw, ih, ow, oh; int err = 0; - for (iw = 16; iw < _rotate_max_w && !err; iw += 2) - for (ih = 8; ih < _rotate_max_h && !err; ++ih) { + for (iw = 16; iw < rotate_max_w_ && !err; iw += 2) { + for (ih = 8; ih < rotate_max_h_ && !err; ++ih) { int i; - uint8 *input; - uint8 *output_a1, *output_b1; - uint8 *output_a2, *output_b2; ow = ih; oh = iw >> 1; - input = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_a1 = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_b1 = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_a2 = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_b2 = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); + align_buffer_16(input, iw * ih) + align_buffer_16(output_a1, ow * oh) + align_buffer_16(output_b1, ow * oh) + align_buffer_16(output_a2, iw * ih) + align_buffer_16(output_b2, iw * ih) - for (i = 0; i < (iw * ih); i += 2) { + for (i = 0; i < iw * ih; i += 2) { input[i] = i >> 1; input[i + 1] = -(i >> 1); } @@ -105,32 +99,35 @@ TEST_F(libyuvTest, TransposeUV) { TransposePlane(output_a1, ow, output_a2, oh, ow, oh); TransposePlane(output_b1, ow, output_b2, oh, ow, oh); - for (i = 0; i < (iw * ih); i += 2) { - if (input[i] != output_a2[i >> 1]) + for (i = 0; i < iw * ih; i += 2) { + if (input[i] != output_a2[i >> 1]) { err++; - if (input[i + 1] != output_b2[i >> 1]) + } + if (input[i + 1] != output_b2[i >> 1]) { err++; + } } if (err) { printf("input %dx%d \n", iw, ih); - print_array(input, iw, ih); + PrintArray(input, iw, ih); printf("transpose 1\n"); - print_array(output_a1, ow, oh); - print_array(output_b1, ow, oh); + PrintArray(output_a1, ow, oh); + PrintArray(output_b1, ow, oh); printf("transpose 2\n"); - print_array(output_a2, oh, ow); - print_array(output_b2, oh, ow); + PrintArray(output_a2, oh, ow); + PrintArray(output_b2, oh, ow); } - free(input); - free(output_a1); - free(output_b1); - free(output_a2); - free(output_b2); + free_aligned_buffer_16(input) + free_aligned_buffer_16(output_a1) + free_aligned_buffer_16(output_b1) + free_aligned_buffer_16(output_a2) + free_aligned_buffer_16(output_b2) } + } EXPECT_EQ(0, err); } @@ -139,60 +136,58 @@ TEST_F(libyuvTest, RotatePlane90) { int iw, ih, ow, oh; int err = 0; - for (iw = 8; iw < _rotate_max_w && !err; ++iw) - for (ih = 8; ih < _rotate_max_h && !err; ++ih) { + for (iw = 8; iw < rotate_max_w_ && !err; ++iw) { + for (ih = 8; ih < rotate_max_h_ && !err; ++ih) { int i; - uint8 *input; - uint8 *output_0; - uint8 *output_90; - uint8 *output_180; - uint8 *output_270; ow = ih; oh = iw; - input = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_0 = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_90 = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_180 = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_270 = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); + align_buffer_16(input, iw * ih) + align_buffer_16(output_0, iw * ih) + align_buffer_16(output_90, ow * oh) + align_buffer_16(output_180, iw * ih) + align_buffer_16(output_270, ow * oh) - for (i = 0; i < (iw * ih); ++i) + for (i = 0; i < iw * ih; ++i) { input[i] = i; + } RotatePlane90(input, iw, output_90, ow, iw, ih); RotatePlane90(output_90, ow, output_180, oh, ow, oh); RotatePlane90(output_180, oh, output_270, ow, oh, ow); RotatePlane90(output_270, ow, output_0, iw, ow, oh); - for (i = 0; i < (iw * ih); ++i) { - if (input[i] != output_0[i]) + for (i = 0; i < iw * ih; ++i) { + if (input[i] != output_0[i]) { err++; + } } if (err) { printf("input %dx%d \n", iw, ih); - print_array(input, iw, ih); + PrintArray(input, iw, ih); printf("output 90\n"); - print_array(output_90, ow, oh); + PrintArray(output_90, ow, oh); printf("output 180\n"); - print_array(output_180, iw, ih); + PrintArray(output_180, iw, ih); printf("output 270\n"); - print_array(output_270, ow, oh); + PrintArray(output_270, ow, oh); printf("output 0\n"); - print_array(output_0, iw, ih); + PrintArray(output_0, iw, ih); } - free(input); - free(output_0); - free(output_90); - free(output_180); - free(output_270); + free_aligned_buffer_16(input) + free_aligned_buffer_16(output_0) + free_aligned_buffer_16(output_90) + free_aligned_buffer_16(output_180) + free_aligned_buffer_16(output_270) } + } EXPECT_EQ(0, err); } @@ -201,29 +196,22 @@ TEST_F(libyuvTest, RotateUV90) { int iw, ih, ow, oh; int err = 0; - for (iw = 16; iw < _rotate_max_w && !err; iw += 2) - for (ih = 8; ih < _rotate_max_h && !err; ++ih) { + for (iw = 16; iw < rotate_max_w_ && !err; iw += 2) { + for (ih = 8; ih < rotate_max_h_ && !err; ++ih) { int i; - uint8 *input; - uint8 *output_0_u; - uint8 *output_0_v; - uint8 *output_90_u; - uint8 *output_90_v; - uint8 *output_180_u; - uint8 *output_180_v; ow = ih; oh = iw >> 1; - input = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_0_u = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_0_v = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_90_u = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_90_v = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_180_u = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_180_v = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); + align_buffer_16(input, iw * ih) + align_buffer_16(output_0_u, ow * oh) + align_buffer_16(output_0_v, ow * oh) + align_buffer_16(output_90_u, ow * oh) + align_buffer_16(output_90_v, ow * oh) + align_buffer_16(output_180_u, ow * oh) + align_buffer_16(output_180_v, ow * oh) - for (i = 0; i < (iw * ih); i += 2) { + for (i = 0; i < iw * ih; i += 2) { input[i] = i >> 1; input[i + 1] = -(i >> 1); } @@ -237,43 +225,46 @@ TEST_F(libyuvTest, RotateUV90) { RotatePlane180(output_180_v, ow, output_0_v, ow, ow, oh); for (i = 0; i < (ow * oh); ++i) { - if (output_0_u[i] != (uint8)i) + if (output_0_u[i] != (uint8)i) { err++; - if (output_0_v[i] != (uint8)(-i)) + } + if (output_0_v[i] != (uint8)(-i)) { err++; + } } if (err) { printf("input %dx%d \n", iw, ih); - print_array(input, iw, ih); + PrintArray(input, iw, ih); printf("output 90_u\n"); - print_array(output_90_u, ow, oh); + PrintArray(output_90_u, ow, oh); printf("output 90_v\n"); - print_array(output_90_v, ow, oh); + PrintArray(output_90_v, ow, oh); printf("output 180_u\n"); - print_array(output_180_u, oh, ow); + PrintArray(output_180_u, oh, ow); printf("output 180_v\n"); - print_array(output_180_v, oh, ow); + PrintArray(output_180_v, oh, ow); printf("output 0_u\n"); - print_array(output_0_u, oh, ow); + PrintArray(output_0_u, oh, ow); printf("output 0_v\n"); - print_array(output_0_v, oh, ow); + PrintArray(output_0_v, oh, ow); } - free(input); - free(output_0_u); - free(output_0_v); - free(output_90_u); - free(output_90_v); - free(output_180_u); - free(output_180_v); + free_aligned_buffer_16(input) + free_aligned_buffer_16(output_0_u) + free_aligned_buffer_16(output_0_v) + free_aligned_buffer_16(output_90_u) + free_aligned_buffer_16(output_90_v) + free_aligned_buffer_16(output_180_u) + free_aligned_buffer_16(output_180_v) } + } EXPECT_EQ(0, err); } @@ -282,29 +273,22 @@ TEST_F(libyuvTest, RotateUV180) { int iw, ih, ow, oh; int err = 0; - for (iw = 16; iw < _rotate_max_w && !err; iw += 2) - for (ih = 8; ih < _rotate_max_h && !err; ++ih) { + for (iw = 16; iw < rotate_max_w_ && !err; iw += 2) { + for (ih = 8; ih < rotate_max_h_ && !err; ++ih) { int i; - uint8 *input; - uint8 *output_0_u; - uint8 *output_0_v; - uint8 *output_90_u; - uint8 *output_90_v; - uint8 *output_180_u; - uint8 *output_180_v; ow = iw >> 1; oh = ih; - input = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_0_u = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_0_v = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_90_u = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_90_v = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_180_u = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_180_v = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); + align_buffer_16(input, iw * ih) + align_buffer_16(output_0_u, ow * oh) + align_buffer_16(output_0_v, ow * oh) + align_buffer_16(output_90_u, ow * oh) + align_buffer_16(output_90_v, ow * oh) + align_buffer_16(output_180_u, ow * oh) + align_buffer_16(output_180_v, ow * oh) - for (i = 0; i < (iw * ih); i += 2) { + for (i = 0; i < iw * ih; i += 2) { input[i] = i >> 1; input[i + 1] = -(i >> 1); } @@ -318,43 +302,46 @@ TEST_F(libyuvTest, RotateUV180) { RotatePlane90(output_90_v, oh, output_0_v, ow, oh, ow); for (i = 0; i < (ow * oh); ++i) { - if (output_0_u[i] != (uint8)i) + if (output_0_u[i] != (uint8)i) { err++; - if (output_0_v[i] != (uint8)(-i)) + } + if (output_0_v[i] != (uint8)(-i)) { err++; + } } if (err) { printf("input %dx%d \n", iw, ih); - print_array(input, iw, ih); + PrintArray(input, iw, ih); printf("output 180_u\n"); - print_array(output_180_u, oh, ow); + PrintArray(output_180_u, oh, ow); printf("output 180_v\n"); - print_array(output_180_v, oh, ow); + PrintArray(output_180_v, oh, ow); printf("output 90_u\n"); - print_array(output_90_u, oh, ow); + PrintArray(output_90_u, oh, ow); printf("output 90_v\n"); - print_array(output_90_v, oh, ow); + PrintArray(output_90_v, oh, ow); printf("output 0_u\n"); - print_array(output_0_u, ow, oh); + PrintArray(output_0_u, ow, oh); printf("output 0_v\n"); - print_array(output_0_v, ow, oh); + PrintArray(output_0_v, ow, oh); } - free(input); - free(output_0_u); - free(output_0_v); - free(output_90_u); - free(output_90_v); - free(output_180_u); - free(output_180_v); + free_aligned_buffer_16(input) + free_aligned_buffer_16(output_0_u) + free_aligned_buffer_16(output_0_v) + free_aligned_buffer_16(output_90_u) + free_aligned_buffer_16(output_90_v) + free_aligned_buffer_16(output_180_u) + free_aligned_buffer_16(output_180_v) } + } EXPECT_EQ(0, err); } @@ -363,29 +350,22 @@ TEST_F(libyuvTest, RotateUV270) { int iw, ih, ow, oh; int err = 0; - for (iw = 16; iw < _rotate_max_w && !err; iw += 2) - for (ih = 8; ih < _rotate_max_h && !err; ++ih) { + for (iw = 16; iw < rotate_max_w_ && !err; iw += 2) { + for (ih = 8; ih < rotate_max_h_ && !err; ++ih) { int i; - uint8 *input; - uint8 *output_0_u; - uint8 *output_0_v; - uint8 *output_270_u; - uint8 *output_270_v; - uint8 *output_180_u; - uint8 *output_180_v; ow = ih; oh = iw >> 1; - input = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_0_u = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_0_v = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_270_u = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_270_v = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_180_u = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_180_v = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); + align_buffer_16(input, iw * ih) + align_buffer_16(output_0_u, ow * oh) + align_buffer_16(output_0_v, ow * oh) + align_buffer_16(output_270_u, ow * oh) + align_buffer_16(output_270_v, ow * oh) + align_buffer_16(output_180_u, ow * oh) + align_buffer_16(output_180_v, ow * oh) - for (i = 0; i < (iw * ih); i += 2) { + for (i = 0; i < iw * ih; i += 2) { input[i] = i >> 1; input[i + 1] = -(i >> 1); } @@ -400,43 +380,46 @@ TEST_F(libyuvTest, RotateUV270) { RotatePlane180(output_180_v, ow, output_0_v, ow, ow, oh); for (i = 0; i < (ow * oh); ++i) { - if (output_0_u[i] != (uint8)i) + if (output_0_u[i] != (uint8)i) { err++; - if (output_0_v[i] != (uint8)(-i)) + } + if (output_0_v[i] != (uint8)(-i)) { err++; + } } if (err) { printf("input %dx%d \n", iw, ih); - print_array(input, iw, ih); + PrintArray(input, iw, ih); printf("output 270_u\n"); - print_array(output_270_u, ow, oh); + PrintArray(output_270_u, ow, oh); printf("output 270_v\n"); - print_array(output_270_v, ow, oh); + PrintArray(output_270_v, ow, oh); printf("output 180_u\n"); - print_array(output_180_u, oh, ow); + PrintArray(output_180_u, oh, ow); printf("output 180_v\n"); - print_array(output_180_v, oh, ow); + PrintArray(output_180_v, oh, ow); printf("output 0_u\n"); - print_array(output_0_u, oh, ow); + PrintArray(output_0_u, oh, ow); printf("output 0_v\n"); - print_array(output_0_v, oh, ow); + PrintArray(output_0_v, oh, ow); } - free(input); - free(output_0_u); - free(output_0_v); - free(output_270_u); - free(output_270_v); - free(output_180_u); - free(output_180_v); + free_aligned_buffer_16(input) + free_aligned_buffer_16(output_0_u) + free_aligned_buffer_16(output_0_v) + free_aligned_buffer_16(output_270_u) + free_aligned_buffer_16(output_270_v) + free_aligned_buffer_16(output_180_u) + free_aligned_buffer_16(output_180_v) } + } EXPECT_EQ(0, err); } @@ -445,45 +428,44 @@ TEST_F(libyuvTest, RotatePlane180) { int iw, ih, ow, oh; int err = 0; - for (iw = 8; iw < _rotate_max_w && !err; ++iw) - for (ih = 8; ih < _rotate_max_h && !err; ++ih) { + for (iw = 8; iw < rotate_max_w_ && !err; ++iw) + for (ih = 8; ih < rotate_max_h_ && !err; ++ih) { int i; - uint8 *input; - uint8 *output_0; - uint8 *output_180; ow = iw; oh = ih; - input = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_0 = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_180 = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); + align_buffer_16(input, iw * ih) + align_buffer_16(output_0, iw * ih) + align_buffer_16(output_180, iw * ih) - for (i = 0; i < (iw * ih); ++i) + for (i = 0; i < iw * ih; ++i) { input[i] = i; + } RotatePlane180(input, iw, output_180, ow, iw, ih); RotatePlane180(output_180, ow, output_0, iw, ow, oh); - for (i = 0; i < (iw * ih); ++i) { - if (input[i] != output_0[i]) + for (i = 0; i < iw * ih; ++i) { + if (input[i] != output_0[i]) { err++; + } } if (err) { printf("input %dx%d \n", iw, ih); - print_array(input, iw, ih); + PrintArray(input, iw, ih); printf("output 180\n"); - print_array(output_180, iw, ih); + PrintArray(output_180, iw, ih); printf("output 0\n"); - print_array(output_0, iw, ih); + PrintArray(output_0, iw, ih); } - free(input); - free(output_0); - free(output_180); + free_aligned_buffer_16(input) + free_aligned_buffer_16(output_0) + free_aligned_buffer_16(output_180) } EXPECT_EQ(0, err); @@ -493,25 +475,20 @@ TEST_F(libyuvTest, RotatePlane270) { int iw, ih, ow, oh; int err = 0; - for (iw = 8; iw < _rotate_max_w && !err; ++iw) - for (ih = 8; ih < _rotate_max_h && !err; ++ih) { + for (iw = 8; iw < rotate_max_w_ && !err; ++iw) { + for (ih = 8; ih < rotate_max_h_ && !err; ++ih) { int i; - uint8 *input; - uint8 *output_0; - uint8 *output_90; - uint8 *output_180; - uint8 *output_270; ow = ih; oh = iw; - input = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_0 = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_90 = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); - output_180 = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_270 = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); + align_buffer_16(input, iw * ih) + align_buffer_16(output_0, iw * ih) + align_buffer_16(output_90, ow * oh) + align_buffer_16(output_180, iw * ih) + align_buffer_16(output_270, ow * oh) - for (i = 0; i < (iw * ih); ++i) + for (i = 0; i < iw * ih; ++i) input[i] = i; RotatePlane270(input, iw, output_270, ow, iw, ih); @@ -519,34 +496,36 @@ TEST_F(libyuvTest, RotatePlane270) { RotatePlane270(output_180, oh, output_90, ow, oh, ow); RotatePlane270(output_90, ow, output_0, iw, ow, oh); - for (i = 0; i < (iw * ih); ++i) { - if (input[i] != output_0[i]) + for (i = 0; i < iw * ih; ++i) { + if (input[i] != output_0[i]) { err++; + } } if (err) { printf("input %dx%d \n", iw, ih); - print_array(input, iw, ih); + PrintArray(input, iw, ih); printf("output 270\n"); - print_array(output_270, ow, oh); + PrintArray(output_270, ow, oh); printf("output 180\n"); - print_array(output_180, iw, ih); + PrintArray(output_180, iw, ih); printf("output 90\n"); - print_array(output_90, ow, oh); + PrintArray(output_90, ow, oh); printf("output 0\n"); - print_array(output_0, iw, ih); + PrintArray(output_0, iw, ih); } - free(input); - free(output_0); - free(output_90); - free(output_180); - free(output_270); + free_aligned_buffer_16(input) + free_aligned_buffer_16(output_0) + free_aligned_buffer_16(output_90) + free_aligned_buffer_16(output_180) + free_aligned_buffer_16(output_270) } + } EXPECT_EQ(0, err); } @@ -555,44 +534,44 @@ TEST_F(libyuvTest, RotatePlane90and270) { int iw, ih, ow, oh; int err = 0; - for (iw = 16; iw < _rotate_max_w && !err; iw += 4) - for (ih = 16; ih < _rotate_max_h && !err; ih += 4) { + for (iw = 16; iw < rotate_max_w_ && !err; iw += 4) + for (ih = 16; ih < rotate_max_h_ && !err; ih += 4) { int i; - uint8 *input; - uint8 *output_0; - uint8 *output_90; + ow = ih; oh = iw; - input = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_0 = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_90 = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); + align_buffer_16(input, iw * ih) + align_buffer_16(output_0, iw * ih) + align_buffer_16(output_90, ow * oh) - for (i = 0; i < (iw * ih); ++i) + for (i = 0; i < iw * ih; ++i) { input[i] = i; + } RotatePlane90(input, iw, output_90, ow, iw, ih); RotatePlane270(output_90, ow, output_0, iw, ow, oh); - for (i = 0; i < (iw * ih); ++i) { - if (input[i] != output_0[i]) + for (i = 0; i < iw * ih; ++i) { + if (input[i] != output_0[i]) { err++; + } } if (err) { printf("intput %dx%d\n", iw, ih); - print_array(input, iw, ih); + PrintArray(input, iw, ih); printf("output \n"); - print_array(output_90, ow, oh); + PrintArray(output_90, ow, oh); printf("output \n"); - print_array(output_0, iw, ih); + PrintArray(output_0, iw, ih); } - free(input); - free(output_0); - free(output_90); + free_aligned_buffer_16(input) + free_aligned_buffer_16(output_0) + free_aligned_buffer_16(output_90) } EXPECT_EQ(0, err); @@ -602,21 +581,20 @@ TEST_F(libyuvTest, RotatePlane90Pitch) { int iw, ih; int err = 0; - for (iw = 16; iw < _rotate_max_w && !err; iw += 4) - for (ih = 16; ih < _rotate_max_h && !err; ih += 4) { + for (iw = 16; iw < rotate_max_w_ && !err; iw += 4) + for (ih = 16; ih < rotate_max_h_ && !err; ih += 4) { int i; - uint8 *input; - uint8 *output_0; - uint8 *output_90; + int ow = ih; int oh = iw; - input = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_0 = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_90 = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); + align_buffer_16(input, iw * ih) + align_buffer_16(output_0, iw * ih) + align_buffer_16(output_90, ow * oh) - for (i = 0; i < (iw * ih); ++i) + for (i = 0; i < iw * ih; ++i) { input[i] = i; + } RotatePlane90(input, iw, output_90 + (ow >> 1), ow, @@ -633,25 +611,26 @@ TEST_F(libyuvTest, RotatePlane90Pitch) { RotatePlane270(output_90, ih, output_0, iw, ow, oh); - for (i = 0; i < (iw * ih); ++i) { - if (input[i] != output_0[i]) + for (i = 0; i < iw * ih; ++i) { + if (input[i] != output_0[i]) { err++; + } } if (err) { printf("intput %dx%d\n", iw, ih); - print_array(input, iw, ih); + PrintArray(input, iw, ih); printf("output \n"); - print_array(output_90, ow, oh); + PrintArray(output_90, ow, oh); printf("output \n"); - print_array(output_0, iw, ih); + PrintArray(output_0, iw, ih); } - free(input); - free(output_0); - free(output_90); + free_aligned_buffer_16(input) + free_aligned_buffer_16(output_0) + free_aligned_buffer_16(output_90) } EXPECT_EQ(0, err); @@ -661,22 +640,20 @@ TEST_F(libyuvTest, RotatePlane270Pitch) { int iw, ih, ow, oh; int err = 0; - for (iw = 16; iw < _rotate_max_w && !err; iw += 4) - for (ih = 16; ih < _rotate_max_h && !err; ih += 4) { + for (iw = 16; iw < rotate_max_w_ && !err; iw += 4) { + for (ih = 16; ih < rotate_max_h_ && !err; ih += 4) { int i; - uint8 *input; - uint8 *output_0; - uint8 *output_270; ow = ih; oh = iw; - input = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_0 = static_cast<uint8*>(calloc(iw * ih, sizeof(uint8))); - output_270 = static_cast<uint8*>(calloc(ow * oh, sizeof(uint8))); + align_buffer_16(input, iw * ih) + align_buffer_16(output_0, iw * ih) + align_buffer_16(output_270, ow * oh) - for (i = 0; i < (iw * ih); ++i) + for (i = 0; i < iw * ih; ++i) { input[i] = i; + } RotatePlane270(input, iw, output_270 + ow * (oh >> 1), ow, @@ -693,36 +670,34 @@ TEST_F(libyuvTest, RotatePlane270Pitch) { RotatePlane90(output_270, ih, output_0, iw, ow, oh); - for (i = 0; i < (iw * ih); ++i) { - if (input[i] != output_0[i]) + for (i = 0; i < iw * ih; ++i) { + if (input[i] != output_0[i]) { err++; + } } if (err) { printf("intput %dx%d\n", iw, ih); - print_array(input, iw, ih); + PrintArray(input, iw, ih); printf("output \n"); - print_array(output_270, ow, oh); + PrintArray(output_270, ow, oh); printf("output \n"); - print_array(output_0, iw, ih); + PrintArray(output_0, iw, ih); } - free(input); - free(output_0); - free(output_270); + free_aligned_buffer_16(input) + free_aligned_buffer_16(output_0) + free_aligned_buffer_16(output_270) } + } EXPECT_EQ(0, err); } TEST_F(libyuvTest, I420Rotate90) { int err = 0; - uint8 *orig_y, *orig_u, *orig_v; - uint8 *ro0_y, *ro0_u, *ro0_v; - uint8 *ro90_y, *ro90_u, *ro90_v; - uint8 *ro270_y, *ro270_u, *ro270_v; int yw = 1024; int yh = 768; @@ -732,50 +707,59 @@ TEST_F(libyuvTest, I420Rotate90) { int i, j; - int y_plane_size = (yw + (2 * b)) * (yh + (2 * b)); - int uv_plane_size = (uvw + (2 * b)) * (uvh + (2 * b)); + int y_plane_size = (yw + b * 2) * (yh + b * 2); + int uv_plane_size = (uvw + b * 2) * (uvh + b * 2); srandom(time(NULL)); - orig_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - orig_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - orig_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - - ro0_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - ro0_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - ro0_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - - ro90_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - ro90_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - ro90_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - - ro270_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - ro270_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - ro270_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); + align_buffer_16(orig_y, y_plane_size) + align_buffer_16(orig_u, uv_plane_size) + align_buffer_16(orig_v, uv_plane_size) + align_buffer_16(ro0_y, y_plane_size) + align_buffer_16(ro0_u, uv_plane_size) + align_buffer_16(ro0_v, uv_plane_size) + align_buffer_16(ro90_y, y_plane_size) + align_buffer_16(ro90_u, uv_plane_size) + align_buffer_16(ro90_v, uv_plane_size) + align_buffer_16(ro270_y, y_plane_size) + align_buffer_16(ro270_u, uv_plane_size) + align_buffer_16(ro270_v, uv_plane_size) + memset(orig_y, 0, y_plane_size); + memset(orig_u, 0, uv_plane_size); + memset(orig_v, 0, uv_plane_size); + memset(ro0_y, 0, y_plane_size); + memset(ro0_u, 0, uv_plane_size); + memset(ro0_v, 0, uv_plane_size); + memset(ro90_y, 0, y_plane_size); + memset(ro90_u, 0, uv_plane_size); + memset(ro90_v, 0, uv_plane_size); + memset(ro270_y, 0, y_plane_size); + memset(ro270_u, 0, uv_plane_size); + memset(ro270_v, 0, uv_plane_size); // fill image buffers with random data for (i = b; i < (yh + b); ++i) { for (j = b; j < (yw + b); ++j) { - orig_y[i * (yw + (2 * b)) + j] = random() & 0xff; + orig_y[i * (yw + b * 2) + j] = random() & 0xff; } } for (i = b; i < (uvh + b); ++i) { for (j = b; j < (uvw + b); ++j) { - orig_u[i * (uvw + (2 * b)) + j] = random() & 0xff; - orig_v[i * (uvw + (2 * b)) + j] = random() & 0xff; + orig_u[i * (uvw + b * 2) + j] = random() & 0xff; + orig_v[i * (uvw + b * 2) + j] = random() & 0xff; } } - int y_off_0 = b * (yw + (2 * b)) + b; - int uv_off_0 = b * (uvw + (2 * b)) + b; - int y_off_90 = b * (yh + (2 * b)) + b; - int uv_off_90 = b * (uvh + (2 * b)) + b; + int y_off_0 = b * (yw + b * 2) + b; + int uv_off_0 = b * (uvw + b * 2) + b; + int y_off_90 = b * (yh + b * 2) + b; + int uv_off_90 = b * (uvh + b * 2) + b; - int y_st_0 = yw + (2 * b); - int uv_st_0 = uvw + (2 * b); - int y_st_90 = yh + (2 * b); - int uv_st_90 = uvh + (2 * b); + int y_st_0 = yw + b * 2; + int uv_st_0 = uvw + b * 2; + int y_st_90 = yh + b * 2; + int uv_st_90 = uvh + b * 2; I420Rotate(orig_y+y_off_0, y_st_0, orig_u+uv_off_0, uv_st_0, @@ -805,39 +789,38 @@ TEST_F(libyuvTest, I420Rotate90) { kRotateClockwise); for (i = 0; i < y_plane_size; ++i) { - if (orig_y[i] != ro0_y[i]) + if (orig_y[i] != ro0_y[i]) { ++err; + } } for (i = 0; i < uv_plane_size; ++i) { - if (orig_u[i] != ro0_u[i]) + if (orig_u[i] != ro0_u[i]) { ++err; - if (orig_v[i] != ro0_v[i]) + } + if (orig_v[i] != ro0_v[i]) { ++err; + } } - free(orig_y); - free(orig_u); - free(orig_v); - free(ro0_y); - free(ro0_u); - free(ro0_v); - free(ro90_y); - free(ro90_u); - free(ro90_v); - free(ro270_y); - free(ro270_u); - free(ro270_v); + free_aligned_buffer_16(orig_y) + free_aligned_buffer_16(orig_u) + free_aligned_buffer_16(orig_v) + free_aligned_buffer_16(ro0_y) + free_aligned_buffer_16(ro0_u) + free_aligned_buffer_16(ro0_v) + free_aligned_buffer_16(ro90_y) + free_aligned_buffer_16(ro90_u) + free_aligned_buffer_16(ro90_v) + free_aligned_buffer_16(ro270_y) + free_aligned_buffer_16(ro270_u) + free_aligned_buffer_16(ro270_v) EXPECT_EQ(0, err); } TEST_F(libyuvTest, I420Rotate270) { int err = 0; - uint8 *orig_y, *orig_u, *orig_v; - uint8 *ro0_y, *ro0_u, *ro0_v; - uint8 *ro90_y, *ro90_u, *ro90_v; - uint8 *ro270_y, *ro270_u, *ro270_v; int yw = 1024; int yh = 768; @@ -847,50 +830,59 @@ TEST_F(libyuvTest, I420Rotate270) { int i, j; - int y_plane_size = (yw + (2 * b)) * (yh + (2 * b)); - int uv_plane_size = (uvw + (2 * b)) * (uvh + (2 * b)); + int y_plane_size = (yw + b * 2) * (yh + b * 2); + int uv_plane_size = (uvw + b * 2) * (uvh + b * 2); srandom(time(NULL)); - orig_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - orig_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - orig_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - - ro0_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - ro0_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - ro0_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - - ro90_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - ro90_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - ro90_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - - ro270_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - ro270_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - ro270_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); + align_buffer_16(orig_y, y_plane_size) + align_buffer_16(orig_u, uv_plane_size) + align_buffer_16(orig_v, uv_plane_size) + align_buffer_16(ro0_y, y_plane_size) + align_buffer_16(ro0_u, uv_plane_size) + align_buffer_16(ro0_v, uv_plane_size) + align_buffer_16(ro90_y, y_plane_size) + align_buffer_16(ro90_u, uv_plane_size) + align_buffer_16(ro90_v, uv_plane_size) + align_buffer_16(ro270_y, y_plane_size) + align_buffer_16(ro270_u, uv_plane_size) + align_buffer_16(ro270_v, uv_plane_size) + memset(orig_y, 0, y_plane_size); + memset(orig_u, 0, uv_plane_size); + memset(orig_v, 0, uv_plane_size); + memset(ro0_y, 0, y_plane_size); + memset(ro0_u, 0, uv_plane_size); + memset(ro0_v, 0, uv_plane_size); + memset(ro90_y, 0, y_plane_size); + memset(ro90_u, 0, uv_plane_size); + memset(ro90_v, 0, uv_plane_size); + memset(ro270_y, 0, y_plane_size); + memset(ro270_u, 0, uv_plane_size); + memset(ro270_v, 0, uv_plane_size); // fill image buffers with random data for (i = b; i < (yh + b); ++i) { for (j = b; j < (yw + b); ++j) { - orig_y[i * (yw + (2 * b)) + j] = random() & 0xff; + orig_y[i * (yw + b * 2) + j] = random() & 0xff; } } for (i = b; i < (uvh + b); ++i) { for (j = b; j < (uvw + b); ++j) { - orig_u[i * (uvw + (2 * b)) + j] = random() & 0xff; - orig_v[i * (uvw + (2 * b)) + j] = random() & 0xff; + orig_u[i * (uvw + b * 2) + j] = random() & 0xff; + orig_v[i * (uvw + b * 2) + j] = random() & 0xff; } } - int y_off_0 = b * (yw + (2 * b)) + b; - int uv_off_0 = b * (uvw + (2 * b)) + b; - int y_off_90 = b * (yh + (2 * b)) + b; - int uv_off_90 = b * (uvh + (2 * b)) + b; + int y_off_0 = b * (yw + b * 2) + b; + int uv_off_0 = b * (uvw + b * 2) + b; + int y_off_90 = b * (yh + b * 2) + b; + int uv_off_90 = b * (uvh + b * 2) + b; - int y_st_0 = yw + (2 * b); - int uv_st_0 = uvw + (2 * b); - int y_st_90 = yh + (2 * b); - int uv_st_90 = uvh + (2 * b); + int y_st_0 = yw + b * 2; + int uv_st_0 = uvw + b * 2; + int y_st_90 = yh + b * 2; + int uv_st_90 = uvh + b * 2; I420Rotate(orig_y+y_off_0, y_st_0, orig_u+uv_off_0, uv_st_0, @@ -920,38 +912,38 @@ TEST_F(libyuvTest, I420Rotate270) { kRotateCounterClockwise); for (i = 0; i < y_plane_size; ++i) { - if (orig_y[i] != ro0_y[i]) + if (orig_y[i] != ro0_y[i]) { ++err; + } } for (i = 0; i < uv_plane_size; ++i) { - if (orig_u[i] != ro0_u[i]) + if (orig_u[i] != ro0_u[i]) { ++err; - if (orig_v[i] != ro0_v[i]) + } + if (orig_v[i] != ro0_v[i]) { ++err; + } } - free(orig_y); - free(orig_u); - free(orig_v); - free(ro0_y); - free(ro0_u); - free(ro0_v); - free(ro90_y); - free(ro90_u); - free(ro90_v); - free(ro270_y); - free(ro270_u); - free(ro270_v); + free_aligned_buffer_16(orig_y) + free_aligned_buffer_16(orig_u) + free_aligned_buffer_16(orig_v) + free_aligned_buffer_16(ro0_y) + free_aligned_buffer_16(ro0_u) + free_aligned_buffer_16(ro0_v) + free_aligned_buffer_16(ro90_y) + free_aligned_buffer_16(ro90_u) + free_aligned_buffer_16(ro90_v) + free_aligned_buffer_16(ro270_y) + free_aligned_buffer_16(ro270_u) + free_aligned_buffer_16(ro270_v) EXPECT_EQ(0, err); } TEST_F(libyuvTest, NV12ToI420Rotate90) { int err = 0; - uint8 *orig_y, *orig_uv; - uint8 *ro0_y, *ro0_u, *ro0_v; - uint8 *ro90_y, *ro90_u, *ro90_v; int yw = 1024; int yh = 768; @@ -960,47 +952,53 @@ TEST_F(libyuvTest, NV12ToI420Rotate90) { int uvh = (yh + 1) >> 1; int i, j; - int y_plane_size = (yw + (2 * b)) * (yh + (2 * b)); - int uv_plane_size = (uvw + (2 * b)) * (uvh + (2 * b)); - int o_uv_plane_size = ((2 * uvw) + (2 * b)) * (uvh + (2 * b)); + int y_plane_size = (yw + b * 2) * (yh + b * 2); + int uv_plane_size = (uvw + b * 2) * (uvh + b * 2); + int o_uv_plane_size = (uvw * 2 + b * 2) * (uvh + b * 2); srandom(time(NULL)); - orig_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - orig_uv = static_cast<uint8*>(calloc(o_uv_plane_size, sizeof(uint8))); - - ro0_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - ro0_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - ro0_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - - ro90_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - ro90_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - ro90_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); + align_buffer_16(orig_y, y_plane_size) + align_buffer_16(orig_uv, o_uv_plane_size) + align_buffer_16(ro0_y, y_plane_size) + align_buffer_16(ro0_u, uv_plane_size) + align_buffer_16(ro0_v, uv_plane_size) + align_buffer_16(ro90_y, y_plane_size) + align_buffer_16(ro90_u, uv_plane_size) + align_buffer_16(ro90_v, uv_plane_size) + memset(orig_y, 0, y_plane_size); + memset(orig_uv, 0, uv_plane_size); + memset(ro0_y, 0, y_plane_size); + memset(ro0_u, 0, uv_plane_size); + memset(ro0_v, 0, uv_plane_size); + memset(ro90_y, 0, y_plane_size); + memset(ro90_u, 0, uv_plane_size); + memset(ro90_v, 0, uv_plane_size); // fill image buffers with random data for (i = b; i < (yh + b); ++i) { for (j = b; j < (yw + b); ++j) { - orig_y[i * (yw + (2 * b)) + j] = random() & 0xff; + orig_y[i * (yw + b * 2) + j] = random() & 0xff; } } for (i = b; i < (uvh + b); ++i) { - for (j = b; j < ((2 * uvw) + b); j += 2) { + for (j = b; j < (uvw * 2 + b); j += 2) { uint8 random_number = random() & 0x7f; - orig_uv[i * ((2 * uvw) + (2 * b)) + j] = random_number; - orig_uv[i * ((2 * uvw) + (2 * b)) + j + 1] = -random_number; + orig_uv[i * (uvw * 2 + b * 2) + j] = random_number; + orig_uv[i * (uvw * 2 + b * 2) + j + 1] = -random_number; } } - int y_off_0 = b * (yw + (2 * b)) + b; - int uv_off_0 = b * (uvw + (2 * b)) + b; - int y_off_90 = b * (yh + (2 * b)) + b; - int uv_off_90 = b * (uvh + (2 * b)) + b; + int y_off_0 = b * (yw + b * 2) + b; + int uv_off_0 = b * (uvw + b * 2) + b; + int y_off_90 = b * (yh + b * 2) + b; + int uv_off_90 = b * (uvh + b * 2) + b; - int y_st_0 = yw + (2 * b); - int uv_st_0 = uvw + (2 * b); - int y_st_90 = yh + (2 * b); - int uv_st_90 = uvh + (2 * b); + int y_st_0 = yw + b * 2; + int uv_st_0 = uvw + b * 2; + int y_st_90 = yh + b * 2; + int uv_st_90 = uvh + b * 2; NV12ToI420Rotate(orig_y+y_off_0, y_st_0, orig_uv+y_off_0, y_st_0, @@ -1027,32 +1025,32 @@ TEST_F(libyuvTest, NV12ToI420Rotate90) { int zero_cnt = 0; for (i = 0; i < uv_plane_size; ++i) { - if ((signed char)ro0_u[i] != -(signed char)ro0_v[i]) + if ((signed char)ro0_u[i] != -(signed char)ro0_v[i]) { ++err; - if (ro0_u[i] != 0) + } + if (ro0_u[i] != 0) { ++zero_cnt; + } } - if (!zero_cnt) + if (!zero_cnt) { ++err; + } - free(orig_y); - free(orig_uv); - free(ro0_y); - free(ro0_u); - free(ro0_v); - free(ro90_y); - free(ro90_u); - free(ro90_v); + free_aligned_buffer_16(orig_y) + free_aligned_buffer_16(orig_uv) + free_aligned_buffer_16(ro0_y) + free_aligned_buffer_16(ro0_u) + free_aligned_buffer_16(ro0_v) + free_aligned_buffer_16(ro90_y) + free_aligned_buffer_16(ro90_u) + free_aligned_buffer_16(ro90_v) EXPECT_EQ(0, err); } TEST_F(libyuvTest, NV12ToI420Rotate270) { int err = 0; - uint8 *orig_y, *orig_uv; - uint8 *ro0_y, *ro0_u, *ro0_v; - uint8 *ro270_y, *ro270_u, *ro270_v; int yw = 1024; int yh = 768; @@ -1062,47 +1060,53 @@ TEST_F(libyuvTest, NV12ToI420Rotate270) { int i, j; - int y_plane_size = (yw + (2 * b)) * (yh + (2 * b)); - int uv_plane_size = (uvw + (2 * b)) * (uvh + (2 * b)); - int o_uv_plane_size = ((2 * uvw) + (2 * b)) * (uvh + (2 * b)); + int y_plane_size = (yw + b * 2) * (yh + b * 2); + int uv_plane_size = (uvw + b * 2) * (uvh + b * 2); + int o_uv_plane_size = (uvw * 2 + b * 2) * (uvh + b * 2); srandom(time(NULL)); - orig_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - orig_uv = static_cast<uint8*>(calloc(o_uv_plane_size, sizeof(uint8))); - - ro0_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - ro0_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - ro0_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - - ro270_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - ro270_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - ro270_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); + align_buffer_16(orig_y, y_plane_size) + align_buffer_16(orig_uv, o_uv_plane_size) + align_buffer_16(ro0_y, y_plane_size) + align_buffer_16(ro0_u, uv_plane_size) + align_buffer_16(ro0_v, uv_plane_size) + align_buffer_16(ro270_y, y_plane_size) + align_buffer_16(ro270_u, uv_plane_size) + align_buffer_16(ro270_v, uv_plane_size) + memset(orig_y, 0, y_plane_size); + memset(orig_uv, 0, o_uv_plane_size); + memset(ro0_y, 0, y_plane_size); + memset(ro0_u, 0, uv_plane_size); + memset(ro0_v, 0, uv_plane_size); + memset(ro270_y, 0, y_plane_size); + memset(ro270_u, 0, uv_plane_size); + memset(ro270_v, 0, uv_plane_size); // fill image buffers with random data for (i = b; i < (yh + b); ++i) { for (j = b; j < (yw + b); ++j) { - orig_y[i * (yw + (2 * b)) + j] = random() & 0xff; + orig_y[i * (yw + b * 2) + j] = random() & 0xff; } } for (i = b; i < (uvh + b); ++i) { - for (j = b; j < ((2 * uvw) + b); j += 2) { + for (j = b; j < (uvw * 2 + b); j += 2) { uint8 random_number = random() & 0x7f; - orig_uv[i * ((2 * uvw) + (2 * b)) + j] = random_number; - orig_uv[i * ((2 * uvw) + (2 * b)) + j + 1] = -random_number; + orig_uv[i * (uvw * 2 + b * 2) + j] = random_number; + orig_uv[i * (uvw * 2 + b * 2) + j + 1] = -random_number; } } - int y_off_0 = b * (yw + (2 * b)) + b; - int uv_off_0 = b * (uvw + (2 * b)) + b; - int y_off_270 = b * (yh + (2 * b)) + b; - int uv_off_270 = b * (uvh + (2 * b)) + b; + int y_off_0 = b * (yw + b * 2) + b; + int uv_off_0 = b * (uvw + b * 2) + b; + int y_off_270 = b * (yh + b * 2) + b; + int uv_off_270 = b * (uvh + b * 2) + b; - int y_st_0 = yw + (2 * b); - int uv_st_0 = uvw + (2 * b); - int y_st_270 = yh + (2 * b); - int uv_st_270 = uvh + (2 * b); + int y_st_0 = yw + b * 2; + int uv_st_0 = uvw + b * 2; + int y_st_270 = yh + b * 2; + int uv_st_270 = uvh + b * 2; NV12ToI420Rotate(orig_y+y_off_0, y_st_0, orig_uv+y_off_0, y_st_0, @@ -1129,32 +1133,32 @@ TEST_F(libyuvTest, NV12ToI420Rotate270) { int zero_cnt = 0; for (i = 0; i < uv_plane_size; ++i) { - if ((signed char)ro0_u[i] != -(signed char)ro0_v[i]) + if ((signed char)ro0_u[i] != -(signed char)ro0_v[i]) { ++err; - if (ro0_u[i] != 0) + } + if (ro0_u[i] != 0) { ++zero_cnt; + } } - if (!zero_cnt) + if (!zero_cnt) { ++err; + } - free(orig_y); - free(orig_uv); - free(ro0_y); - free(ro0_u); - free(ro0_v); - free(ro270_y); - free(ro270_u); - free(ro270_v); + free_aligned_buffer_16(orig_y) + free_aligned_buffer_16(orig_uv) + free_aligned_buffer_16(ro0_y) + free_aligned_buffer_16(ro0_u) + free_aligned_buffer_16(ro0_v) + free_aligned_buffer_16(ro270_y) + free_aligned_buffer_16(ro270_u) + free_aligned_buffer_16(ro270_v) EXPECT_EQ(0, err); } TEST_F(libyuvTest, NV12ToI420Rotate180) { int err = 0; - uint8 *orig_y, *orig_uv; - uint8 *ro0_y, *ro0_u, *ro0_v; - uint8 *ro180_y, *ro180_u, *ro180_v; int yw = 1024; int yh = 768; @@ -1164,43 +1168,49 @@ TEST_F(libyuvTest, NV12ToI420Rotate180) { int i, j; - int y_plane_size = (yw + (2 * b)) * (yh + (2 * b)); - int uv_plane_size = (uvw + (2 * b)) * (uvh + (2 * b)); - int o_uv_plane_size = ((2 * uvw) + (2 * b)) * (uvh + (2 * b)); + int y_plane_size = (yw + b * 2) * (yh + b * 2); + int uv_plane_size = (uvw + b * 2) * (uvh + b * 2); + int o_uv_plane_size = (uvw * 2 + b * 2) * (uvh + b * 2); srandom(time(NULL)); - orig_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - orig_uv = static_cast<uint8*>(calloc(o_uv_plane_size, sizeof(uint8))); - - ro0_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - ro0_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - ro0_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - - ro180_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - ro180_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - ro180_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); + align_buffer_16(orig_y, y_plane_size) + align_buffer_16(orig_uv, o_uv_plane_size) + align_buffer_16(ro0_y, y_plane_size) + align_buffer_16(ro0_u, uv_plane_size) + align_buffer_16(ro0_v, uv_plane_size) + align_buffer_16(ro180_y, y_plane_size) + align_buffer_16(ro180_u, uv_plane_size) + align_buffer_16(ro180_v, uv_plane_size) + memset(orig_y, 0, y_plane_size); + memset(orig_uv, 0, o_uv_plane_size); + memset(ro0_y, 0, y_plane_size); + memset(ro0_u, 0, uv_plane_size); + memset(ro0_v, 0, uv_plane_size); + memset(ro180_y, 0, y_plane_size); + memset(ro180_u, 0, uv_plane_size); + memset(ro180_v, 0, uv_plane_size); // fill image buffers with random data for (i = b; i < (yh + b); ++i) { for (j = b; j < (yw + b); ++j) { - orig_y[i * (yw + (2 * b)) + j] = random() & 0xff; + orig_y[i * (yw + b * 2) + j] = random() & 0xff; } } for (i = b; i < (uvh + b); ++i) { - for (j = b; j < ((2 * uvw) + b); j += 2) { + for (j = b; j < (uvw * 2 + b); j += 2) { uint8 random_number = random() & 0x7f; - orig_uv[i * ((2 * uvw) + (2 * b)) + j] = random_number; - orig_uv[i * ((2 * uvw) + (2 * b)) + j + 1] = -random_number; + orig_uv[i * (uvw * 2 + b * 2) + j] = random_number; + orig_uv[i * (uvw * 2 + b * 2) + j + 1] = -random_number; } } - int y_off = b * (yw + (2 * b)) + b; - int uv_off = b * (uvw + (2 * b)) + b; + int y_off = b * (yw + b * 2) + b; + int uv_off = b * (uvw + b * 2) + b; - int y_st = yw + (2 * b); - int uv_st = uvw + (2 * b); + int y_st = yw + b * 2; + int uv_st = uvw + b * 2; NV12ToI420Rotate(orig_y+y_off, y_st, orig_uv+y_off, y_st, @@ -1220,40 +1230,40 @@ TEST_F(libyuvTest, NV12ToI420Rotate180) { kRotate180); for (i = 0; i < y_plane_size; ++i) { - if (orig_y[i] != ro0_y[i]) + if (orig_y[i] != ro0_y[i]) { ++err; + } } int zero_cnt = 0; for (i = 0; i < uv_plane_size; ++i) { - if ((signed char)ro0_u[i] != -(signed char)ro0_v[i]) + if ((signed char)ro0_u[i] != -(signed char)ro0_v[i]) { ++err; - if (ro0_u[i] != 0) + } + if (ro0_u[i] != 0) { ++zero_cnt; + } } - if (!zero_cnt) + if (!zero_cnt) { ++err; + } - free(orig_y); - free(orig_uv); - free(ro0_y); - free(ro0_u); - free(ro0_v); - free(ro180_y); - free(ro180_u); - free(ro180_v); + free_aligned_buffer_16(orig_y) + free_aligned_buffer_16(orig_uv) + free_aligned_buffer_16(ro0_y) + free_aligned_buffer_16(ro0_u) + free_aligned_buffer_16(ro0_v) + free_aligned_buffer_16(ro180_y) + free_aligned_buffer_16(ro180_u) + free_aligned_buffer_16(ro180_v) EXPECT_EQ(0, err); } TEST_F(libyuvTest, NV12ToI420RotateNegHeight90) { int y_err = 0, uv_err = 0; - uint8 *orig_y, *orig_uv; - uint8 *roa_y, *roa_u, *roa_v; - uint8 *rob_y, *rob_u, *rob_v; - uint8 *roc_y, *roc_u, *roc_v; int yw = 1024; int yh = 768; @@ -1262,51 +1272,59 @@ TEST_F(libyuvTest, NV12ToI420RotateNegHeight90) { int uvh = (yh + 1) >> 1; int i, j; - int y_plane_size = (yw + (2 * b)) * (yh + (2 * b)); - int uv_plane_size = (uvw + (2 * b)) * (uvh + (2 * b)); - int o_uv_plane_size = ((2 * uvw) + (2 * b)) * (uvh + (2 * b)); + int y_plane_size = (yw + b * 2) * (yh + b * 2); + int uv_plane_size = (uvw + b * 2) * (uvh + b * 2); + int o_uv_plane_size = (uvw * 2 + b * 2) * (uvh + b * 2); srandom(time(NULL)); - orig_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - orig_uv = static_cast<uint8*>(calloc(o_uv_plane_size, sizeof(uint8))); - - roa_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - roa_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - roa_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - - rob_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - rob_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - rob_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - - roc_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - roc_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - roc_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); + align_buffer_16(orig_y, y_plane_size) + align_buffer_16(orig_uv, o_uv_plane_size) + align_buffer_16(roa_y, y_plane_size) + align_buffer_16(roa_u, uv_plane_size) + align_buffer_16(roa_v, uv_plane_size) + align_buffer_16(rob_y, y_plane_size) + align_buffer_16(rob_u, uv_plane_size) + align_buffer_16(rob_v, uv_plane_size) + align_buffer_16(roc_y, y_plane_size) + align_buffer_16(roc_u, uv_plane_size) + align_buffer_16(roc_v, uv_plane_size) + memset(orig_y, 0, y_plane_size); + memset(orig_uv, 0, o_uv_plane_size); + memset(roa_y, 0, y_plane_size); + memset(roa_u, 0, uv_plane_size); + memset(roa_v, 0, uv_plane_size); + memset(rob_y, 0, y_plane_size); + memset(rob_u, 0, uv_plane_size); + memset(rob_v, 0, uv_plane_size); + memset(roc_y, 0, y_plane_size); + memset(roc_u, 0, uv_plane_size); + memset(roc_v, 0, uv_plane_size); // fill image buffers with random data for (i = b; i < (yh + b); ++i) { for (j = b; j < (yw + b); ++j) { - orig_y[i * (yw + (2 * b)) + j] = random() & 0xff; + orig_y[i * (yw + b * 2) + j] = random() & 0xff; } } for (i = b; i < (uvh + b); ++i) { - for (j = b; j < ((2 * uvw) + b); j += 2) { + for (j = b; j < (uvw * 2 + b); j += 2) { uint8 random_number = random() & 0x7f; - orig_uv[i * ((2 * uvw) + (2 * b)) + j] = random_number; - orig_uv[i * ((2 * uvw) + (2 * b)) + j + 1] = -random_number; + orig_uv[i * (uvw * 2 + b * 2) + j] = random_number; + orig_uv[i * (uvw * 2 + b * 2) + j + 1] = -random_number; } } - int y_off_0 = b * (yw + (2 * b)) + b; - int uv_off_0 = b * (uvw + (2 * b)) + b; - int y_off_90 = b * (yh + (2 * b)) + b; - int uv_off_90 = b * (uvh + (2 * b)) + b; + int y_off_0 = b * (yw + b * 2) + b; + int uv_off_0 = b * (uvw + b * 2) + b; + int y_off_90 = b * (yh + b * 2) + b; + int uv_off_90 = b * (uvh + b * 2) + b; - int y_st_0 = yw + (2 * b); - int uv_st_0 = uvw + (2 * b); - int y_st_90 = yh + (2 * b); - int uv_st_90 = uvh + (2 * b); + int y_st_0 = yw + b * 2; + int uv_st_0 = uvw + b * 2; + int y_st_90 = yh + b * 2; + int uv_st_90 = uvh + b * 2; NV12ToI420Rotate(orig_y+y_off_0, y_st_0, orig_uv+y_off_0, y_st_0, @@ -1335,73 +1353,74 @@ TEST_F(libyuvTest, NV12ToI420RotateNegHeight90) { kRotate180); for (i = 0; i < y_plane_size; ++i) { - if (orig_y[i] != roc_y[i]) + if (orig_y[i] != roc_y[i]) { ++y_err; + } } if (y_err) { printf("input %dx%d \n", yw, yh); - print_array(orig_y, y_st_0, yh + (2 * b)); + PrintArray(orig_y, y_st_0, yh + b * 2); printf("rotate a\n"); - print_array(roa_y, y_st_90, y_st_0); + PrintArray(roa_y, y_st_90, y_st_0); printf("rotate b\n"); - print_array(rob_y, y_st_90, y_st_0); + PrintArray(rob_y, y_st_90, y_st_0); printf("rotate c\n"); - print_array(roc_y, y_st_0, y_st_90); + PrintArray(roc_y, y_st_0, y_st_90); } int zero_cnt = 0; for (i = 0; i < uv_plane_size; ++i) { - if ((signed char)roc_u[i] != -(signed char)roc_v[i]) + if ((signed char)roc_u[i] != -(signed char)roc_v[i]) { ++uv_err; - if (rob_u[i] != 0) + } + if (rob_u[i] != 0) { ++zero_cnt; + } } - if (!zero_cnt) + if (!zero_cnt) { ++uv_err; + } if (uv_err) { - printf("input %dx%d \n", (2 * uvw), uvh); - print_array(orig_uv, y_st_0, uvh + (2 * b)); + printf("input %dx%d \n", uvw * 2, uvh); + PrintArray(orig_uv, y_st_0, uvh + b * 2); printf("rotate a\n"); - print_array(roa_u, uv_st_90, uv_st_0); - print_array(roa_v, uv_st_90, uv_st_0); + PrintArray(roa_u, uv_st_90, uv_st_0); + PrintArray(roa_v, uv_st_90, uv_st_0); printf("rotate b\n"); - print_array(rob_u, uv_st_90, uv_st_0); - print_array(rob_v, uv_st_90, uv_st_0); + PrintArray(rob_u, uv_st_90, uv_st_0); + PrintArray(rob_v, uv_st_90, uv_st_0); printf("rotate c\n"); - print_array(roc_u, uv_st_0, uv_st_90); - print_array(roc_v, uv_st_0, uv_st_90); + PrintArray(roc_u, uv_st_0, uv_st_90); + PrintArray(roc_v, uv_st_0, uv_st_90); } - free(orig_y); - free(orig_uv); - free(roa_y); - free(roa_u); - free(roa_v); - free(rob_y); - free(rob_u); - free(rob_v); - free(roc_y); - free(roc_u); - free(roc_v); + free_aligned_buffer_16(orig_y) + free_aligned_buffer_16(orig_uv) + free_aligned_buffer_16(roa_y) + free_aligned_buffer_16(roa_u) + free_aligned_buffer_16(roa_v) + free_aligned_buffer_16(rob_y) + free_aligned_buffer_16(rob_u) + free_aligned_buffer_16(rob_v) + free_aligned_buffer_16(roc_y) + free_aligned_buffer_16(roc_u) + free_aligned_buffer_16(roc_v) EXPECT_EQ(0, y_err + uv_err); } TEST_F(libyuvTest, NV12ToI420RotateNegHeight180) { int y_err = 0, uv_err = 0; - uint8 *orig_y, *orig_uv; - uint8 *roa_y, *roa_u, *roa_v; - uint8 *rob_y, *rob_u, *rob_v; int yw = 1024; int yh = 768; @@ -1410,43 +1429,49 @@ TEST_F(libyuvTest, NV12ToI420RotateNegHeight180) { int uvh = (yh + 1) >> 1; int i, j; - int y_plane_size = (yw + (2 * b)) * (yh + (2 * b)); - int uv_plane_size = (uvw + (2 * b)) * (uvh + (2 * b)); - int o_uv_plane_size = ((2 * uvw) + (2 * b)) * (uvh + (2 * b)); + int y_plane_size = (yw + b * 2) * (yh + b * 2); + int uv_plane_size = (uvw + b * 2) * (uvh + b * 2); + int o_uv_plane_size = (uvw * 2 + b * 2) * (uvh + b * 2); srandom(time(NULL)); - orig_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - orig_uv = static_cast<uint8*>(calloc(o_uv_plane_size, sizeof(uint8))); - - roa_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - roa_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - roa_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - - rob_y = static_cast<uint8*>(calloc(y_plane_size, sizeof(uint8))); - rob_u = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); - rob_v = static_cast<uint8*>(calloc(uv_plane_size, sizeof(uint8))); + align_buffer_16(orig_y, y_plane_size) + align_buffer_16(orig_uv, o_uv_plane_size) + align_buffer_16(roa_y, y_plane_size) + align_buffer_16(roa_u, uv_plane_size) + align_buffer_16(roa_v, uv_plane_size) + align_buffer_16(rob_y, y_plane_size) + align_buffer_16(rob_u, uv_plane_size) + align_buffer_16(rob_v, uv_plane_size) + memset(orig_y, 0, y_plane_size); + memset(orig_uv, 0, o_uv_plane_size); + memset(roa_y, 0, y_plane_size); + memset(roa_u, 0, uv_plane_size); + memset(roa_v, 0, uv_plane_size); + memset(rob_y, 0, y_plane_size); + memset(rob_u, 0, uv_plane_size); + memset(rob_v, 0, uv_plane_size); // fill image buffers with random data for (i = b; i < (yh + b); ++i) { for (j = b; j < (yw + b); ++j) { - orig_y[i * (yw + (2 * b)) + j] = random() & 0xff; + orig_y[i * (yw + b * 2) + j] = random() & 0xff; } } for (i = b; i < (uvh + b); ++i) { - for (j = b; j < ((2 * uvw) + b); j += 2) { + for (j = b; j < (uvw * 2 + b); j += 2) { uint8 random_number = random() & 0x7f; - orig_uv[i * ((2 * uvw) + (2 * b)) + j] = random_number; - orig_uv[i * ((2 * uvw) + (2 * b)) + j + 1] = -random_number; + orig_uv[i * (uvw * 2 + b * 2) + j] = random_number; + orig_uv[i * (uvw * 2 + b * 2) + j + 1] = -random_number; } } - int y_off = b * (yw + (2 * b)) + b; - int uv_off = b * (uvw + (2 * b)) + b; + int y_off = b * (yw + b * 2) + b; + int uv_off = b * (uvw + b * 2) + b; - int y_st = yw + (2 * b); - int uv_st = uvw + (2 * b); + int y_st = yw + b * 2; + int uv_st = uvw + b * 2; NV12ToI420Rotate(orig_y+y_off, y_st, orig_uv+y_off, y_st, @@ -1472,48 +1497,53 @@ TEST_F(libyuvTest, NV12ToI420RotateNegHeight180) { if (y_err) { printf("input %dx%d \n", yw, yh); - print_array(orig_y, y_st, yh + (2 * b)); + PrintArray(orig_y, y_st, yh + b * 2); printf("rotate a\n"); - print_array(roa_y, y_st, yh + (2 * b)); + PrintArray(roa_y, y_st, yh + b * 2); printf("rotate b\n"); - print_array(rob_y, y_st, yh + (2 * b)); + PrintArray(rob_y, y_st, yh + b * 2); } int zero_cnt = 0; for (i = 0; i < uv_plane_size; ++i) { - if ((signed char)rob_u[i] != -(signed char)rob_v[i]) + if ((signed char)rob_u[i] != -(signed char)rob_v[i]) { ++uv_err; - if (rob_u[i] != 0) + } + if (rob_u[i] != 0) { ++zero_cnt; + } } - if (!zero_cnt) + if (!zero_cnt) { ++uv_err; + } if (uv_err) { - printf("input %dx%d \n", (2 * uvw), uvh); - print_array(orig_uv, y_st, uvh + (2 * b)); + printf("input %dx%d \n", uvw * 2, uvh); + PrintArray(orig_uv, y_st, uvh + b * 2); printf("rotate a\n"); - print_array(roa_u, uv_st, uvh + (2 * b)); - print_array(roa_v, uv_st, uvh + (2 * b)); + PrintArray(roa_u, uv_st, uvh + b * 2); + PrintArray(roa_v, uv_st, uvh + b * 2); printf("rotate b\n"); - print_array(rob_u, uv_st, uvh + (2 * b)); - print_array(rob_v, uv_st, uvh + (2 * b)); + PrintArray(rob_u, uv_st, uvh + b * 2); + PrintArray(rob_v, uv_st, uvh + b * 2); } - free(orig_y); - free(orig_uv); - free(roa_y); - free(roa_u); - free(roa_v); - free(rob_y); - free(rob_u); - free(rob_v); + free_aligned_buffer_16(orig_y) + free_aligned_buffer_16(orig_uv) + free_aligned_buffer_16(roa_y) + free_aligned_buffer_16(roa_u) + free_aligned_buffer_16(roa_v) + free_aligned_buffer_16(rob_y) + free_aligned_buffer_16(rob_u) + free_aligned_buffer_16(rob_v) EXPECT_EQ(0, y_err + uv_err); } + +} // namespace libyuv diff --git a/files/unit_test/scale_argb_test.cc b/files/unit_test/scale_argb_test.cc new file mode 100644 index 00000000..fef96764 --- /dev/null +++ b/files/unit_test/scale_argb_test.cc @@ -0,0 +1,255 @@ +/* + * Copyright 2011 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 <stdlib.h> +#include <time.h> + +#include "libyuv/cpu_id.h" +#include "libyuv/scale_argb.h" +#include "../unit_test/unit_test.h" + +namespace libyuv { + +static int ARGBTestFilter(int src_width, int src_height, + int dst_width, int dst_height, + FilterMode f, int benchmark_iterations) { + const int b = 128; + int src_argb_plane_size = (src_width + b * 2) * (src_height + b * 2) * 4; + int src_stride_argb = (b * 2 + src_width) * 4; + + align_buffer_16(src_argb, src_argb_plane_size) + memset(src_argb, 1, src_argb_plane_size); + + int dst_argb_plane_size = (dst_width + b * 2) * (dst_height + b * 2) * 4; + int dst_stride_argb = (b * 2 + dst_width) * 4; + + srandom(time(NULL)); + + int i, j; + for (i = b; i < (src_height + b); ++i) { + for (j = b; j < (src_width + b) * 4; ++j) { + src_argb[(i * src_stride_argb) + j] = (random() & 0xff); + } + } + + align_buffer_16(dst_argb_c, dst_argb_plane_size) + align_buffer_16(dst_argb_opt, dst_argb_plane_size) + memset(dst_argb_c, 2, dst_argb_plane_size); + memset(dst_argb_opt, 3, dst_argb_plane_size); + + // Warm up both versions for consistent benchmarks. + MaskCpuFlags(0); // Disable all CPU optimization. + ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, + src_width, src_height, + dst_argb_c + (dst_stride_argb * b) + b * 4, dst_stride_argb, + dst_width, dst_height, f); + MaskCpuFlags(-1); // Enable all CPU optimization. + ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, + src_width, src_height, + dst_argb_opt + (dst_stride_argb * b) + b * 4, dst_stride_argb, + dst_width, dst_height, f); + + MaskCpuFlags(0); // Disable all CPU optimization. + double c_time = get_time(); + for (i = 0; i < benchmark_iterations; ++i) { + ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, + src_width, src_height, + dst_argb_c + (dst_stride_argb * b) + b * 4, dst_stride_argb, + dst_width, dst_height, f); + } + c_time = (get_time() - c_time) / benchmark_iterations; + + MaskCpuFlags(-1); // Enable all CPU optimization. + double opt_time = get_time(); + for (i = 0; i < benchmark_iterations; ++i) { + ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, + src_width, src_height, + dst_argb_opt + (dst_stride_argb * b) + b * 4, dst_stride_argb, + dst_width, dst_height, f); + } + opt_time = (get_time() - opt_time) / benchmark_iterations; + + // Report performance of C vs OPT + printf("filter %d - %8d us C - %8d us OPT\n", + f, static_cast<int>(c_time*1e6), static_cast<int>(opt_time*1e6)); + + // C version may be a little off from the optimized. Order of + // operations may introduce rounding somewhere. So do a difference + // of the buffers and look to see that the max difference isn't + // over 2. + int max_diff = 0; + for (i = b; i < (dst_height + b); ++i) { + for (j = b * 4; j < (dst_width + b) * 4; ++j) { + int abs_diff = abs(dst_argb_c[(i * dst_stride_argb) + j] - + dst_argb_opt[(i * dst_stride_argb) + j]); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + } + + free_aligned_buffer_16(dst_argb_c) + free_aligned_buffer_16(dst_argb_opt) + free_aligned_buffer_16(src_argb) + return max_diff; +} + +TEST_F(libyuvTest, ARGBScaleDownBy2) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = src_width / 2; + const int dst_height = src_height / 2; + + for (int f = 0; f < 2; ++f) { + int max_diff = ARGBTestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ARGBScaleDownBy4) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = src_width / 4; + const int dst_height = src_height / 4; + + for (int f = 0; f < 2; ++f) { + int max_diff = ARGBTestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ARGBScaleDownBy5) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = src_width / 5; + const int dst_height = src_height / 5; + + for (int f = 0; f < 2; ++f) { + int max_diff = ARGBTestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ARGBScaleDownBy8) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = src_width / 8; + const int dst_height = src_height / 8; + + for (int f = 0; f < 2; ++f) { + int max_diff = ARGBTestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ARGBScaleDownBy16) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = src_width / 16; + const int dst_height = src_height / 16; + + for (int f = 0; f < 2; ++f) { + int max_diff = ARGBTestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ARGBScaleDownBy34) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = src_width * 3 / 4; + const int dst_height = src_height * 3 / 4; + + for (int f = 0; f < 2; ++f) { + int max_diff = ARGBTestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ARGBScaleDownBy38) { + int src_width = 1280; + int src_height = 720; + int dst_width = src_width * 3 / 8; + int dst_height = src_height * 3 / 8; + + for (int f = 0; f < 2; ++f) { + int max_diff = ARGBTestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ARGBScaleTo1366) { + int src_width = 1280; + int src_height = 720; + int dst_width = 1366; + int dst_height = 768; + + for (int f = 0; f < 2; ++f) { + int max_diff = ARGBTestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ARGBScaleTo4074) { + int src_width = 2880 * 2; + int src_height = 1800; + int dst_width = 4074; + int dst_height = 1272; + + for (int f = 0; f < 2; ++f) { + int max_diff = ARGBTestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + + +TEST_F(libyuvTest, ARGBScaleTo853) { + int src_width = 1280; + int src_height = 720; + int dst_width = 853; + int dst_height = 480; + + for (int f = 0; f < 2; ++f) { + int max_diff = ARGBTestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +} // namespace libyuv diff --git a/files/unit_test/scale_test.cc b/files/unit_test/scale_test.cc index e147d78b..55b4148d 100644 --- a/files/unit_test/scale_test.cc +++ b/files/unit_test/scale_test.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The LibYuv project authors. All Rights Reserved. + * Copyright 2011 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 @@ -8,152 +8,369 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "libyuv/scale.h" -#include "unit_test.h" #include <stdlib.h> #include <time.h> -using namespace libyuv; - -#define align_buffer_16(var, size) \ - uint8 *var; \ - uint8 *var##_mem; \ - var##_mem = reinterpret_cast<uint8*>(calloc(size+15, sizeof(uint8))); \ - var = reinterpret_cast<uint8*> \ - ((reinterpret_cast<intptr_t>(var##_mem) + 15) & (~0x0f)); - -#define free_aligned_buffer_16(var) \ - free(var##_mem); \ - var = 0; - -TEST_F(libyuvTest, ScaleDownBy4) { - int b = 128; - int src_width = 1280; - int src_height = 720; - int src_width_uv = (src_width + 1) >> 1; - int src_height_uv = (src_height + 1) >> 1; +#include "libyuv/cpu_id.h" +#include "libyuv/scale.h" +#include "../unit_test/unit_test.h" - int src_y_plane_size = (src_width + (2 * b)) * (src_height + (2 * b)); - int src_uv_plane_size = (src_width_uv + (2 * b)) * (src_height_uv + (2 * b)); +namespace libyuv { - int src_stride_y = 2 * b + src_width; - int src_stride_uv = 2 * b + src_width_uv; +static int TestFilter(int src_width, int src_height, + int dst_width, int dst_height, + FilterMode f, int rounding, int benchmark_iterations) { + const int b = 128 * rounding; + int src_width_uv = (src_width + rounding) >> 1; + int src_height_uv = (src_height + rounding) >> 1; - align_buffer_16(src_y, src_y_plane_size) - align_buffer_16(src_u, src_uv_plane_size) - align_buffer_16(src_v, src_uv_plane_size) + int src_y_plane_size = (src_width + b * 2) * (src_height + b * 2); + int src_uv_plane_size = (src_width_uv + b * 2) * (src_height_uv + b * 2); - int dst_width = src_width >> 2; - int dst_height = src_height >> 2; + int src_stride_y = b * 2 + src_width; + int src_stride_uv = b * 2 + src_width_uv; - int dst_width_uv = (dst_width + 1) >> 1; - int dst_height_uv = (dst_height + 1) >> 1; + align_buffer_page_end(src_y, src_y_plane_size) + align_buffer_page_end(src_u, src_uv_plane_size) + align_buffer_page_end(src_v, src_uv_plane_size) - int dst_y_plane_size = (dst_width + (2 * b)) * (dst_height + (2 * b)); - int dst_uv_plane_size = (dst_width_uv + (2 * b)) * (dst_height_uv + (2 * b)); + int dst_width_uv = (dst_width + rounding) >> 1; + int dst_height_uv = (dst_height + rounding) >> 1; - int dst_stride_y = 2 * b + dst_width; - int dst_stride_uv = 2 * b + dst_width_uv; + int dst_y_plane_size = (dst_width + b * 2) * (dst_height + b * 2); + int dst_uv_plane_size = (dst_width_uv + b * 2) * (dst_height_uv + b * 2); - align_buffer_16(dst_y, dst_y_plane_size) - align_buffer_16(dst_u, dst_uv_plane_size) - align_buffer_16(dst_v, dst_uv_plane_size) + int dst_stride_y = b * 2 + dst_width; + int dst_stride_uv = b * 2 + dst_width_uv; - // create an image with random data reoccurring in 4x4 grid. When the image - // is filtered all the values should be the same. srandom(time(NULL)); - uint8 block_data[16]; - int i, j; - - // Pulling 16 random numbers there is an infinitesimally small - // chance that they are all 0. Then the output will be all 0. - // Output buffer is filled with 0, want to make sure that after the - // filtering something went into the output buffer. - // Avoid this by setting one of the values to 128. Also set the - // random data to at least 1 for when point sampling to prevent - // output all being 0. - block_data[0] = 128; - - for (i = 1; i < 16; i++) - block_data[i] = (random() & 0xfe) + 1; - - for (i = b; i < (src_height + b); i += 4) { - for (j = b; j < (src_width + b); j += 4) { - uint8 *ptr = src_y + (i * src_stride_y) + j; - int k, l; - for (k = 0; k < 4; ++k) - for (l = 0; l < 4; ++l) - ptr[k + src_stride_y * l] = block_data[k + 4 * l]; + for (i = b; i < (src_height + b); ++i) { + for (j = b; j < (src_width + b); ++j) { + src_y[(i * src_stride_y) + j] = (random() & 0xff); } } - for (i = 1; i < 16; i++) - block_data[i] = (random() & 0xfe) + 1; - - for (i = b; i < (src_height_uv + b); i += 4) { - for (j = b; j < (src_width_uv + b); j += 4) { - uint8 *ptru = src_u + (i * src_stride_uv) + j; - uint8 *ptrv = src_v + (i * src_stride_uv) + j; - int k, l; - for (k = 0; k < 4; ++k) - for (l = 0; l < 4; ++l) { - ptru[k + src_stride_uv * l] = block_data[k + 4 * l]; - ptrv[k + src_stride_uv * l] = block_data[k + 4 * l]; - } + for (i = b; i < (src_height_uv + b); ++i) { + for (j = b; j < (src_width_uv + b); ++j) { + src_u[(i * src_stride_uv) + j] = (random() & 0xff); + src_v[(i * src_stride_uv) + j] = (random() & 0xff); } } - int f; - int err = 0; + align_buffer_page_end(dst_y_c, dst_y_plane_size) + align_buffer_page_end(dst_u_c, dst_uv_plane_size) + align_buffer_page_end(dst_v_c, dst_uv_plane_size) + align_buffer_page_end(dst_y_opt, dst_y_plane_size) + align_buffer_page_end(dst_u_opt, dst_uv_plane_size) + align_buffer_page_end(dst_v_opt, dst_uv_plane_size) + + // Warm up both versions for consistent benchmarks. + MaskCpuFlags(0); // Disable all CPU optimization. + I420Scale(src_y + (src_stride_y * b) + b, src_stride_y, + src_u + (src_stride_uv * b) + b, src_stride_uv, + src_v + (src_stride_uv * b) + b, src_stride_uv, + src_width, src_height, + dst_y_c + (dst_stride_y * b) + b, dst_stride_y, + dst_u_c + (dst_stride_uv * b) + b, dst_stride_uv, + dst_v_c + (dst_stride_uv * b) + b, dst_stride_uv, + dst_width, dst_height, f); + MaskCpuFlags(-1); // Enable all CPU optimization. + I420Scale(src_y + (src_stride_y * b) + b, src_stride_y, + src_u + (src_stride_uv * b) + b, src_stride_uv, + src_v + (src_stride_uv * b) + b, src_stride_uv, + src_width, src_height, + dst_y_opt + (dst_stride_y * b) + b, dst_stride_y, + dst_u_opt + (dst_stride_uv * b) + b, dst_stride_uv, + dst_v_opt + (dst_stride_uv * b) + b, dst_stride_uv, + dst_width, dst_height, f); - // currently three filter modes, defined as FilterMode in scale.h - for (f = 0; f < 3; ++f) { + MaskCpuFlags(0); // Disable all CPU optimization. + double c_time = get_time(); + for (i = 0; i < benchmark_iterations; ++i) { I420Scale(src_y + (src_stride_y * b) + b, src_stride_y, src_u + (src_stride_uv * b) + b, src_stride_uv, src_v + (src_stride_uv * b) + b, src_stride_uv, src_width, src_height, - dst_y + (dst_stride_y * b) + b, dst_stride_y, - dst_u + (dst_stride_uv * b) + b, dst_stride_uv, - dst_v + (dst_stride_uv * b) + b, dst_stride_uv, - dst_width, dst_height, - static_cast<FilterMode>(f)); - - int value = dst_y[(dst_stride_y * b) + b]; - - // catch the case that the output buffer is all 0 - if (value == 0) - ++err; - - for (i = b; i < (dst_height + b); ++i) { - for (j = b; j < (dst_width + b); ++j) { - if (value != dst_y[(i * dst_stride_y) + j]) - ++err; - } - } + dst_y_c + (dst_stride_y * b) + b, dst_stride_y, + dst_u_c + (dst_stride_uv * b) + b, dst_stride_uv, + dst_v_c + (dst_stride_uv * b) + b, dst_stride_uv, + dst_width, dst_height, f); + } + c_time = (get_time() - c_time) / benchmark_iterations; - value = dst_u[(dst_stride_uv * b) + b]; + MaskCpuFlags(-1); // Enable all CPU optimization. + double opt_time = get_time(); + for (i = 0; i < benchmark_iterations; ++i) { + I420Scale(src_y + (src_stride_y * b) + b, src_stride_y, + src_u + (src_stride_uv * b) + b, src_stride_uv, + src_v + (src_stride_uv * b) + b, src_stride_uv, + src_width, src_height, + dst_y_opt + (dst_stride_y * b) + b, dst_stride_y, + dst_u_opt + (dst_stride_uv * b) + b, dst_stride_uv, + dst_v_opt + (dst_stride_uv * b) + b, dst_stride_uv, + dst_width, dst_height, f); + } + opt_time = (get_time() - opt_time) / benchmark_iterations; + + // Report performance of C vs OPT + printf("filter %d - %8d us C - %8d us OPT\n", + f, static_cast<int>(c_time*1e6), static_cast<int>(opt_time*1e6)); - if (value == 0) - ++err; + // C version may be a little off from the optimized. Order of + // operations may introduce rounding somewhere. So do a difference + // of the buffers and look to see that the max difference isn't + // over 2. + int max_diff = 0; + for (i = b; i < (dst_height + b); ++i) { + for (j = b; j < (dst_width + b); ++j) { + int abs_diff = abs(dst_y_c[(i * dst_stride_y) + j] - + dst_y_opt[(i * dst_stride_y) + j]); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + } - for (i = b; i < (dst_height_uv + b); ++i) { - for (j = b; j < (dst_width_uv + b); ++j) { - if (value != dst_u[(i * dst_stride_uv) + j]) - ++err; - if (value != dst_v[(i * dst_stride_uv) + j]) - ++err; + for (i = b; i < (dst_height_uv + b); ++i) { + for (j = b; j < (dst_width_uv + b); ++j) { + int abs_diff = abs(dst_u_c[(i * dst_stride_uv) + j] - + dst_u_opt[(i * dst_stride_uv) + j]); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + abs_diff = abs(dst_v_c[(i * dst_stride_uv) + j] - + dst_v_opt[(i * dst_stride_uv) + j]); + if (abs_diff > max_diff) { + max_diff = abs_diff; } } } - free_aligned_buffer_16(src_y) - free_aligned_buffer_16(src_u) - free_aligned_buffer_16(src_v) - free_aligned_buffer_16(dst_y) - free_aligned_buffer_16(dst_u) - free_aligned_buffer_16(dst_v) + free_aligned_buffer_page_end(dst_y_c) + free_aligned_buffer_page_end(dst_u_c) + free_aligned_buffer_page_end(dst_v_c) + free_aligned_buffer_page_end(dst_y_opt) + free_aligned_buffer_page_end(dst_u_opt) + free_aligned_buffer_page_end(dst_v_opt) + + free_aligned_buffer_page_end(src_y) + free_aligned_buffer_page_end(src_u) + free_aligned_buffer_page_end(src_v) + + return max_diff; +} + +TEST_F(libyuvTest, ScaleDownBy2) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = src_width / 2; + const int dst_height = src_height / 2; + + for (int f = 0; f < 3; ++f) { + int max_diff = TestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), 1, + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ScaleDownBy4) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = src_width / 4; + const int dst_height = src_height / 4; + + for (int f = 0; f < 3; ++f) { + int max_diff = TestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), 1, + benchmark_iterations_); + EXPECT_LE(max_diff, 2); // This is the only scale factor with error of 2. + } +} + +TEST_F(libyuvTest, ScaleDownBy5) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = src_width / 5; + const int dst_height = src_height / 5; + + for (int f = 0; f < 3; ++f) { + int max_diff = TestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), 1, + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ScaleDownBy8) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = src_width / 8; + const int dst_height = src_height / 8; + + for (int f = 0; f < 3; ++f) { + int max_diff = TestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), 1, + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ScaleDownBy16) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = src_width / 16; + const int dst_height = src_height / 16; + + for (int f = 0; f < 3; ++f) { + int max_diff = TestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), 1, + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ScaleDownBy34) { + const int src_width = 1280; + const int src_height = 720; + const int dst_width = src_width * 3 / 4; + const int dst_height = src_height * 3 / 4; + + for (int f = 0; f < 3; ++f) { + int max_diff = TestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), 1, + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ScaleDownBy38) { + int src_width = 1280; + int src_height = 720; + int dst_width = src_width * 3 / 8; + int dst_height = src_height * 3 / 8; + + for (int f = 0; f < 3; ++f) { + int max_diff = TestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), 1, + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ScaleTo1366) { + int src_width = 1280; + int src_height = 720; + int dst_width = 1366; + int dst_height = 768; + + for (int f = 0; f < 3; ++f) { + int max_diff = TestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), 1, + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ScaleTo4074) { + int src_width = 2880 * 2; + int src_height = 1800; + int dst_width = 4074; + int dst_height = 1272; + + for (int f = 0; f < 3; ++f) { + int max_diff = TestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), 1, + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ScaleTo853) { + int src_width = 1280; + int src_height = 720; + int dst_width = 853; + int dst_height = 480; + + for (int f = 0; f < 3; ++f) { + int max_diff = TestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), 1, + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ScaleTo853Wrong) { + int src_width = 1280; + int src_height = 720; + int dst_width = 853; + int dst_height = 480; - EXPECT_EQ(0, err); + for (int f = 0; f < 3; ++f) { + int max_diff = TestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), 0, + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } } + +// A one off test for a screen cast resolution scale. +TEST_F(libyuvTest, ScaleTo684) { + int src_width = 686; + int src_height = 557; + int dst_width = 684; + int dst_height = 552; + + for (int f = 0; f < 3; ++f) { + int max_diff = TestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), 1, + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ScaleTo342) { + int src_width = 686; + int src_height = 557; + int dst_width = 342; + int dst_height = 276; + + for (int f = 0; f < 3; ++f) { + int max_diff = TestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), 1, + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +TEST_F(libyuvTest, ScaleToHalf342) { + int src_width = 684; + int src_height = 552; + int dst_width = 342; + int dst_height = 276; + + for (int f = 0; f < 3; ++f) { + int max_diff = TestFilter(src_width, src_height, + dst_width, dst_height, + static_cast<FilterMode>(f), 1, + benchmark_iterations_); + EXPECT_LE(max_diff, 1); + } +} + +} // namespace libyuv diff --git a/files/unit_test/testdata/arm_v7.txt b/files/unit_test/testdata/arm_v7.txt new file mode 100644 index 00000000..5d7dbd04 --- /dev/null +++ b/files/unit_test/testdata/arm_v7.txt @@ -0,0 +1,12 @@ +Processor : ARMv7 Processor rev 5 (v7l) +BogoMIPS : 795.44 +Features : swp half thumb fastmult vfp edsp iwmmxt thumbee vfpv3 vfpv3d16 +CPU implementer : 0x56 +CPU architecture: 7 +CPU variant : 0x0 +CPU part : 0x581 +CPU revision : 5 + +Hardware : OLPC XO-1.75 +Revision : 0000 +Serial : 0000000000000000 diff --git a/files/unit_test/testdata/tegra3.txt b/files/unit_test/testdata/tegra3.txt new file mode 100644 index 00000000..d1b09f6b --- /dev/null +++ b/files/unit_test/testdata/tegra3.txt @@ -0,0 +1,23 @@ +Processor : ARMv7 Processor rev 9 (v7l) +processor : 0 +BogoMIPS : 1992.29 + +processor : 1 +BogoMIPS : 1992.29 + +processor : 2 +BogoMIPS : 1992.29 + +processor : 3 +BogoMIPS : 1992.29 + +Features : swp half thumb fastmult vfp edsp neon vfpv3 +CPU implementer : 0×41 +CPU architecture: 7 +CPU variant : 0×2 +CPU part : 0xc09 +CPU revision : 9 + +Hardware : cardhu +Revision : 0000 + diff --git a/files/unit_test/unit_test.cc b/files/unit_test/unit_test.cc index 1996adf1..007c81f0 100644 --- a/files/unit_test/unit_test.cc +++ b/files/unit_test/unit_test.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The LibYuv project authors. All Rights Reserved. + * Copyright 2011 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 @@ -8,33 +8,26 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include <cstring> -#include "unit_test.h" - -class libyuvEnvironment : public ::testing::Environment { - public: - virtual void SetUp() { - } +#include "../unit_test/unit_test.h" - virtual void TearDown() { - } -}; - -libyuvTest::libyuvTest() : - _rotate_max_w(128), - _rotate_max_h(128) { -} +#include <stdlib.h> // For getenv() -void libyuvTest::SetUp() { -} +#include <cstring> -void libyuvTest::TearDown() { +// Change this to 1000 for benchmarking. +// TODO(fbarchard): Add command line parsing to pass this as option. +#define BENCHMARK_ITERATIONS 1 + +libyuvTest::libyuvTest() : rotate_max_w_(128), rotate_max_h_(128), + benchmark_iterations_(BENCHMARK_ITERATIONS), benchmark_width_(1280), + benchmark_height_(720) { + const char* repeat = getenv("LIBYUV_REPEAT"); + if (repeat) { + benchmark_iterations_ = atoi(repeat); // NOLINT + } } int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - libyuvEnvironment* env = new libyuvEnvironment; - ::testing::AddGlobalTestEnvironment(env); - return RUN_ALL_TESTS(); -}
\ No newline at end of file +} diff --git a/files/unit_test/unit_test.h b/files/unit_test/unit_test.h index cac30c72..62521e88 100644 --- a/files/unit_test/unit_test.h +++ b/files/unit_test/unit_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The LibYuv project authors. All Rights Reserved. + * Copyright 2011 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 @@ -8,20 +8,67 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef UINIT_TEST_H_ -#define UINIT_TEST_H_ +#ifndef UNIT_TEST_UNIT_TEST_H_ +#define UNIT_TEST_UNIT_TEST_H_ #include <gtest/gtest.h> +#define align_buffer_16(var, size) \ + uint8* var; \ + uint8* var##_mem; \ + var##_mem = reinterpret_cast<uint8*>(malloc((size) + 15)); \ + var = reinterpret_cast<uint8*> \ + ((reinterpret_cast<intptr_t>(var##_mem) + 15) & ~15); + +#define free_aligned_buffer_16(var) \ + free(var##_mem); \ + var = 0; + + +#define align_buffer_page_end(var, size) \ + uint8* var; \ + uint8* var##_mem; \ + var##_mem = reinterpret_cast<uint8*>(malloc(((size) + 4095) & ~4095)); \ + var = var##_mem + (-(size) & 4095); + +#define free_aligned_buffer_page_end(var) \ + free(var##_mem); \ + var = 0; + +#ifdef WIN32 +#include <windows.h> +static inline double get_time() { + LARGE_INTEGER t, f; + QueryPerformanceCounter(&t); + QueryPerformanceFrequency(&f); + return static_cast<double>(t.QuadPart) / static_cast<double>(f.QuadPart); +} + +#define random rand +#define srandom srand +#else + +#include <sys/time.h> +#include <sys/resource.h> + +static inline double get_time() { + struct timeval t; + struct timezone tzp; + gettimeofday(&t, &tzp); + return t.tv_sec + t.tv_usec * 1e-6; +} +#endif + class libyuvTest : public ::testing::Test { protected: libyuvTest(); - virtual void SetUp(); - virtual void TearDown(); - const int _rotate_max_w; - const int _rotate_max_h; + const int rotate_max_w_; + const int rotate_max_h_; + int benchmark_iterations_; + const int benchmark_width_; + const int benchmark_height_; }; -#endif // UNIT_TEST_H_ +#endif // UNIT_TEST_UNIT_TEST_H_ diff --git a/files/unit_test/version_test.cc b/files/unit_test/version_test.cc new file mode 100644 index 00000000..c53d754c --- /dev/null +++ b/files/unit_test/version_test.cc @@ -0,0 +1,42 @@ +/* + * Copyright 2012 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 <stdlib.h> +#include <string.h> + +#include "libyuv/basic_types.h" +#include "libyuv/version.h" +#include "../unit_test/unit_test.h" + +namespace libyuv { + +// Tests SVN version against include/libyuv/version.h +// SVN version is bumped by documentation changes as well as code. +// Although the versions should match, once checked in, a tolerance is allowed. +TEST_F(libyuvTest, TestVersion) { + EXPECT_GE(LIBYUV_VERSION, 169); // 169 is first version to support version. + printf("LIBYUV_VERSION %d\n", LIBYUV_VERSION); +#ifdef LIBYUV_SVNREVISION + const char *ver = strchr(LIBYUV_SVNREVISION, ':'); + if (ver) { + ++ver; + } else { + ver = LIBYUV_SVNREVISION; + } + int svn_revision = atoi(ver); // NOLINT + printf("LIBYUV_SVNREVISION %d\n", svn_revision); + EXPECT_NEAR(LIBYUV_VERSION, svn_revision, 3); // Allow version to be close. + if (LIBYUV_VERSION != svn_revision) { + printf("WARNING - Versions do not match.\n"); + } +#endif +} + +} // namespace libyuv |