OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <stdlib.h> | 11 #include <stdlib.h> |
12 #include <time.h> | 12 #include <time.h> |
13 | 13 |
14 #include "libyuv/cpu_id.h" | 14 #include "libyuv/cpu_id.h" |
15 #include "libyuv/scale.h" | 15 #include "libyuv/scale.h" |
16 #include "../unit_test/unit_test.h" | 16 #include "../unit_test/unit_test.h" |
17 | 17 |
18 #define STRINGIZE(line) #line | 18 #define STRINGIZE(line) #line |
19 #define FILELINESTR(file, line) file ":" STRINGIZE(line) | 19 #define FILELINESTR(file, line) file ":" STRINGIZE(line) |
20 | 20 |
21 namespace libyuv { | 21 namespace libyuv { |
22 | 22 |
23 // Test scaling with C vs Opt and return maximum pixel difference. 0 = exact. | 23 // Test scaling with C vs Opt and return maximum pixel difference. 0 = exact. |
24 static int TestFilter(int src_width, int src_height, | 24 static int TestFilter(int src_width, int src_height, |
25 int dst_width, int dst_height, | 25 int dst_width, int dst_height, |
26 FilterMode f, int benchmark_iterations, | 26 FilterMode f, int benchmark_iterations, |
27 int disable_cpu_flags) { | 27 int disable_cpu_flags, int benchmark_cpu_info) { |
28 int i, j; | 28 int i, j; |
29 const int b = 0; // 128 to test for padding/stride. | 29 const int b = 0; // 128 to test for padding/stride. |
30 int src_width_uv = (Abs(src_width) + 1) >> 1; | 30 int src_width_uv = (Abs(src_width) + 1) >> 1; |
31 int src_height_uv = (Abs(src_height) + 1) >> 1; | 31 int src_height_uv = (Abs(src_height) + 1) >> 1; |
32 | 32 |
33 int64 src_y_plane_size = (Abs(src_width) + b * 2) * (Abs(src_height) + b * 2); | 33 int64 src_y_plane_size = (Abs(src_width) + b * 2) * (Abs(src_height) + b * 2); |
34 int64 src_uv_plane_size = (src_width_uv + b * 2) * (src_height_uv + b * 2); | 34 int64 src_uv_plane_size = (src_width_uv + b * 2) * (src_height_uv + b * 2); |
35 | 35 |
36 int src_stride_y = b * 2 + Abs(src_width); | 36 int src_stride_y = b * 2 + Abs(src_width); |
37 int src_stride_uv = b * 2 + src_width_uv; | 37 int src_stride_uv = b * 2 + src_width_uv; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 I420Scale(src_y + (src_stride_y * b) + b, src_stride_y, | 73 I420Scale(src_y + (src_stride_y * b) + b, src_stride_y, |
74 src_u + (src_stride_uv * b) + b, src_stride_uv, | 74 src_u + (src_stride_uv * b) + b, src_stride_uv, |
75 src_v + (src_stride_uv * b) + b, src_stride_uv, | 75 src_v + (src_stride_uv * b) + b, src_stride_uv, |
76 src_width, src_height, | 76 src_width, src_height, |
77 dst_y_c + (dst_stride_y * b) + b, dst_stride_y, | 77 dst_y_c + (dst_stride_y * b) + b, dst_stride_y, |
78 dst_u_c + (dst_stride_uv * b) + b, dst_stride_uv, | 78 dst_u_c + (dst_stride_uv * b) + b, dst_stride_uv, |
79 dst_v_c + (dst_stride_uv * b) + b, dst_stride_uv, | 79 dst_v_c + (dst_stride_uv * b) + b, dst_stride_uv, |
80 dst_width, dst_height, f); | 80 dst_width, dst_height, f); |
81 c_time = (get_time() - c_time); | 81 c_time = (get_time() - c_time); |
82 | 82 |
83 MaskCpuFlags(-1); // Enable all CPU optimization. | 83 MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. |
84 double opt_time = get_time(); | 84 double opt_time = get_time(); |
85 for (i = 0; i < benchmark_iterations; ++i) { | 85 for (i = 0; i < benchmark_iterations; ++i) { |
86 I420Scale(src_y + (src_stride_y * b) + b, src_stride_y, | 86 I420Scale(src_y + (src_stride_y * b) + b, src_stride_y, |
87 src_u + (src_stride_uv * b) + b, src_stride_uv, | 87 src_u + (src_stride_uv * b) + b, src_stride_uv, |
88 src_v + (src_stride_uv * b) + b, src_stride_uv, | 88 src_v + (src_stride_uv * b) + b, src_stride_uv, |
89 src_width, src_height, | 89 src_width, src_height, |
90 dst_y_opt + (dst_stride_y * b) + b, dst_stride_y, | 90 dst_y_opt + (dst_stride_y * b) + b, dst_stride_y, |
91 dst_u_opt + (dst_stride_uv * b) + b, dst_stride_uv, | 91 dst_u_opt + (dst_stride_uv * b) + b, dst_stride_uv, |
92 dst_v_opt + (dst_stride_uv * b) + b, dst_stride_uv, | 92 dst_v_opt + (dst_stride_uv * b) + b, dst_stride_uv, |
93 dst_width, dst_height, f); | 93 dst_width, dst_height, f); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 #define DX(x, nom, denom) static_cast<int>((Abs(x) / nom / 2) * nom * 2) | 277 #define DX(x, nom, denom) static_cast<int>((Abs(x) / nom / 2) * nom * 2) |
278 #define SX(x, nom, denom) static_cast<int>((x / nom / 2) * denom * 2) | 278 #define SX(x, nom, denom) static_cast<int>((x / nom / 2) * denom * 2) |
279 | 279 |
280 #define TEST_FACTOR1(name, filter, nom, denom, max_diff) \ | 280 #define TEST_FACTOR1(name, filter, nom, denom, max_diff) \ |
281 TEST_F(LibYUVScaleTest, ScaleDownBy##name##_##filter) { \ | 281 TEST_F(LibYUVScaleTest, ScaleDownBy##name##_##filter) { \ |
282 int diff = TestFilter(SX(benchmark_width_, nom, denom), \ | 282 int diff = TestFilter(SX(benchmark_width_, nom, denom), \ |
283 SX(benchmark_height_, nom, denom), \ | 283 SX(benchmark_height_, nom, denom), \ |
284 DX(benchmark_width_, nom, denom), \ | 284 DX(benchmark_width_, nom, denom), \ |
285 DX(benchmark_height_, nom, denom), \ | 285 DX(benchmark_height_, nom, denom), \ |
286 kFilter##filter, benchmark_iterations_, \ | 286 kFilter##filter, benchmark_iterations_, \ |
287 disable_cpu_flags_); \ | 287 disable_cpu_flags_, benchmark_cpu_info_); \ |
288 EXPECT_LE(diff, max_diff); \ | 288 EXPECT_LE(diff, max_diff); \ |
289 } \ | 289 } \ |
290 TEST_F(LibYUVScaleTest, DISABLED_ScaleDownBy##name##_##filter##_16) { \ | 290 TEST_F(LibYUVScaleTest, DISABLED_ScaleDownBy##name##_##filter##_16) { \ |
291 int diff = TestFilter_16(SX(benchmark_width_, nom, denom), \ | 291 int diff = TestFilter_16(SX(benchmark_width_, nom, denom), \ |
292 SX(benchmark_height_, nom, denom), \ | 292 SX(benchmark_height_, nom, denom), \ |
293 DX(benchmark_width_, nom, denom), \ | 293 DX(benchmark_width_, nom, denom), \ |
294 DX(benchmark_height_, nom, denom), \ | 294 DX(benchmark_height_, nom, denom), \ |
295 kFilter##filter, benchmark_iterations_); \ | 295 kFilter##filter, benchmark_iterations_); \ |
296 EXPECT_LE(diff, max_diff); \ | 296 EXPECT_LE(diff, max_diff); \ |
297 } | 297 } |
(...skipping 15 matching lines...) Expand all Loading... |
313 #undef TEST_FACTOR1 | 313 #undef TEST_FACTOR1 |
314 #undef TEST_FACTOR | 314 #undef TEST_FACTOR |
315 #undef SX | 315 #undef SX |
316 #undef DX | 316 #undef DX |
317 | 317 |
318 #define TEST_SCALETO1(name, width, height, filter, max_diff) \ | 318 #define TEST_SCALETO1(name, width, height, filter, max_diff) \ |
319 TEST_F(LibYUVScaleTest, name##To##width##x##height##_##filter) { \ | 319 TEST_F(LibYUVScaleTest, name##To##width##x##height##_##filter) { \ |
320 int diff = TestFilter(benchmark_width_, benchmark_height_, \ | 320 int diff = TestFilter(benchmark_width_, benchmark_height_, \ |
321 width, height, \ | 321 width, height, \ |
322 kFilter##filter, benchmark_iterations_, \ | 322 kFilter##filter, benchmark_iterations_, \ |
323 disable_cpu_flags_); \ | 323 disable_cpu_flags_, benchmark_cpu_info_); \ |
324 EXPECT_LE(diff, max_diff); \ | 324 EXPECT_LE(diff, max_diff); \ |
325 } \ | 325 } \ |
326 TEST_F(LibYUVScaleTest, name##From##width##x##height##_##filter) { \ | 326 TEST_F(LibYUVScaleTest, name##From##width##x##height##_##filter) { \ |
327 int diff = TestFilter(width, height, \ | 327 int diff = TestFilter(width, height, \ |
328 Abs(benchmark_width_), Abs(benchmark_height_), \ | 328 Abs(benchmark_width_), Abs(benchmark_height_), \ |
329 kFilter##filter, benchmark_iterations_, \ | 329 kFilter##filter, benchmark_iterations_, \ |
330 disable_cpu_flags_); \ | 330 disable_cpu_flags_, benchmark_cpu_info_); \ |
331 EXPECT_LE(diff, max_diff); \ | 331 EXPECT_LE(diff, max_diff); \ |
332 } \ | 332 } \ |
333 TEST_F(LibYUVScaleTest, \ | 333 TEST_F(LibYUVScaleTest, \ |
334 DISABLED_##name##To##width##x##height##_##filter##_16) { \ | 334 DISABLED_##name##To##width##x##height##_##filter##_16) { \ |
335 int diff = TestFilter_16(benchmark_width_, benchmark_height_, \ | 335 int diff = TestFilter_16(benchmark_width_, benchmark_height_, \ |
336 width, height, \ | 336 width, height, \ |
337 kFilter##filter, benchmark_iterations_); \ | 337 kFilter##filter, benchmark_iterations_); \ |
338 EXPECT_LE(diff, max_diff); \ | 338 EXPECT_LE(diff, max_diff); \ |
339 } \ | 339 } \ |
340 TEST_F(LibYUVScaleTest, \ | 340 TEST_F(LibYUVScaleTest, \ |
(...skipping 14 matching lines...) Expand all Loading... |
355 TEST_SCALETO(Scale, 1, 1) | 355 TEST_SCALETO(Scale, 1, 1) |
356 TEST_SCALETO(Scale, 320, 240) | 356 TEST_SCALETO(Scale, 320, 240) |
357 TEST_SCALETO(Scale, 352, 288) | 357 TEST_SCALETO(Scale, 352, 288) |
358 TEST_SCALETO(Scale, 569, 480) | 358 TEST_SCALETO(Scale, 569, 480) |
359 TEST_SCALETO(Scale, 640, 360) | 359 TEST_SCALETO(Scale, 640, 360) |
360 TEST_SCALETO(Scale, 1280, 720) | 360 TEST_SCALETO(Scale, 1280, 720) |
361 #undef TEST_SCALETO1 | 361 #undef TEST_SCALETO1 |
362 #undef TEST_SCALETO | 362 #undef TEST_SCALETO |
363 | 363 |
364 } // namespace libyuv | 364 } // namespace libyuv |
OLD | NEW |