vp9_scale_test.cc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Copyright (c) 2017 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 <assert.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include "third_party/googletest/src/include/gtest/gtest.h"
  14. #include "./vp9_rtcd.h"
  15. #include "./vpx_config.h"
  16. #include "./vpx_scale_rtcd.h"
  17. #include "test/clear_system_state.h"
  18. #include "test/register_state_check.h"
  19. #include "test/vpx_scale_test.h"
  20. #include "vpx_mem/vpx_mem.h"
  21. #include "vpx_ports/vpx_timer.h"
  22. #include "vpx_scale/yv12config.h"
  23. namespace libvpx_test {
  24. typedef void (*ScaleFrameFunc)(const YV12_BUFFER_CONFIG *src,
  25. YV12_BUFFER_CONFIG *dst,
  26. INTERP_FILTER filter_type, int phase_scaler);
  27. class ScaleTest : public VpxScaleBase,
  28. public ::testing::TestWithParam<ScaleFrameFunc> {
  29. public:
  30. virtual ~ScaleTest() {}
  31. protected:
  32. virtual void SetUp() { scale_fn_ = GetParam(); }
  33. void ReferenceScaleFrame(INTERP_FILTER filter_type, int phase_scaler) {
  34. vp9_scale_and_extend_frame_c(&img_, &ref_img_, filter_type, phase_scaler);
  35. }
  36. void ScaleFrame(INTERP_FILTER filter_type, int phase_scaler) {
  37. ASM_REGISTER_STATE_CHECK(
  38. scale_fn_(&img_, &dst_img_, filter_type, phase_scaler));
  39. }
  40. void RunTest() {
  41. static const int kNumSizesToTest = 4;
  42. static const int kNumScaleFactorsToTest = 4;
  43. static const int kWidthsToTest[] = { 16, 32, 48, 64 };
  44. static const int kHeightsToTest[] = { 16, 20, 24, 28 };
  45. static const int kScaleFactors[] = { 1, 2, 3, 4 };
  46. for (INTERP_FILTER filter_type = 0; filter_type < 4; ++filter_type) {
  47. for (int phase_scaler = 0; phase_scaler < 16; ++phase_scaler) {
  48. for (int h = 0; h < kNumSizesToTest; ++h) {
  49. const int src_height = kHeightsToTest[h];
  50. for (int w = 0; w < kNumSizesToTest; ++w) {
  51. const int src_width = kWidthsToTest[w];
  52. for (int sf_up_idx = 0; sf_up_idx < kNumScaleFactorsToTest;
  53. ++sf_up_idx) {
  54. const int sf_up = kScaleFactors[sf_up_idx];
  55. for (int sf_down_idx = 0; sf_down_idx < kNumScaleFactorsToTest;
  56. ++sf_down_idx) {
  57. const int sf_down = kScaleFactors[sf_down_idx];
  58. const int dst_width = src_width * sf_up / sf_down;
  59. const int dst_height = src_height * sf_up / sf_down;
  60. if (sf_up == sf_down && sf_up != 1) {
  61. continue;
  62. }
  63. // I420 frame width and height must be even.
  64. if (dst_width & 1 || dst_height & 1) {
  65. continue;
  66. }
  67. ASSERT_NO_FATAL_FAILURE(ResetScaleImages(
  68. src_width, src_height, dst_width, dst_height));
  69. ReferenceScaleFrame(filter_type, phase_scaler);
  70. ScaleFrame(filter_type, phase_scaler);
  71. if (memcmp(dst_img_.buffer_alloc, ref_img_.buffer_alloc,
  72. ref_img_.frame_size)) {
  73. printf(
  74. "filter_type = %d, phase_scaler = %d, src_width = %4d, "
  75. "src_height = %4d, dst_width = %4d, dst_height = %4d, "
  76. "scale factor = %d:%d\n",
  77. filter_type, phase_scaler, src_width, src_height,
  78. dst_width, dst_height, sf_down, sf_up);
  79. PrintDiff();
  80. }
  81. CompareImages(dst_img_);
  82. DeallocScaleImages();
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89. }
  90. void PrintDiffComponent(const uint8_t *const ref, const uint8_t *const opt,
  91. const int stride, const int width, const int height,
  92. const int plane_idx) const {
  93. for (int y = 0; y < height; y++) {
  94. for (int x = 0; x < width; x++) {
  95. if (ref[y * stride + x] != opt[y * stride + x]) {
  96. printf("Plane %d pixel[%d][%d] diff:%6d (ref),%6d (opt)\n", plane_idx,
  97. y, x, ref[y * stride + x], opt[y * stride + x]);
  98. break;
  99. }
  100. }
  101. }
  102. }
  103. void PrintDiff() const {
  104. assert(ref_img_.y_stride == dst_img_.y_stride);
  105. assert(ref_img_.y_width == dst_img_.y_width);
  106. assert(ref_img_.y_height == dst_img_.y_height);
  107. assert(ref_img_.uv_stride == dst_img_.uv_stride);
  108. assert(ref_img_.uv_width == dst_img_.uv_width);
  109. assert(ref_img_.uv_height == dst_img_.uv_height);
  110. if (memcmp(dst_img_.buffer_alloc, ref_img_.buffer_alloc,
  111. ref_img_.frame_size)) {
  112. PrintDiffComponent(ref_img_.y_buffer, dst_img_.y_buffer,
  113. ref_img_.y_stride, ref_img_.y_width, ref_img_.y_height,
  114. 0);
  115. PrintDiffComponent(ref_img_.u_buffer, dst_img_.u_buffer,
  116. ref_img_.uv_stride, ref_img_.uv_width,
  117. ref_img_.uv_height, 1);
  118. PrintDiffComponent(ref_img_.v_buffer, dst_img_.v_buffer,
  119. ref_img_.uv_stride, ref_img_.uv_width,
  120. ref_img_.uv_height, 2);
  121. }
  122. }
  123. ScaleFrameFunc scale_fn_;
  124. };
  125. TEST_P(ScaleTest, ScaleFrame) { ASSERT_NO_FATAL_FAILURE(RunTest()); }
  126. TEST_P(ScaleTest, DISABLED_Speed) {
  127. static const int kCountSpeedTestBlock = 100;
  128. static const int kNumScaleFactorsToTest = 4;
  129. static const int kScaleFactors[] = { 1, 2, 3, 4 };
  130. const int src_width = 1280;
  131. const int src_height = 720;
  132. for (INTERP_FILTER filter_type = 2; filter_type < 4; ++filter_type) {
  133. for (int phase_scaler = 0; phase_scaler < 2; ++phase_scaler) {
  134. for (int sf_up_idx = 0; sf_up_idx < kNumScaleFactorsToTest; ++sf_up_idx) {
  135. const int sf_up = kScaleFactors[sf_up_idx];
  136. for (int sf_down_idx = 0; sf_down_idx < kNumScaleFactorsToTest;
  137. ++sf_down_idx) {
  138. const int sf_down = kScaleFactors[sf_down_idx];
  139. const int dst_width = src_width * sf_up / sf_down;
  140. const int dst_height = src_height * sf_up / sf_down;
  141. if (sf_up == sf_down && sf_up != 1) {
  142. continue;
  143. }
  144. // I420 frame width and height must be even.
  145. if (dst_width & 1 || dst_height & 1) {
  146. continue;
  147. }
  148. ASSERT_NO_FATAL_FAILURE(
  149. ResetScaleImages(src_width, src_height, dst_width, dst_height));
  150. ASM_REGISTER_STATE_CHECK(
  151. ReferenceScaleFrame(filter_type, phase_scaler));
  152. vpx_usec_timer timer;
  153. vpx_usec_timer_start(&timer);
  154. for (int i = 0; i < kCountSpeedTestBlock; ++i) {
  155. ScaleFrame(filter_type, phase_scaler);
  156. }
  157. libvpx_test::ClearSystemState();
  158. vpx_usec_timer_mark(&timer);
  159. const int elapsed_time =
  160. static_cast<int>(vpx_usec_timer_elapsed(&timer) / 1000);
  161. CompareImages(dst_img_);
  162. DeallocScaleImages();
  163. printf(
  164. "filter_type = %d, phase_scaler = %d, src_width = %4d, "
  165. "src_height = %4d, dst_width = %4d, dst_height = %4d, "
  166. "scale factor = %d:%d, scale time: %5d ms\n",
  167. filter_type, phase_scaler, src_width, src_height, dst_width,
  168. dst_height, sf_down, sf_up, elapsed_time);
  169. }
  170. }
  171. }
  172. }
  173. }
  174. INSTANTIATE_TEST_CASE_P(C, ScaleTest,
  175. ::testing::Values(vp9_scale_and_extend_frame_c));
  176. #if HAVE_SSSE3
  177. INSTANTIATE_TEST_CASE_P(SSSE3, ScaleTest,
  178. ::testing::Values(vp9_scale_and_extend_frame_ssse3));
  179. #endif // HAVE_SSSE3
  180. #if HAVE_NEON
  181. INSTANTIATE_TEST_CASE_P(NEON, ScaleTest,
  182. ::testing::Values(vp9_scale_and_extend_frame_neon));
  183. #endif // HAVE_NEON
  184. } // namespace libvpx_test