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_PLANAR_FUNCTIONS_H_ // NOLINT 12#define INCLUDE_LIBYUV_PLANAR_FUNCTIONS_H_ 13 14#include "libyuv/basic_types.h" 15 16// TODO(fbarchard): Remove the following headers includes. 17#include "libyuv/convert.h" 18#include "libyuv/convert_argb.h" 19 20#ifdef __cplusplus 21namespace libyuv { 22extern "C" { 23#endif 24 25// Copy a plane of data. 26LIBYUV_API 27void CopyPlane(const uint8* src_y, int src_stride_y, 28 uint8* dst_y, int dst_stride_y, 29 int width, int height); 30 31LIBYUV_API 32void CopyPlane_16(const uint16* src_y, int src_stride_y, 33 uint16* dst_y, int dst_stride_y, 34 int width, int height); 35 36// Set a plane of data to a 32 bit value. 37LIBYUV_API 38void SetPlane(uint8* dst_y, int dst_stride_y, 39 int width, int height, 40 uint32 value); 41 42// Copy I400. Supports inverting. 43LIBYUV_API 44int I400ToI400(const uint8* src_y, int src_stride_y, 45 uint8* dst_y, int dst_stride_y, 46 int width, int height); 47 48#define J400ToJ400 I400ToI400 49 50// Copy I422 to I422. 51#define I422ToI422 I422Copy 52LIBYUV_API 53int I422Copy(const uint8* src_y, int src_stride_y, 54 const uint8* src_u, int src_stride_u, 55 const uint8* src_v, int src_stride_v, 56 uint8* dst_y, int dst_stride_y, 57 uint8* dst_u, int dst_stride_u, 58 uint8* dst_v, int dst_stride_v, 59 int width, int height); 60 61// Copy I444 to I444. 62#define I444ToI444 I444Copy 63LIBYUV_API 64int I444Copy(const uint8* src_y, int src_stride_y, 65 const uint8* src_u, int src_stride_u, 66 const uint8* src_v, int src_stride_v, 67 uint8* dst_y, int dst_stride_y, 68 uint8* dst_u, int dst_stride_u, 69 uint8* dst_v, int dst_stride_v, 70 int width, int height); 71 72// Convert YUY2 to I422. 73LIBYUV_API 74int YUY2ToI422(const uint8* src_yuy2, int src_stride_yuy2, 75 uint8* dst_y, int dst_stride_y, 76 uint8* dst_u, int dst_stride_u, 77 uint8* dst_v, int dst_stride_v, 78 int width, int height); 79 80// Convert UYVY to I422. 81LIBYUV_API 82int UYVYToI422(const uint8* src_uyvy, int src_stride_uyvy, 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 88LIBYUV_API 89int YUY2ToNV12(const uint8* src_yuy2, int src_stride_yuy2, 90 uint8* dst_y, int dst_stride_y, 91 uint8* dst_uv, int dst_stride_uv, 92 int width, int height); 93 94LIBYUV_API 95int UYVYToNV12(const uint8* src_uyvy, int src_stride_uyvy, 96 uint8* dst_y, int dst_stride_y, 97 uint8* dst_uv, int dst_stride_uv, 98 int width, int height); 99 100// Convert I420 to I400. (calls CopyPlane ignoring u/v). 101LIBYUV_API 102int I420ToI400(const uint8* src_y, int src_stride_y, 103 const uint8* src_u, int src_stride_u, 104 const uint8* src_v, int src_stride_v, 105 uint8* dst_y, int dst_stride_y, 106 int width, int height); 107 108// Alias 109#define J420ToJ400 I420ToI400 110#define I420ToI420Mirror I420Mirror 111 112// I420 mirror. 113LIBYUV_API 114int I420Mirror(const uint8* src_y, int src_stride_y, 115 const uint8* src_u, int src_stride_u, 116 const uint8* src_v, int src_stride_v, 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// Alias 123#define I400ToI400Mirror I400Mirror 124 125// I400 mirror. A single plane is mirrored horizontally. 126// Pass negative height to achieve 180 degree rotation. 127LIBYUV_API 128int I400Mirror(const uint8* src_y, int src_stride_y, 129 uint8* dst_y, int dst_stride_y, 130 int width, int height); 131 132// Alias 133#define ARGBToARGBMirror ARGBMirror 134 135// ARGB mirror. 136LIBYUV_API 137int ARGBMirror(const uint8* src_argb, int src_stride_argb, 138 uint8* dst_argb, int dst_stride_argb, 139 int width, int height); 140 141// Convert NV12 to RGB565. 142LIBYUV_API 143int NV12ToRGB565(const uint8* src_y, int src_stride_y, 144 const uint8* src_uv, int src_stride_uv, 145 uint8* dst_rgb565, int dst_stride_rgb565, 146 int width, int height); 147 148// Convert NV21 to RGB565. 149LIBYUV_API 150int NV21ToRGB565(const uint8* src_y, int src_stride_y, 151 const uint8* src_uv, int src_stride_uv, 152 uint8* dst_rgb565, int dst_stride_rgb565, 153 int width, int height); 154 155// I422ToARGB is in convert_argb.h 156// Convert I422 to BGRA. 157LIBYUV_API 158int I422ToBGRA(const uint8* src_y, int src_stride_y, 159 const uint8* src_u, int src_stride_u, 160 const uint8* src_v, int src_stride_v, 161 uint8* dst_bgra, int dst_stride_bgra, 162 int width, int height); 163 164// Convert I422 to ABGR. 165LIBYUV_API 166int I422ToABGR(const uint8* src_y, int src_stride_y, 167 const uint8* src_u, int src_stride_u, 168 const uint8* src_v, int src_stride_v, 169 uint8* dst_abgr, int dst_stride_abgr, 170 int width, int height); 171 172// Convert I422 to RGBA. 173LIBYUV_API 174int I422ToRGBA(const uint8* src_y, int src_stride_y, 175 const uint8* src_u, int src_stride_u, 176 const uint8* src_v, int src_stride_v, 177 uint8* dst_rgba, int dst_stride_rgba, 178 int width, int height); 179 180// Draw a rectangle into I420. 181LIBYUV_API 182int I420Rect(uint8* dst_y, int dst_stride_y, 183 uint8* dst_u, int dst_stride_u, 184 uint8* dst_v, int dst_stride_v, 185 int x, int y, int width, int height, 186 int value_y, int value_u, int value_v); 187 188// Draw a rectangle into ARGB. 189LIBYUV_API 190int ARGBRect(uint8* dst_argb, int dst_stride_argb, 191 int x, int y, int width, int height, uint32 value); 192 193// Convert ARGB to gray scale ARGB. 194LIBYUV_API 195int ARGBGrayTo(const uint8* src_argb, int src_stride_argb, 196 uint8* dst_argb, int dst_stride_argb, 197 int width, int height); 198 199// Make a rectangle of ARGB gray scale. 200LIBYUV_API 201int ARGBGray(uint8* dst_argb, int dst_stride_argb, 202 int x, int y, int width, int height); 203 204// Make a rectangle of ARGB Sepia tone. 205LIBYUV_API 206int ARGBSepia(uint8* dst_argb, int dst_stride_argb, 207 int x, int y, int width, int height); 208 209// Apply a matrix rotation to each ARGB pixel. 210// matrix_argb is 4 signed ARGB values. -128 to 127 representing -2 to 2. 211// The first 4 coefficients apply to B, G, R, A and produce B of the output. 212// The next 4 coefficients apply to B, G, R, A and produce G of the output. 213// The next 4 coefficients apply to B, G, R, A and produce R of the output. 214// The last 4 coefficients apply to B, G, R, A and produce A of the output. 215LIBYUV_API 216int ARGBColorMatrix(const uint8* src_argb, int src_stride_argb, 217 uint8* dst_argb, int dst_stride_argb, 218 const int8* matrix_argb, 219 int width, int height); 220 221// Deprecated. Use ARGBColorMatrix instead. 222// Apply a matrix rotation to each ARGB pixel. 223// matrix_argb is 3 signed ARGB values. -128 to 127 representing -1 to 1. 224// The first 4 coefficients apply to B, G, R, A and produce B of the output. 225// The next 4 coefficients apply to B, G, R, A and produce G of the output. 226// The last 4 coefficients apply to B, G, R, A and produce R of the output. 227LIBYUV_API 228int RGBColorMatrix(uint8* dst_argb, int dst_stride_argb, 229 const int8* matrix_rgb, 230 int x, int y, int width, int height); 231 232// Apply a color table each ARGB pixel. 233// Table contains 256 ARGB values. 234LIBYUV_API 235int ARGBColorTable(uint8* dst_argb, int dst_stride_argb, 236 const uint8* table_argb, 237 int x, int y, int width, int height); 238 239// Apply a color table each ARGB pixel but preserve destination alpha. 240// Table contains 256 ARGB values. 241LIBYUV_API 242int RGBColorTable(uint8* dst_argb, int dst_stride_argb, 243 const uint8* table_argb, 244 int x, int y, int width, int height); 245 246// Apply a luma/color table each ARGB pixel but preserve destination alpha. 247// Table contains 32768 values indexed by [Y][C] where 7 it 7 bit luma from 248// RGB (YJ style) and C is an 8 bit color component (R, G or B). 249LIBYUV_API 250int ARGBLumaColorTable(const uint8* src_argb, int src_stride_argb, 251 uint8* dst_argb, int dst_stride_argb, 252 const uint8* luma_rgb_table, 253 int width, int height); 254 255// Apply a 3 term polynomial to ARGB values. 256// poly points to a 4x4 matrix. The first row is constants. The 2nd row is 257// coefficients for b, g, r and a. The 3rd row is coefficients for b squared, 258// g squared, r squared and a squared. The 4rd row is coefficients for b to 259// the 3, g to the 3, r to the 3 and a to the 3. The values are summed and 260// result clamped to 0 to 255. 261// A polynomial approximation can be dirived using software such as 'R'. 262 263LIBYUV_API 264int ARGBPolynomial(const uint8* src_argb, int src_stride_argb, 265 uint8* dst_argb, int dst_stride_argb, 266 const float* poly, 267 int width, int height); 268 269// Quantize a rectangle of ARGB. Alpha unaffected. 270// scale is a 16 bit fractional fixed point scaler between 0 and 65535. 271// interval_size should be a value between 1 and 255. 272// interval_offset should be a value between 0 and 255. 273LIBYUV_API 274int ARGBQuantize(uint8* dst_argb, int dst_stride_argb, 275 int scale, int interval_size, int interval_offset, 276 int x, int y, int width, int height); 277 278// Copy ARGB to ARGB. 279LIBYUV_API 280int ARGBCopy(const uint8* src_argb, int src_stride_argb, 281 uint8* dst_argb, int dst_stride_argb, 282 int width, int height); 283 284// Copy ARGB to ARGB. 285LIBYUV_API 286int ARGBCopyAlpha(const uint8* src_argb, int src_stride_argb, 287 uint8* dst_argb, int dst_stride_argb, 288 int width, int height); 289 290// Copy ARGB to ARGB. 291LIBYUV_API 292int ARGBCopyYToAlpha(const uint8* src_y, int src_stride_y, 293 uint8* dst_argb, int dst_stride_argb, 294 int width, int height); 295 296typedef void (*ARGBBlendRow)(const uint8* src_argb0, const uint8* src_argb1, 297 uint8* dst_argb, int width); 298 299// Get function to Alpha Blend ARGB pixels and store to destination. 300LIBYUV_API 301ARGBBlendRow GetARGBBlend(); 302 303// Alpha Blend ARGB images and store to destination. 304// Alpha of destination is set to 255. 305LIBYUV_API 306int ARGBBlend(const uint8* src_argb0, int src_stride_argb0, 307 const uint8* src_argb1, int src_stride_argb1, 308 uint8* dst_argb, int dst_stride_argb, 309 int width, int height); 310 311// Multiply ARGB image by ARGB image. Shifted down by 8. Saturates to 255. 312LIBYUV_API 313int ARGBMultiply(const uint8* src_argb0, int src_stride_argb0, 314 const uint8* src_argb1, int src_stride_argb1, 315 uint8* dst_argb, int dst_stride_argb, 316 int width, int height); 317 318// Add ARGB image with ARGB image. Saturates to 255. 319LIBYUV_API 320int ARGBAdd(const uint8* src_argb0, int src_stride_argb0, 321 const uint8* src_argb1, int src_stride_argb1, 322 uint8* dst_argb, int dst_stride_argb, 323 int width, int height); 324 325// Subtract ARGB image (argb1) from ARGB image (argb0). Saturates to 0. 326LIBYUV_API 327int ARGBSubtract(const uint8* src_argb0, int src_stride_argb0, 328 const uint8* src_argb1, int src_stride_argb1, 329 uint8* dst_argb, int dst_stride_argb, 330 int width, int height); 331 332// Convert I422 to YUY2. 333LIBYUV_API 334int I422ToYUY2(const uint8* src_y, int src_stride_y, 335 const uint8* src_u, int src_stride_u, 336 const uint8* src_v, int src_stride_v, 337 uint8* dst_frame, int dst_stride_frame, 338 int width, int height); 339 340// Convert I422 to UYVY. 341LIBYUV_API 342int I422ToUYVY(const uint8* src_y, int src_stride_y, 343 const uint8* src_u, int src_stride_u, 344 const uint8* src_v, int src_stride_v, 345 uint8* dst_frame, int dst_stride_frame, 346 int width, int height); 347 348// Convert unattentuated ARGB to preattenuated ARGB. 349LIBYUV_API 350int ARGBAttenuate(const uint8* src_argb, int src_stride_argb, 351 uint8* dst_argb, int dst_stride_argb, 352 int width, int height); 353 354// Convert preattentuated ARGB to unattenuated ARGB. 355LIBYUV_API 356int ARGBUnattenuate(const uint8* src_argb, int src_stride_argb, 357 uint8* dst_argb, int dst_stride_argb, 358 int width, int height); 359 360// Convert MJPG to ARGB. 361LIBYUV_API 362int MJPGToARGB(const uint8* sample, size_t sample_size, 363 uint8* argb, int argb_stride, 364 int w, int h, int dw, int dh); 365 366// Internal function - do not call directly. 367// Computes table of cumulative sum for image where the value is the sum 368// of all values above and to the left of the entry. Used by ARGBBlur. 369LIBYUV_API 370int ARGBComputeCumulativeSum(const uint8* src_argb, int src_stride_argb, 371 int32* dst_cumsum, int dst_stride32_cumsum, 372 int width, int height); 373 374// Blur ARGB image. 375// dst_cumsum table of width * (height + 1) * 16 bytes aligned to 376// 16 byte boundary. 377// dst_stride32_cumsum is number of ints in a row (width * 4). 378// radius is number of pixels around the center. e.g. 1 = 3x3. 2=5x5. 379// Blur is optimized for radius of 5 (11x11) or less. 380LIBYUV_API 381int ARGBBlur(const uint8* src_argb, int src_stride_argb, 382 uint8* dst_argb, int dst_stride_argb, 383 int32* dst_cumsum, int dst_stride32_cumsum, 384 int width, int height, int radius); 385 386// Multiply ARGB image by ARGB value. 387LIBYUV_API 388int ARGBShade(const uint8* src_argb, int src_stride_argb, 389 uint8* dst_argb, int dst_stride_argb, 390 int width, int height, uint32 value); 391 392// Interpolate between two ARGB images using specified amount of interpolation 393// (0 to 255) and store to destination. 394// 'interpolation' is specified as 8 bit fraction where 0 means 100% src_argb0 395// and 255 means 1% src_argb0 and 99% src_argb1. 396// Internally uses ARGBScale bilinear filtering. 397// Caveat: This function will write up to 16 bytes beyond the end of dst_argb. 398LIBYUV_API 399int ARGBInterpolate(const uint8* src_argb0, int src_stride_argb0, 400 const uint8* src_argb1, int src_stride_argb1, 401 uint8* dst_argb, int dst_stride_argb, 402 int width, int height, int interpolation); 403 404#if defined(__pnacl__) || defined(__CLR_VER) || \ 405 (defined(__i386__) && !defined(__SSE2__)) 406#define LIBYUV_DISABLE_X86 407#endif 408// The following are available on all x86 platforms: 409#if !defined(LIBYUV_DISABLE_X86) && \ 410 (defined(_M_IX86) || defined(__x86_64__) || defined(__i386__)) 411#define HAS_ARGBAFFINEROW_SSE2 412#endif 413 414// Row function for copying pixels from a source with a slope to a row 415// of destination. Useful for scaling, rotation, mirror, texture mapping. 416LIBYUV_API 417void ARGBAffineRow_C(const uint8* src_argb, int src_argb_stride, 418 uint8* dst_argb, const float* uv_dudv, int width); 419LIBYUV_API 420void ARGBAffineRow_SSE2(const uint8* src_argb, int src_argb_stride, 421 uint8* dst_argb, const float* uv_dudv, int width); 422 423// Shuffle ARGB channel order. e.g. BGRA to ARGB. 424// shuffler is 16 bytes and must be aligned. 425LIBYUV_API 426int ARGBShuffle(const uint8* src_bgra, int src_stride_bgra, 427 uint8* dst_argb, int dst_stride_argb, 428 const uint8* shuffler, int width, int height); 429 430// Sobel ARGB effect with planar output. 431LIBYUV_API 432int ARGBSobelToPlane(const uint8* src_argb, int src_stride_argb, 433 uint8* dst_y, int dst_stride_y, 434 int width, int height); 435 436// Sobel ARGB effect. 437LIBYUV_API 438int ARGBSobel(const uint8* src_argb, int src_stride_argb, 439 uint8* dst_argb, int dst_stride_argb, 440 int width, int height); 441 442// Sobel ARGB effect w/ Sobel X, Sobel, Sobel Y in ARGB. 443LIBYUV_API 444int ARGBSobelXY(const uint8* src_argb, int src_stride_argb, 445 uint8* dst_argb, int dst_stride_argb, 446 int width, int height); 447 448#ifdef __cplusplus 449} // extern "C" 450} // namespace libyuv 451#endif 452 453#endif // INCLUDE_LIBYUV_PLANAR_FUNCTIONS_H_ NOLINT 454