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. 29 LIBYUV_API 30 int I444ToI420(const uint8_t* src_y, 31 int src_stride_y, 32 const uint8_t* src_u, 33 int src_stride_u, 34 const uint8_t* src_v, 35 int src_stride_v, 36 uint8_t* dst_y, 37 int dst_stride_y, 38 uint8_t* dst_u, 39 int dst_stride_u, 40 uint8_t* dst_v, 41 int dst_stride_v, 42 int width, 43 int height); 44 45 // Convert I422 to I420. 46 LIBYUV_API 47 int I422ToI420(const uint8_t* src_y, 48 int src_stride_y, 49 const uint8_t* src_u, 50 int src_stride_u, 51 const uint8_t* src_v, 52 int src_stride_v, 53 uint8_t* dst_y, 54 int dst_stride_y, 55 uint8_t* dst_u, 56 int dst_stride_u, 57 uint8_t* dst_v, 58 int dst_stride_v, 59 int width, 60 int height); 61 62 // Copy I420 to I420. 63 #define I420ToI420 I420Copy 64 LIBYUV_API 65 int I420Copy(const uint8_t* src_y, 66 int src_stride_y, 67 const uint8_t* src_u, 68 int src_stride_u, 69 const uint8_t* src_v, 70 int src_stride_v, 71 uint8_t* dst_y, 72 int dst_stride_y, 73 uint8_t* dst_u, 74 int dst_stride_u, 75 uint8_t* dst_v, 76 int dst_stride_v, 77 int width, 78 int height); 79 80 // Copy I010 to I010 81 #define I010ToI010 I010Copy 82 #define H010ToH010 I010Copy 83 LIBYUV_API 84 int I010Copy(const uint16_t* src_y, 85 int src_stride_y, 86 const uint16_t* src_u, 87 int src_stride_u, 88 const uint16_t* src_v, 89 int src_stride_v, 90 uint16_t* dst_y, 91 int dst_stride_y, 92 uint16_t* dst_u, 93 int dst_stride_u, 94 uint16_t* dst_v, 95 int dst_stride_v, 96 int width, 97 int height); 98 99 // Convert 10 bit YUV to 8 bit 100 #define H010ToH420 I010ToI420 101 LIBYUV_API 102 int I010ToI420(const uint16_t* src_y, 103 int src_stride_y, 104 const uint16_t* src_u, 105 int src_stride_u, 106 const uint16_t* src_v, 107 int src_stride_v, 108 uint8_t* dst_y, 109 int dst_stride_y, 110 uint8_t* dst_u, 111 int dst_stride_u, 112 uint8_t* dst_v, 113 int dst_stride_v, 114 int width, 115 int height); 116 117 // Convert I400 (grey) to I420. 118 LIBYUV_API 119 int I400ToI420(const uint8_t* src_y, 120 int src_stride_y, 121 uint8_t* dst_y, 122 int dst_stride_y, 123 uint8_t* dst_u, 124 int dst_stride_u, 125 uint8_t* dst_v, 126 int dst_stride_v, 127 int width, 128 int height); 129 130 #define J400ToJ420 I400ToI420 131 132 // Convert NV12 to I420. 133 LIBYUV_API 134 int NV12ToI420(const uint8_t* src_y, 135 int src_stride_y, 136 const uint8_t* src_uv, 137 int src_stride_uv, 138 uint8_t* dst_y, 139 int dst_stride_y, 140 uint8_t* dst_u, 141 int dst_stride_u, 142 uint8_t* dst_v, 143 int dst_stride_v, 144 int width, 145 int height); 146 147 // Convert NV21 to I420. 148 LIBYUV_API 149 int NV21ToI420(const uint8_t* src_y, 150 int src_stride_y, 151 const uint8_t* src_vu, 152 int src_stride_vu, 153 uint8_t* dst_y, 154 int dst_stride_y, 155 uint8_t* dst_u, 156 int dst_stride_u, 157 uint8_t* dst_v, 158 int dst_stride_v, 159 int width, 160 int height); 161 162 // Convert YUY2 to I420. 163 LIBYUV_API 164 int YUY2ToI420(const uint8_t* src_yuy2, 165 int src_stride_yuy2, 166 uint8_t* dst_y, 167 int dst_stride_y, 168 uint8_t* dst_u, 169 int dst_stride_u, 170 uint8_t* dst_v, 171 int dst_stride_v, 172 int width, 173 int height); 174 175 // Convert UYVY to I420. 176 LIBYUV_API 177 int UYVYToI420(const uint8_t* src_uyvy, 178 int src_stride_uyvy, 179 uint8_t* dst_y, 180 int dst_stride_y, 181 uint8_t* dst_u, 182 int dst_stride_u, 183 uint8_t* dst_v, 184 int dst_stride_v, 185 int width, 186 int height); 187 188 // Convert M420 to I420. 189 LIBYUV_API 190 int M420ToI420(const uint8_t* src_m420, 191 int src_stride_m420, 192 uint8_t* dst_y, 193 int dst_stride_y, 194 uint8_t* dst_u, 195 int dst_stride_u, 196 uint8_t* dst_v, 197 int dst_stride_v, 198 int width, 199 int height); 200 201 // Convert Android420 to I420. 202 LIBYUV_API 203 int Android420ToI420(const uint8_t* src_y, 204 int src_stride_y, 205 const uint8_t* src_u, 206 int src_stride_u, 207 const uint8_t* src_v, 208 int src_stride_v, 209 int src_pixel_stride_uv, 210 uint8_t* dst_y, 211 int dst_stride_y, 212 uint8_t* dst_u, 213 int dst_stride_u, 214 uint8_t* dst_v, 215 int dst_stride_v, 216 int width, 217 int height); 218 219 // ARGB little endian (bgra in memory) to I420. 220 LIBYUV_API 221 int ARGBToI420(const uint8_t* src_argb, 222 int src_stride_argb, 223 uint8_t* dst_y, 224 int dst_stride_y, 225 uint8_t* dst_u, 226 int dst_stride_u, 227 uint8_t* dst_v, 228 int dst_stride_v, 229 int width, 230 int height); 231 232 // BGRA little endian (argb in memory) to I420. 233 LIBYUV_API 234 int BGRAToI420(const uint8_t* src_bgra, 235 int src_stride_bgra, 236 uint8_t* dst_y, 237 int dst_stride_y, 238 uint8_t* dst_u, 239 int dst_stride_u, 240 uint8_t* dst_v, 241 int dst_stride_v, 242 int width, 243 int height); 244 245 // ABGR little endian (rgba in memory) to I420. 246 LIBYUV_API 247 int ABGRToI420(const uint8_t* src_abgr, 248 int src_stride_abgr, 249 uint8_t* dst_y, 250 int dst_stride_y, 251 uint8_t* dst_u, 252 int dst_stride_u, 253 uint8_t* dst_v, 254 int dst_stride_v, 255 int width, 256 int height); 257 258 // RGBA little endian (abgr in memory) to I420. 259 LIBYUV_API 260 int RGBAToI420(const uint8_t* src_rgba, 261 int src_stride_rgba, 262 uint8_t* dst_y, 263 int dst_stride_y, 264 uint8_t* dst_u, 265 int dst_stride_u, 266 uint8_t* dst_v, 267 int dst_stride_v, 268 int width, 269 int height); 270 271 // RGB little endian (bgr in memory) to I420. 272 LIBYUV_API 273 int RGB24ToI420(const uint8_t* src_rgb24, 274 int src_stride_rgb24, 275 uint8_t* dst_y, 276 int dst_stride_y, 277 uint8_t* dst_u, 278 int dst_stride_u, 279 uint8_t* dst_v, 280 int dst_stride_v, 281 int width, 282 int height); 283 284 // RGB big endian (rgb in memory) to I420. 285 LIBYUV_API 286 int RAWToI420(const uint8_t* src_raw, 287 int src_stride_raw, 288 uint8_t* dst_y, 289 int dst_stride_y, 290 uint8_t* dst_u, 291 int dst_stride_u, 292 uint8_t* dst_v, 293 int dst_stride_v, 294 int width, 295 int height); 296 297 // RGB16 (RGBP fourcc) little endian to I420. 298 LIBYUV_API 299 int RGB565ToI420(const uint8_t* src_rgb565, 300 int src_stride_rgb565, 301 uint8_t* dst_y, 302 int dst_stride_y, 303 uint8_t* dst_u, 304 int dst_stride_u, 305 uint8_t* dst_v, 306 int dst_stride_v, 307 int width, 308 int height); 309 310 // RGB15 (RGBO fourcc) little endian to I420. 311 LIBYUV_API 312 int ARGB1555ToI420(const uint8_t* src_argb1555, 313 int src_stride_argb1555, 314 uint8_t* dst_y, 315 int dst_stride_y, 316 uint8_t* dst_u, 317 int dst_stride_u, 318 uint8_t* dst_v, 319 int dst_stride_v, 320 int width, 321 int height); 322 323 // RGB12 (R444 fourcc) little endian to I420. 324 LIBYUV_API 325 int ARGB4444ToI420(const uint8_t* src_argb4444, 326 int src_stride_argb4444, 327 uint8_t* dst_y, 328 int dst_stride_y, 329 uint8_t* dst_u, 330 int dst_stride_u, 331 uint8_t* dst_v, 332 int dst_stride_v, 333 int width, 334 int height); 335 336 #ifdef HAVE_JPEG 337 // src_width/height provided by capture. 338 // dst_width/height for clipping determine final size. 339 LIBYUV_API 340 int MJPGToI420(const uint8_t* sample, 341 size_t sample_size, 342 uint8_t* dst_y, 343 int dst_stride_y, 344 uint8_t* dst_u, 345 int dst_stride_u, 346 uint8_t* dst_v, 347 int dst_stride_v, 348 int src_width, 349 int src_height, 350 int dst_width, 351 int dst_height); 352 353 // Query size of MJPG in pixels. 354 LIBYUV_API 355 int MJPGSize(const uint8_t* sample, 356 size_t sample_size, 357 int* width, 358 int* height); 359 #endif 360 361 // Convert camera sample to I420 with cropping, rotation and vertical flip. 362 // "src_size" is needed to parse MJPG. 363 // "dst_stride_y" number of bytes in a row of the dst_y plane. 364 // Normally this would be the same as dst_width, with recommended alignment 365 // to 16 bytes for better efficiency. 366 // If rotation of 90 or 270 is used, stride is affected. The caller should 367 // allocate the I420 buffer according to rotation. 368 // "dst_stride_u" number of bytes in a row of the dst_u plane. 369 // Normally this would be the same as (dst_width + 1) / 2, with 370 // recommended alignment to 16 bytes for better efficiency. 371 // If rotation of 90 or 270 is used, stride is affected. 372 // "crop_x" and "crop_y" are starting position for cropping. 373 // To center, crop_x = (src_width - dst_width) / 2 374 // crop_y = (src_height - dst_height) / 2 375 // "src_width" / "src_height" is size of src_frame in pixels. 376 // "src_height" can be negative indicating a vertically flipped image source. 377 // "crop_width" / "crop_height" is the size to crop the src to. 378 // Must be less than or equal to src_width/src_height 379 // Cropping parameters are pre-rotation. 380 // "rotation" can be 0, 90, 180 or 270. 381 // "fourcc" is a fourcc. ie 'I420', 'YUY2' 382 // Returns 0 for successful; -1 for invalid parameter. Non-zero for failure. 383 LIBYUV_API 384 int ConvertToI420(const uint8_t* sample, 385 size_t sample_size, 386 uint8_t* dst_y, 387 int dst_stride_y, 388 uint8_t* dst_u, 389 int dst_stride_u, 390 uint8_t* dst_v, 391 int dst_stride_v, 392 int crop_x, 393 int crop_y, 394 int src_width, 395 int src_height, 396 int crop_width, 397 int crop_height, 398 enum RotationMode rotation, 399 uint32_t fourcc); 400 401 #ifdef __cplusplus 402 } // extern "C" 403 } // namespace libyuv 404 #endif 405 406 #endif // INCLUDE_LIBYUV_CONVERT_H_ 407