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

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 #if defined(OS_ANDROID)
80 // Helper for swapping red and blue channels of RGBA or BGRA.
81 static void SwapRedAndBlueChannels(unsigned char* pixels, size_t buffer_size) {
82 for (size_t i = 0; i < buffer_size; i += 4) {
83 std::swap(pixels[i], pixels[i + 2]);
84 }
85 }
86 #endif
87
79 namespace media { 88 namespace media {
80 89
81 TEST(YUVConvertTest, YV12) { 90 TEST(YUVConvertTest, YV12) {
82 // Allocate all surfaces. 91 // Allocate all surfaces.
83 scoped_ptr<uint8[]> yuv_bytes; 92 scoped_ptr<uint8[]> yuv_bytes;
84 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); 93 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]);
85 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSizeConverted]); 94 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSizeConverted]);
86 95
87 // Read YUV reference data from file. 96 // Read YUV reference data from file.
88 ReadYV12Data(&yuv_bytes); 97 ReadYV12Data(&yuv_bytes);
89 98
90 // Convert a frame of YUV to 32 bit ARGB. 99 // Convert a frame of YUV to 32 bit ARGB.
91 media::ConvertYUVToRGB32(yuv_bytes.get(), 100 media::ConvertYUVToRGB32(yuv_bytes.get(),
92 yuv_bytes.get() + kSourceUOffset, 101 yuv_bytes.get() + kSourceUOffset,
93 yuv_bytes.get() + kSourceVOffset, 102 yuv_bytes.get() + kSourceVOffset,
94 rgb_converted_bytes.get(), // RGB output 103 rgb_converted_bytes.get(), // RGB output
95 kSourceWidth, kSourceHeight, // Dimensions 104 kSourceWidth, kSourceHeight, // Dimensions
96 kSourceWidth, // YStride 105 kSourceWidth, // YStride
97 kSourceWidth / 2, // UVStride 106 kSourceWidth / 2, // UVStride
98 kSourceWidth * kBpp, // RGBStride 107 kSourceWidth * kBpp, // RGBStride
99 media::YV12); 108 media::YV12);
100 109
110 #if defined(OS_ANDROID)
111 SwapRedAndBlueChannels(rgb_converted_bytes.get(), kRGBSizeConverted);
112 #endif
113
101 uint32 rgb_hash = DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted, 114 uint32 rgb_hash = DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted,
102 kDJB2HashSeed); 115 kDJB2HashSeed);
103 EXPECT_EQ(2413171226u, rgb_hash); 116 EXPECT_EQ(2413171226u, rgb_hash);
104 } 117 }
105 118
106 TEST(YUVConvertTest, YV16) { 119 TEST(YUVConvertTest, YV16) {
107 // Allocate all surfaces. 120 // Allocate all surfaces.
108 scoped_ptr<uint8[]> yuv_bytes; 121 scoped_ptr<uint8[]> yuv_bytes;
109 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]); 122 scoped_ptr<uint8[]> rgb_bytes(new uint8[kRGBSize]);
110 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSizeConverted]); 123 scoped_ptr<uint8[]> rgb_converted_bytes(new uint8[kRGBSizeConverted]);
111 124
112 // Read YUV reference data from file. 125 // Read YUV reference data from file.
113 ReadYV16Data(&yuv_bytes); 126 ReadYV16Data(&yuv_bytes);
114 127
115 // Convert a frame of YUV to 32 bit ARGB. 128 // Convert a frame of YUV to 32 bit ARGB.
116 media::ConvertYUVToRGB32(yuv_bytes.get(), // Y 129 media::ConvertYUVToRGB32(yuv_bytes.get(), // Y
117 yuv_bytes.get() + kSourceUOffset, // U 130 yuv_bytes.get() + kSourceUOffset, // U
118 yuv_bytes.get() + kSourceYSize * 3 / 2, // V 131 yuv_bytes.get() + kSourceYSize * 3 / 2, // V
119 rgb_converted_bytes.get(), // RGB output 132 rgb_converted_bytes.get(), // RGB output
120 kSourceWidth, kSourceHeight, // Dimensions 133 kSourceWidth, kSourceHeight, // Dimensions
121 kSourceWidth, // YStride 134 kSourceWidth, // YStride
122 kSourceWidth / 2, // UVStride 135 kSourceWidth / 2, // UVStride
123 kSourceWidth * kBpp, // RGBStride 136 kSourceWidth * kBpp, // RGBStride
124 media::YV16); 137 media::YV16);
125 138
139 #if defined(OS_ANDROID)
140 SwapRedAndBlueChannels(rgb_converted_bytes.get(), kRGBSizeConverted);
141 #endif
142
126 uint32 rgb_hash = DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted, 143 uint32 rgb_hash = DJB2Hash(rgb_converted_bytes.get(), kRGBSizeConverted,
127 kDJB2HashSeed); 144 kDJB2HashSeed);
128 EXPECT_EQ(4222342047u, rgb_hash); 145 EXPECT_EQ(4222342047u, rgb_hash);
129 } 146 }
130 147
131 struct YUVScaleTestData { 148 struct YUVScaleTestData {
132 YUVScaleTestData(media::YUVType y, media::ScaleFilter s, uint32 r) 149 YUVScaleTestData(media::YUVType y, media::ScaleFilter s, uint32 r)
133 : yuv_type(y), 150 : yuv_type(y),
134 scale_filter(s), 151 scale_filter(s),
135 rgb_hash(r) { 152 rgb_hash(r) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 rgb_bytes_.get(), // RGB output 227 rgb_bytes_.get(), // RGB output
211 kSourceWidth, kSourceHeight, // Dimensions 228 kSourceWidth, kSourceHeight, // Dimensions
212 kScaledWidth, kScaledHeight, // Dimensions 229 kScaledWidth, kScaledHeight, // Dimensions
213 kSourceWidth, // YStride 230 kSourceWidth, // YStride
214 kSourceWidth / 2, // UvStride 231 kSourceWidth / 2, // UvStride
215 kScaledWidth * kBpp, // RgbStride 232 kScaledWidth * kBpp, // RgbStride
216 GetParam().yuv_type, 233 GetParam().yuv_type,
217 media::ROTATE_0, 234 media::ROTATE_0,
218 GetParam().scale_filter); 235 GetParam().scale_filter);
219 236
237 #if defined(OS_ANDROID)
238 SwapRedAndBlueChannels(rgb_bytes_.get(), kRGBSizeScaled);
239 #endif
240
220 uint32 rgb_hash = DJB2Hash(rgb_bytes_.get(), kRGBSizeScaled, kDJB2HashSeed); 241 uint32 rgb_hash = DJB2Hash(rgb_bytes_.get(), kRGBSizeScaled, kDJB2HashSeed);
221 EXPECT_EQ(GetParam().rgb_hash, rgb_hash); 242 EXPECT_EQ(GetParam().rgb_hash, rgb_hash);
222 } 243 }
223 244
224 TEST_P(YUVScaleTest, ZeroSourceSize) { 245 TEST_P(YUVScaleTest, ZeroSourceSize) {
225 media::ScaleYUVToRGB32(y_plane(), // Y 246 media::ScaleYUVToRGB32(y_plane(), // Y
226 u_plane(), // U 247 u_plane(), // U
227 v_plane(), // V 248 v_plane(), // V
228 rgb_bytes_.get(), // RGB output 249 rgb_bytes_.get(), // RGB output
229 0, 0, // Dimensions 250 0, 0, // Dimensions
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 media::ConvertYUVToRGB32(&y, // Y 318 media::ConvertYUVToRGB32(&y, // Y
298 &u, // U 319 &u, // U
299 &v, // V 320 &v, // V
300 &rgb[0], // RGB output 321 &rgb[0], // RGB output
301 1, 1, // Dimensions 322 1, 1, // Dimensions
302 0, // YStride 323 0, // YStride
303 0, // UVStride 324 0, // UVStride
304 0, // RGBStride 325 0, // RGBStride
305 media::YV12); 326 media::YV12);
306 327
328 #if defined(OS_ANDROID)
329 SwapRedAndBlueChannels(rgb, kBpp);
330 #endif
331
307 int expected_test = memcmp(rgb, expected, sizeof(expected)); 332 int expected_test = memcmp(rgb, expected, sizeof(expected));
308 EXPECT_EQ(0, expected_test); 333 EXPECT_EQ(0, expected_test);
309 } 334 }
310 335
311 TEST(YUVConvertTest, RGB24ToYUV) { 336 TEST(YUVConvertTest, RGB24ToYUV) {
312 // Allocate all surfaces. 337 // Allocate all surfaces.
313 scoped_ptr<uint8[]> rgb_bytes; 338 scoped_ptr<uint8[]> rgb_bytes;
314 scoped_ptr<uint8[]> yuv_converted_bytes(new uint8[kYUV12Size]); 339 scoped_ptr<uint8[]> yuv_converted_bytes(new uint8[kYUV12Size]);
315 340
316 // Read RGB24 reference data from file. 341 // Read RGB24 reference data from file.
(...skipping 619 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