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

Side by Side Diff: source/convert.cc

Issue 2114843002: API for deinterlacing YUV420 output on Android (Closed) Base URL: https://chromium.googlesource.com/libyuv/libyuv@master
Patch Set: initial unittest for Android420 Created 4 years, 5 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
« no previous file with comments | « include/libyuv/convert.h ('k') | source/row_common.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 /* 1 /*
2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 CopyRow(src, dst, width); 219 CopyRow(src, dst, width);
220 CopyRow(src + src_stride_0, dst + dst_stride, width); 220 CopyRow(src + src_stride_0, dst + dst_stride, width);
221 src += src_stride_0 + src_stride_1; 221 src += src_stride_0 + src_stride_1;
222 dst += dst_stride * 2; 222 dst += dst_stride * 2;
223 } 223 }
224 if (height & 1) { 224 if (height & 1) {
225 CopyRow(src, dst, width); 225 CopyRow(src, dst, width);
226 } 226 }
227 } 227 }
228 228
229 // Support function for NV12 etc UV channels.
230 // width and height are plane sizes (typically half pixel width)
braveyao 2016/07/12 21:42:04 s/width/Width?
fbarchard1 2016/07/12 23:19:38 Done.
231 static void SplitPlane(const uint8* src_uv, int src_stride_uv,
232 uint8* dst_u, int dst_stride_u,
233 uint8* dst_v, int dst_stride_v,
234 int width, int height) {
235 int y;
236 void (*SplitUVRow)(const uint8* src_uv, uint8* dst_u, uint8* dst_v,
237 int width) = SplitUVRow_C;
238 // Negative height means invert the image.
239 if (height < 0) {
240 height = -height;
241 dst_u = dst_u + (height - 1) * dst_stride_u;
242 dst_v = dst_v + (height - 1) * dst_stride_v;
243 dst_stride_u = -dst_stride_u;
244 dst_stride_v = -dst_stride_v;
245 }
246 // Coalesce rows.
247 if (src_stride_uv == width * 2 &&
248 dst_stride_u == width &&
249 dst_stride_v == width) {
250 width *= height;
251 height = 1;
252 src_stride_uv = dst_stride_u = dst_stride_v = 0;
253 }
254 #if defined(HAS_SPLITUVROW_SSE2)
255 if (TestCpuFlag(kCpuHasSSE2)) {
256 SplitUVRow = SplitUVRow_Any_SSE2;
257 if (IS_ALIGNED(width, 16)) {
258 SplitUVRow = SplitUVRow_SSE2;
259 }
260 }
261 #endif
262 #if defined(HAS_SPLITUVROW_AVX2)
263 if (TestCpuFlag(kCpuHasAVX2)) {
264 SplitUVRow = SplitUVRow_Any_AVX2;
265 if (IS_ALIGNED(width, 32)) {
266 SplitUVRow = SplitUVRow_AVX2;
267 }
268 }
269 #endif
270 #if defined(HAS_SPLITUVROW_NEON)
271 if (TestCpuFlag(kCpuHasNEON)) {
272 SplitUVRow = SplitUVRow_Any_NEON;
273 if (IS_ALIGNED(width, 16)) {
274 SplitUVRow = SplitUVRow_NEON;
275 }
276 }
277 #endif
278 #if defined(HAS_SPLITUVROW_DSPR2)
279 if (TestCpuFlag(kCpuHasDSPR2) &&
280 IS_ALIGNED(dst_u, 4) && IS_ALIGNED(dst_stride_u, 4) &&
281 IS_ALIGNED(dst_v, 4) && IS_ALIGNED(dst_stride_v, 4)) {
282 SplitUVRow = SplitUVRow_Any_DSPR2;
283 if (IS_ALIGNED(width, 16)) {
284 SplitUVRow = SplitUVRow_DSPR2;
285 }
286 }
287 #endif
288
289 for (y = 0; y < height; ++y) {
290 // Copy a row of UV.
291 SplitUVRow(src_uv, dst_u, dst_v, width);
292 dst_u += dst_stride_u;
293 dst_v += dst_stride_v;
294 src_uv += src_stride_uv;
295 }
296 }
297
229 // Support converting from FOURCC_M420 298 // Support converting from FOURCC_M420
230 // Useful for bandwidth constrained transports like USB 1.0 and 2.0 and for 299 // Useful for bandwidth constrained transports like USB 1.0 and 2.0 and for
231 // easy conversion to I420. 300 // easy conversion to I420.
232 // M420 format description: 301 // M420 format description:
233 // M420 is row biplanar 420: 2 rows of Y and 1 row of UV. 302 // M420 is row biplanar 420: 2 rows of Y and 1 row of UV.
234 // Chroma is half width / half height. (420) 303 // Chroma is half width / half height. (420)
235 // src_stride_m420 is row planar. Normally this will be the width in pixels. 304 // src_stride_m420 is row planar. Normally this will be the width in pixels.
236 // The UV plane is half width, but 2 values, so src_stride_m420 applies to 305 // The UV plane is half width, but 2 values, so src_stride_m420 applies to
237 // this as well as the two Y planes. 306 // this as well as the two Y planes.
238 static int X420ToI420(const uint8* src_y, 307 static int X420ToI420(const uint8* src_y,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 width, height); 435 width, height);
367 } 436 }
368 437
369 // Convert M420 to I420. 438 // Convert M420 to I420.
370 LIBYUV_API 439 LIBYUV_API
371 int M420ToI420(const uint8* src_m420, int src_stride_m420, 440 int M420ToI420(const uint8* src_m420, int src_stride_m420,
372 uint8* dst_y, int dst_stride_y, 441 uint8* dst_y, int dst_stride_y,
373 uint8* dst_u, int dst_stride_u, 442 uint8* dst_u, int dst_stride_u,
374 uint8* dst_v, int dst_stride_v, 443 uint8* dst_v, int dst_stride_v,
375 int width, int height) { 444 int width, int height) {
445
braveyao 2016/07/12 21:42:05 why added 2 white lines?
fbarchard1 2016/07/12 23:19:38 Done.
446
376 return X420ToI420(src_m420, src_stride_m420, src_stride_m420 * 2, 447 return X420ToI420(src_m420, src_stride_m420, src_stride_m420 * 2,
377 src_m420 + src_stride_m420 * 2, src_stride_m420 * 3, 448 src_m420 + src_stride_m420 * 2, src_stride_m420 * 3,
378 dst_y, dst_stride_y, 449 dst_y, dst_stride_y,
379 dst_u, dst_stride_u, 450 dst_u, dst_stride_u,
380 dst_v, dst_stride_v, 451 dst_v, dst_stride_v,
381 width, height); 452 width, height);
382 } 453 }
383 454
384 // Convert YUY2 to I420. 455 // Convert YUY2 to I420.
385 LIBYUV_API 456 LIBYUV_API
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 ARGBToYRow(row, dst_y, width); 1447 ARGBToYRow(row, dst_y, width);
1377 #endif 1448 #endif
1378 } 1449 }
1379 #if !defined(HAS_ARGB4444TOYROW_NEON) 1450 #if !defined(HAS_ARGB4444TOYROW_NEON)
1380 free_aligned_buffer_64(row); 1451 free_aligned_buffer_64(row);
1381 } 1452 }
1382 #endif 1453 #endif
1383 return 0; 1454 return 0;
1384 } 1455 }
1385 1456
1457 static void SplitPixels(const uint8* src_u, int pixel_stride_uv,
1458 uint8* dst_u, int width) {
braveyao 2016/07/12 21:42:05 Maybe indent more to align with arguments above?
fbarchard1 2016/07/12 23:19:38 Done.
1459 int i;
1460 for (i = 0; i < width; ++i) {
1461 *dst_u = *src_u;
1462 dst_u ++;
1463 src_u += pixel_stride_uv;
1464 }
1465 }
1466
1467 // Convert Android420 to I420.
1468 LIBYUV_API
1469 int Android420ToI420(const uint8* src_y, int src_stride_y,
1470 const uint8* src_u, int src_stride_u,
1471 const uint8* src_v, int src_stride_v,
1472 int pixel_stride_uv,
1473 uint8* dst_y, int dst_stride_y,
1474 uint8* dst_u, int dst_stride_u,
1475 uint8* dst_v, int dst_stride_v,
1476 int width, int height) {
1477 int y;
1478 int vu_off = src_v - src_u;
1479 int halfwidth = (width + 1) >> 1;
1480 int halfheight = (height + 1) >> 1;
1481 if (!src_y || !src_u || !src_v ||
1482 !dst_y || !dst_u || !dst_v ||
1483 width <= 0 || height == 0) {
1484 return -1;
1485 }
1486 // Negative height means invert the image.
1487 if (height < 0) {
1488 height = -height;
1489 halfheight = (height + 1) >> 1;
1490 src_y = src_y + (height - 1) * src_stride_y;
1491 src_u = src_u + (halfheight - 1) * src_stride_u;
1492 src_v = src_v + (halfheight - 1) * src_stride_v;
1493 src_stride_y = -src_stride_y;
1494 src_stride_u = -src_stride_u;
1495 src_stride_v = -src_stride_v;
1496 }
1497
1498 if (dst_y) {
1499 CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
1500 }
1501 // Copy UV planes as is - I420
1502 if (pixel_stride_uv == 1) {
1503 CopyPlane(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, halfheight);
1504 CopyPlane(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, halfheight);
1505 return 0;
1506 // Split UV planes - NV21
1507 } else if (pixel_stride_uv == 2 && vu_off == -1 &&
1508 src_stride_u == src_stride_v) {
1509 SplitPlane(src_v, src_stride_v, dst_v, dst_stride_v, dst_u, dst_stride_u,
1510 halfwidth, halfheight);
1511 return 0;
1512 // Split UV planes - NV12
1513 } else if (pixel_stride_uv == 2 && vu_off == 1 &&
1514 src_stride_u == src_stride_v) {
1515 SplitPlane(src_u, src_stride_u, dst_u, dst_stride_u, dst_v, dst_stride_v,
1516 halfwidth, halfheight);
1517 return 0;
1518 }
1519
1520 for (y = 0; y < halfheight; ++y) {
1521 SplitPixels(src_u, pixel_stride_uv, dst_u, halfwidth);
1522 SplitPixels(src_v, pixel_stride_uv, dst_v, halfwidth);
1523 src_u += src_stride_u;
1524 src_v += src_stride_v;
1525 }
1526 return 0;
1527 }
1528
1386 #ifdef __cplusplus 1529 #ifdef __cplusplus
1387 } // extern "C" 1530 } // extern "C"
1388 } // namespace libyuv 1531 } // namespace libyuv
1389 #endif 1532 #endif
OLDNEW
« no previous file with comments | « include/libyuv/convert.h ('k') | source/row_common.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698