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