idct_test.cc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. ASSERT_TRUE(input->TopLeftPixel() != NULL);
  63. // When the first element is '4' it will fill the output buffer with '1'.
  64. input->TopLeftPixel()[0] = 4;
  65. predict->Set(0);
  66. output->Set(0);
  67. ASM_REGISTER_STATE_CHECK(UUT(input->TopLeftPixel(), predict->TopLeftPixel(),
  68. predict->stride(), output->TopLeftPixel(),
  69. output->stride()));
  70. ASSERT_TRUE(output->CheckValues(1));
  71. ASSERT_TRUE(output->CheckPadding());
  72. }
  73. TEST_P(IDCTTest, TestAddOne) {
  74. // Set the transform output to '1' and make sure it gets added to the
  75. // prediction buffer.
  76. input->Set(0);
  77. ASSERT_TRUE(input->TopLeftPixel() != NULL);
  78. input->TopLeftPixel()[0] = 4;
  79. output->Set(0);
  80. uint8_t *pred = predict->TopLeftPixel();
  81. for (int y = 0; y < 4; ++y) {
  82. for (int x = 0; x < 4; ++x) {
  83. pred[y * predict->stride() + x] = y * 4 + x;
  84. }
  85. }
  86. ASM_REGISTER_STATE_CHECK(UUT(input->TopLeftPixel(), predict->TopLeftPixel(),
  87. predict->stride(), output->TopLeftPixel(),
  88. output->stride()));
  89. uint8_t const *out = output->TopLeftPixel();
  90. for (int y = 0; y < 4; ++y) {
  91. for (int x = 0; x < 4; ++x) {
  92. EXPECT_EQ(1 + y * 4 + x, out[y * output->stride() + x]);
  93. }
  94. }
  95. if (HasFailure()) {
  96. output->DumpBuffer();
  97. }
  98. ASSERT_TRUE(output->CheckPadding());
  99. }
  100. TEST_P(IDCTTest, TestWithData) {
  101. // Test a single known input.
  102. predict->Set(0);
  103. int16_t *in = input->TopLeftPixel();
  104. for (int y = 0; y < 4; ++y) {
  105. for (int x = 0; x < 4; ++x) {
  106. in[y * input->stride() + x] = y * 4 + x;
  107. }
  108. }
  109. ASM_REGISTER_STATE_CHECK(UUT(input->TopLeftPixel(), predict->TopLeftPixel(),
  110. predict->stride(), output->TopLeftPixel(),
  111. output->stride()));
  112. uint8_t *out = output->TopLeftPixel();
  113. for (int y = 0; y < 4; ++y) {
  114. for (int x = 0; x < 4; ++x) {
  115. switch (y * 4 + x) {
  116. case 0: EXPECT_EQ(11, out[y * output->stride() + x]); break;
  117. case 2:
  118. case 5:
  119. case 8: EXPECT_EQ(3, out[y * output->stride() + x]); break;
  120. case 10: EXPECT_EQ(1, out[y * output->stride() + x]); break;
  121. default: EXPECT_EQ(0, out[y * output->stride() + x]);
  122. }
  123. }
  124. }
  125. if (HasFailure()) {
  126. output->DumpBuffer();
  127. }
  128. ASSERT_TRUE(output->CheckPadding());
  129. }
  130. INSTANTIATE_TEST_CASE_P(C, IDCTTest, ::testing::Values(vp8_short_idct4x4llm_c));
  131. #if HAVE_NEON
  132. INSTANTIATE_TEST_CASE_P(NEON, IDCTTest,
  133. ::testing::Values(vp8_short_idct4x4llm_neon));
  134. #endif // HAVE_NEON
  135. #if HAVE_MMX
  136. INSTANTIATE_TEST_CASE_P(MMX, IDCTTest,
  137. ::testing::Values(vp8_short_idct4x4llm_mmx));
  138. #endif // HAVE_MMX
  139. #if HAVE_MSA
  140. INSTANTIATE_TEST_CASE_P(MSA, IDCTTest,
  141. ::testing::Values(vp8_short_idct4x4llm_msa));
  142. #endif // HAVE_MSA
  143. #if HAVE_MMI
  144. INSTANTIATE_TEST_CASE_P(MMI, IDCTTest,
  145. ::testing::Values(vp8_short_idct4x4llm_mmi));
  146. #endif // HAVE_MMI
  147. } // namespace