| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/base_paths.h" | 5 #include "base/base_paths.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "media/base/cpu_features.h" | 9 #include "media/base/cpu_features.h" |
| 10 #include "media/base/djb2.h" | 10 #include "media/base/djb2.h" |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 yuv_converted_bytes.get(), | 372 yuv_converted_bytes.get(), |
| 373 yuv_converted_bytes.get() + kSourceUOffset, | 373 yuv_converted_bytes.get() + kSourceUOffset, |
| 374 yuv_converted_bytes.get() + kSourceVOffset, | 374 yuv_converted_bytes.get() + kSourceVOffset, |
| 375 kSourceWidth, kSourceHeight); | 375 kSourceWidth, kSourceHeight); |
| 376 | 376 |
| 377 uint32 yuy_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, | 377 uint32 yuy_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, |
| 378 kDJB2HashSeed); | 378 kDJB2HashSeed); |
| 379 EXPECT_EQ(666823187u, yuy_hash); | 379 EXPECT_EQ(666823187u, yuy_hash); |
| 380 } | 380 } |
| 381 | 381 |
| 382 |
| 383 TEST(YUVConvertTest, ScaleWithQuarterRect) { |
| 384 // Read YUV reference data from file. |
| 385 FilePath yuv_url; |
| 386 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); |
| 387 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) |
| 388 .Append(FILE_PATH_LITERAL("test")) |
| 389 .Append(FILE_PATH_LITERAL("data")) |
| 390 .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); |
| 391 const size_t size_of_yuv = kSourceYSize * 12 / 8; // 12 bpp. |
| 392 scoped_array<uint8> yuv_bytes(new uint8[size_of_yuv]); |
| 393 EXPECT_EQ(static_cast<int>(size_of_yuv), |
| 394 file_util::ReadFile(yuv_url, |
| 395 reinterpret_cast<char*>(yuv_bytes.get()), |
| 396 static_cast<int>(size_of_yuv))); |
| 397 |
| 398 // Scale a frame of YUV to 32 bit ARGB. |
| 399 const size_t size_of_rgb_scaled = kScaledWidth * kScaledHeight * kBpp; |
| 400 scoped_array<uint8> rgb_source_bytes(new uint8[size_of_rgb_scaled]); |
| 401 |
| 402 media::ScaleYUVToRGB32WithRect( |
| 403 yuv_bytes.get(), // Y |
| 404 yuv_bytes.get() + kSourceYSize, // U |
| 405 yuv_bytes.get() + kSourceYSize * 5 / 4, // V |
| 406 rgb_source_bytes.get(), // Rgb output |
| 407 kSourceWidth, kSourceHeight, // Dimensions |
| 408 kScaledWidth, kScaledHeight, // Dimensions |
| 409 0, 0, kScaledWidth, kScaledHeight, // Dest rect |
| 410 kSourceWidth, // YStride |
| 411 kSourceWidth / 2, // UvStride |
| 412 kScaledWidth * kBpp); // RgbStride |
| 413 |
| 414 uint32 rgb_hash_full_rect = DJB2Hash(rgb_source_bytes.get(), |
| 415 size_of_rgb_scaled, |
| 416 kDJB2HashSeed); |
| 417 |
| 418 // Scale only a partial rectangle. |
| 419 media::ScaleYUVToRGB32WithRect( |
| 420 yuv_bytes.get(), // Y |
| 421 yuv_bytes.get() + kSourceYSize, // U |
| 422 yuv_bytes.get() + kSourceYSize * 5 / 4, // V |
| 423 rgb_source_bytes.get(), // Rgb output |
| 424 kSourceWidth, kSourceHeight, // Dimensions |
| 425 kScaledWidth, kScaledHeight, // Dimensions |
| 426 kScaledWidth / 4, // Dest rect |
| 427 kScaledHeight / 4, |
| 428 (kScaledWidth * 3) / 4, |
| 429 (kScaledHeight * 3) / 4, |
| 430 kSourceWidth, // YStride |
| 431 kSourceWidth / 2, // UvStride |
| 432 kScaledWidth * kBpp); // RgbStride |
| 433 |
| 434 uint32 rgb_hash_quarter_rect = DJB2Hash(rgb_source_bytes.get(), |
| 435 size_of_rgb_scaled, |
| 436 kDJB2HashSeed); |
| 437 EXPECT_EQ(rgb_hash_full_rect, rgb_hash_quarter_rect); |
| 438 } |
| 439 |
| 440 TEST(YUVConvertTest, ScaleWithTinyRect) { |
| 441 // Read YUV reference data from file. |
| 442 FilePath yuv_url; |
| 443 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); |
| 444 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) |
| 445 .Append(FILE_PATH_LITERAL("test")) |
| 446 .Append(FILE_PATH_LITERAL("data")) |
| 447 .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); |
| 448 const size_t size_of_yuv = kSourceYSize * 12 / 8; // 12 bpp. |
| 449 scoped_array<uint8> yuv_bytes(new uint8[size_of_yuv]); |
| 450 EXPECT_EQ(static_cast<int>(size_of_yuv), |
| 451 file_util::ReadFile(yuv_url, |
| 452 reinterpret_cast<char*>(yuv_bytes.get()), |
| 453 static_cast<int>(size_of_yuv))); |
| 454 |
| 455 // Scale a frame of YUV to 32 bit ARGB. |
| 456 const size_t size_of_rgb_scaled = kScaledWidth * kScaledHeight * kBpp; |
| 457 scoped_array<uint8> rgb_source_bytes(new uint8[size_of_rgb_scaled]); |
| 458 |
| 459 media::ScaleYUVToRGB32WithRect( |
| 460 yuv_bytes.get(), // Y |
| 461 yuv_bytes.get() + kSourceYSize, // U |
| 462 yuv_bytes.get() + kSourceYSize * 5 / 4, // V |
| 463 rgb_source_bytes.get(), // Rgb output |
| 464 kSourceWidth, kSourceHeight, // Dimensions |
| 465 kScaledWidth, kScaledHeight, // Dimensions |
| 466 0, 0, kScaledWidth, kScaledHeight, // Dest rect |
| 467 kSourceWidth, // YStride |
| 468 kSourceWidth / 2, // UvStride |
| 469 kScaledWidth * kBpp); // RgbStride |
| 470 |
| 471 uint32 rgb_hash_full_rect = DJB2Hash(rgb_source_bytes.get(), |
| 472 size_of_rgb_scaled, |
| 473 kDJB2HashSeed); |
| 474 |
| 475 // Scale only one pixel in the middle |
| 476 media::ScaleYUVToRGB32WithRect( |
| 477 yuv_bytes.get(), // Y |
| 478 yuv_bytes.get() + kSourceYSize, // U |
| 479 yuv_bytes.get() + kSourceYSize * 5 / 4, // V |
| 480 rgb_source_bytes.get(), // Rgb output |
| 481 kSourceWidth, kSourceHeight, // Dimensions |
| 482 kScaledWidth, kScaledHeight, // Dimensions |
| 483 kScaledWidth / 4, // Dest rect |
| 484 kScaledHeight / 4, |
| 485 kScaledWidth / 4 + 1, |
| 486 kScaledHeight / 4 + 1, |
| 487 kSourceWidth, // YStride |
| 488 kSourceWidth / 2, // UvStride |
| 489 kScaledWidth * kBpp); // RgbStride |
| 490 |
| 491 uint32 rgb_hash_tiny_rect = DJB2Hash(rgb_source_bytes.get(), |
| 492 size_of_rgb_scaled, |
| 493 kDJB2HashSeed); |
| 494 EXPECT_EQ(rgb_hash_full_rect, rgb_hash_tiny_rect); |
| 495 } |
| 496 |
| 382 #if !defined(ARCH_CPU_ARM_FAMILY) | 497 #if !defined(ARCH_CPU_ARM_FAMILY) |
| 383 TEST(YUVConvertTest, RGB32ToYUV_SSE2_MatchReference) { | 498 TEST(YUVConvertTest, RGB32ToYUV_SSE2_MatchReference) { |
| 384 if (!media::hasSSE2()) { | 499 if (!media::hasSSE2()) { |
| 385 LOG(WARNING) << "System doesn't support SSE2, test not executed."; | 500 LOG(WARNING) << "System doesn't support SSE2, test not executed."; |
| 386 return; | 501 return; |
| 387 } | 502 } |
| 388 | 503 |
| 389 // Allocate all surfaces. | 504 // Allocate all surfaces. |
| 390 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); | 505 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); |
| 391 scoped_array<uint8> rgb_bytes(new uint8[kRGBSize]); | 506 scoped_array<uint8> rgb_bytes(new uint8[kRGBSize]); |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 kSourceDx); | 925 kSourceDx); |
| 811 media::EmptyRegisterState(); | 926 media::EmptyRegisterState(); |
| 812 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | 927 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 813 rgb_bytes_converted.get(), | 928 rgb_bytes_converted.get(), |
| 814 kWidth * kBpp)); | 929 kWidth * kBpp)); |
| 815 } | 930 } |
| 816 | 931 |
| 817 #endif // defined(ARCH_CPU_X86_64) | 932 #endif // defined(ARCH_CPU_X86_64) |
| 818 | 933 |
| 819 #endif // defined(ARCH_CPU_X86_FAMILY) | 934 #endif // defined(ARCH_CPU_X86_FAMILY) |
| OLD | NEW |