Chromium Code Reviews| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 yuv_bytes.get() + kSourceVOffset, | 93 yuv_bytes.get() + kSourceVOffset, |
| 94 rgb_converted_bytes.get(), // RGB output | 94 rgb_converted_bytes.get(), // RGB output |
| 95 kSourceWidth, kSourceHeight, // Dimensions | 95 kSourceWidth, kSourceHeight, // Dimensions |
| 96 kSourceWidth, // YStride | 96 kSourceWidth, // YStride |
| 97 kSourceWidth / 2, // UVStride | 97 kSourceWidth / 2, // UVStride |
| 98 kSourceWidth * kBpp, // RGBStride | 98 kSourceWidth * kBpp, // RGBStride |
| 99 media::YV12); | 99 media::YV12); |
| 100 | 100 |
| 101 uint32 rgb_hash = DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted, | 101 uint32 rgb_hash = DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted, |
| 102 kDJB2HashSeed); | 102 kDJB2HashSeed); |
| 103 #if defined(OS_ANDROID) | |
| 104 EXPECT_EQ(815021082u, rgb_hash); | |
|
scherkus (not reviewing)
2013/06/19 19:49:50
what about writing and using a BGRA->RGBA swizzler
hkuang1
2013/06/19 23:21:11
Done. Wrote a helper function to convert BGRA->RGB
| |
| 105 #else | |
| 103 EXPECT_EQ(2413171226u, rgb_hash); | 106 EXPECT_EQ(2413171226u, rgb_hash); |
| 107 #endif | |
| 104 } | 108 } |
| 105 | 109 |
| 106 TEST(YUVConvertTest, YV16) { | 110 TEST(YUVConvertTest, YV16) { |
| 107 // Allocate all surfaces. | 111 // Allocate all surfaces. |
| 108 scoped_ptr<uint8[]> yuv_bytes; | 112 scoped_ptr<uint8[]> yuv_bytes; |
| 109 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); | 113 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); |
| 110 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSizeConverted]); | 114 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSizeConverted]); |
| 111 | 115 |
| 112 // Read YUV reference data from file. | 116 // Read YUV reference data from file. |
| 113 ReadYV16Data(&yuv_bytes); | 117 ReadYV16Data(&yuv_bytes); |
| 114 | 118 |
| 115 // Convert a frame of YUV to 32 bit ARGB. | 119 // Convert a frame of YUV to 32 bit ARGB. |
| 116 media::ConvertYUVToRGB32(yuv_bytes.get(), // Y | 120 media::ConvertYUVToRGB32(yuv_bytes.get(), // Y |
| 117 yuv_bytes.get() + kSourceUOffset, // U | 121 yuv_bytes.get() + kSourceUOffset, // U |
| 118 yuv_bytes.get() + kSourceYSize * 3 / 2, // V | 122 yuv_bytes.get() + kSourceYSize * 3 / 2, // V |
| 119 rgb_converted_bytes.get(), // RGB output | 123 rgb_converted_bytes.get(), // RGB output |
| 120 kSourceWidth, kSourceHeight, // Dimensions | 124 kSourceWidth, kSourceHeight, // Dimensions |
| 121 kSourceWidth, // YStride | 125 kSourceWidth, // YStride |
| 122 kSourceWidth / 2, // UVStride | 126 kSourceWidth / 2, // UVStride |
| 123 kSourceWidth * kBpp, // RGBStride | 127 kSourceWidth * kBpp, // RGBStride |
| 124 media::YV16); | 128 media::YV16); |
| 125 | 129 |
| 126 uint32 rgb_hash = DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted, | 130 uint32 rgb_hash = DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted, |
| 127 kDJB2HashSeed); | 131 kDJB2HashSeed); |
| 132 #if defined(OS_ANDROID) | |
| 133 EXPECT_EQ(3370743199u, rgb_hash); | |
| 134 #else | |
| 128 EXPECT_EQ(4222342047u, rgb_hash); | 135 EXPECT_EQ(4222342047u, rgb_hash); |
| 136 #endif | |
| 129 } | 137 } |
| 130 | 138 |
| 131 struct YUVScaleTestData { | 139 struct YUVScaleTestData { |
| 132 YUVScaleTestData(media::YUVType y, media::ScaleFilter s, uint32 r) | 140 YUVScaleTestData(media::YUVType y, media::ScaleFilter s, uint32 r) |
| 133 : yuv_type(y), | 141 : yuv_type(y), |
| 134 scale_filter(s), | 142 scale_filter(s), |
| 135 rgb_hash(r) { | 143 rgb_hash(r) { |
| 136 } | 144 } |
| 137 | 145 |
| 138 media::YUVType yuv_type; | 146 media::YUVType yuv_type; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 kSourceWidth, kSourceHeight, // Dimensions | 271 kSourceWidth, kSourceHeight, // Dimensions |
| 264 3, 3, // Dimensions | 272 3, 3, // Dimensions |
| 265 kSourceWidth, // YStride | 273 kSourceWidth, // YStride |
| 266 kSourceWidth / 2, // UvStride | 274 kSourceWidth / 2, // UvStride |
| 267 kScaledWidth * kBpp, // RgbStride | 275 kScaledWidth * kBpp, // RgbStride |
| 268 GetParam().yuv_type, | 276 GetParam().yuv_type, |
| 269 media::ROTATE_0, | 277 media::ROTATE_0, |
| 270 GetParam().scale_filter); | 278 GetParam().scale_filter); |
| 271 } | 279 } |
| 272 | 280 |
| 281 #if defined(OS_ANDROID) | |
| 273 INSTANTIATE_TEST_CASE_P( | 282 INSTANTIATE_TEST_CASE_P( |
| 274 YUVScaleFormats, YUVScaleTest, | 283 YUVScaleFormats, YUVScaleTest, |
| 275 ::testing::Values( | 284 ::testing::Values( |
| 285 YUVScaleTestData(media::YV12, media::FILTER_NONE, 2593983416u), | |
| 286 YUVScaleTestData(media::YV16, media::FILTER_NONE, 246995851u), | |
| 287 YUVScaleTestData(media::YV12, media::FILTER_BILINEAR, 293331713u), | |
| 288 YUVScaleTestData(media::YV16, media::FILTER_BILINEAR, 123521758u))); | |
| 289 #else | |
| 290 INSTANTIATE_TEST_CASE_P( | |
| 291 YUVScaleFormats, YUVScaleTest, | |
| 292 ::testing::Values( | |
| 276 YUVScaleTestData(media::YV12, media::FILTER_NONE, 4136904952u), | 293 YUVScaleTestData(media::YV12, media::FILTER_NONE, 4136904952u), |
| 277 YUVScaleTestData(media::YV16, media::FILTER_NONE, 1501777547u), | 294 YUVScaleTestData(media::YV16, media::FILTER_NONE, 1501777547u), |
| 278 YUVScaleTestData(media::YV12, media::FILTER_BILINEAR, 3164274689u), | 295 YUVScaleTestData(media::YV12, media::FILTER_BILINEAR, 3164274689u), |
| 279 YUVScaleTestData(media::YV16, media::FILTER_BILINEAR, 3095878046u))); | 296 YUVScaleTestData(media::YV16, media::FILTER_BILINEAR, 3095878046u))); |
| 297 #endif | |
| 280 | 298 |
| 281 // This tests a known worst case YUV value, and for overflow. | 299 // This tests a known worst case YUV value, and for overflow. |
| 282 TEST(YUVConvertTest, Clamp) { | 300 TEST(YUVConvertTest, Clamp) { |
| 283 // Allocate all surfaces. | 301 // Allocate all surfaces. |
| 284 scoped_ptr<uint8[]> yuv_bytes(new uint8[1]); | 302 scoped_ptr<uint8[]> yuv_bytes(new uint8[1]); |
| 285 scoped_ptr<uint8[]> rgb_bytes(new uint8[1]); | 303 scoped_ptr<uint8[]> rgb_bytes(new uint8[1]); |
| 286 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[1]); | 304 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[1]); |
| 287 | 305 |
| 288 // Values that failed previously in bug report. | 306 // Values that failed previously in bug report. |
| 289 unsigned char y = 255u; | 307 unsigned char y = 255u; |
| 290 unsigned char u = 255u; | 308 unsigned char u = 255u; |
| 291 unsigned char v = 19u; | 309 unsigned char v = 19u; |
| 292 | 310 |
| 293 // Prefill extra large destination buffer to test for overflow. | 311 // Prefill extra large destination buffer to test for overflow. |
| 294 unsigned char rgb[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; | 312 unsigned char rgb[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; |
| 295 unsigned char expected[8] = { 255, 255, 104, 255, 4, 5, 6, 7 }; | 313 unsigned char expected[8] = { 255, 255, 104, 255, 4, 5, 6, 7 }; |
| 296 // Convert a frame of YUV to 32 bit ARGB. | 314 // Convert a frame of YUV to 32 bit ARGB. |
| 297 media::ConvertYUVToRGB32(&y, // Y | 315 media::ConvertYUVToRGB32(&y, // Y |
| 298 &u, // U | 316 &u, // U |
| 299 &v, // V | 317 &v, // V |
| 300 &rgb[0], // RGB output | 318 &rgb[0], // RGB output |
| 301 1, 1, // Dimensions | 319 1, 1, // Dimensions |
| 302 0, // YStride | 320 0, // YStride |
| 303 0, // UVStride | 321 0, // UVStride |
| 304 0, // RGBStride | 322 0, // RGBStride |
| 305 media::YV12); | 323 media::YV12); |
| 306 | 324 |
| 325 #if defined(OS_ANDROID) | |
| 326 unsigned char expectedAndroid[8] = { 104, 255, 255, 255, 4, 5, 6, 7 }; | |
| 327 int expected_test = memcmp(rgb, expectedAndroid, sizeof(expected)); | |
| 328 EXPECT_EQ(0, expected_test); | |
| 329 #else | |
| 307 int expected_test = memcmp(rgb, expected, sizeof(expected)); | 330 int expected_test = memcmp(rgb, expected, sizeof(expected)); |
| 308 EXPECT_EQ(0, expected_test); | 331 EXPECT_EQ(0, expected_test); |
| 332 #endif | |
| 309 } | 333 } |
| 310 | 334 |
| 311 TEST(YUVConvertTest, RGB24ToYUV) { | 335 TEST(YUVConvertTest, RGB24ToYUV) { |
| 312 // Allocate all surfaces. | 336 // Allocate all surfaces. |
| 313 scoped_ptr<uint8[]> rgb_bytes; | 337 scoped_ptr<uint8[]> rgb_bytes; |
| 314 scoped_ptr<uint8[]> yuv_converted_bytes(new uint8[kYUV12Size]); | 338 scoped_ptr<uint8[]> yuv_converted_bytes(new uint8[kYUV12Size]); |
| 315 | 339 |
| 316 // Read RGB24 reference data from file. | 340 // Read RGB24 reference data from file. |
| 317 ReadRGB24Data(&rgb_bytes); | 341 ReadRGB24Data(&rgb_bytes); |
| 318 | 342 |
| 319 // Convert to I420. | 343 // Convert to I420. |
| 320 media::ConvertRGB24ToYUV(rgb_bytes.get(), | 344 media::ConvertRGB24ToYUV(rgb_bytes.get(), |
| 321 yuv_converted_bytes.get(), | 345 yuv_converted_bytes.get(), |
| 322 yuv_converted_bytes.get() + kSourceUOffset, | 346 yuv_converted_bytes.get() + kSourceUOffset, |
| 323 yuv_converted_bytes.get() + kSourceVOffset, | 347 yuv_converted_bytes.get() + kSourceVOffset, |
| 324 kSourceWidth, kSourceHeight, // Dimensions | 348 kSourceWidth, kSourceHeight, // Dimensions |
| 325 kSourceWidth * 3, // RGBStride | 349 kSourceWidth * 3, // RGBStride |
| 326 kSourceWidth, // YStride | 350 kSourceWidth, // YStride |
| 327 kSourceWidth / 2); // UVStride | 351 kSourceWidth / 2); // UVStride |
| 328 | 352 |
| 329 uint32 rgb_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, | 353 uint32 rgb_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, |
| 330 kDJB2HashSeed); | 354 kDJB2HashSeed); |
| 355 #if defined(OS_ANDROID) | |
| 331 EXPECT_EQ(320824432u, rgb_hash); | 356 EXPECT_EQ(320824432u, rgb_hash); |
| 357 #else | |
| 358 EXPECT_EQ(320824432u, rgb_hash); | |
|
scherkus (not reviewing)
2013/06/19 19:49:50
these values are the same
hkuang1
2013/06/19 23:21:11
A mistake. Delete it.
| |
| 359 #endif | |
| 332 } | 360 } |
| 333 | 361 |
| 334 TEST(YUVConvertTest, RGB32ToYUV) { | 362 TEST(YUVConvertTest, RGB32ToYUV) { |
| 335 // Allocate all surfaces. | 363 // Allocate all surfaces. |
| 336 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); | 364 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); |
| 337 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); | 365 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); |
| 338 scoped_ptr<uint8[]> yuv_converted_bytes(new uint8[kYUV12Size]); | 366 scoped_ptr<uint8[]> yuv_converted_bytes(new uint8[kYUV12Size]); |
| 339 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSize]); | 367 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSize]); |
| 340 | 368 |
| 341 // Read YUV reference data from file. | 369 // Read YUV reference data from file. |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 936 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | 964 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 937 rgb_bytes_converted.get(), | 965 rgb_bytes_converted.get(), |
| 938 kWidth * kBpp)); | 966 kWidth * kBpp)); |
| 939 } | 967 } |
| 940 | 968 |
| 941 #endif // defined(ARCH_CPU_X86_64) | 969 #endif // defined(ARCH_CPU_X86_64) |
| 942 | 970 |
| 943 #endif // defined(ARCH_CPU_X86_FAMILY) | 971 #endif // defined(ARCH_CPU_X86_FAMILY) |
| 944 | 972 |
| 945 } // namespace media | 973 } // namespace media |
| OLD | NEW |