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/convert.h" |
15 #include "libyuv/scale_argb.h" | 16 #include "libyuv/scale_argb.h" |
16 #include "libyuv/row.h" | 17 #include "libyuv/row.h" |
| 18 #include "libyuv/video_common.h" |
17 #include "../unit_test/unit_test.h" | 19 #include "../unit_test/unit_test.h" |
18 | 20 |
19 namespace libyuv { | 21 namespace libyuv { |
20 | 22 |
21 #define STRINGIZE(line) #line | 23 #define STRINGIZE(line) #line |
22 #define FILELINESTR(file, line) file ":" STRINGIZE(line) | 24 #define FILELINESTR(file, line) file ":" STRINGIZE(line) |
23 | 25 |
24 // Test scaling with C vs Opt and return maximum pixel difference. 0 = exact. | 26 // Test scaling with C vs Opt and return maximum pixel difference. 0 = exact. |
25 static int ARGBTestFilter(int src_width, int src_height, | 27 static int ARGBTestFilter(int src_width, int src_height, |
26 int dst_width, int dst_height, | 28 int dst_width, int dst_height, |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 294 |
293 TEST_SCALETO(ARGBScale, 1, 1) | 295 TEST_SCALETO(ARGBScale, 1, 1) |
294 TEST_SCALETO(ARGBScale, 320, 240) | 296 TEST_SCALETO(ARGBScale, 320, 240) |
295 TEST_SCALETO(ARGBScale, 352, 288) | 297 TEST_SCALETO(ARGBScale, 352, 288) |
296 TEST_SCALETO(ARGBScale, 569, 480) | 298 TEST_SCALETO(ARGBScale, 569, 480) |
297 TEST_SCALETO(ARGBScale, 640, 360) | 299 TEST_SCALETO(ARGBScale, 640, 360) |
298 TEST_SCALETO(ARGBScale, 1280, 720) | 300 TEST_SCALETO(ARGBScale, 1280, 720) |
299 #undef TEST_SCALETO1 | 301 #undef TEST_SCALETO1 |
300 #undef TEST_SCALETO | 302 #undef TEST_SCALETO |
301 | 303 |
| 304 // Scale with YUV conversion to ARGB and clipping. |
| 305 LIBYUV_API |
| 306 int YUVToARGBScaleReference2(const uint8* src_y, int src_stride_y, |
| 307 const uint8* src_u, int src_stride_u, |
| 308 const uint8* src_v, int src_stride_v, |
| 309 uint32 src_fourcc, |
| 310 int src_width, int src_height, |
| 311 uint8* dst_argb, int dst_stride_argb, |
| 312 uint32 dst_fourcc, |
| 313 int dst_width, int dst_height, |
| 314 int clip_x, int clip_y, |
| 315 int clip_width, int clip_height, |
| 316 enum FilterMode filtering) { |
| 317 |
| 318 uint8* argb_buffer = (uint8*)malloc(src_width * src_height * 4); |
| 319 int r; |
| 320 I420ToARGB(src_y, src_stride_y, |
| 321 src_u, src_stride_u, |
| 322 src_v, src_stride_v, |
| 323 argb_buffer, src_width * 4, |
| 324 src_width, src_height); |
| 325 |
| 326 r = ARGBScaleClip(argb_buffer, src_width * 4, |
| 327 src_width, src_height, |
| 328 dst_argb, dst_stride_argb, |
| 329 dst_width, dst_height, |
| 330 clip_x, clip_y, clip_width, clip_height, |
| 331 filtering); |
| 332 free(argb_buffer); |
| 333 return r; |
| 334 } |
| 335 |
| 336 static void FillRamp(uint8* buf, int width, int height, int v, int dx, int dy) { |
| 337 int rv = v; |
| 338 for (int y = 0; y < height; ++y) { |
| 339 for (int x = 0; x < width; ++x) { |
| 340 *buf++ = v; |
| 341 v += dx; |
| 342 if (v < 0 || v > 255) { |
| 343 dx = -dx; |
| 344 v += dx; |
| 345 } |
| 346 } |
| 347 v = rv + dy; |
| 348 if (v < 0 || v > 255) { |
| 349 dy = -dy; |
| 350 v += dy; |
| 351 } |
| 352 rv = v; |
| 353 } |
| 354 } |
| 355 |
| 356 // Test scaling with C vs Opt and return maximum pixel difference. 0 = exact. |
| 357 static int YUVToARGBTestFilter(int src_width, int src_height, |
| 358 int dst_width, int dst_height, |
| 359 FilterMode f, int benchmark_iterations, |
| 360 int disable_cpu_flags, int benchmark_cpu_info) { |
| 361 int64 src_y_plane_size = Abs(src_width) * Abs(src_height); |
| 362 int64 src_uv_plane_size = ((Abs(src_width) + 1) / 2) * |
| 363 ((Abs(src_height) + 1) / 2); |
| 364 int src_stride_y = Abs(src_width); |
| 365 int src_stride_uv = (Abs(src_width) + 1) / 2; |
| 366 |
| 367 align_buffer_page_end(src_y, src_y_plane_size); |
| 368 align_buffer_page_end(src_u, src_uv_plane_size); |
| 369 align_buffer_page_end(src_v, src_uv_plane_size); |
| 370 |
| 371 int64 dst_argb_plane_size = (dst_width) * (dst_height) * 4LL; |
| 372 int dst_stride_argb = (dst_width) * 4; |
| 373 align_buffer_page_end(dst_argb_c, dst_argb_plane_size); |
| 374 align_buffer_page_end(dst_argb_opt, dst_argb_plane_size); |
| 375 if (!dst_argb_c || !dst_argb_opt || !src_y || !src_u || !src_v) { |
| 376 printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); |
| 377 return 0; |
| 378 } |
| 379 // Fill YUV image with continuous ramp, which is less sensitive to |
| 380 // subsampling and filtering differences for test purposes. |
| 381 FillRamp(src_y, Abs(src_width), Abs(src_height), 128, 1, 1); |
| 382 FillRamp(src_u, (Abs(src_width) + 1) / 2, (Abs(src_height) + 1) / 2, 3, 1, 1); |
| 383 FillRamp(src_v, (Abs(src_width) + 1) / 2, (Abs(src_height) + 1) / 2, 4, 1, 1); |
| 384 memset(dst_argb_c, 2, dst_argb_plane_size); |
| 385 memset(dst_argb_opt, 3, dst_argb_plane_size); |
| 386 |
| 387 YUVToARGBScaleReference2(src_y, src_stride_y, |
| 388 src_u, src_stride_uv, |
| 389 src_v, src_stride_uv, |
| 390 libyuv::FOURCC_I420, |
| 391 src_width, src_height, |
| 392 dst_argb_c, dst_stride_argb, |
| 393 libyuv::FOURCC_I420, |
| 394 dst_width, dst_height, |
| 395 0, 0, dst_width, dst_height, |
| 396 f); |
| 397 |
| 398 for (int i = 0; i < benchmark_iterations; ++i) { |
| 399 YUVToARGBScaleClip(src_y, src_stride_y, |
| 400 src_u, src_stride_uv, |
| 401 src_v, src_stride_uv, |
| 402 libyuv::FOURCC_I420, |
| 403 src_width, src_height, |
| 404 dst_argb_opt, dst_stride_argb, |
| 405 libyuv::FOURCC_I420, |
| 406 dst_width, dst_height, |
| 407 0, 0, dst_width, dst_height, |
| 408 f); |
| 409 } |
| 410 int max_diff = 0; |
| 411 for (int i = 0; i < dst_height; ++i) { |
| 412 for (int j = 0; j < dst_width * 4; ++j) { |
| 413 int abs_diff = Abs(dst_argb_c[(i * dst_stride_argb) + j] - |
| 414 dst_argb_opt[(i * dst_stride_argb) + j]); |
| 415 if (abs_diff > max_diff) { |
| 416 printf("error %d at %d,%d c %d opt %d", |
| 417 abs_diff, |
| 418 j, i, |
| 419 dst_argb_c[(i * dst_stride_argb) + j], |
| 420 dst_argb_opt[(i * dst_stride_argb) + j]); |
| 421 EXPECT_LE(abs_diff, 40); |
| 422 max_diff = abs_diff; |
| 423 } |
| 424 } |
| 425 } |
| 426 |
| 427 free_aligned_buffer_page_end(dst_argb_c); |
| 428 free_aligned_buffer_page_end(dst_argb_opt); |
| 429 free_aligned_buffer_page_end(src_y); |
| 430 free_aligned_buffer_page_end(src_u); |
| 431 free_aligned_buffer_page_end(src_v); |
| 432 return max_diff; |
| 433 } |
| 434 |
| 435 TEST_F(LibYUVScaleTest, YUVToRGBScaleUp) { |
| 436 int diff = YUVToARGBTestFilter(benchmark_width_, benchmark_height_, |
| 437 benchmark_width_ * 3 / 2, |
| 438 benchmark_height_ * 3 / 2, |
| 439 libyuv::kFilterBilinear, |
| 440 benchmark_iterations_, |
| 441 disable_cpu_flags_, benchmark_cpu_info_); |
| 442 EXPECT_LE(diff, 10); |
| 443 } |
| 444 |
| 445 TEST_F(LibYUVScaleTest, YUVToRGBScaleDown) { |
| 446 int diff = YUVToARGBTestFilter(benchmark_width_ * 3 / 2, |
| 447 benchmark_height_ * 3 / 2, |
| 448 benchmark_width_, benchmark_height_, |
| 449 libyuv::kFilterBilinear, |
| 450 benchmark_iterations_, |
| 451 disable_cpu_flags_, benchmark_cpu_info_); |
| 452 EXPECT_LE(diff, 10); |
| 453 } |
| 454 |
| 455 |
302 } // namespace libyuv | 456 } // namespace libyuv |
OLD | NEW |