Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: media/base/yuv_convert_unittest.cc

Issue 17043007: Fix the WebRTC color bug. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing Andrew's comments. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/simd/convert_yuv_to_rgb_c.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/cpu.h" 6 #include "base/cpu.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "media/base/djb2.h" 10 #include "media/base/djb2.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 69 }
70 70
71 static void ReadRGB24Data(scoped_ptr<uint8[]>* data) { 71 static void ReadRGB24Data(scoped_ptr<uint8[]>* data) {
72 ReadData(FILE_PATH_LITERAL("bali_640x360_RGB24.rgb"), kRGB24Size, data); 72 ReadData(FILE_PATH_LITERAL("bali_640x360_RGB24.rgb"), kRGB24Size, data);
73 } 73 }
74 74
75 static void ReadYUY2Data(scoped_ptr<uint8[]>* data) { 75 static void ReadYUY2Data(scoped_ptr<uint8[]>* data) {
76 ReadData(FILE_PATH_LITERAL("bali_640x360_YUY2.yuv"), kYUY2Size, data); 76 ReadData(FILE_PATH_LITERAL("bali_640x360_YUY2.yuv"), kYUY2Size, data);
77 } 77 }
78 78
79 // Helper for converting image format from BGRA to RGBA.
80 static void ConvertBGRAToRGBA(unsigned char* pixels, size_t buffer_size) {
scherkus (not reviewing) 2013/06/20 00:28:08 wait ... isn't this backwards? your comment in me
hkuang1 2013/06/20 03:45:33 Yes, my bad. Should be RGBA to BGRA. "SwapRedAndBl
81 // Swizzle red and blue channels.
82 for (size_t i = 0; i < buffer_size; i += 4) {
83 std::swap(pixels[i], pixels[i + 2]);
84 }
85 }
86
79 namespace media { 87 namespace media {
80 88
81 TEST(YUVConvertTest, YV12) { 89 TEST(YUVConvertTest, YV12) {
82 // Allocate all surfaces. 90 // Allocate all surfaces.
83 scoped_ptr<uint8[]> yuv_bytes; 91 scoped_ptr<uint8[]> yuv_bytes;
84 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); 92 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]);
85 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSizeConverted]); 93 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSizeConverted]);
86 94
87 // Read YUV reference data from file. 95 // Read YUV reference data from file.
88 ReadYV12Data(&yuv_bytes); 96 ReadYV12Data(&yuv_bytes);
89 97
90 // Convert a frame of YUV to 32 bit ARGB. 98 // Convert a frame of YUV to 32 bit ARGB.
91 media::ConvertYUVToRGB32(yuv_bytes.get(), 99 media::ConvertYUVToRGB32(yuv_bytes.get(),
92 yuv_bytes.get() + kSourceUOffset, 100 yuv_bytes.get() + kSourceUOffset,
93 yuv_bytes.get() + kSourceVOffset, 101 yuv_bytes.get() + kSourceVOffset,
94 rgb_converted_bytes.get(), // RGB output 102 rgb_converted_bytes.get(), // RGB output
95 kSourceWidth, kSourceHeight, // Dimensions 103 kSourceWidth, kSourceHeight, // Dimensions
96 kSourceWidth, // YStride 104 kSourceWidth, // YStride
97 kSourceWidth / 2, // UVStride 105 kSourceWidth / 2, // UVStride
98 kSourceWidth * kBpp, // RGBStride 106 kSourceWidth * kBpp, // RGBStride
99 media::YV12); 107 media::YV12);
100 108
109 #if defined(OS_ANDROID)
110 ConvertBGRAToRGBA(rgb_converted_bytes.get(), kRGBSizeConverted);
111 #endif
112
101 uint32 rgb_hash = DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted, 113 uint32 rgb_hash = DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted,
102 kDJB2HashSeed); 114 kDJB2HashSeed);
103 EXPECT_EQ(2413171226u, rgb_hash); 115 EXPECT_EQ(2413171226u, rgb_hash);
104 } 116 }
105 117
106 TEST(YUVConvertTest, YV16) { 118 TEST(YUVConvertTest, YV16) {
107 // Allocate all surfaces. 119 // Allocate all surfaces.
108 scoped_ptr<uint8[]> yuv_bytes; 120 scoped_ptr<uint8[]> yuv_bytes;
109 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); 121 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]);
110 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSizeConverted]); 122 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSizeConverted]);
111 123
112 // Read YUV reference data from file. 124 // Read YUV reference data from file.
113 ReadYV16Data(&yuv_bytes); 125 ReadYV16Data(&yuv_bytes);
114 126
115 // Convert a frame of YUV to 32 bit ARGB. 127 // Convert a frame of YUV to 32 bit ARGB.
116 media::ConvertYUVToRGB32(yuv_bytes.get(), // Y 128 media::ConvertYUVToRGB32(yuv_bytes.get(), // Y
117 yuv_bytes.get() + kSourceUOffset, // U 129 yuv_bytes.get() + kSourceUOffset, // U
118 yuv_bytes.get() + kSourceYSize * 3 / 2, // V 130 yuv_bytes.get() + kSourceYSize * 3 / 2, // V
119 rgb_converted_bytes.get(), // RGB output 131 rgb_converted_bytes.get(), // RGB output
120 kSourceWidth, kSourceHeight, // Dimensions 132 kSourceWidth, kSourceHeight, // Dimensions
121 kSourceWidth, // YStride 133 kSourceWidth, // YStride
122 kSourceWidth / 2, // UVStride 134 kSourceWidth / 2, // UVStride
123 kSourceWidth * kBpp, // RGBStride 135 kSourceWidth * kBpp, // RGBStride
124 media::YV16); 136 media::YV16);
125 137
138 #if defined(OS_ANDROID)
139 ConvertBGRAToRGBA(rgb_converted_bytes.get(), kRGBSizeConverted);
140 #endif
141
126 uint32 rgb_hash = DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted, 142 uint32 rgb_hash = DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted,
127 kDJB2HashSeed); 143 kDJB2HashSeed);
128 EXPECT_EQ(4222342047u, rgb_hash); 144 EXPECT_EQ(4222342047u, rgb_hash);
129 } 145 }
130 146
131 struct YUVScaleTestData { 147 struct YUVScaleTestData {
132 YUVScaleTestData(media::YUVType y, media::ScaleFilter s, uint32 r) 148 YUVScaleTestData(media::YUVType y, media::ScaleFilter s, uint32 r)
133 : yuv_type(y), 149 : yuv_type(y),
134 scale_filter(s), 150 scale_filter(s),
135 rgb_hash(r) { 151 rgb_hash(r) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 rgb_bytes_.get(), // RGB output 226 rgb_bytes_.get(), // RGB output
211 kSourceWidth, kSourceHeight, // Dimensions 227 kSourceWidth, kSourceHeight, // Dimensions
212 kScaledWidth, kScaledHeight, // Dimensions 228 kScaledWidth, kScaledHeight, // Dimensions
213 kSourceWidth, // YStride 229 kSourceWidth, // YStride
214 kSourceWidth / 2, // UvStride 230 kSourceWidth / 2, // UvStride
215 kScaledWidth * kBpp, // RgbStride 231 kScaledWidth * kBpp, // RgbStride
216 GetParam().yuv_type, 232 GetParam().yuv_type,
217 media::ROTATE_0, 233 media::ROTATE_0,
218 GetParam().scale_filter); 234 GetParam().scale_filter);
219 235
236 #if defined(OS_ANDROID)
237 ConvertBGRAToRGBA(rgb_bytes_.get(), kRGBSizeScaled);
238 #endif
239
220 uint32 rgb_hash = DJB2Hash(rgb_bytes_.get(), kRGBSizeScaled, kDJB2HashSeed); 240 uint32 rgb_hash = DJB2Hash(rgb_bytes_.get(), kRGBSizeScaled, kDJB2HashSeed);
221 EXPECT_EQ(GetParam().rgb_hash, rgb_hash); 241 EXPECT_EQ(GetParam().rgb_hash, rgb_hash);
222 } 242 }
223 243
224 TEST_P(YUVScaleTest, ZeroSourceSize) { 244 TEST_P(YUVScaleTest, ZeroSourceSize) {
225 media::ScaleYUVToRGB32(y_plane(), // Y 245 media::ScaleYUVToRGB32(y_plane(), // Y
226 u_plane(), // U 246 u_plane(), // U
227 v_plane(), // V 247 v_plane(), // V
228 rgb_bytes_.get(), // RGB output 248 rgb_bytes_.get(), // RGB output
229 0, 0, // Dimensions 249 0, 0, // Dimensions
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 media::ConvertYUVToRGB32(&y, // Y 317 media::ConvertYUVToRGB32(&y, // Y
298 &u, // U 318 &u, // U
299 &v, // V 319 &v, // V
300 &rgb[0], // RGB output 320 &rgb[0], // RGB output
301 1, 1, // Dimensions 321 1, 1, // Dimensions
302 0, // YStride 322 0, // YStride
303 0, // UVStride 323 0, // UVStride
304 0, // RGBStride 324 0, // RGBStride
305 media::YV12); 325 media::YV12);
306 326
327 #if defined(OS_ANDROID)
328 ConvertBGRAToRGBA(rgb, kBpp);
329 #endif
330
307 int expected_test = memcmp(rgb, expected, sizeof(expected)); 331 int expected_test = memcmp(rgb, expected, sizeof(expected));
308 EXPECT_EQ(0, expected_test); 332 EXPECT_EQ(0, expected_test);
309 } 333 }
310 334
311 TEST(YUVConvertTest, RGB24ToYUV) { 335 TEST(YUVConvertTest, RGB24ToYUV) {
312 // Allocate all surfaces. 336 // Allocate all surfaces.
313 scoped_ptr<uint8[]> rgb_bytes; 337 scoped_ptr<uint8[]> rgb_bytes;
314 scoped_ptr<uint8[]> yuv_converted_bytes(new uint8[kYUV12Size]); 338 scoped_ptr<uint8[]> yuv_converted_bytes(new uint8[kYUV12Size]);
315 339
316 // Read RGB24 reference data from file. 340 // Read RGB24 reference data from file.
317 ReadRGB24Data(&rgb_bytes); 341 ReadRGB24Data(&rgb_bytes);
318 342
319 // Convert to I420. 343 // Convert to I420.
320 media::ConvertRGB24ToYUV(rgb_bytes.get(), 344 media::ConvertRGB24ToYUV(rgb_bytes.get(),
321 yuv_converted_bytes.get(), 345 yuv_converted_bytes.get(),
322 yuv_converted_bytes.get() + kSourceUOffset, 346 yuv_converted_bytes.get() + kSourceUOffset,
323 yuv_converted_bytes.get() + kSourceVOffset, 347 yuv_converted_bytes.get() + kSourceVOffset,
324 kSourceWidth, kSourceHeight, // Dimensions 348 kSourceWidth, kSourceHeight, // Dimensions
325 kSourceWidth * 3, // RGBStride 349 kSourceWidth * 3, // RGBStride
326 kSourceWidth, // YStride 350 kSourceWidth, // YStride
327 kSourceWidth / 2); // UVStride 351 kSourceWidth / 2); // UVStride
328 352
329 uint32 rgb_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, 353 uint32 rgb_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size,
330 kDJB2HashSeed); 354 kDJB2HashSeed);
355
scherkus (not reviewing) 2013/06/20 00:28:08 remove extra line that snuck in
hkuang1 2013/06/20 03:45:33 Done.
331 EXPECT_EQ(320824432u, rgb_hash); 356 EXPECT_EQ(320824432u, rgb_hash);
332 } 357 }
333 358
334 TEST(YUVConvertTest, RGB32ToYUV) { 359 TEST(YUVConvertTest, RGB32ToYUV) {
335 // Allocate all surfaces. 360 // Allocate all surfaces.
336 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]); 361 scoped_ptr<uint8[]> yuv_bytes(new uint8[kYUV12Size]);
337 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); 362 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]);
338 scoped_ptr<uint8[]> yuv_converted_bytes(new uint8[kYUV12Size]); 363 scoped_ptr<uint8[]> yuv_converted_bytes(new uint8[kYUV12Size]);
339 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSize]); 364 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSize]);
340 365
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(), 961 EXPECT_EQ(0, memcmp(rgb_bytes_reference.get(),
937 rgb_bytes_converted.get(), 962 rgb_bytes_converted.get(),
938 kWidth * kBpp)); 963 kWidth * kBpp));
939 } 964 }
940 965
941 #endif // defined(ARCH_CPU_X86_64) 966 #endif // defined(ARCH_CPU_X86_64)
942 967
943 #endif // defined(ARCH_CPU_X86_FAMILY) 968 #endif // defined(ARCH_CPU_X86_FAMILY)
944 969
945 } // namespace media 970 } // namespace media
OLDNEW
« no previous file with comments | « media/base/simd/convert_yuv_to_rgb_c.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698