2 * Copyright (c) 2017 The WebM project authors. All Rights Reserved.
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.
15 #include "third_party/googletest/src/include/gtest/gtest.h"
17 #include "./vp9_rtcd.h"
18 #include "./vpx_config.h"
19 #include "./vpx_scale_rtcd.h"
20 #include "test/clear_system_state.h"
21 #include "test/register_state_check.h"
22 #include "test/vpx_scale_test.h"
23 #include "vpx_mem/vpx_mem.h"
24 #include "vpx_ports/vpx_timer.h"
25 #include "vpx_scale/yv12config.h"
27 namespace libvpx_test {
29 typedef void (*ScaleFrameFunc)(const YV12_BUFFER_CONFIG *src,
30 YV12_BUFFER_CONFIG *dst,
31 INTERP_FILTER filter_type, int phase_scaler);
33 class ScaleTest : public VpxScaleBase,
34 public ::testing::TestWithParam<ScaleFrameFunc> {
36 virtual ~ScaleTest() {}
39 virtual void SetUp() { scale_fn_ = GetParam(); }
41 void ReferenceScaleFrame(INTERP_FILTER filter_type, int phase_scaler) {
42 vp9_scale_and_extend_frame_c(&img_, &ref_img_, filter_type, phase_scaler);
45 void ScaleFrame(INTERP_FILTER filter_type, int phase_scaler) {
46 ASM_REGISTER_STATE_CHECK(
47 scale_fn_(&img_, &dst_img_, filter_type, phase_scaler));
50 void RunTest(INTERP_FILTER filter_type) {
51 static const int kNumSizesToTest = 20;
52 static const int kNumScaleFactorsToTest = 4;
53 static const int kSizesToTest[] = {
54 2, 4, 6, 8, 10, 12, 14, 16, 18, 20,
55 22, 24, 26, 28, 30, 32, 34, 68, 128, 134
57 static const int kScaleFactors[] = { 1, 2, 3, 4 };
58 for (int phase_scaler = 0; phase_scaler < 16; ++phase_scaler) {
59 for (int h = 0; h < kNumSizesToTest; ++h) {
60 const int src_height = kSizesToTest[h];
61 for (int w = 0; w < kNumSizesToTest; ++w) {
62 const int src_width = kSizesToTest[w];
63 for (int sf_up_idx = 0; sf_up_idx < kNumScaleFactorsToTest;
65 const int sf_up = kScaleFactors[sf_up_idx];
66 for (int sf_down_idx = 0; sf_down_idx < kNumScaleFactorsToTest;
68 const int sf_down = kScaleFactors[sf_down_idx];
69 const int dst_width = src_width * sf_up / sf_down;
70 const int dst_height = src_height * sf_up / sf_down;
71 if (sf_up == sf_down && sf_up != 1) {
74 // I420 frame width and height must be even.
75 if (!dst_width || !dst_height || dst_width & 1 ||
79 // vpx_convolve8_c() has restriction on the step which cannot
80 // exceed 64 (ratio 1 to 4).
81 if (src_width > 4 * dst_width || src_height > 4 * dst_height) {
84 ASSERT_NO_FATAL_FAILURE(ResetScaleImages(src_width, src_height,
85 dst_width, dst_height));
86 ReferenceScaleFrame(filter_type, phase_scaler);
87 ScaleFrame(filter_type, phase_scaler);
88 if (memcmp(dst_img_.buffer_alloc, ref_img_.buffer_alloc,
89 ref_img_.frame_size)) {
91 "filter_type = %d, phase_scaler = %d, src_width = %4d, "
92 "src_height = %4d, dst_width = %4d, dst_height = %4d, "
93 "scale factor = %d:%d\n",
94 filter_type, phase_scaler, src_width, src_height, dst_width,
95 dst_height, sf_down, sf_up);
98 CompareImages(dst_img_);
107 void PrintDiffComponent(const uint8_t *const ref, const uint8_t *const opt,
108 const int stride, const int width, const int height,
109 const int plane_idx) const {
110 for (int y = 0; y < height; y++) {
111 for (int x = 0; x < width; x++) {
112 if (ref[y * stride + x] != opt[y * stride + x]) {
113 printf("Plane %d pixel[%d][%d] diff:%6d (ref),%6d (opt)\n", plane_idx,
114 y, x, ref[y * stride + x], opt[y * stride + x]);
121 void PrintDiff() const {
122 assert(ref_img_.y_stride == dst_img_.y_stride);
123 assert(ref_img_.y_width == dst_img_.y_width);
124 assert(ref_img_.y_height == dst_img_.y_height);
125 assert(ref_img_.uv_stride == dst_img_.uv_stride);
126 assert(ref_img_.uv_width == dst_img_.uv_width);
127 assert(ref_img_.uv_height == dst_img_.uv_height);
129 if (memcmp(dst_img_.buffer_alloc, ref_img_.buffer_alloc,
130 ref_img_.frame_size)) {
131 PrintDiffComponent(ref_img_.y_buffer, dst_img_.y_buffer,
132 ref_img_.y_stride, ref_img_.y_width, ref_img_.y_height,
134 PrintDiffComponent(ref_img_.u_buffer, dst_img_.u_buffer,
135 ref_img_.uv_stride, ref_img_.uv_width,
136 ref_img_.uv_height, 1);
137 PrintDiffComponent(ref_img_.v_buffer, dst_img_.v_buffer,
138 ref_img_.uv_stride, ref_img_.uv_width,
139 ref_img_.uv_height, 2);
143 ScaleFrameFunc scale_fn_;
146 TEST_P(ScaleTest, ScaleFrame_EightTap) { RunTest(EIGHTTAP); }
147 TEST_P(ScaleTest, ScaleFrame_EightTapSmooth) { RunTest(EIGHTTAP_SMOOTH); }
148 TEST_P(ScaleTest, ScaleFrame_EightTapSharp) { RunTest(EIGHTTAP_SHARP); }
149 TEST_P(ScaleTest, ScaleFrame_Bilinear) { RunTest(BILINEAR); }
151 TEST_P(ScaleTest, DISABLED_Speed) {
152 static const int kCountSpeedTestBlock = 100;
153 static const int kNumScaleFactorsToTest = 4;
154 static const int kScaleFactors[] = { 1, 2, 3, 4 };
155 const int src_width = 1280;
156 const int src_height = 720;
157 for (INTERP_FILTER filter_type = 2; filter_type < 4; ++filter_type) {
158 for (int phase_scaler = 0; phase_scaler < 2; ++phase_scaler) {
159 for (int sf_up_idx = 0; sf_up_idx < kNumScaleFactorsToTest; ++sf_up_idx) {
160 const int sf_up = kScaleFactors[sf_up_idx];
161 for (int sf_down_idx = 0; sf_down_idx < kNumScaleFactorsToTest;
163 const int sf_down = kScaleFactors[sf_down_idx];
164 const int dst_width = src_width * sf_up / sf_down;
165 const int dst_height = src_height * sf_up / sf_down;
166 if (sf_up == sf_down && sf_up != 1) {
169 // I420 frame width and height must be even.
170 if (dst_width & 1 || dst_height & 1) {
173 ASSERT_NO_FATAL_FAILURE(
174 ResetScaleImages(src_width, src_height, dst_width, dst_height));
175 ASM_REGISTER_STATE_CHECK(
176 ReferenceScaleFrame(filter_type, phase_scaler));
178 vpx_usec_timer timer;
179 vpx_usec_timer_start(&timer);
180 for (int i = 0; i < kCountSpeedTestBlock; ++i) {
181 ScaleFrame(filter_type, phase_scaler);
183 libvpx_test::ClearSystemState();
184 vpx_usec_timer_mark(&timer);
185 const int elapsed_time =
186 static_cast<int>(vpx_usec_timer_elapsed(&timer) / 1000);
187 CompareImages(dst_img_);
188 DeallocScaleImages();
191 "filter_type = %d, phase_scaler = %d, src_width = %4d, "
192 "src_height = %4d, dst_width = %4d, dst_height = %4d, "
193 "scale factor = %d:%d, scale time: %5d ms\n",
194 filter_type, phase_scaler, src_width, src_height, dst_width,
195 dst_height, sf_down, sf_up, elapsed_time);
202 INSTANTIATE_TEST_SUITE_P(C, ScaleTest,
203 ::testing::Values(vp9_scale_and_extend_frame_c));
206 INSTANTIATE_TEST_SUITE_P(SSSE3, ScaleTest,
207 ::testing::Values(vp9_scale_and_extend_frame_ssse3));
211 INSTANTIATE_TEST_SUITE_P(NEON, ScaleTest,
212 ::testing::Values(vp9_scale_and_extend_frame_neon));
215 } // namespace libvpx_test