1 /*
2  *  Copyright 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 INCLUDE_LIBYUV_CONVERT_H_
12 #define INCLUDE_LIBYUV_CONVERT_H_
13 
14 #include "libyuv/basic_types.h"
15 
16 #include "libyuv/rotate.h"  // For enum RotationMode.
17 
18 // TODO(fbarchard): fix WebRTC source to include following libyuv headers:
19 #include "libyuv/convert_argb.h"      // For WebRTC I420ToARGB. b/620
20 #include "libyuv/convert_from.h"      // For WebRTC ConvertFromI420. b/620
21 #include "libyuv/planar_functions.h"  // For WebRTC I420Rect, CopyPlane. b/618
22 
23 #ifdef __cplusplus
24 namespace libyuv {
25 extern "C" {
26 #endif
27 
28 // Convert I444 to I420.
29 LIBYUV_API
30 int I444ToI420(const uint8* src_y,
31                int src_stride_y,
32                const uint8* src_u,
33                int src_stride_u,
34                const uint8* src_v,
35                int src_stride_v,
36                uint8* dst_y,
37                int dst_stride_y,
38                uint8* dst_u,
39                int dst_stride_u,
40                uint8* dst_v,
41                int dst_stride_v,
42                int width,
43                int height);
44 
45 // Convert I422 to I420.
46 LIBYUV_API
47 int I422ToI420(const uint8* src_y,
48                int src_stride_y,
49                const uint8* src_u,
50                int src_stride_u,
51                const uint8* src_v,
52                int src_stride_v,
53                uint8* dst_y,
54                int dst_stride_y,
55                uint8* dst_u,
56                int dst_stride_u,
57                uint8* dst_v,
58                int dst_stride_v,
59                int width,
60                int height);
61 
62 // Copy I420 to I420.
63 #define I420ToI420 I420Copy
64 LIBYUV_API
65 int I420Copy(const uint8* src_y,
66              int src_stride_y,
67              const uint8* src_u,
68              int src_stride_u,
69              const uint8* src_v,
70              int src_stride_v,
71              uint8* dst_y,
72              int dst_stride_y,
73              uint8* dst_u,
74              int dst_stride_u,
75              uint8* dst_v,
76              int dst_stride_v,
77              int width,
78              int height);
79 
80 // Convert I400 (grey) to I420.
81 LIBYUV_API
82 int I400ToI420(const uint8* src_y,
83                int src_stride_y,
84                uint8* dst_y,
85                int dst_stride_y,
86                uint8* dst_u,
87                int dst_stride_u,
88                uint8* dst_v,
89                int dst_stride_v,
90                int width,
91                int height);
92 
93 #define J400ToJ420 I400ToI420
94 
95 // Convert NV12 to I420.
96 LIBYUV_API
97 int NV12ToI420(const uint8* src_y,
98                int src_stride_y,
99                const uint8* src_uv,
100                int src_stride_uv,
101                uint8* dst_y,
102                int dst_stride_y,
103                uint8* dst_u,
104                int dst_stride_u,
105                uint8* dst_v,
106                int dst_stride_v,
107                int width,
108                int height);
109 
110 // Convert NV21 to I420.
111 LIBYUV_API
112 int NV21ToI420(const uint8* src_y,
113                int src_stride_y,
114                const uint8* src_vu,
115                int src_stride_vu,
116                uint8* dst_y,
117                int dst_stride_y,
118                uint8* dst_u,
119                int dst_stride_u,
120                uint8* dst_v,
121                int dst_stride_v,
122                int width,
123                int height);
124 
125 // Convert YUY2 to I420.
126 LIBYUV_API
127 int YUY2ToI420(const uint8* src_yuy2,
128                int src_stride_yuy2,
129                uint8* dst_y,
130                int dst_stride_y,
131                uint8* dst_u,
132                int dst_stride_u,
133                uint8* dst_v,
134                int dst_stride_v,
135                int width,
136                int height);
137 
138 // Convert UYVY to I420.
139 LIBYUV_API
140 int UYVYToI420(const uint8* src_uyvy,
141                int src_stride_uyvy,
142                uint8* dst_y,
143                int dst_stride_y,
144                uint8* dst_u,
145                int dst_stride_u,
146                uint8* dst_v,
147                int dst_stride_v,
148                int width,
149                int height);
150 
151 // Convert M420 to I420.
152 LIBYUV_API
153 int M420ToI420(const uint8* src_m420,
154                int src_stride_m420,
155                uint8* dst_y,
156                int dst_stride_y,
157                uint8* dst_u,
158                int dst_stride_u,
159                uint8* dst_v,
160                int dst_stride_v,
161                int width,
162                int height);
163 
164 // Convert Android420 to I420.
165 LIBYUV_API
166 int Android420ToI420(const uint8* src_y,
167                      int src_stride_y,
168                      const uint8* src_u,
169                      int src_stride_u,
170                      const uint8* src_v,
171                      int src_stride_v,
172                      int pixel_stride_uv,
173                      uint8* dst_y,
174                      int dst_stride_y,
175                      uint8* dst_u,
176                      int dst_stride_u,
177                      uint8* dst_v,
178                      int dst_stride_v,
179                      int width,
180                      int height);
181 
182 // ARGB little endian (bgra in memory) to I420.
183 LIBYUV_API
184 int ARGBToI420(const uint8* src_frame,
185                int src_stride_frame,
186                uint8* dst_y,
187                int dst_stride_y,
188                uint8* dst_u,
189                int dst_stride_u,
190                uint8* dst_v,
191                int dst_stride_v,
192                int width,
193                int height);
194 
195 // BGRA little endian (argb in memory) to I420.
196 LIBYUV_API
197 int BGRAToI420(const uint8* src_frame,
198                int src_stride_frame,
199                uint8* dst_y,
200                int dst_stride_y,
201                uint8* dst_u,
202                int dst_stride_u,
203                uint8* dst_v,
204                int dst_stride_v,
205                int width,
206                int height);
207 
208 // ABGR little endian (rgba in memory) to I420.
209 LIBYUV_API
210 int ABGRToI420(const uint8* src_frame,
211                int src_stride_frame,
212                uint8* dst_y,
213                int dst_stride_y,
214                uint8* dst_u,
215                int dst_stride_u,
216                uint8* dst_v,
217                int dst_stride_v,
218                int width,
219                int height);
220 
221 // RGBA little endian (abgr in memory) to I420.
222 LIBYUV_API
223 int RGBAToI420(const uint8* src_frame,
224                int src_stride_frame,
225                uint8* dst_y,
226                int dst_stride_y,
227                uint8* dst_u,
228                int dst_stride_u,
229                uint8* dst_v,
230                int dst_stride_v,
231                int width,
232                int height);
233 
234 // RGB little endian (bgr in memory) to I420.
235 LIBYUV_API
236 int RGB24ToI420(const uint8* src_frame,
237                 int src_stride_frame,
238                 uint8* dst_y,
239                 int dst_stride_y,
240                 uint8* dst_u,
241                 int dst_stride_u,
242                 uint8* dst_v,
243                 int dst_stride_v,
244                 int width,
245                 int height);
246 
247 // RGB big endian (rgb in memory) to I420.
248 LIBYUV_API
249 int RAWToI420(const uint8* src_frame,
250               int src_stride_frame,
251               uint8* dst_y,
252               int dst_stride_y,
253               uint8* dst_u,
254               int dst_stride_u,
255               uint8* dst_v,
256               int dst_stride_v,
257               int width,
258               int height);
259 
260 // RGB16 (RGBP fourcc) little endian to I420.
261 LIBYUV_API
262 int RGB565ToI420(const uint8* src_frame,
263                  int src_stride_frame,
264                  uint8* dst_y,
265                  int dst_stride_y,
266                  uint8* dst_u,
267                  int dst_stride_u,
268                  uint8* dst_v,
269                  int dst_stride_v,
270                  int width,
271                  int height);
272 
273 // RGB15 (RGBO fourcc) little endian to I420.
274 LIBYUV_API
275 int ARGB1555ToI420(const uint8* src_frame,
276                    int src_stride_frame,
277                    uint8* dst_y,
278                    int dst_stride_y,
279                    uint8* dst_u,
280                    int dst_stride_u,
281                    uint8* dst_v,
282                    int dst_stride_v,
283                    int width,
284                    int height);
285 
286 // RGB12 (R444 fourcc) little endian to I420.
287 LIBYUV_API
288 int ARGB4444ToI420(const uint8* src_frame,
289                    int src_stride_frame,
290                    uint8* dst_y,
291                    int dst_stride_y,
292                    uint8* dst_u,
293                    int dst_stride_u,
294                    uint8* dst_v,
295                    int dst_stride_v,
296                    int width,
297                    int height);
298 
299 #ifdef HAVE_JPEG
300 // src_width/height provided by capture.
301 // dst_width/height for clipping determine final size.
302 LIBYUV_API
303 int MJPGToI420(const uint8* sample,
304                size_t sample_size,
305                uint8* dst_y,
306                int dst_stride_y,
307                uint8* dst_u,
308                int dst_stride_u,
309                uint8* dst_v,
310                int dst_stride_v,
311                int src_width,
312                int src_height,
313                int dst_width,
314                int dst_height);
315 
316 // Query size of MJPG in pixels.
317 LIBYUV_API
318 int MJPGSize(const uint8* sample, size_t sample_size, int* width, int* height);
319 #endif
320 
321 // Convert camera sample to I420 with cropping, rotation and vertical flip.
322 // "src_size" is needed to parse MJPG.
323 // "dst_stride_y" number of bytes in a row of the dst_y plane.
324 //   Normally this would be the same as dst_width, with recommended alignment
325 //   to 16 bytes for better efficiency.
326 //   If rotation of 90 or 270 is used, stride is affected. The caller should
327 //   allocate the I420 buffer according to rotation.
328 // "dst_stride_u" number of bytes in a row of the dst_u plane.
329 //   Normally this would be the same as (dst_width + 1) / 2, with
330 //   recommended alignment to 16 bytes for better efficiency.
331 //   If rotation of 90 or 270 is used, stride is affected.
332 // "crop_x" and "crop_y" are starting position for cropping.
333 //   To center, crop_x = (src_width - dst_width) / 2
334 //              crop_y = (src_height - dst_height) / 2
335 // "src_width" / "src_height" is size of src_frame in pixels.
336 //   "src_height" can be negative indicating a vertically flipped image source.
337 // "crop_width" / "crop_height" is the size to crop the src to.
338 //    Must be less than or equal to src_width/src_height
339 //    Cropping parameters are pre-rotation.
340 // "rotation" can be 0, 90, 180 or 270.
341 // "format" is a fourcc. ie 'I420', 'YUY2'
342 // Returns 0 for successful; -1 for invalid parameter. Non-zero for failure.
343 LIBYUV_API
344 int ConvertToI420(const uint8* src_frame,
345                   size_t src_size,
346                   uint8* dst_y,
347                   int dst_stride_y,
348                   uint8* dst_u,
349                   int dst_stride_u,
350                   uint8* dst_v,
351                   int dst_stride_v,
352                   int crop_x,
353                   int crop_y,
354                   int src_width,
355                   int src_height,
356                   int crop_width,
357                   int crop_height,
358                   enum RotationMode rotation,
359                   uint32 format);
360 
361 #ifdef __cplusplus
362 }  // extern "C"
363 }  // namespace libyuv
364 #endif
365 
366 #endif  // INCLUDE_LIBYUV_CONVERT_H_
367