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

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

Issue 7891039: Resubmit - Rewrite color space conversions suite using YASM" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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_mmx.asm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/base/simd/convert_yuv_to_rgb.h"
6 // TODO(hclam): Shouldn't depend on yuv_row.h.
7 #include "media/base/yuv_row.h"
8
9 #define packuswb(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x)))
10 #define paddsw(x, y) (((x) + (y)) < -32768 ? -32768 : \
11 (((x) + (y)) > 32767 ? 32767 : ((x) + (y))))
12
13 static inline void YUVPixel(uint8 y,
14 uint8 u,
15 uint8 v,
16 uint8* rgb_buf) {
17
18 int b = kCoefficientsRgbY[256+u][0];
19 int g = kCoefficientsRgbY[256+u][1];
20 int r = kCoefficientsRgbY[256+u][2];
21 int a = kCoefficientsRgbY[256+u][3];
22
23 b = paddsw(b, kCoefficientsRgbY[512+v][0]);
24 g = paddsw(g, kCoefficientsRgbY[512+v][1]);
25 r = paddsw(r, kCoefficientsRgbY[512+v][2]);
26 a = paddsw(a, kCoefficientsRgbY[512+v][3]);
27
28 b = paddsw(b, kCoefficientsRgbY[y][0]);
29 g = paddsw(g, kCoefficientsRgbY[y][1]);
30 r = paddsw(r, kCoefficientsRgbY[y][2]);
31 a = paddsw(a, kCoefficientsRgbY[y][3]);
32
33 b >>= 6;
34 g >>= 6;
35 r >>= 6;
36 a >>= 6;
37
38 *reinterpret_cast<uint32*>(rgb_buf) = (packuswb(b)) |
39 (packuswb(g) << 8) |
40 (packuswb(r) << 16) |
41 (packuswb(a) << 24);
42 }
43
44 extern "C" {
45
46 void ConvertYUVToRGB32Row_C(const uint8* y_buf,
47 const uint8* u_buf,
48 const uint8* v_buf,
49 uint8* rgb_buf,
50 int width) {
51 for (int x = 0; x < width; x += 2) {
52 uint8 u = u_buf[x >> 1];
53 uint8 v = v_buf[x >> 1];
54 uint8 y0 = y_buf[x];
55 YUVPixel(y0, u, v, rgb_buf);
56 if ((x + 1) < width) {
57 uint8 y1 = y_buf[x + 1];
58 YUVPixel(y1, u, v, rgb_buf + 4);
59 }
60 rgb_buf += 8; // Advance 2 pixels.
61 }
62 }
63
64 // 16.16 fixed point is used. A shift by 16 isolates the integer.
65 // A shift by 17 is used to further subsample the chrominence channels.
66 // & 0xffff isolates the fixed point fraction. >> 2 to get the upper 2 bits,
67 // for 1/65536 pixel accurate interpolation.
68 void ScaleYUVToRGB32Row_C(const uint8* y_buf,
69 const uint8* u_buf,
70 const uint8* v_buf,
71 uint8* rgb_buf,
72 int width,
73 int source_dx) {
74 int x = 0;
75 for (int i = 0; i < width; i += 2) {
76 int y = y_buf[x >> 16];
77 int u = u_buf[(x >> 17)];
78 int v = v_buf[(x >> 17)];
79 YUVPixel(y, u, v, rgb_buf);
80 x += source_dx;
81 if ((i + 1) < width) {
82 y = y_buf[x >> 16];
83 YUVPixel(y, u, v, rgb_buf+4);
84 x += source_dx;
85 }
86 rgb_buf += 8;
87 }
88 }
89
90 void LinearScaleYUVToRGB32Row_C(const uint8* y_buf,
91 const uint8* u_buf,
92 const uint8* v_buf,
93 uint8* rgb_buf,
94 int width,
95 int source_dx) {
96 int x = 0;
97 if (source_dx >= 0x20000) {
98 x = 32768;
99 }
100 for (int i = 0; i < width; i += 2) {
101 int y0 = y_buf[x >> 16];
102 int y1 = y_buf[(x >> 16) + 1];
103 int u0 = u_buf[(x >> 17)];
104 int u1 = u_buf[(x >> 17) + 1];
105 int v0 = v_buf[(x >> 17)];
106 int v1 = v_buf[(x >> 17) + 1];
107 int y_frac = (x & 65535);
108 int uv_frac = ((x >> 1) & 65535);
109 int y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16;
110 int u = (uv_frac * u1 + (uv_frac ^ 65535) * u0) >> 16;
111 int v = (uv_frac * v1 + (uv_frac ^ 65535) * v0) >> 16;
112 YUVPixel(y, u, v, rgb_buf);
113 x += source_dx;
114 if ((i + 1) < width) {
115 y0 = y_buf[x >> 16];
116 y1 = y_buf[(x >> 16) + 1];
117 y_frac = (x & 65535);
118 y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16;
119 YUVPixel(y, u, v, rgb_buf+4);
120 x += source_dx;
121 }
122 rgb_buf += 8;
123 }
124 }
125
126 }
127
128 namespace media {
129
130 void ConvertYUVToRGB32_C(const uint8* yplane,
131 const uint8* uplane,
132 const uint8* vplane,
133 uint8* rgbframe,
134 int width,
135 int height,
136 int ystride,
137 int uvstride,
138 int rgbstride,
139 YUVType yuv_type) {
140 unsigned int y_shift = yuv_type;
141 for (int y = 0; y < height; ++y) {
142 uint8* rgb_row = rgbframe + y * rgbstride;
143 const uint8* y_ptr = yplane + y * ystride;
144 const uint8* u_ptr = uplane + (y >> y_shift) * uvstride;
145 const uint8* v_ptr = vplane + (y >> y_shift) * uvstride;
146
147 ConvertYUVToRGB32Row_C(y_ptr,
148 u_ptr,
149 v_ptr,
150 rgb_row,
151 width);
152 }
153 }
154
155 } // namespace media
OLDNEW
« no previous file with comments | « media/base/simd/convert_yuv_to_rgb.h ('k') | media/base/simd/convert_yuv_to_rgb_mmx.asm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698