vp9_scale_test.cc 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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(INTERP_FILTER filter_type) {
  41. static const int kNumSizesToTest = 20;
  42. static const int kNumScaleFactorsToTest = 4;
  43. static const int kSizesToTest[] = {
  44. 2, 4, 6, 8, 10, 12, 14, 16, 18, 20,
  45. 22, 24, 26, 28, 30, 32, 34, 68, 128, 134
  46. };
  47. static const int kScaleFactors[] = { 1, 2, 3, 4 };
  48. for (int phase_scaler = 0; phase_scaler < 16; ++phase_scaler) {
  49. for (int h = 0; h < kNumSizesToTest; ++h) {
  50. const int src_height = kSizesToTest[h];
  51. for (int w = 0; w < kNumSizesToTest; ++w) {
  52. const int src_width = kSizesToTest[w];
  53. for (int sf_up_idx = 0; sf_up_idx < kNumScaleFactorsToTest;
  54. ++sf_up_idx) {
  55. const int sf_up = kScaleFactors[sf_up_idx];
  56. for (int sf_down_idx = 0; sf_down_idx < kNumScaleFactorsToTest;
  57. ++sf_down_idx) {
  58. const int sf_down = kScaleFactors[sf_down_idx];
  59. const int dst_width = src_width * sf_up / sf_down;
  60. const int dst_height = src_height * sf_up / sf_down;
  61. if (sf_up == sf_down && sf_up != 1) {
  62. continue;
  63. }
  64. // I420 frame width and height must be even.
  65. if (!dst_width || !dst_height || dst_width & 1 ||
  66. dst_height & 1) {
  67. continue;
  68. }
  69. // vpx_convolve8_c() has restriction on the step which cannot
  70. // exceed 64 (ratio 1 to 4).
  71. if (src_width > 4 * dst_width || src_height > 4 * dst_height) {
  72. continue;
  73. }
  74. ASSERT_NO_FATAL_FAILURE(ResetScaleImages(src_width, src_height,
  75. dst_width, dst_height));
  76. ReferenceScaleFrame(filter_type, phase_scaler);
  77. ScaleFrame(filter_type, phase_scaler);
  78. if (memcmp(dst_img_.buffer_alloc, ref_img_.buffer_alloc,
  79. ref_img_.frame_size)) {
  80. printf(
  81. "filter_type = %d, phase_scaler = %d, src_width = %4d, "
  82. "src_height = %4d, dst_width = %4d, dst_height = %4d, "
  83. "scale factor = %d:%d\n",
  84. filter_type, phase_scaler, src_width, src_height, dst_width,
  85. dst_height, sf_down, sf_up);
  86. PrintDiff();
  87. }
  88. CompareImages(dst_img_);
  89. DeallocScaleImages();
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }
  96. void PrintDiffComponent(const uint8_t *const ref, const uint8_t *const opt,
  97. const int stride, const int width, const int height,
  98. const int plane_idx) const {
  99. for (int y = 0; y < height; y++) {
  100. for (int x = 0; x < width; x++) {
  101. if (ref[y * stride + x] != opt[y * stride + x]) {
  102. printf("Plane %d pixel[%d][%d] diff:%6d (ref),%6d (opt)\n", plane_idx,
  103. y, x, ref[y * stride + x], opt[y * stride + x]);
  104. break;
  105. }
  106. }
  107. }
  108. }
  109. void PrintDiff() const {
  110. assert(ref_img_.y_stride == dst_img_.y_stride);
  111. assert(ref_img_.y_width == dst_img_.y_width);
  112. assert(ref_img_.y_height == dst_img_.y_height);
  113. assert(ref_img_.uv_stride == dst_img_.uv_stride);
  114. assert(ref_img_.uv_width == dst_img_.uv_width);
  115. assert(ref_img_.uv_height == dst_img_.uv_height);
  116. if (memcmp(dst_img_.buffer_alloc, ref_img_.buffer_alloc,
  117. ref_img_.frame_size)) {
  118. PrintDiffComponent(ref_img_.y_buffer, dst_img_.y_buffer,
  119. ref_img_.y_stride, ref_img_.y_width, ref_img_.y_height,
  120. 0);
  121. PrintDiffComponent(ref_img_.u_buffer, dst_img_.u_buffer,
  122. ref_img_.uv_stride, ref_img_.uv_width,
  123. ref_img_.uv_height, 1);
  124. PrintDiffComponent(ref_img_.v_buffer, dst_img_.v_buffer,
  125. ref_img_.uv_stride, ref_img_.uv_width,
  126. ref_img_.uv_height, 2);
  127. }
  128. }
  129. ScaleFrameFunc scale_fn_;
  130. };
  131. TEST_P(ScaleTest, ScaleFrame_EightTap) { RunTest(EIGHTTAP); }
  132. TEST_P(ScaleTest, ScaleFrame_EightTapSmooth) { RunTest(EIGHTTAP_SMOOTH); }
  133. TEST_P(ScaleTest, ScaleFrame_EightTapSharp) { RunTest(EIGHTTAP_SHARP); }
  134. TEST_P(ScaleTest, ScaleFrame_Bilinear) { RunTest(BILINEAR); }
  135. TEST_P(ScaleTest, DISABLED_Speed) {
  136. static const int kCountSpeedTestBlock = 100;
  137. static const int kNumScaleFactorsToTest = 4;
  138. static const int kScaleFactors[] = { 1, 2, 3, 4 };
  139. const int src_width = 1280;
  140. const int src_height = 720;
  141. for (INTERP_FILTER filter_type = 2; filter_type < 4; ++filter_type) {
  142. for (int phase_scaler = 0; phase_scaler < 2; ++phase_scaler) {
  143. for (int sf_up_idx = 0; sf_up_idx < kNumScaleFactorsToTest; ++sf_up_idx) {
  144. const int sf_up = kScaleFactors[sf_up_idx];
  145. for (int sf_down_idx = 0; sf_down_idx < kNumScaleFactorsToTest;
  146. ++sf_down_idx) {
  147. const int sf_down = kScaleFactors[sf_down_idx];
  148. const int dst_width = src_width * sf_up / sf_down;
  149. const int dst_height = src_height * sf_up / sf_down;
  150. if (sf_up == sf_down && sf_up != 1) {
  151. continue;
  152. }
  153. // I420 frame width and height must be even.
  154. if (dst_width & 1 || dst_height & 1) {
  155. continue;
  156. }
  157. ASSERT_NO_FATAL_FAILURE(
  158. ResetScaleImages(src_width, src_height, dst_width, dst_height));
  159. ASM_REGISTER_STATE_CHECK(
  160. ReferenceScaleFrame(filter_type, phase_scaler));
  161. vpx_usec_timer timer;
  162. vpx_usec_timer_start(&timer);
  163. for (int i = 0; i < kCountSpeedTestBlock; ++i) {
  164. ScaleFrame(filter_type, phase_scaler);
  165. }
  166. libvpx_test::ClearSystemState();
  167. vpx_usec_timer_mark(&timer);
  168. const int elapsed_time =
  169. static_cast<int>(vpx_usec_timer_elapsed(&timer) / 1000);
  170. CompareImages(dst_img_);
  171. DeallocScaleImages();
  172. printf(
  173. "filter_type = %d, phase_scaler = %d, src_width = %4d, "
  174. "src_height = %4d, dst_width = %4d, dst_height = %4d, "
  175. "scale factor = %d:%d, scale time: %5d ms\n",
  176. filter_type, phase_scaler, src_width, src_height, dst_width,
  177. dst_height, sf_down, sf_up, elapsed_time);
  178. }
  179. }
  180. }
  181. }
  182. }
  183. INSTANTIATE_TEST_CASE_P(C, ScaleTest,
  184. ::testing::Values(vp9_scale_and_extend_frame_c));
  185. #if HAVE_SSSE3
  186. INSTANTIATE_TEST_CASE_P(SSSE3, ScaleTest,
  187. ::testing::Values(vp9_scale_and_extend_frame_ssse3));
  188. #endif // HAVE_SSSE3
  189. #if HAVE_NEON
  190. INSTANTIATE_TEST_CASE_P(NEON, ScaleTest,
  191. ::testing::Values(vp9_scale_and_extend_frame_neon));
  192. #endif // HAVE_NEON
  193. } // namespace libvpx_test