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