1 /*
2  *  Copyright (c) 2011 The LibYuv project authors. All Rights Reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef LIBYUV_SOURCE_ROW_H_
12 #define LIBYUV_SOURCE_ROW_H_
13 
14 #include "third_party/libyuv/include/libyuv/basic_types.h"
15 
16 #define kMaxStride (2048 * 4)
17 #define IS_ALIGNED(p, a) (!((uintptr_t)(p) & ((a) - 1)))
18 
19 #if defined(COVERAGE_ENABLED) || defined(TARGET_IPHONE_SIMULATOR)
20 #define YUV_DISABLE_ASM
21 #endif
22 
23 #if defined(__ARM_NEON__) && !defined(YUV_DISABLE_ASM)
24 #define HAS_FASTCONVERTYUVTOARGBROW_NEON
25 void FastConvertYUVToARGBRow_NEON(const uint8* y_buf,
26                                   const uint8* u_buf,
27                                   const uint8* v_buf,
28                                   uint8* rgb_buf,
29                                   int width);
30 #define HAS_FASTCONVERTYUVTOBGRAROW_NEON
31 void FastConvertYUVToBGRARow_NEON(const uint8* y_buf,
32                                   const uint8* u_buf,
33                                   const uint8* v_buf,
34                                   uint8* rgb_buf,
35                                   int width);
36 #define HAS_FASTCONVERTYUVTOABGRROW_NEON
37 void FastConvertYUVToABGRRow_NEON(const uint8* y_buf,
38                                   const uint8* u_buf,
39                                   const uint8* v_buf,
40                                   uint8* rgb_buf,
41                                   int width);
42 #endif
43 
44 // The following are available on all x86 platforms
45 #if (defined(_M_IX86) || defined(__x86_64__) || defined(__i386__)) && \
46     !defined(YUV_DISABLE_ASM)
47 #define HAS_ABGRTOARGBROW_SSSE3
48 #define HAS_BGRATOARGBROW_SSSE3
49 #define HAS_BG24TOARGBROW_SSSE3
50 #define HAS_RAWTOARGBROW_SSSE3
51 #define HAS_RGB24TOYROW_SSSE3
52 #define HAS_RAWTOYROW_SSSE3
53 #define HAS_RGB24TOUVROW_SSSE3
54 #define HAS_RAWTOUVROW_SSSE3
55 #define HAS_ARGBTOYROW_SSSE3
56 #define HAS_BGRATOYROW_SSSE3
57 #define HAS_ABGRTOYROW_SSSE3
58 #define HAS_ARGBTOUVROW_SSSE3
59 #define HAS_BGRATOUVROW_SSSE3
60 #define HAS_ABGRTOUVROW_SSSE3
61 #define HAS_I400TOARGBROW_SSE2
62 #define HAS_FASTCONVERTYTOARGBROW_SSE2
63 #define HAS_FASTCONVERTYUVTOARGBROW_SSSE3
64 #define HAS_FASTCONVERTYUVTOBGRAROW_SSSE3
65 #define HAS_FASTCONVERTYUVTOABGRROW_SSSE3
66 #define HAS_FASTCONVERTYUV444TOARGBROW_SSSE3
67 #define HAS_REVERSE_ROW_SSSE3
68 #endif
69 
70 // The following are available on Neon platforms
71 #if defined(__ARM_NEON__) && !defined(YUV_DISABLE_ASM)
72 #define HAS_REVERSE_ROW_NEON
73 #endif
74 
75 #ifdef __cplusplus
76 namespace libyuv {
77 extern "C" {
78 #endif
79 
80 #ifdef HAS_ARGBTOYROW_SSSE3
81 void ARGBToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
82 void BGRAToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
83 void ABGRToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
84 void ARGBToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb,
85                        uint8* dst_u, uint8* dst_v, int width);
86 void BGRAToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb,
87                        uint8* dst_u, uint8* dst_v, int width);
88 void ABGRToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb,
89                        uint8* dst_u, uint8* dst_v, int width);
90 #endif
91 #if defined(HAS_BG24TOARGBROW_SSSE3) && defined(HAS_ARGBTOYROW_SSSE3)
92 #define HASRGB24TOYROW_SSSE3
93 #endif
94 #ifdef HASRGB24TOYROW_SSSE3
95 void RGB24ToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
96 void RAWToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
97 void RGB24ToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb,
98                         uint8* dst_u, uint8* dst_v, int width);
99 void RAWToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb,
100                       uint8* dst_u, uint8* dst_v, int width);
101 #endif
102 #ifdef HAS_REVERSE_ROW_SSSE3
103 void ReverseRow_SSSE3(const uint8* src, uint8* dst, int width);
104 #endif
105 #ifdef HAS_REVERSE_ROW_NEON
106 void ReverseRow_NEON(const uint8* src, uint8* dst, int width);
107 #endif
108 void ReverseRow_C(const uint8* src, uint8* dst, int width);
109 
110 void ARGBToYRow_C(const uint8* src_argb, uint8* dst_y, int pix);
111 void BGRAToYRow_C(const uint8* src_argb, uint8* dst_y, int pix);
112 void ABGRToYRow_C(const uint8* src_argb, uint8* dst_y, int pix);
113 void RGB24ToYRow_C(const uint8* src_argb, uint8* dst_y, int pix);
114 void RAWToYRow_C(const uint8* src_argb, uint8* dst_y, int pix);
115 void ARGBToUVRow_C(const uint8* src_argb0, int src_stride_argb,
116                    uint8* dst_u, uint8* dst_v, int width);
117 void BGRAToUVRow_C(const uint8* src_argb0, int src_stride_argb,
118                    uint8* dst_u, uint8* dst_v, int width);
119 void ABGRToUVRow_C(const uint8* src_argb0, int src_stride_argb,
120                    uint8* dst_u, uint8* dst_v, int width);
121 void RGB24ToUVRow_C(const uint8* src_argb0, int src_stride_argb,
122                     uint8* dst_u, uint8* dst_v, int width);
123 void RAWToUVRow_C(const uint8* src_argb0, int src_stride_argb,
124                   uint8* dst_u, uint8* dst_v, int width);
125 
126 #ifdef HAS_BG24TOARGBROW_SSSE3
127 void ABGRToARGBRow_SSSE3(const uint8* src_abgr, uint8* dst_argb, int pix);
128 void BGRAToARGBRow_SSSE3(const uint8* src_bgra, uint8* dst_argb, int pix);
129 void BG24ToARGBRow_SSSE3(const uint8* src_bg24, uint8* dst_argb, int pix);
130 void RAWToARGBRow_SSSE3(const uint8* src_bg24, uint8* dst_argb, int pix);
131 #endif
132 void ABGRToARGBRow_C(const uint8* src_abgr, uint8* dst_argb, int pix);
133 void BGRAToARGBRow_C(const uint8* src_bgra, uint8* dst_argb, int pix);
134 void BG24ToARGBRow_C(const uint8* src_bg24, uint8* dst_argb, int pix);
135 void RAWToARGBRow_C(const uint8* src_bg24, uint8* dst_argb, int pix);
136 
137 #ifdef HAS_I400TOARGBROW_SSE2
138 void I400ToARGBRow_SSE2(const uint8* src_y, uint8* dst_argb, int pix);
139 #endif
140 void I400ToARGBRow_C(const uint8* src_y, uint8* dst_argb, int pix);
141 
142 #if defined(_MSC_VER)
143 #define SIMD_ALIGNED(var) __declspec(align(16)) var
144 typedef __declspec(align(16)) signed char vec8[16];
145 typedef __declspec(align(16)) unsigned char uvec8[16];
146 typedef __declspec(align(16)) signed short vec16[8];
147 #else // __GNUC__
148 #define SIMD_ALIGNED(var) var __attribute__((aligned(16)))
149 typedef signed char __attribute__((vector_size(16))) vec8;
150 typedef unsigned char __attribute__((vector_size(16))) uvec8;
151 typedef signed short __attribute__((vector_size(16))) vec16;
152 #endif
153 
154 //extern "C"
155 SIMD_ALIGNED(const int16 kCoefficientsRgbY[768][4]);
156 //extern "C"
157 SIMD_ALIGNED(const int16 kCoefficientsBgraY[768][4]);
158 //extern "C"
159 SIMD_ALIGNED(const int16 kCoefficientsAbgrY[768][4]);
160 
161 void FastConvertYUVToARGBRow_C(const uint8* y_buf,
162                                const uint8* u_buf,
163                                const uint8* v_buf,
164                                uint8* rgb_buf,
165                                int width);
166 
167 void FastConvertYUVToBGRARow_C(const uint8* y_buf,
168                                const uint8* u_buf,
169                                const uint8* v_buf,
170                                uint8* rgb_buf,
171                                int width);
172 
173 void FastConvertYUVToABGRRow_C(const uint8* y_buf,
174                                const uint8* u_buf,
175                                const uint8* v_buf,
176                                uint8* rgb_buf,
177                                int width);
178 
179 void FastConvertYUV444ToARGBRow_C(const uint8* y_buf,
180                                   const uint8* u_buf,
181                                   const uint8* v_buf,
182                                   uint8* rgb_buf,
183                                   int width);
184 
185 void FastConvertYToARGBRow_C(const uint8* y_buf,
186                              uint8* rgb_buf,
187                              int width);
188 
189 #ifdef HAS_FASTCONVERTYUVTOARGBROW_SSE2
190 void FastConvertYUVToARGBRow_SSE2(const uint8* y_buf,
191                                   const uint8* u_buf,
192                                   const uint8* v_buf,
193                                   uint8* rgb_buf,
194                                   int width);
195 
196 void FastConvertYUVToARGBRow4_SSE2(const uint8* y_buf,
197                                    const uint8* u_buf,
198                                    const uint8* v_buf,
199                                    uint8* rgb_buf,
200                                    int width);
201 
202 void FastConvertYUVToBGRARow_SSE2(const uint8* y_buf,
203                                   const uint8* u_buf,
204                                   const uint8* v_buf,
205                                   uint8* rgb_buf,
206                                   int width);
207 
208 void FastConvertYUVToABGRRow_SSE2(const uint8* y_buf,
209                                   const uint8* u_buf,
210                                   const uint8* v_buf,
211                                   uint8* rgb_buf,
212                                   int width);
213 
214 void FastConvertYUV444ToARGBRow_SSE2(const uint8* y_buf,
215                                      const uint8* u_buf,
216                                      const uint8* v_buf,
217                                      uint8* rgb_buf,
218                                      int width);
219 
220 void FastConvertYToARGBRow_SSE2(const uint8* y_buf,
221                                 uint8* rgb_buf,
222                                 int width);
223 #endif
224 
225 #ifdef HAS_FASTCONVERTYUVTOARGBROW_SSSE3
226 void FastConvertYUVToARGBRow_SSSE3(const uint8* y_buf,
227                                    const uint8* u_buf,
228                                    const uint8* v_buf,
229                                    uint8* rgb_buf,
230                                    int width);
231 
232 void FastConvertYUVToBGRARow_SSSE3(const uint8* y_buf,
233                                    const uint8* u_buf,
234                                    const uint8* v_buf,
235                                    uint8* rgb_buf,
236                                    int width);
237 
238 void FastConvertYUVToABGRRow_SSSE3(const uint8* y_buf,
239                                    const uint8* u_buf,
240                                    const uint8* v_buf,
241                                    uint8* rgb_buf,
242                                    int width);
243 
244 void FastConvertYUV444ToARGBRow_SSSE3(const uint8* y_buf,
245                                       const uint8* u_buf,
246                                       const uint8* v_buf,
247                                       uint8* rgb_buf,
248                                       int width);
249 
250 #endif
251 
252 #ifdef HAS_FASTCONVERTYTOARGBROW_SSE2
253 void FastConvertYToARGBRow_SSE2(const uint8* y_buf,
254                                 uint8* rgb_buf,
255                                 int width);
256 
257 #endif
258 
259 #ifdef __cplusplus
260 }  // extern "C"
261 }  // namespace libyuv
262 #endif
263 
264 #endif  // LIBYUV_SOURCE_ROW_H_
265