| OLD | NEW |
| 1 // Copyright (c) 2010 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/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" |
| 12 | 12 |
| 13 // Size of raw image. | 13 // Size of raw image. |
| 14 static const int kSourceWidth = 640; | 14 static const int kSourceWidth = 640; |
| 15 static const int kSourceHeight = 360; | 15 static const int kSourceHeight = 360; |
| 16 static const int kSourceYSize = kSourceWidth * kSourceHeight; | 16 static const int kSourceYSize = kSourceWidth * kSourceHeight; |
| 17 static const int kScaledWidth = 1024; | 17 static const int kScaledWidth = 1024; |
| 18 static const int kScaledHeight = 768; | 18 static const int kScaledHeight = 768; |
| 19 static const int kBpp = 4; | 19 static const int kBpp = 4; |
| 20 | 20 |
| 21 // Surface sizes. | 21 // Surface sizes. |
| 22 static const size_t kYUV12Size = kSourceYSize * 12 / 8; | 22 static const size_t kYUV12Size = kSourceYSize * 12 / 8; |
| 23 static const size_t kYUV16Size = kSourceYSize * 16 / 8; | 23 static const size_t kYUV16Size = kSourceYSize * 16 / 8; |
| 24 static const size_t kYUY2Size = kSourceYSize * 16 / 8; |
| 24 static const size_t kRGBSize = kSourceYSize * kBpp; | 25 static const size_t kRGBSize = kSourceYSize * kBpp; |
| 26 static const size_t kRGB24Size = kSourceYSize *3; |
| 25 static const size_t kRGBSizeConverted = kSourceYSize * kBpp; | 27 static const size_t kRGBSizeConverted = kSourceYSize * kBpp; |
| 26 | 28 |
| 27 TEST(YUVConvertTest, YV12) { | 29 TEST(YUVConvertTest, YV12) { |
| 28 // Allocate all surfaces. | 30 // Allocate all surfaces. |
| 29 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); | 31 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); |
| 30 scoped_array<uint8> rgb_bytes(new uint8[kRGBSize]); | 32 scoped_array<uint8> rgb_bytes(new uint8[kRGBSize]); |
| 31 scoped_array<uint8> rgb_converted_bytes(new uint8[kRGBSizeConverted]); | 33 scoped_array<uint8> rgb_converted_bytes(new uint8[kRGBSizeConverted]); |
| 32 | 34 |
| 33 // Read YUV reference data from file. | 35 // Read YUV reference data from file. |
| 34 FilePath yuv_url; | 36 FilePath yuv_url; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 &rgb[0], // RGB output | 264 &rgb[0], // RGB output |
| 263 1, 1, // Dimensions | 265 1, 1, // Dimensions |
| 264 0, // YStride | 266 0, // YStride |
| 265 0, // UVStride | 267 0, // UVStride |
| 266 0, // RGBStride | 268 0, // RGBStride |
| 267 media::YV12); | 269 media::YV12); |
| 268 | 270 |
| 269 int expected_test = memcmp(rgb, expected, sizeof(expected)); | 271 int expected_test = memcmp(rgb, expected, sizeof(expected)); |
| 270 EXPECT_EQ(0, expected_test); | 272 EXPECT_EQ(0, expected_test); |
| 271 } | 273 } |
| 274 |
| 275 TEST(YUVConvertTest, RGB24ToYUV) { |
| 276 // Allocate all surfaces. |
| 277 scoped_array<uint8> rgb_bytes(new uint8[kRGB24Size]); |
| 278 scoped_array<uint8> yuv_converted_bytes(new uint8[kYUV12Size]); |
| 279 |
| 280 // Read RGB24 reference data from file. |
| 281 FilePath rgb_url; |
| 282 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &rgb_url)); |
| 283 rgb_url = rgb_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_RGB24.rgb")); |
| 287 EXPECT_EQ(static_cast<int>(kRGB24Size), |
| 288 file_util::ReadFile(rgb_url, |
| 289 reinterpret_cast<char*>(rgb_bytes.get()), |
| 290 static_cast<int>(kRGB24Size))); |
| 291 |
| 292 |
| 293 // Convert to I420. |
| 294 media::ConvertRGB24ToYUV(rgb_bytes.get(), |
| 295 yuv_converted_bytes.get(), |
| 296 yuv_converted_bytes.get() + kSourceYSize, |
| 297 yuv_converted_bytes.get() + kSourceYSize * 5 / 4, |
| 298 kSourceWidth, kSourceHeight, // Dimensions |
| 299 kSourceWidth * 3, // RGBStride |
| 300 kSourceWidth, // YStride |
| 301 kSourceWidth / 2); // UVStride |
| 302 |
| 303 uint32 rgb_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, |
| 304 kDJB2HashSeed); |
| 305 EXPECT_EQ(1802801079u, rgb_hash); |
| 306 } |
| 307 |
| 308 TEST(YUVConvertTest, YUY2ToYUV) { |
| 309 // Allocate all surfaces. |
| 310 scoped_array<uint8> yuy_bytes(new uint8[kYUY2Size]); |
| 311 scoped_array<uint8> yuv_converted_bytes(new uint8[kYUV12Size]); |
| 312 |
| 313 // Read YUY reference data from file. |
| 314 FilePath yuy_url; |
| 315 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuy_url)); |
| 316 yuy_url = yuy_url.Append(FILE_PATH_LITERAL("media")) |
| 317 .Append(FILE_PATH_LITERAL("test")) |
| 318 .Append(FILE_PATH_LITERAL("data")) |
| 319 .Append(FILE_PATH_LITERAL("bali_640x360_YUY2.yuv")); |
| 320 EXPECT_EQ(static_cast<int>(kYUY2Size), |
| 321 file_util::ReadFile(yuy_url, |
| 322 reinterpret_cast<char*>(yuy_bytes.get()), |
| 323 static_cast<int>(kYUY2Size))); |
| 324 |
| 325 // Convert to I420. |
| 326 media::ConvertYUY2ToYUV(yuy_bytes.get(), |
| 327 yuv_converted_bytes.get(), |
| 328 yuv_converted_bytes.get() + kSourceYSize, |
| 329 yuv_converted_bytes.get() + kSourceYSize * 5 / 4, |
| 330 kSourceWidth, kSourceHeight); |
| 331 |
| 332 uint32 yuy_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, |
| 333 kDJB2HashSeed); |
| 334 EXPECT_EQ(666823187u, yuy_hash); |
| 335 } |
| OLD | NEW |