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