| 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, int benchmark_cpu_info) { | 27 int disable_cpu_flags, int benchmark_cpu_info) { |
| 28 if (src_width > 32768 || src_height > 32768 || |
| 29 dst_width > 32768 || dst_height > 32768) { |
| 30 printf("Warning - size too large to test. Skipping\n"); |
| 31 return 0; |
| 32 } |
| 28 int i, j; | 33 int i, j; |
| 29 const int b = 0; // 128 to test for padding/stride. | 34 const int b = 0; // 128 to test for padding/stride. |
| 30 int src_width_uv = (Abs(src_width) + 1) >> 1; | 35 int src_width_uv = (Abs(src_width) + 1) >> 1; |
| 31 int src_height_uv = (Abs(src_height) + 1) >> 1; | 36 int src_height_uv = (Abs(src_height) + 1) >> 1; |
| 32 | 37 |
| 33 int64 src_y_plane_size = (Abs(src_width) + b * 2) * (Abs(src_height) + b * 2); | 38 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); | 39 int64 src_uv_plane_size = (src_width_uv + b * 2) * (src_height_uv + b * 2); |
| 35 | 40 |
| 36 int src_stride_y = b * 2 + Abs(src_width); | 41 int src_stride_y = b * 2 + Abs(src_width); |
| 37 int src_stride_uv = b * 2 + src_width_uv; | 42 int src_stride_uv = b * 2 + src_width_uv; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 free_aligned_buffer_page_end(src_v) | 146 free_aligned_buffer_page_end(src_v) |
| 142 | 147 |
| 143 return max_diff; | 148 return max_diff; |
| 144 } | 149 } |
| 145 | 150 |
| 146 // Test scaling with 8 bit C vs 16 bit C and return maximum pixel difference. | 151 // Test scaling with 8 bit C vs 16 bit C and return maximum pixel difference. |
| 147 // 0 = exact. | 152 // 0 = exact. |
| 148 static int TestFilter_16(int src_width, int src_height, | 153 static int TestFilter_16(int src_width, int src_height, |
| 149 int dst_width, int dst_height, | 154 int dst_width, int dst_height, |
| 150 FilterMode f, int benchmark_iterations) { | 155 FilterMode f, int benchmark_iterations) { |
| 156 if (src_width > 32768 || src_height > 32768 || |
| 157 dst_width > 32768 || dst_height > 32768) { |
| 158 printf("Warning - size too large to test. Skipping\n"); |
| 159 return 0; |
| 160 } |
| 151 int i, j; | 161 int i, j; |
| 152 const int b = 0; // 128 to test for padding/stride. | 162 const int b = 0; // 128 to test for padding/stride. |
| 153 int src_width_uv = (Abs(src_width) + 1) >> 1; | 163 int src_width_uv = (Abs(src_width) + 1) >> 1; |
| 154 int src_height_uv = (Abs(src_height) + 1) >> 1; | 164 int src_height_uv = (Abs(src_height) + 1) >> 1; |
| 155 | 165 |
| 156 int64 src_y_plane_size = (Abs(src_width) + b * 2) * | 166 int64 src_y_plane_size = (Abs(src_width) + b * 2) * |
| 157 (Abs(src_height) + b * 2); | 167 (Abs(src_height) + b * 2); |
| 158 int64 src_uv_plane_size = (src_width_uv + b * 2) * (src_height_uv + b * 2); | 168 int64 src_uv_plane_size = (src_width_uv + b * 2) * (src_height_uv + b * 2); |
| 159 | 169 |
| 160 int src_stride_y = b * 2 + Abs(src_width); | 170 int src_stride_y = b * 2 + Abs(src_width); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 free_aligned_buffer_page_end(src_y_16) | 277 free_aligned_buffer_page_end(src_y_16) |
| 268 free_aligned_buffer_page_end(src_u_16) | 278 free_aligned_buffer_page_end(src_u_16) |
| 269 free_aligned_buffer_page_end(src_v_16) | 279 free_aligned_buffer_page_end(src_v_16) |
| 270 | 280 |
| 271 return max_diff; | 281 return max_diff; |
| 272 } | 282 } |
| 273 | 283 |
| 274 // The following adjustments in dimensions ensure the scale factor will be | 284 // The following adjustments in dimensions ensure the scale factor will be |
| 275 // exactly achieved. | 285 // exactly achieved. |
| 276 // 2 is chroma subsample | 286 // 2 is chroma subsample |
| 277 #define DX(x, nom, denom) static_cast<int>((Abs(x) / nom / 2) * nom * 2) | 287 #define DX(x, nom, denom) static_cast<int>(((Abs(x) / nom + 1) / 2) * nom * 2) |
| 278 #define SX(x, nom, denom) static_cast<int>((x / nom / 2) * denom * 2) | 288 #define SX(x, nom, denom) static_cast<int>(((x / nom + 1) / 2) * denom * 2) |
| 279 | 289 |
| 280 #define TEST_FACTOR1(name, filter, nom, denom, max_diff) \ | 290 #define TEST_FACTOR1(name, filter, nom, denom, max_diff) \ |
| 281 TEST_F(LibYUVScaleTest, ScaleDownBy##name##_##filter) { \ | 291 TEST_F(LibYUVScaleTest, ScaleDownBy##name##_##filter) { \ |
| 282 int diff = TestFilter(SX(benchmark_width_, nom, denom), \ | 292 int diff = TestFilter(SX(benchmark_width_, nom, denom), \ |
| 283 SX(benchmark_height_, nom, denom), \ | 293 SX(benchmark_height_, nom, denom), \ |
| 284 DX(benchmark_width_, nom, denom), \ | 294 DX(benchmark_width_, nom, denom), \ |
| 285 DX(benchmark_height_, nom, denom), \ | 295 DX(benchmark_height_, nom, denom), \ |
| 286 kFilter##filter, benchmark_iterations_, \ | 296 kFilter##filter, benchmark_iterations_, \ |
| 287 disable_cpu_flags_, benchmark_cpu_info_); \ | 297 disable_cpu_flags_, benchmark_cpu_info_); \ |
| 288 EXPECT_LE(diff, max_diff); \ | 298 EXPECT_LE(diff, max_diff); \ |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 TEST_SCALETO(Scale, 1, 1) | 365 TEST_SCALETO(Scale, 1, 1) |
| 356 TEST_SCALETO(Scale, 320, 240) | 366 TEST_SCALETO(Scale, 320, 240) |
| 357 TEST_SCALETO(Scale, 352, 288) | 367 TEST_SCALETO(Scale, 352, 288) |
| 358 TEST_SCALETO(Scale, 569, 480) | 368 TEST_SCALETO(Scale, 569, 480) |
| 359 TEST_SCALETO(Scale, 640, 360) | 369 TEST_SCALETO(Scale, 640, 360) |
| 360 TEST_SCALETO(Scale, 1280, 720) | 370 TEST_SCALETO(Scale, 1280, 720) |
| 361 #undef TEST_SCALETO1 | 371 #undef TEST_SCALETO1 |
| 362 #undef TEST_SCALETO | 372 #undef TEST_SCALETO |
| 363 | 373 |
| 364 } // namespace libyuv | 374 } // namespace libyuv |
| OLD | NEW |