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

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

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

Powered by Google App Engine
This is Rietveld 408576698