vp9_denoiser_test.cc 5.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
 *  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#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"

#include "vpx_scale/yv12config.h"
#include "vpx/vpx_integer.h"
#include "vp9/common/vp9_reconinter.h"
#include "vp9/encoder/vp9_context_tree.h"
#include "vp9/encoder/vp9_denoiser.h"

using libvpx_test::ACMRandom;

namespace {

const int kNumPixels = 64 * 64;
32 33 34 35 36 37 38 39 40 41 42

typedef int (*Vp9DenoiserFilterFunc)(const uint8_t *sig, int sig_stride,
                                     const uint8_t *mc_avg, int mc_avg_stride,
                                     uint8_t *avg, int avg_stride,
                                     int increase_denoising, BLOCK_SIZE bs,
                                     int motion_magnitude);
typedef std::tr1::tuple<Vp9DenoiserFilterFunc, BLOCK_SIZE> VP9DenoiserTestParam;

class VP9DenoiserTest
    : public ::testing::Test,
      public ::testing::WithParamInterface<VP9DenoiserTestParam> {
43 44 45
 public:
  virtual ~VP9DenoiserTest() {}

46
  virtual void SetUp() { bs_ = GET_PARAM(1); }
47 48 49 50

  virtual void TearDown() { libvpx_test::ClearSystemState(); }

 protected:
51
  BLOCK_SIZE bs_;
52 53 54 55 56 57 58 59 60 61 62
};

TEST_P(VP9DenoiserTest, BitexactCheck) {
  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.
63 64 65 66
  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]);
67 68 69

  for (int i = 0; i < count_test_block; ++i) {
    // Generate random motion magnitude, 20% of which exceed the threshold.
70 71
    const int motion_magnitude_random =
        rnd.Rand8() % static_cast<int>(MOTION_MAGNITUDE_THRESHOLD * 1.2);
72 73 74 75 76 77 78

    // 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
79 80
      temp =
          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
    }

clang-format's avatar
clang-format committed
85 86 87
    ASM_REGISTER_STATE_CHECK(vp9_denoiser_filter_c(sig_block, 64, mc_avg_block,
                                                   64, avg_block_c, 64, 0, bs_,
                                                   motion_magnitude_random));
88

89 90 91
    ASM_REGISTER_STATE_CHECK(GET_PARAM(0)(sig_block, 64, mc_avg_block, 64,
                                          avg_block_sse2, 64, 0, bs_,
                                          motion_magnitude_random));
92 93

    // Test bitexactness.
94 95
    for (int h = 0; h < (4 << b_height_log2_lookup[bs_]); ++h) {
      for (int w = 0; w < (4 << b_width_log2_lookup[bs_]); ++w) {
96 97 98 99 100 101
        EXPECT_EQ(avg_block_c[h * 64 + w], avg_block_sse2[h * 64 + w]);
      }
    }
  }
}

102 103
using std::tr1::make_tuple;

104
// Test for all block size.
105 106 107 108 109 110 111 112 113 114 115 116 117 118
#if HAVE_SSE2
INSTANTIATE_TEST_CASE_P(
    SSE2, VP9DenoiserTest,
    ::testing::Values(make_tuple(&vp9_denoiser_filter_sse2, BLOCK_8X8),
                      make_tuple(&vp9_denoiser_filter_sse2, BLOCK_8X16),
                      make_tuple(&vp9_denoiser_filter_sse2, BLOCK_16X8),
                      make_tuple(&vp9_denoiser_filter_sse2, BLOCK_16X16),
                      make_tuple(&vp9_denoiser_filter_sse2, BLOCK_16X32),
                      make_tuple(&vp9_denoiser_filter_sse2, BLOCK_32X16),
                      make_tuple(&vp9_denoiser_filter_sse2, BLOCK_32X32),
                      make_tuple(&vp9_denoiser_filter_sse2, BLOCK_32X64),
                      make_tuple(&vp9_denoiser_filter_sse2, BLOCK_64X32),
                      make_tuple(&vp9_denoiser_filter_sse2, BLOCK_64X64)));
#endif  // HAVE_SSE2
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

#if HAVE_NEON
INSTANTIATE_TEST_CASE_P(
    NEON, VP9DenoiserTest,
    ::testing::Values(make_tuple(&vp9_denoiser_filter_neon, BLOCK_8X8),
                      make_tuple(&vp9_denoiser_filter_neon, BLOCK_8X16),
                      make_tuple(&vp9_denoiser_filter_neon, BLOCK_16X8),
                      make_tuple(&vp9_denoiser_filter_neon, BLOCK_16X16),
                      make_tuple(&vp9_denoiser_filter_neon, BLOCK_16X32),
                      make_tuple(&vp9_denoiser_filter_neon, BLOCK_32X16),
                      make_tuple(&vp9_denoiser_filter_neon, BLOCK_32X32),
                      make_tuple(&vp9_denoiser_filter_neon, BLOCK_32X64),
                      make_tuple(&vp9_denoiser_filter_neon, BLOCK_64X32),
                      make_tuple(&vp9_denoiser_filter_neon, BLOCK_64X64)));
#endif
134
}  // namespace