| 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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
| 5 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
| 6 #include "base/cpu.h" | 9 #include "base/cpu.h" |
| 7 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 8 #include "base/logging.h" | 11 #include "base/logging.h" |
| 9 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "build/build_config.h" |
| 10 #include "media/base/djb2.h" | 14 #include "media/base/djb2.h" |
| 11 #include "media/base/simd/convert_rgb_to_yuv.h" | 15 #include "media/base/simd/convert_rgb_to_yuv.h" |
| 12 #include "media/base/simd/convert_yuv_to_rgb.h" | 16 #include "media/base/simd/convert_yuv_to_rgb.h" |
| 13 #include "media/base/simd/filter_yuv.h" | 17 #include "media/base/simd/filter_yuv.h" |
| 14 #include "media/base/yuv_convert.h" | 18 #include "media/base/yuv_convert.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "ui/gfx/geometry/rect.h" | 20 #include "ui/gfx/geometry/rect.h" |
| 17 | 21 |
| 18 // Size of raw image. | 22 // Size of raw image. |
| 19 static const int kSourceWidth = 640; | 23 static const int kSourceWidth = 640; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 33 static const int kRGBSize = kSourceYSize * kBpp; | 37 static const int kRGBSize = kSourceYSize * kBpp; |
| 34 static const int kRGBSizeScaled = kScaledWidth * kScaledHeight * kBpp; | 38 static const int kRGBSizeScaled = kScaledWidth * kScaledHeight * kBpp; |
| 35 static const int kRGB24Size = kSourceYSize * 3; | 39 static const int kRGB24Size = kSourceYSize * 3; |
| 36 static const int kRGBSizeConverted = kSourceYSize * kBpp; | 40 static const int kRGBSizeConverted = kSourceYSize * kBpp; |
| 37 | 41 |
| 38 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) | 42 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) |
| 39 static const int kSourceAOffset = kSourceYSize * 12 / 8; | 43 static const int kSourceAOffset = kSourceYSize * 12 / 8; |
| 40 static const int kYUVA12Size = kSourceYSize * 20 / 8; | 44 static const int kYUVA12Size = kSourceYSize * 20 / 8; |
| 41 #endif | 45 #endif |
| 42 | 46 |
| 43 // Helper for reading test data into a scoped_ptr<uint8[]>. | 47 // Helper for reading test data into a scoped_ptr<uint8_t[]>. |
| 44 static void ReadData(const base::FilePath::CharType* filename, | 48 static void ReadData(const base::FilePath::CharType* filename, |
| 45 int expected_size, | 49 int expected_size, |
| 46 scoped_ptr<uint8[]>* data) { | 50 scoped_ptr<uint8_t[]>* data) { |
| 47 data->reset(new uint8[expected_size]); | 51 data->reset(new uint8_t[expected_size]); |
| 48 | 52 |
| 49 base::FilePath path; | 53 base::FilePath path; |
| 50 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &path)); | 54 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &path)); |
| 51 path = path.Append(FILE_PATH_LITERAL("media")) | 55 path = path.Append(FILE_PATH_LITERAL("media")) |
| 52 .Append(FILE_PATH_LITERAL("test")) | 56 .Append(FILE_PATH_LITERAL("test")) |
| 53 .Append(FILE_PATH_LITERAL("data")) | 57 .Append(FILE_PATH_LITERAL("data")) |
| 54 .Append(filename); | 58 .Append(filename); |
| 55 | 59 |
| 56 // Verify file size is correct. | 60 // Verify file size is correct. |
| 57 int64 actual_size = 0; | 61 int64_t actual_size = 0; |
| 58 base::GetFileSize(path, &actual_size); | 62 base::GetFileSize(path, &actual_size); |
| 59 CHECK_EQ(actual_size, expected_size); | 63 CHECK_EQ(actual_size, expected_size); |
| 60 | 64 |
| 61 // Verify bytes read are correct. | 65 // Verify bytes read are correct. |
| 62 int bytes_read = base::ReadFile( | 66 int bytes_read = base::ReadFile( |
| 63 path, reinterpret_cast<char*>(data->get()), expected_size); | 67 path, reinterpret_cast<char*>(data->get()), expected_size); |
| 64 CHECK_EQ(bytes_read, expected_size); | 68 CHECK_EQ(bytes_read, expected_size); |
| 65 } | 69 } |
| 66 | 70 |
| 67 static void ReadYV12Data(scoped_ptr<uint8[]>* data) { | 71 static void ReadYV12Data(scoped_ptr<uint8_t[]>* data) { |
| 68 ReadData(FILE_PATH_LITERAL("bali_640x360_P420.yuv"), kYUV12Size, data); | 72 ReadData(FILE_PATH_LITERAL("bali_640x360_P420.yuv"), kYUV12Size, data); |
| 69 } | 73 } |
| 70 | 74 |
| 71 static void ReadYV16Data(scoped_ptr<uint8[]>* data) { | 75 static void ReadYV16Data(scoped_ptr<uint8_t[]>* data) { |
| 72 ReadData(FILE_PATH_LITERAL("bali_640x360_P422.yuv"), kYUV16Size, data); | 76 ReadData(FILE_PATH_LITERAL("bali_640x360_P422.yuv"), kYUV16Size, data); |
| 73 } | 77 } |
| 74 | 78 |
| 75 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) && \ | 79 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) && \ |
| 76 !defined(OS_ANDROID) | 80 !defined(OS_ANDROID) |
| 77 static void ReadYV12AData(scoped_ptr<uint8[]>* data) { | 81 static void ReadYV12AData(scoped_ptr<uint8_t[]>* data) { |
| 78 ReadData(FILE_PATH_LITERAL("bali_640x360_P420_alpha.yuv"), kYUVA12Size, data); | 82 ReadData(FILE_PATH_LITERAL("bali_640x360_P420_alpha.yuv"), kYUVA12Size, data); |
| 79 } | 83 } |
| 80 #endif | 84 #endif |
| 81 | 85 |
| 82 static void ReadRGB24Data(scoped_ptr<uint8[]>* data) { | 86 static void ReadRGB24Data(scoped_ptr<uint8_t[]>* data) { |
| 83 ReadData(FILE_PATH_LITERAL("bali_640x360_RGB24.rgb"), kRGB24Size, data); | 87 ReadData(FILE_PATH_LITERAL("bali_640x360_RGB24.rgb"), kRGB24Size, data); |
| 84 } | 88 } |
| 85 | 89 |
| 86 #if defined(OS_ANDROID) | 90 #if defined(OS_ANDROID) |
| 87 // Helper for swapping red and blue channels of RGBA or BGRA. | 91 // Helper for swapping red and blue channels of RGBA or BGRA. |
| 88 static void SwapRedAndBlueChannels(unsigned char* pixels, size_t buffer_size) { | 92 static void SwapRedAndBlueChannels(unsigned char* pixels, size_t buffer_size) { |
| 89 for (size_t i = 0; i < buffer_size; i += 4) { | 93 for (size_t i = 0; i < buffer_size; i += 4) { |
| 90 std::swap(pixels[i], pixels[i + 2]); | 94 std::swap(pixels[i], pixels[i + 2]); |
| 91 } | 95 } |
| 92 } | 96 } |
| 93 #endif | 97 #endif |
| 94 | 98 |
| 95 namespace media { | 99 namespace media { |
| 96 | 100 |
| 97 TEST(YUVConvertTest, YV12) { | 101 TEST(YUVConvertTest, YV12) { |
| 98 // Allocate all surfaces. | 102 // Allocate all surfaces. |
| 99 scoped_ptr<uint8[]> yuv_bytes; | 103 scoped_ptr<uint8_t[]> yuv_bytes; |
| 100 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); | 104 scoped_ptr<uint8_t[]> rgb_bytes(new uint8_t[kRGBSize]); |
| 101 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSizeConverted]); | 105 scoped_ptr<uint8_t[]> rgb_converted_bytes(new uint8_t[kRGBSizeConverted]); |
| 102 | 106 |
| 103 // Read YUV reference data from file. | 107 // Read YUV reference data from file. |
| 104 ReadYV12Data(&yuv_bytes); | 108 ReadYV12Data(&yuv_bytes); |
| 105 | 109 |
| 106 // Convert a frame of YUV to 32 bit ARGB. | 110 // Convert a frame of YUV to 32 bit ARGB. |
| 107 media::ConvertYUVToRGB32(yuv_bytes.get(), | 111 media::ConvertYUVToRGB32(yuv_bytes.get(), |
| 108 yuv_bytes.get() + kSourceUOffset, | 112 yuv_bytes.get() + kSourceUOffset, |
| 109 yuv_bytes.get() + kSourceVOffset, | 113 yuv_bytes.get() + kSourceVOffset, |
| 110 rgb_converted_bytes.get(), // RGB output | 114 rgb_converted_bytes.get(), // RGB output |
| 111 kSourceWidth, kSourceHeight, // Dimensions | 115 kSourceWidth, kSourceHeight, // Dimensions |
| 112 kSourceWidth, // YStride | 116 kSourceWidth, // YStride |
| 113 kSourceWidth / 2, // UVStride | 117 kSourceWidth / 2, // UVStride |
| 114 kSourceWidth * kBpp, // RGBStride | 118 kSourceWidth * kBpp, // RGBStride |
| 115 media::YV12); | 119 media::YV12); |
| 116 | 120 |
| 117 #if defined(OS_ANDROID) | 121 #if defined(OS_ANDROID) |
| 118 SwapRedAndBlueChannels(rgb_converted_bytes.get(), kRGBSizeConverted); | 122 SwapRedAndBlueChannels(rgb_converted_bytes.get(), kRGBSizeConverted); |
| 119 #endif | 123 #endif |
| 120 | 124 |
| 121 uint32 rgb_hash = DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted, | 125 uint32_t rgb_hash = |
| 122 kDJB2HashSeed); | 126 DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted, kDJB2HashSeed); |
| 123 EXPECT_EQ(2413171226u, rgb_hash); | 127 EXPECT_EQ(2413171226u, rgb_hash); |
| 124 } | 128 } |
| 125 | 129 |
| 126 TEST(YUVConvertTest, YV16) { | 130 TEST(YUVConvertTest, YV16) { |
| 127 // Allocate all surfaces. | 131 // Allocate all surfaces. |
| 128 scoped_ptr<uint8[]> yuv_bytes; | 132 scoped_ptr<uint8_t[]> yuv_bytes; |
| 129 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); | 133 scoped_ptr<uint8_t[]> rgb_bytes(new uint8_t[kRGBSize]); |
| 130 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSizeConverted]); | 134 scoped_ptr<uint8_t[]> rgb_converted_bytes(new uint8_t[kRGBSizeConverted]); |
| 131 | 135 |
| 132 // Read YUV reference data from file. | 136 // Read YUV reference data from file. |
| 133 ReadYV16Data(&yuv_bytes); | 137 ReadYV16Data(&yuv_bytes); |
| 134 | 138 |
| 135 // Convert a frame of YUV to 32 bit ARGB. | 139 // Convert a frame of YUV to 32 bit ARGB. |
| 136 media::ConvertYUVToRGB32(yuv_bytes.get(), // Y | 140 media::ConvertYUVToRGB32(yuv_bytes.get(), // Y |
| 137 yuv_bytes.get() + kSourceUOffset, // U | 141 yuv_bytes.get() + kSourceUOffset, // U |
| 138 yuv_bytes.get() + kSourceYSize * 3 / 2, // V | 142 yuv_bytes.get() + kSourceYSize * 3 / 2, // V |
| 139 rgb_converted_bytes.get(), // RGB output | 143 rgb_converted_bytes.get(), // RGB output |
| 140 kSourceWidth, kSourceHeight, // Dimensions | 144 kSourceWidth, kSourceHeight, // Dimensions |
| 141 kSourceWidth, // YStride | 145 kSourceWidth, // YStride |
| 142 kSourceWidth / 2, // UVStride | 146 kSourceWidth / 2, // UVStride |
| 143 kSourceWidth * kBpp, // RGBStride | 147 kSourceWidth * kBpp, // RGBStride |
| 144 media::YV16); | 148 media::YV16); |
| 145 | 149 |
| 146 #if defined(OS_ANDROID) | 150 #if defined(OS_ANDROID) |
| 147 SwapRedAndBlueChannels(rgb_converted_bytes.get(), kRGBSizeConverted); | 151 SwapRedAndBlueChannels(rgb_converted_bytes.get(), kRGBSizeConverted); |
| 148 #endif | 152 #endif |
| 149 | 153 |
| 150 uint32 rgb_hash = DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted, | 154 uint32_t rgb_hash = |
| 151 kDJB2HashSeed); | 155 DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted, kDJB2HashSeed); |
| 152 EXPECT_EQ(4222342047u, rgb_hash); | 156 EXPECT_EQ(4222342047u, rgb_hash); |
| 153 } | 157 } |
| 154 | 158 |
| 155 struct YUVScaleTestData { | 159 struct YUVScaleTestData { |
| 156 YUVScaleTestData(media::YUVType y, media::ScaleFilter s, uint32 r) | 160 YUVScaleTestData(media::YUVType y, media::ScaleFilter s, uint32_t r) |
| 157 : yuv_type(y), | 161 : yuv_type(y), scale_filter(s), rgb_hash(r) {} |
| 158 scale_filter(s), | |
| 159 rgb_hash(r) { | |
| 160 } | |
| 161 | 162 |
| 162 media::YUVType yuv_type; | 163 media::YUVType yuv_type; |
| 163 media::ScaleFilter scale_filter; | 164 media::ScaleFilter scale_filter; |
| 164 uint32 rgb_hash; | 165 uint32_t rgb_hash; |
| 165 }; | 166 }; |
| 166 | 167 |
| 167 class YUVScaleTest : public ::testing::TestWithParam<YUVScaleTestData> { | 168 class YUVScaleTest : public ::testing::TestWithParam<YUVScaleTestData> { |
| 168 public: | 169 public: |
| 169 YUVScaleTest() { | 170 YUVScaleTest() { |
| 170 switch (GetParam().yuv_type) { | 171 switch (GetParam().yuv_type) { |
| 171 case media::YV12: | 172 case media::YV12: |
| 172 case media::YV12J: | 173 case media::YV12J: |
| 173 case media::YV12HD: | 174 case media::YV12HD: |
| 174 ReadYV12Data(&yuv_bytes_); | 175 ReadYV12Data(&yuv_bytes_); |
| 175 break; | 176 break; |
| 176 case media::YV16: | 177 case media::YV16: |
| 177 ReadYV16Data(&yuv_bytes_); | 178 ReadYV16Data(&yuv_bytes_); |
| 178 break; | 179 break; |
| 179 } | 180 } |
| 180 | 181 |
| 181 rgb_bytes_.reset(new uint8[kRGBSizeScaled]); | 182 rgb_bytes_.reset(new uint8_t[kRGBSizeScaled]); |
| 182 } | 183 } |
| 183 | 184 |
| 184 // Helpers for getting the proper Y, U and V plane offsets. | 185 // Helpers for getting the proper Y, U and V plane offsets. |
| 185 uint8* y_plane() { return yuv_bytes_.get(); } | 186 uint8_t* y_plane() { return yuv_bytes_.get(); } |
| 186 uint8* u_plane() { return yuv_bytes_.get() + kSourceYSize; } | 187 uint8_t* u_plane() { return yuv_bytes_.get() + kSourceYSize; } |
| 187 uint8* v_plane() { | 188 uint8_t* v_plane() { |
| 188 switch (GetParam().yuv_type) { | 189 switch (GetParam().yuv_type) { |
| 189 case media::YV12: | 190 case media::YV12: |
| 190 case media::YV12J: | 191 case media::YV12J: |
| 191 case media::YV12HD: | 192 case media::YV12HD: |
| 192 return yuv_bytes_.get() + kSourceVOffset; | 193 return yuv_bytes_.get() + kSourceVOffset; |
| 193 case media::YV16: | 194 case media::YV16: |
| 194 return yuv_bytes_.get() + kSourceYSize * 3 / 2; | 195 return yuv_bytes_.get() + kSourceYSize * 3 / 2; |
| 195 } | 196 } |
| 196 return NULL; | 197 return NULL; |
| 197 } | 198 } |
| 198 | 199 |
| 199 scoped_ptr<uint8[]> yuv_bytes_; | 200 scoped_ptr<uint8_t[]> yuv_bytes_; |
| 200 scoped_ptr<uint8[]> rgb_bytes_; | 201 scoped_ptr<uint8_t[]> rgb_bytes_; |
| 201 }; | 202 }; |
| 202 | 203 |
| 203 TEST_P(YUVScaleTest, NoScale) { | 204 TEST_P(YUVScaleTest, NoScale) { |
| 204 media::ScaleYUVToRGB32(y_plane(), // Y | 205 media::ScaleYUVToRGB32(y_plane(), // Y |
| 205 u_plane(), // U | 206 u_plane(), // U |
| 206 v_plane(), // V | 207 v_plane(), // V |
| 207 rgb_bytes_.get(), // RGB output | 208 rgb_bytes_.get(), // RGB output |
| 208 kSourceWidth, kSourceHeight, // Dimensions | 209 kSourceWidth, kSourceHeight, // Dimensions |
| 209 kSourceWidth, kSourceHeight, // Dimensions | 210 kSourceWidth, kSourceHeight, // Dimensions |
| 210 kSourceWidth, // YStride | 211 kSourceWidth, // YStride |
| 211 kSourceWidth / 2, // UvStride | 212 kSourceWidth / 2, // UvStride |
| 212 kSourceWidth * kBpp, // RgbStride | 213 kSourceWidth * kBpp, // RgbStride |
| 213 GetParam().yuv_type, | 214 GetParam().yuv_type, |
| 214 media::ROTATE_0, | 215 media::ROTATE_0, |
| 215 GetParam().scale_filter); | 216 GetParam().scale_filter); |
| 216 | 217 |
| 217 uint32 yuv_hash = DJB2Hash(rgb_bytes_.get(), kRGBSize, kDJB2HashSeed); | 218 uint32_t yuv_hash = DJB2Hash(rgb_bytes_.get(), kRGBSize, kDJB2HashSeed); |
| 218 | 219 |
| 219 media::ConvertYUVToRGB32(y_plane(), // Y | 220 media::ConvertYUVToRGB32(y_plane(), // Y |
| 220 u_plane(), // U | 221 u_plane(), // U |
| 221 v_plane(), // V | 222 v_plane(), // V |
| 222 rgb_bytes_.get(), // RGB output | 223 rgb_bytes_.get(), // RGB output |
| 223 kSourceWidth, kSourceHeight, // Dimensions | 224 kSourceWidth, kSourceHeight, // Dimensions |
| 224 kSourceWidth, // YStride | 225 kSourceWidth, // YStride |
| 225 kSourceWidth / 2, // UVStride | 226 kSourceWidth / 2, // UVStride |
| 226 kSourceWidth * kBpp, // RGBStride | 227 kSourceWidth * kBpp, // RGBStride |
| 227 GetParam().yuv_type); | 228 GetParam().yuv_type); |
| 228 | 229 |
| 229 uint32 rgb_hash = DJB2Hash(rgb_bytes_.get(), kRGBSize, kDJB2HashSeed); | 230 uint32_t rgb_hash = DJB2Hash(rgb_bytes_.get(), kRGBSize, kDJB2HashSeed); |
| 230 | 231 |
| 231 EXPECT_EQ(yuv_hash, rgb_hash); | 232 EXPECT_EQ(yuv_hash, rgb_hash); |
| 232 } | 233 } |
| 233 | 234 |
| 234 TEST_P(YUVScaleTest, Normal) { | 235 TEST_P(YUVScaleTest, Normal) { |
| 235 media::ScaleYUVToRGB32(y_plane(), // Y | 236 media::ScaleYUVToRGB32(y_plane(), // Y |
| 236 u_plane(), // U | 237 u_plane(), // U |
| 237 v_plane(), // V | 238 v_plane(), // V |
| 238 rgb_bytes_.get(), // RGB output | 239 rgb_bytes_.get(), // RGB output |
| 239 kSourceWidth, kSourceHeight, // Dimensions | 240 kSourceWidth, kSourceHeight, // Dimensions |
| 240 kScaledWidth, kScaledHeight, // Dimensions | 241 kScaledWidth, kScaledHeight, // Dimensions |
| 241 kSourceWidth, // YStride | 242 kSourceWidth, // YStride |
| 242 kSourceWidth / 2, // UvStride | 243 kSourceWidth / 2, // UvStride |
| 243 kScaledWidth * kBpp, // RgbStride | 244 kScaledWidth * kBpp, // RgbStride |
| 244 GetParam().yuv_type, | 245 GetParam().yuv_type, |
| 245 media::ROTATE_0, | 246 media::ROTATE_0, |
| 246 GetParam().scale_filter); | 247 GetParam().scale_filter); |
| 247 | 248 |
| 248 #if defined(OS_ANDROID) | 249 #if defined(OS_ANDROID) |
| 249 SwapRedAndBlueChannels(rgb_bytes_.get(), kRGBSizeScaled); | 250 SwapRedAndBlueChannels(rgb_bytes_.get(), kRGBSizeScaled); |
| 250 #endif | 251 #endif |
| 251 | 252 |
| 252 uint32 rgb_hash = DJB2Hash(rgb_bytes_.get(), kRGBSizeScaled, kDJB2HashSeed); | 253 uint32_t rgb_hash = DJB2Hash(rgb_bytes_.get(), kRGBSizeScaled, kDJB2HashSeed); |
| 253 EXPECT_EQ(GetParam().rgb_hash, rgb_hash); | 254 EXPECT_EQ(GetParam().rgb_hash, rgb_hash); |
| 254 } | 255 } |
| 255 | 256 |
| 256 TEST_P(YUVScaleTest, ZeroSourceSize) { | 257 TEST_P(YUVScaleTest, ZeroSourceSize) { |
| 257 media::ScaleYUVToRGB32(y_plane(), // Y | 258 media::ScaleYUVToRGB32(y_plane(), // Y |
| 258 u_plane(), // U | 259 u_plane(), // U |
| 259 v_plane(), // V | 260 v_plane(), // V |
| 260 rgb_bytes_.get(), // RGB output | 261 rgb_bytes_.get(), // RGB output |
| 261 0, 0, // Dimensions | 262 0, 0, // Dimensions |
| 262 kScaledWidth, kScaledHeight, // Dimensions | 263 kScaledWidth, kScaledHeight, // Dimensions |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 YUVScaleFormats, YUVScaleTest, | 307 YUVScaleFormats, YUVScaleTest, |
| 307 ::testing::Values( | 308 ::testing::Values( |
| 308 YUVScaleTestData(media::YV12, media::FILTER_NONE, 4136904952u), | 309 YUVScaleTestData(media::YV12, media::FILTER_NONE, 4136904952u), |
| 309 YUVScaleTestData(media::YV16, media::FILTER_NONE, 1501777547u), | 310 YUVScaleTestData(media::YV16, media::FILTER_NONE, 1501777547u), |
| 310 YUVScaleTestData(media::YV12, media::FILTER_BILINEAR, 3164274689u), | 311 YUVScaleTestData(media::YV12, media::FILTER_BILINEAR, 3164274689u), |
| 311 YUVScaleTestData(media::YV16, media::FILTER_BILINEAR, 3095878046u))); | 312 YUVScaleTestData(media::YV16, media::FILTER_BILINEAR, 3095878046u))); |
| 312 | 313 |
| 313 // This tests a known worst case YUV value, and for overflow. | 314 // This tests a known worst case YUV value, and for overflow. |
| 314 TEST(YUVConvertTest, Clamp) { | 315 TEST(YUVConvertTest, Clamp) { |
| 315 // Allocate all surfaces. | 316 // Allocate all surfaces. |
| 316 scoped_ptr<uint8[]> yuv_bytes(new uint8[1]); | 317 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[1]); |
| 317 scoped_ptr<uint8[]> rgb_bytes(new uint8[1]); | 318 scoped_ptr<uint8_t[]> rgb_bytes(new uint8_t[1]); |
| 318 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[1]); | 319 scoped_ptr<uint8_t[]> rgb_converted_bytes(new uint8_t[1]); |
| 319 | 320 |
| 320 // Values that failed previously in bug report. | 321 // Values that failed previously in bug report. |
| 321 unsigned char y = 255u; | 322 unsigned char y = 255u; |
| 322 unsigned char u = 255u; | 323 unsigned char u = 255u; |
| 323 unsigned char v = 19u; | 324 unsigned char v = 19u; |
| 324 | 325 |
| 325 // Prefill extra large destination buffer to test for overflow. | 326 // Prefill extra large destination buffer to test for overflow. |
| 326 unsigned char rgb[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; | 327 unsigned char rgb[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; |
| 327 unsigned char expected[8] = { 255, 255, 104, 255, 4, 5, 6, 7 }; | 328 unsigned char expected[8] = { 255, 255, 104, 255, 4, 5, 6, 7 }; |
| 328 // Convert a frame of YUV to 32 bit ARGB. | 329 // Convert a frame of YUV to 32 bit ARGB. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 339 #if defined(OS_ANDROID) | 340 #if defined(OS_ANDROID) |
| 340 SwapRedAndBlueChannels(rgb, kBpp); | 341 SwapRedAndBlueChannels(rgb, kBpp); |
| 341 #endif | 342 #endif |
| 342 | 343 |
| 343 int expected_test = memcmp(rgb, expected, sizeof(expected)); | 344 int expected_test = memcmp(rgb, expected, sizeof(expected)); |
| 344 EXPECT_EQ(0, expected_test); | 345 EXPECT_EQ(0, expected_test); |
| 345 } | 346 } |
| 346 | 347 |
| 347 TEST(YUVConvertTest, RGB24ToYUV) { | 348 TEST(YUVConvertTest, RGB24ToYUV) { |
| 348 // Allocate all surfaces. | 349 // Allocate all surfaces. |
| 349 scoped_ptr<uint8[]> rgb_bytes; | 350 scoped_ptr<uint8_t[]> rgb_bytes; |
| 350 scoped_ptr<uint8[]> yuv_converted_bytes(new uint8[kYUV12Size]); | 351 scoped_ptr<uint8_t[]> yuv_converted_bytes(new uint8_t[kYUV12Size]); |
| 351 | 352 |
| 352 // Read RGB24 reference data from file. | 353 // Read RGB24 reference data from file. |
| 353 ReadRGB24Data(&rgb_bytes); | 354 ReadRGB24Data(&rgb_bytes); |
| 354 | 355 |
| 355 // Convert to I420. | 356 // Convert to I420. |
| 356 media::ConvertRGB24ToYUV(rgb_bytes.get(), | 357 media::ConvertRGB24ToYUV(rgb_bytes.get(), |
| 357 yuv_converted_bytes.get(), | 358 yuv_converted_bytes.get(), |
| 358 yuv_converted_bytes.get() + kSourceUOffset, | 359 yuv_converted_bytes.get() + kSourceUOffset, |
| 359 yuv_converted_bytes.get() + kSourceVOffset, | 360 yuv_converted_bytes.get() + kSourceVOffset, |
| 360 kSourceWidth, kSourceHeight, // Dimensions | 361 kSourceWidth, kSourceHeight, // Dimensions |
| 361 kSourceWidth * 3, // RGBStride | 362 kSourceWidth * 3, // RGBStride |
| 362 kSourceWidth, // YStride | 363 kSourceWidth, // YStride |
| 363 kSourceWidth / 2); // UVStride | 364 kSourceWidth / 2); // UVStride |
| 364 | 365 |
| 365 uint32 rgb_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, | 366 uint32_t rgb_hash = |
| 366 kDJB2HashSeed); | 367 DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, kDJB2HashSeed); |
| 367 EXPECT_EQ(320824432u, rgb_hash); | 368 EXPECT_EQ(320824432u, rgb_hash); |
| 368 } | 369 } |
| 369 | 370 |
| 370 TEST(YUVConvertTest, RGB32ToYUV) { | 371 TEST(YUVConvertTest, RGB32ToYUV) { |
| 371 // Allocate all surfaces. | 372 // Allocate all surfaces. |
| 372 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); | 373 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); |
| 373 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); | 374 scoped_ptr<uint8_t[]> rgb_bytes(new uint8_t[kRGBSize]); |
| 374 scoped_ptr<uint8[]> yuv_converted_bytes(new uint8[kYUV12Size]); | 375 scoped_ptr<uint8_t[]> yuv_converted_bytes(new uint8_t[kYUV12Size]); |
| 375 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSize]); | 376 scoped_ptr<uint8_t[]> rgb_converted_bytes(new uint8_t[kRGBSize]); |
| 376 | 377 |
| 377 // Read YUV reference data from file. | 378 // Read YUV reference data from file. |
| 378 base::FilePath yuv_url; | 379 base::FilePath yuv_url; |
| 379 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); | 380 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); |
| 380 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) | 381 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) |
| 381 .Append(FILE_PATH_LITERAL("test")) | 382 .Append(FILE_PATH_LITERAL("test")) |
| 382 .Append(FILE_PATH_LITERAL("data")) | 383 .Append(FILE_PATH_LITERAL("data")) |
| 383 .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); | 384 .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); |
| 384 EXPECT_EQ(static_cast<int>(kYUV12Size), | 385 EXPECT_EQ(static_cast<int>(kYUV12Size), |
| 385 base::ReadFile(yuv_url, | 386 base::ReadFile(yuv_url, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 434 |
| 434 TEST(YUVConvertTest, DownScaleYUVToRGB32WithRect) { | 435 TEST(YUVConvertTest, DownScaleYUVToRGB32WithRect) { |
| 435 // Read YUV reference data from file. | 436 // Read YUV reference data from file. |
| 436 base::FilePath yuv_url; | 437 base::FilePath yuv_url; |
| 437 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); | 438 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); |
| 438 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) | 439 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) |
| 439 .Append(FILE_PATH_LITERAL("test")) | 440 .Append(FILE_PATH_LITERAL("test")) |
| 440 .Append(FILE_PATH_LITERAL("data")) | 441 .Append(FILE_PATH_LITERAL("data")) |
| 441 .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); | 442 .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); |
| 442 const size_t size_of_yuv = kSourceYSize * 12 / 8; // 12 bpp. | 443 const size_t size_of_yuv = kSourceYSize * 12 / 8; // 12 bpp. |
| 443 scoped_ptr<uint8[]> yuv_bytes(new uint8[size_of_yuv]); | 444 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[size_of_yuv]); |
| 444 EXPECT_EQ(static_cast<int>(size_of_yuv), | 445 EXPECT_EQ(static_cast<int>(size_of_yuv), |
| 445 base::ReadFile(yuv_url, | 446 base::ReadFile(yuv_url, |
| 446 reinterpret_cast<char*>(yuv_bytes.get()), | 447 reinterpret_cast<char*>(yuv_bytes.get()), |
| 447 static_cast<int>(size_of_yuv))); | 448 static_cast<int>(size_of_yuv))); |
| 448 | 449 |
| 449 // Scale the full frame of YUV to 32 bit ARGB. | 450 // Scale the full frame of YUV to 32 bit ARGB. |
| 450 // The API currently only supports down-scaling, so we don't test up-scaling. | 451 // The API currently only supports down-scaling, so we don't test up-scaling. |
| 451 const size_t size_of_rgb_scaled = kDownScaledWidth * kDownScaledHeight * kBpp; | 452 const size_t size_of_rgb_scaled = kDownScaledWidth * kDownScaledHeight * kBpp; |
| 452 scoped_ptr<uint8[]> rgb_scaled_bytes(new uint8[size_of_rgb_scaled]); | 453 scoped_ptr<uint8_t[]> rgb_scaled_bytes(new uint8_t[size_of_rgb_scaled]); |
| 453 gfx::Rect sub_rect(0, 0, kDownScaledWidth, kDownScaledHeight); | 454 gfx::Rect sub_rect(0, 0, kDownScaledWidth, kDownScaledHeight); |
| 454 | 455 |
| 455 // We can't compare with the full-frame scaler because it uses slightly | 456 // We can't compare with the full-frame scaler because it uses slightly |
| 456 // different sampling coordinates. | 457 // different sampling coordinates. |
| 457 media::ScaleYUVToRGB32WithRect( | 458 media::ScaleYUVToRGB32WithRect( |
| 458 yuv_bytes.get(), // Y | 459 yuv_bytes.get(), // Y |
| 459 yuv_bytes.get() + kSourceUOffset, // U | 460 yuv_bytes.get() + kSourceUOffset, // U |
| 460 yuv_bytes.get() + kSourceVOffset, // V | 461 yuv_bytes.get() + kSourceVOffset, // V |
| 461 rgb_scaled_bytes.get(), // Rgb output | 462 rgb_scaled_bytes.get(), // Rgb output |
| 462 kSourceWidth, kSourceHeight, // Dimensions | 463 kSourceWidth, kSourceHeight, // Dimensions |
| 463 kDownScaledWidth, kDownScaledHeight, // Dimensions | 464 kDownScaledWidth, kDownScaledHeight, // Dimensions |
| 464 sub_rect.x(), sub_rect.y(), // Dest rect | 465 sub_rect.x(), sub_rect.y(), // Dest rect |
| 465 sub_rect.right(), sub_rect.bottom(), // Dest rect | 466 sub_rect.right(), sub_rect.bottom(), // Dest rect |
| 466 kSourceWidth, // YStride | 467 kSourceWidth, // YStride |
| 467 kSourceWidth / 2, // UvStride | 468 kSourceWidth / 2, // UvStride |
| 468 kDownScaledWidth * kBpp); // RgbStride | 469 kDownScaledWidth * kBpp); // RgbStride |
| 469 | 470 |
| 470 uint32 rgb_hash_full_rect = DJB2Hash(rgb_scaled_bytes.get(), | 471 uint32_t rgb_hash_full_rect = |
| 471 size_of_rgb_scaled, | 472 DJB2Hash(rgb_scaled_bytes.get(), size_of_rgb_scaled, kDJB2HashSeed); |
| 472 kDJB2HashSeed); | |
| 473 | 473 |
| 474 // Re-scale sub-rectangles and verify the results are the same. | 474 // Re-scale sub-rectangles and verify the results are the same. |
| 475 int next_sub_rect = 0; | 475 int next_sub_rect = 0; |
| 476 while (!sub_rect.IsEmpty()) { | 476 while (!sub_rect.IsEmpty()) { |
| 477 // Scale a partial rectangle. | 477 // Scale a partial rectangle. |
| 478 media::ScaleYUVToRGB32WithRect( | 478 media::ScaleYUVToRGB32WithRect( |
| 479 yuv_bytes.get(), // Y | 479 yuv_bytes.get(), // Y |
| 480 yuv_bytes.get() + kSourceUOffset, // U | 480 yuv_bytes.get() + kSourceUOffset, // U |
| 481 yuv_bytes.get() + kSourceVOffset, // V | 481 yuv_bytes.get() + kSourceVOffset, // V |
| 482 rgb_scaled_bytes.get(), // Rgb output | 482 rgb_scaled_bytes.get(), // Rgb output |
| 483 kSourceWidth, kSourceHeight, // Dimensions | 483 kSourceWidth, kSourceHeight, // Dimensions |
| 484 kDownScaledWidth, kDownScaledHeight, // Dimensions | 484 kDownScaledWidth, kDownScaledHeight, // Dimensions |
| 485 sub_rect.x(), sub_rect.y(), // Dest rect | 485 sub_rect.x(), sub_rect.y(), // Dest rect |
| 486 sub_rect.right(), sub_rect.bottom(), // Dest rect | 486 sub_rect.right(), sub_rect.bottom(), // Dest rect |
| 487 kSourceWidth, // YStride | 487 kSourceWidth, // YStride |
| 488 kSourceWidth / 2, // UvStride | 488 kSourceWidth / 2, // UvStride |
| 489 kDownScaledWidth * kBpp); // RgbStride | 489 kDownScaledWidth * kBpp); // RgbStride |
| 490 uint32 rgb_hash_sub_rect = DJB2Hash(rgb_scaled_bytes.get(), | 490 uint32_t rgb_hash_sub_rect = |
| 491 size_of_rgb_scaled, | 491 DJB2Hash(rgb_scaled_bytes.get(), size_of_rgb_scaled, kDJB2HashSeed); |
| 492 kDJB2HashSeed); | |
| 493 | 492 |
| 494 EXPECT_EQ(rgb_hash_full_rect, rgb_hash_sub_rect); | 493 EXPECT_EQ(rgb_hash_full_rect, rgb_hash_sub_rect); |
| 495 | 494 |
| 496 // Now pick choose a quarter rect of this sub-rect. | 495 // Now pick choose a quarter rect of this sub-rect. |
| 497 if (next_sub_rect & 1) | 496 if (next_sub_rect & 1) |
| 498 sub_rect.set_x(sub_rect.x() + sub_rect.width() / 2); | 497 sub_rect.set_x(sub_rect.x() + sub_rect.width() / 2); |
| 499 if (next_sub_rect & 2) | 498 if (next_sub_rect & 2) |
| 500 sub_rect.set_y(sub_rect.y() + sub_rect.height() / 2); | 499 sub_rect.set_y(sub_rect.y() + sub_rect.height() / 2); |
| 501 sub_rect.set_width(sub_rect.width() / 2); | 500 sub_rect.set_width(sub_rect.width() / 2); |
| 502 sub_rect.set_height(sub_rect.height() / 2); | 501 sub_rect.set_height(sub_rect.height() / 2); |
| 503 next_sub_rect++; | 502 next_sub_rect++; |
| 504 } | 503 } |
| 505 } | 504 } |
| 506 | 505 |
| 507 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) | 506 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) |
| 508 #if !defined(OS_ANDROID) | 507 #if !defined(OS_ANDROID) |
| 509 TEST(YUVConvertTest, YUVAtoARGB_MMX_MatchReference) { | 508 TEST(YUVConvertTest, YUVAtoARGB_MMX_MatchReference) { |
| 510 // Allocate all surfaces. | 509 // Allocate all surfaces. |
| 511 scoped_ptr<uint8[]> yuv_bytes; | 510 scoped_ptr<uint8_t[]> yuv_bytes; |
| 512 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); | 511 scoped_ptr<uint8_t[]> rgb_bytes(new uint8_t[kRGBSize]); |
| 513 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSizeConverted]); | 512 scoped_ptr<uint8_t[]> rgb_converted_bytes(new uint8_t[kRGBSizeConverted]); |
| 514 scoped_ptr<uint8[]> rgb_converted_bytes_ref(new uint8[kRGBSizeConverted]); | 513 scoped_ptr<uint8_t[]> rgb_converted_bytes_ref(new uint8_t[kRGBSizeConverted]); |
| 515 | 514 |
| 516 // Read YUV reference data from file. | 515 // Read YUV reference data from file. |
| 517 ReadYV12AData(&yuv_bytes); | 516 ReadYV12AData(&yuv_bytes); |
| 518 | 517 |
| 519 // Convert a frame of YUV to 32 bit ARGB using both C and MMX versions. | 518 // Convert a frame of YUV to 32 bit ARGB using both C and MMX versions. |
| 520 media::ConvertYUVAToARGB_C(yuv_bytes.get(), | 519 media::ConvertYUVAToARGB_C(yuv_bytes.get(), |
| 521 yuv_bytes.get() + kSourceUOffset, | 520 yuv_bytes.get() + kSourceUOffset, |
| 522 yuv_bytes.get() + kSourceVOffset, | 521 yuv_bytes.get() + kSourceVOffset, |
| 523 yuv_bytes.get() + kSourceAOffset, | 522 yuv_bytes.get() + kSourceAOffset, |
| 524 rgb_converted_bytes_ref.get(), | 523 rgb_converted_bytes_ref.get(), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 550 #endif // !defined(OS_ANDROID) | 549 #endif // !defined(OS_ANDROID) |
| 551 | 550 |
| 552 TEST(YUVConvertTest, RGB32ToYUV_SSE2_MatchReference) { | 551 TEST(YUVConvertTest, RGB32ToYUV_SSE2_MatchReference) { |
| 553 base::CPU cpu; | 552 base::CPU cpu; |
| 554 if (!cpu.has_sse2()) { | 553 if (!cpu.has_sse2()) { |
| 555 LOG(WARNING) << "System doesn't support SSE2, test not executed."; | 554 LOG(WARNING) << "System doesn't support SSE2, test not executed."; |
| 556 return; | 555 return; |
| 557 } | 556 } |
| 558 | 557 |
| 559 // Allocate all surfaces. | 558 // Allocate all surfaces. |
| 560 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); | 559 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); |
| 561 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); | 560 scoped_ptr<uint8_t[]> rgb_bytes(new uint8_t[kRGBSize]); |
| 562 scoped_ptr<uint8[]> yuv_converted_bytes(new uint8[kYUV12Size]); | 561 scoped_ptr<uint8_t[]> yuv_converted_bytes(new uint8_t[kYUV12Size]); |
| 563 scoped_ptr<uint8[]> yuv_reference_bytes(new uint8[kYUV12Size]); | 562 scoped_ptr<uint8_t[]> yuv_reference_bytes(new uint8_t[kYUV12Size]); |
| 564 | 563 |
| 565 ReadYV12Data(&yuv_bytes); | 564 ReadYV12Data(&yuv_bytes); |
| 566 | 565 |
| 567 // Convert a frame of YUV to 32 bit ARGB. | 566 // Convert a frame of YUV to 32 bit ARGB. |
| 568 media::ConvertYUVToRGB32( | 567 media::ConvertYUVToRGB32( |
| 569 yuv_bytes.get(), | 568 yuv_bytes.get(), |
| 570 yuv_bytes.get() + kSourceUOffset, | 569 yuv_bytes.get() + kSourceUOffset, |
| 571 yuv_bytes.get() + kSourceVOffset, | 570 yuv_bytes.get() + kSourceVOffset, |
| 572 rgb_bytes.get(), // RGB output | 571 rgb_bytes.get(), // RGB output |
| 573 kSourceWidth, kSourceHeight, // Dimensions | 572 kSourceWidth, kSourceHeight, // Dimensions |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 EXPECT_EQ(0, error); | 635 EXPECT_EQ(0, error); |
| 637 } | 636 } |
| 638 | 637 |
| 639 TEST(YUVConvertTest, ConvertYUVToRGB32Row_SSE) { | 638 TEST(YUVConvertTest, ConvertYUVToRGB32Row_SSE) { |
| 640 base::CPU cpu; | 639 base::CPU cpu; |
| 641 if (!cpu.has_sse()) { | 640 if (!cpu.has_sse()) { |
| 642 LOG(WARNING) << "System not supported. Test skipped."; | 641 LOG(WARNING) << "System not supported. Test skipped."; |
| 643 return; | 642 return; |
| 644 } | 643 } |
| 645 | 644 |
| 646 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); | 645 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); |
| 647 scoped_ptr<uint8[]> rgb_bytes_reference(new uint8[kRGBSize]); | 646 scoped_ptr<uint8_t[]> rgb_bytes_reference(new uint8_t[kRGBSize]); |
| 648 scoped_ptr<uint8[]> rgb_bytes_converted(new uint8[kRGBSize]); | 647 scoped_ptr<uint8_t[]> rgb_bytes_converted(new uint8_t[kRGBSize]); |
| 649 ReadYV12Data(&yuv_bytes); | 648 ReadYV12Data(&yuv_bytes); |
| 650 | 649 |
| 651 const int kWidth = 167; | 650 const int kWidth = 167; |
| 652 ConvertYUVToRGB32Row_C(yuv_bytes.get(), | 651 ConvertYUVToRGB32Row_C(yuv_bytes.get(), |
| 653 yuv_bytes.get() + kSourceUOffset, | 652 yuv_bytes.get() + kSourceUOffset, |
| 654 yuv_bytes.get() + kSourceVOffset, | 653 yuv_bytes.get() + kSourceVOffset, |
| 655 rgb_bytes_reference.get(), | 654 rgb_bytes_reference.get(), |
| 656 kWidth, | 655 kWidth, |
| 657 GetLookupTable(YV12)); | 656 GetLookupTable(YV12)); |
| 658 ConvertYUVToRGB32Row_SSE(yuv_bytes.get(), | 657 ConvertYUVToRGB32Row_SSE(yuv_bytes.get(), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 670 // 64-bit release + component builds on Windows are too smart and optimizes | 669 // 64-bit release + component builds on Windows are too smart and optimizes |
| 671 // away the function being tested. | 670 // away the function being tested. |
| 672 #if defined(OS_WIN) && (defined(ARCH_CPU_X86) || !defined(COMPONENT_BUILD)) | 671 #if defined(OS_WIN) && (defined(ARCH_CPU_X86) || !defined(COMPONENT_BUILD)) |
| 673 TEST(YUVConvertTest, ScaleYUVToRGB32Row_SSE) { | 672 TEST(YUVConvertTest, ScaleYUVToRGB32Row_SSE) { |
| 674 base::CPU cpu; | 673 base::CPU cpu; |
| 675 if (!cpu.has_sse()) { | 674 if (!cpu.has_sse()) { |
| 676 LOG(WARNING) << "System not supported. Test skipped."; | 675 LOG(WARNING) << "System not supported. Test skipped."; |
| 677 return; | 676 return; |
| 678 } | 677 } |
| 679 | 678 |
| 680 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); | 679 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); |
| 681 scoped_ptr<uint8[]> rgb_bytes_reference(new uint8[kRGBSize]); | 680 scoped_ptr<uint8_t[]> rgb_bytes_reference(new uint8_t[kRGBSize]); |
| 682 scoped_ptr<uint8[]> rgb_bytes_converted(new uint8[kRGBSize]); | 681 scoped_ptr<uint8_t[]> rgb_bytes_converted(new uint8_t[kRGBSize]); |
| 683 ReadYV12Data(&yuv_bytes); | 682 ReadYV12Data(&yuv_bytes); |
| 684 | 683 |
| 685 const int kWidth = 167; | 684 const int kWidth = 167; |
| 686 const int kSourceDx = 80000; // This value means a scale down. | 685 const int kSourceDx = 80000; // This value means a scale down. |
| 687 ScaleYUVToRGB32Row_C(yuv_bytes.get(), | 686 ScaleYUVToRGB32Row_C(yuv_bytes.get(), |
| 688 yuv_bytes.get() + kSourceUOffset, | 687 yuv_bytes.get() + kSourceUOffset, |
| 689 yuv_bytes.get() + kSourceVOffset, | 688 yuv_bytes.get() + kSourceVOffset, |
| 690 rgb_bytes_reference.get(), | 689 rgb_bytes_reference.get(), |
| 691 kWidth, | 690 kWidth, |
| 692 kSourceDx, | 691 kSourceDx, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 704 kWidth * kBpp)); | 703 kWidth * kBpp)); |
| 705 } | 704 } |
| 706 | 705 |
| 707 TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_SSE) { | 706 TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_SSE) { |
| 708 base::CPU cpu; | 707 base::CPU cpu; |
| 709 if (!cpu.has_sse()) { | 708 if (!cpu.has_sse()) { |
| 710 LOG(WARNING) << "System not supported. Test skipped."; | 709 LOG(WARNING) << "System not supported. Test skipped."; |
| 711 return; | 710 return; |
| 712 } | 711 } |
| 713 | 712 |
| 714 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); | 713 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); |
| 715 scoped_ptr<uint8[]> rgb_bytes_reference(new uint8[kRGBSize]); | 714 scoped_ptr<uint8_t[]> rgb_bytes_reference(new uint8_t[kRGBSize]); |
| 716 scoped_ptr<uint8[]> rgb_bytes_converted(new uint8[kRGBSize]); | 715 scoped_ptr<uint8_t[]> rgb_bytes_converted(new uint8_t[kRGBSize]); |
| 717 ReadYV12Data(&yuv_bytes); | 716 ReadYV12Data(&yuv_bytes); |
| 718 | 717 |
| 719 const int kWidth = 167; | 718 const int kWidth = 167; |
| 720 const int kSourceDx = 80000; // This value means a scale down. | 719 const int kSourceDx = 80000; // This value means a scale down. |
| 721 LinearScaleYUVToRGB32Row_C(yuv_bytes.get(), | 720 LinearScaleYUVToRGB32Row_C(yuv_bytes.get(), |
| 722 yuv_bytes.get() + kSourceUOffset, | 721 yuv_bytes.get() + kSourceUOffset, |
| 723 yuv_bytes.get() + kSourceVOffset, | 722 yuv_bytes.get() + kSourceVOffset, |
| 724 rgb_bytes_reference.get(), | 723 rgb_bytes_reference.get(), |
| 725 kWidth, | 724 kWidth, |
| 726 kSourceDx, | 725 kSourceDx, |
| 727 GetLookupTable(YV12)); | 726 GetLookupTable(YV12)); |
| 728 LinearScaleYUVToRGB32Row_SSE(yuv_bytes.get(), | 727 LinearScaleYUVToRGB32Row_SSE(yuv_bytes.get(), |
| 729 yuv_bytes.get() + kSourceUOffset, | 728 yuv_bytes.get() + kSourceUOffset, |
| 730 yuv_bytes.get() + kSourceVOffset, | 729 yuv_bytes.get() + kSourceVOffset, |
| 731 rgb_bytes_converted.get(), | 730 rgb_bytes_converted.get(), |
| 732 kWidth, | 731 kWidth, |
| 733 kSourceDx, | 732 kSourceDx, |
| 734 GetLookupTable(YV12)); | 733 GetLookupTable(YV12)); |
| 735 media::EmptyRegisterState(); | 734 media::EmptyRegisterState(); |
| 736 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | 735 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 737 rgb_bytes_converted.get(), | 736 rgb_bytes_converted.get(), |
| 738 kWidth * kBpp)); | 737 kWidth * kBpp)); |
| 739 } | 738 } |
| 740 #endif // defined(OS_WIN) && (ARCH_CPU_X86 || COMPONENT_BUILD) | 739 #endif // defined(OS_WIN) && (ARCH_CPU_X86 || COMPONENT_BUILD) |
| 741 | 740 |
| 742 TEST(YUVConvertTest, FilterYUVRows_C_OutOfBounds) { | 741 TEST(YUVConvertTest, FilterYUVRows_C_OutOfBounds) { |
| 743 scoped_ptr<uint8[]> src(new uint8[16]); | 742 scoped_ptr<uint8_t[]> src(new uint8_t[16]); |
| 744 scoped_ptr<uint8[]> dst(new uint8[16]); | 743 scoped_ptr<uint8_t[]> dst(new uint8_t[16]); |
| 745 | 744 |
| 746 memset(src.get(), 0xff, 16); | 745 memset(src.get(), 0xff, 16); |
| 747 memset(dst.get(), 0, 16); | 746 memset(dst.get(), 0, 16); |
| 748 | 747 |
| 749 media::FilterYUVRows_C(dst.get(), src.get(), src.get(), 1, 255); | 748 media::FilterYUVRows_C(dst.get(), src.get(), src.get(), 1, 255); |
| 750 | 749 |
| 751 EXPECT_EQ(255u, dst[0]); | 750 EXPECT_EQ(255u, dst[0]); |
| 752 for (int i = 1; i < 16; ++i) { | 751 for (int i = 1; i < 16; ++i) { |
| 753 EXPECT_EQ(0u, dst[i]) << " not equal at " << i; | 752 EXPECT_EQ(0u, dst[i]) << " not equal at " << i; |
| 754 } | 753 } |
| 755 } | 754 } |
| 756 | 755 |
| 757 TEST(YUVConvertTest, FilterYUVRows_SSE2_OutOfBounds) { | 756 TEST(YUVConvertTest, FilterYUVRows_SSE2_OutOfBounds) { |
| 758 base::CPU cpu; | 757 base::CPU cpu; |
| 759 if (!cpu.has_sse2()) { | 758 if (!cpu.has_sse2()) { |
| 760 LOG(WARNING) << "System not supported. Test skipped."; | 759 LOG(WARNING) << "System not supported. Test skipped."; |
| 761 return; | 760 return; |
| 762 } | 761 } |
| 763 | 762 |
| 764 scoped_ptr<uint8[]> src(new uint8[16]); | 763 scoped_ptr<uint8_t[]> src(new uint8_t[16]); |
| 765 scoped_ptr<uint8[]> dst(new uint8[16]); | 764 scoped_ptr<uint8_t[]> dst(new uint8_t[16]); |
| 766 | 765 |
| 767 memset(src.get(), 0xff, 16); | 766 memset(src.get(), 0xff, 16); |
| 768 memset(dst.get(), 0, 16); | 767 memset(dst.get(), 0, 16); |
| 769 | 768 |
| 770 media::FilterYUVRows_SSE2(dst.get(), src.get(), src.get(), 1, 255); | 769 media::FilterYUVRows_SSE2(dst.get(), src.get(), src.get(), 1, 255); |
| 771 | 770 |
| 772 EXPECT_EQ(255u, dst[0]); | 771 EXPECT_EQ(255u, dst[0]); |
| 773 for (int i = 1; i < 16; ++i) { | 772 for (int i = 1; i < 16; ++i) { |
| 774 EXPECT_EQ(0u, dst[i]); | 773 EXPECT_EQ(0u, dst[i]); |
| 775 } | 774 } |
| 776 } | 775 } |
| 777 | 776 |
| 778 TEST(YUVConvertTest, FilterYUVRows_SSE2_UnalignedDestination) { | 777 TEST(YUVConvertTest, FilterYUVRows_SSE2_UnalignedDestination) { |
| 779 base::CPU cpu; | 778 base::CPU cpu; |
| 780 if (!cpu.has_sse2()) { | 779 if (!cpu.has_sse2()) { |
| 781 LOG(WARNING) << "System not supported. Test skipped."; | 780 LOG(WARNING) << "System not supported. Test skipped."; |
| 782 return; | 781 return; |
| 783 } | 782 } |
| 784 | 783 |
| 785 const int kSize = 64; | 784 const int kSize = 64; |
| 786 scoped_ptr<uint8[]> src(new uint8[kSize]); | 785 scoped_ptr<uint8_t[]> src(new uint8_t[kSize]); |
| 787 scoped_ptr<uint8[]> dst_sample(new uint8[kSize]); | 786 scoped_ptr<uint8_t[]> dst_sample(new uint8_t[kSize]); |
| 788 scoped_ptr<uint8[]> dst(new uint8[kSize]); | 787 scoped_ptr<uint8_t[]> dst(new uint8_t[kSize]); |
| 789 | 788 |
| 790 memset(dst_sample.get(), 0, kSize); | 789 memset(dst_sample.get(), 0, kSize); |
| 791 memset(dst.get(), 0, kSize); | 790 memset(dst.get(), 0, kSize); |
| 792 for (int i = 0; i < kSize; ++i) | 791 for (int i = 0; i < kSize; ++i) |
| 793 src[i] = 100 + i; | 792 src[i] = 100 + i; |
| 794 | 793 |
| 795 media::FilterYUVRows_C(dst_sample.get(), | 794 media::FilterYUVRows_C(dst_sample.get(), |
| 796 src.get(), src.get(), 37, 128); | 795 src.get(), src.get(), 37, 128); |
| 797 | 796 |
| 798 // Generate an unaligned output address. | 797 // Generate an unaligned output address. |
| 799 uint8* dst_ptr = | 798 uint8_t* dst_ptr = reinterpret_cast<uint8_t*>( |
| 800 reinterpret_cast<uint8*>( | 799 (reinterpret_cast<uintptr_t>(dst.get() + 16) & ~15) + 1); |
| 801 (reinterpret_cast<uintptr_t>(dst.get() + 16) & ~15) + 1); | |
| 802 media::FilterYUVRows_SSE2(dst_ptr, src.get(), src.get(), 37, 128); | 800 media::FilterYUVRows_SSE2(dst_ptr, src.get(), src.get(), 37, 128); |
| 803 media::EmptyRegisterState(); | 801 media::EmptyRegisterState(); |
| 804 | 802 |
| 805 EXPECT_EQ(0, memcmp(dst_sample.get(), dst_ptr, 37)); | 803 EXPECT_EQ(0, memcmp(dst_sample.get(), dst_ptr, 37)); |
| 806 } | 804 } |
| 807 | 805 |
| 808 #if defined(ARCH_CPU_X86_64) | 806 #if defined(ARCH_CPU_X86_64) |
| 809 | 807 |
| 810 TEST(YUVConvertTest, ScaleYUVToRGB32Row_SSE2_X64) { | 808 TEST(YUVConvertTest, ScaleYUVToRGB32Row_SSE2_X64) { |
| 811 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); | 809 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); |
| 812 scoped_ptr<uint8[]> rgb_bytes_reference(new uint8[kRGBSize]); | 810 scoped_ptr<uint8_t[]> rgb_bytes_reference(new uint8_t[kRGBSize]); |
| 813 scoped_ptr<uint8[]> rgb_bytes_converted(new uint8[kRGBSize]); | 811 scoped_ptr<uint8_t[]> rgb_bytes_converted(new uint8_t[kRGBSize]); |
| 814 ReadYV12Data(&yuv_bytes); | 812 ReadYV12Data(&yuv_bytes); |
| 815 | 813 |
| 816 const int kWidth = 167; | 814 const int kWidth = 167; |
| 817 const int kSourceDx = 80000; // This value means a scale down. | 815 const int kSourceDx = 80000; // This value means a scale down. |
| 818 ScaleYUVToRGB32Row_C(yuv_bytes.get(), | 816 ScaleYUVToRGB32Row_C(yuv_bytes.get(), |
| 819 yuv_bytes.get() + kSourceUOffset, | 817 yuv_bytes.get() + kSourceUOffset, |
| 820 yuv_bytes.get() + kSourceVOffset, | 818 yuv_bytes.get() + kSourceVOffset, |
| 821 rgb_bytes_reference.get(), | 819 rgb_bytes_reference.get(), |
| 822 kWidth, | 820 kWidth, |
| 823 kSourceDx, | 821 kSourceDx, |
| 824 GetLookupTable(YV12)); | 822 GetLookupTable(YV12)); |
| 825 ScaleYUVToRGB32Row_SSE2_X64(yuv_bytes.get(), | 823 ScaleYUVToRGB32Row_SSE2_X64(yuv_bytes.get(), |
| 826 yuv_bytes.get() + kSourceUOffset, | 824 yuv_bytes.get() + kSourceUOffset, |
| 827 yuv_bytes.get() + kSourceVOffset, | 825 yuv_bytes.get() + kSourceVOffset, |
| 828 rgb_bytes_converted.get(), | 826 rgb_bytes_converted.get(), |
| 829 kWidth, | 827 kWidth, |
| 830 kSourceDx, | 828 kSourceDx, |
| 831 GetLookupTable(YV12)); | 829 GetLookupTable(YV12)); |
| 832 media::EmptyRegisterState(); | 830 media::EmptyRegisterState(); |
| 833 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | 831 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 834 rgb_bytes_converted.get(), | 832 rgb_bytes_converted.get(), |
| 835 kWidth * kBpp)); | 833 kWidth * kBpp)); |
| 836 } | 834 } |
| 837 | 835 |
| 838 TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_MMX_X64) { | 836 TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_MMX_X64) { |
| 839 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); | 837 scoped_ptr<uint8_t[]> yuv_bytes(new uint8_t[kYUV12Size]); |
| 840 scoped_ptr<uint8[]> rgb_bytes_reference(new uint8[kRGBSize]); | 838 scoped_ptr<uint8_t[]> rgb_bytes_reference(new uint8_t[kRGBSize]); |
| 841 scoped_ptr<uint8[]> rgb_bytes_converted(new uint8[kRGBSize]); | 839 scoped_ptr<uint8_t[]> rgb_bytes_converted(new uint8_t[kRGBSize]); |
| 842 ReadYV12Data(&yuv_bytes); | 840 ReadYV12Data(&yuv_bytes); |
| 843 | 841 |
| 844 const int kWidth = 167; | 842 const int kWidth = 167; |
| 845 const int kSourceDx = 80000; // This value means a scale down. | 843 const int kSourceDx = 80000; // This value means a scale down. |
| 846 LinearScaleYUVToRGB32Row_C(yuv_bytes.get(), | 844 LinearScaleYUVToRGB32Row_C(yuv_bytes.get(), |
| 847 yuv_bytes.get() + kSourceUOffset, | 845 yuv_bytes.get() + kSourceUOffset, |
| 848 yuv_bytes.get() + kSourceVOffset, | 846 yuv_bytes.get() + kSourceVOffset, |
| 849 rgb_bytes_reference.get(), | 847 rgb_bytes_reference.get(), |
| 850 kWidth, | 848 kWidth, |
| 851 kSourceDx, | 849 kSourceDx, |
| 852 GetLookupTable(YV12)); | 850 GetLookupTable(YV12)); |
| 853 LinearScaleYUVToRGB32Row_MMX_X64(yuv_bytes.get(), | 851 LinearScaleYUVToRGB32Row_MMX_X64(yuv_bytes.get(), |
| 854 yuv_bytes.get() + kSourceUOffset, | 852 yuv_bytes.get() + kSourceUOffset, |
| 855 yuv_bytes.get() + kSourceVOffset, | 853 yuv_bytes.get() + kSourceVOffset, |
| 856 rgb_bytes_converted.get(), | 854 rgb_bytes_converted.get(), |
| 857 kWidth, | 855 kWidth, |
| 858 kSourceDx, | 856 kSourceDx, |
| 859 GetLookupTable(YV12)); | 857 GetLookupTable(YV12)); |
| 860 media::EmptyRegisterState(); | 858 media::EmptyRegisterState(); |
| 861 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), | 859 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), |
| 862 rgb_bytes_converted.get(), | 860 rgb_bytes_converted.get(), |
| 863 kWidth * kBpp)); | 861 kWidth * kBpp)); |
| 864 } | 862 } |
| 865 | 863 |
| 866 #endif // defined(ARCH_CPU_X86_64) | 864 #endif // defined(ARCH_CPU_X86_64) |
| 867 | 865 |
| 868 #endif // defined(ARCH_CPU_X86_FAMILY) | 866 #endif // defined(ARCH_CPU_X86_FAMILY) |
| 869 | 867 |
| 870 } // namespace media | 868 } // namespace media |
| OLD | NEW |