xref: /aosp_15_r20/external/libvpx/test/vp8_denoiser_sse2_test.cc (revision fb1b10ab9aebc7c7068eedab379b749d7e3900be)
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 "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_config.h"
25 #include "vpx_mem/vpx_mem.h"
26 
27 using libvpx_test::ACMRandom;
28 
29 namespace {
30 
31 const int kNumPixels = 16 * 16;
32 class VP8DenoiserTest : public ::testing::TestWithParam<int> {
33  public:
34   ~VP8DenoiserTest() override = default;
35 
SetUp()36   void SetUp() override { increase_denoising_ = GetParam(); }
37 
TearDown()38   void TearDown() override { libvpx_test::ClearSystemState(); }
39 
40  protected:
41   int increase_denoising_;
42 };
43 
44 // TODO(https://crbug.com/webm/1718): This test fails with gcc 8-10.
45 #if defined(__GNUC__) && __GNUC__ >= 8
TEST_P(VP8DenoiserTest,DISABLED_BitexactCheck)46 TEST_P(VP8DenoiserTest, DISABLED_BitexactCheck) {
47 #else
48 TEST_P(VP8DenoiserTest, BitexactCheck) {
49 #endif
50   ACMRandom rnd(ACMRandom::DeterministicSeed());
51   const int count_test_block = 4000;
52   const int stride = 16;
53 
54   // Allocate the space for input and output,
55   // where sig_block_c/_sse2 is the block to be denoised,
56   // mc_avg_block is the denoised reference block,
57   // avg_block_c is the denoised result from C code,
58   // avg_block_sse2 is the denoised result from SSE2 code.
59   DECLARE_ALIGNED(16, uint8_t, sig_block_c[kNumPixels]);
60   // Since in VP8 denoiser, the source signal will be changed,
61   // we need another copy of the source signal as the input of sse2 code.
62   DECLARE_ALIGNED(16, uint8_t, sig_block_sse2[kNumPixels]);
63   DECLARE_ALIGNED(16, uint8_t, mc_avg_block[kNumPixels]);
64   DECLARE_ALIGNED(16, uint8_t, avg_block_c[kNumPixels]);
65   DECLARE_ALIGNED(16, uint8_t, avg_block_sse2[kNumPixels]);
66 
67   for (int i = 0; i < count_test_block; ++i) {
68     // Generate random motion magnitude, 20% of which exceed the threshold.
69     const int motion_magnitude_ran =
70         rnd.Rand8() % static_cast<int>(MOTION_MAGNITUDE_THRESHOLD * 1.2);
71 
72     // Initialize a test block with random number in range [0, 255].
73     for (int j = 0; j < kNumPixels; ++j) {
74       int temp = 0;
75       sig_block_sse2[j] = sig_block_c[j] = rnd.Rand8();
76       // The pixels in mc_avg_block are generated by adding a random
77       // number in range [-19, 19] to corresponding pixels in sig_block.
78       temp =
79           sig_block_c[j] + (rnd.Rand8() % 2 == 0 ? -1 : 1) * (rnd.Rand8() % 20);
80       // Clip.
81       mc_avg_block[j] = (temp < 0) ? 0 : ((temp > 255) ? 255 : temp);
82     }
83 
84     // Test denosiser on Y component.
85     ASM_REGISTER_STATE_CHECK(vp8_denoiser_filter_c(
86         mc_avg_block, stride, avg_block_c, stride, sig_block_c, stride,
87         motion_magnitude_ran, increase_denoising_));
88 
89     ASM_REGISTER_STATE_CHECK(vp8_denoiser_filter_sse2(
90         mc_avg_block, stride, avg_block_sse2, stride, sig_block_sse2, stride,
91         motion_magnitude_ran, increase_denoising_));
92 
93     // Check bitexactness.
94     for (int h = 0; h < 16; ++h) {
95       for (int w = 0; w < 16; ++w) {
96         ASSERT_EQ(avg_block_c[h * stride + w], avg_block_sse2[h * stride + w]);
97       }
98     }
99 
100     // Test denoiser on UV component.
101     ASM_REGISTER_STATE_CHECK(vp8_denoiser_filter_uv_c(
102         mc_avg_block, stride, avg_block_c, stride, sig_block_c, stride,
103         motion_magnitude_ran, increase_denoising_));
104 
105     ASM_REGISTER_STATE_CHECK(vp8_denoiser_filter_uv_sse2(
106         mc_avg_block, stride, avg_block_sse2, stride, sig_block_sse2, stride,
107         motion_magnitude_ran, increase_denoising_));
108 
109     // Check bitexactness.
110     for (int h = 0; h < 16; ++h) {
111       for (int w = 0; w < 16; ++w) {
112         ASSERT_EQ(avg_block_c[h * stride + w], avg_block_sse2[h * stride + w]);
113       }
114     }
115   }
116 }
117 
118 // Test for all block size.
119 INSTANTIATE_TEST_SUITE_P(SSE2, VP8DenoiserTest, ::testing::Values(0, 1));
120 }  // namespace
121