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 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 UYVYToUV422Row(src_uyvy, dst_u, dst_v, width); | 581 UYVYToUV422Row(src_uyvy, dst_u, dst_v, width); |
582 UYVYToYRow(src_uyvy, dst_y, width); | 582 UYVYToYRow(src_uyvy, dst_y, width); |
583 src_uyvy += src_stride_uyvy; | 583 src_uyvy += src_stride_uyvy; |
584 dst_y += dst_stride_y; | 584 dst_y += dst_stride_y; |
585 dst_u += dst_stride_u; | 585 dst_u += dst_stride_u; |
586 dst_v += dst_stride_v; | 586 dst_v += dst_stride_v; |
587 } | 587 } |
588 return 0; | 588 return 0; |
589 } | 589 } |
590 | 590 |
| 591 // Convert YUY2 to Y. |
| 592 LIBYUV_API |
| 593 int YUY2ToY(const uint8* src_yuy2, int src_stride_yuy2, |
| 594 uint8* dst_y, int dst_stride_y, |
| 595 int width, int height) { |
| 596 int y; |
| 597 void (*YUY2ToYRow)(const uint8* src_yuy2, uint8* dst_y, int width) = |
| 598 YUY2ToYRow_C; |
| 599 if (!src_yuy2 || !dst_y || width <= 0 || height == 0) { |
| 600 return -1; |
| 601 } |
| 602 // Negative height means invert the image. |
| 603 if (height < 0) { |
| 604 height = -height; |
| 605 src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; |
| 606 src_stride_yuy2 = -src_stride_yuy2; |
| 607 } |
| 608 // Coalesce rows. |
| 609 if (src_stride_yuy2 == width * 2 && |
| 610 dst_stride_y == width) { |
| 611 width *= height; |
| 612 height = 1; |
| 613 src_stride_yuy2 = dst_stride_y = 0; |
| 614 } |
| 615 #if defined(HAS_YUY2TOYROW_SSE2) |
| 616 if (TestCpuFlag(kCpuHasSSE2)) { |
| 617 YUY2ToYRow = YUY2ToYRow_Any_SSE2; |
| 618 if (IS_ALIGNED(width, 16)) { |
| 619 YUY2ToYRow = YUY2ToYRow_SSE2; |
| 620 } |
| 621 } |
| 622 #endif |
| 623 #if defined(HAS_YUY2TOYROW_AVX2) |
| 624 if (TestCpuFlag(kCpuHasAVX2)) { |
| 625 YUY2ToYRow = YUY2ToYRow_Any_AVX2; |
| 626 if (IS_ALIGNED(width, 32)) { |
| 627 YUY2ToYRow = YUY2ToYRow_AVX2; |
| 628 } |
| 629 } |
| 630 #endif |
| 631 #if defined(HAS_YUY2TOYROW_NEON) |
| 632 if (TestCpuFlag(kCpuHasNEON)) { |
| 633 YUY2ToYRow = YUY2ToYRow_Any_NEON; |
| 634 if (IS_ALIGNED(width, 16)) { |
| 635 YUY2ToYRow = YUY2ToYRow_NEON; |
| 636 } |
| 637 } |
| 638 #endif |
| 639 #if defined(HAS_YUY2TOYROW_MSA) |
| 640 if (TestCpuFlag(kCpuHasMSA)) { |
| 641 YUY2ToYRow = YUY2ToYRow_Any_MSA; |
| 642 if (IS_ALIGNED(width, 32)) { |
| 643 YUY2ToYRow = YUY2ToYRow_MSA; |
| 644 } |
| 645 } |
| 646 #endif |
| 647 |
| 648 for (y = 0; y < height; ++y) { |
| 649 YUY2ToYRow(src_yuy2, dst_y, width); |
| 650 src_yuy2 += src_stride_yuy2; |
| 651 dst_y += dst_stride_y; |
| 652 } |
| 653 return 0; |
| 654 } |
| 655 |
591 // Mirror I400 with optional flipping | 656 // Mirror I400 with optional flipping |
592 LIBYUV_API | 657 LIBYUV_API |
593 int I400Mirror(const uint8* src_y, int src_stride_y, | 658 int I400Mirror(const uint8* src_y, int src_stride_y, |
594 uint8* dst_y, int dst_stride_y, | 659 uint8* dst_y, int dst_stride_y, |
595 int width, int height) { | 660 int width, int height) { |
596 if (!src_y || !dst_y || | 661 if (!src_y || !dst_y || |
597 width <= 0 || height == 0) { | 662 width <= 0 || height == 0) { |
598 return -1; | 663 return -1; |
599 } | 664 } |
600 // Negative height means invert the image. | 665 // Negative height means invert the image. |
(...skipping 2091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2692 #endif | 2757 #endif |
2693 | 2758 |
2694 for (y = 0; y < height; ++y) { | 2759 for (y = 0; y < height; ++y) { |
2695 ARGBCopyYToAlphaRow(src_y, dst_argb, width); | 2760 ARGBCopyYToAlphaRow(src_y, dst_argb, width); |
2696 src_y += src_stride_y; | 2761 src_y += src_stride_y; |
2697 dst_argb += dst_stride_argb; | 2762 dst_argb += dst_stride_argb; |
2698 } | 2763 } |
2699 return 0; | 2764 return 0; |
2700 } | 2765 } |
2701 | 2766 |
| 2767 |
2702 // TODO(fbarchard): Consider if width is even Y channel can be split | 2768 // TODO(fbarchard): Consider if width is even Y channel can be split |
2703 // directly. A SplitUVRow_Odd function could copy the remaining chroma. | 2769 // directly. A SplitUVRow_Odd function could copy the remaining chroma. |
2704 | 2770 |
2705 LIBYUV_API | 2771 LIBYUV_API |
2706 int YUY2ToNV12(const uint8* src_yuy2, int src_stride_yuy2, | 2772 int YUY2ToNV12(const uint8* src_yuy2, int src_stride_yuy2, |
2707 uint8* dst_y, int dst_stride_y, | 2773 uint8* dst_y, int dst_stride_y, |
2708 uint8* dst_uv, int dst_stride_uv, | 2774 uint8* dst_uv, int dst_stride_uv, |
2709 int width, int height) { | 2775 int width, int height) { |
2710 int y; | 2776 int y; |
2711 int halfwidth = (width + 1) >> 1; | 2777 int halfwidth = (width + 1) >> 1; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2895 } | 2961 } |
2896 free_aligned_buffer_64(rows); | 2962 free_aligned_buffer_64(rows); |
2897 } | 2963 } |
2898 return 0; | 2964 return 0; |
2899 } | 2965 } |
2900 | 2966 |
2901 #ifdef __cplusplus | 2967 #ifdef __cplusplus |
2902 } // extern "C" | 2968 } // extern "C" |
2903 } // namespace libyuv | 2969 } // namespace libyuv |
2904 #endif | 2970 #endif |
OLD | NEW |