| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 src_argb = src_argb + (height - 1) * src_stride_argb; | 38 src_argb = src_argb + (height - 1) * src_stride_argb; |
| 39 src_stride_argb = -src_stride_argb; | 39 src_stride_argb = -src_stride_argb; |
| 40 } | 40 } |
| 41 | 41 |
| 42 CopyPlane(src_argb, src_stride_argb, dst_argb, dst_stride_argb, | 42 CopyPlane(src_argb, src_stride_argb, dst_argb, dst_stride_argb, |
| 43 width * 4, height); | 43 width * 4, height); |
| 44 return 0; | 44 return 0; |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Convert I444 to ARGB. | 47 // Convert I444 to ARGB. |
| 48 LIBYUV_API | |
| 49 static int I444ToARGBMatrix(const uint8* src_y, int src_stride_y, | 48 static int I444ToARGBMatrix(const uint8* src_y, int src_stride_y, |
| 50 const uint8* src_u, int src_stride_u, | 49 const uint8* src_u, int src_stride_u, |
| 51 const uint8* src_v, int src_stride_v, | 50 const uint8* src_v, int src_stride_v, |
| 52 uint8* dst_argb, int dst_stride_argb, | 51 uint8* dst_argb, int dst_stride_argb, |
| 53 const struct YuvConstants* yuvconstants, | 52 const struct YuvConstants* yuvconstants, |
| 54 int width, int height) { | 53 int width, int height) { |
| 55 int y; | 54 int y; |
| 56 void (*I444ToARGBRow)(const uint8* y_buf, | 55 void (*I444ToARGBRow)(const uint8* y_buf, |
| 57 const uint8* u_buf, | 56 const uint8* u_buf, |
| 58 const uint8* v_buf, | 57 const uint8* v_buf, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 uint8* dst_argb, int dst_stride_argb, | 121 uint8* dst_argb, int dst_stride_argb, |
| 123 int width, int height) { | 122 int width, int height) { |
| 124 return I444ToARGBMatrix(src_y, src_stride_y, | 123 return I444ToARGBMatrix(src_y, src_stride_y, |
| 125 src_u, src_stride_u, | 124 src_u, src_stride_u, |
| 126 src_v, src_stride_v, | 125 src_v, src_stride_v, |
| 127 dst_argb, dst_stride_argb, | 126 dst_argb, dst_stride_argb, |
| 128 &kYuvIConstants, | 127 &kYuvIConstants, |
| 129 width, height); | 128 width, height); |
| 130 } | 129 } |
| 131 | 130 |
| 131 // Convert I444 to ABGR. |
| 132 LIBYUV_API |
| 133 int I444ToABGR(const uint8* src_y, int src_stride_y, |
| 134 const uint8* src_u, int src_stride_u, |
| 135 const uint8* src_v, int src_stride_v, |
| 136 uint8* dst_abgr, int dst_stride_abgr, |
| 137 int width, int height) { |
| 138 return I444ToARGBMatrix(src_y, src_stride_y, |
| 139 src_v, src_stride_v, // Swap U and V |
| 140 src_u, src_stride_u, |
| 141 dst_abgr, dst_stride_abgr, |
| 142 &kYvuIConstants, // Use Yvu matrix |
| 143 width, height); |
| 144 } |
| 145 |
| 132 // Convert J444 to ARGB. | 146 // Convert J444 to ARGB. |
| 133 LIBYUV_API | 147 LIBYUV_API |
| 134 int J444ToARGB(const uint8* src_y, int src_stride_y, | 148 int J444ToARGB(const uint8* src_y, int src_stride_y, |
| 135 const uint8* src_u, int src_stride_u, | 149 const uint8* src_u, int src_stride_u, |
| 136 const uint8* src_v, int src_stride_v, | 150 const uint8* src_v, int src_stride_v, |
| 137 uint8* dst_argb, int dst_stride_argb, | 151 uint8* dst_argb, int dst_stride_argb, |
| 138 int width, int height) { | 152 int width, int height) { |
| 139 return I444ToARGBMatrix(src_y, src_stride_y, | 153 return I444ToARGBMatrix(src_y, src_stride_y, |
| 140 src_u, src_stride_u, | 154 src_u, src_stride_u, |
| 141 src_v, src_stride_v, | 155 src_v, src_stride_v, |
| 142 dst_argb, dst_stride_argb, | 156 dst_argb, dst_stride_argb, |
| 143 &kYuvJConstants, | 157 &kYuvJConstants, |
| 144 width, height); | 158 width, height); |
| 145 } | 159 } |
| 146 | 160 |
| 147 // Convert I444 to ABGR. | |
| 148 LIBYUV_API | |
| 149 int I444ToABGR(const uint8* src_y, int src_stride_y, | |
| 150 const uint8* src_u, int src_stride_u, | |
| 151 const uint8* src_v, int src_stride_v, | |
| 152 uint8* dst_abgr, int dst_stride_abgr, | |
| 153 int width, int height) { | |
| 154 return I444ToARGBMatrix(src_y, src_stride_y, | |
| 155 src_v, src_stride_v, | |
| 156 src_u, src_stride_u, | |
| 157 dst_abgr, dst_stride_abgr, | |
| 158 &kYvuIConstants, | |
| 159 width, height); | |
| 160 } | |
| 161 | |
| 162 // Convert I422 to ARGB. | 161 // Convert I422 to ARGB. |
| 163 LIBYUV_API | 162 LIBYUV_API |
| 164 int I422ToARGB(const uint8* src_y, int src_stride_y, | 163 int I422ToARGB(const uint8* src_y, int src_stride_y, |
| 165 const uint8* src_u, int src_stride_u, | 164 const uint8* src_u, int src_stride_u, |
| 166 const uint8* src_v, int src_stride_v, | 165 const uint8* src_v, int src_stride_v, |
| 167 uint8* dst_argb, int dst_stride_argb, | 166 uint8* dst_argb, int dst_stride_argb, |
| 168 int width, int height) { | 167 int width, int height) { |
| 169 int y; | 168 int y; |
| 170 void (*I422ToARGBRow)(const uint8* y_buf, | 169 void (*I422ToARGBRow)(const uint8* y_buf, |
| 171 const uint8* u_buf, | 170 const uint8* u_buf, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 I411ToARGBRow(src_y, src_u, src_v, dst_argb, &kYuvIConstants, width); | 299 I411ToARGBRow(src_y, src_u, src_v, dst_argb, &kYuvIConstants, width); |
| 301 dst_argb += dst_stride_argb; | 300 dst_argb += dst_stride_argb; |
| 302 src_y += src_stride_y; | 301 src_y += src_stride_y; |
| 303 src_u += src_stride_u; | 302 src_u += src_stride_u; |
| 304 src_v += src_stride_v; | 303 src_v += src_stride_v; |
| 305 } | 304 } |
| 306 return 0; | 305 return 0; |
| 307 } | 306 } |
| 308 | 307 |
| 309 // Convert I420 with Alpha to preattenuated ARGB. | 308 // Convert I420 with Alpha to preattenuated ARGB. |
| 310 LIBYUV_API | 309 static int I420AlphaToARGBMatrix(const uint8* src_y, int src_stride_y, |
| 311 int I420AlphaToARGB(const uint8* src_y, int src_stride_y, | 310 const uint8* src_u, int src_stride_u, |
| 312 const uint8* src_u, int src_stride_u, | 311 const uint8* src_v, int src_stride_v, |
| 313 const uint8* src_v, int src_stride_v, | 312 const uint8* src_a, int src_stride_a, |
| 314 const uint8* src_a, int src_stride_a, | 313 uint8* dst_argb, int dst_stride_argb, |
| 315 uint8* dst_argb, int dst_stride_argb, | 314 const struct YuvConstants* yuvconstants, |
| 316 int width, int height, int attenuate) { | 315 int width, int height, int attenuate) { |
| 317 int y; | 316 int y; |
| 318 void (*I422AlphaToARGBRow)(const uint8* y_buf, | 317 void (*I422AlphaToARGBRow)(const uint8* y_buf, |
| 319 const uint8* u_buf, | 318 const uint8* u_buf, |
| 320 const uint8* v_buf, | 319 const uint8* v_buf, |
| 321 const uint8* a_buf, | 320 const uint8* a_buf, |
| 322 uint8* dst_argb, | 321 uint8* dst_argb, |
| 323 const struct YuvConstants* yuvconstants, | 322 const struct YuvConstants* yuvconstants, |
| 324 int width) = I422AlphaToARGBRow_C; | 323 int width) = I422AlphaToARGBRow_C; |
| 325 void (*ARGBAttenuateRow)(const uint8* src_argb, uint8* dst_argb, | 324 void (*ARGBAttenuateRow)(const uint8* src_argb, uint8* dst_argb, |
| 326 int width) = ARGBAttenuateRow_C; | 325 int width) = ARGBAttenuateRow_C; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 #if defined(HAS_ARGBATTENUATEROW_NEON) | 385 #if defined(HAS_ARGBATTENUATEROW_NEON) |
| 387 if (TestCpuFlag(kCpuHasNEON)) { | 386 if (TestCpuFlag(kCpuHasNEON)) { |
| 388 ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; | 387 ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; |
| 389 if (IS_ALIGNED(width, 8)) { | 388 if (IS_ALIGNED(width, 8)) { |
| 390 ARGBAttenuateRow = ARGBAttenuateRow_NEON; | 389 ARGBAttenuateRow = ARGBAttenuateRow_NEON; |
| 391 } | 390 } |
| 392 } | 391 } |
| 393 #endif | 392 #endif |
| 394 | 393 |
| 395 for (y = 0; y < height; ++y) { | 394 for (y = 0; y < height; ++y) { |
| 396 I422AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, &kYuvIConstants, | 395 I422AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, |
| 397 width); | 396 width); |
| 398 if (attenuate) { | 397 if (attenuate) { |
| 399 ARGBAttenuateRow(dst_argb, dst_argb, width); | 398 ARGBAttenuateRow(dst_argb, dst_argb, width); |
| 400 } | 399 } |
| 401 dst_argb += dst_stride_argb; | 400 dst_argb += dst_stride_argb; |
| 402 src_a += src_stride_a; | 401 src_a += src_stride_a; |
| 403 src_y += src_stride_y; | 402 src_y += src_stride_y; |
| 404 if (y & 1) { | 403 if (y & 1) { |
| 405 src_u += src_stride_u; | 404 src_u += src_stride_u; |
| 406 src_v += src_stride_v; | 405 src_v += src_stride_v; |
| 407 } | 406 } |
| 408 } | 407 } |
| 409 return 0; | 408 return 0; |
| 410 } | 409 } |
| 411 | 410 |
| 412 // Convert I420 with Alpha to preattenuated ARGB. | 411 // Convert I420 with Alpha to preattenuated ARGB. |
| 413 LIBYUV_API | 412 LIBYUV_API |
| 413 int I420AlphaToARGB(const uint8* src_y, int src_stride_y, |
| 414 const uint8* src_u, int src_stride_u, |
| 415 const uint8* src_v, int src_stride_v, |
| 416 const uint8* src_a, int src_stride_a, |
| 417 uint8* dst_argb, int dst_stride_argb, |
| 418 int width, int height, int attenuate) { |
| 419 return I420AlphaToARGBMatrix(src_y, src_stride_y, |
| 420 src_u, src_stride_u, |
| 421 src_v, src_stride_v, |
| 422 src_a, src_stride_a, |
| 423 dst_argb, dst_stride_argb, |
| 424 &kYuvIConstants, |
| 425 width, height, attenuate); |
| 426 } |
| 427 |
| 428 // Convert I420 with Alpha to preattenuated ARGB. |
| 429 LIBYUV_API |
| 414 int I420AlphaToABGR(const uint8* src_y, int src_stride_y, | 430 int I420AlphaToABGR(const uint8* src_y, int src_stride_y, |
| 415 const uint8* src_u, int src_stride_u, | 431 const uint8* src_u, int src_stride_u, |
| 416 const uint8* src_v, int src_stride_v, | 432 const uint8* src_v, int src_stride_v, |
| 417 const uint8* src_a, int src_stride_a, | 433 const uint8* src_a, int src_stride_a, |
| 418 uint8* dst_abgr, int dst_stride_abgr, | 434 uint8* dst_abgr, int dst_stride_abgr, |
| 419 int width, int height, int attenuate) { | 435 int width, int height, int attenuate) { |
| 420 int y; | 436 return I420AlphaToARGBMatrix(src_y, src_stride_y, |
| 421 void (*I422AlphaToABGRRow)(const uint8* y_buf, | 437 src_v, src_stride_v, // Swap U and V |
| 422 const uint8* u_buf, | 438 src_u, src_stride_u, |
| 423 const uint8* v_buf, | 439 src_a, src_stride_a, |
| 424 const uint8* a_buf, | 440 dst_abgr, dst_stride_abgr, |
| 425 uint8* dst_abgr, | 441 &kYvuIConstants, // Use Yvu matrix |
| 426 const struct YuvConstants* yuvconstants, | 442 width, height, attenuate); |
| 427 int width) = I422AlphaToABGRRow_C; | |
| 428 void (*ARGBAttenuateRow)(const uint8* src_abgr, uint8* dst_abgr, | |
| 429 int width) = ARGBAttenuateRow_C; | |
| 430 if (!src_y || !src_u || !src_v || !dst_abgr || | |
| 431 width <= 0 || height == 0) { | |
| 432 return -1; | |
| 433 } | |
| 434 // Negative height means invert the image. | |
| 435 if (height < 0) { | |
| 436 height = -height; | |
| 437 dst_abgr = dst_abgr + (height - 1) * dst_stride_abgr; | |
| 438 dst_stride_abgr = -dst_stride_abgr; | |
| 439 } | |
| 440 #if defined(HAS_I422ALPHATOABGRROW_SSSE3) | |
| 441 if (TestCpuFlag(kCpuHasSSSE3)) { | |
| 442 I422AlphaToABGRRow = I422AlphaToABGRRow_Any_SSSE3; | |
| 443 if (IS_ALIGNED(width, 8)) { | |
| 444 I422AlphaToABGRRow = I422AlphaToABGRRow_SSSE3; | |
| 445 } | |
| 446 } | |
| 447 #endif | |
| 448 #if defined(HAS_I422ALPHATOABGRROW_AVX2) | |
| 449 if (TestCpuFlag(kCpuHasAVX2)) { | |
| 450 I422AlphaToABGRRow = I422AlphaToABGRRow_Any_AVX2; | |
| 451 if (IS_ALIGNED(width, 16)) { | |
| 452 I422AlphaToABGRRow = I422AlphaToABGRRow_AVX2; | |
| 453 } | |
| 454 } | |
| 455 #endif | |
| 456 #if defined(HAS_I422ALPHATOABGRROW_NEON) | |
| 457 if (TestCpuFlag(kCpuHasNEON)) { | |
| 458 I422AlphaToABGRRow = I422AlphaToABGRRow_Any_NEON; | |
| 459 if (IS_ALIGNED(width, 8)) { | |
| 460 I422AlphaToABGRRow = I422AlphaToABGRRow_NEON; | |
| 461 } | |
| 462 } | |
| 463 #endif | |
| 464 #if defined(HAS_I422ALPHATOABGRROW_MIPS_DSPR2) | |
| 465 if (TestCpuFlag(kCpuHasMIPS_DSPR2) && IS_ALIGNED(width, 4) && | |
| 466 IS_ALIGNED(src_y, 4) && IS_ALIGNED(src_stride_y, 4) && | |
| 467 IS_ALIGNED(src_u, 2) && IS_ALIGNED(src_stride_u, 2) && | |
| 468 IS_ALIGNED(src_v, 2) && IS_ALIGNED(src_stride_v, 2) && | |
| 469 IS_ALIGNED(dst_abgr, 4) && IS_ALIGNED(dst_stride_abgr, 4)) { | |
| 470 I422AlphaToABGRRow = I422AlphaToABGRRow_MIPS_DSPR2; | |
| 471 } | |
| 472 #endif | |
| 473 #if defined(HAS_ARGBATTENUATEROW_SSSE3) | |
| 474 if (TestCpuFlag(kCpuHasSSSE3)) { | |
| 475 ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; | |
| 476 if (IS_ALIGNED(width, 4)) { | |
| 477 ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; | |
| 478 } | |
| 479 } | |
| 480 #endif | |
| 481 #if defined(HAS_ARGBATTENUATEROW_AVX2) | |
| 482 if (TestCpuFlag(kCpuHasAVX2)) { | |
| 483 ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; | |
| 484 if (IS_ALIGNED(width, 8)) { | |
| 485 ARGBAttenuateRow = ARGBAttenuateRow_AVX2; | |
| 486 } | |
| 487 } | |
| 488 #endif | |
| 489 #if defined(HAS_ARGBATTENUATEROW_NEON) | |
| 490 if (TestCpuFlag(kCpuHasNEON)) { | |
| 491 ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; | |
| 492 if (IS_ALIGNED(width, 8)) { | |
| 493 ARGBAttenuateRow = ARGBAttenuateRow_NEON; | |
| 494 } | |
| 495 } | |
| 496 #endif | |
| 497 | |
| 498 for (y = 0; y < height; ++y) { | |
| 499 I422AlphaToABGRRow(src_y, src_u, src_v, src_a, dst_abgr, &kYuvIConstants, | |
| 500 width); | |
| 501 if (attenuate) { | |
| 502 ARGBAttenuateRow(dst_abgr, dst_abgr, width); | |
| 503 } | |
| 504 dst_abgr += dst_stride_abgr; | |
| 505 src_a += src_stride_a; | |
| 506 src_y += src_stride_y; | |
| 507 if (y & 1) { | |
| 508 src_u += src_stride_u; | |
| 509 src_v += src_stride_v; | |
| 510 } | |
| 511 } | |
| 512 return 0; | |
| 513 } | 443 } |
| 514 | 444 |
| 515 // Convert I400 to ARGB. | 445 // Convert I400 to ARGB. |
| 516 LIBYUV_API | 446 LIBYUV_API |
| 517 int I400ToARGB(const uint8* src_y, int src_stride_y, | 447 int I400ToARGB(const uint8* src_y, int src_stride_y, |
| 518 uint8* dst_argb, int dst_stride_argb, | 448 uint8* dst_argb, int dst_stride_argb, |
| 519 int width, int height) { | 449 int width, int height) { |
| 520 int y; | 450 int y; |
| 521 void (*I400ToARGBRow)(const uint8* y_buf, | 451 void (*I400ToARGBRow)(const uint8* y_buf, |
| 522 uint8* rgb_buf, | 452 uint8* rgb_buf, |
| (...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1858 src_u += src_stride_u; | 1788 src_u += src_stride_u; |
| 1859 src_v += src_stride_v; | 1789 src_v += src_stride_v; |
| 1860 } | 1790 } |
| 1861 return 0; | 1791 return 0; |
| 1862 } | 1792 } |
| 1863 | 1793 |
| 1864 #ifdef __cplusplus | 1794 #ifdef __cplusplus |
| 1865 } // extern "C" | 1795 } // extern "C" |
| 1866 } // namespace libyuv | 1796 } // namespace libyuv |
| 1867 #endif | 1797 #endif |
| OLD | NEW |