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" |
11 #include "SkSwizzler.h" | 11 #include "SkSwizzler.h" |
12 #include "SkTemplates.h" | 12 #include "SkTemplates.h" |
13 | 13 |
14 static void copy(void* dst, const uint8_t* src, int width, int bpp, int deltaSrc , int offset, | 14 static void copy(void* dst, const uint8_t* src, int width, int bpp, int deltaSrc , int offset, |
15 const SkPMColor ctable[]) { | 15 const SkPMColor ctable[]) { |
16 // This function must not be called if we are sampling. If we are not | 16 // This function must not be called if we are sampling. If we are not |
17 // sampling, deltaSrc should equal bpp. | 17 // sampling, deltaSrc should equal bpp. |
18 SkASSERT(deltaSrc == bpp); | 18 SkASSERT(deltaSrc == bpp); |
19 | 19 |
20 memcpy(dst, src + offset, width * bpp); | 20 memcpy(dst, src + offset, width * bpp); |
21 } | 21 } |
22 | 22 |
23 static void sample1(void* dst, const uint8_t* src, int width, int bpp, int delta Src, int offset, | 23 static void sample_1bpp(void* dst, const uint8_t* src, int width, int bpp, int d eltaSrc, int offset, |
24 const SkPMColor ctable[]) { | 24 const SkPMColor ctable[]) { |
25 src += offset; | 25 src += offset; |
26 uint8_t* dst8 = (uint8_t*) dst; | 26 uint8_t* dst8 = (uint8_t*) dst; |
27 for (int x = 0; x < width; x++) { | 27 for (int x = 0; x < width; x++) { |
28 dst8[x] = *src; | 28 dst8[x] = *src; |
29 src += deltaSrc; | 29 src += deltaSrc; |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 static void sample2(void* dst, const uint8_t* src, int width, int bpp, int delta Src, int offset, | 33 static void sample_2bpp(void* dst, const uint8_t* src, int width, int bpp, int d eltaSrc, int offset, |
34 const SkPMColor ctable[]) { | 34 const SkPMColor ctable[]) { |
35 src += offset; | 35 src += offset; |
36 uint16_t* dst16 = (uint16_t*) dst; | 36 uint16_t* dst16 = (uint16_t*) dst; |
37 for (int x = 0; x < width; x++) { | 37 for (int x = 0; x < width; x++) { |
38 dst16[x] = *((const uint16_t*) src); | 38 dst16[x] = *((const uint16_t*) src); |
39 src += deltaSrc; | 39 src += deltaSrc; |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 static void sample4(void* dst, const uint8_t* src, int width, int bpp, int delta Src, int offset, | 43 static void sample_4bpp(void* dst, const uint8_t* src, int width, int bpp, int d eltaSrc, int offset, |
44 const SkPMColor ctable[]) { | 44 const SkPMColor ctable[]) { |
45 src += offset; | 45 src += offset; |
46 uint32_t* dst32 = (uint32_t*) dst; | 46 uint32_t* dst32 = (uint32_t*) dst; |
47 for (int x = 0; x < width; x++) { | 47 for (int x = 0; x < width; x++) { |
48 dst32[x] = *((const uint32_t*) src); | 48 dst32[x] = *((const uint32_t*) src); |
49 src += deltaSrc; | 49 src += deltaSrc; |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 // kBit | 53 // kBit |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 // sampling, deltaSrc should equal bpp. | 496 // sampling, deltaSrc should equal bpp. |
497 SkASSERT(deltaSrc == bpp); | 497 SkASSERT(deltaSrc == bpp); |
498 | 498 |
499 #ifdef SK_PMCOLOR_IS_RGBA | 499 #ifdef SK_PMCOLOR_IS_RGBA |
500 SkOpts::RGBA_to_rgbA((uint32_t*) dst, src + offset, width); | 500 SkOpts::RGBA_to_rgbA((uint32_t*) dst, src + offset, width); |
501 #else | 501 #else |
502 SkOpts::RGBA_to_bgrA((uint32_t*) dst, src + offset, width); | 502 SkOpts::RGBA_to_bgrA((uint32_t*) dst, src + offset, width); |
503 #endif | 503 #endif |
504 } | 504 } |
505 | 505 |
506 static void fast_sample2_rgba_to_n32_premul( | |
507 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, | |
508 int offset, const SkPMColor ctable[]) { | |
509 | |
510 // This function should only be called if the sampleSize is 2. | |
511 SkASSERT(deltaSrc == 2*bpp); | |
512 | |
513 // TODO: Implementation. | |
514 } | |
515 | |
516 static void fast_sample4_rgba_to_n32_premul( | |
517 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, | |
518 int offset, const SkPMColor ctable[]) { | |
519 | |
520 // This function should only be called if the sampleSize is 4. | |
521 SkASSERT(deltaSrc == 4*bpp); | |
522 | |
523 // TODO: Implementation. | |
524 } | |
525 | |
526 static void fast_sample8_rgba_to_n32_premul( | |
527 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, | |
528 int offset, const SkPMColor ctable[]) { | |
529 | |
530 // This function should only be called if the sampleSize is 8. | |
531 SkASSERT(deltaSrc == 8*bpp); | |
532 | |
533 // TODO: Implementation. | |
534 } | |
535 | |
506 static void swizzle_rgba_to_n32_unpremul( | 536 static void swizzle_rgba_to_n32_unpremul( |
507 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 537 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
508 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 538 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
509 | 539 |
510 src += offset; | 540 src += offset; |
511 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); | 541 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); |
512 for (int x = 0; x < dstWidth; x++) { | 542 for (int x = 0; x < dstWidth; x++) { |
513 unsigned alpha = src[3]; | 543 unsigned alpha = src[3]; |
514 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); | 544 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); |
515 src += deltaSrc; | 545 src += deltaSrc; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
651 const SkImageInfo& dstInfo, | 681 const SkImageInfo& dstInfo, |
652 const SkCodec::Options& options, | 682 const SkCodec::Options& options, |
653 const SkIRect* frame) { | 683 const SkIRect* frame) { |
654 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { | 684 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { |
655 return nullptr; | 685 return nullptr; |
656 } | 686 } |
657 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) | 687 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) |
658 && nullptr == ctable) { | 688 && nullptr == ctable) { |
659 return nullptr; | 689 return nullptr; |
660 } | 690 } |
661 RowProc fastProc = nullptr; | 691 |
662 RowProc proc = nullptr; | 692 RowProc proc = nullptr; |
693 FastProcs fastProcs; | |
663 SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized; | 694 SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized; |
664 switch (sc) { | 695 switch (sc) { |
665 case kBit: | 696 case kBit: |
666 switch (dstInfo.colorType()) { | 697 switch (dstInfo.colorType()) { |
667 case kN32_SkColorType: | 698 case kN32_SkColorType: |
668 proc = &swizzle_bit_to_n32; | 699 proc = &swizzle_bit_to_n32; |
669 break; | 700 break; |
670 case kIndex_8_SkColorType: | 701 case kIndex_8_SkColorType: |
671 proc = &swizzle_bit_to_index; | 702 proc = &swizzle_bit_to_index; |
672 break; | 703 break; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
706 break; | 737 break; |
707 } else { | 738 } else { |
708 proc = &swizzle_index_to_n32; | 739 proc = &swizzle_index_to_n32; |
709 break; | 740 break; |
710 } | 741 } |
711 break; | 742 break; |
712 case kRGB_565_SkColorType: | 743 case kRGB_565_SkColorType: |
713 proc = &swizzle_index_to_565; | 744 proc = &swizzle_index_to_565; |
714 break; | 745 break; |
715 case kIndex_8_SkColorType: | 746 case kIndex_8_SkColorType: |
716 proc = &sample1; | 747 proc = &sample_1bpp; |
717 fastProc = © | 748 fastProcs.fSampleSize1 = © |
718 break; | 749 break; |
719 default: | 750 default: |
720 break; | 751 break; |
721 } | 752 } |
722 break; | 753 break; |
723 case kGray: | 754 case kGray: |
724 switch (dstInfo.colorType()) { | 755 switch (dstInfo.colorType()) { |
725 case kN32_SkColorType: | 756 case kN32_SkColorType: |
726 proc = &swizzle_gray_to_n32; | 757 proc = &swizzle_gray_to_n32; |
727 fastProc = &fast_swizzle_gray_to_n32; | 758 fastProcs.fSampleSize1 = &fast_swizzle_gray_to_n32; |
728 break; | 759 break; |
729 case kGray_8_SkColorType: | 760 case kGray_8_SkColorType: |
730 proc = &sample1; | 761 proc = &sample_1bpp; |
731 fastProc = © | 762 fastProcs.fSampleSize1 = © |
732 break; | 763 break; |
733 case kRGB_565_SkColorType: | 764 case kRGB_565_SkColorType: |
734 proc = &swizzle_gray_to_565; | 765 proc = &swizzle_gray_to_565; |
735 break; | 766 break; |
736 default: | 767 default: |
737 break; | 768 break; |
738 } | 769 } |
739 break; | 770 break; |
740 case kGrayAlpha: | 771 case kGrayAlpha: |
741 switch (dstInfo.colorType()) { | 772 switch (dstInfo.colorType()) { |
742 case kN32_SkColorType: | 773 case kN32_SkColorType: |
743 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 774 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { |
744 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 775 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
745 proc = &SkipLeadingGrayAlphaZerosThen | 776 proc = &SkipLeadingGrayAlphaZerosThen |
746 <swizzle_grayalpha_to_n32_unpremul>; | 777 <swizzle_grayalpha_to_n32_unpremul>; |
747 fastProc = &SkipLeadingGrayAlphaZerosThen | 778 fastProcs.fSampleSize1 = &SkipLeadingGrayAlphaZerosT hen |
748 <fast_swizzle_grayalpha_to_n32_unpremul>; | 779 <fast_swizzle_grayalpha_to_n32_unpremul>; |
749 } else { | 780 } else { |
750 proc = &swizzle_grayalpha_to_n32_unpremul; | 781 proc = &swizzle_grayalpha_to_n32_unpremul; |
751 fastProc = &fast_swizzle_grayalpha_to_n32_unpremul; | 782 fastProcs.fSampleSize1 = &fast_swizzle_grayalpha_to_ n32_unpremul; |
752 } | 783 } |
753 } else { | 784 } else { |
754 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 785 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
755 proc = &SkipLeadingGrayAlphaZerosThen<swizzle_grayal pha_to_n32_premul>; | 786 proc = &SkipLeadingGrayAlphaZerosThen<swizzle_grayal pha_to_n32_premul>; |
756 fastProc = &SkipLeadingGrayAlphaZerosThen | 787 fastProcs.fSampleSize1 = &SkipLeadingGrayAlphaZerosT hen |
757 <fast_swizzle_grayalpha_to_n32_premul>; | 788 <fast_swizzle_grayalpha_to_n32_premul>; |
758 } else { | 789 } else { |
759 proc = &swizzle_grayalpha_to_n32_premul; | 790 proc = &swizzle_grayalpha_to_n32_premul; |
760 fastProc = &fast_swizzle_grayalpha_to_n32_premul; | 791 fastProcs.fSampleSize1 = &fast_swizzle_grayalpha_to_ n32_premul; |
761 } | 792 } |
762 } | 793 } |
763 break; | 794 break; |
764 default: | 795 default: |
765 break; | 796 break; |
766 } | 797 } |
767 break; | 798 break; |
768 case kBGR: | 799 case kBGR: |
769 case kBGRX: | 800 case kBGRX: |
770 switch (dstInfo.colorType()) { | 801 switch (dstInfo.colorType()) { |
771 case kN32_SkColorType: | 802 case kN32_SkColorType: |
772 proc = &swizzle_bgrx_to_n32; | 803 proc = &swizzle_bgrx_to_n32; |
773 break; | 804 break; |
774 case kRGB_565_SkColorType: | 805 case kRGB_565_SkColorType: |
775 proc = &swizzle_bgrx_to_565; | 806 proc = &swizzle_bgrx_to_565; |
776 break; | 807 break; |
777 default: | 808 default: |
778 break; | 809 break; |
779 } | 810 } |
780 break; | 811 break; |
781 case kBGRA: | 812 case kBGRA: |
782 switch (dstInfo.colorType()) { | 813 switch (dstInfo.colorType()) { |
783 case kN32_SkColorType: | 814 case kN32_SkColorType: |
784 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 815 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { |
785 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 816 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
786 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32 _unpremul>; | 817 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32 _unpremul>; |
787 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg ra_to_n32_unpremul>; | 818 fastProcs.fSampleSize1 = &SkipLeading8888ZerosThen |
819 <fast_swizzle_bgra_to_n32_unpremul>; | |
788 } else { | 820 } else { |
789 proc = &swizzle_bgra_to_n32_unpremul; | 821 proc = &swizzle_bgra_to_n32_unpremul; |
790 fastProc = &fast_swizzle_bgra_to_n32_unpremul; | 822 fastProcs.fSampleSize1 = &fast_swizzle_bgra_to_n32_u npremul; |
791 } | 823 } |
792 } else { | 824 } else { |
793 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 825 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
794 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32 _premul>; | 826 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32 _premul>; |
795 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg ra_to_n32_premul>; | 827 fastProcs.fSampleSize1 = &SkipLeading8888ZerosThen |
828 <fast_swizzle_bgra_to_n32_premul>; | |
796 } else { | 829 } else { |
797 proc = &swizzle_bgra_to_n32_premul; | 830 proc = &swizzle_bgra_to_n32_premul; |
798 fastProc = &fast_swizzle_bgra_to_n32_premul; | 831 fastProcs.fSampleSize1 = &fast_swizzle_bgra_to_n32_p remul; |
799 } | 832 } |
800 } | 833 } |
801 break; | 834 break; |
802 default: | 835 default: |
803 break; | 836 break; |
804 } | 837 } |
805 break; | 838 break; |
806 case kRGB: | 839 case kRGB: |
807 switch (dstInfo.colorType()) { | 840 switch (dstInfo.colorType()) { |
808 case kN32_SkColorType: | 841 case kN32_SkColorType: |
809 proc = &swizzle_rgb_to_n32; | 842 proc = &swizzle_rgb_to_n32; |
810 fastProc = &fast_swizzle_rgb_to_n32; | 843 fastProcs.fSampleSize1 = &fast_swizzle_rgb_to_n32; |
811 break; | 844 break; |
812 case kRGB_565_SkColorType: | 845 case kRGB_565_SkColorType: |
813 proc = &swizzle_rgb_to_565; | 846 proc = &swizzle_rgb_to_565; |
814 default: | 847 default: |
815 break; | 848 break; |
816 } | 849 } |
817 break; | 850 break; |
818 case kRGBA: | 851 case kRGBA: |
819 switch (dstInfo.colorType()) { | 852 switch (dstInfo.colorType()) { |
820 case kN32_SkColorType: | 853 case kN32_SkColorType: |
821 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 854 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { |
822 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 855 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
823 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _unpremul>; | 856 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _unpremul>; |
824 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg ba_to_n32_unpremul>; | 857 fastProcs.fSampleSize1 = &SkipLeading8888ZerosThen |
858 <fast_swizzle_rgba_to_n32_unpremul>; | |
825 } else { | 859 } else { |
826 proc = &swizzle_rgba_to_n32_unpremul; | 860 proc = &swizzle_rgba_to_n32_unpremul; |
827 fastProc = &fast_swizzle_rgba_to_n32_unpremul; | 861 fastProcs.fSampleSize1 = &fast_swizzle_rgba_to_n32_u npremul; |
828 } | 862 } |
829 } else { | 863 } else { |
830 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 864 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
831 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _premul>; | 865 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _premul>; |
832 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg ba_to_n32_premul>; | 866 fastProcs.fSampleSize1 = &SkipLeading8888ZerosThen |
867 <fast_swizzle_rgba_to_n32_premul>; | |
868 fastProcs.fSampleSize2 = &SkipLeading8888ZerosThen | |
869 <fast_sample2_rgba_to_n32_premul>; | |
870 fastProcs.fSampleSize4 = &SkipLeading8888ZerosThen | |
871 <fast_sample4_rgba_to_n32_premul>; | |
872 fastProcs.fSampleSize8 = &SkipLeading8888ZerosThen | |
873 <fast_sample8_rgba_to_n32_premul>; | |
833 } else { | 874 } else { |
834 proc = &swizzle_rgba_to_n32_premul; | 875 proc = &swizzle_rgba_to_n32_premul; |
835 fastProc = &fast_swizzle_rgba_to_n32_premul; | 876 fastProcs.fSampleSize1 = &fast_swizzle_rgba_to_n32_p remul; |
877 fastProcs.fSampleSize2 = &fast_sample2_rgba_to_n32_p remul; | |
878 fastProcs.fSampleSize4 = &fast_sample4_rgba_to_n32_p remul; | |
879 fastProcs.fSampleSize8 = &fast_sample8_rgba_to_n32_p remul; | |
836 } | 880 } |
837 } | 881 } |
838 break; | 882 break; |
839 default: | 883 default: |
840 break; | 884 break; |
841 } | 885 } |
842 break; | 886 break; |
843 case kCMYK: | 887 case kCMYK: |
844 switch (dstInfo.colorType()) { | 888 switch (dstInfo.colorType()) { |
845 case kN32_SkColorType: | 889 case kN32_SkColorType: |
846 proc = &swizzle_cmyk_to_n32; | 890 proc = &swizzle_cmyk_to_n32; |
847 break; | 891 break; |
848 case kRGB_565_SkColorType: | 892 case kRGB_565_SkColorType: |
849 proc = &swizzle_cmyk_to_565; | 893 proc = &swizzle_cmyk_to_565; |
850 break; | 894 break; |
851 default: | 895 default: |
852 break; | 896 break; |
853 } | 897 } |
854 break; | 898 break; |
855 case kNoOp8: | 899 case kNoOp8: |
856 proc = &sample1; | 900 proc = &sample_1bpp; |
857 fastProc = © | 901 fastProcs.fSampleSize1 = © |
858 break; | 902 break; |
859 case kNoOp16: | 903 case kNoOp16: |
860 proc = sample2; | 904 proc = sample_2bpp; |
861 fastProc = © | 905 fastProcs.fSampleSize1 = © |
862 break; | 906 break; |
863 case kNoOp32: | 907 case kNoOp32: |
864 proc = &sample4; | 908 proc = &sample_4bpp; |
865 fastProc = © | 909 fastProcs.fSampleSize1 = © |
866 break; | 910 break; |
867 default: | 911 default: |
868 break; | 912 break; |
869 } | 913 } |
870 | 914 |
871 // Store bpp in bytes if it is an even multiple, otherwise use bits | 915 // Store bpp in bytes if it is an even multiple, otherwise use bits |
872 int srcBPP = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel (sc); | 916 int srcBPP = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel (sc); |
873 int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType()); | 917 int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType()); |
874 | 918 |
875 int srcOffset = 0; | 919 int srcOffset = 0; |
876 int srcWidth = dstInfo.width(); | 920 int srcWidth = dstInfo.width(); |
877 int dstOffset = 0; | 921 int dstOffset = 0; |
878 int dstWidth = srcWidth; | 922 int dstWidth = srcWidth; |
879 if (options.fSubset) { | 923 if (options.fSubset) { |
880 // We do not currently support subset decodes for image types that may h ave | 924 // We do not currently support subset decodes for image types that may h ave |
881 // frames (gif). | 925 // frames (gif). |
882 SkASSERT(!frame); | 926 SkASSERT(!frame); |
883 srcOffset = options.fSubset->left(); | 927 srcOffset = options.fSubset->left(); |
884 srcWidth = options.fSubset->width(); | 928 srcWidth = options.fSubset->width(); |
885 dstWidth = srcWidth; | 929 dstWidth = srcWidth; |
886 } else if (frame) { | 930 } else if (frame) { |
887 dstOffset = frame->left(); | 931 dstOffset = frame->left(); |
888 srcWidth = frame->width(); | 932 srcWidth = frame->width(); |
889 } | 933 } |
890 | 934 |
891 return new SkSwizzler(fastProc, proc, ctable, srcOffset, srcWidth, dstOffset , dstWidth, | 935 return new SkSwizzler(proc, fastProcs, ctable, srcOffset, srcWidth, dstOffse t, dstWidth, |
892 srcBPP, dstBPP); | 936 srcBPP, dstBPP); |
893 } | 937 } |
894 | 938 |
895 SkSwizzler::SkSwizzler(RowProc fastProc, RowProc proc, const SkPMColor* ctable, int srcOffset, | 939 SkSwizzler::SkSwizzler(RowProc proc, const FastProcs& fastProcs, const SkPMColor * ctable, |
896 int srcWidth, int dstOffset, int dstWidth, int srcBPP, int dstBPP) | 940 int srcOffset, int srcWidth, int dstOffset, int dstWidth, int srcBPP, in t dstBPP) |
897 : fFastProc(fastProc) | 941 : fSlowProc(proc) |
898 , fSlowProc(proc) | 942 , fFastProcs(fastProcs) |
899 , fActualProc(fFastProc ? fFastProc : fSlowProc) | 943 , fActualProc(fFastProcs.fSampleSize1 ? fFastProcs.fSampleSize1 : fSlowProc) |
900 , fColorTable(ctable) | 944 , fColorTable(ctable) |
901 , fSrcOffset(srcOffset) | 945 , fSrcOffset(srcOffset) |
902 , fDstOffset(dstOffset) | 946 , fDstOffset(dstOffset) |
903 , fSrcOffsetUnits(srcOffset * srcBPP) | 947 , fSrcOffsetUnits(srcOffset * srcBPP) |
904 , fDstOffsetBytes(dstOffset * dstBPP) | 948 , fDstOffsetBytes(dstOffset * dstBPP) |
905 , fSrcWidth(srcWidth) | 949 , fSrcWidth(srcWidth) |
906 , fDstWidth(dstWidth) | 950 , fDstWidth(dstWidth) |
907 , fSwizzleWidth(srcWidth) | 951 , fSwizzleWidth(srcWidth) |
908 , fAllocatedWidth(dstWidth) | 952 , fAllocatedWidth(dstWidth) |
909 , fSampleX(1) | 953 , fSampleX(1) |
910 , fSrcBPP(srcBPP) | 954 , fSrcBPP(srcBPP) |
911 , fDstBPP(dstBPP) | 955 , fDstBPP(dstBPP) |
912 {} | 956 {} |
913 | 957 |
914 int SkSwizzler::onSetSampleX(int sampleX) { | 958 int SkSwizzler::onSetSampleX(int sampleX) { |
915 SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be | 959 SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be |
916 // way to report failure? | 960 // way to report failure? |
917 fSampleX = sampleX; | 961 fSampleX = sampleX; |
918 fSrcOffsetUnits = (get_start_coord(sampleX) + fSrcOffset) * fSrcBPP; | 962 fSrcOffsetUnits = (get_start_coord(sampleX) + fSrcOffset) * fSrcBPP; |
919 fDstOffsetBytes = (fDstOffset / sampleX) * fDstBPP; | 963 fDstOffsetBytes = (fDstOffset / sampleX) * fDstBPP; |
920 fSwizzleWidth = get_scaled_dimension(fSrcWidth, sampleX); | 964 fSwizzleWidth = get_scaled_dimension(fSrcWidth, sampleX); |
921 fAllocatedWidth = get_scaled_dimension(fDstWidth, sampleX); | 965 fAllocatedWidth = get_scaled_dimension(fDstWidth, sampleX); |
922 | 966 |
923 // The optimized swizzler routines do not (yet) support sampling. | 967 // Choose an optimized swizzler function (if it exists). |
924 if (1 == fSampleX && fFastProc) { | 968 if (1 == fSampleX && fFastProcs.fSampleSize1) { |
scroggo
2016/02/09 13:06:10
Why not:
switch (fSampleX) {
case 1:
fActua
msarett
2016/02/10 00:36:19
I agree this is nicer. Done.
| |
925 fActualProc = fFastProc; | 969 fActualProc = fFastProcs.fSampleSize1; |
970 } else if (2 == fSampleX && fFastProcs.fSampleSize2) { | |
971 fActualProc = fFastProcs.fSampleSize2; | |
972 } else if (4 == fSampleX && fFastProcs.fSampleSize4) { | |
973 fActualProc = fFastProcs.fSampleSize4; | |
974 } else if (8 == fSampleX && fFastProcs.fSampleSize8) { | |
975 fActualProc = fFastProcs.fSampleSize8; | |
926 } else { | 976 } else { |
927 fActualProc = fSlowProc; | 977 fActualProc = fSlowProc; |
928 } | 978 } |
929 | 979 |
930 return fAllocatedWidth; | 980 return fAllocatedWidth; |
931 } | 981 } |
932 | 982 |
933 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { | 983 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { |
934 SkASSERT(nullptr != dst && nullptr != src); | 984 SkASSERT(nullptr != dst && nullptr != src); |
935 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS rcBPP, | 985 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS rcBPP, |
936 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); | 986 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); |
937 } | 987 } |
OLD | NEW |