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 // 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, 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.
39 LIBYUV_API
40 int 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 I411 to I420.
49 LIBYUV_API
50 int I411ToI420(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 // Copy I420 to I420.
59 #define I420ToI420 I420Copy
60 LIBYUV_API
61 int I420Copy(const uint8* src_y, int src_stride_y,
62              const uint8* src_u, int src_stride_u,
63              const uint8* src_v, int src_stride_v,
64              uint8* dst_y, int dst_stride_y,
65              uint8* dst_u, int dst_stride_u,
66              uint8* dst_v, int dst_stride_v,
67              int width, int height);
68 
69 // Convert I400 (grey) to I420.
70 LIBYUV_API
71 int I400ToI420(const uint8* src_y, int src_stride_y,
72                uint8* dst_y, int dst_stride_y,
73                uint8* dst_u, int dst_stride_u,
74                uint8* dst_v, int dst_stride_v,
75                int width, int height);
76 
77 #define J400ToJ420 I400ToI420
78 
79 // Convert NV12 to I420.
80 LIBYUV_API
81 int NV12ToI420(const uint8* src_y, int src_stride_y,
82                const uint8* src_uv, int src_stride_uv,
83                uint8* dst_y, int dst_stride_y,
84                uint8* dst_u, int dst_stride_u,
85                uint8* dst_v, int dst_stride_v,
86                int width, int height);
87 
88 // Convert NV21 to I420.
89 LIBYUV_API
90 int NV21ToI420(const uint8* src_y, int src_stride_y,
91                const uint8* src_vu, int src_stride_vu,
92                uint8* dst_y, int dst_stride_y,
93                uint8* dst_u, int dst_stride_u,
94                uint8* dst_v, int dst_stride_v,
95                int width, int height);
96 
97 // Convert YUY2 to I420.
98 LIBYUV_API
99 int YUY2ToI420(const uint8* src_yuy2, int src_stride_yuy2,
100                uint8* dst_y, int dst_stride_y,
101                uint8* dst_u, int dst_stride_u,
102                uint8* dst_v, int dst_stride_v,
103                int width, int height);
104 
105 // Convert UYVY to I420.
106 LIBYUV_API
107 int UYVYToI420(const uint8* src_uyvy, int src_stride_uyvy,
108                uint8* dst_y, int dst_stride_y,
109                uint8* dst_u, int dst_stride_u,
110                uint8* dst_v, int dst_stride_v,
111                int width, int height);
112 
113 // Convert M420 to I420.
114 LIBYUV_API
115 int M420ToI420(const uint8* src_m420, int src_stride_m420,
116                uint8* dst_y, int dst_stride_y,
117                uint8* dst_u, int dst_stride_u,
118                uint8* dst_v, int dst_stride_v,
119                int width, int height);
120 
121 // Convert Android420 to I420.
122 LIBYUV_API
123 int Android420ToI420(const uint8* src_y, int src_stride_y,
124                      const uint8* src_u, int src_stride_u,
125                      const uint8* src_v, int src_stride_v,
126                      int pixel_stride_uv,
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 // ARGB little endian (bgra in memory) to I420.
133 LIBYUV_API
134 int ARGBToI420(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 // BGRA little endian (argb in memory) to I420.
141 LIBYUV_API
142 int BGRAToI420(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 // ABGR little endian (rgba in memory) to I420.
149 LIBYUV_API
150 int ABGRToI420(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 // RGBA little endian (abgr in memory) to I420.
157 LIBYUV_API
158 int RGBAToI420(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 // RGB little endian (bgr in memory) to I420.
165 LIBYUV_API
166 int RGB24ToI420(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 // RGB big endian (rgb in memory) to I420.
173 LIBYUV_API
174 int RAWToI420(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 // RGB16 (RGBP fourcc) little endian to I420.
181 LIBYUV_API
182 int RGB565ToI420(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 // RGB15 (RGBO fourcc) little endian to I420.
189 LIBYUV_API
190 int ARGB1555ToI420(const uint8* src_frame, int src_stride_frame,
191                    uint8* dst_y, int dst_stride_y,
192                    uint8* dst_u, int dst_stride_u,
193                    uint8* dst_v, int dst_stride_v,
194                    int width, int height);
195 
196 // RGB12 (R444 fourcc) little endian to I420.
197 LIBYUV_API
198 int ARGB4444ToI420(const uint8* src_frame, int src_stride_frame,
199                    uint8* dst_y, int dst_stride_y,
200                    uint8* dst_u, int dst_stride_u,
201                    uint8* dst_v, int dst_stride_v,
202                    int width, int height);
203 
204 #ifdef HAVE_JPEG
205 // src_width/height provided by capture.
206 // dst_width/height for clipping determine final size.
207 LIBYUV_API
208 int MJPGToI420(const uint8* sample, size_t sample_size,
209                uint8* dst_y, int dst_stride_y,
210                uint8* dst_u, int dst_stride_u,
211                uint8* dst_v, int dst_stride_v,
212                int src_width, int src_height,
213                int dst_width, int dst_height);
214 
215 // Query size of MJPG in pixels.
216 LIBYUV_API
217 int MJPGSize(const uint8* sample, size_t sample_size,
218              int* width, int* height);
219 #endif
220 
221 // Convert camera sample to I420 with cropping, rotation and vertical flip.
222 // "src_size" is needed to parse MJPG.
223 // "dst_stride_y" number of bytes in a row of the dst_y plane.
224 //   Normally this would be the same as dst_width, with recommended alignment
225 //   to 16 bytes for better efficiency.
226 //   If rotation of 90 or 270 is used, stride is affected. The caller should
227 //   allocate the I420 buffer according to rotation.
228 // "dst_stride_u" number of bytes in a row of the dst_u plane.
229 //   Normally this would be the same as (dst_width + 1) / 2, with
230 //   recommended alignment to 16 bytes for better efficiency.
231 //   If rotation of 90 or 270 is used, stride is affected.
232 // "crop_x" and "crop_y" are starting position for cropping.
233 //   To center, crop_x = (src_width - dst_width) / 2
234 //              crop_y = (src_height - dst_height) / 2
235 // "src_width" / "src_height" is size of src_frame in pixels.
236 //   "src_height" can be negative indicating a vertically flipped image source.
237 // "crop_width" / "crop_height" is the size to crop the src to.
238 //    Must be less than or equal to src_width/src_height
239 //    Cropping parameters are pre-rotation.
240 // "rotation" can be 0, 90, 180 or 270.
241 // "format" is a fourcc. ie 'I420', 'YUY2'
242 // Returns 0 for successful; -1 for invalid parameter. Non-zero for failure.
243 LIBYUV_API
244 int ConvertToI420(const uint8* src_frame, size_t src_size,
245                   uint8* dst_y, int dst_stride_y,
246                   uint8* dst_u, int dst_stride_u,
247                   uint8* dst_v, int dst_stride_v,
248                   int crop_x, int crop_y,
249                   int src_width, int src_height,
250                   int crop_width, int crop_height,
251                   enum RotationMode rotation,
252                   uint32 format);
253 
254 #ifdef __cplusplus
255 }  // extern "C"
256 }  // namespace libyuv
257 #endif
258 
259 #endif  // INCLUDE_LIBYUV_CONVERT_H_  NOLINT
260