av1_temporal_denoiser_test.cc (5816B)
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 using Av1DenoiserFilterFunc = int (*)(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 using AV1DenoiserTestParam = std::tuple<Av1DenoiserFilterFunc, BLOCK_SIZE>; 41 42 class AV1DenoiserTest 43 : public ::testing::Test, 44 public ::testing::WithParamInterface<AV1DenoiserTestParam> { 45 public: 46 ~AV1DenoiserTest() override = default; 47 48 void SetUp() override { bs_ = GET_PARAM(1); } 49 50 protected: 51 BLOCK_SIZE bs_; 52 }; 53 54 TEST_P(AV1DenoiserTest, BitexactCheck) { 55 ACMRandom rnd(ACMRandom::DeterministicSeed()); 56 const int count_test_block = 4000; 57 58 // Allocate the space for input and output, 59 // where sig_block is the block to be denoised, 60 // mc_avg_block is the denoised reference block, 61 // avg_block_c is the denoised result from C code, 62 // avg_block_sse2 is the denoised result from SSE2 code. 63 DECLARE_ALIGNED(16, uint8_t, sig_block[kNumPixels]); 64 DECLARE_ALIGNED(16, uint8_t, mc_avg_block[kNumPixels]); 65 DECLARE_ALIGNED(16, uint8_t, avg_block_c[kNumPixels]); 66 DECLARE_ALIGNED(16, uint8_t, avg_block_sse2[kNumPixels]); 67 68 for (int i = 0; i < count_test_block; ++i) { 69 // Generate random motion magnitude, 20% of which exceed the threshold. 70 const int motion_magnitude_random = 71 rnd.Rand8() % static_cast<int>(MOTION_MAGNITUDE_THRESHOLD * 1.2); 72 73 // Initialize a test block with random number in range [0, 255]. 74 for (int j = 0; j < kNumPixels; ++j) { 75 int temp = 0; 76 sig_block[j] = rnd.Rand8(); 77 // The pixels in mc_avg_block are generated by adding a random 78 // number in range [-19, 19] to corresponding pixels in sig_block. 79 temp = 80 sig_block[j] + ((rnd.Rand8() % 2 == 0) ? -1 : 1) * (rnd.Rand8() % 20); 81 // Clip. 82 mc_avg_block[j] = (temp < 0) ? 0 : ((temp > 255) ? 255 : temp); 83 } 84 85 API_REGISTER_STATE_CHECK( 86 av1_denoiser_filter_c(sig_block, 128, mc_avg_block, 128, avg_block_c, 87 128, 0, bs_, motion_magnitude_random)); 88 89 API_REGISTER_STATE_CHECK(GET_PARAM(0)(sig_block, 128, mc_avg_block, 128, 90 avg_block_sse2, 128, 0, bs_, 91 motion_magnitude_random)); 92 93 // Test bitexactness. 94 for (int h = 0; h < block_size_high[bs_]; ++h) { 95 for (int w = 0; w < block_size_wide[bs_]; ++w) { 96 EXPECT_EQ(avg_block_c[h * 128 + w], avg_block_sse2[h * 128 + w]); 97 } 98 } 99 } 100 } 101 102 using std::make_tuple; 103 104 // Test for all block size. 105 #if HAVE_SSE2 106 INSTANTIATE_TEST_SUITE_P( 107 SSE2, AV1DenoiserTest, 108 ::testing::Values(make_tuple(&av1_denoiser_filter_sse2, BLOCK_8X8), 109 make_tuple(&av1_denoiser_filter_sse2, BLOCK_8X16), 110 make_tuple(&av1_denoiser_filter_sse2, BLOCK_16X8), 111 make_tuple(&av1_denoiser_filter_sse2, BLOCK_16X16), 112 make_tuple(&av1_denoiser_filter_sse2, BLOCK_16X32), 113 make_tuple(&av1_denoiser_filter_sse2, BLOCK_32X16), 114 make_tuple(&av1_denoiser_filter_sse2, BLOCK_32X32), 115 make_tuple(&av1_denoiser_filter_sse2, BLOCK_32X64), 116 make_tuple(&av1_denoiser_filter_sse2, BLOCK_64X32), 117 make_tuple(&av1_denoiser_filter_sse2, BLOCK_64X64), 118 make_tuple(&av1_denoiser_filter_sse2, BLOCK_128X64), 119 make_tuple(&av1_denoiser_filter_sse2, BLOCK_64X128), 120 make_tuple(&av1_denoiser_filter_sse2, BLOCK_128X128))); 121 #endif // HAVE_SSE2 122 123 #if HAVE_NEON 124 INSTANTIATE_TEST_SUITE_P( 125 NEON, AV1DenoiserTest, 126 ::testing::Values(make_tuple(&av1_denoiser_filter_neon, BLOCK_8X8), 127 make_tuple(&av1_denoiser_filter_neon, BLOCK_8X16), 128 make_tuple(&av1_denoiser_filter_neon, BLOCK_16X8), 129 make_tuple(&av1_denoiser_filter_neon, BLOCK_16X16), 130 make_tuple(&av1_denoiser_filter_neon, BLOCK_16X32), 131 make_tuple(&av1_denoiser_filter_neon, BLOCK_32X16), 132 make_tuple(&av1_denoiser_filter_neon, BLOCK_32X32), 133 make_tuple(&av1_denoiser_filter_neon, BLOCK_32X64), 134 make_tuple(&av1_denoiser_filter_neon, BLOCK_64X32), 135 make_tuple(&av1_denoiser_filter_neon, BLOCK_64X64), 136 make_tuple(&av1_denoiser_filter_neon, BLOCK_128X64), 137 make_tuple(&av1_denoiser_filter_neon, BLOCK_64X128), 138 make_tuple(&av1_denoiser_filter_neon, BLOCK_128X128))); 139 #endif 140 } // namespace