1 /* 2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include <math.h> 12 #include <stdlib.h> 13 #include <string.h> 14 15 #include "third_party/googletest/src/include/gtest/gtest.h" 16 #include "test/acm_random.h" 17 #include "test/clear_system_state.h" 18 #include "test/register_state_check.h" 19 #include "test/util.h" 20 21 #include "vpx_scale/yv12config.h" 22 #include "vpx/vpx_integer.h" 23 #include "vp9/common/vp9_reconinter.h" 24 #include "vp9/encoder/vp9_context_tree.h" 25 #include "vp9/encoder/vp9_denoiser.h" 26 27 using libvpx_test::ACMRandom; 28 29 namespace { 30 31 const int kNumPixels = 64 * 64; 32 33 typedef int (*Vp9DenoiserFilterFunc)(const uint8_t *sig, int sig_stride, 34 const uint8_t *mc_avg, int mc_avg_stride, 35 uint8_t *avg, int avg_stride, 36 int increase_denoising, BLOCK_SIZE bs, 37 int motion_magnitude); 38 typedef std::tr1::tuple<Vp9DenoiserFilterFunc, BLOCK_SIZE> VP9DenoiserTestParam; 39 40 class VP9DenoiserTest 41 : public ::testing::Test, 42 public ::testing::WithParamInterface<VP9DenoiserTestParam> { 43 public: 44 virtual ~VP9DenoiserTest() {} 45 46 virtual void SetUp() { bs_ = GET_PARAM(1); } 47 48 virtual void TearDown() { libvpx_test::ClearSystemState(); } 49 50 protected: 51 BLOCK_SIZE bs_; 52 }; 53 54 TEST_P(VP9DenoiserTest, BitexactCheck) { 55 ACMRandom rnd(ACMRandom::DeterministicSeed()); 56 const int count_test_block = 4000; 57 58 // Allocate the space for input and output, 59 // where sig_block is the block to be denoised, 60 // mc_avg_block is the denoised reference block, 61 // avg_block_c is the denoised result from C code, 62 // avg_block_sse2 is the denoised result from SSE2 code. 63 DECLARE_ALIGNED(16, uint8_t, sig_block[kNumPixels]); 64 DECLARE_ALIGNED(16, uint8_t, mc_avg_block[kNumPixels]); 65 DECLARE_ALIGNED(16, uint8_t, avg_block_c[kNumPixels]); 66 DECLARE_ALIGNED(16, uint8_t, avg_block_sse2[kNumPixels]); 67 68 for (int i = 0; i < count_test_block; ++i) { 69 // Generate random motion magnitude, 20% of which exceed the threshold. 70 const int motion_magnitude_random = 71 rnd.Rand8() % static_cast<int>(MOTION_MAGNITUDE_THRESHOLD * 1.2); 72 73 // Initialize a test block with random number in range [0, 255]. 74 for (int j = 0; j < kNumPixels; ++j) { 75 int temp = 0; 76 sig_block[j] = rnd.Rand8(); 77 // The pixels in mc_avg_block are generated by adding a random 78 // number in range [-19, 19] to corresponding pixels in sig_block. 79 temp = 80 sig_block[j] + ((rnd.Rand8() % 2 == 0) ? -1 : 1) * (rnd.Rand8() % 20); 81 // Clip. 82 mc_avg_block[j] = (temp < 0) ? 0 : ((temp > 255) ? 255 : temp); 83 } 84 85 ASM_REGISTER_STATE_CHECK(vp9_denoiser_filter_c(sig_block, 64, mc_avg_block, 86 64, avg_block_c, 64, 0, bs_, 87 motion_magnitude_random)); 88 89 ASM_REGISTER_STATE_CHECK(GET_PARAM(0)(sig_block, 64, mc_avg_block, 64, 90 avg_block_sse2, 64, 0, bs_, 91 motion_magnitude_random)); 92 93 // Test bitexactness. 94 for (int h = 0; h < (4 << b_height_log2_lookup[bs_]); ++h) { 95 for (int w = 0; w < (4 << b_width_log2_lookup[bs_]); ++w) { 96 EXPECT_EQ(avg_block_c[h * 64 + w], avg_block_sse2[h * 64 + w]); 97 } 98 } 99 } 100 } 101 102 using std::tr1::make_tuple; 103 104 // Test for all block size. 105 #if HAVE_SSE2 106 INSTANTIATE_TEST_CASE_P( 107 SSE2, VP9DenoiserTest, 108 ::testing::Values(make_tuple(&vp9_denoiser_filter_sse2, BLOCK_8X8), 109 make_tuple(&vp9_denoiser_filter_sse2, BLOCK_8X16), 110 make_tuple(&vp9_denoiser_filter_sse2, BLOCK_16X8), 111 make_tuple(&vp9_denoiser_filter_sse2, BLOCK_16X16), 112 make_tuple(&vp9_denoiser_filter_sse2, BLOCK_16X32), 113 make_tuple(&vp9_denoiser_filter_sse2, BLOCK_32X16), 114 make_tuple(&vp9_denoiser_filter_sse2, BLOCK_32X32), 115 make_tuple(&vp9_denoiser_filter_sse2, BLOCK_32X64), 116 make_tuple(&vp9_denoiser_filter_sse2, BLOCK_64X32), 117 make_tuple(&vp9_denoiser_filter_sse2, BLOCK_64X64))); 118 #endif // HAVE_SSE2 119 120 #if HAVE_NEON 121 INSTANTIATE_TEST_CASE_P( 122 NEON, VP9DenoiserTest, 123 ::testing::Values(make_tuple(&vp9_denoiser_filter_neon, BLOCK_8X8), 124 make_tuple(&vp9_denoiser_filter_neon, BLOCK_8X16), 125 make_tuple(&vp9_denoiser_filter_neon, BLOCK_16X8), 126 make_tuple(&vp9_denoiser_filter_neon, BLOCK_16X16), 127 make_tuple(&vp9_denoiser_filter_neon, BLOCK_16X32), 128 make_tuple(&vp9_denoiser_filter_neon, BLOCK_32X16), 129 make_tuple(&vp9_denoiser_filter_neon, BLOCK_32X32), 130 make_tuple(&vp9_denoiser_filter_neon, BLOCK_32X64), 131 make_tuple(&vp9_denoiser_filter_neon, BLOCK_64X32), 132 make_tuple(&vp9_denoiser_filter_neon, BLOCK_64X64))); 133 #endif 134 } // namespace 135