vp8_denoiser_sse2_test.cc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 "vp8/encoder/denoising.h"
  19. #include "vp8/common/reconinter.h"
  20. #include "vpx/vpx_integer.h"
  21. #include "vpx_mem/vpx_mem.h"
  22. using libvpx_test::ACMRandom;
  23. namespace {
  24. const int kNumPixels = 16 * 16;
  25. class VP8DenoiserTest : public ::testing::TestWithParam<int> {
  26. public:
  27. virtual ~VP8DenoiserTest() {}
  28. virtual void SetUp() { increase_denoising_ = GetParam(); }
  29. virtual void TearDown() { libvpx_test::ClearSystemState(); }
  30. protected:
  31. int increase_denoising_;
  32. };
  33. TEST_P(VP8DenoiserTest, BitexactCheck) {
  34. ACMRandom rnd(ACMRandom::DeterministicSeed());
  35. const int count_test_block = 4000;
  36. const int stride = 16;
  37. // Allocate the space for input and output,
  38. // where sig_block_c/_sse2 is the block to be denoised,
  39. // mc_avg_block is the denoised reference block,
  40. // avg_block_c is the denoised result from C code,
  41. // avg_block_sse2 is the denoised result from SSE2 code.
  42. DECLARE_ALIGNED(16, uint8_t, sig_block_c[kNumPixels]);
  43. // Since in VP8 denoiser, the source signal will be changed,
  44. // we need another copy of the source signal as the input of sse2 code.
  45. DECLARE_ALIGNED(16, uint8_t, sig_block_sse2[kNumPixels]);
  46. DECLARE_ALIGNED(16, uint8_t, mc_avg_block[kNumPixels]);
  47. DECLARE_ALIGNED(16, uint8_t, avg_block_c[kNumPixels]);
  48. DECLARE_ALIGNED(16, uint8_t, avg_block_sse2[kNumPixels]);
  49. for (int i = 0; i < count_test_block; ++i) {
  50. // Generate random motion magnitude, 20% of which exceed the threshold.
  51. const int motion_magnitude_ran =
  52. rnd.Rand8() % static_cast<int>(MOTION_MAGNITUDE_THRESHOLD * 1.2);
  53. // Initialize a test block with random number in range [0, 255].
  54. for (int j = 0; j < kNumPixels; ++j) {
  55. int temp = 0;
  56. sig_block_sse2[j] = sig_block_c[j] = rnd.Rand8();
  57. // The pixels in mc_avg_block are generated by adding a random
  58. // number in range [-19, 19] to corresponding pixels in sig_block.
  59. temp =
  60. sig_block_c[j] + (rnd.Rand8() % 2 == 0 ? -1 : 1) * (rnd.Rand8() % 20);
  61. // Clip.
  62. mc_avg_block[j] = (temp < 0) ? 0 : ((temp > 255) ? 255 : temp);
  63. }
  64. // Test denosiser on Y component.
  65. ASM_REGISTER_STATE_CHECK(vp8_denoiser_filter_c(
  66. mc_avg_block, stride, avg_block_c, stride, sig_block_c, stride,
  67. motion_magnitude_ran, increase_denoising_));
  68. ASM_REGISTER_STATE_CHECK(vp8_denoiser_filter_sse2(
  69. mc_avg_block, stride, avg_block_sse2, stride, sig_block_sse2, stride,
  70. motion_magnitude_ran, increase_denoising_));
  71. // Check bitexactness.
  72. for (int h = 0; h < 16; ++h) {
  73. for (int w = 0; w < 16; ++w) {
  74. EXPECT_EQ(avg_block_c[h * stride + w], avg_block_sse2[h * stride + w]);
  75. }
  76. }
  77. // Test denoiser on UV component.
  78. ASM_REGISTER_STATE_CHECK(vp8_denoiser_filter_uv_c(
  79. mc_avg_block, stride, avg_block_c, stride, sig_block_c, stride,
  80. motion_magnitude_ran, increase_denoising_));
  81. ASM_REGISTER_STATE_CHECK(vp8_denoiser_filter_uv_sse2(
  82. mc_avg_block, stride, avg_block_sse2, stride, sig_block_sse2, stride,
  83. motion_magnitude_ran, increase_denoising_));
  84. // Check bitexactness.
  85. for (int h = 0; h < 16; ++h) {
  86. for (int w = 0; w < 16; ++w) {
  87. EXPECT_EQ(avg_block_c[h * stride + w], avg_block_sse2[h * stride + w]);
  88. }
  89. }
  90. }
  91. }
  92. // Test for all block size.
  93. INSTANTIATE_TEST_CASE_P(SSE2, VP8DenoiserTest, ::testing::Values(0, 1));
  94. } // namespace