• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
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  */
11 
12 #include <math.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <tuple>
16 
17 #include "config/av1_rtcd.h"
18 
19 #include "test/acm_random.h"
20 #include "test/util.h"
21 #include "test/register_state_check.h"
22 
23 #include "aom_scale/yv12config.h"
24 #include "aom/aom_integer.h"
25 #include "av1/common/reconinter.h"
26 #include "av1/encoder/context_tree.h"
27 #include "av1/encoder/av1_temporal_denoiser.h"
28 
29 using libaom_test::ACMRandom;
30 
31 namespace {
32 
33 const int kNumPixels = 128 * 128;
34 
35 typedef int (*Av1DenoiserFilterFunc)(const uint8_t *sig, int sig_stride,
36                                      const uint8_t *mc_avg, int mc_avg_stride,
37                                      uint8_t *avg, int avg_stride,
38                                      int increase_denoising, BLOCK_SIZE bs,
39                                      int motion_magnitude);
40 typedef std::tuple<Av1DenoiserFilterFunc, BLOCK_SIZE> AV1DenoiserTestParam;
41 
42 class AV1DenoiserTest
43     : public ::testing::Test,
44       public ::testing::WithParamInterface<AV1DenoiserTestParam> {
45  public:
~AV1DenoiserTest()46   virtual ~AV1DenoiserTest() {}
47 
SetUp()48   virtual void SetUp() { bs_ = GET_PARAM(1); }
49 
TearDown()50   virtual void TearDown() {}
51 
52  protected:
53   BLOCK_SIZE bs_;
54 };
55 
TEST_P(AV1DenoiserTest,BitexactCheck)56 TEST_P(AV1DenoiserTest, BitexactCheck) {
57   ACMRandom rnd(ACMRandom::DeterministicSeed());
58   const int count_test_block = 4000;
59 
60   // Allocate the space for input and output,
61   // where sig_block is the block to be denoised,
62   // mc_avg_block is the denoised reference block,
63   // avg_block_c is the denoised result from C code,
64   // avg_block_sse2 is the denoised result from SSE2 code.
65   DECLARE_ALIGNED(16, uint8_t, sig_block[kNumPixels]);
66   DECLARE_ALIGNED(16, uint8_t, mc_avg_block[kNumPixels]);
67   DECLARE_ALIGNED(16, uint8_t, avg_block_c[kNumPixels]);
68   DECLARE_ALIGNED(16, uint8_t, avg_block_sse2[kNumPixels]);
69 
70   for (int i = 0; i < count_test_block; ++i) {
71     // Generate random motion magnitude, 20% of which exceed the threshold.
72     const int motion_magnitude_random =
73         rnd.Rand8() % static_cast<int>(MOTION_MAGNITUDE_THRESHOLD * 1.2);
74 
75     // Initialize a test block with random number in range [0, 255].
76     for (int j = 0; j < kNumPixels; ++j) {
77       int temp = 0;
78       sig_block[j] = rnd.Rand8();
79       // The pixels in mc_avg_block are generated by adding a random
80       // number in range [-19, 19] to corresponding pixels in sig_block.
81       temp =
82           sig_block[j] + ((rnd.Rand8() % 2 == 0) ? -1 : 1) * (rnd.Rand8() % 20);
83       // Clip.
84       mc_avg_block[j] = (temp < 0) ? 0 : ((temp > 255) ? 255 : temp);
85     }
86 
87     API_REGISTER_STATE_CHECK(
88         av1_denoiser_filter_c(sig_block, 128, mc_avg_block, 128, avg_block_c,
89                               128, 0, bs_, motion_magnitude_random));
90 
91     API_REGISTER_STATE_CHECK(GET_PARAM(0)(sig_block, 128, mc_avg_block, 128,
92                                           avg_block_sse2, 128, 0, bs_,
93                                           motion_magnitude_random));
94 
95     // Test bitexactness.
96     for (int h = 0; h < block_size_high[bs_]; ++h) {
97       for (int w = 0; w < block_size_wide[bs_]; ++w) {
98         EXPECT_EQ(avg_block_c[h * 128 + w], avg_block_sse2[h * 128 + w]);
99       }
100     }
101   }
102 }
103 
104 using std::make_tuple;
105 
106 // Test for all block size.
107 #if HAVE_SSE2
108 INSTANTIATE_TEST_SUITE_P(
109     SSE2, AV1DenoiserTest,
110     ::testing::Values(make_tuple(&av1_denoiser_filter_sse2, BLOCK_8X8),
111                       make_tuple(&av1_denoiser_filter_sse2, BLOCK_8X16),
112                       make_tuple(&av1_denoiser_filter_sse2, BLOCK_16X8),
113                       make_tuple(&av1_denoiser_filter_sse2, BLOCK_16X16),
114                       make_tuple(&av1_denoiser_filter_sse2, BLOCK_16X32),
115                       make_tuple(&av1_denoiser_filter_sse2, BLOCK_32X16),
116                       make_tuple(&av1_denoiser_filter_sse2, BLOCK_32X32),
117                       make_tuple(&av1_denoiser_filter_sse2, BLOCK_32X64),
118                       make_tuple(&av1_denoiser_filter_sse2, BLOCK_64X32),
119                       make_tuple(&av1_denoiser_filter_sse2, BLOCK_64X64),
120                       make_tuple(&av1_denoiser_filter_sse2, BLOCK_128X64),
121                       make_tuple(&av1_denoiser_filter_sse2, BLOCK_64X128),
122                       make_tuple(&av1_denoiser_filter_sse2, BLOCK_128X128)));
123 #endif  // HAVE_SSE2
124 
125 #if HAVE_NEON
126 INSTANTIATE_TEST_SUITE_P(
127     NEON, AV1DenoiserTest,
128     ::testing::Values(make_tuple(&av1_denoiser_filter_neon, BLOCK_8X8),
129                       make_tuple(&av1_denoiser_filter_neon, BLOCK_8X16),
130                       make_tuple(&av1_denoiser_filter_neon, BLOCK_16X8),
131                       make_tuple(&av1_denoiser_filter_neon, BLOCK_16X16),
132                       make_tuple(&av1_denoiser_filter_neon, BLOCK_16X32),
133                       make_tuple(&av1_denoiser_filter_neon, BLOCK_32X16),
134                       make_tuple(&av1_denoiser_filter_neon, BLOCK_32X32),
135                       make_tuple(&av1_denoiser_filter_neon, BLOCK_32X64),
136                       make_tuple(&av1_denoiser_filter_neon, BLOCK_64X32),
137                       make_tuple(&av1_denoiser_filter_neon, BLOCK_64X64),
138                       make_tuple(&av1_denoiser_filter_neon, BLOCK_128X64),
139                       make_tuple(&av1_denoiser_filter_neon, BLOCK_64X128),
140                       make_tuple(&av1_denoiser_filter_neon, BLOCK_128X128)));
141 #endif
142 }  // namespace
143