Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
|
scherkus (not reviewing)
2011/05/26 05:33:14
copyright year
Per K
2011/05/26 09:23:36
Done.
| |
| 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/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "media/base/djb2.h" | 8 #include "media/base/djb2.h" |
| 9 #include "media/base/yuv_convert.h" | 9 #include "media/base/yuv_convert.h" |
| 10 #include "media/base/yuv_row.h" | 10 #include "media/base/yuv_row.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 &rgb[0], // RGB output | 262 &rgb[0], // RGB output |
| 263 1, 1, // Dimensions | 263 1, 1, // Dimensions |
| 264 0, // YStride | 264 0, // YStride |
| 265 0, // UVStride | 265 0, // UVStride |
| 266 0, // RGBStride | 266 0, // RGBStride |
| 267 media::YV12); | 267 media::YV12); |
| 268 | 268 |
| 269 int expected_test = memcmp(rgb, expected, sizeof(expected)); | 269 int expected_test = memcmp(rgb, expected, sizeof(expected)); |
| 270 EXPECT_EQ(0, expected_test); | 270 EXPECT_EQ(0, expected_test); |
| 271 } | 271 } |
| 272 | |
| 273 TEST(YUVConvertTest, RGB24ToYUV) { | |
| 274 // Allocate all surfaces. | |
| 275 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); | |
| 276 scoped_array<uint8> rgb_bytes(new uint8[kRGBSizeConverted]); | |
| 277 scoped_array<uint8> rgb_converted_bytes(new uint8[kSourceYSize*3]); | |
| 278 scoped_array<uint8> yuv_converted_bytes(new uint8[kYUV12Size]); | |
| 279 | |
| 280 // Read YUV reference data from file. | |
| 281 FilePath yuv_url; | |
| 282 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); | |
| 283 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) | |
| 284 .Append(FILE_PATH_LITERAL("test")) | |
| 285 .Append(FILE_PATH_LITERAL("data")) | |
| 286 .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.
| |
| 287 EXPECT_EQ(static_cast<int>(kYUV12Size), | |
| 288 file_util::ReadFile(yuv_url, | |
| 289 reinterpret_cast<char*>(yuv_bytes.get()), | |
| 290 static_cast<int>(kYUV12Size))); | |
| 291 | |
| 292 // Convert a frame of YUV to 32 bit ARGB. | |
| 293 media::ConvertYUVToRGB32(yuv_bytes.get(), | |
| 294 yuv_bytes.get() + kSourceYSize, | |
| 295 yuv_bytes.get() + kSourceYSize * 5 / 4, | |
| 296 rgb_bytes.get(), // RGB output | |
| 297 kSourceWidth, kSourceHeight, // Dimensions | |
| 298 kSourceWidth, // YStride | |
| 299 kSourceWidth / 2, // UVStride | |
| 300 kSourceWidth * kBpp, // RGBStride | |
| 301 media::YV12); | |
| 302 | |
| 303 // Convert from RGB32 to RGB24. | |
| 304 uint8* rgb_32ptr = rgb_bytes.get(); | |
| 305 uint8* rgb_24ptr = rgb_converted_bytes.get(); | |
| 306 for (int j = 0; j < kSourceWidth * kSourceHeight; ++j) { // For each pixel | |
| 307 for (int i = 0; i < 3; ++i) { // Copy each color byte. | |
| 308 *rgb_24ptr++=*rgb_32ptr++; | |
| 309 } | |
| 310 ++rgb_32ptr; // Skip the alpha channel | |
| 311 } | |
| 312 | |
| 313 // Convert back to I420. | |
| 314 media::ConvertRGB24ToYUV(rgb_converted_bytes.get(), | |
| 315 yuv_converted_bytes.get(), | |
| 316 yuv_converted_bytes.get() + kSourceYSize, | |
| 317 yuv_converted_bytes.get() + kSourceYSize * 5 / 4, | |
| 318 kSourceWidth, kSourceHeight, // Dimensions | |
| 319 kSourceWidth * 3, // RGBStride | |
| 320 kSourceWidth, // YStride | |
| 321 kSourceWidth / 2); // UVStride | |
| 322 | |
| 323 uint32 rgb_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, | |
| 324 kDJB2HashSeed); | |
| 325 | |
| 326 EXPECT_EQ(1802801079u, rgb_hash); | |
| 327 } | |
| 328 | |
| 329 TEST(YUVConvertTest, YUY2ToYUV) { | |
| 330 // Allocate all surfaces. | |
| 331 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); | |
| 332 scoped_array<uint8> yuy_converted_bytes(new uint8[kYUV16Size]); | |
| 333 scoped_array<uint8> yuv_converted_bytes(new uint8[kYUV12Size]); | |
| 334 | |
| 335 // Read YUV reference data from file. | |
| 336 FilePath yuv_url; | |
| 337 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); | |
| 338 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) | |
| 339 .Append(FILE_PATH_LITERAL("test")) | |
| 340 .Append(FILE_PATH_LITERAL("data")) | |
| 341 .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); | |
| 342 EXPECT_EQ(static_cast<int>(kYUV12Size), | |
| 343 file_util::ReadFile(yuv_url, | |
| 344 reinterpret_cast<char*>(yuv_bytes.get()), | |
| 345 static_cast<int>(kYUV12Size))); | |
| 346 | |
| 347 uint32 yuv_hash = DJB2Hash(yuv_bytes.get(), kYUV12Size, | |
| 348 kDJB2HashSeed); | |
| 349 | |
| 350 // 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.
| |
| 351 uint8* yuy_ptr = yuy_converted_bytes.get(); | |
| 352 uint8* yplane = yuv_bytes.get(); | |
| 353 uint8* uplane = yuv_bytes.get() + kSourceYSize; | |
| 354 uint8* vplane = yuv_bytes.get() + kSourceYSize * 5 / 4; | |
| 355 for (int i = 0; i < kSourceHeight / 2; ++i) { | |
| 356 for (int j = 0; j < (kSourceWidth / 2); ++j) { | |
| 357 yuy_ptr[0] = yplane[0]; | |
| 358 yuy_ptr[1] = *uplane; | |
| 359 yuy_ptr[2] = yplane[1]; | |
| 360 yuy_ptr[3] = *vplane; | |
| 361 yuy_ptr += 4; | |
| 362 yplane += 2; | |
| 363 uplane++; | |
| 364 vplane++; | |
| 365 } | |
| 366 for (int j = 0; j < (kSourceWidth / 2); ++j) { | |
| 367 yuy_ptr[0] = yplane[0]; | |
| 368 yuy_ptr[1] = 0xff; | |
| 369 yuy_ptr[2] = yplane[1]; | |
| 370 yuy_ptr[3] = 0xff; | |
| 371 yuy_ptr += 4; | |
| 372 yplane += 2; | |
| 373 } | |
| 374 } | |
| 375 | |
| 376 // Convert back to I420. | |
| 377 media::ConvertYUY2ToYUV(yuy_converted_bytes.get(), | |
| 378 yuv_converted_bytes.get(), | |
| 379 yuv_converted_bytes.get() + kSourceYSize, | |
| 380 yuv_converted_bytes.get() + kSourceYSize * 5 / 4, | |
| 381 kSourceWidth, kSourceHeight); | |
| 382 | |
| 383 uint32 yuy_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, | |
| 384 kDJB2HashSeed); | |
| 385 | |
| 386 EXPECT_EQ(yuv_hash, yuy_hash); | |
| 387 } | |
| OLD | NEW |