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

Side by Side Diff: media/base/yuv_row_mac.cc

Issue 113407: ScaleYV12 optimization.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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/yuv_row_linux.cc ('k') | media/base/yuv_row_win.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/yuv_row.h" 5 #include "media/base/yuv_row.h"
6 6
7 // Enable bilinear filtering by turning on the following macro. 7 // Enable bilinear filtering by turning on the following macro.
8 // #define MEDIA_BILINEAR_FILTER 1 8 // #define MEDIA_BILINEAR_FILTER 1
9 9
10 #ifdef _DEBUG 10 #ifdef _DEBUG
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 int32 cg = (- 100 * d - 208 * e + 128); 143 int32 cg = (- 100 * d - 208 * e + 128);
144 int32 cr = (409 * e + 128); 144 int32 cr = (409 * e + 128);
145 145
146 int32 C298a = ((static_cast<int32>(y) - 16) * 298 + 128); 146 int32 C298a = ((static_cast<int32>(y) - 16) * 298 + 128);
147 *reinterpret_cast<uint32*>(rgb_buf) = (clip(C298a + cb)) | 147 *reinterpret_cast<uint32*>(rgb_buf) = (clip(C298a + cb)) |
148 (clip(C298a + cg) << 8) | 148 (clip(C298a + cg) << 8) |
149 (clip(C298a + cr) << 16) | 149 (clip(C298a + cr) << 16) |
150 (0xff000000); 150 (0xff000000);
151 } 151 }
152 152
153 void ConvertYV12ToRGB32Row(const uint8* y_buf, 153 void FastConvertYUVToRGB32Row(const uint8* y_buf,
154 const uint8* u_buf, 154 const uint8* u_buf,
155 const uint8* v_buf, 155 const uint8* v_buf,
156 uint8* rgb_buf, 156 uint8* rgb_buf,
157 int width) { 157 int width) {
158 for (int32 x = 0; x < static_cast<int32>(width); x += 2) { 158 for (int32 x = 0; x < static_cast<int32>(width); x += 2) {
159 uint8 u = u_buf[x >> 1]; 159 uint8 u = u_buf[x >> 1];
160 uint8 v = v_buf[x >> 1]; 160 uint8 v = v_buf[x >> 1];
161 int32 d = static_cast<int32>(u) - 128;
162 int32 e = static_cast<int32>(v) - 128;
163
164 int32 cb = (516 * d + 128);
165 int32 cg = (- 100 * d - 208 * e + 128);
166 int32 cr = (409 * e + 128);
167
168 uint8 y0 = y_buf[x]; 161 uint8 y0 = y_buf[x];
169 int32 C298a = ((static_cast<int32>(y0) - 16) * 298 + 128);
170 *reinterpret_cast<uint32*>(rgb_buf) = clip(C298a + cb) |
171 (clip(C298a + cg) << 8) |
172 (clip(C298a + cr) << 16) |
173 0xff000000;
174
175 uint8 y1 = y_buf[x + 1]; 162 uint8 y1 = y_buf[x + 1];
176 int32 C298b = ((static_cast<int32>(y1) - 16) * 298 + 128); 163 YuvPixel(y0, u, v, rgb_buf);
177 *reinterpret_cast<uint32*>(rgb_buf + 4) = clip(C298b + cb) | 164 YuvPixel(y1, u, v, rgb_buf + 4);
178 (clip(C298b + cg) << 8) |
179 (clip(C298b + cr) << 16) |
180 0xff000000;
181 165
182 rgb_buf += 8; // Advance 2 pixels. 166 rgb_buf += 8; // Advance 2 pixels.
183 } 167 }
184 } 168 }
185 169
186 void HalfYV12ToRGB32Row(const uint8* y_buf,
187 const uint8* u_buf,
188 const uint8* v_buf,
189 uint8* rgb_buf,
190 int width) {
191 for (int32 x = 0; x < width; ++x) {
192 uint8 u = u_buf[x];
193 uint8 v = v_buf[x];
194 int32 d = static_cast<int32>(u) - 128;
195 int32 e = static_cast<int32>(v) - 128;
196
197 int32 cb = (516 * d + 128);
198 int32 cg = (- 100 * d - 208 * e + 128);
199 int32 cr = (409 * e + 128);
200
201 uint8 y0 = y_buf[x * 2 + 0];
202 uint8 y1 = y_buf[x * 2 + 1];
203 int32 C298a = ((static_cast<int32>((y0 + y1) >> 1) - 16) * 298 + 128);
204 *reinterpret_cast<uint32*>(rgb_buf) = clip(C298a + cb) |
205 (clip(C298a + cg) << 8) |
206 (clip(C298a + cr) << 16) |
207 0xff000000;
208
209 rgb_buf += 4;
210 }
211 }
212
213 // 28.4 fixed point is used. A shift by 4 isolates the integer. 170 // 28.4 fixed point is used. A shift by 4 isolates the integer.
214 // A shift by 5 is used to further subsample the chrominence channels. 171 // A shift by 5 is used to further subsample the chrominence channels.
215 // & 15 isolates the fixed point fraction. >> 2 to get the upper 2 bits, 172 // & 15 isolates the fixed point fraction. >> 2 to get the upper 2 bits,
216 // for 1/4 pixel accurate interpolation. 173 // for 1/4 pixel accurate interpolation.
217 void ScaleYV12ToRGB32Row(const uint8* y_buf, 174 void ScaleYUVToRGB32Row(const uint8* y_buf,
218 const uint8* u_buf, 175 const uint8* u_buf,
219 const uint8* v_buf, 176 const uint8* v_buf,
220 uint8* rgb_buf, 177 uint8* rgb_buf,
221 int width, 178 int width,
222 int scaled_dx) { 179 int scaled_dx) {
223 int scaled_x = 0; 180 int scaled_x = 0;
224 for (int32 x = 0; x < width; ++x) { 181 for (int32 x = 0; x < width; ++x) {
225 uint8 u = u_buf[scaled_x >> 5]; 182 uint8 u = u_buf[scaled_x >> 5];
226 uint8 v = v_buf[scaled_x >> 5]; 183 uint8 v = v_buf[scaled_x >> 5];
227 uint8 y0 = y_buf[scaled_x >> 4]; 184 uint8 y0 = y_buf[scaled_x >> 4];
228 #if MEDIA_BILINEAR_FILTER
229 uint8 y1 = y_buf[(scaled_x >> 4) + 1];
230 switch ((scaled_x & 15) >> 2) {
231 case 1: // 75% first pixel, 25% second pixel.
232 y0 = (y0 + y0 + y0 + y1) >> 2;
233 break;
234 case 2: // 50/50 blend
235 y0 = (y0 + y1) >> 1;
236 break;
237 case 3: // 25% first pixel, 75% second pixel.
238 y0 = (y0 + y1 + y1 + y1) >> 2;
239 break;
240 default:
241 case 0: // 100% first pixel.
242 break;
243 }
244 #endif // MEDIA_BILINEAR_FILTER
245
246 YuvPixel(y0, u, v, rgb_buf); 185 YuvPixel(y0, u, v, rgb_buf);
247
248 rgb_buf += 4; 186 rgb_buf += 4;
249 scaled_x += scaled_dx; 187 scaled_x += scaled_dx;
250 } 188 }
251 } 189 }
252 190
253 } // namespace media 191 } // namespace media
254 192
OLDNEW
« no previous file with comments | « media/base/yuv_row_linux.cc ('k') | media/base/yuv_row_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698