| 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" |
| 11 #include "media/base/simd/convert_yuv_to_rgb.h" |
| 11 #include "media/base/yuv_convert.h" | 12 #include "media/base/yuv_convert.h" |
| 12 #include "media/base/yuv_convert_internal.h" | 13 #include "media/base/yuv_convert_internal.h" |
| 13 #include "media/base/yuv_row.h" | 14 #include "media/base/yuv_row.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 // Size of raw image. | 17 // Size of raw image. |
| 17 static const int kSourceWidth = 640; | 18 static const int kSourceWidth = 640; |
| 18 static const int kSourceHeight = 360; | 19 static const int kSourceHeight = 360; |
| 19 static const int kSourceYSize = kSourceWidth * kSourceHeight; | 20 static const int kSourceYSize = kSourceWidth * kSourceHeight; |
| 20 static const int kSourceUOffset = kSourceYSize; | 21 static const int kSourceUOffset = kSourceYSize; |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 LOG(WARNING) << "System doesn't support SSE2, test not executed."; | 370 LOG(WARNING) << "System doesn't support SSE2, test not executed."; |
| 370 return; | 371 return; |
| 371 } | 372 } |
| 372 | 373 |
| 373 // Allocate all surfaces. | 374 // Allocate all surfaces. |
| 374 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); | 375 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); |
| 375 scoped_array<uint8> rgb_bytes(new uint8[kRGBSize]); | 376 scoped_array<uint8> rgb_bytes(new uint8[kRGBSize]); |
| 376 scoped_array<uint8> yuv_converted_bytes(new uint8[kYUV12Size]); | 377 scoped_array<uint8> yuv_converted_bytes(new uint8[kYUV12Size]); |
| 377 scoped_array<uint8> yuv_reference_bytes(new uint8[kYUV12Size]); | 378 scoped_array<uint8> yuv_reference_bytes(new uint8[kYUV12Size]); |
| 378 | 379 |
| 379 // Read YUV reference data from file. | 380 ReadYV12Data(&yuv_bytes); |
| 380 FilePath yuv_url; | |
| 381 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); | |
| 382 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) | |
| 383 .Append(FILE_PATH_LITERAL("test")) | |
| 384 .Append(FILE_PATH_LITERAL("data")) | |
| 385 .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); | |
| 386 EXPECT_EQ(static_cast<int>(kYUV12Size), | |
| 387 file_util::ReadFile(yuv_url, | |
| 388 reinterpret_cast<char*>(yuv_bytes.get()), | |
| 389 static_cast<int>(kYUV12Size))); | |
| 390 | 381 |
| 391 // Convert a frame of YUV to 32 bit ARGB. | 382 // Convert a frame of YUV to 32 bit ARGB. |
| 392 media::ConvertYUVToRGB32( | 383 media::ConvertYUVToRGB32( |
| 393 yuv_bytes.get(), | 384 yuv_bytes.get(), |
| 394 yuv_bytes.get() + kSourceUOffset, | 385 yuv_bytes.get() + kSourceUOffset, |
| 395 yuv_bytes.get() + kSourceVOffset, | 386 yuv_bytes.get() + kSourceVOffset, |
| 396 rgb_bytes.get(), // RGB output | 387 rgb_bytes.get(), // RGB output |
| 397 kSourceWidth, kSourceHeight, // Dimensions | 388 kSourceWidth, kSourceHeight, // Dimensions |
| 398 kSourceWidth, // YStride | 389 kSourceWidth, // YStride |
| 399 kSourceWidth / 2, // UVStride | 390 kSourceWidth / 2, // UVStride |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 for (int i = 0; i < kYUV12Size; ++i) { | 443 for (int i = 0; i < kYUV12Size; ++i) { |
| 453 int diff = yuv_reference_bytes[i] - yuv_converted_bytes[i]; | 444 int diff = yuv_reference_bytes[i] - yuv_converted_bytes[i]; |
| 454 if (diff < 0) | 445 if (diff < 0) |
| 455 diff = -diff; | 446 diff = -diff; |
| 456 error += diff; | 447 error += diff; |
| 457 } | 448 } |
| 458 | 449 |
| 459 // Make sure there's no difference from the reference. | 450 // Make sure there's no difference from the reference. |
| 460 EXPECT_EQ(0, error); | 451 EXPECT_EQ(0, error); |
| 461 } | 452 } |
| 462 #endif | 453 |
| 454 TEST(YUVConvertTest, ConvertYUVToRGB32Row_MMX) { |
| 455 if (!media::hasMMX()) { |
| 456 LOG(WARNING) << "System not supported. Test skipped."; |
| 457 return; |
| 458 } |
| 459 |
| 460 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); |
| 461 scoped_array<uint8> rgb_bytes_reference(new uint8[kRGBSize]); |
| 462 scoped_array<uint8> rgb_bytes_converted(new uint8[kRGBSize]); |
| 463 ReadYV12Data(&yuv_bytes); |
| 464 |
| 465 const int kWidth = 167; |
| 466 ConvertYUVToRGB32Row_C(yuv_bytes.get(), |
| 467 yuv_bytes.get() + kSourceUOffset, |
| 468 yuv_bytes.get() + kSourceVOffset, |
| 469 rgb_bytes_reference.get(), |
| 470 kWidth); |
| 471 ConvertYUVToRGB32Row_MMX(yuv_bytes.get(), |
| 472 yuv_bytes.get() + kSourceUOffset, |
| 473 yuv_bytes.get() + kSourceVOffset, |
| 474 rgb_bytes_converted.get(), |
| 475 kWidth); |
| 476 media::EmptyRegisterState(); |
| 477 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 478 rgb_bytes_converted.get(), |
| 479 kWidth * kBpp)); |
| 480 } |
| 481 |
| 482 TEST(YUVConvertTest, ConvertYUVToRGB32Row_SSE) { |
| 483 if (!media::hasSSE()) { |
| 484 LOG(WARNING) << "System not supported. Test skipped."; |
| 485 return; |
| 486 } |
| 487 |
| 488 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); |
| 489 scoped_array<uint8> rgb_bytes_reference(new uint8[kRGBSize]); |
| 490 scoped_array<uint8> rgb_bytes_converted(new uint8[kRGBSize]); |
| 491 ReadYV12Data(&yuv_bytes); |
| 492 |
| 493 const int kWidth = 167; |
| 494 ConvertYUVToRGB32Row_C(yuv_bytes.get(), |
| 495 yuv_bytes.get() + kSourceUOffset, |
| 496 yuv_bytes.get() + kSourceVOffset, |
| 497 rgb_bytes_reference.get(), |
| 498 kWidth); |
| 499 ConvertYUVToRGB32Row_SSE(yuv_bytes.get(), |
| 500 yuv_bytes.get() + kSourceUOffset, |
| 501 yuv_bytes.get() + kSourceVOffset, |
| 502 rgb_bytes_converted.get(), |
| 503 kWidth); |
| 504 media::EmptyRegisterState(); |
| 505 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 506 rgb_bytes_converted.get(), |
| 507 kWidth * kBpp)); |
| 508 } |
| 509 |
| 510 TEST(YUVConvertTest, ScaleYUVToRGB32Row_MMX) { |
| 511 if (!media::hasMMX()) { |
| 512 LOG(WARNING) << "System not supported. Test skipped."; |
| 513 return; |
| 514 } |
| 515 |
| 516 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); |
| 517 scoped_array<uint8> rgb_bytes_reference(new uint8[kRGBSize]); |
| 518 scoped_array<uint8> rgb_bytes_converted(new uint8[kRGBSize]); |
| 519 ReadYV12Data(&yuv_bytes); |
| 520 |
| 521 const int kWidth = 167; |
| 522 const int kSourceDx = 80000; // This value means a scale down. |
| 523 ScaleYUVToRGB32Row_C(yuv_bytes.get(), |
| 524 yuv_bytes.get() + kSourceUOffset, |
| 525 yuv_bytes.get() + kSourceVOffset, |
| 526 rgb_bytes_reference.get(), |
| 527 kWidth, |
| 528 kSourceDx); |
| 529 ScaleYUVToRGB32Row_MMX(yuv_bytes.get(), |
| 530 yuv_bytes.get() + kSourceUOffset, |
| 531 yuv_bytes.get() + kSourceVOffset, |
| 532 rgb_bytes_converted.get(), |
| 533 kWidth, |
| 534 kSourceDx); |
| 535 media::EmptyRegisterState(); |
| 536 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 537 rgb_bytes_converted.get(), |
| 538 kWidth * kBpp)); |
| 539 } |
| 540 |
| 541 TEST(YUVConvertTest, ScaleYUVToRGB32Row_SSE) { |
| 542 if (!media::hasSSE()) { |
| 543 LOG(WARNING) << "System not supported. Test skipped."; |
| 544 return; |
| 545 } |
| 546 |
| 547 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); |
| 548 scoped_array<uint8> rgb_bytes_reference(new uint8[kRGBSize]); |
| 549 scoped_array<uint8> rgb_bytes_converted(new uint8[kRGBSize]); |
| 550 ReadYV12Data(&yuv_bytes); |
| 551 |
| 552 const int kWidth = 167; |
| 553 const int kSourceDx = 80000; // This value means a scale down. |
| 554 ScaleYUVToRGB32Row_C(yuv_bytes.get(), |
| 555 yuv_bytes.get() + kSourceUOffset, |
| 556 yuv_bytes.get() + kSourceVOffset, |
| 557 rgb_bytes_reference.get(), |
| 558 kWidth, |
| 559 kSourceDx); |
| 560 ScaleYUVToRGB32Row_SSE(yuv_bytes.get(), |
| 561 yuv_bytes.get() + kSourceUOffset, |
| 562 yuv_bytes.get() + kSourceVOffset, |
| 563 rgb_bytes_converted.get(), |
| 564 kWidth, |
| 565 kSourceDx); |
| 566 media::EmptyRegisterState(); |
| 567 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 568 rgb_bytes_converted.get(), |
| 569 kWidth * kBpp)); |
| 570 } |
| 571 |
| 572 TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_MMX) { |
| 573 if (!media::hasMMX()) { |
| 574 LOG(WARNING) << "System not supported. Test skipped."; |
| 575 return; |
| 576 } |
| 577 |
| 578 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); |
| 579 scoped_array<uint8> rgb_bytes_reference(new uint8[kRGBSize]); |
| 580 scoped_array<uint8> rgb_bytes_converted(new uint8[kRGBSize]); |
| 581 ReadYV12Data(&yuv_bytes); |
| 582 |
| 583 const int kWidth = 167; |
| 584 const int kSourceDx = 80000; // This value means a scale down. |
| 585 LinearScaleYUVToRGB32Row_C(yuv_bytes.get(), |
| 586 yuv_bytes.get() + kSourceUOffset, |
| 587 yuv_bytes.get() + kSourceVOffset, |
| 588 rgb_bytes_reference.get(), |
| 589 kWidth, |
| 590 kSourceDx); |
| 591 LinearScaleYUVToRGB32Row_MMX(yuv_bytes.get(), |
| 592 yuv_bytes.get() + kSourceUOffset, |
| 593 yuv_bytes.get() + kSourceVOffset, |
| 594 rgb_bytes_converted.get(), |
| 595 kWidth, |
| 596 kSourceDx); |
| 597 media::EmptyRegisterState(); |
| 598 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 599 rgb_bytes_converted.get(), |
| 600 kWidth * kBpp)); |
| 601 } |
| 602 |
| 603 TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_SSE) { |
| 604 if (!media::hasSSE()) { |
| 605 LOG(WARNING) << "System not supported. Test skipped."; |
| 606 return; |
| 607 } |
| 608 |
| 609 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); |
| 610 scoped_array<uint8> rgb_bytes_reference(new uint8[kRGBSize]); |
| 611 scoped_array<uint8> rgb_bytes_converted(new uint8[kRGBSize]); |
| 612 ReadYV12Data(&yuv_bytes); |
| 613 |
| 614 const int kWidth = 167; |
| 615 const int kSourceDx = 80000; // This value means a scale down. |
| 616 LinearScaleYUVToRGB32Row_C(yuv_bytes.get(), |
| 617 yuv_bytes.get() + kSourceUOffset, |
| 618 yuv_bytes.get() + kSourceVOffset, |
| 619 rgb_bytes_reference.get(), |
| 620 kWidth, |
| 621 kSourceDx); |
| 622 LinearScaleYUVToRGB32Row_SSE(yuv_bytes.get(), |
| 623 yuv_bytes.get() + kSourceUOffset, |
| 624 yuv_bytes.get() + kSourceVOffset, |
| 625 rgb_bytes_converted.get(), |
| 626 kWidth, |
| 627 kSourceDx); |
| 628 media::EmptyRegisterState(); |
| 629 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 630 rgb_bytes_converted.get(), |
| 631 kWidth * kBpp)); |
| 632 } |
| 633 |
| 634 #if defined(ARCH_CPU_X86_64) |
| 635 |
| 636 TEST(YUVConvertTest, ScaleYUVToRGB32Row_SSE2_X64) { |
| 637 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); |
| 638 scoped_array<uint8> rgb_bytes_reference(new uint8[kRGBSize]); |
| 639 scoped_array<uint8> rgb_bytes_converted(new uint8[kRGBSize]); |
| 640 ReadYV12Data(&yuv_bytes); |
| 641 |
| 642 const int kWidth = 167; |
| 643 const int kSourceDx = 80000; // This value means a scale down. |
| 644 ScaleYUVToRGB32Row_C(yuv_bytes.get(), |
| 645 yuv_bytes.get() + kSourceUOffset, |
| 646 yuv_bytes.get() + kSourceVOffset, |
| 647 rgb_bytes_reference.get(), |
| 648 kWidth, |
| 649 kSourceDx); |
| 650 ScaleYUVToRGB32Row_SSE2_X64(yuv_bytes.get(), |
| 651 yuv_bytes.get() + kSourceUOffset, |
| 652 yuv_bytes.get() + kSourceVOffset, |
| 653 rgb_bytes_converted.get(), |
| 654 kWidth, |
| 655 kSourceDx); |
| 656 media::EmptyRegisterState(); |
| 657 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 658 rgb_bytes_converted.get(), |
| 659 kWidth * kBpp)); |
| 660 } |
| 661 |
| 662 TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_MMX_X64) { |
| 663 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); |
| 664 scoped_array<uint8> rgb_bytes_reference(new uint8[kRGBSize]); |
| 665 scoped_array<uint8> rgb_bytes_converted(new uint8[kRGBSize]); |
| 666 ReadYV12Data(&yuv_bytes); |
| 667 |
| 668 const int kWidth = 167; |
| 669 const int kSourceDx = 80000; // This value means a scale down. |
| 670 LinearScaleYUVToRGB32Row_C(yuv_bytes.get(), |
| 671 yuv_bytes.get() + kSourceUOffset, |
| 672 yuv_bytes.get() + kSourceVOffset, |
| 673 rgb_bytes_reference.get(), |
| 674 kWidth, |
| 675 kSourceDx); |
| 676 LinearScaleYUVToRGB32Row_MMX_X64(yuv_bytes.get(), |
| 677 yuv_bytes.get() + kSourceUOffset, |
| 678 yuv_bytes.get() + kSourceVOffset, |
| 679 rgb_bytes_converted.get(), |
| 680 kWidth, |
| 681 kSourceDx); |
| 682 media::EmptyRegisterState(); |
| 683 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 684 rgb_bytes_converted.get(), |
| 685 kWidth * kBpp)); |
| 686 } |
| 687 |
| 688 #endif // defined(ARCH_CPU_X86_64) |
| 689 |
| 690 #endif // defined(ARCH_CPU_X86_FAMILY) |
| OLD | NEW |