JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
| 10 | */ |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 11 | |
| 12 | #include <math.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
| 15 | |
| 16 | #include "third_party/googletest/src/include/gtest/gtest.h" |
| 17 | #include "test/acm_random.h" |
| 18 | #include "test/clear_system_state.h" |
| 19 | #include "test/register_state_check.h" |
| 20 | #include "test/util.h" |
| 21 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 22 | #include "aom_scale/yv12config.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 23 | #include "aom/aom_integer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 24 | #include "av1/common/reconinter.h" |
| 25 | #include "av1/encoder/context_tree.h" |
| 26 | #include "av1/encoder/denoiser.h" |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 27 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 28 | using libaom_test::ACMRandom; |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 29 | |
| 30 | namespace { |
| 31 | |
| 32 | const int kNumPixels = 64 * 64; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 33 | class AV1DenoiserTest : public ::testing::TestWithParam<BLOCK_SIZE> { |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 34 | public: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 35 | virtual ~AV1DenoiserTest() {} |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 36 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 37 | virtual void SetUp() { bs_ = GetParam(); } |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 38 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 39 | virtual void TearDown() { libaom_test::ClearSystemState(); } |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 40 | |
| 41 | protected: |
JackyChen | 31780e6 | 2014-10-10 10:04:22 -0700 | [diff] [blame] | 42 | BLOCK_SIZE bs_; |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 45 | TEST_P(AV1DenoiserTest, BitexactCheck) { |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 46 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 47 | const int count_test_block = 4000; |
| 48 | |
| 49 | // Allocate the space for input and output, |
| 50 | // where sig_block is the block to be denoised, |
| 51 | // mc_avg_block is the denoised reference block, |
| 52 | // avg_block_c is the denoised result from C code, |
| 53 | // avg_block_sse2 is the denoised result from SSE2 code. |
James Zern | fd3658b | 2015-05-02 13:24:16 -0700 | [diff] [blame] | 54 | DECLARE_ALIGNED(16, uint8_t, sig_block[kNumPixels]); |
| 55 | DECLARE_ALIGNED(16, uint8_t, mc_avg_block[kNumPixels]); |
| 56 | DECLARE_ALIGNED(16, uint8_t, avg_block_c[kNumPixels]); |
| 57 | DECLARE_ALIGNED(16, uint8_t, avg_block_sse2[kNumPixels]); |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 58 | |
| 59 | for (int i = 0; i < count_test_block; ++i) { |
| 60 | // Generate random motion magnitude, 20% of which exceed the threshold. |
JackyChen | 31780e6 | 2014-10-10 10:04:22 -0700 | [diff] [blame] | 61 | const int motion_magnitude_random = |
| 62 | rnd.Rand8() % static_cast<int>(MOTION_MAGNITUDE_THRESHOLD * 1.2); |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 63 | |
| 64 | // Initialize a test block with random number in range [0, 255]. |
| 65 | for (int j = 0; j < kNumPixels; ++j) { |
| 66 | int temp = 0; |
| 67 | sig_block[j] = rnd.Rand8(); |
| 68 | // The pixels in mc_avg_block are generated by adding a random |
| 69 | // number in range [-19, 19] to corresponding pixels in sig_block. |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 70 | temp = |
| 71 | sig_block[j] + ((rnd.Rand8() % 2 == 0) ? -1 : 1) * (rnd.Rand8() % 20); |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 72 | // Clip. |
JackyChen | 31780e6 | 2014-10-10 10:04:22 -0700 | [diff] [blame] | 73 | mc_avg_block[j] = (temp < 0) ? 0 : ((temp > 255) ? 255 : temp); |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 76 | ASM_REGISTER_STATE_CHECK(av1_denoiser_filter_c(sig_block, 64, mc_avg_block, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 77 | 64, avg_block_c, 64, 0, bs_, |
| 78 | motion_magnitude_random)); |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 79 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 80 | ASM_REGISTER_STATE_CHECK(av1_denoiser_filter_sse2( |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 81 | sig_block, 64, mc_avg_block, 64, avg_block_sse2, 64, 0, bs_, |
| 82 | motion_magnitude_random)); |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 83 | |
| 84 | // Test bitexactness. |
JackyChen | 31780e6 | 2014-10-10 10:04:22 -0700 | [diff] [blame] | 85 | for (int h = 0; h < (4 << b_height_log2_lookup[bs_]); ++h) { |
| 86 | for (int w = 0; w < (4 << b_width_log2_lookup[bs_]); ++w) { |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 87 | EXPECT_EQ(avg_block_c[h * 64 + w], avg_block_sse2[h * 64 + w]); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // Test for all block size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 94 | INSTANTIATE_TEST_CASE_P(SSE2, AV1DenoiserTest, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 95 | ::testing::Values(BLOCK_8X8, BLOCK_8X16, BLOCK_16X8, |
| 96 | BLOCK_16X16, BLOCK_16X32, BLOCK_32X16, |
| 97 | BLOCK_32X32, BLOCK_32X64, BLOCK_64X32, |
| 98 | BLOCK_64X64)); |
JackyChen | 80465da | 2014-09-18 16:45:53 -0700 | [diff] [blame] | 99 | } // namespace |