JackyChen | 09fbe88 | 2014-10-07 15:30:23 -0700 | [diff] [blame] | 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 "vp8/encoder/denoising.h" |
| 22 | #include "vp8/common/reconinter.h" |
| 23 | #include "vpx/vpx_integer.h" |
| 24 | #include "vpx_mem/vpx_mem.h" |
| 25 | |
| 26 | using libvpx_test::ACMRandom; |
| 27 | |
| 28 | namespace { |
| 29 | |
| 30 | const int kNumPixels = 16 * 16; |
JackyChen | 31780e6 | 2014-10-10 10:04:22 -0700 | [diff] [blame] | 31 | class VP8DenoiserTest : public ::testing::TestWithParam<int> { |
JackyChen | 09fbe88 | 2014-10-07 15:30:23 -0700 | [diff] [blame] | 32 | public: |
| 33 | virtual ~VP8DenoiserTest() {} |
| 34 | |
| 35 | virtual void SetUp() { |
JackyChen | 31780e6 | 2014-10-10 10:04:22 -0700 | [diff] [blame] | 36 | increase_denoising_ = GetParam(); |
JackyChen | 09fbe88 | 2014-10-07 15:30:23 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | virtual void TearDown() { libvpx_test::ClearSystemState(); } |
| 40 | |
| 41 | protected: |
JackyChen | 31780e6 | 2014-10-10 10:04:22 -0700 | [diff] [blame] | 42 | int increase_denoising_; |
JackyChen | 09fbe88 | 2014-10-07 15:30:23 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | TEST_P(VP8DenoiserTest, BitexactCheck) { |
| 46 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 47 | const int count_test_block = 4000; |
| 48 | const int stride = 16; |
| 49 | |
| 50 | // Allocate the space for input and output, |
| 51 | // where sig_block_c/_sse2 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. |
James Zern | fd3658b | 2015-05-02 13:24:16 -0700 | [diff] [blame] | 55 | DECLARE_ALIGNED(16, uint8_t, sig_block_c[kNumPixels]); |
JackyChen | 09fbe88 | 2014-10-07 15:30:23 -0700 | [diff] [blame] | 56 | // Since in VP8 denoiser, the source signal will be changed, |
| 57 | // we need another copy of the source signal as the input of sse2 code. |
James Zern | fd3658b | 2015-05-02 13:24:16 -0700 | [diff] [blame] | 58 | DECLARE_ALIGNED(16, uint8_t, sig_block_sse2[kNumPixels]); |
| 59 | DECLARE_ALIGNED(16, uint8_t, mc_avg_block[kNumPixels]); |
| 60 | DECLARE_ALIGNED(16, uint8_t, avg_block_c[kNumPixels]); |
| 61 | DECLARE_ALIGNED(16, uint8_t, avg_block_sse2[kNumPixels]); |
JackyChen | 09fbe88 | 2014-10-07 15:30:23 -0700 | [diff] [blame] | 62 | |
| 63 | for (int i = 0; i < count_test_block; ++i) { |
| 64 | // Generate random motion magnitude, 20% of which exceed the threshold. |
JackyChen | 31780e6 | 2014-10-10 10:04:22 -0700 | [diff] [blame] | 65 | const int motion_magnitude_ran = |
| 66 | rnd.Rand8() % static_cast<int>(MOTION_MAGNITUDE_THRESHOLD * 1.2); |
JackyChen | 09fbe88 | 2014-10-07 15:30:23 -0700 | [diff] [blame] | 67 | |
| 68 | // Initialize a test block with random number in range [0, 255]. |
| 69 | for (int j = 0; j < kNumPixels; ++j) { |
| 70 | int temp = 0; |
| 71 | sig_block_sse2[j] = sig_block_c[j] = rnd.Rand8(); |
| 72 | // The pixels in mc_avg_block are generated by adding a random |
| 73 | // number in range [-19, 19] to corresponding pixels in sig_block. |
JackyChen | 31780e6 | 2014-10-10 10:04:22 -0700 | [diff] [blame] | 74 | temp = sig_block_c[j] + (rnd.Rand8() % 2 == 0 ? -1 : 1) * |
| 75 | (rnd.Rand8() % 20); |
JackyChen | 09fbe88 | 2014-10-07 15:30:23 -0700 | [diff] [blame] | 76 | // Clip. |
JackyChen | 31780e6 | 2014-10-10 10:04:22 -0700 | [diff] [blame] | 77 | mc_avg_block[j] = (temp < 0) ? 0 : ((temp > 255) ? 255 : temp); |
JackyChen | 09fbe88 | 2014-10-07 15:30:23 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | // Test denosiser on Y component. |
JackyChen | 31780e6 | 2014-10-10 10:04:22 -0700 | [diff] [blame] | 81 | ASM_REGISTER_STATE_CHECK(vp8_denoiser_filter_c( |
| 82 | mc_avg_block, stride, avg_block_c, stride, sig_block_c, stride, |
| 83 | motion_magnitude_ran, increase_denoising_)); |
JackyChen | 09fbe88 | 2014-10-07 15:30:23 -0700 | [diff] [blame] | 84 | |
JackyChen | 31780e6 | 2014-10-10 10:04:22 -0700 | [diff] [blame] | 85 | ASM_REGISTER_STATE_CHECK(vp8_denoiser_filter_sse2( |
| 86 | mc_avg_block, stride, avg_block_sse2, stride, sig_block_sse2, stride, |
| 87 | motion_magnitude_ran, increase_denoising_)); |
JackyChen | 09fbe88 | 2014-10-07 15:30:23 -0700 | [diff] [blame] | 88 | |
| 89 | // Check bitexactness. |
| 90 | for (int h = 0; h < 16; ++h) { |
| 91 | for (int w = 0; w < 16; ++w) { |
| 92 | EXPECT_EQ(avg_block_c[h * stride + w], avg_block_sse2[h * stride + w]); |
| 93 | } |
| 94 | } |
| 95 | |
JackyChen | 31780e6 | 2014-10-10 10:04:22 -0700 | [diff] [blame] | 96 | // Test denoiser on UV component. |
| 97 | ASM_REGISTER_STATE_CHECK(vp8_denoiser_filter_uv_c( |
| 98 | mc_avg_block, stride, avg_block_c, stride, sig_block_c, stride, |
| 99 | motion_magnitude_ran, increase_denoising_)); |
JackyChen | 09fbe88 | 2014-10-07 15:30:23 -0700 | [diff] [blame] | 100 | |
JackyChen | 31780e6 | 2014-10-10 10:04:22 -0700 | [diff] [blame] | 101 | ASM_REGISTER_STATE_CHECK(vp8_denoiser_filter_uv_sse2( |
| 102 | mc_avg_block, stride, avg_block_sse2, stride, sig_block_sse2, stride, |
| 103 | motion_magnitude_ran, increase_denoising_)); |
JackyChen | 09fbe88 | 2014-10-07 15:30:23 -0700 | [diff] [blame] | 104 | |
| 105 | // Check bitexactness. |
| 106 | for (int h = 0; h < 16; ++h) { |
| 107 | for (int w = 0; w < 16; ++w) { |
| 108 | EXPECT_EQ(avg_block_c[h * stride + w], avg_block_sse2[h * stride + w]); |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // Test for all block size. |
JackyChen | 31780e6 | 2014-10-10 10:04:22 -0700 | [diff] [blame] | 115 | INSTANTIATE_TEST_CASE_P(SSE2, VP8DenoiserTest, ::testing::Values(0, 1)); |
JackyChen | 09fbe88 | 2014-10-07 15:30:23 -0700 | [diff] [blame] | 116 | } // namespace |