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