| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2012 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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 uint8* dst_vu, int dst_stride_vu, | 443 uint8* dst_vu, int dst_stride_vu, |
| 444 int width, int height) { | 444 int width, int height) { |
| 445 return I420ToNV12(src_y, src_stride_y, | 445 return I420ToNV12(src_y, src_stride_y, |
| 446 src_v, src_stride_v, | 446 src_v, src_stride_v, |
| 447 src_u, src_stride_u, | 447 src_u, src_stride_u, |
| 448 dst_y, src_stride_y, | 448 dst_y, src_stride_y, |
| 449 dst_vu, dst_stride_vu, | 449 dst_vu, dst_stride_vu, |
| 450 width, height); | 450 width, height); |
| 451 } | 451 } |
| 452 | 452 |
| 453 // Convert I420 to BGRA. | 453 // Convert I422 to RGBA with matrix |
| 454 LIBYUV_API | 454 static int I420ToRGBAMatrix(const uint8* src_y, int src_stride_y, |
| 455 int I420ToBGRA(const uint8* src_y, int src_stride_y, | 455 const uint8* src_u, int src_stride_u, |
| 456 const uint8* src_u, int src_stride_u, | 456 const uint8* src_v, int src_stride_v, |
| 457 const uint8* src_v, int src_stride_v, | 457 uint8* dst_rgba, int dst_stride_rgba, |
| 458 uint8* dst_bgra, int dst_stride_bgra, | 458 const struct YuvConstants* yuvconstants, |
| 459 int width, int height) { | 459 int width, int height) { |
| 460 int y; | |
| 461 void (*I422ToBGRARow)(const uint8* y_buf, | |
| 462 const uint8* u_buf, | |
| 463 const uint8* v_buf, | |
| 464 uint8* rgb_buf, | |
| 465 const struct YuvConstants* yuvconstants, | |
| 466 int width) = I422ToBGRARow_C; | |
| 467 if (!src_y || !src_u || !src_v || !dst_bgra || | |
| 468 width <= 0 || height == 0) { | |
| 469 return -1; | |
| 470 } | |
| 471 // Negative height means invert the image. | |
| 472 if (height < 0) { | |
| 473 height = -height; | |
| 474 dst_bgra = dst_bgra + (height - 1) * dst_stride_bgra; | |
| 475 dst_stride_bgra = -dst_stride_bgra; | |
| 476 } | |
| 477 #if defined(HAS_I422TOBGRAROW_SSSE3) | |
| 478 if (TestCpuFlag(kCpuHasSSSE3)) { | |
| 479 I422ToBGRARow = I422ToBGRARow_Any_SSSE3; | |
| 480 if (IS_ALIGNED(width, 8)) { | |
| 481 I422ToBGRARow = I422ToBGRARow_SSSE3; | |
| 482 } | |
| 483 } | |
| 484 #endif | |
| 485 #if defined(HAS_I422TOBGRAROW_AVX2) | |
| 486 if (TestCpuFlag(kCpuHasAVX2)) { | |
| 487 I422ToBGRARow = I422ToBGRARow_Any_AVX2; | |
| 488 if (IS_ALIGNED(width, 16)) { | |
| 489 I422ToBGRARow = I422ToBGRARow_AVX2; | |
| 490 } | |
| 491 } | |
| 492 #endif | |
| 493 #if defined(HAS_I422TOBGRAROW_NEON) | |
| 494 if (TestCpuFlag(kCpuHasNEON)) { | |
| 495 I422ToBGRARow = I422ToBGRARow_Any_NEON; | |
| 496 if (IS_ALIGNED(width, 8)) { | |
| 497 I422ToBGRARow = I422ToBGRARow_NEON; | |
| 498 } | |
| 499 } | |
| 500 #endif | |
| 501 #if defined(HAS_I422TOBGRAROW_MIPS_DSPR2) | |
| 502 if (TestCpuFlag(kCpuHasMIPS_DSPR2) && IS_ALIGNED(width, 4) && | |
| 503 IS_ALIGNED(src_y, 4) && IS_ALIGNED(src_stride_y, 4) && | |
| 504 IS_ALIGNED(src_u, 2) && IS_ALIGNED(src_stride_u, 2) && | |
| 505 IS_ALIGNED(src_v, 2) && IS_ALIGNED(src_stride_v, 2) && | |
| 506 IS_ALIGNED(dst_bgra, 4) && IS_ALIGNED(dst_stride_bgra, 4)) { | |
| 507 I422ToBGRARow = I422ToBGRARow_MIPS_DSPR2; | |
| 508 } | |
| 509 #endif | |
| 510 | |
| 511 for (y = 0; y < height; ++y) { | |
| 512 I422ToBGRARow(src_y, src_u, src_v, dst_bgra, &kYuvIConstants, width); | |
| 513 dst_bgra += dst_stride_bgra; | |
| 514 src_y += src_stride_y; | |
| 515 if (y & 1) { | |
| 516 src_u += src_stride_u; | |
| 517 src_v += src_stride_v; | |
| 518 } | |
| 519 } | |
| 520 return 0; | |
| 521 } | |
| 522 | |
| 523 // Convert I420 to RGBA. | |
| 524 LIBYUV_API | |
| 525 int I420ToRGBA(const uint8* src_y, int src_stride_y, | |
| 526 const uint8* src_u, int src_stride_u, | |
| 527 const uint8* src_v, int src_stride_v, | |
| 528 uint8* dst_rgba, int dst_stride_rgba, | |
| 529 int width, int height) { | |
| 530 int y; | 460 int y; |
| 531 void (*I422ToRGBARow)(const uint8* y_buf, | 461 void (*I422ToRGBARow)(const uint8* y_buf, |
| 532 const uint8* u_buf, | 462 const uint8* u_buf, |
| 533 const uint8* v_buf, | 463 const uint8* v_buf, |
| 534 uint8* rgb_buf, | 464 uint8* rgb_buf, |
| 535 const struct YuvConstants* yuvconstants, | 465 const struct YuvConstants* yuvconstants, |
| 536 int width) = I422ToRGBARow_C; | 466 int width) = I422ToRGBARow_C; |
| 537 if (!src_y || !src_u || !src_v || !dst_rgba || | 467 if (!src_y || !src_u || !src_v || !dst_rgba || |
| 538 width <= 0 || height == 0) { | 468 width <= 0 || height == 0) { |
| 539 return -1; | 469 return -1; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 561 } | 491 } |
| 562 #endif | 492 #endif |
| 563 #if defined(HAS_I422TORGBAROW_NEON) | 493 #if defined(HAS_I422TORGBAROW_NEON) |
| 564 if (TestCpuFlag(kCpuHasNEON)) { | 494 if (TestCpuFlag(kCpuHasNEON)) { |
| 565 I422ToRGBARow = I422ToRGBARow_Any_NEON; | 495 I422ToRGBARow = I422ToRGBARow_Any_NEON; |
| 566 if (IS_ALIGNED(width, 8)) { | 496 if (IS_ALIGNED(width, 8)) { |
| 567 I422ToRGBARow = I422ToRGBARow_NEON; | 497 I422ToRGBARow = I422ToRGBARow_NEON; |
| 568 } | 498 } |
| 569 } | 499 } |
| 570 #endif | 500 #endif |
| 501 #if defined(HAS_I422TORGBAROW_MIPS_DSPR2) |
| 502 if (TestCpuFlag(kCpuHasMIPS_DSPR2) && IS_ALIGNED(width, 4) && |
| 503 IS_ALIGNED(src_y, 4) && IS_ALIGNED(src_stride_y, 4) && |
| 504 IS_ALIGNED(src_u, 2) && IS_ALIGNED(src_stride_u, 2) && |
| 505 IS_ALIGNED(src_v, 2) && IS_ALIGNED(src_stride_v, 2) && |
| 506 IS_ALIGNED(dst_rgba, 4) && IS_ALIGNED(dst_stride_rgba, 4)) { |
| 507 I422ToRGBARow = I422ToRGBARow_MIPS_DSPR2; |
| 508 } |
| 509 #endif |
| 571 | 510 |
| 572 for (y = 0; y < height; ++y) { | 511 for (y = 0; y < height; ++y) { |
| 573 I422ToRGBARow(src_y, src_u, src_v, dst_rgba, &kYuvIConstants, width); | 512 I422ToRGBARow(src_y, src_u, src_v, dst_rgba, yuvconstants, width); |
| 574 dst_rgba += dst_stride_rgba; | 513 dst_rgba += dst_stride_rgba; |
| 575 src_y += src_stride_y; | 514 src_y += src_stride_y; |
| 576 if (y & 1) { | 515 if (y & 1) { |
| 577 src_u += src_stride_u; | 516 src_u += src_stride_u; |
| 578 src_v += src_stride_v; | 517 src_v += src_stride_v; |
| 579 } | 518 } |
| 580 } | 519 } |
| 581 return 0; | 520 return 0; |
| 582 } | 521 } |
| 583 | 522 |
| 584 // Convert I420 to RGB24. | 523 // Convert I420 to RGBA. |
| 585 LIBYUV_API | 524 LIBYUV_API |
| 586 int I420ToRGB24(const uint8* src_y, int src_stride_y, | 525 int I420ToRGBA(const uint8* src_y, int src_stride_y, |
| 587 const uint8* src_u, int src_stride_u, | 526 const uint8* src_u, int src_stride_u, |
| 588 const uint8* src_v, int src_stride_v, | 527 const uint8* src_v, int src_stride_v, |
| 589 uint8* dst_rgb24, int dst_stride_rgb24, | 528 uint8* dst_rgba, int dst_stride_rgba, |
| 590 int width, int height) { | 529 int width, int height) { |
| 530 return I420ToRGBAMatrix(src_y, src_stride_y, |
| 531 src_u, src_stride_u, |
| 532 src_v, src_stride_v, |
| 533 dst_rgba, dst_stride_rgba, |
| 534 &kYuvIConstants, |
| 535 width, height); |
| 536 } |
| 537 |
| 538 // Convert I420 to BGRA. |
| 539 LIBYUV_API |
| 540 int I420ToBGRA(const uint8* src_y, int src_stride_y, |
| 541 const uint8* src_u, int src_stride_u, |
| 542 const uint8* src_v, int src_stride_v, |
| 543 uint8* dst_bgra, int dst_stride_bgra, |
| 544 int width, int height) { |
| 545 return I420ToRGBAMatrix(src_y, src_stride_y, |
| 546 src_v, src_stride_v, // Swap U and V |
| 547 src_u, src_stride_u, |
| 548 dst_bgra, dst_stride_bgra, |
| 549 &kYvuIConstants, // Use Yvu matrix |
| 550 width, height); |
| 551 } |
| 552 |
| 553 // Convert I420 to RGB24 with matrix |
| 554 static int I420ToRGB24Matrix(const uint8* src_y, int src_stride_y, |
| 555 const uint8* src_u, int src_stride_u, |
| 556 const uint8* src_v, int src_stride_v, |
| 557 uint8* dst_rgb24, int dst_stride_rgb24, |
| 558 const struct YuvConstants* yuvconstants, |
| 559 int width, int height) { |
| 591 int y; | 560 int y; |
| 592 void (*I422ToRGB24Row)(const uint8* y_buf, | 561 void (*I422ToRGB24Row)(const uint8* y_buf, |
| 593 const uint8* u_buf, | 562 const uint8* u_buf, |
| 594 const uint8* v_buf, | 563 const uint8* v_buf, |
| 595 uint8* rgb_buf, | 564 uint8* rgb_buf, |
| 596 const struct YuvConstants* yuvconstants, | 565 const struct YuvConstants* yuvconstants, |
| 597 int width) = I422ToRGB24Row_C; | 566 int width) = I422ToRGB24Row_C; |
| 598 if (!src_y || !src_u || !src_v || !dst_rgb24 || | 567 if (!src_y || !src_u || !src_v || !dst_rgb24 || |
| 599 width <= 0 || height == 0) { | 568 width <= 0 || height == 0) { |
| 600 return -1; | 569 return -1; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 624 #if defined(HAS_I422TORGB24ROW_NEON) | 593 #if defined(HAS_I422TORGB24ROW_NEON) |
| 625 if (TestCpuFlag(kCpuHasNEON)) { | 594 if (TestCpuFlag(kCpuHasNEON)) { |
| 626 I422ToRGB24Row = I422ToRGB24Row_Any_NEON; | 595 I422ToRGB24Row = I422ToRGB24Row_Any_NEON; |
| 627 if (IS_ALIGNED(width, 8)) { | 596 if (IS_ALIGNED(width, 8)) { |
| 628 I422ToRGB24Row = I422ToRGB24Row_NEON; | 597 I422ToRGB24Row = I422ToRGB24Row_NEON; |
| 629 } | 598 } |
| 630 } | 599 } |
| 631 #endif | 600 #endif |
| 632 | 601 |
| 633 for (y = 0; y < height; ++y) { | 602 for (y = 0; y < height; ++y) { |
| 634 I422ToRGB24Row(src_y, src_u, src_v, dst_rgb24, &kYuvIConstants, width); | 603 I422ToRGB24Row(src_y, src_u, src_v, dst_rgb24, yuvconstants, width); |
| 635 dst_rgb24 += dst_stride_rgb24; | 604 dst_rgb24 += dst_stride_rgb24; |
| 636 src_y += src_stride_y; | 605 src_y += src_stride_y; |
| 637 if (y & 1) { | 606 if (y & 1) { |
| 638 src_u += src_stride_u; | 607 src_u += src_stride_u; |
| 639 src_v += src_stride_v; | 608 src_v += src_stride_v; |
| 640 } | 609 } |
| 641 } | 610 } |
| 642 return 0; | 611 return 0; |
| 643 } | 612 } |
| 644 | 613 |
| 614 // Convert I420 to RGB24. |
| 615 LIBYUV_API |
| 616 int I420ToRGB24(const uint8* src_y, int src_stride_y, |
| 617 const uint8* src_u, int src_stride_u, |
| 618 const uint8* src_v, int src_stride_v, |
| 619 uint8* dst_rgb24, int dst_stride_rgb24, |
| 620 int width, int height) { |
| 621 return I420ToRGB24Matrix(src_y, src_stride_y, |
| 622 src_u, src_stride_u, |
| 623 src_v, src_stride_v, |
| 624 dst_rgb24, dst_stride_rgb24, |
| 625 &kYuvIConstants, |
| 626 width, height); |
| 627 } |
| 628 |
| 645 // Convert I420 to RAW. | 629 // Convert I420 to RAW. |
| 646 LIBYUV_API | 630 LIBYUV_API |
| 647 int I420ToRAW(const uint8* src_y, int src_stride_y, | 631 int I420ToRAW(const uint8* src_y, int src_stride_y, |
| 648 const uint8* src_u, int src_stride_u, | 632 const uint8* src_u, int src_stride_u, |
| 649 const uint8* src_v, int src_stride_v, | 633 const uint8* src_v, int src_stride_v, |
| 650 uint8* dst_raw, int dst_stride_raw, | 634 uint8* dst_raw, int dst_stride_raw, |
| 651 int width, int height) { | 635 int width, int height) { |
| 652 int y; | 636 return I420ToRGB24Matrix(src_y, src_stride_y, |
| 653 void (*I422ToRAWRow)(const uint8* y_buf, | 637 src_v, src_stride_v, // Swap U and V |
| 654 const uint8* u_buf, | 638 src_u, src_stride_u, |
| 655 const uint8* v_buf, | 639 dst_raw, dst_stride_raw, |
| 656 uint8* rgb_buf, | 640 &kYvuIConstants, // Use Yvu matrix |
| 657 const struct YuvConstants* yuvconstants, | 641 width, height); |
| 658 int width) = I422ToRAWRow_C; | |
| 659 if (!src_y || !src_u || !src_v || !dst_raw || | |
| 660 width <= 0 || height == 0) { | |
| 661 return -1; | |
| 662 } | |
| 663 // Negative height means invert the image. | |
| 664 if (height < 0) { | |
| 665 height = -height; | |
| 666 dst_raw = dst_raw + (height - 1) * dst_stride_raw; | |
| 667 dst_stride_raw = -dst_stride_raw; | |
| 668 } | |
| 669 #if defined(HAS_I422TORAWROW_SSSE3) | |
| 670 if (TestCpuFlag(kCpuHasSSSE3)) { | |
| 671 I422ToRAWRow = I422ToRAWRow_Any_SSSE3; | |
| 672 if (IS_ALIGNED(width, 8)) { | |
| 673 I422ToRAWRow = I422ToRAWRow_SSSE3; | |
| 674 } | |
| 675 } | |
| 676 #endif | |
| 677 #if defined(HAS_I422TORAWROW_AVX2) | |
| 678 if (TestCpuFlag(kCpuHasAVX2)) { | |
| 679 I422ToRAWRow = I422ToRAWRow_Any_AVX2; | |
| 680 if (IS_ALIGNED(width, 16)) { | |
| 681 I422ToRAWRow = I422ToRAWRow_AVX2; | |
| 682 } | |
| 683 } | |
| 684 #endif | |
| 685 #if defined(HAS_I422TORAWROW_NEON) | |
| 686 if (TestCpuFlag(kCpuHasNEON)) { | |
| 687 I422ToRAWRow = I422ToRAWRow_Any_NEON; | |
| 688 if (IS_ALIGNED(width, 8)) { | |
| 689 I422ToRAWRow = I422ToRAWRow_NEON; | |
| 690 } | |
| 691 } | |
| 692 #endif | |
| 693 | |
| 694 for (y = 0; y < height; ++y) { | |
| 695 I422ToRAWRow(src_y, src_u, src_v, dst_raw, &kYuvIConstants, width); | |
| 696 dst_raw += dst_stride_raw; | |
| 697 src_y += src_stride_y; | |
| 698 if (y & 1) { | |
| 699 src_u += src_stride_u; | |
| 700 src_v += src_stride_v; | |
| 701 } | |
| 702 } | |
| 703 return 0; | |
| 704 } | 642 } |
| 705 | 643 |
| 706 // Convert I420 to ARGB1555. | 644 // Convert I420 to ARGB1555. |
| 707 LIBYUV_API | 645 LIBYUV_API |
| 708 int I420ToARGB1555(const uint8* src_y, int src_stride_y, | 646 int I420ToARGB1555(const uint8* src_y, int src_stride_y, |
| 709 const uint8* src_u, int src_stride_u, | 647 const uint8* src_u, int src_stride_u, |
| 710 const uint8* src_v, int src_stride_v, | 648 const uint8* src_v, int src_stride_v, |
| 711 uint8* dst_argb1555, int dst_stride_argb1555, | 649 uint8* dst_argb1555, int dst_stride_argb1555, |
| 712 int width, int height) { | 650 int width, int height) { |
| 713 int y; | 651 int y; |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1220 default: | 1158 default: |
| 1221 return -1; // unknown fourcc - return failure code. | 1159 return -1; // unknown fourcc - return failure code. |
| 1222 } | 1160 } |
| 1223 return r; | 1161 return r; |
| 1224 } | 1162 } |
| 1225 | 1163 |
| 1226 #ifdef __cplusplus | 1164 #ifdef __cplusplus |
| 1227 } // extern "C" | 1165 } // extern "C" |
| 1228 } // namespace libyuv | 1166 } // namespace libyuv |
| 1229 #endif | 1167 #endif |
| OLD | NEW |