• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
21 namespace libyuv {
22 extern "C" {
23 #endif
24 
25 // Convert I444 to I420.
26 LIBYUV_API
27 int I444ToI420(const uint8* src_y, int src_stride_y,
28                const uint8* src_u, int src_stride_u,
29                const uint8* src_v, int src_stride_v,
30                uint8* dst_y, int dst_stride_y,
31                uint8* dst_u, int dst_stride_u,
32                uint8* dst_v, int dst_stride_v,
33                int width, int height);
34 
35 // Convert I422 to I420.
36 LIBYUV_API
37 int I422ToI420(const uint8* src_y, int src_stride_y,
38                const uint8* src_u, int src_stride_u,
39                const uint8* src_v, int src_stride_v,
40                uint8* dst_y, int dst_stride_y,
41                uint8* dst_u, int dst_stride_u,
42                uint8* dst_v, int dst_stride_v,
43                int width, int height);
44 
45 // Convert I411 to I420.
46 LIBYUV_API
47 int I411ToI420(const uint8* src_y, int src_stride_y,
48                const uint8* src_u, int src_stride_u,
49                const uint8* src_v, int src_stride_v,
50                uint8* dst_y, int dst_stride_y,
51                uint8* dst_u, int dst_stride_u,
52                uint8* dst_v, int dst_stride_v,
53                int width, int height);
54 
55 // Copy I420 to I420.
56 #define I420ToI420 I420Copy
57 LIBYUV_API
58 int I420Copy(const uint8* src_y, int src_stride_y,
59              const uint8* src_u, int src_stride_u,
60              const uint8* src_v, int src_stride_v,
61              uint8* dst_y, int dst_stride_y,
62              uint8* dst_u, int dst_stride_u,
63              uint8* dst_v, int dst_stride_v,
64              int width, int height);
65 
66 // Convert I400 (grey) to I420.
67 LIBYUV_API
68 int I400ToI420(const uint8* src_y, int src_stride_y,
69                uint8* dst_y, int dst_stride_y,
70                uint8* dst_u, int dst_stride_u,
71                uint8* dst_v, int dst_stride_v,
72                int width, int height);
73 
74 #define J400ToJ420 I400ToI420
75 
76 // Convert NV12 to I420.
77 LIBYUV_API
78 int 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 NV21 to I420.
86 LIBYUV_API
87 int NV21ToI420(const uint8* src_y, int src_stride_y,
88                const uint8* src_vu, int src_stride_vu,
89                uint8* dst_y, int dst_stride_y,
90                uint8* dst_u, int dst_stride_u,
91                uint8* dst_v, int dst_stride_v,
92                int width, int height);
93 
94 // Convert YUY2 to I420.
95 LIBYUV_API
96 int YUY2ToI420(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 UYVY to I420.
103 LIBYUV_API
104 int UYVYToI420(const uint8* src_uyvy, int src_stride_uyvy,
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 M420 to I420.
111 LIBYUV_API
112 int M420ToI420(const uint8* src_m420, int src_stride_m420,
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 // ARGB little endian (bgra in memory) to I420.
119 LIBYUV_API
120 int ARGBToI420(const uint8* src_frame, int src_stride_frame,
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 // BGRA little endian (argb in memory) to I420.
127 LIBYUV_API
128 int BGRAToI420(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 // ABGR little endian (rgba in memory) to I420.
135 LIBYUV_API
136 int ABGRToI420(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 // RGBA little endian (abgr in memory) to I420.
143 LIBYUV_API
144 int RGBAToI420(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 // RGB little endian (bgr in memory) to I420.
151 LIBYUV_API
152 int RGB24ToI420(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 big endian (rgb in memory) to I420.
159 LIBYUV_API
160 int RAWToI420(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 // RGB16 (RGBP fourcc) little endian to I420.
167 LIBYUV_API
168 int RGB565ToI420(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 // RGB15 (RGBO fourcc) little endian to I420.
175 LIBYUV_API
176 int ARGB1555ToI420(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 // RGB12 (R444 fourcc) little endian to I420.
183 LIBYUV_API
184 int ARGB4444ToI420(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 #ifdef HAVE_JPEG
191 // src_width/height provided by capture.
192 // dst_width/height for clipping determine final size.
193 LIBYUV_API
194 int MJPGToI420(const uint8* sample, size_t sample_size,
195                uint8* dst_y, int dst_stride_y,
196                uint8* dst_u, int dst_stride_u,
197                uint8* dst_v, int dst_stride_v,
198                int src_width, int src_height,
199                int dst_width, int dst_height);
200 
201 // Query size of MJPG in pixels.
202 LIBYUV_API
203 int MJPGSize(const uint8* sample, size_t sample_size,
204              int* width, int* height);
205 #endif
206 
207 // Convert camera sample to I420 with cropping, rotation and vertical flip.
208 // "src_size" is needed to parse MJPG.
209 // "dst_stride_y" number of bytes in a row of the dst_y plane.
210 //   Normally this would be the same as dst_width, with recommended alignment
211 //   to 16 bytes for better efficiency.
212 //   If rotation of 90 or 270 is used, stride is affected. The caller should
213 //   allocate the I420 buffer according to rotation.
214 // "dst_stride_u" number of bytes in a row of the dst_u plane.
215 //   Normally this would be the same as (dst_width + 1) / 2, with
216 //   recommended alignment to 16 bytes for better efficiency.
217 //   If rotation of 90 or 270 is used, stride is affected.
218 // "crop_x" and "crop_y" are starting position for cropping.
219 //   To center, crop_x = (src_width - dst_width) / 2
220 //              crop_y = (src_height - dst_height) / 2
221 // "src_width" / "src_height" is size of src_frame in pixels.
222 //   "src_height" can be negative indicating a vertically flipped image source.
223 // "crop_width" / "crop_height" is the size to crop the src to.
224 //    Must be less than or equal to src_width/src_height
225 //    Cropping parameters are pre-rotation.
226 // "rotation" can be 0, 90, 180 or 270.
227 // "format" is a fourcc. ie 'I420', 'YUY2'
228 // Returns 0 for successful; -1 for invalid parameter. Non-zero for failure.
229 LIBYUV_API
230 int ConvertToI420(const uint8* src_frame, size_t src_size,
231                   uint8* dst_y, int dst_stride_y,
232                   uint8* dst_u, int dst_stride_u,
233                   uint8* dst_v, int dst_stride_v,
234                   int crop_x, int crop_y,
235                   int src_width, int src_height,
236                   int crop_width, int crop_height,
237                   enum RotationMode rotation,
238                   uint32 format);
239 
240 #ifdef __cplusplus
241 }  // extern "C"
242 }  // namespace libyuv
243 #endif
244 
245 #endif  // INCLUDE_LIBYUV_CONVERT_H_  NOLINT
246