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_  // NOLINT
12#define INCLUDE_LIBYUV_CONVERT_H_
13
14#include "libyuv/basic_types.h"
15// TODO(fbarchard): Remove the following headers includes.
16#include "libyuv/convert_from.h"
17#include "libyuv/planar_functions.h"
18#include "libyuv/rotate.h"
19
20#ifdef __cplusplus
21namespace libyuv {
22extern "C" {
23#endif
24
25// Alias.
26#define I420ToI420 I420Copy
27
28// Copy I420 to I420.
29LIBYUV_API
30int I420Copy(const uint8* src_y, int src_stride_y,
31             const uint8* src_u, int src_stride_u,
32             const uint8* src_v, int src_stride_v,
33             uint8* dst_y, int dst_stride_y,
34             uint8* dst_u, int dst_stride_u,
35             uint8* dst_v, int dst_stride_v,
36             int width, int height);
37
38// Convert I422 to I420.
39LIBYUV_API
40int I422ToI420(const uint8* src_y, int src_stride_y,
41               const uint8* src_u, int src_stride_u,
42               const uint8* src_v, int src_stride_v,
43               uint8* dst_y, int dst_stride_y,
44               uint8* dst_u, int dst_stride_u,
45               uint8* dst_v, int dst_stride_v,
46               int width, int height);
47
48// Convert I444 to I420.
49LIBYUV_API
50int I444ToI420(const uint8* src_y, int src_stride_y,
51               const uint8* src_u, int src_stride_u,
52               const uint8* src_v, int src_stride_v,
53               uint8* dst_y, int dst_stride_y,
54               uint8* dst_u, int dst_stride_u,
55               uint8* dst_v, int dst_stride_v,
56               int width, int height);
57
58// Convert I411 to I420.
59LIBYUV_API
60int I411ToI420(const uint8* src_y, int src_stride_y,
61               const uint8* src_u, int src_stride_u,
62               const uint8* src_v, int src_stride_v,
63               uint8* dst_y, int dst_stride_y,
64               uint8* dst_u, int dst_stride_u,
65               uint8* dst_v, int dst_stride_v,
66               int width, int height);
67
68// Convert I400 (grey) to I420.
69LIBYUV_API
70int I400ToI420(const uint8* src_y, int src_stride_y,
71               uint8* dst_y, int dst_stride_y,
72               uint8* dst_u, int dst_stride_u,
73               uint8* dst_v, int dst_stride_v,
74               int width, int height);
75
76// Convert NV12 to I420. Also used for NV21.
77LIBYUV_API
78int NV12ToI420(const uint8* src_y, int src_stride_y,
79               const uint8* src_uv, int src_stride_uv,
80               uint8* dst_y, int dst_stride_y,
81               uint8* dst_u, int dst_stride_u,
82               uint8* dst_v, int dst_stride_v,
83               int width, int height);
84
85// Convert M420 to I420.
86LIBYUV_API
87int M420ToI420(const uint8* src_m420, int src_stride_m420,
88               uint8* dst_y, int dst_stride_y,
89               uint8* dst_u, int dst_stride_u,
90               uint8* dst_v, int dst_stride_v,
91               int width, int height);
92
93// Convert Q420 to I420.
94LIBYUV_API
95int Q420ToI420(const uint8* src_y, int src_stride_y,
96               const uint8* src_yuy2, int src_stride_yuy2,
97               uint8* dst_y, int dst_stride_y,
98               uint8* dst_u, int dst_stride_u,
99               uint8* dst_v, int dst_stride_v,
100               int width, int height);
101
102// Convert YUY2 to I420.
103LIBYUV_API
104int YUY2ToI420(const uint8* src_yuy2, int src_stride_yuy2,
105               uint8* dst_y, int dst_stride_y,
106               uint8* dst_u, int dst_stride_u,
107               uint8* dst_v, int dst_stride_v,
108               int width, int height);
109
110// Convert UYVY to I420.
111LIBYUV_API
112int UYVYToI420(const uint8* src_uyvy, int src_stride_uyvy,
113               uint8* dst_y, int dst_stride_y,
114               uint8* dst_u, int dst_stride_u,
115               uint8* dst_v, int dst_stride_v,
116               int width, int height);
117
118// Convert V210 to I420.
119LIBYUV_API
120int V210ToI420(const uint8* src_uyvy, int src_stride_uyvy,
121               uint8* dst_y, int dst_stride_y,
122               uint8* dst_u, int dst_stride_u,
123               uint8* dst_v, int dst_stride_v,
124               int width, int height);
125
126// ARGB little endian (bgra in memory) to I420.
127LIBYUV_API
128int ARGBToI420(const uint8* src_frame, int src_stride_frame,
129               uint8* dst_y, int dst_stride_y,
130               uint8* dst_u, int dst_stride_u,
131               uint8* dst_v, int dst_stride_v,
132               int width, int height);
133
134// BGRA little endian (argb in memory) to I420.
135LIBYUV_API
136int BGRAToI420(const uint8* src_frame, int src_stride_frame,
137               uint8* dst_y, int dst_stride_y,
138               uint8* dst_u, int dst_stride_u,
139               uint8* dst_v, int dst_stride_v,
140               int width, int height);
141
142// ABGR little endian (rgba in memory) to I420.
143LIBYUV_API
144int ABGRToI420(const uint8* src_frame, int src_stride_frame,
145               uint8* dst_y, int dst_stride_y,
146               uint8* dst_u, int dst_stride_u,
147               uint8* dst_v, int dst_stride_v,
148               int width, int height);
149
150// RGBA little endian (abgr in memory) to I420.
151LIBYUV_API
152int RGBAToI420(const uint8* src_frame, int src_stride_frame,
153               uint8* dst_y, int dst_stride_y,
154               uint8* dst_u, int dst_stride_u,
155               uint8* dst_v, int dst_stride_v,
156               int width, int height);
157
158// RGB little endian (bgr in memory) to I420.
159LIBYUV_API
160int RGB24ToI420(const uint8* src_frame, int src_stride_frame,
161                uint8* dst_y, int dst_stride_y,
162                uint8* dst_u, int dst_stride_u,
163                uint8* dst_v, int dst_stride_v,
164                int width, int height);
165
166// RGB big endian (rgb in memory) to I420.
167LIBYUV_API
168int RAWToI420(const uint8* src_frame, int src_stride_frame,
169              uint8* dst_y, int dst_stride_y,
170              uint8* dst_u, int dst_stride_u,
171              uint8* dst_v, int dst_stride_v,
172              int width, int height);
173
174// RGB16 (RGBP fourcc) little endian to I420.
175LIBYUV_API
176int RGB565ToI420(const uint8* src_frame, int src_stride_frame,
177                 uint8* dst_y, int dst_stride_y,
178                 uint8* dst_u, int dst_stride_u,
179                 uint8* dst_v, int dst_stride_v,
180                 int width, int height);
181
182// RGB15 (RGBO fourcc) little endian to I420.
183LIBYUV_API
184int ARGB1555ToI420(const uint8* src_frame, int src_stride_frame,
185                   uint8* dst_y, int dst_stride_y,
186                   uint8* dst_u, int dst_stride_u,
187                   uint8* dst_v, int dst_stride_v,
188                   int width, int height);
189
190// RGB12 (R444 fourcc) little endian to I420.
191LIBYUV_API
192int ARGB4444ToI420(const uint8* src_frame, int src_stride_frame,
193                   uint8* dst_y, int dst_stride_y,
194                   uint8* dst_u, int dst_stride_u,
195                   uint8* dst_v, int dst_stride_v,
196                   int width, int height);
197
198#ifdef HAVE_JPEG
199// src_width/height provided by capture.
200// dst_width/height for clipping determine final size.
201LIBYUV_API
202int MJPGToI420(const uint8* sample, size_t sample_size,
203               uint8* dst_y, int dst_stride_y,
204               uint8* dst_u, int dst_stride_u,
205               uint8* dst_v, int dst_stride_v,
206               int src_width, int src_height,
207               int dst_width, int dst_height);
208#endif
209
210// Note Bayer formats (BGGR) To I420 are in format_conversion.h
211
212// Convert camera sample to I420 with cropping, rotation and vertical flip.
213// "src_size" is needed to parse MJPG.
214// "dst_stride_y" number of bytes in a row of the dst_y plane.
215//   Normally this would be the same as dst_width, with recommended alignment
216//   to 16 bytes for better efficiency.
217//   If rotation of 90 or 270 is used, stride is affected. The caller should
218//   allocate the I420 buffer according to rotation.
219// "dst_stride_u" number of bytes in a row of the dst_u plane.
220//   Normally this would be the same as (dst_width + 1) / 2, with
221//   recommended alignment to 16 bytes for better efficiency.
222//   If rotation of 90 or 270 is used, stride is affected.
223// "crop_x" and "crop_y" are starting position for cropping.
224//   To center, crop_x = (src_width - dst_width) / 2
225//              crop_y = (src_height - dst_height) / 2
226// "src_width" / "src_height" is size of src_frame in pixels.
227//   "src_height" can be negative indicating a vertically flipped image source.
228// "dst_width" / "dst_height" is size of destination to crop to.
229//    Must be less than or equal to src_width/src_height
230//    Cropping parameters are pre-rotation.
231// "rotation" can be 0, 90, 180 or 270.
232// "format" is a fourcc. ie 'I420', 'YUY2'
233// Returns 0 for successful; -1 for invalid parameter. Non-zero for failure.
234LIBYUV_API
235int ConvertToI420(const uint8* src_frame, size_t src_size,
236                  uint8* dst_y, int dst_stride_y,
237                  uint8* dst_u, int dst_stride_u,
238                  uint8* dst_v, int dst_stride_v,
239                  int crop_x, int crop_y,
240                  int src_width, int src_height,
241                  int dst_width, int dst_height,
242                  RotationMode rotation,
243                  uint32 format);
244
245#ifdef __cplusplus
246}  // extern "C"
247}  // namespace libyuv
248#endif
249
250#endif  // INCLUDE_LIBYUV_CONVERT_H_  NOLINT
251