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 21namespace libyuv { 22extern "C" { 23#endif 24 25// Convert I444 to I420. 26LIBYUV_API 27int 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. 36LIBYUV_API 37int 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. 46LIBYUV_API 47int 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 57LIBYUV_API 58int 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. 67LIBYUV_API 68int 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// Convert NV12 to I420. 75LIBYUV_API 76int NV12ToI420(const uint8* src_y, int src_stride_y, 77 const uint8* src_uv, int src_stride_uv, 78 uint8* dst_y, int dst_stride_y, 79 uint8* dst_u, int dst_stride_u, 80 uint8* dst_v, int dst_stride_v, 81 int width, int height); 82 83// Convert NV21 to I420. 84LIBYUV_API 85int NV21ToI420(const uint8* src_y, int src_stride_y, 86 const uint8* src_vu, int src_stride_vu, 87 uint8* dst_y, int dst_stride_y, 88 uint8* dst_u, int dst_stride_u, 89 uint8* dst_v, int dst_stride_v, 90 int width, int height); 91 92// Convert YUY2 to I420. 93LIBYUV_API 94int YUY2ToI420(const uint8* src_yuy2, int src_stride_yuy2, 95 uint8* dst_y, int dst_stride_y, 96 uint8* dst_u, int dst_stride_u, 97 uint8* dst_v, int dst_stride_v, 98 int width, int height); 99 100// Convert UYVY to I420. 101LIBYUV_API 102int UYVYToI420(const uint8* src_uyvy, int src_stride_uyvy, 103 uint8* dst_y, int dst_stride_y, 104 uint8* dst_u, int dst_stride_u, 105 uint8* dst_v, int dst_stride_v, 106 int width, int height); 107 108// Convert M420 to I420. 109LIBYUV_API 110int M420ToI420(const uint8* src_m420, int src_stride_m420, 111 uint8* dst_y, int dst_stride_y, 112 uint8* dst_u, int dst_stride_u, 113 uint8* dst_v, int dst_stride_v, 114 int width, int height); 115 116// Convert Q420 to I420. 117LIBYUV_API 118int Q420ToI420(const uint8* src_y, int src_stride_y, 119 const uint8* src_yuy2, int src_stride_yuy2, 120 uint8* dst_y, int dst_stride_y, 121 uint8* dst_u, int dst_stride_u, 122 uint8* dst_v, int dst_stride_v, 123 int width, int height); 124 125// ARGB little endian (bgra in memory) to I420. 126LIBYUV_API 127int ARGBToI420(const uint8* src_frame, int src_stride_frame, 128 uint8* dst_y, int dst_stride_y, 129 uint8* dst_u, int dst_stride_u, 130 uint8* dst_v, int dst_stride_v, 131 int width, int height); 132 133// BGRA little endian (argb in memory) to I420. 134LIBYUV_API 135int BGRAToI420(const uint8* src_frame, int src_stride_frame, 136 uint8* dst_y, int dst_stride_y, 137 uint8* dst_u, int dst_stride_u, 138 uint8* dst_v, int dst_stride_v, 139 int width, int height); 140 141// ABGR little endian (rgba in memory) to I420. 142LIBYUV_API 143int ABGRToI420(const uint8* src_frame, int src_stride_frame, 144 uint8* dst_y, int dst_stride_y, 145 uint8* dst_u, int dst_stride_u, 146 uint8* dst_v, int dst_stride_v, 147 int width, int height); 148 149// RGBA little endian (abgr in memory) to I420. 150LIBYUV_API 151int RGBAToI420(const uint8* src_frame, int src_stride_frame, 152 uint8* dst_y, int dst_stride_y, 153 uint8* dst_u, int dst_stride_u, 154 uint8* dst_v, int dst_stride_v, 155 int width, int height); 156 157// RGB little endian (bgr in memory) to I420. 158LIBYUV_API 159int RGB24ToI420(const uint8* src_frame, int src_stride_frame, 160 uint8* dst_y, int dst_stride_y, 161 uint8* dst_u, int dst_stride_u, 162 uint8* dst_v, int dst_stride_v, 163 int width, int height); 164 165// RGB big endian (rgb in memory) to I420. 166LIBYUV_API 167int RAWToI420(const uint8* src_frame, int src_stride_frame, 168 uint8* dst_y, int dst_stride_y, 169 uint8* dst_u, int dst_stride_u, 170 uint8* dst_v, int dst_stride_v, 171 int width, int height); 172 173// RGB16 (RGBP fourcc) little endian to I420. 174LIBYUV_API 175int RGB565ToI420(const uint8* src_frame, int src_stride_frame, 176 uint8* dst_y, int dst_stride_y, 177 uint8* dst_u, int dst_stride_u, 178 uint8* dst_v, int dst_stride_v, 179 int width, int height); 180 181// RGB15 (RGBO fourcc) little endian to I420. 182LIBYUV_API 183int ARGB1555ToI420(const uint8* src_frame, int src_stride_frame, 184 uint8* dst_y, int dst_stride_y, 185 uint8* dst_u, int dst_stride_u, 186 uint8* dst_v, int dst_stride_v, 187 int width, int height); 188 189// RGB12 (R444 fourcc) little endian to I420. 190LIBYUV_API 191int ARGB4444ToI420(const uint8* src_frame, int src_stride_frame, 192 uint8* dst_y, int dst_stride_y, 193 uint8* dst_u, int dst_stride_u, 194 uint8* dst_v, int dst_stride_v, 195 int width, int height); 196 197#ifdef HAVE_JPEG 198// src_width/height provided by capture. 199// dst_width/height for clipping determine final size. 200LIBYUV_API 201int MJPGToI420(const uint8* sample, size_t sample_size, 202 uint8* dst_y, int dst_stride_y, 203 uint8* dst_u, int dst_stride_u, 204 uint8* dst_v, int dst_stride_v, 205 int src_width, int src_height, 206 int dst_width, int dst_height); 207 208// Query size of MJPG in pixels. 209LIBYUV_API 210int MJPGSize(const uint8* sample, size_t sample_size, 211 int* width, int* height); 212#endif 213 214// Note Bayer formats (BGGR) To I420 are in format_conversion.h 215 216// Convert camera sample to I420 with cropping, rotation and vertical flip. 217// "src_size" is needed to parse MJPG. 218// "dst_stride_y" number of bytes in a row of the dst_y plane. 219// Normally this would be the same as dst_width, with recommended alignment 220// to 16 bytes for better efficiency. 221// If rotation of 90 or 270 is used, stride is affected. The caller should 222// allocate the I420 buffer according to rotation. 223// "dst_stride_u" number of bytes in a row of the dst_u plane. 224// Normally this would be the same as (dst_width + 1) / 2, with 225// recommended alignment to 16 bytes for better efficiency. 226// If rotation of 90 or 270 is used, stride is affected. 227// "crop_x" and "crop_y" are starting position for cropping. 228// To center, crop_x = (src_width - dst_width) / 2 229// crop_y = (src_height - dst_height) / 2 230// "src_width" / "src_height" is size of src_frame in pixels. 231// "src_height" can be negative indicating a vertically flipped image source. 232// "crop_width" / "crop_height" is the size to crop the src to. 233// Must be less than or equal to src_width/src_height 234// Cropping parameters are pre-rotation. 235// "rotation" can be 0, 90, 180 or 270. 236// "format" is a fourcc. ie 'I420', 'YUY2' 237// Returns 0 for successful; -1 for invalid parameter. Non-zero for failure. 238LIBYUV_API 239int ConvertToI420(const uint8* src_frame, size_t src_size, 240 uint8* dst_y, int dst_stride_y, 241 uint8* dst_u, int dst_stride_u, 242 uint8* dst_v, int dst_stride_v, 243 int crop_x, int crop_y, 244 int src_width, int src_height, 245 int crop_width, int crop_height, 246 enum RotationMode rotation, 247 uint32 format); 248 249#ifdef __cplusplus 250} // extern "C" 251} // namespace libyuv 252#endif 253 254#endif // INCLUDE_LIBYUV_CONVERT_H_ NOLINT 255