idct_test.cc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright (c) 2010 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 "./vpx_config.h"
  11. #include "./vp8_rtcd.h"
  12. #include "third_party/googletest/src/include/gtest/gtest.h"
  13. #include "test/buffer.h"
  14. #include "test/clear_system_state.h"
  15. #include "test/register_state_check.h"
  16. #include "vpx/vpx_integer.h"
  17. typedef void (*IdctFunc)(int16_t *input, unsigned char *pred_ptr,
  18. int pred_stride, unsigned char *dst_ptr,
  19. int dst_stride);
  20. namespace {
  21. using libvpx_test::Buffer;
  22. class IDCTTest : public ::testing::TestWithParam<IdctFunc> {
  23. protected:
  24. virtual void SetUp() {
  25. UUT = GetParam();
  26. input = new Buffer<int16_t>(4, 4, 0);
  27. ASSERT_TRUE(input != NULL);
  28. ASSERT_TRUE(input->Init());
  29. predict = new Buffer<uint8_t>(4, 4, 3);
  30. ASSERT_TRUE(predict != NULL);
  31. ASSERT_TRUE(predict->Init());
  32. output = new Buffer<uint8_t>(4, 4, 3);
  33. ASSERT_TRUE(output != NULL);
  34. ASSERT_TRUE(output->Init());
  35. }
  36. virtual void TearDown() {
  37. delete input;
  38. delete predict;
  39. delete output;
  40. libvpx_test::ClearSystemState();
  41. }
  42. IdctFunc UUT;
  43. Buffer<int16_t> *input;
  44. Buffer<uint8_t> *predict;
  45. Buffer<uint8_t> *output;
  46. };
  47. TEST_P(IDCTTest, TestAllZeros) {
  48. // When the input is '0' the output will be '0'.
  49. input->Set(0);
  50. predict->Set(0);
  51. output->Set(0);
  52. ASM_REGISTER_STATE_CHECK(UUT(input->TopLeftPixel(), predict->TopLeftPixel(),
  53. predict->stride(), output->TopLeftPixel(),
  54. output->stride()));
  55. ASSERT_TRUE(input->CheckValues(0));
  56. ASSERT_TRUE(input->CheckPadding());
  57. ASSERT_TRUE(output->CheckValues(0));
  58. ASSERT_TRUE(output->CheckPadding());
  59. }
  60. TEST_P(IDCTTest, TestAllOnes) {
  61. input->Set(0);
  62. // When the first element is '4' it will fill the output buffer with '1'.
  63. input->TopLeftPixel()[0] = 4;
  64. predict->Set(0);
  65. output->Set(0);
  66. ASM_REGISTER_STATE_CHECK(UUT(input->TopLeftPixel(), predict->TopLeftPixel(),
  67. predict->stride(), output->TopLeftPixel(),
  68. output->stride()));
  69. ASSERT_TRUE(output->CheckValues(1));
  70. ASSERT_TRUE(output->CheckPadding());
  71. }
  72. TEST_P(IDCTTest, TestAddOne) {
  73. // Set the transform output to '1' and make sure it gets added to the
  74. // prediction buffer.
  75. input->Set(0);
  76. input->TopLeftPixel()[0] = 4;
  77. output->Set(0);
  78. uint8_t *pred = predict->TopLeftPixel();
  79. for (int y = 0; y < 4; ++y) {
  80. for (int x = 0; x < 4; ++x) {
  81. pred[y * predict->stride() + x] = y * 4 + x;
  82. }
  83. }
  84. ASM_REGISTER_STATE_CHECK(UUT(input->TopLeftPixel(), predict->TopLeftPixel(),
  85. predict->stride(), output->TopLeftPixel(),
  86. output->stride()));
  87. uint8_t const *out = output->TopLeftPixel();
  88. for (int y = 0; y < 4; ++y) {
  89. for (int x = 0; x < 4; ++x) {
  90. EXPECT_EQ(1 + y * 4 + x, out[y * output->stride() + x]);
  91. }
  92. }
  93. if (HasFailure()) {
  94. output->DumpBuffer();
  95. }
  96. ASSERT_TRUE(output->CheckPadding());
  97. }
  98. TEST_P(IDCTTest, TestWithData) {
  99. // Test a single known input.
  100. predict->Set(0);
  101. int16_t *in = input->TopLeftPixel();
  102. for (int y = 0; y < 4; ++y) {
  103. for (int x = 0; x < 4; ++x) {
  104. in[y * input->stride() + x] = y * 4 + x;
  105. }
  106. }
  107. ASM_REGISTER_STATE_CHECK(UUT(input->TopLeftPixel(), predict->TopLeftPixel(),
  108. predict->stride(), output->TopLeftPixel(),
  109. output->stride()));
  110. uint8_t *out = output->TopLeftPixel();
  111. for (int y = 0; y < 4; ++y) {
  112. for (int x = 0; x < 4; ++x) {
  113. switch (y * 4 + x) {
  114. case 0: EXPECT_EQ(11, out[y * output->stride() + x]); break;
  115. case 2:
  116. case 5:
  117. case 8: EXPECT_EQ(3, out[y * output->stride() + x]); break;
  118. case 10: EXPECT_EQ(1, out[y * output->stride() + x]); break;
  119. default: EXPECT_EQ(0, out[y * output->stride() + x]);
  120. }
  121. }
  122. }
  123. if (HasFailure()) {
  124. output->DumpBuffer();
  125. }
  126. ASSERT_TRUE(output->CheckPadding());
  127. }
  128. INSTANTIATE_TEST_CASE_P(C, IDCTTest, ::testing::Values(vp8_short_idct4x4llm_c));
  129. #if HAVE_NEON
  130. INSTANTIATE_TEST_CASE_P(NEON, IDCTTest,
  131. ::testing::Values(vp8_short_idct4x4llm_neon));
  132. #endif // HAVE_NEON
  133. #if HAVE_MMX
  134. INSTANTIATE_TEST_CASE_P(MMX, IDCTTest,
  135. ::testing::Values(vp8_short_idct4x4llm_mmx));
  136. #endif // HAVE_MMX
  137. #if HAVE_MSA
  138. INSTANTIATE_TEST_CASE_P(MSA, IDCTTest,
  139. ::testing::Values(vp8_short_idct4x4llm_msa));
  140. #endif // HAVE_MSA
  141. #if HAVE_MMI
  142. INSTANTIATE_TEST_CASE_P(MMI, IDCTTest,
  143. ::testing::Values(vp8_short_idct4x4llm_mmi));
  144. #endif // HAVE_MMI
  145. }