OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCodecPriv.h" | 8 #include "SkCodecPriv.h" |
9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 #include "SkOpts.h" | 10 #include "SkOpts.h" |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 // This may miss opportunities to skip when the output is premultiplied, | 654 // This may miss opportunities to skip when the output is premultiplied, |
655 // e.g. for a src pixel 0x00FFFFFF which is not zero but becomes zero after
premultiplication. | 655 // e.g. for a src pixel 0x00FFFFFF which is not zero but becomes zero after
premultiplication. |
656 while (dstWidth > 0 && *src32 == 0x00000000) { | 656 while (dstWidth > 0 && *src32 == 0x00000000) { |
657 dstWidth--; | 657 dstWidth--; |
658 dst32++; | 658 dst32++; |
659 src32 += deltaSrc/4; | 659 src32 += deltaSrc/4; |
660 } | 660 } |
661 proc(dst32, (const uint8_t*)src32, dstWidth, bpp, deltaSrc, 0, ctable); | 661 proc(dst32, (const uint8_t*)src32, dstWidth, bpp, deltaSrc, 0, ctable); |
662 } | 662 } |
663 | 663 |
664 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, | 664 SkSwizzler* SkSwizzler::CreateSwizzler(const SkEncodedInfo& encodedInfo, |
665 const SkPMColor* ctable, | 665 const SkPMColor* ctable, |
666 const SkImageInfo& dstInfo, | 666 const SkImageInfo& dstInfo, |
667 const SkCodec::Options& options, | 667 const SkCodec::Options& options, |
668 const SkIRect* frame) { | 668 const SkIRect* frame) { |
669 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { | 669 if (SkEncodedInfo::kPalette_Color == encodedInfo.color() && nullptr == ctabl
e) { |
670 return nullptr; | 670 return nullptr; |
671 } | 671 } |
672 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) | 672 |
673 && nullptr == ctable) { | |
674 return nullptr; | |
675 } | |
676 RowProc fastProc = nullptr; | 673 RowProc fastProc = nullptr; |
677 RowProc proc = nullptr; | 674 RowProc proc = nullptr; |
678 SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized; | 675 SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized; |
679 switch (sc) { | 676 const bool premultiply = (SkEncodedInfo::kOpaque_Alpha != encodedInfo.alpha(
)) && |
680 case kBit: | 677 (kPremul_SkAlphaType == dstInfo.alphaType()); |
| 678 switch (encodedInfo.color()) { |
| 679 case SkEncodedInfo::kGray_Color: |
| 680 switch (encodedInfo.bitsPerComponent()) { |
| 681 case 1: |
| 682 switch (dstInfo.colorType()) { |
| 683 case kN32_SkColorType: |
| 684 proc = &swizzle_bit_to_n32; |
| 685 break; |
| 686 case kIndex_8_SkColorType: |
| 687 proc = &swizzle_bit_to_index; |
| 688 break; |
| 689 case kRGB_565_SkColorType: |
| 690 proc = &swizzle_bit_to_565; |
| 691 break; |
| 692 case kGray_8_SkColorType: |
| 693 proc = &swizzle_bit_to_grayscale; |
| 694 break; |
| 695 default: |
| 696 return nullptr; |
| 697 } |
| 698 break; |
| 699 case 8: |
| 700 switch (dstInfo.colorType()) { |
| 701 case kN32_SkColorType: |
| 702 proc = &swizzle_gray_to_n32; |
| 703 fastProc = &fast_swizzle_gray_to_n32; |
| 704 break; |
| 705 case kGray_8_SkColorType: |
| 706 proc = &sample1; |
| 707 fastProc = © |
| 708 break; |
| 709 case kRGB_565_SkColorType: |
| 710 proc = &swizzle_gray_to_565; |
| 711 break; |
| 712 default: |
| 713 return nullptr; |
| 714 } |
| 715 break; |
| 716 default: |
| 717 return nullptr; |
| 718 } |
| 719 break; |
| 720 case SkEncodedInfo::kGrayAlpha_Color: |
681 switch (dstInfo.colorType()) { | 721 switch (dstInfo.colorType()) { |
682 case kN32_SkColorType: | 722 case kN32_SkColorType: |
683 proc = &swizzle_bit_to_n32; | 723 if (premultiply) { |
684 break; | 724 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
685 case kIndex_8_SkColorType: | 725 proc = &SkipLeadingGrayAlphaZerosThen<swizzle_grayal
pha_to_n32_premul>; |
686 proc = &swizzle_bit_to_index; | 726 fastProc = &SkipLeadingGrayAlphaZerosThen |
687 break; | 727 <fast_swizzle_grayalpha_to_n32_premul>; |
688 case kRGB_565_SkColorType: | 728 } else { |
689 proc = &swizzle_bit_to_565; | 729 proc = &swizzle_grayalpha_to_n32_premul; |
690 break; | 730 fastProc = &fast_swizzle_grayalpha_to_n32_premul; |
691 case kGray_8_SkColorType: | 731 } |
692 proc = &swizzle_bit_to_grayscale; | |
693 break; | |
694 default: | |
695 break; | |
696 } | |
697 break; | |
698 case kIndex1: | |
699 case kIndex2: | |
700 case kIndex4: | |
701 switch (dstInfo.colorType()) { | |
702 case kN32_SkColorType: | |
703 proc = &swizzle_small_index_to_n32; | |
704 break; | |
705 case kRGB_565_SkColorType: | |
706 proc = &swizzle_small_index_to_565; | |
707 break; | |
708 case kIndex_8_SkColorType: | |
709 proc = &swizzle_small_index_to_index; | |
710 break; | |
711 default: | |
712 break; | |
713 } | |
714 break; | |
715 case kIndex: | |
716 switch (dstInfo.colorType()) { | |
717 case kN32_SkColorType: | |
718 // We assume the color premultiplied ctable (or not) as desi
red. | |
719 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | |
720 proc = &swizzle_index_to_n32_skipZ; | |
721 break; | |
722 } else { | 732 } else { |
723 proc = &swizzle_index_to_n32; | |
724 break; | |
725 } | |
726 break; | |
727 case kRGB_565_SkColorType: | |
728 proc = &swizzle_index_to_565; | |
729 break; | |
730 case kIndex_8_SkColorType: | |
731 proc = &sample1; | |
732 fastProc = © | |
733 break; | |
734 default: | |
735 break; | |
736 } | |
737 break; | |
738 case kGray: | |
739 switch (dstInfo.colorType()) { | |
740 case kN32_SkColorType: | |
741 proc = &swizzle_gray_to_n32; | |
742 fastProc = &fast_swizzle_gray_to_n32; | |
743 break; | |
744 case kGray_8_SkColorType: | |
745 proc = &sample1; | |
746 fastProc = © | |
747 break; | |
748 case kRGB_565_SkColorType: | |
749 proc = &swizzle_gray_to_565; | |
750 break; | |
751 default: | |
752 break; | |
753 } | |
754 break; | |
755 case kGrayAlpha: | |
756 switch (dstInfo.colorType()) { | |
757 case kN32_SkColorType: | |
758 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | |
759 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 733 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
760 proc = &SkipLeadingGrayAlphaZerosThen | 734 proc = &SkipLeadingGrayAlphaZerosThen |
761 <swizzle_grayalpha_to_n32_unpremul>; | 735 <swizzle_grayalpha_to_n32_unpremul>; |
762 fastProc = &SkipLeadingGrayAlphaZerosThen | 736 fastProc = &SkipLeadingGrayAlphaZerosThen |
763 <fast_swizzle_grayalpha_to_n32_unpremul>; | 737 <fast_swizzle_grayalpha_to_n32_unpremul>; |
764 } else { | 738 } else { |
765 proc = &swizzle_grayalpha_to_n32_unpremul; | 739 proc = &swizzle_grayalpha_to_n32_unpremul; |
766 fastProc = &fast_swizzle_grayalpha_to_n32_unpremul; | 740 fastProc = &fast_swizzle_grayalpha_to_n32_unpremul; |
767 } | 741 } |
| 742 } |
| 743 break; |
| 744 default: |
| 745 return nullptr; |
| 746 } |
| 747 break; |
| 748 case SkEncodedInfo::kPalette_Color: |
| 749 // We assume that the color table is premultiplied and swizzled |
| 750 // as desired. |
| 751 switch (encodedInfo.bitsPerComponent()) { |
| 752 case 1: |
| 753 case 2: |
| 754 case 4: |
| 755 switch (dstInfo.colorType()) { |
| 756 case kN32_SkColorType: |
| 757 proc = &swizzle_small_index_to_n32; |
| 758 break; |
| 759 case kRGB_565_SkColorType: |
| 760 proc = &swizzle_small_index_to_565; |
| 761 break; |
| 762 case kIndex_8_SkColorType: |
| 763 proc = &swizzle_small_index_to_index; |
| 764 break; |
| 765 default: |
| 766 return nullptr; |
| 767 } |
| 768 break; |
| 769 case 8: |
| 770 switch (dstInfo.colorType()) { |
| 771 case kN32_SkColorType: |
| 772 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 773 proc = &swizzle_index_to_n32_skipZ; |
| 774 } else { |
| 775 proc = &swizzle_index_to_n32; |
| 776 } |
| 777 break; |
| 778 case kRGB_565_SkColorType: |
| 779 proc = &swizzle_index_to_565; |
| 780 break; |
| 781 case kIndex_8_SkColorType: |
| 782 proc = &sample1; |
| 783 fastProc = © |
| 784 break; |
| 785 default: |
| 786 return nullptr; |
| 787 } |
| 788 break; |
| 789 default: |
| 790 return nullptr; |
| 791 } |
| 792 break; |
| 793 case SkEncodedInfo::kRGB_Color: |
| 794 switch (dstInfo.colorType()) { |
| 795 case kN32_SkColorType: |
| 796 proc = &swizzle_rgb_to_n32; |
| 797 fastProc = &fast_swizzle_rgb_to_n32; |
| 798 break; |
| 799 case kRGB_565_SkColorType: |
| 800 proc = &swizzle_rgb_to_565; |
| 801 break; |
| 802 default: |
| 803 return nullptr; |
| 804 } |
| 805 break; |
| 806 case SkEncodedInfo::kRGBA_Color: |
| 807 switch (dstInfo.colorType()) { |
| 808 case kN32_SkColorType: |
| 809 if (premultiply) { |
| 810 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 811 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
_premul>; |
| 812 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg
ba_to_n32_premul>; |
| 813 } else { |
| 814 proc = &swizzle_rgba_to_n32_premul; |
| 815 fastProc = &fast_swizzle_rgba_to_n32_premul; |
| 816 } |
768 } else { | 817 } else { |
769 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 818 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
770 proc = &SkipLeadingGrayAlphaZerosThen<swizzle_grayal
pha_to_n32_premul>; | 819 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
_unpremul>; |
771 fastProc = &SkipLeadingGrayAlphaZerosThen | 820 fastProc = &SkipLeading8888ZerosThen |
772 <fast_swizzle_grayalpha_to_n32_premul>; | 821 <fast_swizzle_rgba_to_n32_unpremul>; |
773 } else { | 822 } else { |
774 proc = &swizzle_grayalpha_to_n32_premul; | 823 proc = &swizzle_rgba_to_n32_unpremul; |
775 fastProc = &fast_swizzle_grayalpha_to_n32_premul; | 824 fastProc = &fast_swizzle_rgba_to_n32_unpremul; |
776 } | 825 } |
777 } | 826 } |
778 break; | 827 break; |
779 default: | 828 default: |
780 break; | 829 return nullptr; |
781 } | 830 } |
782 break; | 831 break; |
783 case kBGR: | 832 case SkEncodedInfo::kBGR_Color: |
784 case kBGRX: | |
785 switch (dstInfo.colorType()) { | 833 switch (dstInfo.colorType()) { |
786 case kN32_SkColorType: | 834 case kN32_SkColorType: |
787 proc = &swizzle_bgrx_to_n32; | 835 proc = &swizzle_bgrx_to_n32; |
788 break; | 836 break; |
789 case kRGB_565_SkColorType: | 837 case kRGB_565_SkColorType: |
790 proc = &swizzle_bgrx_to_565; | 838 proc = &swizzle_bgrx_to_565; |
791 break; | 839 break; |
792 default: | 840 default: |
793 break; | 841 return nullptr; |
794 } | 842 } |
795 break; | 843 break; |
796 case kBGRA: | 844 case SkEncodedInfo::kBGRX_Color: |
797 switch (dstInfo.colorType()) { | 845 switch (dstInfo.colorType()) { |
798 case kN32_SkColorType: | 846 case kN32_SkColorType: |
799 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 847 proc = &swizzle_bgrx_to_n32; |
800 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 848 break; |
801 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32
_unpremul>; | 849 case kRGB_565_SkColorType: |
802 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg
ra_to_n32_unpremul>; | 850 proc = &swizzle_bgrx_to_565; |
803 } else { | 851 break; |
804 proc = &swizzle_bgra_to_n32_unpremul; | 852 default: |
805 fastProc = &fast_swizzle_bgra_to_n32_unpremul; | 853 return nullptr; |
806 } | 854 } |
807 } else { | 855 break; |
| 856 case SkEncodedInfo::kBGRA_Color: |
| 857 switch (dstInfo.colorType()) { |
| 858 case kN32_SkColorType: |
| 859 if (premultiply) { |
808 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 860 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
809 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32
_premul>; | 861 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32
_premul>; |
810 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg
ra_to_n32_premul>; | 862 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg
ra_to_n32_premul>; |
811 } else { | 863 } else { |
812 proc = &swizzle_bgra_to_n32_premul; | 864 proc = &swizzle_bgra_to_n32_premul; |
813 fastProc = &fast_swizzle_bgra_to_n32_premul; | 865 fastProc = &fast_swizzle_bgra_to_n32_premul; |
814 } | 866 } |
815 } | 867 } else { |
816 break; | |
817 default: | |
818 break; | |
819 } | |
820 break; | |
821 case kRGB: | |
822 switch (dstInfo.colorType()) { | |
823 case kN32_SkColorType: | |
824 proc = &swizzle_rgb_to_n32; | |
825 fastProc = &fast_swizzle_rgb_to_n32; | |
826 break; | |
827 case kRGB_565_SkColorType: | |
828 proc = &swizzle_rgb_to_565; | |
829 break; | |
830 default: | |
831 break; | |
832 } | |
833 break; | |
834 case kRGBA: | |
835 switch (dstInfo.colorType()) { | |
836 case kN32_SkColorType: | |
837 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | |
838 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 868 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
839 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
_unpremul>; | 869 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
_unpremul>; |
840 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg
ba_to_n32_unpremul>; | 870 fastProc = &SkipLeading8888ZerosThen |
| 871 <fast_swizzle_bgra_to_n32_unpremul>; |
841 } else { | 872 } else { |
842 proc = &swizzle_rgba_to_n32_unpremul; | 873 proc = &swizzle_bgra_to_n32_unpremul; |
843 fastProc = &fast_swizzle_rgba_to_n32_unpremul; | 874 fastProc = &fast_swizzle_bgra_to_n32_unpremul; |
844 } | |
845 } else { | |
846 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | |
847 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
_premul>; | |
848 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg
ba_to_n32_premul>; | |
849 } else { | |
850 proc = &swizzle_rgba_to_n32_premul; | |
851 fastProc = &fast_swizzle_rgba_to_n32_premul; | |
852 } | 875 } |
853 } | 876 } |
854 break; | 877 break; |
855 default: | 878 default: |
856 break; | 879 return nullptr; |
857 } | 880 } |
858 break; | 881 break; |
859 case kCMYK: | 882 case SkEncodedInfo::kInvertedCMYK_Color: |
860 switch (dstInfo.colorType()) { | 883 switch (dstInfo.colorType()) { |
861 case kN32_SkColorType: | 884 case kN32_SkColorType: |
862 proc = &swizzle_cmyk_to_n32; | 885 proc = &swizzle_cmyk_to_n32; |
863 fastProc = &fast_swizzle_cmyk_to_n32; | 886 fastProc = &fast_swizzle_cmyk_to_n32; |
864 break; | 887 break; |
865 case kRGB_565_SkColorType: | 888 case kRGB_565_SkColorType: |
866 proc = &swizzle_cmyk_to_565; | 889 proc = &swizzle_cmyk_to_565; |
867 break; | 890 break; |
868 default: | 891 default: |
869 break; | 892 return nullptr; |
870 } | 893 } |
871 break; | 894 break; |
872 case kNoOp8: | 895 case SkEncodedInfo::kPreSwizzled_Color: |
873 proc = &sample1; | 896 switch (dstInfo.colorType()) { |
874 fastProc = © | 897 case kGray_8_SkColorType: |
875 break; | 898 proc = &sample1; |
876 case kNoOp16: | 899 fastProc = © |
877 proc = sample2; | 900 break; |
878 fastProc = © | 901 case kRGB_565_SkColorType: |
879 break; | 902 proc = &sample2; |
880 case kNoOp32: | 903 fastProc = © |
881 proc = &sample4; | 904 break; |
882 fastProc = © | 905 case kN32_SkColorType: |
| 906 proc = &sample4; |
| 907 fastProc = © |
| 908 break; |
| 909 default: |
| 910 return nullptr; |
| 911 } |
883 break; | 912 break; |
884 default: | 913 default: |
885 break; | 914 return nullptr; |
886 } | 915 } |
887 | 916 |
888 // Store bpp in bytes if it is an even multiple, otherwise use bits | |
889 int srcBPP = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel
(sc); | |
890 int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType()); | 917 int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType()); |
| 918 int srcBPP; |
| 919 if (SkEncodedInfo::kPreSwizzled_Color == encodedInfo.color()) { |
| 920 srcBPP = dstBPP; |
| 921 } else { |
| 922 // Store bpp in bytes if it is an even multiple, otherwise use bits |
| 923 uint8_t bitsPerPixel = encodedInfo.bitsPerPixel(); |
| 924 srcBPP = SkIsAlign8(bitsPerPixel) ? bitsPerPixel / 8 : bitsPerPixel; |
| 925 } |
891 | 926 |
892 int srcOffset = 0; | 927 int srcOffset = 0; |
893 int srcWidth = dstInfo.width(); | 928 int srcWidth = dstInfo.width(); |
894 int dstOffset = 0; | 929 int dstOffset = 0; |
895 int dstWidth = srcWidth; | 930 int dstWidth = srcWidth; |
896 if (options.fSubset) { | 931 if (options.fSubset) { |
897 // We do not currently support subset decodes for image types that may h
ave | 932 // We do not currently support subset decodes for image types that may h
ave |
898 // frames (gif). | 933 // frames (gif). |
899 SkASSERT(!frame); | 934 SkASSERT(!frame); |
900 srcOffset = options.fSubset->left(); | 935 srcOffset = options.fSubset->left(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 } | 982 } |
948 | 983 |
949 return fAllocatedWidth; | 984 return fAllocatedWidth; |
950 } | 985 } |
951 | 986 |
952 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { | 987 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { |
953 SkASSERT(nullptr != dst && nullptr != src); | 988 SkASSERT(nullptr != dst && nullptr != src); |
954 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS
rcBPP, | 989 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS
rcBPP, |
955 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); | 990 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); |
956 } | 991 } |
OLD | NEW |