blob: d51155ddba3488bca4717c56388531313933437a [file] [log] [blame]
JackyChen80465da2014-09-18 16:45:53 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
JackyChen80465da2014-09-18 16:45:53 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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*/
JackyChen80465da2014-09-18 16:45:53 -070011
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 Xuc27fc142016-08-22 16:08:15 -070022#include "aom_scale/yv12config.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070023#include "aom/aom_integer.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070024#include "av1/common/reconinter.h"
25#include "av1/encoder/context_tree.h"
26#include "av1/encoder/denoiser.h"
JackyChen80465da2014-09-18 16:45:53 -070027
Yaowu Xuc27fc142016-08-22 16:08:15 -070028using libaom_test::ACMRandom;
JackyChen80465da2014-09-18 16:45:53 -070029
30namespace {
31
32const int kNumPixels = 64 * 64;
Yaowu Xuf883b422016-08-30 14:01:10 -070033class AV1DenoiserTest : public ::testing::TestWithParam<BLOCK_SIZE> {
JackyChen80465da2014-09-18 16:45:53 -070034 public:
Yaowu Xuf883b422016-08-30 14:01:10 -070035 virtual ~AV1DenoiserTest() {}
JackyChen80465da2014-09-18 16:45:53 -070036
clang-format3a826f12016-08-11 17:46:05 -070037 virtual void SetUp() { bs_ = GetParam(); }
JackyChen80465da2014-09-18 16:45:53 -070038
Yaowu Xuc27fc142016-08-22 16:08:15 -070039 virtual void TearDown() { libaom_test::ClearSystemState(); }
JackyChen80465da2014-09-18 16:45:53 -070040
41 protected:
JackyChen31780e62014-10-10 10:04:22 -070042 BLOCK_SIZE bs_;
JackyChen80465da2014-09-18 16:45:53 -070043};
44
Yaowu Xuf883b422016-08-30 14:01:10 -070045TEST_P(AV1DenoiserTest, BitexactCheck) {
JackyChen80465da2014-09-18 16:45:53 -070046 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 Zernfd3658b2015-05-02 13:24:16 -070054 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]);
JackyChen80465da2014-09-18 16:45:53 -070058
59 for (int i = 0; i < count_test_block; ++i) {
60 // Generate random motion magnitude, 20% of which exceed the threshold.
JackyChen31780e62014-10-10 10:04:22 -070061 const int motion_magnitude_random =
62 rnd.Rand8() % static_cast<int>(MOTION_MAGNITUDE_THRESHOLD * 1.2);
JackyChen80465da2014-09-18 16:45:53 -070063
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-format3a826f12016-08-11 17:46:05 -070070 temp =
71 sig_block[j] + ((rnd.Rand8() % 2 == 0) ? -1 : 1) * (rnd.Rand8() % 20);
JackyChen80465da2014-09-18 16:45:53 -070072 // Clip.
JackyChen31780e62014-10-10 10:04:22 -070073 mc_avg_block[j] = (temp < 0) ? 0 : ((temp > 255) ? 255 : temp);
JackyChen80465da2014-09-18 16:45:53 -070074 }
75
Yaowu Xuf883b422016-08-30 14:01:10 -070076 ASM_REGISTER_STATE_CHECK(av1_denoiser_filter_c(sig_block, 64, mc_avg_block,
clang-format3a826f12016-08-11 17:46:05 -070077 64, avg_block_c, 64, 0, bs_,
78 motion_magnitude_random));
JackyChen80465da2014-09-18 16:45:53 -070079
Yaowu Xuf883b422016-08-30 14:01:10 -070080 ASM_REGISTER_STATE_CHECK(av1_denoiser_filter_sse2(
clang-format3a826f12016-08-11 17:46:05 -070081 sig_block, 64, mc_avg_block, 64, avg_block_sse2, 64, 0, bs_,
82 motion_magnitude_random));
JackyChen80465da2014-09-18 16:45:53 -070083
84 // Test bitexactness.
JackyChen31780e62014-10-10 10:04:22 -070085 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) {
JackyChen80465da2014-09-18 16:45:53 -070087 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 Xuf883b422016-08-30 14:01:10 -070094INSTANTIATE_TEST_CASE_P(SSE2, AV1DenoiserTest,
clang-format3a826f12016-08-11 17:46:05 -070095 ::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));
JackyChen80465da2014-09-18 16:45:53 -070099} // namespace