vp9_denoiser_test.cc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. #include <math.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include "third_party/googletest/src/include/gtest/gtest.h"
  14. #include "test/acm_random.h"
  15. #include "test/clear_system_state.h"
  16. #include "test/register_state_check.h"
  17. #include "test/util.h"
  18. #include "vpx_scale/yv12config.h"
  19. #include "vpx/vpx_integer.h"
  20. #include "vp9/common/vp9_reconinter.h"
  21. #include "vp9/encoder/vp9_context_tree.h"
  22. #include "vp9/encoder/vp9_denoiser.h"
  23. using libvpx_test::ACMRandom;
  24. namespace {
  25. const int kNumPixels = 64 * 64;
  26. typedef int (*Vp9DenoiserFilterFunc)(const uint8_t *sig, int sig_stride,
  27. const uint8_t *mc_avg, int mc_avg_stride,
  28. uint8_t *avg, int avg_stride,
  29. int increase_denoising, BLOCK_SIZE bs,
  30. int motion_magnitude);
  31. typedef std::tr1::tuple<Vp9DenoiserFilterFunc, BLOCK_SIZE> VP9DenoiserTestParam;
  32. class VP9DenoiserTest
  33. : public ::testing::Test,
  34. public ::testing::WithParamInterface<VP9DenoiserTestParam> {
  35. public:
  36. virtual ~VP9DenoiserTest() {}
  37. virtual void SetUp() { bs_ = GET_PARAM(1); }
  38. virtual void TearDown() { libvpx_test::ClearSystemState(); }
  39. protected:
  40. BLOCK_SIZE bs_;
  41. };
  42. TEST_P(VP9DenoiserTest, BitexactCheck) {
  43. ACMRandom rnd(ACMRandom::DeterministicSeed());
  44. const int count_test_block = 4000;
  45. // Allocate the space for input and output,
  46. // where sig_block is the block to be denoised,
  47. // mc_avg_block is the denoised reference block,
  48. // avg_block_c is the denoised result from C code,
  49. // avg_block_sse2 is the denoised result from SSE2 code.
  50. DECLARE_ALIGNED(16, uint8_t, sig_block[kNumPixels]);
  51. DECLARE_ALIGNED(16, uint8_t, mc_avg_block[kNumPixels]);
  52. DECLARE_ALIGNED(16, uint8_t, avg_block_c[kNumPixels]);
  53. DECLARE_ALIGNED(16, uint8_t, avg_block_sse2[kNumPixels]);
  54. for (int i = 0; i < count_test_block; ++i) {
  55. // Generate random motion magnitude, 20% of which exceed the threshold.
  56. const int motion_magnitude_random =
  57. rnd.Rand8() % static_cast<int>(MOTION_MAGNITUDE_THRESHOLD * 1.2);
  58. // Initialize a test block with random number in range [0, 255].
  59. for (int j = 0; j < kNumPixels; ++j) {
  60. int temp = 0;
  61. sig_block[j] = rnd.Rand8();
  62. // The pixels in mc_avg_block are generated by adding a random
  63. // number in range [-19, 19] to corresponding pixels in sig_block.
  64. temp =
  65. sig_block[j] + ((rnd.Rand8() % 2 == 0) ? -1 : 1) * (rnd.Rand8() % 20);
  66. // Clip.
  67. mc_avg_block[j] = (temp < 0) ? 0 : ((temp > 255) ? 255 : temp);
  68. }
  69. ASM_REGISTER_STATE_CHECK(vp9_denoiser_filter_c(sig_block, 64, mc_avg_block,
  70. 64, avg_block_c, 64, 0, bs_,
  71. motion_magnitude_random));
  72. ASM_REGISTER_STATE_CHECK(GET_PARAM(0)(sig_block, 64, mc_avg_block, 64,
  73. avg_block_sse2, 64, 0, bs_,
  74. motion_magnitude_random));
  75. // Test bitexactness.
  76. for (int h = 0; h < (4 << b_height_log2_lookup[bs_]); ++h) {
  77. for (int w = 0; w < (4 << b_width_log2_lookup[bs_]); ++w) {
  78. EXPECT_EQ(avg_block_c[h * 64 + w], avg_block_sse2[h * 64 + w]);
  79. }
  80. }
  81. }
  82. }
  83. using std::tr1::make_tuple;
  84. // Test for all block size.
  85. #if HAVE_SSE2
  86. INSTANTIATE_TEST_CASE_P(
  87. SSE2, VP9DenoiserTest,
  88. ::testing::Values(make_tuple(&vp9_denoiser_filter_sse2, BLOCK_8X8),
  89. make_tuple(&vp9_denoiser_filter_sse2, BLOCK_8X16),
  90. make_tuple(&vp9_denoiser_filter_sse2, BLOCK_16X8),
  91. make_tuple(&vp9_denoiser_filter_sse2, BLOCK_16X16),
  92. make_tuple(&vp9_denoiser_filter_sse2, BLOCK_16X32),
  93. make_tuple(&vp9_denoiser_filter_sse2, BLOCK_32X16),
  94. make_tuple(&vp9_denoiser_filter_sse2, BLOCK_32X32),
  95. make_tuple(&vp9_denoiser_filter_sse2, BLOCK_32X64),
  96. make_tuple(&vp9_denoiser_filter_sse2, BLOCK_64X32),
  97. make_tuple(&vp9_denoiser_filter_sse2, BLOCK_64X64)));
  98. #endif // HAVE_SSE2
  99. #if HAVE_NEON
  100. INSTANTIATE_TEST_CASE_P(
  101. NEON, VP9DenoiserTest,
  102. ::testing::Values(make_tuple(&vp9_denoiser_filter_neon, BLOCK_8X8),
  103. make_tuple(&vp9_denoiser_filter_neon, BLOCK_8X16),
  104. make_tuple(&vp9_denoiser_filter_neon, BLOCK_16X8),
  105. make_tuple(&vp9_denoiser_filter_neon, BLOCK_16X16),
  106. make_tuple(&vp9_denoiser_filter_neon, BLOCK_16X32),
  107. make_tuple(&vp9_denoiser_filter_neon, BLOCK_32X16),
  108. make_tuple(&vp9_denoiser_filter_neon, BLOCK_32X32),
  109. make_tuple(&vp9_denoiser_filter_neon, BLOCK_32X64),
  110. make_tuple(&vp9_denoiser_filter_neon, BLOCK_64X32),
  111. make_tuple(&vp9_denoiser_filter_neon, BLOCK_64X64)));
  112. #endif
  113. } // namespace