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 27using libvpx_test::ACMRandom; 28 29namespace { 30 31const int kNumPixels = 64 * 64; 32class VP9DenoiserTest : public ::testing::TestWithParam<BLOCK_SIZE> { 33 public: 34 virtual ~VP9DenoiserTest() {} 35 36 virtual void SetUp() { 37 bs_ = GetParam(); 38 } 39 40 virtual void TearDown() { libvpx_test::ClearSystemState(); } 41 42 protected: 43 BLOCK_SIZE bs_; 44}; 45 46TEST_P(VP9DenoiserTest, BitexactCheck) { 47 ACMRandom rnd(ACMRandom::DeterministicSeed()); 48 const int count_test_block = 4000; 49 50 // Allocate the space for input and output, 51 // where sig_block is the block to be denoised, 52 // mc_avg_block is the denoised reference block, 53 // avg_block_c is the denoised result from C code, 54 // avg_block_sse2 is the denoised result from SSE2 code. 55 DECLARE_ALIGNED(16, uint8_t, sig_block[kNumPixels]); 56 DECLARE_ALIGNED(16, uint8_t, mc_avg_block[kNumPixels]); 57 DECLARE_ALIGNED(16, uint8_t, avg_block_c[kNumPixels]); 58 DECLARE_ALIGNED(16, uint8_t, avg_block_sse2[kNumPixels]); 59 60 for (int i = 0; i < count_test_block; ++i) { 61 // Generate random motion magnitude, 20% of which exceed the threshold. 62 const int motion_magnitude_random = 63 rnd.Rand8() % static_cast<int>(MOTION_MAGNITUDE_THRESHOLD * 1.2); 64 65 // Initialize a test block with random number in range [0, 255]. 66 for (int j = 0; j < kNumPixels; ++j) { 67 int temp = 0; 68 sig_block[j] = rnd.Rand8(); 69 // The pixels in mc_avg_block are generated by adding a random 70 // number in range [-19, 19] to corresponding pixels in sig_block. 71 temp = sig_block[j] + ((rnd.Rand8() % 2 == 0) ? -1 : 1) * 72 (rnd.Rand8() % 20); 73 // Clip. 74 mc_avg_block[j] = (temp < 0) ? 0 : ((temp > 255) ? 255 : temp); 75 } 76 77 ASM_REGISTER_STATE_CHECK(vp9_denoiser_filter_c( 78 sig_block, 64, mc_avg_block, 64, avg_block_c, 79 64, 0, bs_, motion_magnitude_random)); 80 81 ASM_REGISTER_STATE_CHECK(vp9_denoiser_filter_sse2( 82 sig_block, 64, mc_avg_block, 64, avg_block_sse2, 83 64, 0, bs_, motion_magnitude_random)); 84 85 // Test bitexactness. 86 for (int h = 0; h < (4 << b_height_log2_lookup[bs_]); ++h) { 87 for (int w = 0; w < (4 << b_width_log2_lookup[bs_]); ++w) { 88 EXPECT_EQ(avg_block_c[h * 64 + w], avg_block_sse2[h * 64 + w]); 89 } 90 } 91 } 92} 93 94// Test for all block size. 95INSTANTIATE_TEST_CASE_P( 96 SSE2, VP9DenoiserTest, 97 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4, BLOCK_8X8, 98 BLOCK_8X16, BLOCK_16X8, BLOCK_16X16, BLOCK_16X32, 99 BLOCK_32X16, BLOCK_32X32, BLOCK_32X64, BLOCK_64X32, 100 BLOCK_64X64)); 101} // namespace 102