webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
convert.h
Go to the documentation of this file.
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_
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.
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.
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 // Copy I420 to I420.
49 #define I420ToI420 I420Copy
51 int I420Copy(const uint8* src_y, int src_stride_y,
52  const uint8* src_u, int src_stride_u,
53  const uint8* src_v, int src_stride_v,
54  uint8* dst_y, int dst_stride_y,
55  uint8* dst_u, int dst_stride_u,
56  uint8* dst_v, int dst_stride_v,
57  int width, int height);
58 
59 // Convert I400 (grey) to I420.
61 int I400ToI420(const uint8* src_y, int src_stride_y,
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 #define J400ToJ420 I400ToI420
68 
69 // Convert NV12 to I420.
71 int NV12ToI420(const uint8* src_y, int src_stride_y,
72  const uint8* src_uv, int src_stride_uv,
73  uint8* dst_y, int dst_stride_y,
74  uint8* dst_u, int dst_stride_u,
75  uint8* dst_v, int dst_stride_v,
76  int width, int height);
77 
78 // Convert NV21 to I420.
80 int NV21ToI420(const uint8* src_y, int src_stride_y,
81  const uint8* src_vu, int src_stride_vu,
82  uint8* dst_y, int dst_stride_y,
83  uint8* dst_u, int dst_stride_u,
84  uint8* dst_v, int dst_stride_v,
85  int width, int height);
86 
87 // Convert YUY2 to I420.
89 int YUY2ToI420(const uint8* src_yuy2, int src_stride_yuy2,
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 UYVY to I420.
97 int UYVYToI420(const uint8* src_uyvy, int src_stride_uyvy,
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 M420 to I420.
105 int M420ToI420(const uint8* src_m420, int src_stride_m420,
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 Android420 to I420.
113 int Android420ToI420(const uint8* src_y, int src_stride_y,
114  const uint8* src_u, int src_stride_u,
115  const uint8* src_v, int src_stride_v,
116  int pixel_stride_uv,
117  uint8* dst_y, int dst_stride_y,
118  uint8* dst_u, int dst_stride_u,
119  uint8* dst_v, int dst_stride_v,
120  int width, int height);
121 
122 // ARGB little endian (bgra in memory) to I420.
124 int ARGBToI420(const uint8* src_frame, int src_stride_frame,
125  uint8* dst_y, int dst_stride_y,
126  uint8* dst_u, int dst_stride_u,
127  uint8* dst_v, int dst_stride_v,
128  int width, int height);
129 
130 // BGRA little endian (argb in memory) to I420.
132 int BGRAToI420(const uint8* src_frame, int src_stride_frame,
133  uint8* dst_y, int dst_stride_y,
134  uint8* dst_u, int dst_stride_u,
135  uint8* dst_v, int dst_stride_v,
136  int width, int height);
137 
138 // ABGR little endian (rgba in memory) to I420.
140 int ABGRToI420(const uint8* src_frame, int src_stride_frame,
141  uint8* dst_y, int dst_stride_y,
142  uint8* dst_u, int dst_stride_u,
143  uint8* dst_v, int dst_stride_v,
144  int width, int height);
145 
146 // RGBA little endian (abgr in memory) to I420.
148 int RGBAToI420(const uint8* src_frame, int src_stride_frame,
149  uint8* dst_y, int dst_stride_y,
150  uint8* dst_u, int dst_stride_u,
151  uint8* dst_v, int dst_stride_v,
152  int width, int height);
153 
154 // RGB little endian (bgr in memory) to I420.
156 int RGB24ToI420(const uint8* src_frame, int src_stride_frame,
157  uint8* dst_y, int dst_stride_y,
158  uint8* dst_u, int dst_stride_u,
159  uint8* dst_v, int dst_stride_v,
160  int width, int height);
161 
162 // RGB big endian (rgb in memory) to I420.
164 int RAWToI420(const uint8* src_frame, int src_stride_frame,
165  uint8* dst_y, int dst_stride_y,
166  uint8* dst_u, int dst_stride_u,
167  uint8* dst_v, int dst_stride_v,
168  int width, int height);
169 
170 // RGB16 (RGBP fourcc) little endian to I420.
172 int RGB565ToI420(const uint8* src_frame, int src_stride_frame,
173  uint8* dst_y, int dst_stride_y,
174  uint8* dst_u, int dst_stride_u,
175  uint8* dst_v, int dst_stride_v,
176  int width, int height);
177 
178 // RGB15 (RGBO fourcc) little endian to I420.
180 int ARGB1555ToI420(const uint8* src_frame, int src_stride_frame,
181  uint8* dst_y, int dst_stride_y,
182  uint8* dst_u, int dst_stride_u,
183  uint8* dst_v, int dst_stride_v,
184  int width, int height);
185 
186 // RGB12 (R444 fourcc) little endian to I420.
188 int ARGB4444ToI420(const uint8* src_frame, int src_stride_frame,
189  uint8* dst_y, int dst_stride_y,
190  uint8* dst_u, int dst_stride_u,
191  uint8* dst_v, int dst_stride_v,
192  int width, int height);
193 
194 #ifdef HAVE_JPEG
195 // src_width/height provided by capture.
196 // dst_width/height for clipping determine final size.
198 int MJPGToI420(const uint8* sample, size_t sample_size,
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 src_width, int src_height,
203  int dst_width, int dst_height);
204 
205 // Query size of MJPG in pixels.
207 int MJPGSize(const uint8* sample, size_t sample_size,
208  int* width, int* height);
209 #endif
210 
211 // Convert camera sample to I420 with cropping, rotation and vertical flip.
212 // "src_size" is needed to parse MJPG.
213 // "dst_stride_y" number of bytes in a row of the dst_y plane.
214 // Normally this would be the same as dst_width, with recommended alignment
215 // to 16 bytes for better efficiency.
216 // If rotation of 90 or 270 is used, stride is affected. The caller should
217 // allocate the I420 buffer according to rotation.
218 // "dst_stride_u" number of bytes in a row of the dst_u plane.
219 // Normally this would be the same as (dst_width + 1) / 2, with
220 // recommended alignment to 16 bytes for better efficiency.
221 // If rotation of 90 or 270 is used, stride is affected.
222 // "crop_x" and "crop_y" are starting position for cropping.
223 // To center, crop_x = (src_width - dst_width) / 2
224 // crop_y = (src_height - dst_height) / 2
225 // "src_width" / "src_height" is size of src_frame in pixels.
226 // "src_height" can be negative indicating a vertically flipped image source.
227 // "crop_width" / "crop_height" is the size to crop the src to.
228 // Must be less than or equal to src_width/src_height
229 // Cropping parameters are pre-rotation.
230 // "rotation" can be 0, 90, 180 or 270.
231 // "format" is a fourcc. ie 'I420', 'YUY2'
232 // Returns 0 for successful; -1 for invalid parameter. Non-zero for failure.
234 int ConvertToI420(const uint8* src_frame, size_t src_size,
235  uint8* dst_y, int dst_stride_y,
236  uint8* dst_u, int dst_stride_u,
237  uint8* dst_v, int dst_stride_v,
238  int crop_x, int crop_y,
239  int src_width, int src_height,
240  int crop_width, int crop_height,
241  enum RotationMode rotation,
242  uint32 format);
243 
244 #ifdef __cplusplus
245 } // extern "C"
246 } // namespace libyuv
247 #endif
248 
249 #endif // INCLUDE_LIBYUV_CONVERT_H_
EGLSurface EGLint EGLint EGLint EGLint height
Definition: eglext.h:950
LIBYUV_API int ConvertToI420(const uint8 *src_frame, size_t src_size, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int crop_x, int crop_y, int src_width, int src_height, int crop_width, int crop_height, enum RotationMode rotation, uint32 format)
Definition: convert_to_i420.cc:28
uint8_t * dst_v
Definition: peerconnection_jni.cc:2274
LIBYUV_API int BGRAToI420(const uint8 *src_frame, int src_stride_frame, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:570
GLint GLint GLint GLsizei GLsizei GLenum format
Definition: gl2.h:403
EGLSurface EGLint EGLint EGLint width
Definition: eglext.h:950
LIBYUV_API int UYVYToI420(const uint8 *src_uyvy, int src_stride_uyvy, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:403
LIBYUV_API int YUY2ToI420(const uint8 *src_yuy2, int src_stride_yuy2, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:328
uint8_t * dst_y
Definition: peerconnection_jni.cc:2270
unsigned char uint8
Definition: basic_types.h:62
int dst_height
Definition: convert.cc:32
LIBYUV_API int NV21ToI420(const uint8 *src_y, int src_stride_y, const uint8 *src_vu, int src_stride_vu, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:297
LIBYUV_API int I420Copy(const uint8 *src_y, int src_stride_y, const uint8 *src_u, int src_stride_u, const uint8 *src_v, int src_stride_v, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:64
uint8_t * src_u
Definition: peerconnection_jni.cc:2263
LIBYUV_API int ARGB1555ToI420(const uint8 *src_frame, int src_stride_frame, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:1118
LIBYUV_API int ABGRToI420(const uint8 *src_frame, int src_stride_frame, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:636
LIBYUV_API int ARGBToI420(const uint8 *src_frame, int src_stride_frame, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:478
LIBYUV_API int RAWToI420(const uint8 *src_frame, int src_stride_frame, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:882
uint8_t * src_y
Definition: peerconnection_jni.cc:2261
LIBYUV_API int I422ToI420(const uint8 *src_y, int src_stride_y, const uint8 *src_u, int src_stride_u, const uint8 *src_v, int src_stride_v, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:102
JNIEnv jlong jbyteArray jint jint jint jint rotation
Definition: androidvideotracksource_jni.cc:30
size_t dst_stride_v
Definition: peerconnection_jni.cc:2275
Definition: basictypes_test.cc:14
int dst_width
Definition: convert.cc:32
#define LIBYUV_API
Definition: basic_types.h:102
size_t dst_stride_u
Definition: peerconnection_jni.cc:2273
LIBYUV_API int RGB565ToI420(const uint8 *src_frame, int src_stride_frame, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:996
LIBYUV_API int NV12ToI420(const uint8 *src_y, int src_stride_y, const uint8 *src_uv, int src_stride_uv, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:281
uint8_t * dst_u
Definition: peerconnection_jni.cc:2272
LIBYUV_API int RGBAToI420(const uint8 *src_frame, int src_stride_frame, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:702
LIBYUV_API int I444ToI420(const uint8 *src_y, int src_stride_y, const uint8 *src_u, int src_stride_u, const uint8 *src_v, int src_stride_v, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:123
LIBYUV_API int ARGB4444ToI420(const uint8 *src_frame, int src_stride_frame, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:1242
uint32_t uint32
Definition: angle_config.h:28
LIBYUV_API int I400ToI420(const uint8 *src_y, int src_stride_y, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:142
size_t dst_stride_y
Definition: peerconnection_jni.cc:2271
LIBYUV_API int Android420ToI420(const uint8 *src_y, int src_stride_y, const uint8 *src_u, int src_stride_u, const uint8 *src_v, int src_stride_v, int pixel_stride_uv, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:1396
uint8_t * src_v
Definition: peerconnection_jni.cc:2265
RotationMode
Definition: rotate.h:22
LIBYUV_API int RGB24ToI420(const uint8 *src_frame, int src_stride_frame, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:768
LIBYUV_API int M420ToI420(const uint8 *src_m420, int src_stride_m420, uint8 *dst_y, int dst_stride_y, uint8 *dst_u, int dst_stride_u, uint8 *dst_v, int dst_stride_v, int width, int height)
Definition: convert.cc:313