OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2012 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 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 dst_stride_rgb24 = -dst_stride_rgb24; | 732 dst_stride_rgb24 = -dst_stride_rgb24; |
733 } | 733 } |
734 #if defined(HAS_I422TORGB24ROW_SSSE3) | 734 #if defined(HAS_I422TORGB24ROW_SSSE3) |
735 if (TestCpuFlag(kCpuHasSSSE3)) { | 735 if (TestCpuFlag(kCpuHasSSSE3)) { |
736 I422ToRGB24Row = I422ToRGB24Row_Any_SSSE3; | 736 I422ToRGB24Row = I422ToRGB24Row_Any_SSSE3; |
737 if (IS_ALIGNED(width, 8)) { | 737 if (IS_ALIGNED(width, 8)) { |
738 I422ToRGB24Row = I422ToRGB24Row_SSSE3; | 738 I422ToRGB24Row = I422ToRGB24Row_SSSE3; |
739 } | 739 } |
740 } | 740 } |
741 #endif | 741 #endif |
| 742 #if defined(HAS_I422TORGB24ROW_AVX2) |
| 743 if (TestCpuFlag(kCpuHasAVX2)) { |
| 744 I422ToRGB24Row = I422ToRGB24Row_Any_AVX2; |
| 745 if (IS_ALIGNED(width, 16)) { |
| 746 I422ToRGB24Row = I422ToRGB24Row_AVX2; |
| 747 } |
| 748 } |
| 749 #endif |
742 #if defined(HAS_I422TORGB24ROW_NEON) | 750 #if defined(HAS_I422TORGB24ROW_NEON) |
743 if (TestCpuFlag(kCpuHasNEON)) { | 751 if (TestCpuFlag(kCpuHasNEON)) { |
744 I422ToRGB24Row = I422ToRGB24Row_Any_NEON; | 752 I422ToRGB24Row = I422ToRGB24Row_Any_NEON; |
745 if (IS_ALIGNED(width, 8)) { | 753 if (IS_ALIGNED(width, 8)) { |
746 I422ToRGB24Row = I422ToRGB24Row_NEON; | 754 I422ToRGB24Row = I422ToRGB24Row_NEON; |
747 } | 755 } |
748 } | 756 } |
749 #endif | 757 #endif |
750 | 758 |
751 for (y = 0; y < height; ++y) { | 759 for (y = 0; y < height; ++y) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 dst_stride_raw = -dst_stride_raw; | 792 dst_stride_raw = -dst_stride_raw; |
785 } | 793 } |
786 #if defined(HAS_I422TORAWROW_SSSE3) | 794 #if defined(HAS_I422TORAWROW_SSSE3) |
787 if (TestCpuFlag(kCpuHasSSSE3)) { | 795 if (TestCpuFlag(kCpuHasSSSE3)) { |
788 I422ToRAWRow = I422ToRAWRow_Any_SSSE3; | 796 I422ToRAWRow = I422ToRAWRow_Any_SSSE3; |
789 if (IS_ALIGNED(width, 8)) { | 797 if (IS_ALIGNED(width, 8)) { |
790 I422ToRAWRow = I422ToRAWRow_SSSE3; | 798 I422ToRAWRow = I422ToRAWRow_SSSE3; |
791 } | 799 } |
792 } | 800 } |
793 #endif | 801 #endif |
| 802 #if defined(HAS_I422TORAWROW_AVX2) |
| 803 if (TestCpuFlag(kCpuHasAVX2)) { |
| 804 I422ToRAWRow = I422ToRAWRow_Any_AVX2; |
| 805 if (IS_ALIGNED(width, 16)) { |
| 806 I422ToRAWRow = I422ToRAWRow_AVX2; |
| 807 } |
| 808 } |
| 809 #endif |
794 #if defined(HAS_I422TORAWROW_NEON) | 810 #if defined(HAS_I422TORAWROW_NEON) |
795 if (TestCpuFlag(kCpuHasNEON)) { | 811 if (TestCpuFlag(kCpuHasNEON)) { |
796 I422ToRAWRow = I422ToRAWRow_Any_NEON; | 812 I422ToRAWRow = I422ToRAWRow_Any_NEON; |
797 if (IS_ALIGNED(width, 8)) { | 813 if (IS_ALIGNED(width, 8)) { |
798 I422ToRAWRow = I422ToRAWRow_NEON; | 814 I422ToRAWRow = I422ToRAWRow_NEON; |
799 } | 815 } |
800 } | 816 } |
801 #endif | 817 #endif |
802 | 818 |
803 for (y = 0; y < height; ++y) { | 819 for (y = 0; y < height; ++y) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 dst_rgb565 += dst_stride_rgb565; | 1002 dst_rgb565 += dst_stride_rgb565; |
987 src_y += src_stride_y; | 1003 src_y += src_stride_y; |
988 if (y & 1) { | 1004 if (y & 1) { |
989 src_u += src_stride_u; | 1005 src_u += src_stride_u; |
990 src_v += src_stride_v; | 1006 src_v += src_stride_v; |
991 } | 1007 } |
992 } | 1008 } |
993 return 0; | 1009 return 0; |
994 } | 1010 } |
995 | 1011 |
| 1012 // Ordered 8x8 dither for 888 to 565. Values from 0 to 7. |
| 1013 static const uint8 kDither565_4x4[16] = { |
| 1014 0, 4, 1, 5, |
| 1015 6, 2, 7, 3, |
| 1016 1, 5, 0, 4, |
| 1017 7, 3, 6, 2, |
| 1018 }; |
| 1019 |
| 1020 // Convert I420 to RGB565 with dithering. |
| 1021 LIBYUV_API |
| 1022 int I420ToRGB565Dither(const uint8* src_y, int src_stride_y, |
| 1023 const uint8* src_u, int src_stride_u, |
| 1024 const uint8* src_v, int src_stride_v, |
| 1025 uint8* dst_rgb565, int dst_stride_rgb565, |
| 1026 const uint8* dither4x4, int width, int height) { |
| 1027 int y; |
| 1028 void (*I422ToARGBRow)(const uint8* y_buf, |
| 1029 const uint8* u_buf, |
| 1030 const uint8* v_buf, |
| 1031 uint8* rgb_buf, |
| 1032 int width) = I422ToARGBRow_C; |
| 1033 void (*ARGBToRGB565DitherRow)(const uint8* src_argb, uint8* dst_rgb, |
| 1034 const uint32 dither4, int pix) = ARGBToRGB565DitherRow_C; |
| 1035 if (!src_y || !src_u || !src_v || !dst_rgb565 || |
| 1036 width <= 0 || height == 0) { |
| 1037 return -1; |
| 1038 } |
| 1039 // Negative height means invert the image. |
| 1040 if (height < 0) { |
| 1041 height = -height; |
| 1042 dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565; |
| 1043 dst_stride_rgb565 = -dst_stride_rgb565; |
| 1044 } |
| 1045 if (!dither4x4) { |
| 1046 dither4x4 = kDither565_4x4; |
| 1047 } |
| 1048 #if defined(HAS_I422TOARGBROW_SSSE3) |
| 1049 if (TestCpuFlag(kCpuHasSSSE3)) { |
| 1050 I422ToARGBRow = I422ToARGBRow_Any_SSSE3; |
| 1051 if (IS_ALIGNED(width, 8)) { |
| 1052 I422ToARGBRow = I422ToARGBRow_SSSE3; |
| 1053 } |
| 1054 } |
| 1055 #endif |
| 1056 #if defined(HAS_I422TOARGBROW_AVX2) |
| 1057 if (TestCpuFlag(kCpuHasAVX2)) { |
| 1058 I422ToARGBRow = I422ToARGBRow_Any_AVX2; |
| 1059 if (IS_ALIGNED(width, 16)) { |
| 1060 I422ToARGBRow = I422ToARGBRow_AVX2; |
| 1061 } |
| 1062 } |
| 1063 #endif |
| 1064 #if defined(HAS_I422TOARGBROW_NEON) |
| 1065 if (TestCpuFlag(kCpuHasNEON)) { |
| 1066 I422ToARGBRow = I422ToARGBRow_Any_NEON; |
| 1067 if (IS_ALIGNED(width, 8)) { |
| 1068 I422ToARGBRow = I422ToARGBRow_NEON; |
| 1069 } |
| 1070 } |
| 1071 #endif |
| 1072 #if defined(HAS_I422TOARGBROW_MIPS_DSPR2) |
| 1073 if (TestCpuFlag(kCpuHasMIPS_DSPR2) && IS_ALIGNED(width, 4) && |
| 1074 IS_ALIGNED(src_y, 4) && IS_ALIGNED(src_stride_y, 4) && |
| 1075 IS_ALIGNED(src_u, 2) && IS_ALIGNED(src_stride_u, 2) && |
| 1076 IS_ALIGNED(src_v, 2) && IS_ALIGNED(src_stride_v, 2)) { |
| 1077 I422ToARGBRow = I422ToARGBRow_MIPS_DSPR2; |
| 1078 } |
| 1079 #endif |
| 1080 #if defined(HAS_ARGBTORGB565DITHERROW_SSE2) |
| 1081 if (TestCpuFlag(kCpuHasSSE2)) { |
| 1082 ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_SSE2; |
| 1083 if (IS_ALIGNED(width, 4)) { |
| 1084 ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_SSE2; |
| 1085 } |
| 1086 } |
| 1087 #endif |
| 1088 #if defined(HAS_ARGBTORGB565DITHERROW_AVX2) |
| 1089 if (TestCpuFlag(kCpuHasAVX2)) { |
| 1090 ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_AVX2; |
| 1091 if (IS_ALIGNED(width, 8)) { |
| 1092 ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_AVX2; |
| 1093 } |
| 1094 } |
| 1095 #endif |
| 1096 #if defined(HAS_ARGBTORGB565DITHERROW_NEON) |
| 1097 if (TestCpuFlag(kCpuHasNEON)) { |
| 1098 ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_NEON; |
| 1099 if (IS_ALIGNED(width, 8)) { |
| 1100 ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_NEON; |
| 1101 } |
| 1102 } |
| 1103 #endif |
| 1104 { |
| 1105 // Allocate a row of argb. |
| 1106 align_buffer_64(row_argb, width * 4); |
| 1107 for (y = 0; y < height; ++y) { |
| 1108 I422ToARGBRow(src_y, src_u, src_v, row_argb, width); |
| 1109 ARGBToRGB565DitherRow(row_argb, dst_rgb565, |
| 1110 *(uint32*)(dither4x4 + ((y & 3) << 2)), width); |
| 1111 dst_rgb565 += dst_stride_rgb565; |
| 1112 src_y += src_stride_y; |
| 1113 if (y & 1) { |
| 1114 src_u += src_stride_u; |
| 1115 src_v += src_stride_v; |
| 1116 } |
| 1117 } |
| 1118 free_aligned_buffer_64(row_argb); |
| 1119 } |
| 1120 return 0; |
| 1121 } |
| 1122 |
996 // Convert I420 to specified format | 1123 // Convert I420 to specified format |
997 LIBYUV_API | 1124 LIBYUV_API |
998 int ConvertFromI420(const uint8* y, int y_stride, | 1125 int ConvertFromI420(const uint8* y, int y_stride, |
999 const uint8* u, int u_stride, | 1126 const uint8* u, int u_stride, |
1000 const uint8* v, int v_stride, | 1127 const uint8* v, int v_stride, |
1001 uint8* dst_sample, int dst_sample_stride, | 1128 uint8* dst_sample, int dst_sample_stride, |
1002 int width, int height, | 1129 int width, int height, |
1003 uint32 fourcc) { | 1130 uint32 fourcc) { |
1004 uint32 format = CanonicalFourCC(fourcc); | 1131 uint32 format = CanonicalFourCC(fourcc); |
1005 int r = 0; | 1132 int r = 0; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 default: | 1339 default: |
1213 return -1; // unknown fourcc - return failure code. | 1340 return -1; // unknown fourcc - return failure code. |
1214 } | 1341 } |
1215 return r; | 1342 return r; |
1216 } | 1343 } |
1217 | 1344 |
1218 #ifdef __cplusplus | 1345 #ifdef __cplusplus |
1219 } // extern "C" | 1346 } // extern "C" |
1220 } // namespace libyuv | 1347 } // namespace libyuv |
1221 #endif | 1348 #endif |
OLD | NEW |