vp9_denoiser_test.cc 5.3 KB

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