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

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

Issue 12263013: media: Add support for playback of VP8 Alpha video streams (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « media/base/simd/convert_yuv_to_rgb.h ('k') | media/base/simd/convert_yuv_to_rgb_x86.cc » ('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 "media/base/simd/convert_yuv_to_rgb.h" 5 #include "media/base/simd/convert_yuv_to_rgb.h"
6 #include "media/base/simd/yuv_to_rgb_table.h" 6 #include "media/base/simd/yuv_to_rgb_table.h"
7 7
8 #define packuswb(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x))) 8 #define packuswb(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x)))
9 #define paddsw(x, y) (((x) + (y)) < -32768 ? -32768 : \ 9 #define paddsw(x, y) (((x) + (y)) < -32768 ? -32768 : \
10 (((x) + (y)) > 32767 ? 32767 : ((x) + (y)))) 10 (((x) + (y)) > 32767 ? 32767 : ((x) + (y))))
(...skipping 21 matching lines...) Expand all
32 g >>= 6; 32 g >>= 6;
33 r >>= 6; 33 r >>= 6;
34 a >>= 6; 34 a >>= 6;
35 35
36 *reinterpret_cast<uint32*>(rgb_buf) = (packuswb(b)) | 36 *reinterpret_cast<uint32*>(rgb_buf) = (packuswb(b)) |
37 (packuswb(g) << 8) | 37 (packuswb(g) << 8) |
38 (packuswb(r) << 16) | 38 (packuswb(r) << 16) |
39 (packuswb(a) << 24); 39 (packuswb(a) << 24);
40 } 40 }
41 41
42 static inline void ConvertYUVAToARGB_C(uint8 y,
43 uint8 u,
44 uint8 v,
45 uint8 a,
46 uint8* rgb_buf) {
47 int b = kCoefficientsRgbY[256+u][0];
48 int g = kCoefficientsRgbY[256+u][1];
49 int r = kCoefficientsRgbY[256+u][2];
50
51 b = paddsw(b, kCoefficientsRgbY[512+v][0]);
52 g = paddsw(g, kCoefficientsRgbY[512+v][1]);
53 r = paddsw(r, kCoefficientsRgbY[512+v][2]);
54
55 b = paddsw(b, kCoefficientsRgbY[y][0]);
56 g = paddsw(g, kCoefficientsRgbY[y][1]);
57 r = paddsw(r, kCoefficientsRgbY[y][2]);
58
59 b >>= 6;
60 g >>= 6;
61 r >>= 6;
62
63 b = packuswb(b) * a >> 8;
64 g = packuswb(g) * a >> 8;
65 r = packuswb(r) * a >> 8;
66
67 *reinterpret_cast<uint32*>(rgb_buf) = b | (g << 8) | (r << 16) | (a << 24);
68 }
69
42 extern "C" { 70 extern "C" {
43 71
44 void ConvertYUVToRGB32Row_C(const uint8* y_buf, 72 void ConvertYUVToRGB32Row_C(const uint8* y_buf,
45 const uint8* u_buf, 73 const uint8* u_buf,
46 const uint8* v_buf, 74 const uint8* v_buf,
47 uint8* rgb_buf, 75 uint8* rgb_buf,
48 ptrdiff_t width) { 76 ptrdiff_t width) {
49 for (int x = 0; x < width; x += 2) { 77 for (int x = 0; x < width; x += 2) {
50 uint8 u = u_buf[x >> 1]; 78 uint8 u = u_buf[x >> 1];
51 uint8 v = v_buf[x >> 1]; 79 uint8 v = v_buf[x >> 1];
52 uint8 y0 = y_buf[x]; 80 uint8 y0 = y_buf[x];
53 ConvertYUVToRGB32_C(y0, u, v, rgb_buf); 81 ConvertYUVToRGB32_C(y0, u, v, rgb_buf);
54 if ((x + 1) < width) { 82 if ((x + 1) < width) {
55 uint8 y1 = y_buf[x + 1]; 83 uint8 y1 = y_buf[x + 1];
56 ConvertYUVToRGB32_C(y1, u, v, rgb_buf + 4); 84 ConvertYUVToRGB32_C(y1, u, v, rgb_buf + 4);
57 } 85 }
58 rgb_buf += 8; // Advance 2 pixels. 86 rgb_buf += 8; // Advance 2 pixels.
59 } 87 }
60 } 88 }
61 89
90 void ConvertYUVAToARGBRow_C(const uint8* y_buf,
91 const uint8* u_buf,
92 const uint8* v_buf,
93 const uint8* a_buf,
94 uint8* rgba_buf,
95 ptrdiff_t width) {
96 for (int x = 0; x < width; x += 2) {
97 uint8 u = u_buf[x >> 1];
98 uint8 v = v_buf[x >> 1];
99 uint8 y0 = y_buf[x];
100 uint8 a0 = a_buf[x];
101 ConvertYUVAToARGB_C(y0, u, v, a0, rgba_buf);
102 if ((x + 1) < width) {
103 uint8 y1 = y_buf[x + 1];
104 uint8 a1 = a_buf[x + 1];
105 ConvertYUVAToARGB_C(y1, u, v, a1, rgba_buf + 4);
106 }
107 rgba_buf += 8; // Advance 2 pixels.
108 }
109 }
110
62 // 16.16 fixed point is used. A shift by 16 isolates the integer. 111 // 16.16 fixed point is used. A shift by 16 isolates the integer.
63 // A shift by 17 is used to further subsample the chrominence channels. 112 // A shift by 17 is used to further subsample the chrominence channels.
64 // & 0xffff isolates the fixed point fraction. >> 2 to get the upper 2 bits, 113 // & 0xffff isolates the fixed point fraction. >> 2 to get the upper 2 bits,
65 // for 1/65536 pixel accurate interpolation. 114 // for 1/65536 pixel accurate interpolation.
66 void ScaleYUVToRGB32Row_C(const uint8* y_buf, 115 void ScaleYUVToRGB32Row_C(const uint8* y_buf,
67 const uint8* u_buf, 116 const uint8* u_buf,
68 const uint8* v_buf, 117 const uint8* v_buf,
69 uint8* rgb_buf, 118 uint8* rgb_buf,
70 ptrdiff_t width, 119 ptrdiff_t width,
71 ptrdiff_t source_dx) { 120 ptrdiff_t source_dx) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 const uint8* v_ptr = vplane + (y >> y_shift) * uvstride; 203 const uint8* v_ptr = vplane + (y >> y_shift) * uvstride;
155 204
156 ConvertYUVToRGB32Row_C(y_ptr, 205 ConvertYUVToRGB32Row_C(y_ptr,
157 u_ptr, 206 u_ptr,
158 v_ptr, 207 v_ptr,
159 rgb_row, 208 rgb_row,
160 width); 209 width);
161 } 210 }
162 } 211 }
163 212
213 void ConvertYUVAToARGB_C(const uint8* yplane,
214 const uint8* uplane,
215 const uint8* vplane,
216 const uint8* aplane,
217 uint8* rgbaframe,
218 int width,
219 int height,
220 int ystride,
221 int uvstride,
222 int astride,
223 int rgbastride,
224 YUVType yuv_type) {
225 unsigned int y_shift = yuv_type;
226 for (int y = 0; y < height; y++) {
227 uint8* rgba_row = rgbaframe + y * rgbastride;
228 const uint8* y_ptr = yplane + y * ystride;
229 const uint8* u_ptr = uplane + (y >> y_shift) * uvstride;
230 const uint8* v_ptr = vplane + (y >> y_shift) * uvstride;
231 const uint8* a_ptr = aplane + y * astride;
232
233 ConvertYUVAToARGBRow_C(y_ptr,
234 u_ptr,
235 v_ptr,
236 a_ptr,
237 rgba_row,
238 width);
239 }
240 }
241
164 } // namespace media 242 } // namespace media
OLDNEW
« no previous file with comments | « media/base/simd/convert_yuv_to_rgb.h ('k') | media/base/simd/convert_yuv_to_rgb_x86.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698