| 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 "media/base/yuv_convert.h" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 #include <stdint.h> | 8 #include <stdint.h> |
| 7 | 9 |
| 10 #include <memory> |
| 11 |
| 8 #include "base/base_paths.h" | 12 #include "base/base_paths.h" |
| 9 #include "base/cpu.h" | 13 #include "base/cpu.h" |
| 10 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 11 #include "base/logging.h" | 15 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 14 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 15 #include "media/base/djb2.h" | 18 #include "media/base/djb2.h" |
| 16 #include "media/base/simd/convert_rgb_to_yuv.h" | 19 #include "media/base/simd/convert_rgb_to_yuv.h" |
| 17 #include "media/base/simd/convert_yuv_to_rgb.h" | 20 #include "media/base/simd/convert_yuv_to_rgb.h" |
| 18 #include "media/base/simd/filter_yuv.h" | 21 #include "media/base/simd/filter_yuv.h" |
| 19 #include "media/base/yuv_convert.h" | |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/gfx/geometry/rect.h" | 23 #include "ui/gfx/geometry/rect.h" |
| 22 | 24 |
| 23 // Size of raw image. | 25 // Size of raw image. |
| 24 static const int kSourceWidth = 640; | 26 static const int kSourceWidth = 640; |
| 25 static const int kSourceHeight = 360; | 27 static const int kSourceHeight = 360; |
| 26 static const int kSourceYSize = kSourceWidth * kSourceHeight; | 28 static const int kSourceYSize = kSourceWidth * kSourceHeight; |
| 27 static const int kSourceUOffset = kSourceYSize; | 29 static const int kSourceUOffset = kSourceYSize; |
| 28 static const int kSourceVOffset = kSourceYSize * 5 / 4; | 30 static const int kSourceVOffset = kSourceYSize * 5 / 4; |
| 29 static const int kScaledWidth = 1024; | 31 static const int kScaledWidth = 1024; |
| 30 static const int kScaledHeight = 768; | 32 static const int kScaledHeight = 768; |
| 31 static const int kDownScaledWidth = 512; | 33 static const int kDownScaledWidth = 512; |
| 32 static const int kDownScaledHeight = 320; | 34 static const int kDownScaledHeight = 320; |
| 33 static const int kBpp = 4; | 35 static const int kBpp = 4; |
| 34 | 36 |
| 35 // Surface sizes for various test files. | 37 // Surface sizes for various test files. |
| 36 static const int kYUV12Size = kSourceYSize * 12 / 8; | 38 static const int kYUV12Size = kSourceYSize * 12 / 8; |
| 37 static const int kYUV16Size = kSourceYSize * 16 / 8; | 39 static const int kYUV16Size = kSourceYSize * 16 / 8; |
| 38 static const int kRGBSize = kSourceYSize * kBpp; | 40 static const int kRGBSize = kSourceYSize * kBpp; |
| 39 static const int kRGBSizeScaled = kScaledWidth * kScaledHeight * kBpp; | 41 static const int kRGBSizeScaled = kScaledWidth * kScaledHeight * kBpp; |
| 40 static const int kRGB24Size = kSourceYSize * 3; | 42 static const int kRGB24Size = kSourceYSize * 3; |
| 41 static const int kRGBSizeConverted = kSourceYSize * kBpp; | 43 static const int kRGBSizeConverted = kSourceYSize * kBpp; |
| 42 | 44 |
| 43 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) && \ | 45 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) && \ |
| 44 !defined(OS_ANDROID) | 46 !defined(OS_ANDROID) |
| 45 static const int kSourceAOffset = kSourceYSize * 12 / 8; | 47 static const int kSourceAOffset = kSourceYSize * 12 / 8; |
| 46 static const int kYUVA12Size = kSourceYSize * 20 / 8; | 48 static const int kYUVA12Size = kSourceYSize * 20 / 8; |
| 47 #endif | 49 #endif |
| 48 | 50 |
| 49 // Helper for reading test data into a scoped_ptr<uint8_t[]>. | 51 // Helper for reading test data into a std::unique_ptr<uint8_t[]>. |
| 50 static void ReadData(const base::FilePath::CharType* filename, | 52 static void ReadData(const base::FilePath::CharType* filename, |
| 51 int expected_size, | 53 int expected_size, |
| 52 scoped_ptr<uint8_t[]>* data) { | 54 std::unique_ptr<uint8_t[]>* data) { |
| 53 data->reset(new uint8_t[expected_size]); | 55 data->reset(new uint8_t[expected_size]); |
| 54 | 56 |
| 55 base::FilePath path; | 57 base::FilePath path; |
| 56 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &path)); | 58 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &path)); |
| 57 path = path.Append(FILE_PATH_LITERAL("media")) | 59 path = path.Append(FILE_PATH_LITERAL("media")) |
| 58 .Append(FILE_PATH_LITERAL("test")) | 60 .Append(FILE_PATH_LITERAL("test")) |
| 59 .Append(FILE_PATH_LITERAL("data")) | 61 .Append(FILE_PATH_LITERAL("data")) |
| 60 .Append(filename); | 62 .Append(filename); |
| 61 | 63 |
| 62 // Verify file size is correct. | 64 // Verify file size is correct. |
| 63 int64_t actual_size = 0; | 65 int64_t actual_size = 0; |
| 64 base::GetFileSize(path, &actual_size); | 66 base::GetFileSize(path, &actual_size); |
| 65 CHECK_EQ(actual_size, expected_size); | 67 CHECK_EQ(actual_size, expected_size); |
| 66 | 68 |
| 67 // Verify bytes read are correct. | 69 // Verify bytes read are correct. |
| 68 int bytes_read = base::ReadFile( | 70 int bytes_read = base::ReadFile( |
| 69 path, reinterpret_cast<char*>(data->get()), expected_size); | 71 path, reinterpret_cast<char*>(data->get()), expected_size); |
| 70 CHECK_EQ(bytes_read, expected_size); | 72 CHECK_EQ(bytes_read, expected_size); |
| 71 } | 73 } |
| 72 | 74 |
| 73 static void ReadYV12Data(scoped_ptr<uint8_t[]>* data) { | 75 static void ReadYV12Data(std::unique_ptr<uint8_t[]>* data) { |
| 74 ReadData(FILE_PATH_LITERAL("bali_640x360_P420.yuv"), kYUV12Size, data); | 76 ReadData(FILE_PATH_LITERAL("bali_640x360_P420.yuv"), kYUV12Size, data); |
| 75 } | 77 } |
| 76 | 78 |
| 77 static void ReadYV16Data(scoped_ptr<uint8_t[]>* data) { | 79 static void ReadYV16Data(std::unique_ptr<uint8_t[]>* data) { |
| 78 ReadData(FILE_PATH_LITERAL("bali_640x360_P422.yuv"), kYUV16Size, data); | 80 ReadData(FILE_PATH_LITERAL("bali_640x360_P422.yuv"), kYUV16Size, data); |
| 79 } | 81 } |
| 80 | 82 |
| 81 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) && \ | 83 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) && \ |
| 82 !defined(OS_ANDROID) | 84 !defined(OS_ANDROID) |
| 83 static void ReadYV12AData(scoped_ptr<uint8_t[]>* data) { | 85 static void ReadYV12AData(std::unique_ptr<uint8_t[]>* data) { |
| 84 ReadData(FILE_PATH_LITERAL("bali_640x360_P420_alpha.yuv"), kYUVA12Size, data); | 86 ReadData(FILE_PATH_LITERAL("bali_640x360_P420_alpha.yuv"), kYUVA12Size, data); |
| 85 } | 87 } |
| 86 #endif | 88 #endif |
| 87 | 89 |
| 88 static void ReadRGB24Data(scoped_ptr<uint8_t[]>* data) { | 90 static void ReadRGB24Data(std::unique_ptr<uint8_t[]>* data) { |
| 89 ReadData(FILE_PATH_LITERAL("bali_640x360_RGB24.rgb"), kRGB24Size, data); | 91 ReadData(FILE_PATH_LITERAL("bali_640x360_RGB24.rgb"), kRGB24Size, data); |
| 90 } | 92 } |
| 91 | 93 |
| 92 #if defined(OS_ANDROID) | 94 #if defined(OS_ANDROID) |
| 93 // Helper for swapping red and blue channels of RGBA or BGRA. | 95 // Helper for swapping red and blue channels of RGBA or BGRA. |
| 94 static void SwapRedAndBlueChannels(unsigned char* pixels, size_t buffer_size) { | 96 static void SwapRedAndBlueChannels(unsigned char* pixels, size_t buffer_size) { |
| 95 for (size_t i = 0; i < buffer_size; i += 4) { | 97 for (size_t i = 0; i < buffer_size; i += 4) { |
| 96 std::swap(pixels[i], pixels[i + 2]); | 98 std::swap(pixels[i], pixels[i + 2]); |
| 97 } | 99 } |
| 98 } | 100 } |
| 99 #endif | 101 #endif |
| 100 | 102 |
| 101 namespace media { | 103 namespace media { |
| 102 | 104 |
| 103 TEST(YUVConvertTest, YV12) { | 105 TEST(YUVConvertTest, YV12) { |
| 104 // Allocate all surfaces. | 106 // Allocate all surfaces. |
| 105 scoped_ptr<uint8_t[]> yuv_bytes; | 107 std::unique_ptr<uint8_t[]> yuv_bytes; |
| 106 scoped_ptr<uint8_t[]> rgb_bytes(new uint8_t[kRGBSize]); | 108 std::unique_ptr<uint8_t[]> rgb_bytes(new uint8_t[kRGBSize]); |
| 107 scoped_ptr<uint8_t[]> rgb_converted_bytes(new uint8_t[kRGBSizeConverted]); | 109 std::unique_ptr<uint8_t[]> rgb_converted_bytes( |
| 110 new uint8_t[kRGBSizeConverted]); |
| 108 | 111 |
| 109 // Read YUV reference data from file. | 112 // Read YUV reference data from file. |
| 110 ReadYV12Data(&yuv_bytes); | 113 ReadYV12Data(&yuv_bytes); |
| 111 | 114 |
| 112 // Convert a frame of YUV to 32 bit ARGB. | 115 // Convert a frame of YUV to 32 bit ARGB. |
| 113 media::ConvertYUVToRGB32(yuv_bytes.get(), | 116 media::ConvertYUVToRGB32(yuv_bytes.get(), |
| 114 yuv_bytes.get() + kSourceUOffset, | 117 yuv_bytes.get() + kSourceUOffset, |
| 115 yuv_bytes.get() + kSourceVOffset, | 118 yuv_bytes.get() + kSourceVOffset, |
| 116 rgb_converted_bytes.get(), // RGB output | 119 rgb_converted_bytes.get(), // RGB output |
| 117 kSourceWidth, kSourceHeight, // Dimensions | 120 kSourceWidth, kSourceHeight, // Dimensions |
| 118 kSourceWidth, // YStride | 121 kSourceWidth, // YStride |
| 119 kSourceWidth / 2, // UVStride | 122 kSourceWidth / 2, // UVStride |
| 120 kSourceWidth * kBpp, // RGBStride | 123 kSourceWidth * kBpp, // RGBStride |
| 121 media::YV12); | 124 media::YV12); |
| 122 | 125 |
| 123 #if defined(OS_ANDROID) | 126 #if defined(OS_ANDROID) |
| 124 SwapRedAndBlueChannels(rgb_converted_bytes.get(), kRGBSizeConverted); | 127 SwapRedAndBlueChannels(rgb_converted_bytes.get(), kRGBSizeConverted); |
| 125 #endif | 128 #endif |
| 126 | 129 |
| 127 uint32_t rgb_hash = | 130 uint32_t rgb_hash = |
| 128 DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted, kDJB2HashSeed); | 131 DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted, kDJB2HashSeed); |
| 129 EXPECT_EQ(2413171226u, rgb_hash); | 132 EXPECT_EQ(2413171226u, rgb_hash); |
| 130 } | 133 } |
| 131 | 134 |
| 132 TEST(YUVConvertTest, YV16) { | 135 TEST(YUVConvertTest, YV16) { |
| 133 // Allocate all surfaces. | 136 // Allocate all surfaces. |
| 134 scoped_ptr<uint8_t[]> yuv_bytes; | 137 std::unique_ptr<uint8_t[]> yuv_bytes; |
| 135 scoped_ptr<uint8_t[]> rgb_bytes(new uint8_t[kRGBSize]); | 138 std::unique_ptr<uint8_t[]> rgb_bytes(new uint8_t[kRGBSize]); |
| 136 scoped_ptr<uint8_t[]> rgb_converted_bytes(new uint8_t[kRGBSizeConverted]); | 139 std::unique_ptr<uint8_t[]> rgb_converted_bytes( |
| 140 new uint8_t[kRGBSizeConverted]); |
| 137 | 141 |
| 138 // Read YUV reference data from file. | 142 // Read YUV reference data from file. |
| 139 ReadYV16Data(&yuv_bytes); | 143 ReadYV16Data(&yuv_bytes); |
| 140 | 144 |
| 141 // Convert a frame of YUV to 32 bit ARGB. | 145 // Convert a frame of YUV to 32 bit ARGB. |
| 142 media::ConvertYUVToRGB32(yuv_bytes.get(), // Y | 146 media::ConvertYUVToRGB32(yuv_bytes.get(), // Y |
| 143 yuv_bytes.get() + kSourceUOffset, // U | 147 yuv_bytes.get() + kSourceUOffset, // U |
| 144 yuv_bytes.get() + kSourceYSize * 3 / 2, // V | 148 yuv_bytes.get() + kSourceYSize * 3 / 2, // V |
| 145 rgb_converted_bytes.get(), // RGB output | 149 rgb_converted_bytes.get(), // RGB output |
| 146 kSourceWidth, kSourceHeight, // Dimensions | 150 kSourceWidth, kSourceHeight, // Dimensions |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 case media::YV12: | 196 case media::YV12: |
| 193 case media::YV12J: | 197 case media::YV12J: |
| 194 case media::YV12HD: | 198 case media::YV12HD: |
| 195 return yuv_bytes_.get() + kSourceVOffset; | 199 return yuv_bytes_.get() + kSourceVOffset; |
| 196 case media::YV16: | 200 case media::YV16: |
| 197 return yuv_bytes_.get() + kSourceYSize * 3 / 2; | 201 return yuv_bytes_.get() + kSourceYSize * 3 / 2; |
| 198 } | 202 } |
| 199 return NULL; | 203 return NULL; |
| 200 } | 204 } |
| 201 | 205 |
| 202 scoped_ptr<uint8_t[]> yuv_bytes_; | 206 std::unique_ptr<uint8_t[]> yuv_bytes_; |
| 203 scoped_ptr<uint8_t[]> rgb_bytes_; | 207 std::unique_ptr<uint8_t[]> rgb_bytes_; |
| 204 }; | 208 }; |
| 205 | 209 |
| 206 TEST_P(YUVScaleTest, NoScale) { | 210 TEST_P(YUVScaleTest, NoScale) { |
| 207 media::ScaleYUVToRGB32(y_plane(), // Y | 211 media::ScaleYUVToRGB32(y_plane(), // Y |
| 208 u_plane(), // U | 212 u_plane(), // U |
| 209 v_plane(), // V | 213 v_plane(), // V |
| 210 rgb_bytes_.get(), // RGB output | 214 rgb_bytes_.get(), // RGB output |
| 211 kSourceWidth, kSourceHeight, // Dimensions | 215 kSourceWidth, kSourceHeight, // Dimensions |
| 212 kSourceWidth, kSourceHeight, // Dimensions | 216 kSourceWidth, kSourceHeight, // Dimensions |
| 213 kSourceWidth, // YStride | 217 kSourceWidth, // YStride |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 YUVScaleFormats, YUVScaleTest, | 313 YUVScaleFormats, YUVScaleTest, |
| 310 ::testing::Values( | 314 ::testing::Values( |
| 311 YUVScaleTestData(media::YV12, media::FILTER_NONE, 4136904952u), | 315 YUVScaleTestData(media::YV12, media::FILTER_NONE, 4136904952u), |
| 312 YUVScaleTestData(media::YV16, media::FILTER_NONE, 1501777547u), | 316 YUVScaleTestData(media::YV16, media::FILTER_NONE, 1501777547u), |
| 313 YUVScaleTestData(media::YV12, media::FILTER_BILINEAR, 3164274689u), | 317 YUVScaleTestData(media::YV12, media::FILTER_BILINEAR, 3164274689u), |
| 314 YUVScaleTestData(media::YV16, media::FILTER_BILINEAR, 3095878046u))); | 318 YUVScaleTestData(media::YV16, media::FILTER_BILINEAR, 3095878046u))); |
| 315 | 319 |
| 316 // This tests a known worst case YUV value, and for overflow. | 320 // This tests a known worst case YUV value, and for overflow. |
| 317 TEST(YUVConvertTest, Clamp) { | 321 TEST(YUVConvertTest, Clamp) { |
| 318 // Allocate all surfaces. | 322 // Allocate all surfaces. |
| 319 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[1]); | 323 std::unique_ptr<uint8_t[]> yuv_bytes(new uint8_t[1]); |
| 320 scoped_ptr<uint8_t[]> rgb_bytes(new uint8_t[1]); | 324 std::unique_ptr<uint8_t[]> rgb_bytes(new uint8_t[1]); |
| 321 scoped_ptr<uint8_t[]> rgb_converted_bytes(new uint8_t[1]); | 325 std::unique_ptr<uint8_t[]> rgb_converted_bytes(new uint8_t[1]); |
| 322 | 326 |
| 323 // Values that failed previously in bug report. | 327 // Values that failed previously in bug report. |
| 324 unsigned char y = 255u; | 328 unsigned char y = 255u; |
| 325 unsigned char u = 255u; | 329 unsigned char u = 255u; |
| 326 unsigned char v = 19u; | 330 unsigned char v = 19u; |
| 327 | 331 |
| 328 // Prefill extra large destination buffer to test for overflow. | 332 // Prefill extra large destination buffer to test for overflow. |
| 329 unsigned char rgb[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; | 333 unsigned char rgb[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; |
| 330 unsigned char expected[8] = { 255, 255, 104, 255, 4, 5, 6, 7 }; | 334 unsigned char expected[8] = { 255, 255, 104, 255, 4, 5, 6, 7 }; |
| 331 // Convert a frame of YUV to 32 bit ARGB. | 335 // Convert a frame of YUV to 32 bit ARGB. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 342 #if defined(OS_ANDROID) | 346 #if defined(OS_ANDROID) |
| 343 SwapRedAndBlueChannels(rgb, kBpp); | 347 SwapRedAndBlueChannels(rgb, kBpp); |
| 344 #endif | 348 #endif |
| 345 | 349 |
| 346 int expected_test = memcmp(rgb, expected, sizeof(expected)); | 350 int expected_test = memcmp(rgb, expected, sizeof(expected)); |
| 347 EXPECT_EQ(0, expected_test); | 351 EXPECT_EQ(0, expected_test); |
| 348 } | 352 } |
| 349 | 353 |
| 350 TEST(YUVConvertTest, RGB24ToYUV) { | 354 TEST(YUVConvertTest, RGB24ToYUV) { |
| 351 // Allocate all surfaces. | 355 // Allocate all surfaces. |
| 352 scoped_ptr<uint8_t[]> rgb_bytes; | 356 std::unique_ptr<uint8_t[]> rgb_bytes; |
| 353 scoped_ptr<uint8_t[]> yuv_converted_bytes(new uint8_t[kYUV12Size]); | 357 std::unique_ptr<uint8_t[]> yuv_converted_bytes(new uint8_t[kYUV12Size]); |
| 354 | 358 |
| 355 // Read RGB24 reference data from file. | 359 // Read RGB24 reference data from file. |
| 356 ReadRGB24Data(&rgb_bytes); | 360 ReadRGB24Data(&rgb_bytes); |
| 357 | 361 |
| 358 // Convert to I420. | 362 // Convert to I420. |
| 359 media::ConvertRGB24ToYUV(rgb_bytes.get(), | 363 media::ConvertRGB24ToYUV(rgb_bytes.get(), |
| 360 yuv_converted_bytes.get(), | 364 yuv_converted_bytes.get(), |
| 361 yuv_converted_bytes.get() + kSourceUOffset, | 365 yuv_converted_bytes.get() + kSourceUOffset, |
| 362 yuv_converted_bytes.get() + kSourceVOffset, | 366 yuv_converted_bytes.get() + kSourceVOffset, |
| 363 kSourceWidth, kSourceHeight, // Dimensions | 367 kSourceWidth, kSourceHeight, // Dimensions |
| 364 kSourceWidth * 3, // RGBStride | 368 kSourceWidth * 3, // RGBStride |
| 365 kSourceWidth, // YStride | 369 kSourceWidth, // YStride |
| 366 kSourceWidth / 2); // UVStride | 370 kSourceWidth / 2); // UVStride |
| 367 | 371 |
| 368 uint32_t rgb_hash = | 372 uint32_t rgb_hash = |
| 369 DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, kDJB2HashSeed); | 373 DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, kDJB2HashSeed); |
| 370 EXPECT_EQ(320824432u, rgb_hash); | 374 EXPECT_EQ(320824432u, rgb_hash); |
| 371 } | 375 } |
| 372 | 376 |
| 373 TEST(YUVConvertTest, RGB32ToYUV) { | 377 TEST(YUVConvertTest, RGB32ToYUV) { |
| 374 // Allocate all surfaces. | 378 // Allocate all surfaces. |
| 375 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); | 379 std::unique_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); |
| 376 scoped_ptr<uint8_t[]> rgb_bytes(new uint8_t[kRGBSize]); | 380 std::unique_ptr<uint8_t[]> rgb_bytes(new uint8_t[kRGBSize]); |
| 377 scoped_ptr<uint8_t[]> yuv_converted_bytes(new uint8_t[kYUV12Size]); | 381 std::unique_ptr<uint8_t[]> yuv_converted_bytes(new uint8_t[kYUV12Size]); |
| 378 scoped_ptr<uint8_t[]> rgb_converted_bytes(new uint8_t[kRGBSize]); | 382 std::unique_ptr<uint8_t[]> rgb_converted_bytes(new uint8_t[kRGBSize]); |
| 379 | 383 |
| 380 // Read YUV reference data from file. | 384 // Read YUV reference data from file. |
| 381 base::FilePath yuv_url; | 385 base::FilePath yuv_url; |
| 382 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); | 386 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); |
| 383 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) | 387 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) |
| 384 .Append(FILE_PATH_LITERAL("test")) | 388 .Append(FILE_PATH_LITERAL("test")) |
| 385 .Append(FILE_PATH_LITERAL("data")) | 389 .Append(FILE_PATH_LITERAL("data")) |
| 386 .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); | 390 .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); |
| 387 EXPECT_EQ(static_cast<int>(kYUV12Size), | 391 EXPECT_EQ(static_cast<int>(kYUV12Size), |
| 388 base::ReadFile(yuv_url, | 392 base::ReadFile(yuv_url, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 | 440 |
| 437 TEST(YUVConvertTest, DownScaleYUVToRGB32WithRect) { | 441 TEST(YUVConvertTest, DownScaleYUVToRGB32WithRect) { |
| 438 // Read YUV reference data from file. | 442 // Read YUV reference data from file. |
| 439 base::FilePath yuv_url; | 443 base::FilePath yuv_url; |
| 440 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); | 444 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); |
| 441 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) | 445 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) |
| 442 .Append(FILE_PATH_LITERAL("test")) | 446 .Append(FILE_PATH_LITERAL("test")) |
| 443 .Append(FILE_PATH_LITERAL("data")) | 447 .Append(FILE_PATH_LITERAL("data")) |
| 444 .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); | 448 .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); |
| 445 const size_t size_of_yuv = kSourceYSize * 12 / 8; // 12 bpp. | 449 const size_t size_of_yuv = kSourceYSize * 12 / 8; // 12 bpp. |
| 446 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[size_of_yuv]); | 450 std::unique_ptr<uint8_t[]> yuv_bytes(new uint8_t[size_of_yuv]); |
| 447 EXPECT_EQ(static_cast<int>(size_of_yuv), | 451 EXPECT_EQ(static_cast<int>(size_of_yuv), |
| 448 base::ReadFile(yuv_url, | 452 base::ReadFile(yuv_url, |
| 449 reinterpret_cast<char*>(yuv_bytes.get()), | 453 reinterpret_cast<char*>(yuv_bytes.get()), |
| 450 static_cast<int>(size_of_yuv))); | 454 static_cast<int>(size_of_yuv))); |
| 451 | 455 |
| 452 // Scale the full frame of YUV to 32 bit ARGB. | 456 // Scale the full frame of YUV to 32 bit ARGB. |
| 453 // The API currently only supports down-scaling, so we don't test up-scaling. | 457 // The API currently only supports down-scaling, so we don't test up-scaling. |
| 454 const size_t size_of_rgb_scaled = kDownScaledWidth * kDownScaledHeight * kBpp; | 458 const size_t size_of_rgb_scaled = kDownScaledWidth * kDownScaledHeight * kBpp; |
| 455 scoped_ptr<uint8_t[]> rgb_scaled_bytes(new uint8_t[size_of_rgb_scaled]); | 459 std::unique_ptr<uint8_t[]> rgb_scaled_bytes(new uint8_t[size_of_rgb_scaled]); |
| 456 gfx::Rect sub_rect(0, 0, kDownScaledWidth, kDownScaledHeight); | 460 gfx::Rect sub_rect(0, 0, kDownScaledWidth, kDownScaledHeight); |
| 457 | 461 |
| 458 // We can't compare with the full-frame scaler because it uses slightly | 462 // We can't compare with the full-frame scaler because it uses slightly |
| 459 // different sampling coordinates. | 463 // different sampling coordinates. |
| 460 media::ScaleYUVToRGB32WithRect( | 464 media::ScaleYUVToRGB32WithRect( |
| 461 yuv_bytes.get(), // Y | 465 yuv_bytes.get(), // Y |
| 462 yuv_bytes.get() + kSourceUOffset, // U | 466 yuv_bytes.get() + kSourceUOffset, // U |
| 463 yuv_bytes.get() + kSourceVOffset, // V | 467 yuv_bytes.get() + kSourceVOffset, // V |
| 464 rgb_scaled_bytes.get(), // Rgb output | 468 rgb_scaled_bytes.get(), // Rgb output |
| 465 kSourceWidth, kSourceHeight, // Dimensions | 469 kSourceWidth, kSourceHeight, // Dimensions |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 sub_rect.set_width(sub_rect.width() / 2); | 506 sub_rect.set_width(sub_rect.width() / 2); |
| 503 sub_rect.set_height(sub_rect.height() / 2); | 507 sub_rect.set_height(sub_rect.height() / 2); |
| 504 next_sub_rect++; | 508 next_sub_rect++; |
| 505 } | 509 } |
| 506 } | 510 } |
| 507 | 511 |
| 508 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) | 512 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) |
| 509 #if !defined(OS_ANDROID) | 513 #if !defined(OS_ANDROID) |
| 510 TEST(YUVConvertTest, YUVAtoARGB_MMX_MatchReference) { | 514 TEST(YUVConvertTest, YUVAtoARGB_MMX_MatchReference) { |
| 511 // Allocate all surfaces. | 515 // Allocate all surfaces. |
| 512 scoped_ptr<uint8_t[]> yuv_bytes; | 516 std::unique_ptr<uint8_t[]> yuv_bytes; |
| 513 scoped_ptr<uint8_t[]> rgb_bytes(new uint8_t[kRGBSize]); | 517 std::unique_ptr<uint8_t[]> rgb_bytes(new uint8_t[kRGBSize]); |
| 514 scoped_ptr<uint8_t[]> rgb_converted_bytes(new uint8_t[kRGBSizeConverted]); | 518 std::unique_ptr<uint8_t[]> rgb_converted_bytes( |
| 515 scoped_ptr<uint8_t[]> rgb_converted_bytes_ref(new uint8_t[kRGBSizeConverted]); | 519 new uint8_t[kRGBSizeConverted]); |
| 520 std::unique_ptr<uint8_t[]> rgb_converted_bytes_ref( |
| 521 new uint8_t[kRGBSizeConverted]); |
| 516 | 522 |
| 517 // Read YUV reference data from file. | 523 // Read YUV reference data from file. |
| 518 ReadYV12AData(&yuv_bytes); | 524 ReadYV12AData(&yuv_bytes); |
| 519 | 525 |
| 520 // Convert a frame of YUV to 32 bit ARGB using both C and MMX versions. | 526 // Convert a frame of YUV to 32 bit ARGB using both C and MMX versions. |
| 521 media::ConvertYUVAToARGB_C(yuv_bytes.get(), | 527 media::ConvertYUVAToARGB_C(yuv_bytes.get(), |
| 522 yuv_bytes.get() + kSourceUOffset, | 528 yuv_bytes.get() + kSourceUOffset, |
| 523 yuv_bytes.get() + kSourceVOffset, | 529 yuv_bytes.get() + kSourceVOffset, |
| 524 yuv_bytes.get() + kSourceAOffset, | 530 yuv_bytes.get() + kSourceAOffset, |
| 525 rgb_converted_bytes_ref.get(), | 531 rgb_converted_bytes_ref.get(), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 551 #endif // !defined(OS_ANDROID) | 557 #endif // !defined(OS_ANDROID) |
| 552 | 558 |
| 553 TEST(YUVConvertTest, RGB32ToYUV_SSE2_MatchReference) { | 559 TEST(YUVConvertTest, RGB32ToYUV_SSE2_MatchReference) { |
| 554 base::CPU cpu; | 560 base::CPU cpu; |
| 555 if (!cpu.has_sse2()) { | 561 if (!cpu.has_sse2()) { |
| 556 LOG(WARNING) << "System doesn't support SSE2, test not executed."; | 562 LOG(WARNING) << "System doesn't support SSE2, test not executed."; |
| 557 return; | 563 return; |
| 558 } | 564 } |
| 559 | 565 |
| 560 // Allocate all surfaces. | 566 // Allocate all surfaces. |
| 561 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); | 567 std::unique_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); |
| 562 scoped_ptr<uint8_t[]> rgb_bytes(new uint8_t[kRGBSize]); | 568 std::unique_ptr<uint8_t[]> rgb_bytes(new uint8_t[kRGBSize]); |
| 563 scoped_ptr<uint8_t[]> yuv_converted_bytes(new uint8_t[kYUV12Size]); | 569 std::unique_ptr<uint8_t[]> yuv_converted_bytes(new uint8_t[kYUV12Size]); |
| 564 scoped_ptr<uint8_t[]> yuv_reference_bytes(new uint8_t[kYUV12Size]); | 570 std::unique_ptr<uint8_t[]> yuv_reference_bytes(new uint8_t[kYUV12Size]); |
| 565 | 571 |
| 566 ReadYV12Data(&yuv_bytes); | 572 ReadYV12Data(&yuv_bytes); |
| 567 | 573 |
| 568 // Convert a frame of YUV to 32 bit ARGB. | 574 // Convert a frame of YUV to 32 bit ARGB. |
| 569 media::ConvertYUVToRGB32( | 575 media::ConvertYUVToRGB32( |
| 570 yuv_bytes.get(), | 576 yuv_bytes.get(), |
| 571 yuv_bytes.get() + kSourceUOffset, | 577 yuv_bytes.get() + kSourceUOffset, |
| 572 yuv_bytes.get() + kSourceVOffset, | 578 yuv_bytes.get() + kSourceVOffset, |
| 573 rgb_bytes.get(), // RGB output | 579 rgb_bytes.get(), // RGB output |
| 574 kSourceWidth, kSourceHeight, // Dimensions | 580 kSourceWidth, kSourceHeight, // Dimensions |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 EXPECT_EQ(0, error); | 643 EXPECT_EQ(0, error); |
| 638 } | 644 } |
| 639 | 645 |
| 640 TEST(YUVConvertTest, ConvertYUVToRGB32Row_SSE) { | 646 TEST(YUVConvertTest, ConvertYUVToRGB32Row_SSE) { |
| 641 base::CPU cpu; | 647 base::CPU cpu; |
| 642 if (!cpu.has_sse()) { | 648 if (!cpu.has_sse()) { |
| 643 LOG(WARNING) << "System not supported. Test skipped."; | 649 LOG(WARNING) << "System not supported. Test skipped."; |
| 644 return; | 650 return; |
| 645 } | 651 } |
| 646 | 652 |
| 647 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); | 653 std::unique_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); |
| 648 scoped_ptr<uint8_t[]> rgb_bytes_reference(new uint8_t[kRGBSize]); | 654 std::unique_ptr<uint8_t[]> rgb_bytes_reference(new uint8_t[kRGBSize]); |
| 649 scoped_ptr<uint8_t[]> rgb_bytes_converted(new uint8_t[kRGBSize]); | 655 std::unique_ptr<uint8_t[]> rgb_bytes_converted(new uint8_t[kRGBSize]); |
| 650 ReadYV12Data(&yuv_bytes); | 656 ReadYV12Data(&yuv_bytes); |
| 651 | 657 |
| 652 const int kWidth = 167; | 658 const int kWidth = 167; |
| 653 ConvertYUVToRGB32Row_C(yuv_bytes.get(), | 659 ConvertYUVToRGB32Row_C(yuv_bytes.get(), |
| 654 yuv_bytes.get() + kSourceUOffset, | 660 yuv_bytes.get() + kSourceUOffset, |
| 655 yuv_bytes.get() + kSourceVOffset, | 661 yuv_bytes.get() + kSourceVOffset, |
| 656 rgb_bytes_reference.get(), | 662 rgb_bytes_reference.get(), |
| 657 kWidth, | 663 kWidth, |
| 658 GetLookupTable(YV12)); | 664 GetLookupTable(YV12)); |
| 659 ConvertYUVToRGB32Row_SSE(yuv_bytes.get(), | 665 ConvertYUVToRGB32Row_SSE(yuv_bytes.get(), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 671 // 64-bit release + component builds on Windows are too smart and optimizes | 677 // 64-bit release + component builds on Windows are too smart and optimizes |
| 672 // away the function being tested. | 678 // away the function being tested. |
| 673 #if defined(OS_WIN) && (defined(ARCH_CPU_X86) || !defined(COMPONENT_BUILD)) | 679 #if defined(OS_WIN) && (defined(ARCH_CPU_X86) || !defined(COMPONENT_BUILD)) |
| 674 TEST(YUVConvertTest, ScaleYUVToRGB32Row_SSE) { | 680 TEST(YUVConvertTest, ScaleYUVToRGB32Row_SSE) { |
| 675 base::CPU cpu; | 681 base::CPU cpu; |
| 676 if (!cpu.has_sse()) { | 682 if (!cpu.has_sse()) { |
| 677 LOG(WARNING) << "System not supported. Test skipped."; | 683 LOG(WARNING) << "System not supported. Test skipped."; |
| 678 return; | 684 return; |
| 679 } | 685 } |
| 680 | 686 |
| 681 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); | 687 std::unique_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); |
| 682 scoped_ptr<uint8_t[]> rgb_bytes_reference(new uint8_t[kRGBSize]); | 688 std::unique_ptr<uint8_t[]> rgb_bytes_reference(new uint8_t[kRGBSize]); |
| 683 scoped_ptr<uint8_t[]> rgb_bytes_converted(new uint8_t[kRGBSize]); | 689 std::unique_ptr<uint8_t[]> rgb_bytes_converted(new uint8_t[kRGBSize]); |
| 684 ReadYV12Data(&yuv_bytes); | 690 ReadYV12Data(&yuv_bytes); |
| 685 | 691 |
| 686 const int kWidth = 167; | 692 const int kWidth = 167; |
| 687 const int kSourceDx = 80000; // This value means a scale down. | 693 const int kSourceDx = 80000; // This value means a scale down. |
| 688 ScaleYUVToRGB32Row_C(yuv_bytes.get(), | 694 ScaleYUVToRGB32Row_C(yuv_bytes.get(), |
| 689 yuv_bytes.get() + kSourceUOffset, | 695 yuv_bytes.get() + kSourceUOffset, |
| 690 yuv_bytes.get() + kSourceVOffset, | 696 yuv_bytes.get() + kSourceVOffset, |
| 691 rgb_bytes_reference.get(), | 697 rgb_bytes_reference.get(), |
| 692 kWidth, | 698 kWidth, |
| 693 kSourceDx, | 699 kSourceDx, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 705 kWidth * kBpp)); | 711 kWidth * kBpp)); |
| 706 } | 712 } |
| 707 | 713 |
| 708 TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_SSE) { | 714 TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_SSE) { |
| 709 base::CPU cpu; | 715 base::CPU cpu; |
| 710 if (!cpu.has_sse()) { | 716 if (!cpu.has_sse()) { |
| 711 LOG(WARNING) << "System not supported. Test skipped."; | 717 LOG(WARNING) << "System not supported. Test skipped."; |
| 712 return; | 718 return; |
| 713 } | 719 } |
| 714 | 720 |
| 715 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); | 721 std::unique_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); |
| 716 scoped_ptr<uint8_t[]> rgb_bytes_reference(new uint8_t[kRGBSize]); | 722 std::unique_ptr<uint8_t[]> rgb_bytes_reference(new uint8_t[kRGBSize]); |
| 717 scoped_ptr<uint8_t[]> rgb_bytes_converted(new uint8_t[kRGBSize]); | 723 std::unique_ptr<uint8_t[]> rgb_bytes_converted(new uint8_t[kRGBSize]); |
| 718 ReadYV12Data(&yuv_bytes); | 724 ReadYV12Data(&yuv_bytes); |
| 719 | 725 |
| 720 const int kWidth = 167; | 726 const int kWidth = 167; |
| 721 const int kSourceDx = 80000; // This value means a scale down. | 727 const int kSourceDx = 80000; // This value means a scale down. |
| 722 LinearScaleYUVToRGB32Row_C(yuv_bytes.get(), | 728 LinearScaleYUVToRGB32Row_C(yuv_bytes.get(), |
| 723 yuv_bytes.get() + kSourceUOffset, | 729 yuv_bytes.get() + kSourceUOffset, |
| 724 yuv_bytes.get() + kSourceVOffset, | 730 yuv_bytes.get() + kSourceVOffset, |
| 725 rgb_bytes_reference.get(), | 731 rgb_bytes_reference.get(), |
| 726 kWidth, | 732 kWidth, |
| 727 kSourceDx, | 733 kSourceDx, |
| 728 GetLookupTable(YV12)); | 734 GetLookupTable(YV12)); |
| 729 LinearScaleYUVToRGB32Row_SSE(yuv_bytes.get(), | 735 LinearScaleYUVToRGB32Row_SSE(yuv_bytes.get(), |
| 730 yuv_bytes.get() + kSourceUOffset, | 736 yuv_bytes.get() + kSourceUOffset, |
| 731 yuv_bytes.get() + kSourceVOffset, | 737 yuv_bytes.get() + kSourceVOffset, |
| 732 rgb_bytes_converted.get(), | 738 rgb_bytes_converted.get(), |
| 733 kWidth, | 739 kWidth, |
| 734 kSourceDx, | 740 kSourceDx, |
| 735 GetLookupTable(YV12)); | 741 GetLookupTable(YV12)); |
| 736 media::EmptyRegisterState(); | 742 media::EmptyRegisterState(); |
| 737 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | 743 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 738 rgb_bytes_converted.get(), | 744 rgb_bytes_converted.get(), |
| 739 kWidth * kBpp)); | 745 kWidth * kBpp)); |
| 740 } | 746 } |
| 741 #endif // defined(OS_WIN) && (ARCH_CPU_X86 || COMPONENT_BUILD) | 747 #endif // defined(OS_WIN) && (ARCH_CPU_X86 || COMPONENT_BUILD) |
| 742 | 748 |
| 743 TEST(YUVConvertTest, FilterYUVRows_C_OutOfBounds) { | 749 TEST(YUVConvertTest, FilterYUVRows_C_OutOfBounds) { |
| 744 scoped_ptr<uint8_t[]> src(new uint8_t[16]); | 750 std::unique_ptr<uint8_t[]> src(new uint8_t[16]); |
| 745 scoped_ptr<uint8_t[]> dst(new uint8_t[16]); | 751 std::unique_ptr<uint8_t[]> dst(new uint8_t[16]); |
| 746 | 752 |
| 747 memset(src.get(), 0xff, 16); | 753 memset(src.get(), 0xff, 16); |
| 748 memset(dst.get(), 0, 16); | 754 memset(dst.get(), 0, 16); |
| 749 | 755 |
| 750 media::FilterYUVRows_C(dst.get(), src.get(), src.get(), 1, 255); | 756 media::FilterYUVRows_C(dst.get(), src.get(), src.get(), 1, 255); |
| 751 | 757 |
| 752 EXPECT_EQ(255u, dst[0]); | 758 EXPECT_EQ(255u, dst[0]); |
| 753 for (int i = 1; i < 16; ++i) { | 759 for (int i = 1; i < 16; ++i) { |
| 754 EXPECT_EQ(0u, dst[i]) << " not equal at " << i; | 760 EXPECT_EQ(0u, dst[i]) << " not equal at " << i; |
| 755 } | 761 } |
| 756 } | 762 } |
| 757 | 763 |
| 758 TEST(YUVConvertTest, FilterYUVRows_SSE2_OutOfBounds) { | 764 TEST(YUVConvertTest, FilterYUVRows_SSE2_OutOfBounds) { |
| 759 base::CPU cpu; | 765 base::CPU cpu; |
| 760 if (!cpu.has_sse2()) { | 766 if (!cpu.has_sse2()) { |
| 761 LOG(WARNING) << "System not supported. Test skipped."; | 767 LOG(WARNING) << "System not supported. Test skipped."; |
| 762 return; | 768 return; |
| 763 } | 769 } |
| 764 | 770 |
| 765 scoped_ptr<uint8_t[]> src(new uint8_t[16]); | 771 std::unique_ptr<uint8_t[]> src(new uint8_t[16]); |
| 766 scoped_ptr<uint8_t[]> dst(new uint8_t[16]); | 772 std::unique_ptr<uint8_t[]> dst(new uint8_t[16]); |
| 767 | 773 |
| 768 memset(src.get(), 0xff, 16); | 774 memset(src.get(), 0xff, 16); |
| 769 memset(dst.get(), 0, 16); | 775 memset(dst.get(), 0, 16); |
| 770 | 776 |
| 771 media::FilterYUVRows_SSE2(dst.get(), src.get(), src.get(), 1, 255); | 777 media::FilterYUVRows_SSE2(dst.get(), src.get(), src.get(), 1, 255); |
| 772 | 778 |
| 773 EXPECT_EQ(255u, dst[0]); | 779 EXPECT_EQ(255u, dst[0]); |
| 774 for (int i = 1; i < 16; ++i) { | 780 for (int i = 1; i < 16; ++i) { |
| 775 EXPECT_EQ(0u, dst[i]); | 781 EXPECT_EQ(0u, dst[i]); |
| 776 } | 782 } |
| 777 } | 783 } |
| 778 | 784 |
| 779 TEST(YUVConvertTest, FilterYUVRows_SSE2_UnalignedDestination) { | 785 TEST(YUVConvertTest, FilterYUVRows_SSE2_UnalignedDestination) { |
| 780 base::CPU cpu; | 786 base::CPU cpu; |
| 781 if (!cpu.has_sse2()) { | 787 if (!cpu.has_sse2()) { |
| 782 LOG(WARNING) << "System not supported. Test skipped."; | 788 LOG(WARNING) << "System not supported. Test skipped."; |
| 783 return; | 789 return; |
| 784 } | 790 } |
| 785 | 791 |
| 786 const int kSize = 64; | 792 const int kSize = 64; |
| 787 scoped_ptr<uint8_t[]> src(new uint8_t[kSize]); | 793 std::unique_ptr<uint8_t[]> src(new uint8_t[kSize]); |
| 788 scoped_ptr<uint8_t[]> dst_sample(new uint8_t[kSize]); | 794 std::unique_ptr<uint8_t[]> dst_sample(new uint8_t[kSize]); |
| 789 scoped_ptr<uint8_t[]> dst(new uint8_t[kSize]); | 795 std::unique_ptr<uint8_t[]> dst(new uint8_t[kSize]); |
| 790 | 796 |
| 791 memset(dst_sample.get(), 0, kSize); | 797 memset(dst_sample.get(), 0, kSize); |
| 792 memset(dst.get(), 0, kSize); | 798 memset(dst.get(), 0, kSize); |
| 793 for (int i = 0; i < kSize; ++i) | 799 for (int i = 0; i < kSize; ++i) |
| 794 src[i] = 100 + i; | 800 src[i] = 100 + i; |
| 795 | 801 |
| 796 media::FilterYUVRows_C(dst_sample.get(), | 802 media::FilterYUVRows_C(dst_sample.get(), |
| 797 src.get(), src.get(), 37, 128); | 803 src.get(), src.get(), 37, 128); |
| 798 | 804 |
| 799 // Generate an unaligned output address. | 805 // Generate an unaligned output address. |
| 800 uint8_t* dst_ptr = reinterpret_cast<uint8_t*>( | 806 uint8_t* dst_ptr = reinterpret_cast<uint8_t*>( |
| 801 (reinterpret_cast<uintptr_t>(dst.get() + 16) & ~15) + 1); | 807 (reinterpret_cast<uintptr_t>(dst.get() + 16) & ~15) + 1); |
| 802 media::FilterYUVRows_SSE2(dst_ptr, src.get(), src.get(), 37, 128); | 808 media::FilterYUVRows_SSE2(dst_ptr, src.get(), src.get(), 37, 128); |
| 803 media::EmptyRegisterState(); | 809 media::EmptyRegisterState(); |
| 804 | 810 |
| 805 EXPECT_EQ(0, memcmp(dst_sample.get(), dst_ptr, 37)); | 811 EXPECT_EQ(0, memcmp(dst_sample.get(), dst_ptr, 37)); |
| 806 } | 812 } |
| 807 | 813 |
| 808 #if defined(ARCH_CPU_X86_64) | 814 #if defined(ARCH_CPU_X86_64) |
| 809 | 815 |
| 810 TEST(YUVConvertTest, ScaleYUVToRGB32Row_SSE2_X64) { | 816 TEST(YUVConvertTest, ScaleYUVToRGB32Row_SSE2_X64) { |
| 811 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); | 817 std::unique_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); |
| 812 scoped_ptr<uint8_t[]> rgb_bytes_reference(new uint8_t[kRGBSize]); | 818 std::unique_ptr<uint8_t[]> rgb_bytes_reference(new uint8_t[kRGBSize]); |
| 813 scoped_ptr<uint8_t[]> rgb_bytes_converted(new uint8_t[kRGBSize]); | 819 std::unique_ptr<uint8_t[]> rgb_bytes_converted(new uint8_t[kRGBSize]); |
| 814 ReadYV12Data(&yuv_bytes); | 820 ReadYV12Data(&yuv_bytes); |
| 815 | 821 |
| 816 const int kWidth = 167; | 822 const int kWidth = 167; |
| 817 const int kSourceDx = 80000; // This value means a scale down. | 823 const int kSourceDx = 80000; // This value means a scale down. |
| 818 ScaleYUVToRGB32Row_C(yuv_bytes.get(), | 824 ScaleYUVToRGB32Row_C(yuv_bytes.get(), |
| 819 yuv_bytes.get() + kSourceUOffset, | 825 yuv_bytes.get() + kSourceUOffset, |
| 820 yuv_bytes.get() + kSourceVOffset, | 826 yuv_bytes.get() + kSourceVOffset, |
| 821 rgb_bytes_reference.get(), | 827 rgb_bytes_reference.get(), |
| 822 kWidth, | 828 kWidth, |
| 823 kSourceDx, | 829 kSourceDx, |
| 824 GetLookupTable(YV12)); | 830 GetLookupTable(YV12)); |
| 825 ScaleYUVToRGB32Row_SSE2_X64(yuv_bytes.get(), | 831 ScaleYUVToRGB32Row_SSE2_X64(yuv_bytes.get(), |
| 826 yuv_bytes.get() + kSourceUOffset, | 832 yuv_bytes.get() + kSourceUOffset, |
| 827 yuv_bytes.get() + kSourceVOffset, | 833 yuv_bytes.get() + kSourceVOffset, |
| 828 rgb_bytes_converted.get(), | 834 rgb_bytes_converted.get(), |
| 829 kWidth, | 835 kWidth, |
| 830 kSourceDx, | 836 kSourceDx, |
| 831 GetLookupTable(YV12)); | 837 GetLookupTable(YV12)); |
| 832 media::EmptyRegisterState(); | 838 media::EmptyRegisterState(); |
| 833 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | 839 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 834 rgb_bytes_converted.get(), | 840 rgb_bytes_converted.get(), |
| 835 kWidth * kBpp)); | 841 kWidth * kBpp)); |
| 836 } | 842 } |
| 837 | 843 |
| 838 TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_MMX_X64) { | 844 TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_MMX_X64) { |
| 839 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); | 845 std::unique_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); |
| 840 scoped_ptr<uint8_t[]> rgb_bytes_reference(new uint8_t[kRGBSize]); | 846 std::unique_ptr<uint8_t[]> rgb_bytes_reference(new uint8_t[kRGBSize]); |
| 841 scoped_ptr<uint8_t[]> rgb_bytes_converted(new uint8_t[kRGBSize]); | 847 std::unique_ptr<uint8_t[]> rgb_bytes_converted(new uint8_t[kRGBSize]); |
| 842 ReadYV12Data(&yuv_bytes); | 848 ReadYV12Data(&yuv_bytes); |
| 843 | 849 |
| 844 const int kWidth = 167; | 850 const int kWidth = 167; |
| 845 const int kSourceDx = 80000; // This value means a scale down. | 851 const int kSourceDx = 80000; // This value means a scale down. |
| 846 LinearScaleYUVToRGB32Row_C(yuv_bytes.get(), | 852 LinearScaleYUVToRGB32Row_C(yuv_bytes.get(), |
| 847 yuv_bytes.get() + kSourceUOffset, | 853 yuv_bytes.get() + kSourceUOffset, |
| 848 yuv_bytes.get() + kSourceVOffset, | 854 yuv_bytes.get() + kSourceVOffset, |
| 849 rgb_bytes_reference.get(), | 855 rgb_bytes_reference.get(), |
| 850 kWidth, | 856 kWidth, |
| 851 kSourceDx, | 857 kSourceDx, |
| 852 GetLookupTable(YV12)); | 858 GetLookupTable(YV12)); |
| 853 LinearScaleYUVToRGB32Row_MMX_X64(yuv_bytes.get(), | 859 LinearScaleYUVToRGB32Row_MMX_X64(yuv_bytes.get(), |
| 854 yuv_bytes.get() + kSourceUOffset, | 860 yuv_bytes.get() + kSourceUOffset, |
| 855 yuv_bytes.get() + kSourceVOffset, | 861 yuv_bytes.get() + kSourceVOffset, |
| 856 rgb_bytes_converted.get(), | 862 rgb_bytes_converted.get(), |
| 857 kWidth, | 863 kWidth, |
| 858 kSourceDx, | 864 kSourceDx, |
| 859 GetLookupTable(YV12)); | 865 GetLookupTable(YV12)); |
| 860 media::EmptyRegisterState(); | 866 media::EmptyRegisterState(); |
| 861 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | 867 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 862 rgb_bytes_converted.get(), | 868 rgb_bytes_converted.get(), |
| 863 kWidth * kBpp)); | 869 kWidth * kBpp)); |
| 864 } | 870 } |
| 865 | 871 |
| 866 #endif // defined(ARCH_CPU_X86_64) | 872 #endif // defined(ARCH_CPU_X86_64) |
| 867 | 873 |
| 868 #endif // defined(ARCH_CPU_X86_FAMILY) | 874 #endif // defined(ARCH_CPU_X86_FAMILY) |
| 869 | 875 |
| 870 } // namespace media | 876 } // namespace media |
| OLD | NEW |