| 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 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 | 757 |
| 758 // Subtract plane | 758 // Subtract plane |
| 759 for (y = 0; y < height; ++y) { | 759 for (y = 0; y < height; ++y) { |
| 760 ARGBSubtractRow(src_argb0, src_argb1, dst_argb, width); | 760 ARGBSubtractRow(src_argb0, src_argb1, dst_argb, width); |
| 761 src_argb0 += src_stride_argb0; | 761 src_argb0 += src_stride_argb0; |
| 762 src_argb1 += src_stride_argb1; | 762 src_argb1 += src_stride_argb1; |
| 763 dst_argb += dst_stride_argb; | 763 dst_argb += dst_stride_argb; |
| 764 } | 764 } |
| 765 return 0; | 765 return 0; |
| 766 } | 766 } |
| 767 | 767 // Convert I422 to RGBA with matrix |
| 768 // Convert I422 to BGRA. | 768 static int I422ToRGBAMatrix(const uint8* src_y, int src_stride_y, |
| 769 LIBYUV_API | 769 const uint8* src_u, int src_stride_u, |
| 770 int I422ToBGRA(const uint8* src_y, int src_stride_y, | 770 const uint8* src_v, int src_stride_v, |
| 771 const uint8* src_u, int src_stride_u, | 771 uint8* dst_rgba, int dst_stride_rgba, |
| 772 const uint8* src_v, int src_stride_v, | 772 const struct YuvConstants* yuvconstants, |
| 773 uint8* dst_bgra, int dst_stride_bgra, | 773 int width, int height) { |
| 774 int width, int height) { | |
| 775 int y; | 774 int y; |
| 776 void (*I422ToBGRARow)(const uint8* y_buf, | 775 void (*I422ToRGBARow)(const uint8* y_buf, |
| 777 const uint8* u_buf, | 776 const uint8* u_buf, |
| 778 const uint8* v_buf, | 777 const uint8* v_buf, |
| 779 uint8* rgb_buf, | 778 uint8* rgb_buf, |
| 780 const struct YuvConstants* yuvconstants, | 779 const struct YuvConstants* yuvconstants, |
| 781 int width) = I422ToBGRARow_C; | 780 int width) = I422ToRGBARow_C; |
| 782 if (!src_y || !src_u || !src_v || | 781 if (!src_y || !src_u || !src_v || !dst_rgba || |
| 783 !dst_bgra || | |
| 784 width <= 0 || height == 0) { | 782 width <= 0 || height == 0) { |
| 785 return -1; | 783 return -1; |
| 786 } | 784 } |
| 787 // Negative height means invert the image. | 785 // Negative height means invert the image. |
| 788 if (height < 0) { | 786 if (height < 0) { |
| 789 height = -height; | 787 height = -height; |
| 790 dst_bgra = dst_bgra + (height - 1) * dst_stride_bgra; | 788 dst_rgba = dst_rgba + (height - 1) * dst_stride_rgba; |
| 791 dst_stride_bgra = -dst_stride_bgra; | 789 dst_stride_rgba = -dst_stride_rgba; |
| 792 } | 790 } |
| 793 // Coalesce rows. | 791 #if defined(HAS_I422TORGBAROW_SSSE3) |
| 794 if (src_stride_y == width && | |
| 795 src_stride_u * 2 == width && | |
| 796 src_stride_v * 2 == width && | |
| 797 dst_stride_bgra == width * 4) { | |
| 798 width *= height; | |
| 799 height = 1; | |
| 800 src_stride_y = src_stride_u = src_stride_v = dst_stride_bgra = 0; | |
| 801 } | |
| 802 #if defined(HAS_I422TOBGRAROW_SSSE3) | |
| 803 if (TestCpuFlag(kCpuHasSSSE3)) { | 792 if (TestCpuFlag(kCpuHasSSSE3)) { |
| 804 I422ToBGRARow = I422ToBGRARow_Any_SSSE3; | 793 I422ToRGBARow = I422ToRGBARow_Any_SSSE3; |
| 805 if (IS_ALIGNED(width, 8)) { | 794 if (IS_ALIGNED(width, 8)) { |
| 806 I422ToBGRARow = I422ToBGRARow_SSSE3; | 795 I422ToRGBARow = I422ToRGBARow_SSSE3; |
| 807 } | 796 } |
| 808 } | 797 } |
| 809 #endif | 798 #endif |
| 810 #if defined(HAS_I422TOBGRAROW_AVX2) | 799 #if defined(HAS_I422TORGBAROW_AVX2) |
| 811 if (TestCpuFlag(kCpuHasAVX2)) { | 800 if (TestCpuFlag(kCpuHasAVX2)) { |
| 812 I422ToBGRARow = I422ToBGRARow_Any_AVX2; | 801 I422ToRGBARow = I422ToRGBARow_Any_AVX2; |
| 813 if (IS_ALIGNED(width, 16)) { | 802 if (IS_ALIGNED(width, 16)) { |
| 814 I422ToBGRARow = I422ToBGRARow_AVX2; | 803 I422ToRGBARow = I422ToRGBARow_AVX2; |
| 815 } | 804 } |
| 816 } | 805 } |
| 817 #endif | 806 #endif |
| 818 #if defined(HAS_I422TOBGRAROW_NEON) | 807 #if defined(HAS_I422TORGBAROW_NEON) |
| 819 if (TestCpuFlag(kCpuHasNEON)) { | 808 if (TestCpuFlag(kCpuHasNEON)) { |
| 820 I422ToBGRARow = I422ToBGRARow_Any_NEON; | 809 I422ToRGBARow = I422ToRGBARow_Any_NEON; |
| 821 if (IS_ALIGNED(width, 8)) { | 810 if (IS_ALIGNED(width, 8)) { |
| 822 I422ToBGRARow = I422ToBGRARow_NEON; | 811 I422ToRGBARow = I422ToRGBARow_NEON; |
| 823 } | 812 } |
| 824 } | 813 } |
| 825 #endif | 814 #endif |
| 826 #if defined(HAS_I422TOBGRAROW_MIPS_DSPR2) | 815 #if defined(HAS_I422TORGBAROW_MIPS_DSPR2) |
| 827 if (TestCpuFlag(kCpuHasMIPS_DSPR2) && IS_ALIGNED(width, 4) && | 816 if (TestCpuFlag(kCpuHasMIPS_DSPR2) && IS_ALIGNED(width, 4) && |
| 828 IS_ALIGNED(src_y, 4) && IS_ALIGNED(src_stride_y, 4) && | 817 IS_ALIGNED(src_y, 4) && IS_ALIGNED(src_stride_y, 4) && |
| 829 IS_ALIGNED(src_u, 2) && IS_ALIGNED(src_stride_u, 2) && | 818 IS_ALIGNED(src_u, 2) && IS_ALIGNED(src_stride_u, 2) && |
| 830 IS_ALIGNED(src_v, 2) && IS_ALIGNED(src_stride_v, 2) && | 819 IS_ALIGNED(src_v, 2) && IS_ALIGNED(src_stride_v, 2) && |
| 831 IS_ALIGNED(dst_bgra, 4) && IS_ALIGNED(dst_stride_bgra, 4)) { | 820 IS_ALIGNED(dst_rgba, 4) && IS_ALIGNED(dst_stride_rgba, 4)) { |
| 832 I422ToBGRARow = I422ToBGRARow_MIPS_DSPR2; | 821 I422ToRGBARow = I422ToRGBARow_MIPS_DSPR2; |
| 833 } | 822 } |
| 834 #endif | 823 #endif |
| 835 | 824 |
| 836 for (y = 0; y < height; ++y) { | 825 for (y = 0; y < height; ++y) { |
| 837 I422ToBGRARow(src_y, src_u, src_v, dst_bgra, &kYuvIConstants, width); | 826 I422ToRGBARow(src_y, src_u, src_v, dst_rgba, yuvconstants, width); |
| 838 dst_bgra += dst_stride_bgra; | 827 dst_rgba += dst_stride_rgba; |
| 839 src_y += src_stride_y; | 828 src_y += src_stride_y; |
| 840 src_u += src_stride_u; | 829 src_u += src_stride_u; |
| 841 src_v += src_stride_v; | 830 src_v += src_stride_v; |
| 842 } | 831 } |
| 843 return 0; | 832 return 0; |
| 844 } | 833 } |
| 845 | 834 |
| 846 // Convert I422 to RGBA. | 835 // Convert I422 to RGBA. |
| 847 LIBYUV_API | 836 LIBYUV_API |
| 848 int I422ToRGBA(const uint8* src_y, int src_stride_y, | 837 int I422ToRGBA(const uint8* src_y, int src_stride_y, |
| 849 const uint8* src_u, int src_stride_u, | 838 const uint8* src_u, int src_stride_u, |
| 850 const uint8* src_v, int src_stride_v, | 839 const uint8* src_v, int src_stride_v, |
| 851 uint8* dst_rgba, int dst_stride_rgba, | 840 uint8* dst_rgba, int dst_stride_rgba, |
| 852 int width, int height) { | 841 int width, int height) { |
| 853 int y; | 842 return I422ToRGBAMatrix(src_y, src_stride_y, |
| 854 void (*I422ToRGBARow)(const uint8* y_buf, | 843 src_u, src_stride_u, |
| 855 const uint8* u_buf, | 844 src_v, src_stride_v, |
| 856 const uint8* v_buf, | 845 dst_rgba, dst_stride_rgba, |
| 857 uint8* rgb_buf, | 846 &kYuvIConstants, |
| 858 const struct YuvConstants* yuvconstants, | 847 width, height); |
| 859 int width) = I422ToRGBARow_C; | 848 } |
| 860 if (!src_y || !src_u || !src_v || | |
| 861 !dst_rgba || | |
| 862 width <= 0 || height == 0) { | |
| 863 return -1; | |
| 864 } | |
| 865 // Negative height means invert the image. | |
| 866 if (height < 0) { | |
| 867 height = -height; | |
| 868 dst_rgba = dst_rgba + (height - 1) * dst_stride_rgba; | |
| 869 dst_stride_rgba = -dst_stride_rgba; | |
| 870 } | |
| 871 // Coalesce rows. | |
| 872 if (src_stride_y == width && | |
| 873 src_stride_u * 2 == width && | |
| 874 src_stride_v * 2 == width && | |
| 875 dst_stride_rgba == width * 4) { | |
| 876 width *= height; | |
| 877 height = 1; | |
| 878 src_stride_y = src_stride_u = src_stride_v = dst_stride_rgba = 0; | |
| 879 } | |
| 880 #if defined(HAS_I422TORGBAROW_NEON) | |
| 881 if (TestCpuFlag(kCpuHasNEON) && width >= 8) { | |
| 882 I422ToRGBARow = I422ToRGBARow_Any_NEON; | |
| 883 if (IS_ALIGNED(width, 8)) { | |
| 884 I422ToRGBARow = I422ToRGBARow_NEON; | |
| 885 } | |
| 886 } | |
| 887 #endif | |
| 888 #if defined(HAS_I422TORGBAROW_SSSE3) | |
| 889 if (TestCpuFlag(kCpuHasSSSE3)) { | |
| 890 I422ToRGBARow = I422ToRGBARow_Any_SSSE3; | |
| 891 if (IS_ALIGNED(width, 8)) { | |
| 892 I422ToRGBARow = I422ToRGBARow_SSSE3; | |
| 893 } | |
| 894 } | |
| 895 #endif | |
| 896 #if defined(HAS_I422TORGBAROW_AVX2) | |
| 897 if (TestCpuFlag(kCpuHasAVX2)) { | |
| 898 I422ToRGBARow = I422ToRGBARow_Any_AVX2; | |
| 899 if (IS_ALIGNED(width, 16)) { | |
| 900 I422ToRGBARow = I422ToRGBARow_AVX2; | |
| 901 } | |
| 902 } | |
| 903 #endif | |
| 904 | 849 |
| 905 for (y = 0; y < height; ++y) { | 850 // Convert I422 to BGRA. |
| 906 I422ToRGBARow(src_y, src_u, src_v, dst_rgba, &kYuvIConstants, width); | 851 LIBYUV_API |
| 907 dst_rgba += dst_stride_rgba; | 852 int I422ToBGRA(const uint8* src_y, int src_stride_y, |
| 908 src_y += src_stride_y; | 853 const uint8* src_u, int src_stride_u, |
| 909 src_u += src_stride_u; | 854 const uint8* src_v, int src_stride_v, |
| 910 src_v += src_stride_v; | 855 uint8* dst_bgra, int dst_stride_bgra, |
| 911 } | 856 int width, int height) { |
| 912 return 0; | 857 return I422ToRGBAMatrix(src_y, src_stride_y, |
| 858 src_v, src_stride_v, // Swap U and V |
| 859 src_u, src_stride_u, |
| 860 dst_bgra, dst_stride_bgra, |
| 861 &kYvuIConstants, // Use Yvu matrix |
| 862 width, height); |
| 913 } | 863 } |
| 914 | 864 |
| 915 // Convert NV12 to RGB565. | 865 // Convert NV12 to RGB565. |
| 916 LIBYUV_API | 866 LIBYUV_API |
| 917 int NV12ToRGB565(const uint8* src_y, int src_stride_y, | 867 int NV12ToRGB565(const uint8* src_y, int src_stride_y, |
| 918 const uint8* src_uv, int src_stride_uv, | 868 const uint8* src_uv, int src_stride_uv, |
| 919 uint8* dst_rgb565, int dst_stride_rgb565, | 869 uint8* dst_rgb565, int dst_stride_rgb565, |
| 920 int width, int height) { | 870 int width, int height) { |
| 921 int y; | 871 int y; |
| 922 void (*NV12ToRGB565Row)(const uint8* y_buf, | 872 void (*NV12ToRGB565Row)(const uint8* y_buf, |
| (...skipping 1492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2415 } | 2365 } |
| 2416 free_aligned_buffer_64(rows); | 2366 free_aligned_buffer_64(rows); |
| 2417 } | 2367 } |
| 2418 return 0; | 2368 return 0; |
| 2419 } | 2369 } |
| 2420 | 2370 |
| 2421 #ifdef __cplusplus | 2371 #ifdef __cplusplus |
| 2422 } // extern "C" | 2372 } // extern "C" |
| 2423 } // namespace libyuv | 2373 } // namespace libyuv |
| 2424 #endif | 2374 #endif |
| OLD | NEW |