OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/cpu.h" | 6 #include "base/cpu.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "media/base/djb2.h" | 10 #include "media/base/djb2.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 // Surface sizes for various test files. | 31 // Surface sizes for various test files. |
32 static const int kYUV12Size = kSourceYSize * 12 / 8; | 32 static const int kYUV12Size = kSourceYSize * 12 / 8; |
33 static const int kYUV16Size = kSourceYSize * 16 / 8; | 33 static const int kYUV16Size = kSourceYSize * 16 / 8; |
34 static const int kYUY2Size = kSourceYSize * 16 / 8; | 34 static const int kYUY2Size = kSourceYSize * 16 / 8; |
35 static const int kRGBSize = kSourceYSize * kBpp; | 35 static const int kRGBSize = kSourceYSize * kBpp; |
36 static const int kRGBSizeScaled = kScaledWidth * kScaledHeight * kBpp; | 36 static const int kRGBSizeScaled = kScaledWidth * kScaledHeight * kBpp; |
37 static const int kRGB24Size = kSourceYSize * 3; | 37 static const int kRGB24Size = kSourceYSize * 3; |
38 static const int kRGBSizeConverted = kSourceYSize * kBpp; | 38 static const int kRGBSizeConverted = kSourceYSize * kBpp; |
39 | 39 |
| 40 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) |
| 41 static const int kSourceAOffset = kSourceYSize * 12 / 8; |
| 42 static const int kYUVA12Size = kSourceYSize * 20 / 8; |
| 43 #endif |
| 44 |
40 // Helper for reading test data into a scoped_ptr<uint8[]>. | 45 // Helper for reading test data into a scoped_ptr<uint8[]>. |
41 static void ReadData(const base::FilePath::CharType* filename, | 46 static void ReadData(const base::FilePath::CharType* filename, |
42 int expected_size, | 47 int expected_size, |
43 scoped_ptr<uint8[]>* data) { | 48 scoped_ptr<uint8[]>* data) { |
44 data->reset(new uint8[expected_size]); | 49 data->reset(new uint8[expected_size]); |
45 | 50 |
46 base::FilePath path; | 51 base::FilePath path; |
47 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &path)); | 52 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &path)); |
48 path = path.Append(FILE_PATH_LITERAL("media")) | 53 path = path.Append(FILE_PATH_LITERAL("media")) |
49 .Append(FILE_PATH_LITERAL("test")) | 54 .Append(FILE_PATH_LITERAL("test")) |
(...skipping 12 matching lines...) Expand all Loading... |
62 } | 67 } |
63 | 68 |
64 static void ReadYV12Data(scoped_ptr<uint8[]>* data) { | 69 static void ReadYV12Data(scoped_ptr<uint8[]>* data) { |
65 ReadData(FILE_PATH_LITERAL("bali_640x360_P420.yuv"), kYUV12Size, data); | 70 ReadData(FILE_PATH_LITERAL("bali_640x360_P420.yuv"), kYUV12Size, data); |
66 } | 71 } |
67 | 72 |
68 static void ReadYV16Data(scoped_ptr<uint8[]>* data) { | 73 static void ReadYV16Data(scoped_ptr<uint8[]>* data) { |
69 ReadData(FILE_PATH_LITERAL("bali_640x360_P422.yuv"), kYUV16Size, data); | 74 ReadData(FILE_PATH_LITERAL("bali_640x360_P422.yuv"), kYUV16Size, data); |
70 } | 75 } |
71 | 76 |
| 77 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) |
| 78 static void ReadYV12AData(scoped_ptr<uint8[]>* data) { |
| 79 ReadData(FILE_PATH_LITERAL("bali_640x360_P420_alpha.yuv"), kYUVA12Size, data); |
| 80 } |
| 81 #endif |
| 82 |
72 static void ReadRGB24Data(scoped_ptr<uint8[]>* data) { | 83 static void ReadRGB24Data(scoped_ptr<uint8[]>* data) { |
73 ReadData(FILE_PATH_LITERAL("bali_640x360_RGB24.rgb"), kRGB24Size, data); | 84 ReadData(FILE_PATH_LITERAL("bali_640x360_RGB24.rgb"), kRGB24Size, data); |
74 } | 85 } |
75 | 86 |
76 static void ReadYUY2Data(scoped_ptr<uint8[]>* data) { | 87 static void ReadYUY2Data(scoped_ptr<uint8[]>* data) { |
77 ReadData(FILE_PATH_LITERAL("bali_640x360_YUY2.yuv"), kYUY2Size, data); | 88 ReadData(FILE_PATH_LITERAL("bali_640x360_YUY2.yuv"), kYUY2Size, data); |
78 } | 89 } |
79 | 90 |
80 #if defined(OS_ANDROID) | 91 #if defined(OS_ANDROID) |
81 // Helper for swapping red and blue channels of RGBA or BGRA. | 92 // Helper for swapping red and blue channels of RGBA or BGRA. |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 sub_rect.set_x(sub_rect.x() + sub_rect.width() / 2); | 521 sub_rect.set_x(sub_rect.x() + sub_rect.width() / 2); |
511 if (next_sub_rect & 2) | 522 if (next_sub_rect & 2) |
512 sub_rect.set_y(sub_rect.y() + sub_rect.height() / 2); | 523 sub_rect.set_y(sub_rect.y() + sub_rect.height() / 2); |
513 sub_rect.set_width(sub_rect.width() / 2); | 524 sub_rect.set_width(sub_rect.width() / 2); |
514 sub_rect.set_height(sub_rect.height() / 2); | 525 sub_rect.set_height(sub_rect.height() / 2); |
515 next_sub_rect++; | 526 next_sub_rect++; |
516 } | 527 } |
517 } | 528 } |
518 | 529 |
519 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) | 530 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) |
| 531 TEST(YUVConvertTest, YUVAtoARGB_MMX_MatchReference) { |
| 532 // Allocate all surfaces. |
| 533 scoped_ptr<uint8[]> yuv_bytes; |
| 534 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); |
| 535 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSizeConverted]); |
| 536 scoped_ptr<uint8[]> rgb_converted_bytes_ref(new uint8[kRGBSizeConverted]); |
| 537 |
| 538 // Read YUV reference data from file. |
| 539 ReadYV12AData(&yuv_bytes); |
| 540 |
| 541 // Convert a frame of YUV to 32 bit ARGB using both C and MMX versions. |
| 542 media::ConvertYUVAToARGB_C(yuv_bytes.get(), |
| 543 yuv_bytes.get() + kSourceUOffset, |
| 544 yuv_bytes.get() + kSourceVOffset, |
| 545 yuv_bytes.get() + kSourceAOffset, |
| 546 rgb_converted_bytes_ref.get(), |
| 547 kSourceWidth, |
| 548 kSourceHeight, |
| 549 kSourceWidth, |
| 550 kSourceWidth / 2, |
| 551 kSourceWidth, |
| 552 kSourceWidth * kBpp, |
| 553 media::YV12); |
| 554 media::ConvertYUVAToARGB_MMX(yuv_bytes.get(), |
| 555 yuv_bytes.get() + kSourceUOffset, |
| 556 yuv_bytes.get() + kSourceVOffset, |
| 557 yuv_bytes.get() + kSourceAOffset, |
| 558 rgb_converted_bytes.get(), |
| 559 kSourceWidth, |
| 560 kSourceHeight, |
| 561 kSourceWidth, |
| 562 kSourceWidth / 2, |
| 563 kSourceWidth, |
| 564 kSourceWidth * kBpp, |
| 565 media::YV12); |
| 566 |
| 567 EXPECT_EQ(0, |
| 568 memcmp(rgb_converted_bytes.get(), |
| 569 rgb_converted_bytes_ref.get(), |
| 570 kRGBSizeConverted)); |
| 571 } |
| 572 |
520 TEST(YUVConvertTest, RGB32ToYUV_SSE2_MatchReference) { | 573 TEST(YUVConvertTest, RGB32ToYUV_SSE2_MatchReference) { |
521 base::CPU cpu; | 574 base::CPU cpu; |
522 if (!cpu.has_sse2()) { | 575 if (!cpu.has_sse2()) { |
523 LOG(WARNING) << "System doesn't support SSE2, test not executed."; | 576 LOG(WARNING) << "System doesn't support SSE2, test not executed."; |
524 return; | 577 return; |
525 } | 578 } |
526 | 579 |
527 // Allocate all surfaces. | 580 // Allocate all surfaces. |
528 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); | 581 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); |
529 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); | 582 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | 1033 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
981 rgb_bytes_converted.get(), | 1034 rgb_bytes_converted.get(), |
982 kWidth * kBpp)); | 1035 kWidth * kBpp)); |
983 } | 1036 } |
984 | 1037 |
985 #endif // defined(ARCH_CPU_X86_64) | 1038 #endif // defined(ARCH_CPU_X86_64) |
986 | 1039 |
987 #endif // defined(ARCH_CPU_X86_FAMILY) | 1040 #endif // defined(ARCH_CPU_X86_FAMILY) |
988 | 1041 |
989 } // namespace media | 1042 } // namespace media |
OLD | NEW |