denoiser_sse2_test.cc 3.65 KB
Newer Older
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3
 *
4 5 6 7 8 9 10 11
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/

12 13 14 15 16 17 18 19 20 21 22

#include <math.h>
#include <stdlib.h>
#include <string.h>

#include "third_party/googletest/src/include/gtest/gtest.h"
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"

Yaowu Xu's avatar
Yaowu Xu committed
23
#include "aom_scale/yv12config.h"
Adrian Grange's avatar
Adrian Grange committed
24
#include "aom/aom_integer.h"
Yaowu Xu's avatar
Yaowu Xu committed
25 26 27
#include "av1/common/reconinter.h"
#include "av1/encoder/context_tree.h"
#include "av1/encoder/denoiser.h"
28

Yaowu Xu's avatar
Yaowu Xu committed
29
using libaom_test::ACMRandom;
30 31 32 33

namespace {

const int kNumPixels = 64 * 64;
Adrian Grange's avatar
Adrian Grange committed
34
class AV1DenoiserTest : public ::testing::TestWithParam<BLOCK_SIZE> {
35
 public:
Adrian Grange's avatar
Adrian Grange committed
36
  virtual ~AV1DenoiserTest() {}
37

clang-format's avatar
clang-format committed
38
  virtual void SetUp() { bs_ = GetParam(); }
39

Yaowu Xu's avatar
Yaowu Xu committed
40
  virtual void TearDown() { libaom_test::ClearSystemState(); }
41 42

 protected:
43
  BLOCK_SIZE bs_;
44 45
};

Adrian Grange's avatar
Adrian Grange committed
46
TEST_P(AV1DenoiserTest, BitexactCheck) {
47 48 49 50 51 52 53 54
  ACMRandom rnd(ACMRandom::DeterministicSeed());
  const int count_test_block = 4000;

  // Allocate the space for input and output,
  // where sig_block is the block to be denoised,
  // mc_avg_block is the denoised reference block,
  // avg_block_c is the denoised result from C code,
  // avg_block_sse2 is the denoised result from SSE2 code.
55 56 57 58
  DECLARE_ALIGNED(16, uint8_t, sig_block[kNumPixels]);
  DECLARE_ALIGNED(16, uint8_t, mc_avg_block[kNumPixels]);
  DECLARE_ALIGNED(16, uint8_t, avg_block_c[kNumPixels]);
  DECLARE_ALIGNED(16, uint8_t, avg_block_sse2[kNumPixels]);
59 60 61

  for (int i = 0; i < count_test_block; ++i) {
    // Generate random motion magnitude, 20% of which exceed the threshold.
62 63
    const int motion_magnitude_random =
        rnd.Rand8() % static_cast<int>(MOTION_MAGNITUDE_THRESHOLD * 1.2);
64 65 66 67 68 69 70

    // Initialize a test block with random number in range [0, 255].
    for (int j = 0; j < kNumPixels; ++j) {
      int temp = 0;
      sig_block[j] = rnd.Rand8();
      // The pixels in mc_avg_block are generated by adding a random
      // number in range [-19, 19] to corresponding pixels in sig_block.
clang-format's avatar
clang-format committed
71 72
      temp =
          sig_block[j] + ((rnd.Rand8() % 2 == 0) ? -1 : 1) * (rnd.Rand8() % 20);
73
      // Clip.
74
      mc_avg_block[j] = (temp < 0) ? 0 : ((temp > 255) ? 255 : temp);
75 76
    }

Adrian Grange's avatar
Adrian Grange committed
77
    ASM_REGISTER_STATE_CHECK(av1_denoiser_filter_c(sig_block, 64, mc_avg_block,
clang-format's avatar
clang-format committed
78 79
                                                   64, avg_block_c, 64, 0, bs_,
                                                   motion_magnitude_random));
80

Adrian Grange's avatar
Adrian Grange committed
81
    ASM_REGISTER_STATE_CHECK(av1_denoiser_filter_sse2(
clang-format's avatar
clang-format committed
82 83
        sig_block, 64, mc_avg_block, 64, avg_block_sse2, 64, 0, bs_,
        motion_magnitude_random));
84 85

    // Test bitexactness.
86 87
    for (int h = 0; h < (4 << b_height_log2_lookup[bs_]); ++h) {
      for (int w = 0; w < (4 << b_width_log2_lookup[bs_]); ++w) {
88 89 90 91 92 93 94
        EXPECT_EQ(avg_block_c[h * 64 + w], avg_block_sse2[h * 64 + w]);
      }
    }
  }
}

// Test for all block size.
Adrian Grange's avatar
Adrian Grange committed
95
INSTANTIATE_TEST_CASE_P(SSE2, AV1DenoiserTest,
clang-format's avatar
clang-format committed
96 97 98 99 100
                        ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
                                          BLOCK_8X8, BLOCK_8X16, BLOCK_16X8,
                                          BLOCK_16X16, BLOCK_16X32, BLOCK_32X16,
                                          BLOCK_32X32, BLOCK_32X64, BLOCK_64X32,
                                          BLOCK_64X64));
101
}  // namespace