Chromium Code Reviews| Index: media/base/yuv_convert_unittest.cc |
| =================================================================== |
| --- media/base/yuv_convert_unittest.cc (revision 86049) |
| +++ media/base/yuv_convert_unittest.cc (working copy) |
| @@ -269,3 +269,119 @@ |
| int expected_test = memcmp(rgb, expected, sizeof(expected)); |
| EXPECT_EQ(0, expected_test); |
| } |
| + |
| +TEST(YUVConvertTest, RGB24ToYUV) { |
| + // Allocate all surfaces. |
| + scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); |
| + scoped_array<uint8> rgb_bytes(new uint8[kRGBSizeConverted]); |
| + scoped_array<uint8> rgb_converted_bytes(new uint8[kSourceYSize*3]); |
| + scoped_array<uint8> yuv_converted_bytes(new uint8[kYUV12Size]); |
| + |
| + // Read YUV reference data from file. |
| + FilePath yuv_url; |
| + EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); |
| + yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) |
| + .Append(FILE_PATH_LITERAL("test")) |
| + .Append(FILE_PATH_LITERAL("data")) |
| + .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); |
|
scherkus (not reviewing)
2011/05/26 05:33:14
I think it'd make more sense to check in RGB24 fil
Per K
2011/05/26 09:23:36
Done.
|
| + EXPECT_EQ(static_cast<int>(kYUV12Size), |
| + file_util::ReadFile(yuv_url, |
| + reinterpret_cast<char*>(yuv_bytes.get()), |
| + static_cast<int>(kYUV12Size))); |
| + |
| + // Convert a frame of YUV to 32 bit ARGB. |
| + media::ConvertYUVToRGB32(yuv_bytes.get(), |
| + yuv_bytes.get() + kSourceYSize, |
| + yuv_bytes.get() + kSourceYSize * 5 / 4, |
| + rgb_bytes.get(), // RGB output |
| + kSourceWidth, kSourceHeight, // Dimensions |
| + kSourceWidth, // YStride |
| + kSourceWidth / 2, // UVStride |
| + kSourceWidth * kBpp, // RGBStride |
| + media::YV12); |
| + |
| + // Convert from RGB32 to RGB24. |
| + uint8* rgb_32ptr = rgb_bytes.get(); |
| + uint8* rgb_24ptr = rgb_converted_bytes.get(); |
| + for (int j = 0; j < kSourceWidth * kSourceHeight; ++j) { // For each pixel |
| + for (int i = 0; i < 3; ++i) { // Copy each color byte. |
| + *rgb_24ptr++=*rgb_32ptr++; |
| + } |
| + ++rgb_32ptr; // Skip the alpha channel |
| + } |
| + |
| + // Convert back to I420. |
| + media::ConvertRGB24ToYUV(rgb_converted_bytes.get(), |
| + yuv_converted_bytes.get(), |
| + yuv_converted_bytes.get() + kSourceYSize, |
| + yuv_converted_bytes.get() + kSourceYSize * 5 / 4, |
| + kSourceWidth, kSourceHeight, // Dimensions |
| + kSourceWidth * 3, // RGBStride |
| + kSourceWidth, // YStride |
| + kSourceWidth / 2); // UVStride |
| + |
| + uint32 rgb_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, |
| + kDJB2HashSeed); |
| + |
| + EXPECT_EQ(1802801079u, rgb_hash); |
| +} |
| + |
| +TEST(YUVConvertTest, YUY2ToYUV) { |
| + // Allocate all surfaces. |
| + scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); |
| + scoped_array<uint8> yuy_converted_bytes(new uint8[kYUV16Size]); |
| + scoped_array<uint8> yuv_converted_bytes(new uint8[kYUV12Size]); |
| + |
| + // Read YUV reference data from file. |
| + FilePath yuv_url; |
| + EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); |
| + yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) |
| + .Append(FILE_PATH_LITERAL("test")) |
| + .Append(FILE_PATH_LITERAL("data")) |
| + .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); |
| + EXPECT_EQ(static_cast<int>(kYUV12Size), |
| + file_util::ReadFile(yuv_url, |
| + reinterpret_cast<char*>(yuv_bytes.get()), |
| + static_cast<int>(kYUV12Size))); |
| + |
| + uint32 yuv_hash = DJB2Hash(yuv_bytes.get(), kYUV12Size, |
| + kDJB2HashSeed); |
| + |
| + // Convert from YUV to YUY. |
|
scherkus (not reviewing)
2011/05/26 05:33:14
ditto for a YUY2 file
Per K
2011/05/26 09:23:36
Done.
|
| + uint8* yuy_ptr = yuy_converted_bytes.get(); |
| + uint8* yplane = yuv_bytes.get(); |
| + uint8* uplane = yuv_bytes.get() + kSourceYSize; |
| + uint8* vplane = yuv_bytes.get() + kSourceYSize * 5 / 4; |
| + for (int i = 0; i < kSourceHeight / 2; ++i) { |
| + for (int j = 0; j < (kSourceWidth / 2); ++j) { |
| + yuy_ptr[0] = yplane[0]; |
| + yuy_ptr[1] = *uplane; |
| + yuy_ptr[2] = yplane[1]; |
| + yuy_ptr[3] = *vplane; |
| + yuy_ptr += 4; |
| + yplane += 2; |
| + uplane++; |
| + vplane++; |
| + } |
| + for (int j = 0; j < (kSourceWidth / 2); ++j) { |
| + yuy_ptr[0] = yplane[0]; |
| + yuy_ptr[1] = 0xff; |
| + yuy_ptr[2] = yplane[1]; |
| + yuy_ptr[3] = 0xff; |
| + yuy_ptr += 4; |
| + yplane += 2; |
| + } |
| + } |
| + |
| + // Convert back to I420. |
| + media::ConvertYUY2ToYUV(yuy_converted_bytes.get(), |
| + yuv_converted_bytes.get(), |
| + yuv_converted_bytes.get() + kSourceYSize, |
| + yuv_converted_bytes.get() + kSourceYSize * 5 / 4, |
| + kSourceWidth, kSourceHeight); |
| + |
| + uint32 yuy_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, |
| + kDJB2HashSeed); |
| + |
| + EXPECT_EQ(yuv_hash, yuy_hash); |
| +} |