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