vp9_subtract_test.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (c) 2012 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 "third_party/googletest/src/include/gtest/gtest.h"
  11. #include "./vp9_rtcd.h"
  12. #include "./vpx_config.h"
  13. #include "./vpx_dsp_rtcd.h"
  14. #include "test/acm_random.h"
  15. #include "test/clear_system_state.h"
  16. #include "test/register_state_check.h"
  17. #include "vp9/common/vp9_blockd.h"
  18. #include "vpx_mem/vpx_mem.h"
  19. typedef void (*SubtractFunc)(int rows, int cols, int16_t *diff_ptr,
  20. ptrdiff_t diff_stride, const uint8_t *src_ptr,
  21. ptrdiff_t src_stride, const uint8_t *pred_ptr,
  22. ptrdiff_t pred_stride);
  23. namespace vp9 {
  24. class VP9SubtractBlockTest : public ::testing::TestWithParam<SubtractFunc> {
  25. public:
  26. virtual void TearDown() { libvpx_test::ClearSystemState(); }
  27. };
  28. using libvpx_test::ACMRandom;
  29. TEST_P(VP9SubtractBlockTest, SimpleSubtract) {
  30. ACMRandom rnd(ACMRandom::DeterministicSeed());
  31. // FIXME(rbultje) split in its own file
  32. for (BLOCK_SIZE bsize = BLOCK_4X4; bsize < BLOCK_SIZES;
  33. bsize = static_cast<BLOCK_SIZE>(static_cast<int>(bsize) + 1)) {
  34. const int block_width = 4 * num_4x4_blocks_wide_lookup[bsize];
  35. const int block_height = 4 * num_4x4_blocks_high_lookup[bsize];
  36. int16_t *diff = reinterpret_cast<int16_t *>(
  37. vpx_memalign(16, sizeof(*diff) * block_width * block_height * 2));
  38. uint8_t *pred = reinterpret_cast<uint8_t *>(
  39. vpx_memalign(16, block_width * block_height * 2));
  40. uint8_t *src = reinterpret_cast<uint8_t *>(
  41. vpx_memalign(16, block_width * block_height * 2));
  42. for (int n = 0; n < 100; n++) {
  43. for (int r = 0; r < block_height; ++r) {
  44. for (int c = 0; c < block_width * 2; ++c) {
  45. src[r * block_width * 2 + c] = rnd.Rand8();
  46. pred[r * block_width * 2 + c] = rnd.Rand8();
  47. }
  48. }
  49. GetParam()(block_height, block_width, diff, block_width, src, block_width,
  50. pred, block_width);
  51. for (int r = 0; r < block_height; ++r) {
  52. for (int c = 0; c < block_width; ++c) {
  53. EXPECT_EQ(diff[r * block_width + c],
  54. (src[r * block_width + c] - pred[r * block_width + c]))
  55. << "r = " << r << ", c = " << c << ", bs = " << bsize;
  56. }
  57. }
  58. GetParam()(block_height, block_width, diff, block_width * 2, src,
  59. block_width * 2, pred, block_width * 2);
  60. for (int r = 0; r < block_height; ++r) {
  61. for (int c = 0; c < block_width; ++c) {
  62. EXPECT_EQ(
  63. diff[r * block_width * 2 + c],
  64. (src[r * block_width * 2 + c] - pred[r * block_width * 2 + c]))
  65. << "r = " << r << ", c = " << c << ", bs = " << bsize;
  66. }
  67. }
  68. }
  69. vpx_free(diff);
  70. vpx_free(pred);
  71. vpx_free(src);
  72. }
  73. }
  74. INSTANTIATE_TEST_CASE_P(C, VP9SubtractBlockTest,
  75. ::testing::Values(vpx_subtract_block_c));
  76. #if HAVE_SSE2
  77. INSTANTIATE_TEST_CASE_P(SSE2, VP9SubtractBlockTest,
  78. ::testing::Values(vpx_subtract_block_sse2));
  79. #endif
  80. #if HAVE_NEON
  81. INSTANTIATE_TEST_CASE_P(NEON, VP9SubtractBlockTest,
  82. ::testing::Values(vpx_subtract_block_neon));
  83. #endif
  84. #if HAVE_MSA
  85. INSTANTIATE_TEST_CASE_P(MSA, VP9SubtractBlockTest,
  86. ::testing::Values(vpx_subtract_block_msa));
  87. #endif
  88. #if HAVE_MMI
  89. INSTANTIATE_TEST_CASE_P(MMI, VP9SubtractBlockTest,
  90. ::testing::Values(vpx_subtract_block_mmi));
  91. #endif
  92. } // namespace vp9