Revert of Add correct support for videos with YUVJ420P color format, in the software...
[chromium-blink-merge.git] / media / base / yuv_convert.cc
blob2b27c1da4a9a717160e6640f84ac77c95d8bb2b4
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
3 // found in the LICENSE file.
5 // This webpage shows layout of YV12 and other YUV formats
6 // http://www.fourcc.org/yuv.php
7 // The actual conversion is best described here
8 // http://en.wikipedia.org/wiki/YUV
9 // An article on optimizing YUV conversion using tables instead of multiplies
10 // http://lestourtereaux.free.fr/papers/data/yuvrgb.pdf
12 // YV12 is a full plane of Y and a half height, half width chroma planes
13 // YV16 is a full plane of Y and a full height, half width chroma planes
15 // ARGB pixel format is output, which on little endian is stored as BGRA.
16 // The alpha is set to 255, allowing the application to use RGBA or RGB32.
18 #include "media/base/yuv_convert.h"
20 #include "base/cpu.h"
21 #include "base/logging.h"
22 #include "base/memory/scoped_ptr.h"
23 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
24 #include "build/build_config.h"
25 #include "media/base/simd/convert_rgb_to_yuv.h"
26 #include "media/base/simd/convert_yuv_to_rgb.h"
27 #include "media/base/simd/filter_yuv.h"
29 #if defined(ARCH_CPU_X86_FAMILY)
30 #if defined(COMPILER_MSVC)
31 #include <intrin.h>
32 #else
33 #include <mmintrin.h>
34 #endif
35 #endif
37 // Assembly functions are declared without namespace.
38 extern "C" { void EmptyRegisterState_MMX(); } // extern "C"
40 namespace media {
42 typedef void (*FilterYUVRowsProc)(uint8*, const uint8*, const uint8*, int, int);
44 typedef void (*ConvertRGBToYUVProc)(const uint8*,
45 uint8*,
46 uint8*,
47 uint8*,
48 int,
49 int,
50 int,
51 int,
52 int);
54 typedef void (*ConvertYUVToRGB32Proc)(const uint8*,
55 const uint8*,
56 const uint8*,
57 uint8*,
58 int,
59 int,
60 int,
61 int,
62 int,
63 YUVType);
65 typedef void (*ConvertYUVAToARGBProc)(const uint8*,
66 const uint8*,
67 const uint8*,
68 const uint8*,
69 uint8*,
70 int,
71 int,
72 int,
73 int,
74 int,
75 int,
76 YUVType);
78 typedef void (*ConvertYUVToRGB32RowProc)(const uint8*,
79 const uint8*,
80 const uint8*,
81 uint8*,
82 ptrdiff_t);
84 typedef void (*ConvertYUVAToARGBRowProc)(const uint8*,
85 const uint8*,
86 const uint8*,
87 const uint8*,
88 uint8*,
89 ptrdiff_t);
91 typedef void (*ScaleYUVToRGB32RowProc)(const uint8*,
92 const uint8*,
93 const uint8*,
94 uint8*,
95 ptrdiff_t,
96 ptrdiff_t);
98 static FilterYUVRowsProc g_filter_yuv_rows_proc_ = NULL;
99 static ConvertYUVToRGB32RowProc g_convert_yuv_to_rgb32_row_proc_ = NULL;
100 static ScaleYUVToRGB32RowProc g_scale_yuv_to_rgb32_row_proc_ = NULL;
101 static ScaleYUVToRGB32RowProc g_linear_scale_yuv_to_rgb32_row_proc_ = NULL;
102 static ConvertRGBToYUVProc g_convert_rgb32_to_yuv_proc_ = NULL;
103 static ConvertRGBToYUVProc g_convert_rgb24_to_yuv_proc_ = NULL;
104 static ConvertYUVToRGB32Proc g_convert_yuv_to_rgb32_proc_ = NULL;
105 static ConvertYUVAToARGBProc g_convert_yuva_to_argb_proc_ = NULL;
107 // Empty SIMD registers state after using them.
108 void EmptyRegisterStateStub() {}
109 #if defined(MEDIA_MMX_INTRINSICS_AVAILABLE)
110 void EmptyRegisterStateIntrinsic() { _mm_empty(); }
111 #endif
112 typedef void (*EmptyRegisterStateProc)();
113 static EmptyRegisterStateProc g_empty_register_state_proc_ = NULL;
115 void InitializeCPUSpecificYUVConversions() {
116 CHECK(!g_filter_yuv_rows_proc_);
117 CHECK(!g_convert_yuv_to_rgb32_row_proc_);
118 CHECK(!g_scale_yuv_to_rgb32_row_proc_);
119 CHECK(!g_linear_scale_yuv_to_rgb32_row_proc_);
120 CHECK(!g_convert_rgb32_to_yuv_proc_);
121 CHECK(!g_convert_rgb24_to_yuv_proc_);
122 CHECK(!g_convert_yuv_to_rgb32_proc_);
123 CHECK(!g_convert_yuva_to_argb_proc_);
124 CHECK(!g_empty_register_state_proc_);
126 g_filter_yuv_rows_proc_ = FilterYUVRows_C;
127 g_convert_yuv_to_rgb32_row_proc_ = ConvertYUVToRGB32Row_C;
128 g_scale_yuv_to_rgb32_row_proc_ = ScaleYUVToRGB32Row_C;
129 g_linear_scale_yuv_to_rgb32_row_proc_ = LinearScaleYUVToRGB32Row_C;
130 g_convert_rgb32_to_yuv_proc_ = ConvertRGB32ToYUV_C;
131 g_convert_rgb24_to_yuv_proc_ = ConvertRGB24ToYUV_C;
132 g_convert_yuv_to_rgb32_proc_ = ConvertYUVToRGB32_C;
133 g_convert_yuva_to_argb_proc_ = ConvertYUVAToARGB_C;
134 g_empty_register_state_proc_ = EmptyRegisterStateStub;
136 // Assembly code confuses MemorySanitizer.
137 #if defined(ARCH_CPU_X86_FAMILY) && !defined(MEMORY_SANITIZER)
138 base::CPU cpu;
139 if (cpu.has_mmx()) {
140 g_convert_yuv_to_rgb32_row_proc_ = ConvertYUVToRGB32Row_MMX;
141 g_scale_yuv_to_rgb32_row_proc_ = ScaleYUVToRGB32Row_MMX;
142 g_convert_yuv_to_rgb32_proc_ = ConvertYUVToRGB32_MMX;
143 g_convert_yuva_to_argb_proc_ = ConvertYUVAToARGB_MMX;
144 g_linear_scale_yuv_to_rgb32_row_proc_ = LinearScaleYUVToRGB32Row_MMX;
146 #if defined(MEDIA_MMX_INTRINSICS_AVAILABLE)
147 g_filter_yuv_rows_proc_ = FilterYUVRows_MMX;
148 g_empty_register_state_proc_ = EmptyRegisterStateIntrinsic;
149 #else
150 g_empty_register_state_proc_ = EmptyRegisterState_MMX;
151 #endif
154 if (cpu.has_sse()) {
155 g_convert_yuv_to_rgb32_row_proc_ = ConvertYUVToRGB32Row_SSE;
156 g_scale_yuv_to_rgb32_row_proc_ = ScaleYUVToRGB32Row_SSE;
157 g_linear_scale_yuv_to_rgb32_row_proc_ = LinearScaleYUVToRGB32Row_SSE;
158 g_convert_yuv_to_rgb32_proc_ = ConvertYUVToRGB32_SSE;
161 if (cpu.has_sse2()) {
162 g_filter_yuv_rows_proc_ = FilterYUVRows_SSE2;
163 g_convert_rgb32_to_yuv_proc_ = ConvertRGB32ToYUV_SSE2;
165 #if defined(ARCH_CPU_X86_64)
166 g_scale_yuv_to_rgb32_row_proc_ = ScaleYUVToRGB32Row_SSE2_X64;
168 // Technically this should be in the MMX section, but MSVC will optimize out
169 // the export of LinearScaleYUVToRGB32Row_MMX, which is required by the unit
170 // tests, if that decision can be made at compile time. Since all X64 CPUs
171 // have SSE2, we can hack around this by making the selection here.
172 g_linear_scale_yuv_to_rgb32_row_proc_ = LinearScaleYUVToRGB32Row_MMX_X64;
173 #endif
176 if (cpu.has_ssse3()) {
177 g_convert_rgb24_to_yuv_proc_ = &ConvertRGB24ToYUV_SSSE3;
179 // TODO(hclam): Add ConvertRGB32ToYUV_SSSE3 when the cyan problem is solved.
180 // See: crbug.com/100462
182 #endif
185 // Empty SIMD registers state after using them.
186 void EmptyRegisterState() { g_empty_register_state_proc_(); }
188 // 16.16 fixed point arithmetic
189 const int kFractionBits = 16;
190 const int kFractionMax = 1 << kFractionBits;
191 const int kFractionMask = ((1 << kFractionBits) - 1);
193 // Scale a frame of YUV to 32 bit ARGB.
194 void ScaleYUVToRGB32(const uint8* y_buf,
195 const uint8* u_buf,
196 const uint8* v_buf,
197 uint8* rgb_buf,
198 int source_width,
199 int source_height,
200 int width,
201 int height,
202 int y_pitch,
203 int uv_pitch,
204 int rgb_pitch,
205 YUVType yuv_type,
206 Rotate view_rotate,
207 ScaleFilter filter) {
208 // Handle zero sized sources and destinations.
209 if ((yuv_type == YV12 && (source_width < 2 || source_height < 2)) ||
210 (yuv_type == YV16 && (source_width < 2 || source_height < 1)) ||
211 width == 0 || height == 0)
212 return;
214 // 4096 allows 3 buffers to fit in 12k.
215 // Helps performance on CPU with 16K L1 cache.
216 // Large enough for 3830x2160 and 30" displays which are 2560x1600.
217 const int kFilterBufferSize = 4096;
218 // Disable filtering if the screen is too big (to avoid buffer overflows).
219 // This should never happen to regular users: they don't have monitors
220 // wider than 4096 pixels.
221 // TODO(fbarchard): Allow rotated videos to filter.
222 if (source_width > kFilterBufferSize || view_rotate)
223 filter = FILTER_NONE;
225 unsigned int y_shift = yuv_type;
226 // Diagram showing origin and direction of source sampling.
227 // ->0 4<-
228 // 7 3
230 // 6 5
231 // ->1 2<-
232 // Rotations that start at right side of image.
233 if ((view_rotate == ROTATE_180) || (view_rotate == ROTATE_270) ||
234 (view_rotate == MIRROR_ROTATE_0) || (view_rotate == MIRROR_ROTATE_90)) {
235 y_buf += source_width - 1;
236 u_buf += source_width / 2 - 1;
237 v_buf += source_width / 2 - 1;
238 source_width = -source_width;
240 // Rotations that start at bottom of image.
241 if ((view_rotate == ROTATE_90) || (view_rotate == ROTATE_180) ||
242 (view_rotate == MIRROR_ROTATE_90) || (view_rotate == MIRROR_ROTATE_180)) {
243 y_buf += (source_height - 1) * y_pitch;
244 u_buf += ((source_height >> y_shift) - 1) * uv_pitch;
245 v_buf += ((source_height >> y_shift) - 1) * uv_pitch;
246 source_height = -source_height;
249 int source_dx = source_width * kFractionMax / width;
251 if ((view_rotate == ROTATE_90) || (view_rotate == ROTATE_270)) {
252 int tmp = height;
253 height = width;
254 width = tmp;
255 tmp = source_height;
256 source_height = source_width;
257 source_width = tmp;
258 int source_dy = source_height * kFractionMax / height;
259 source_dx = ((source_dy >> kFractionBits) * y_pitch) << kFractionBits;
260 if (view_rotate == ROTATE_90) {
261 y_pitch = -1;
262 uv_pitch = -1;
263 source_height = -source_height;
264 } else {
265 y_pitch = 1;
266 uv_pitch = 1;
270 // Need padding because FilterRows() will write 1 to 16 extra pixels
271 // after the end for SSE2 version.
272 uint8 yuvbuf[16 + kFilterBufferSize * 3 + 16];
273 uint8* ybuf =
274 reinterpret_cast<uint8*>(reinterpret_cast<uintptr_t>(yuvbuf + 15) & ~15);
275 uint8* ubuf = ybuf + kFilterBufferSize;
276 uint8* vbuf = ubuf + kFilterBufferSize;
278 // TODO(fbarchard): Fixed point math is off by 1 on negatives.
280 // We take a y-coordinate in [0,1] space in the source image space, and
281 // transform to a y-coordinate in [0,1] space in the destination image space.
282 // Note that the coordinate endpoints lie on pixel boundaries, not on pixel
283 // centers: e.g. a two-pixel-high image will have pixel centers at 0.25 and
284 // 0.75. The formula is as follows (in fixed-point arithmetic):
285 // y_dst = dst_height * ((y_src + 0.5) / src_height)
286 // dst_pixel = clamp([0, dst_height - 1], floor(y_dst - 0.5))
287 // Implement this here as an accumulator + delta, to avoid expensive math
288 // in the loop.
289 int source_y_subpixel_accum =
290 ((kFractionMax / 2) * source_height) / height - (kFractionMax / 2);
291 int source_y_subpixel_delta = ((1 << kFractionBits) * source_height) / height;
293 // TODO(fbarchard): Split this into separate function for better efficiency.
294 for (int y = 0; y < height; ++y) {
295 uint8* dest_pixel = rgb_buf + y * rgb_pitch;
296 int source_y_subpixel = source_y_subpixel_accum;
297 source_y_subpixel_accum += source_y_subpixel_delta;
298 if (source_y_subpixel < 0)
299 source_y_subpixel = 0;
300 else if (source_y_subpixel > ((source_height - 1) << kFractionBits))
301 source_y_subpixel = (source_height - 1) << kFractionBits;
303 const uint8* y_ptr = NULL;
304 const uint8* u_ptr = NULL;
305 const uint8* v_ptr = NULL;
306 // Apply vertical filtering if necessary.
307 // TODO(fbarchard): Remove memcpy when not necessary.
308 if (filter & media::FILTER_BILINEAR_V) {
309 int source_y = source_y_subpixel >> kFractionBits;
310 y_ptr = y_buf + source_y * y_pitch;
311 u_ptr = u_buf + (source_y >> y_shift) * uv_pitch;
312 v_ptr = v_buf + (source_y >> y_shift) * uv_pitch;
314 // Vertical scaler uses 16.8 fixed point.
315 int source_y_fraction = (source_y_subpixel & kFractionMask) >> 8;
316 if (source_y_fraction != 0) {
317 g_filter_yuv_rows_proc_(
318 ybuf, y_ptr, y_ptr + y_pitch, source_width, source_y_fraction);
319 } else {
320 memcpy(ybuf, y_ptr, source_width);
322 y_ptr = ybuf;
323 ybuf[source_width] = ybuf[source_width - 1];
325 int uv_source_width = (source_width + 1) / 2;
326 int source_uv_fraction;
328 // For formats with half-height UV planes, each even-numbered pixel row
329 // should not interpolate, since the next row to interpolate from should
330 // be a duplicate of the current row.
331 if (y_shift && (source_y & 0x1) == 0)
332 source_uv_fraction = 0;
333 else
334 source_uv_fraction = source_y_fraction;
336 if (source_uv_fraction != 0) {
337 g_filter_yuv_rows_proc_(
338 ubuf, u_ptr, u_ptr + uv_pitch, uv_source_width, source_uv_fraction);
339 g_filter_yuv_rows_proc_(
340 vbuf, v_ptr, v_ptr + uv_pitch, uv_source_width, source_uv_fraction);
341 } else {
342 memcpy(ubuf, u_ptr, uv_source_width);
343 memcpy(vbuf, v_ptr, uv_source_width);
345 u_ptr = ubuf;
346 v_ptr = vbuf;
347 ubuf[uv_source_width] = ubuf[uv_source_width - 1];
348 vbuf[uv_source_width] = vbuf[uv_source_width - 1];
349 } else {
350 // Offset by 1/2 pixel for center sampling.
351 int source_y = (source_y_subpixel + (kFractionMax / 2)) >> kFractionBits;
352 y_ptr = y_buf + source_y * y_pitch;
353 u_ptr = u_buf + (source_y >> y_shift) * uv_pitch;
354 v_ptr = v_buf + (source_y >> y_shift) * uv_pitch;
356 if (source_dx == kFractionMax) { // Not scaled
357 g_convert_yuv_to_rgb32_row_proc_(y_ptr, u_ptr, v_ptr, dest_pixel, width);
358 } else {
359 if (filter & FILTER_BILINEAR_H) {
360 g_linear_scale_yuv_to_rgb32_row_proc_(
361 y_ptr, u_ptr, v_ptr, dest_pixel, width, source_dx);
362 } else {
363 g_scale_yuv_to_rgb32_row_proc_(
364 y_ptr, u_ptr, v_ptr, dest_pixel, width, source_dx);
369 g_empty_register_state_proc_();
372 // Scale a frame of YV12 to 32 bit ARGB for a specific rectangle.
373 void ScaleYUVToRGB32WithRect(const uint8* y_buf,
374 const uint8* u_buf,
375 const uint8* v_buf,
376 uint8* rgb_buf,
377 int source_width,
378 int source_height,
379 int dest_width,
380 int dest_height,
381 int dest_rect_left,
382 int dest_rect_top,
383 int dest_rect_right,
384 int dest_rect_bottom,
385 int y_pitch,
386 int uv_pitch,
387 int rgb_pitch) {
388 // This routine doesn't currently support up-scaling.
389 CHECK_LE(dest_width, source_width);
390 CHECK_LE(dest_height, source_height);
392 // Sanity-check the destination rectangle.
393 DCHECK(dest_rect_left >= 0 && dest_rect_right <= dest_width);
394 DCHECK(dest_rect_top >= 0 && dest_rect_bottom <= dest_height);
395 DCHECK(dest_rect_right > dest_rect_left);
396 DCHECK(dest_rect_bottom > dest_rect_top);
398 // Fixed-point value of vertical and horizontal scale down factor.
399 // Values are in the format 16.16.
400 int y_step = kFractionMax * source_height / dest_height;
401 int x_step = kFractionMax * source_width / dest_width;
403 // Determine the coordinates of the rectangle in 16.16 coords.
404 // NB: Our origin is the *center* of the top/left pixel, NOT its top/left.
405 // If we're down-scaling by more than a factor of two, we start with a 50%
406 // fraction to avoid degenerating to point-sampling - we should really just
407 // fix the fraction at 50% for all pixels in that case.
408 int source_left = dest_rect_left * x_step;
409 int source_right = (dest_rect_right - 1) * x_step;
410 if (x_step < kFractionMax * 2) {
411 source_left += ((x_step - kFractionMax) / 2);
412 source_right += ((x_step - kFractionMax) / 2);
413 } else {
414 source_left += kFractionMax / 2;
415 source_right += kFractionMax / 2;
417 int source_top = dest_rect_top * y_step;
418 if (y_step < kFractionMax * 2) {
419 source_top += ((y_step - kFractionMax) / 2);
420 } else {
421 source_top += kFractionMax / 2;
424 // Determine the parts of the Y, U and V buffers to interpolate.
425 int source_y_left = source_left >> kFractionBits;
426 int source_y_right =
427 std::min((source_right >> kFractionBits) + 2, source_width + 1);
429 int source_uv_left = source_y_left / 2;
430 int source_uv_right = std::min((source_right >> (kFractionBits + 1)) + 2,
431 (source_width + 1) / 2);
433 int source_y_width = source_y_right - source_y_left;
434 int source_uv_width = source_uv_right - source_uv_left;
436 // Determine number of pixels in each output row.
437 int dest_rect_width = dest_rect_right - dest_rect_left;
439 // Intermediate buffer for vertical interpolation.
440 // 4096 bytes allows 3 buffers to fit in 12k, which fits in a 16K L1 cache,
441 // and is bigger than most users will generally need.
442 // The buffer is 16-byte aligned and padded with 16 extra bytes; some of the
443 // FilterYUVRowProcs have alignment requirements, and the SSE version can
444 // write up to 16 bytes past the end of the buffer.
445 const int kFilterBufferSize = 4096;
446 const bool kAvoidUsingOptimizedFilter = source_width > kFilterBufferSize;
447 uint8 yuv_temp[16 + kFilterBufferSize * 3 + 16];
448 // memset() yuv_temp to 0 to avoid bogus warnings when running on Valgrind.
449 if (RunningOnValgrind())
450 memset(yuv_temp, 0, sizeof(yuv_temp));
451 uint8* y_temp = reinterpret_cast<uint8*>(
452 reinterpret_cast<uintptr_t>(yuv_temp + 15) & ~15);
453 uint8* u_temp = y_temp + kFilterBufferSize;
454 uint8* v_temp = u_temp + kFilterBufferSize;
456 // Move to the top-left pixel of output.
457 rgb_buf += dest_rect_top * rgb_pitch;
458 rgb_buf += dest_rect_left * 4;
460 // For each destination row perform interpolation and color space
461 // conversion to produce the output.
462 for (int row = dest_rect_top; row < dest_rect_bottom; ++row) {
463 // Round the fixed-point y position to get the current row.
464 int source_row = source_top >> kFractionBits;
465 int source_uv_row = source_row / 2;
466 DCHECK(source_row < source_height);
468 // Locate the first row for each plane for interpolation.
469 const uint8* y0_ptr = y_buf + y_pitch * source_row + source_y_left;
470 const uint8* u0_ptr = u_buf + uv_pitch * source_uv_row + source_uv_left;
471 const uint8* v0_ptr = v_buf + uv_pitch * source_uv_row + source_uv_left;
472 const uint8* y1_ptr = NULL;
473 const uint8* u1_ptr = NULL;
474 const uint8* v1_ptr = NULL;
476 // Locate the second row for interpolation, being careful not to overrun.
477 if (source_row + 1 >= source_height) {
478 y1_ptr = y0_ptr;
479 } else {
480 y1_ptr = y0_ptr + y_pitch;
482 if (source_uv_row + 1 >= (source_height + 1) / 2) {
483 u1_ptr = u0_ptr;
484 v1_ptr = v0_ptr;
485 } else {
486 u1_ptr = u0_ptr + uv_pitch;
487 v1_ptr = v0_ptr + uv_pitch;
490 if (!kAvoidUsingOptimizedFilter) {
491 // Vertical scaler uses 16.8 fixed point.
492 int fraction = (source_top & kFractionMask) >> 8;
493 g_filter_yuv_rows_proc_(
494 y_temp + source_y_left, y0_ptr, y1_ptr, source_y_width, fraction);
495 g_filter_yuv_rows_proc_(
496 u_temp + source_uv_left, u0_ptr, u1_ptr, source_uv_width, fraction);
497 g_filter_yuv_rows_proc_(
498 v_temp + source_uv_left, v0_ptr, v1_ptr, source_uv_width, fraction);
500 // Perform horizontal interpolation and color space conversion.
501 // TODO(hclam): Use the MMX version after more testing.
502 LinearScaleYUVToRGB32RowWithRange_C(y_temp,
503 u_temp,
504 v_temp,
505 rgb_buf,
506 dest_rect_width,
507 source_left,
508 x_step);
509 } else {
510 // If the frame is too large then we linear scale a single row.
511 LinearScaleYUVToRGB32RowWithRange_C(y0_ptr,
512 u0_ptr,
513 v0_ptr,
514 rgb_buf,
515 dest_rect_width,
516 source_left,
517 x_step);
520 // Advance vertically in the source and destination image.
521 source_top += y_step;
522 rgb_buf += rgb_pitch;
525 g_empty_register_state_proc_();
528 void ConvertRGB32ToYUV(const uint8* rgbframe,
529 uint8* yplane,
530 uint8* uplane,
531 uint8* vplane,
532 int width,
533 int height,
534 int rgbstride,
535 int ystride,
536 int uvstride) {
537 g_convert_rgb32_to_yuv_proc_(rgbframe,
538 yplane,
539 uplane,
540 vplane,
541 width,
542 height,
543 rgbstride,
544 ystride,
545 uvstride);
548 void ConvertRGB24ToYUV(const uint8* rgbframe,
549 uint8* yplane,
550 uint8* uplane,
551 uint8* vplane,
552 int width,
553 int height,
554 int rgbstride,
555 int ystride,
556 int uvstride) {
557 g_convert_rgb24_to_yuv_proc_(rgbframe,
558 yplane,
559 uplane,
560 vplane,
561 width,
562 height,
563 rgbstride,
564 ystride,
565 uvstride);
568 void ConvertYUY2ToYUV(const uint8* src,
569 uint8* yplane,
570 uint8* uplane,
571 uint8* vplane,
572 int width,
573 int height) {
574 for (int i = 0; i < height / 2; ++i) {
575 for (int j = 0; j < (width / 2); ++j) {
576 yplane[0] = src[0];
577 *uplane = src[1];
578 yplane[1] = src[2];
579 *vplane = src[3];
580 src += 4;
581 yplane += 2;
582 uplane++;
583 vplane++;
585 for (int j = 0; j < (width / 2); ++j) {
586 yplane[0] = src[0];
587 yplane[1] = src[2];
588 src += 4;
589 yplane += 2;
594 void ConvertNV21ToYUV(const uint8* src,
595 uint8* yplane,
596 uint8* uplane,
597 uint8* vplane,
598 int width,
599 int height) {
600 int y_plane_size = width * height;
601 memcpy(yplane, src, y_plane_size);
603 src += y_plane_size;
604 int u_plane_size = y_plane_size >> 2;
605 for (int i = 0; i < u_plane_size; ++i) {
606 *vplane++ = *src++;
607 *uplane++ = *src++;
611 void ConvertYUVToRGB32(const uint8* yplane,
612 const uint8* uplane,
613 const uint8* vplane,
614 uint8* rgbframe,
615 int width,
616 int height,
617 int ystride,
618 int uvstride,
619 int rgbstride,
620 YUVType yuv_type) {
621 g_convert_yuv_to_rgb32_proc_(yplane,
622 uplane,
623 vplane,
624 rgbframe,
625 width,
626 height,
627 ystride,
628 uvstride,
629 rgbstride,
630 yuv_type);
633 void ConvertYUVAToARGB(const uint8* yplane,
634 const uint8* uplane,
635 const uint8* vplane,
636 const uint8* aplane,
637 uint8* rgbframe,
638 int width,
639 int height,
640 int ystride,
641 int uvstride,
642 int astride,
643 int rgbstride,
644 YUVType yuv_type) {
645 g_convert_yuva_to_argb_proc_(yplane,
646 uplane,
647 vplane,
648 aplane,
649 rgbframe,
650 width,
651 height,
652 ystride,
653 uvstride,
654 astride,
655 rgbstride,
656 yuv_type);
659 } // namespace media