OLD | NEW |
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 Loading... |
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) |
| 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 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1376 ARGBToYRow(row, dst_y, width); | 1445 ARGBToYRow(row, dst_y, width); |
1377 #endif | 1446 #endif |
1378 } | 1447 } |
1379 #if !defined(HAS_ARGB4444TOYROW_NEON) | 1448 #if !defined(HAS_ARGB4444TOYROW_NEON) |
1380 free_aligned_buffer_64(row); | 1449 free_aligned_buffer_64(row); |
1381 } | 1450 } |
1382 #endif | 1451 #endif |
1383 return 0; | 1452 return 0; |
1384 } | 1453 } |
1385 | 1454 |
| 1455 static void SplitPixels(const uint8* src_u, int src_pixel_stride_uv, |
| 1456 uint8* dst_u, int width) { |
| 1457 int i; |
| 1458 for (i = 0; i < width; ++i) { |
| 1459 *dst_u = *src_u; |
| 1460 ++dst_u; |
| 1461 src_u += src_pixel_stride_uv; |
| 1462 } |
| 1463 } |
| 1464 |
| 1465 // Convert Android420 to I420. |
| 1466 LIBYUV_API |
| 1467 int Android420ToI420(const uint8* src_y, int src_stride_y, |
| 1468 const uint8* src_u, int src_stride_u, |
| 1469 const uint8* src_v, int src_stride_v, |
| 1470 int src_pixel_stride_uv, |
| 1471 uint8* dst_y, int dst_stride_y, |
| 1472 uint8* dst_u, int dst_stride_u, |
| 1473 uint8* dst_v, int dst_stride_v, |
| 1474 int width, int height) { |
| 1475 int y; |
| 1476 const int vu_off = src_v - src_u; |
| 1477 int halfwidth = (width + 1) >> 1; |
| 1478 int halfheight = (height + 1) >> 1; |
| 1479 if (!src_y || !src_u || !src_v || |
| 1480 !dst_y || !dst_u || !dst_v || |
| 1481 width <= 0 || height == 0) { |
| 1482 return -1; |
| 1483 } |
| 1484 // Negative height means invert the image. |
| 1485 if (height < 0) { |
| 1486 height = -height; |
| 1487 halfheight = (height + 1) >> 1; |
| 1488 src_y = src_y + (height - 1) * src_stride_y; |
| 1489 src_u = src_u + (halfheight - 1) * src_stride_u; |
| 1490 src_v = src_v + (halfheight - 1) * src_stride_v; |
| 1491 src_stride_y = -src_stride_y; |
| 1492 src_stride_u = -src_stride_u; |
| 1493 src_stride_v = -src_stride_v; |
| 1494 } |
| 1495 |
| 1496 if (dst_y) { |
| 1497 CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); |
| 1498 } |
| 1499 |
| 1500 // Copy UV planes as is - I420 |
| 1501 if (src_pixel_stride_uv == 1) { |
| 1502 CopyPlane(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, halfheight); |
| 1503 CopyPlane(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, halfheight); |
| 1504 return 0; |
| 1505 // Split UV planes - NV21 |
| 1506 } else if (src_pixel_stride_uv == 2 && vu_off == -1 && |
| 1507 src_stride_u == src_stride_v) { |
| 1508 SplitPlane(src_v, src_stride_v, dst_v, dst_stride_v, dst_u, dst_stride_u, |
| 1509 halfwidth, halfheight); |
| 1510 return 0; |
| 1511 // Split UV planes - NV12 |
| 1512 } else if (src_pixel_stride_uv == 2 && vu_off == 1 && |
| 1513 src_stride_u == src_stride_v) { |
| 1514 SplitPlane(src_u, src_stride_u, dst_u, dst_stride_u, dst_v, dst_stride_v, |
| 1515 halfwidth, halfheight); |
| 1516 return 0; |
| 1517 } |
| 1518 |
| 1519 for (y = 0; y < halfheight; ++y) { |
| 1520 SplitPixels(src_u, src_pixel_stride_uv, dst_u, halfwidth); |
| 1521 SplitPixels(src_v, src_pixel_stride_uv, dst_v, halfwidth); |
| 1522 src_u += src_stride_u; |
| 1523 src_v += src_stride_v; |
| 1524 dst_u += dst_stride_u; |
| 1525 dst_v += dst_stride_v; |
| 1526 } |
| 1527 return 0; |
| 1528 } |
| 1529 |
1386 #ifdef __cplusplus | 1530 #ifdef __cplusplus |
1387 } // extern "C" | 1531 } // extern "C" |
1388 } // namespace libyuv | 1532 } // namespace libyuv |
1389 #endif | 1533 #endif |
OLD | NEW |