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

Side by Side Diff: media/base/simd/convert_yuv_to_rgb_c.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 "media/base/simd/convert_yuv_to_rgb.h" 5 #include "media/base/simd/convert_yuv_to_rgb.h"
6 6
7 namespace media { 7 namespace media {
8 8
9 #define packuswb(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x))) 9 #define packuswb(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x)))
10 #define paddsw(x, y) (((x) + (y)) < -32768 ? -32768 : \ 10 #define paddsw(x, y) (((x) + (y)) < -32768 ? -32768 : \
(...skipping 16 matching lines...) Expand all
27 #define SK_B32_SHIFT 0 27 #define SK_B32_SHIFT 0
28 #define SK_G32_SHIFT 8 28 #define SK_G32_SHIFT 8
29 #define SK_R32_SHIFT 16 29 #define SK_R32_SHIFT 16
30 #define SK_A32_SHIFT 24 30 #define SK_A32_SHIFT 24
31 #define B_INDEX 0 31 #define B_INDEX 0
32 #define G_INDEX 1 32 #define G_INDEX 1
33 #define R_INDEX 2 33 #define R_INDEX 2
34 #define A_INDEX 3 34 #define A_INDEX 3
35 #endif 35 #endif
36 36
37 static inline void ConvertYUVToRGB32_C(uint8 y, 37 static inline void ConvertYUVToRGB32_C(uint8_t y,
38 uint8 u, 38 uint8_t u,
39 uint8 v, 39 uint8_t v,
40 uint8* rgb_buf, 40 uint8_t* rgb_buf,
41 const int16* convert_table) { 41 const int16_t* convert_table) {
42 int b = convert_table[4 * (256 + u) + B_INDEX]; 42 int b = convert_table[4 * (256 + u) + B_INDEX];
43 int g = convert_table[4 * (256 + u) + G_INDEX]; 43 int g = convert_table[4 * (256 + u) + G_INDEX];
44 int r = convert_table[4 * (256 + u) + R_INDEX]; 44 int r = convert_table[4 * (256 + u) + R_INDEX];
45 int a = convert_table[4 * (256 + u) + A_INDEX]; 45 int a = convert_table[4 * (256 + u) + A_INDEX];
46 46
47 b = paddsw(b, convert_table[4 * (512 + v) + B_INDEX]); 47 b = paddsw(b, convert_table[4 * (512 + v) + B_INDEX]);
48 g = paddsw(g, convert_table[4 * (512 + v) + G_INDEX]); 48 g = paddsw(g, convert_table[4 * (512 + v) + G_INDEX]);
49 r = paddsw(r, convert_table[4 * (512 + v) + R_INDEX]); 49 r = paddsw(r, convert_table[4 * (512 + v) + R_INDEX]);
50 a = paddsw(a, convert_table[4 * (512 + v) + A_INDEX]); 50 a = paddsw(a, convert_table[4 * (512 + v) + A_INDEX]);
51 51
52 b = paddsw(b, convert_table[4 * y + B_INDEX]); 52 b = paddsw(b, convert_table[4 * y + B_INDEX]);
53 g = paddsw(g, convert_table[4 * y + G_INDEX]); 53 g = paddsw(g, convert_table[4 * y + G_INDEX]);
54 r = paddsw(r, convert_table[4 * y + R_INDEX]); 54 r = paddsw(r, convert_table[4 * y + R_INDEX]);
55 a = paddsw(a, convert_table[4 * y + A_INDEX]); 55 a = paddsw(a, convert_table[4 * y + A_INDEX]);
56 56
57 b >>= 6; 57 b >>= 6;
58 g >>= 6; 58 g >>= 6;
59 r >>= 6; 59 r >>= 6;
60 a >>= 6; 60 a >>= 6;
61 61
62 *reinterpret_cast<uint32*>(rgb_buf) = (packuswb(b) << SK_B32_SHIFT) | 62 *reinterpret_cast<uint32_t*>(rgb_buf) =
63 (packuswb(g) << SK_G32_SHIFT) | 63 (packuswb(b) << SK_B32_SHIFT) | (packuswb(g) << SK_G32_SHIFT) |
64 (packuswb(r) << SK_R32_SHIFT) | 64 (packuswb(r) << SK_R32_SHIFT) | (packuswb(a) << SK_A32_SHIFT);
65 (packuswb(a) << SK_A32_SHIFT);
66 } 65 }
67 66
68 static inline void ConvertYUVAToARGB_C(uint8 y, 67 static inline void ConvertYUVAToARGB_C(uint8_t y,
69 uint8 u, 68 uint8_t u,
70 uint8 v, 69 uint8_t v,
71 uint8 a, 70 uint8_t a,
72 uint8* rgb_buf, 71 uint8_t* rgb_buf,
73 const int16* convert_table) { 72 const int16_t* convert_table) {
74 int b = convert_table[4 * (256 + u) + 0]; 73 int b = convert_table[4 * (256 + u) + 0];
75 int g = convert_table[4 * (256 + u) + 1]; 74 int g = convert_table[4 * (256 + u) + 1];
76 int r = convert_table[4 * (256 + u) + 2]; 75 int r = convert_table[4 * (256 + u) + 2];
77 76
78 b = paddsw(b, convert_table[4 * (512 + v) + 0]); 77 b = paddsw(b, convert_table[4 * (512 + v) + 0]);
79 g = paddsw(g, convert_table[4 * (512 + v) + 1]); 78 g = paddsw(g, convert_table[4 * (512 + v) + 1]);
80 r = paddsw(r, convert_table[4 * (512 + v) + 2]); 79 r = paddsw(r, convert_table[4 * (512 + v) + 2]);
81 80
82 b = paddsw(b, convert_table[4 * y + 0]); 81 b = paddsw(b, convert_table[4 * y + 0]);
83 g = paddsw(g, convert_table[4 * y + 1]); 82 g = paddsw(g, convert_table[4 * y + 1]);
84 r = paddsw(r, convert_table[4 * y + 2]); 83 r = paddsw(r, convert_table[4 * y + 2]);
85 84
86 b >>= 6; 85 b >>= 6;
87 g >>= 6; 86 g >>= 6;
88 r >>= 6; 87 r >>= 6;
89 88
90 b = packuswb(b) * a >> 8; 89 b = packuswb(b) * a >> 8;
91 g = packuswb(g) * a >> 8; 90 g = packuswb(g) * a >> 8;
92 r = packuswb(r) * a >> 8; 91 r = packuswb(r) * a >> 8;
93 92
94 *reinterpret_cast<uint32*>(rgb_buf) = (b << SK_B32_SHIFT) | 93 *reinterpret_cast<uint32_t*>(rgb_buf) =
95 (g << SK_G32_SHIFT) | 94 (b << SK_B32_SHIFT) | (g << SK_G32_SHIFT) | (r << SK_R32_SHIFT) |
96 (r << SK_R32_SHIFT) | 95 (a << SK_A32_SHIFT);
97 (a << SK_A32_SHIFT);
98 } 96 }
99 97
100 void ConvertYUVToRGB32Row_C(const uint8* y_buf, 98 void ConvertYUVToRGB32Row_C(const uint8_t* y_buf,
101 const uint8* u_buf, 99 const uint8_t* u_buf,
102 const uint8* v_buf, 100 const uint8_t* v_buf,
103 uint8* rgb_buf, 101 uint8_t* rgb_buf,
104 ptrdiff_t width, 102 ptrdiff_t width,
105 const int16* convert_table) { 103 const int16_t* convert_table) {
106 for (int x = 0; x < width; x += 2) { 104 for (int x = 0; x < width; x += 2) {
107 uint8 u = u_buf[x >> 1]; 105 uint8_t u = u_buf[x >> 1];
108 uint8 v = v_buf[x >> 1]; 106 uint8_t v = v_buf[x >> 1];
109 uint8 y0 = y_buf[x]; 107 uint8_t y0 = y_buf[x];
110 ConvertYUVToRGB32_C(y0, u, v, rgb_buf, convert_table); 108 ConvertYUVToRGB32_C(y0, u, v, rgb_buf, convert_table);
111 if ((x + 1) < width) { 109 if ((x + 1) < width) {
112 uint8 y1 = y_buf[x + 1]; 110 uint8_t y1 = y_buf[x + 1];
113 ConvertYUVToRGB32_C(y1, u, v, rgb_buf + 4, convert_table); 111 ConvertYUVToRGB32_C(y1, u, v, rgb_buf + 4, convert_table);
114 } 112 }
115 rgb_buf += 8; // Advance 2 pixels. 113 rgb_buf += 8; // Advance 2 pixels.
116 } 114 }
117 } 115 }
118 116
119 void ConvertYUVAToARGBRow_C(const uint8* y_buf, 117 void ConvertYUVAToARGBRow_C(const uint8_t* y_buf,
120 const uint8* u_buf, 118 const uint8_t* u_buf,
121 const uint8* v_buf, 119 const uint8_t* v_buf,
122 const uint8* a_buf, 120 const uint8_t* a_buf,
123 uint8* rgba_buf, 121 uint8_t* rgba_buf,
124 ptrdiff_t width, 122 ptrdiff_t width,
125 const int16* convert_table) { 123 const int16_t* convert_table) {
126 for (int x = 0; x < width; x += 2) { 124 for (int x = 0; x < width; x += 2) {
127 uint8 u = u_buf[x >> 1]; 125 uint8_t u = u_buf[x >> 1];
128 uint8 v = v_buf[x >> 1]; 126 uint8_t v = v_buf[x >> 1];
129 uint8 y0 = y_buf[x]; 127 uint8_t y0 = y_buf[x];
130 uint8 a0 = a_buf[x]; 128 uint8_t a0 = a_buf[x];
131 ConvertYUVAToARGB_C(y0, u, v, a0, rgba_buf, convert_table); 129 ConvertYUVAToARGB_C(y0, u, v, a0, rgba_buf, convert_table);
132 if ((x + 1) < width) { 130 if ((x + 1) < width) {
133 uint8 y1 = y_buf[x + 1]; 131 uint8_t y1 = y_buf[x + 1];
134 uint8 a1 = a_buf[x + 1]; 132 uint8_t a1 = a_buf[x + 1];
135 ConvertYUVAToARGB_C(y1, u, v, a1, rgba_buf + 4, convert_table); 133 ConvertYUVAToARGB_C(y1, u, v, a1, rgba_buf + 4, convert_table);
136 } 134 }
137 rgba_buf += 8; // Advance 2 pixels. 135 rgba_buf += 8; // Advance 2 pixels.
138 } 136 }
139 } 137 }
140 138
141 // 16.16 fixed point is used. A shift by 16 isolates the integer. 139 // 16.16 fixed point is used. A shift by 16 isolates the integer.
142 // A shift by 17 is used to further subsample the chrominence channels. 140 // A shift by 17 is used to further subsample the chrominence channels.
143 // & 0xffff isolates the fixed point fraction. >> 2 to get the upper 2 bits, 141 // & 0xffff isolates the fixed point fraction. >> 2 to get the upper 2 bits,
144 // for 1/65536 pixel accurate interpolation. 142 // for 1/65536 pixel accurate interpolation.
145 void ScaleYUVToRGB32Row_C(const uint8* y_buf, 143 void ScaleYUVToRGB32Row_C(const uint8_t* y_buf,
146 const uint8* u_buf, 144 const uint8_t* u_buf,
147 const uint8* v_buf, 145 const uint8_t* v_buf,
148 uint8* rgb_buf, 146 uint8_t* rgb_buf,
149 ptrdiff_t width, 147 ptrdiff_t width,
150 ptrdiff_t source_dx, 148 ptrdiff_t source_dx,
151 const int16* convert_table) { 149 const int16_t* convert_table) {
152 int x = 0; 150 int x = 0;
153 for (int i = 0; i < width; i += 2) { 151 for (int i = 0; i < width; i += 2) {
154 int y = y_buf[x >> 16]; 152 int y = y_buf[x >> 16];
155 int u = u_buf[(x >> 17)]; 153 int u = u_buf[(x >> 17)];
156 int v = v_buf[(x >> 17)]; 154 int v = v_buf[(x >> 17)];
157 ConvertYUVToRGB32_C(y, u, v, rgb_buf, convert_table); 155 ConvertYUVToRGB32_C(y, u, v, rgb_buf, convert_table);
158 x += source_dx; 156 x += source_dx;
159 if ((i + 1) < width) { 157 if ((i + 1) < width) {
160 y = y_buf[x >> 16]; 158 y = y_buf[x >> 16];
161 ConvertYUVToRGB32_C(y, u, v, rgb_buf+4, convert_table); 159 ConvertYUVToRGB32_C(y, u, v, rgb_buf+4, convert_table);
162 x += source_dx; 160 x += source_dx;
163 } 161 }
164 rgb_buf += 8; 162 rgb_buf += 8;
165 } 163 }
166 } 164 }
167 165
168 void LinearScaleYUVToRGB32Row_C(const uint8* y_buf, 166 void LinearScaleYUVToRGB32Row_C(const uint8_t* y_buf,
169 const uint8* u_buf, 167 const uint8_t* u_buf,
170 const uint8* v_buf, 168 const uint8_t* v_buf,
171 uint8* rgb_buf, 169 uint8_t* rgb_buf,
172 ptrdiff_t width, 170 ptrdiff_t width,
173 ptrdiff_t source_dx, 171 ptrdiff_t source_dx,
174 const int16* convert_table) { 172 const int16_t* convert_table) {
175 // Avoid point-sampling for down-scaling by > 2:1. 173 // Avoid point-sampling for down-scaling by > 2:1.
176 int source_x = 0; 174 int source_x = 0;
177 if (source_dx >= 0x20000) 175 if (source_dx >= 0x20000)
178 source_x += 0x8000; 176 source_x += 0x8000;
179 LinearScaleYUVToRGB32RowWithRange_C(y_buf, u_buf, v_buf, rgb_buf, width, 177 LinearScaleYUVToRGB32RowWithRange_C(y_buf, u_buf, v_buf, rgb_buf, width,
180 source_x, source_dx, convert_table); 178 source_x, source_dx, convert_table);
181 } 179 }
182 180
183 void LinearScaleYUVToRGB32RowWithRange_C(const uint8* y_buf, 181 void LinearScaleYUVToRGB32RowWithRange_C(const uint8_t* y_buf,
184 const uint8* u_buf, 182 const uint8_t* u_buf,
185 const uint8* v_buf, 183 const uint8_t* v_buf,
186 uint8* rgb_buf, 184 uint8_t* rgb_buf,
187 int dest_width, 185 int dest_width,
188 int x, 186 int x,
189 int source_dx, 187 int source_dx,
190 const int16* convert_table) { 188 const int16_t* convert_table) {
191 for (int i = 0; i < dest_width; i += 2) { 189 for (int i = 0; i < dest_width; i += 2) {
192 int y0 = y_buf[x >> 16]; 190 int y0 = y_buf[x >> 16];
193 int y1 = y_buf[(x >> 16) + 1]; 191 int y1 = y_buf[(x >> 16) + 1];
194 int u0 = u_buf[(x >> 17)]; 192 int u0 = u_buf[(x >> 17)];
195 int u1 = u_buf[(x >> 17) + 1]; 193 int u1 = u_buf[(x >> 17) + 1];
196 int v0 = v_buf[(x >> 17)]; 194 int v0 = v_buf[(x >> 17)];
197 int v1 = v_buf[(x >> 17) + 1]; 195 int v1 = v_buf[(x >> 17) + 1];
198 int y_frac = (x & 65535); 196 int y_frac = (x & 65535);
199 int uv_frac = ((x >> 1) & 65535); 197 int uv_frac = ((x >> 1) & 65535);
200 int y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16; 198 int y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16;
201 int u = (uv_frac * u1 + (uv_frac ^ 65535) * u0) >> 16; 199 int u = (uv_frac * u1 + (uv_frac ^ 65535) * u0) >> 16;
202 int v = (uv_frac * v1 + (uv_frac ^ 65535) * v0) >> 16; 200 int v = (uv_frac * v1 + (uv_frac ^ 65535) * v0) >> 16;
203 ConvertYUVToRGB32_C(y, u, v, rgb_buf, convert_table); 201 ConvertYUVToRGB32_C(y, u, v, rgb_buf, convert_table);
204 x += source_dx; 202 x += source_dx;
205 if ((i + 1) < dest_width) { 203 if ((i + 1) < dest_width) {
206 y0 = y_buf[x >> 16]; 204 y0 = y_buf[x >> 16];
207 y1 = y_buf[(x >> 16) + 1]; 205 y1 = y_buf[(x >> 16) + 1];
208 y_frac = (x & 65535); 206 y_frac = (x & 65535);
209 y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16; 207 y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16;
210 ConvertYUVToRGB32_C(y, u, v, rgb_buf+4, convert_table); 208 ConvertYUVToRGB32_C(y, u, v, rgb_buf+4, convert_table);
211 x += source_dx; 209 x += source_dx;
212 } 210 }
213 rgb_buf += 8; 211 rgb_buf += 8;
214 } 212 }
215 } 213 }
216 214
217 void ConvertYUVToRGB32_C(const uint8* yplane, 215 void ConvertYUVToRGB32_C(const uint8_t* yplane,
218 const uint8* uplane, 216 const uint8_t* uplane,
219 const uint8* vplane, 217 const uint8_t* vplane,
220 uint8* rgbframe, 218 uint8_t* rgbframe,
221 int width, 219 int width,
222 int height, 220 int height,
223 int ystride, 221 int ystride,
224 int uvstride, 222 int uvstride,
225 int rgbstride, 223 int rgbstride,
226 YUVType yuv_type) { 224 YUVType yuv_type) {
227 unsigned int y_shift = GetVerticalShift(yuv_type); 225 unsigned int y_shift = GetVerticalShift(yuv_type);
228 const int16* lookup_table = GetLookupTable(yuv_type); 226 const int16_t* lookup_table = GetLookupTable(yuv_type);
229 for (int y = 0; y < height; ++y) { 227 for (int y = 0; y < height; ++y) {
230 uint8* rgb_row = rgbframe + y * rgbstride; 228 uint8_t* rgb_row = rgbframe + y * rgbstride;
231 const uint8* y_ptr = yplane + y * ystride; 229 const uint8_t* y_ptr = yplane + y * ystride;
232 const uint8* u_ptr = uplane + (y >> y_shift) * uvstride; 230 const uint8_t* u_ptr = uplane + (y >> y_shift) * uvstride;
233 const uint8* v_ptr = vplane + (y >> y_shift) * uvstride; 231 const uint8_t* v_ptr = vplane + (y >> y_shift) * uvstride;
234 232
235 ConvertYUVToRGB32Row_C(y_ptr, 233 ConvertYUVToRGB32Row_C(y_ptr,
236 u_ptr, 234 u_ptr,
237 v_ptr, 235 v_ptr,
238 rgb_row, 236 rgb_row,
239 width, 237 width,
240 lookup_table); 238 lookup_table);
241 } 239 }
242 } 240 }
243 241
244 void ConvertYUVAToARGB_C(const uint8* yplane, 242 void ConvertYUVAToARGB_C(const uint8_t* yplane,
245 const uint8* uplane, 243 const uint8_t* uplane,
246 const uint8* vplane, 244 const uint8_t* vplane,
247 const uint8* aplane, 245 const uint8_t* aplane,
248 uint8* rgbaframe, 246 uint8_t* rgbaframe,
249 int width, 247 int width,
250 int height, 248 int height,
251 int ystride, 249 int ystride,
252 int uvstride, 250 int uvstride,
253 int astride, 251 int astride,
254 int rgbastride, 252 int rgbastride,
255 YUVType yuv_type) { 253 YUVType yuv_type) {
256 unsigned int y_shift = GetVerticalShift(yuv_type); 254 unsigned int y_shift = GetVerticalShift(yuv_type);
257 const int16* lookup_table = GetLookupTable(yuv_type); 255 const int16_t* lookup_table = GetLookupTable(yuv_type);
258 for (int y = 0; y < height; y++) { 256 for (int y = 0; y < height; y++) {
259 uint8* rgba_row = rgbaframe + y * rgbastride; 257 uint8_t* rgba_row = rgbaframe + y * rgbastride;
260 const uint8* y_ptr = yplane + y * ystride; 258 const uint8_t* y_ptr = yplane + y * ystride;
261 const uint8* u_ptr = uplane + (y >> y_shift) * uvstride; 259 const uint8_t* u_ptr = uplane + (y >> y_shift) * uvstride;
262 const uint8* v_ptr = vplane + (y >> y_shift) * uvstride; 260 const uint8_t* v_ptr = vplane + (y >> y_shift) * uvstride;
263 const uint8* a_ptr = aplane + y * astride; 261 const uint8_t* a_ptr = aplane + y * astride;
264 262
265 ConvertYUVAToARGBRow_C(y_ptr, 263 ConvertYUVAToARGBRow_C(y_ptr,
266 u_ptr, 264 u_ptr,
267 v_ptr, 265 v_ptr,
268 a_ptr, 266 a_ptr,
269 rgba_row, 267 rgba_row,
270 width, 268 width,
271 lookup_table); 269 lookup_table);
272 } 270 }
273 } 271 }
274 272
275 } // namespace media 273 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698