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