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

Side by Side Diff: media/base/simd/convert_rgb_to_yuv_unittest.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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
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/cpu.h" 5 #include "base/cpu.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "media/base/simd/convert_rgb_to_yuv.h" 7 #include "media/base/simd/convert_rgb_to_yuv.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace { 10 namespace {
11 11
12 // Reference code that converts RGB pixels to YUV pixels. 12 // Reference code that converts RGB pixels to YUV pixels.
13 int ConvertRGBToY(const uint8* rgb) { 13 int ConvertRGBToY(const uint8_t* rgb) {
14 int y = 25 * rgb[0] + 129 * rgb[1] + 66 * rgb[2]; 14 int y = 25 * rgb[0] + 129 * rgb[1] + 66 * rgb[2];
15 y = ((y + 128) >> 8) + 16; 15 y = ((y + 128) >> 8) + 16;
16 return std::max(0, std::min(255, y)); 16 return std::max(0, std::min(255, y));
17 } 17 }
18 18
19 int ConvertRGBToU(const uint8* rgb, int size) { 19 int ConvertRGBToU(const uint8_t* rgb, int size) {
20 int u = 112 * rgb[0] - 74 * rgb[1] - 38 * rgb[2]; 20 int u = 112 * rgb[0] - 74 * rgb[1] - 38 * rgb[2];
21 u = ((u + 128) >> 8) + 128; 21 u = ((u + 128) >> 8) + 128;
22 return std::max(0, std::min(255, u)); 22 return std::max(0, std::min(255, u));
23 } 23 }
24 24
25 int ConvertRGBToV(const uint8* rgb, int size) { 25 int ConvertRGBToV(const uint8_t* rgb, int size) {
26 int v = -18 * rgb[0] - 94 * rgb[1] + 112 * rgb[2]; 26 int v = -18 * rgb[0] - 94 * rgb[1] + 112 * rgb[2];
27 v = ((v + 128) >> 8) + 128; 27 v = ((v + 128) >> 8) + 128;
28 return std::max(0, std::min(255, v)); 28 return std::max(0, std::min(255, v));
29 } 29 }
30 30
31 } // namespace 31 } // namespace
32 32
33 // Assembly code confuses MemorySanitizer. Do not run it in MSan builds. 33 // Assembly code confuses MemorySanitizer. Do not run it in MSan builds.
34 #if defined(MEMORY_SANITIZER) 34 #if defined(MEMORY_SANITIZER)
35 #define MAYBE_SideBySideRGB DISABLED_SideBySideRGB 35 #define MAYBE_SideBySideRGB DISABLED_SideBySideRGB
(...skipping 13 matching lines...) Expand all
49 if (!cpu.has_ssse3()) 49 if (!cpu.has_ssse3())
50 return; 50 return;
51 51
52 // This test checks a subset of all RGB values so this test does not take so 52 // This test checks a subset of all RGB values so this test does not take so
53 // long time. 53 // long time.
54 const int kStep = 8; 54 const int kStep = 8;
55 const int kWidth = 256 / kStep; 55 const int kWidth = 256 / kStep;
56 56
57 for (int size = 3; size <= 4; ++size) { 57 for (int size = 3; size <= 4; ++size) {
58 // Create the output buffers. 58 // Create the output buffers.
59 scoped_ptr<uint8[]> rgb(new uint8[kWidth * size]); 59 scoped_ptr<uint8_t[]> rgb(new uint8_t[kWidth * size]);
60 scoped_ptr<uint8[]> y(new uint8[kWidth]); 60 scoped_ptr<uint8_t[]> y(new uint8_t[kWidth]);
61 scoped_ptr<uint8[]> u(new uint8[kWidth / 2]); 61 scoped_ptr<uint8_t[]> u(new uint8_t[kWidth / 2]);
62 scoped_ptr<uint8[]> v(new uint8[kWidth / 2]); 62 scoped_ptr<uint8_t[]> v(new uint8_t[kWidth / 2]);
63 63
64 // Choose the function that converts from RGB pixels to YUV ones. 64 // Choose the function that converts from RGB pixels to YUV ones.
65 void (*convert)(const uint8*, uint8*, uint8*, uint8*, 65 void (*convert)(const uint8_t*, uint8_t*, uint8_t*, uint8_t*, int, int, int,
66 int, int, int, int, int) = NULL; 66 int, int) = NULL;
67 if (size == 3) 67 if (size == 3)
68 convert = media::ConvertRGB24ToYUV_SSSE3; 68 convert = media::ConvertRGB24ToYUV_SSSE3;
69 else 69 else
70 convert = media::ConvertRGB32ToYUV_SSSE3; 70 convert = media::ConvertRGB32ToYUV_SSSE3;
71 71
72 int total_error = 0; 72 int total_error = 0;
73 for (int r = 0; r < kWidth; ++r) { 73 for (int r = 0; r < kWidth; ++r) {
74 for (int g = 0; g < kWidth; ++g) { 74 for (int g = 0; g < kWidth; ++g) {
75 75
76 // Fill the input pixels. 76 // Fill the input pixels.
77 for (int b = 0; b < kWidth; ++b) { 77 for (int b = 0; b < kWidth; ++b) {
78 rgb[b * size + 0] = b * kStep; 78 rgb[b * size + 0] = b * kStep;
79 rgb[b * size + 1] = g * kStep; 79 rgb[b * size + 1] = g * kStep;
80 rgb[b * size + 2] = r * kStep; 80 rgb[b * size + 2] = r * kStep;
81 if (size == 4) 81 if (size == 4)
82 rgb[b * size + 3] = 255; 82 rgb[b * size + 3] = 255;
83 } 83 }
84 84
85 // Convert the input RGB pixels to YUV ones. 85 // Convert the input RGB pixels to YUV ones.
86 convert(rgb.get(), y.get(), u.get(), v.get(), kWidth, 1, kWidth * size, 86 convert(rgb.get(), y.get(), u.get(), v.get(), kWidth, 1, kWidth * size,
87 kWidth, kWidth / 2); 87 kWidth, kWidth / 2);
88 88
89 // Check the output Y pixels. 89 // Check the output Y pixels.
90 for (int i = 0; i < kWidth; ++i) { 90 for (int i = 0; i < kWidth; ++i) {
91 const uint8* p = &rgb[i * size]; 91 const uint8_t* p = &rgb[i * size];
92 int error = ConvertRGBToY(p) - y[i]; 92 int error = ConvertRGBToY(p) - y[i];
93 total_error += error > 0 ? error : -error; 93 total_error += error > 0 ? error : -error;
94 } 94 }
95 95
96 // Check the output U pixels. 96 // Check the output U pixels.
97 for (int i = 0; i < kWidth / 2; ++i) { 97 for (int i = 0; i < kWidth / 2; ++i) {
98 const uint8* p = &rgb[i * 2 * size]; 98 const uint8_t* p = &rgb[i * 2 * size];
99 int error = ConvertRGBToU(p, size) - u[i]; 99 int error = ConvertRGBToU(p, size) - u[i];
100 total_error += error > 0 ? error : -error; 100 total_error += error > 0 ? error : -error;
101 } 101 }
102 102
103 // Check the output V pixels. 103 // Check the output V pixels.
104 for (int i = 0; i < kWidth / 2; ++i) { 104 for (int i = 0; i < kWidth / 2; ++i) {
105 const uint8* p = &rgb[i * 2 * size]; 105 const uint8_t* p = &rgb[i * 2 * size];
106 int error = ConvertRGBToV(p, size) - v[i]; 106 int error = ConvertRGBToV(p, size) - v[i];
107 total_error += error > 0 ? error : -error; 107 total_error += error > 0 ? error : -error;
108 } 108 }
109 } 109 }
110 } 110 }
111 111
112 EXPECT_EQ(0, total_error); 112 EXPECT_EQ(0, total_error);
113 } 113 }
114 } 114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698