| OLD | NEW |
| 1 // Copyright (c) 2011 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/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_rgb_to_yuv.h" | 11 #include "media/base/simd/convert_rgb_to_yuv.h" |
| 12 #include "media/base/simd/convert_yuv_to_rgb.h" | 12 #include "media/base/simd/convert_yuv_to_rgb.h" |
| 13 #include "media/base/simd/filter_yuv.h" | 13 #include "media/base/simd/filter_yuv.h" |
| 14 #include "media/base/yuv_convert.h" | 14 #include "media/base/yuv_convert.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "ui/gfx/rect.h" |
| 16 | 17 |
| 17 // Size of raw image. | 18 // Size of raw image. |
| 18 static const int kSourceWidth = 640; | 19 static const int kSourceWidth = 640; |
| 19 static const int kSourceHeight = 360; | 20 static const int kSourceHeight = 360; |
| 20 static const int kSourceYSize = kSourceWidth * kSourceHeight; | 21 static const int kSourceYSize = kSourceWidth * kSourceHeight; |
| 21 static const int kSourceUOffset = kSourceYSize; | 22 static const int kSourceUOffset = kSourceYSize; |
| 22 static const int kSourceVOffset = kSourceYSize * 5 / 4; | 23 static const int kSourceVOffset = kSourceYSize * 5 / 4; |
| 23 static const int kScaledWidth = 1024; | 24 static const int kScaledWidth = 1024; |
| 24 static const int kScaledHeight = 768; | 25 static const int kScaledHeight = 768; |
| 26 static const int kDownScaledWidth = 512; |
| 27 static const int kDownScaledHeight = 320; |
| 25 static const int kBpp = 4; | 28 static const int kBpp = 4; |
| 26 | 29 |
| 27 // Surface sizes for various test files. | 30 // Surface sizes for various test files. |
| 28 static const int kYUV12Size = kSourceYSize * 12 / 8; | 31 static const int kYUV12Size = kSourceYSize * 12 / 8; |
| 29 static const int kYUV16Size = kSourceYSize * 16 / 8; | 32 static const int kYUV16Size = kSourceYSize * 16 / 8; |
| 30 static const int kYUY2Size = kSourceYSize * 16 / 8; | 33 static const int kYUY2Size = kSourceYSize * 16 / 8; |
| 31 static const int kRGBSize = kSourceYSize * kBpp; | 34 static const int kRGBSize = kSourceYSize * kBpp; |
| 32 static const int kRGBSizeScaled = kScaledWidth * kScaledHeight * kBpp; | 35 static const int kRGBSizeScaled = kScaledWidth * kScaledHeight * kBpp; |
| 33 static const int kRGB24Size = kSourceYSize * 3; | 36 static const int kRGB24Size = kSourceYSize * 3; |
| 34 static const int kRGBSizeConverted = kSourceYSize * kBpp; | 37 static const int kRGBSizeConverted = kSourceYSize * kBpp; |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 yuv_converted_bytes.get(), | 375 yuv_converted_bytes.get(), |
| 373 yuv_converted_bytes.get() + kSourceUOffset, | 376 yuv_converted_bytes.get() + kSourceUOffset, |
| 374 yuv_converted_bytes.get() + kSourceVOffset, | 377 yuv_converted_bytes.get() + kSourceVOffset, |
| 375 kSourceWidth, kSourceHeight); | 378 kSourceWidth, kSourceHeight); |
| 376 | 379 |
| 377 uint32 yuy_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, | 380 uint32 yuy_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, |
| 378 kDJB2HashSeed); | 381 kDJB2HashSeed); |
| 379 EXPECT_EQ(666823187u, yuy_hash); | 382 EXPECT_EQ(666823187u, yuy_hash); |
| 380 } | 383 } |
| 381 | 384 |
| 385 TEST(YUVConvertTest, DownScaleYUVToRGB32WithRect) { |
| 386 // Read YUV reference data from file. |
| 387 FilePath yuv_url; |
| 388 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); |
| 389 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) |
| 390 .Append(FILE_PATH_LITERAL("test")) |
| 391 .Append(FILE_PATH_LITERAL("data")) |
| 392 .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); |
| 393 const size_t size_of_yuv = kSourceYSize * 12 / 8; // 12 bpp. |
| 394 scoped_array<uint8> yuv_bytes(new uint8[size_of_yuv]); |
| 395 EXPECT_EQ(static_cast<int>(size_of_yuv), |
| 396 file_util::ReadFile(yuv_url, |
| 397 reinterpret_cast<char*>(yuv_bytes.get()), |
| 398 static_cast<int>(size_of_yuv))); |
| 399 |
| 400 // Scale the full frame of YUV to 32 bit ARGB. |
| 401 // The API currently only supports down-scaling, so we don't test up-scaling. |
| 402 const size_t size_of_rgb_scaled = kDownScaledWidth * kDownScaledHeight * kBpp; |
| 403 scoped_array<uint8> rgb_scaled_bytes(new uint8[size_of_rgb_scaled]); |
| 404 gfx::Rect sub_rect(0, 0, kDownScaledWidth, kDownScaledHeight); |
| 405 |
| 406 // We can't compare with the full-frame scaler because it uses slightly |
| 407 // different sampling coordinates. |
| 408 media::ScaleYUVToRGB32WithRect( |
| 409 yuv_bytes.get(), // Y |
| 410 yuv_bytes.get() + kSourceUOffset, // U |
| 411 yuv_bytes.get() + kSourceVOffset, // V |
| 412 rgb_scaled_bytes.get(), // Rgb output |
| 413 kSourceWidth, kSourceHeight, // Dimensions |
| 414 kDownScaledWidth, kDownScaledHeight, // Dimensions |
| 415 sub_rect.x(), sub_rect.y(), // Dest rect |
| 416 sub_rect.right(), sub_rect.bottom(), // Dest rect |
| 417 kSourceWidth, // YStride |
| 418 kSourceWidth / 2, // UvStride |
| 419 kDownScaledWidth * kBpp); // RgbStride |
| 420 |
| 421 uint32 rgb_hash_full_rect = DJB2Hash(rgb_scaled_bytes.get(), |
| 422 size_of_rgb_scaled, |
| 423 kDJB2HashSeed); |
| 424 |
| 425 // Re-scale sub-rectangles and verify the results are the same. |
| 426 int next_sub_rect = 0; |
| 427 while (!sub_rect.IsEmpty()) { |
| 428 // Scale a partial rectangle. |
| 429 media::ScaleYUVToRGB32WithRect( |
| 430 yuv_bytes.get(), // Y |
| 431 yuv_bytes.get() + kSourceUOffset, // U |
| 432 yuv_bytes.get() + kSourceVOffset, // V |
| 433 rgb_scaled_bytes.get(), // Rgb output |
| 434 kSourceWidth, kSourceHeight, // Dimensions |
| 435 kDownScaledWidth, kDownScaledHeight, // Dimensions |
| 436 sub_rect.x(), sub_rect.y(), // Dest rect |
| 437 sub_rect.right(), sub_rect.bottom(), // Dest rect |
| 438 kSourceWidth, // YStride |
| 439 kSourceWidth / 2, // UvStride |
| 440 kDownScaledWidth * kBpp); // RgbStride |
| 441 uint32 rgb_hash_sub_rect = DJB2Hash(rgb_scaled_bytes.get(), |
| 442 size_of_rgb_scaled, |
| 443 kDJB2HashSeed); |
| 444 |
| 445 EXPECT_EQ(rgb_hash_full_rect, rgb_hash_sub_rect); |
| 446 |
| 447 // Now pick choose a quarter rect of this sub-rect. |
| 448 if (next_sub_rect & 1) |
| 449 sub_rect.set_x(sub_rect.x() + sub_rect.width() / 2); |
| 450 if (next_sub_rect & 2) |
| 451 sub_rect.set_y(sub_rect.y() + sub_rect.height() / 2); |
| 452 sub_rect.set_width(sub_rect.width() / 2); |
| 453 sub_rect.set_height(sub_rect.height() / 2); |
| 454 next_sub_rect++; |
| 455 } |
| 456 } |
| 457 |
| 382 #if !defined(ARCH_CPU_ARM_FAMILY) | 458 #if !defined(ARCH_CPU_ARM_FAMILY) |
| 383 TEST(YUVConvertTest, RGB32ToYUV_SSE2_MatchReference) { | 459 TEST(YUVConvertTest, RGB32ToYUV_SSE2_MatchReference) { |
| 384 if (!media::hasSSE2()) { | 460 if (!media::hasSSE2()) { |
| 385 LOG(WARNING) << "System doesn't support SSE2, test not executed."; | 461 LOG(WARNING) << "System doesn't support SSE2, test not executed."; |
| 386 return; | 462 return; |
| 387 } | 463 } |
| 388 | 464 |
| 389 // Allocate all surfaces. | 465 // Allocate all surfaces. |
| 390 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); | 466 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); |
| 391 scoped_array<uint8> rgb_bytes(new uint8[kRGBSize]); | 467 scoped_array<uint8> rgb_bytes(new uint8[kRGBSize]); |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 kSourceDx); | 886 kSourceDx); |
| 811 media::EmptyRegisterState(); | 887 media::EmptyRegisterState(); |
| 812 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | 888 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 813 rgb_bytes_converted.get(), | 889 rgb_bytes_converted.get(), |
| 814 kWidth * kBpp)); | 890 kWidth * kBpp)); |
| 815 } | 891 } |
| 816 | 892 |
| 817 #endif // defined(ARCH_CPU_X86_64) | 893 #endif // defined(ARCH_CPU_X86_64) |
| 818 | 894 |
| 819 #endif // defined(ARCH_CPU_X86_FAMILY) | 895 #endif // defined(ARCH_CPU_X86_FAMILY) |
| OLD | NEW |