Chromium Code Reviews| 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 #ifdef SK_PMCOLOR_IS_RGBA | |
| 514 SkOpts::RGBA_to_rgbA_sample2((uint32_t*) dst, src + offset, width); | |
|
msarett
2016/02/10 00:36:19
For sampling, whether or not to add "offset" here
| |
| 515 #else | |
| 516 SkOpts::RGBA_to_bgrA_sample2((uint32_t*) dst, src + offset, width); | |
| 517 #endif | |
| 518 } | |
| 519 | |
| 520 static void fast_sample4_rgba_to_n32_premul( | |
| 521 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, | |
| 522 int offset, const SkPMColor ctable[]) { | |
| 523 | |
| 524 // This function should only be called if the sampleSize is 4. | |
| 525 SkASSERT(deltaSrc == 4*bpp); | |
| 526 | |
| 527 #ifdef SK_PMCOLOR_IS_RGBA | |
| 528 SkOpts::RGBA_to_rgbA_sample4((uint32_t*) dst, src + offset, width); | |
| 529 #else | |
| 530 SkOpts::RGBA_to_bgrA_sample4((uint32_t*) dst, src + offset, width); | |
| 531 #endif | |
| 532 } | |
| 533 | |
| 534 static void fast_sample8_rgba_to_n32_premul( | |
| 535 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, | |
| 536 int offset, const SkPMColor ctable[]) { | |
| 537 | |
| 538 // This function should only be called if the sampleSize is 8. | |
| 539 SkASSERT(deltaSrc == 8*bpp); | |
| 540 | |
| 541 #ifdef SK_PMCOLOR_IS_RGBA | |
| 542 SkOpts::RGBA_to_rgbA_sample8((uint32_t*) dst, src + offset, width); | |
| 543 #else | |
| 544 SkOpts::RGBA_to_bgrA_sample8((uint32_t*) dst, src + offset, width); | |
| 545 #endif | |
| 546 } | |
| 547 | |
| 506 static void swizzle_rgba_to_n32_unpremul( | 548 static void swizzle_rgba_to_n32_unpremul( |
| 507 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 549 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 508 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 550 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 509 | 551 |
| 510 src += offset; | 552 src += offset; |
| 511 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); | 553 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); |
| 512 for (int x = 0; x < dstWidth; x++) { | 554 for (int x = 0; x < dstWidth; x++) { |
| 513 unsigned alpha = src[3]; | 555 unsigned alpha = src[3]; |
| 514 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); | 556 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); |
| 515 src += deltaSrc; | 557 src += deltaSrc; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 666 const SkImageInfo& dstInfo, | 708 const SkImageInfo& dstInfo, |
| 667 const SkCodec::Options& options, | 709 const SkCodec::Options& options, |
| 668 const SkIRect* frame) { | 710 const SkIRect* frame) { |
| 669 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { | 711 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { |
| 670 return nullptr; | 712 return nullptr; |
| 671 } | 713 } |
| 672 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) | 714 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) |
| 673 && nullptr == ctable) { | 715 && nullptr == ctable) { |
| 674 return nullptr; | 716 return nullptr; |
| 675 } | 717 } |
| 676 RowProc fastProc = nullptr; | 718 |
| 677 RowProc proc = nullptr; | 719 RowProc proc = nullptr; |
| 720 FastProcs fastProcs; | |
| 678 SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized; | 721 SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized; |
| 679 switch (sc) { | 722 switch (sc) { |
| 680 case kBit: | 723 case kBit: |
| 681 switch (dstInfo.colorType()) { | 724 switch (dstInfo.colorType()) { |
| 682 case kN32_SkColorType: | 725 case kN32_SkColorType: |
| 683 proc = &swizzle_bit_to_n32; | 726 proc = &swizzle_bit_to_n32; |
| 684 break; | 727 break; |
| 685 case kIndex_8_SkColorType: | 728 case kIndex_8_SkColorType: |
| 686 proc = &swizzle_bit_to_index; | 729 proc = &swizzle_bit_to_index; |
| 687 break; | 730 break; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 721 break; | 764 break; |
| 722 } else { | 765 } else { |
| 723 proc = &swizzle_index_to_n32; | 766 proc = &swizzle_index_to_n32; |
| 724 break; | 767 break; |
| 725 } | 768 } |
| 726 break; | 769 break; |
| 727 case kRGB_565_SkColorType: | 770 case kRGB_565_SkColorType: |
| 728 proc = &swizzle_index_to_565; | 771 proc = &swizzle_index_to_565; |
| 729 break; | 772 break; |
| 730 case kIndex_8_SkColorType: | 773 case kIndex_8_SkColorType: |
| 731 proc = &sample1; | 774 proc = &sample_1bpp; |
| 732 fastProc = © | 775 fastProcs.fSampleSize1 = © |
| 733 break; | 776 break; |
| 734 default: | 777 default: |
| 735 break; | 778 break; |
| 736 } | 779 } |
| 737 break; | 780 break; |
| 738 case kGray: | 781 case kGray: |
| 739 switch (dstInfo.colorType()) { | 782 switch (dstInfo.colorType()) { |
| 740 case kN32_SkColorType: | 783 case kN32_SkColorType: |
| 741 proc = &swizzle_gray_to_n32; | 784 proc = &swizzle_gray_to_n32; |
| 742 fastProc = &fast_swizzle_gray_to_n32; | 785 fastProcs.fSampleSize1 = &fast_swizzle_gray_to_n32; |
| 743 break; | 786 break; |
| 744 case kGray_8_SkColorType: | 787 case kGray_8_SkColorType: |
| 745 proc = &sample1; | 788 proc = &sample_1bpp; |
| 746 fastProc = © | 789 fastProcs.fSampleSize1 = © |
| 747 break; | 790 break; |
| 748 case kRGB_565_SkColorType: | 791 case kRGB_565_SkColorType: |
| 749 proc = &swizzle_gray_to_565; | 792 proc = &swizzle_gray_to_565; |
| 750 break; | 793 break; |
| 751 default: | 794 default: |
| 752 break; | 795 break; |
| 753 } | 796 } |
| 754 break; | 797 break; |
| 755 case kGrayAlpha: | 798 case kGrayAlpha: |
| 756 switch (dstInfo.colorType()) { | 799 switch (dstInfo.colorType()) { |
| 757 case kN32_SkColorType: | 800 case kN32_SkColorType: |
| 758 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 801 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { |
| 759 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 802 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 760 proc = &SkipLeadingGrayAlphaZerosThen | 803 proc = &SkipLeadingGrayAlphaZerosThen |
| 761 <swizzle_grayalpha_to_n32_unpremul>; | 804 <swizzle_grayalpha_to_n32_unpremul>; |
| 762 fastProc = &SkipLeadingGrayAlphaZerosThen | 805 fastProcs.fSampleSize1 = &SkipLeadingGrayAlphaZerosT hen |
| 763 <fast_swizzle_grayalpha_to_n32_unpremul>; | 806 <fast_swizzle_grayalpha_to_n32_unpremul>; |
| 764 } else { | 807 } else { |
| 765 proc = &swizzle_grayalpha_to_n32_unpremul; | 808 proc = &swizzle_grayalpha_to_n32_unpremul; |
| 766 fastProc = &fast_swizzle_grayalpha_to_n32_unpremul; | 809 fastProcs.fSampleSize1 = &fast_swizzle_grayalpha_to_ n32_unpremul; |
| 767 } | 810 } |
| 768 } else { | 811 } else { |
| 769 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 812 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 770 proc = &SkipLeadingGrayAlphaZerosThen<swizzle_grayal pha_to_n32_premul>; | 813 proc = &SkipLeadingGrayAlphaZerosThen<swizzle_grayal pha_to_n32_premul>; |
| 771 fastProc = &SkipLeadingGrayAlphaZerosThen | 814 fastProcs.fSampleSize1 = &SkipLeadingGrayAlphaZerosT hen |
| 772 <fast_swizzle_grayalpha_to_n32_premul>; | 815 <fast_swizzle_grayalpha_to_n32_premul>; |
| 773 } else { | 816 } else { |
| 774 proc = &swizzle_grayalpha_to_n32_premul; | 817 proc = &swizzle_grayalpha_to_n32_premul; |
| 775 fastProc = &fast_swizzle_grayalpha_to_n32_premul; | 818 fastProcs.fSampleSize1 = &fast_swizzle_grayalpha_to_ n32_premul; |
| 776 } | 819 } |
| 777 } | 820 } |
| 778 break; | 821 break; |
| 779 default: | 822 default: |
| 780 break; | 823 break; |
| 781 } | 824 } |
| 782 break; | 825 break; |
| 783 case kBGR: | 826 case kBGR: |
| 784 case kBGRX: | 827 case kBGRX: |
| 785 switch (dstInfo.colorType()) { | 828 switch (dstInfo.colorType()) { |
| 786 case kN32_SkColorType: | 829 case kN32_SkColorType: |
| 787 proc = &swizzle_bgrx_to_n32; | 830 proc = &swizzle_bgrx_to_n32; |
| 788 break; | 831 break; |
| 789 case kRGB_565_SkColorType: | 832 case kRGB_565_SkColorType: |
| 790 proc = &swizzle_bgrx_to_565; | 833 proc = &swizzle_bgrx_to_565; |
| 791 break; | 834 break; |
| 792 default: | 835 default: |
| 793 break; | 836 break; |
| 794 } | 837 } |
| 795 break; | 838 break; |
| 796 case kBGRA: | 839 case kBGRA: |
| 797 switch (dstInfo.colorType()) { | 840 switch (dstInfo.colorType()) { |
| 798 case kN32_SkColorType: | 841 case kN32_SkColorType: |
| 799 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 842 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { |
| 800 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 843 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 801 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32 _unpremul>; | 844 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32 _unpremul>; |
| 802 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg ra_to_n32_unpremul>; | 845 fastProcs.fSampleSize1 = &SkipLeading8888ZerosThen |
| 846 <fast_swizzle_bgra_to_n32_unpremul>; | |
| 803 } else { | 847 } else { |
| 804 proc = &swizzle_bgra_to_n32_unpremul; | 848 proc = &swizzle_bgra_to_n32_unpremul; |
| 805 fastProc = &fast_swizzle_bgra_to_n32_unpremul; | 849 fastProcs.fSampleSize1 = &fast_swizzle_bgra_to_n32_u npremul; |
| 806 } | 850 } |
| 807 } else { | 851 } else { |
| 808 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 852 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 809 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32 _premul>; | 853 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32 _premul>; |
| 810 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg ra_to_n32_premul>; | 854 fastProcs.fSampleSize1 = &SkipLeading8888ZerosThen |
| 855 <fast_swizzle_bgra_to_n32_premul>; | |
| 811 } else { | 856 } else { |
| 812 proc = &swizzle_bgra_to_n32_premul; | 857 proc = &swizzle_bgra_to_n32_premul; |
| 813 fastProc = &fast_swizzle_bgra_to_n32_premul; | 858 fastProcs.fSampleSize1 = &fast_swizzle_bgra_to_n32_p remul; |
| 814 } | 859 } |
| 815 } | 860 } |
| 816 break; | 861 break; |
| 817 default: | 862 default: |
| 818 break; | 863 break; |
| 819 } | 864 } |
| 820 break; | 865 break; |
| 821 case kRGB: | 866 case kRGB: |
| 822 switch (dstInfo.colorType()) { | 867 switch (dstInfo.colorType()) { |
| 823 case kN32_SkColorType: | 868 case kN32_SkColorType: |
| 824 proc = &swizzle_rgb_to_n32; | 869 proc = &swizzle_rgb_to_n32; |
| 825 fastProc = &fast_swizzle_rgb_to_n32; | 870 fastProcs.fSampleSize1 = &fast_swizzle_rgb_to_n32; |
| 826 break; | 871 break; |
| 827 case kRGB_565_SkColorType: | 872 case kRGB_565_SkColorType: |
| 828 proc = &swizzle_rgb_to_565; | 873 proc = &swizzle_rgb_to_565; |
| 829 break; | 874 break; |
| 830 default: | 875 default: |
| 831 break; | 876 break; |
| 832 } | 877 } |
| 833 break; | 878 break; |
| 834 case kRGBA: | 879 case kRGBA: |
| 835 switch (dstInfo.colorType()) { | 880 switch (dstInfo.colorType()) { |
| 836 case kN32_SkColorType: | 881 case kN32_SkColorType: |
| 837 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 882 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { |
| 838 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 883 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 839 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _unpremul>; | 884 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _unpremul>; |
| 840 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg ba_to_n32_unpremul>; | 885 fastProcs.fSampleSize1 = &SkipLeading8888ZerosThen |
| 886 <fast_swizzle_rgba_to_n32_unpremul>; | |
| 841 } else { | 887 } else { |
| 842 proc = &swizzle_rgba_to_n32_unpremul; | 888 proc = &swizzle_rgba_to_n32_unpremul; |
| 843 fastProc = &fast_swizzle_rgba_to_n32_unpremul; | 889 fastProcs.fSampleSize1 = &fast_swizzle_rgba_to_n32_u npremul; |
| 844 } | 890 } |
| 845 } else { | 891 } else { |
| 846 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 892 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 847 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _premul>; | 893 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32 _premul>; |
| 848 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg ba_to_n32_premul>; | 894 fastProcs.fSampleSize1 = &SkipLeading8888ZerosThen |
| 895 <fast_swizzle_rgba_to_n32_premul>; | |
| 896 fastProcs.fSampleSize2 = &SkipLeading8888ZerosThen | |
| 897 <fast_sample2_rgba_to_n32_premul>; | |
| 898 fastProcs.fSampleSize4 = &SkipLeading8888ZerosThen | |
| 899 <fast_sample4_rgba_to_n32_premul>; | |
| 900 fastProcs.fSampleSize8 = &SkipLeading8888ZerosThen | |
| 901 <fast_sample8_rgba_to_n32_premul>; | |
| 849 } else { | 902 } else { |
| 850 proc = &swizzle_rgba_to_n32_premul; | 903 proc = &swizzle_rgba_to_n32_premul; |
| 851 fastProc = &fast_swizzle_rgba_to_n32_premul; | 904 fastProcs.fSampleSize1 = &fast_swizzle_rgba_to_n32_p remul; |
| 905 fastProcs.fSampleSize2 = &fast_sample2_rgba_to_n32_p remul; | |
| 906 fastProcs.fSampleSize4 = &fast_sample4_rgba_to_n32_p remul; | |
| 907 fastProcs.fSampleSize8 = &fast_sample8_rgba_to_n32_p remul; | |
| 852 } | 908 } |
| 853 } | 909 } |
| 854 break; | 910 break; |
| 855 default: | 911 default: |
| 856 break; | 912 break; |
| 857 } | 913 } |
| 858 break; | 914 break; |
| 859 case kCMYK: | 915 case kCMYK: |
| 860 switch (dstInfo.colorType()) { | 916 switch (dstInfo.colorType()) { |
| 861 case kN32_SkColorType: | 917 case kN32_SkColorType: |
| 862 proc = &swizzle_cmyk_to_n32; | 918 proc = &swizzle_cmyk_to_n32; |
| 863 fastProc = &fast_swizzle_cmyk_to_n32; | 919 fastProcs.fSampleSize1 = &fast_swizzle_cmyk_to_n32; |
| 864 break; | 920 break; |
| 865 case kRGB_565_SkColorType: | 921 case kRGB_565_SkColorType: |
| 866 proc = &swizzle_cmyk_to_565; | 922 proc = &swizzle_cmyk_to_565; |
| 867 break; | 923 break; |
| 868 default: | 924 default: |
| 869 break; | 925 break; |
| 870 } | 926 } |
| 871 break; | 927 break; |
| 872 case kNoOp8: | 928 case kNoOp8: |
| 873 proc = &sample1; | 929 proc = &sample_1bpp; |
| 874 fastProc = © | 930 fastProcs.fSampleSize1 = © |
| 875 break; | 931 break; |
| 876 case kNoOp16: | 932 case kNoOp16: |
| 877 proc = sample2; | 933 proc = sample_2bpp; |
| 878 fastProc = © | 934 fastProcs.fSampleSize1 = © |
| 879 break; | 935 break; |
| 880 case kNoOp32: | 936 case kNoOp32: |
| 881 proc = &sample4; | 937 proc = &sample_4bpp; |
| 882 fastProc = © | 938 fastProcs.fSampleSize1 = © |
| 883 break; | 939 break; |
| 884 default: | 940 default: |
| 885 break; | 941 break; |
| 886 } | 942 } |
| 887 | 943 |
| 888 // Store bpp in bytes if it is an even multiple, otherwise use bits | 944 // Store bpp in bytes if it is an even multiple, otherwise use bits |
| 889 int srcBPP = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel (sc); | 945 int srcBPP = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel (sc); |
| 890 int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType()); | 946 int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType()); |
| 891 | 947 |
| 892 int srcOffset = 0; | 948 int srcOffset = 0; |
| 893 int srcWidth = dstInfo.width(); | 949 int srcWidth = dstInfo.width(); |
| 894 int dstOffset = 0; | 950 int dstOffset = 0; |
| 895 int dstWidth = srcWidth; | 951 int dstWidth = srcWidth; |
| 896 if (options.fSubset) { | 952 if (options.fSubset) { |
| 897 // We do not currently support subset decodes for image types that may h ave | 953 // We do not currently support subset decodes for image types that may h ave |
| 898 // frames (gif). | 954 // frames (gif). |
| 899 SkASSERT(!frame); | 955 SkASSERT(!frame); |
| 900 srcOffset = options.fSubset->left(); | 956 srcOffset = options.fSubset->left(); |
| 901 srcWidth = options.fSubset->width(); | 957 srcWidth = options.fSubset->width(); |
| 902 dstWidth = srcWidth; | 958 dstWidth = srcWidth; |
| 903 } else if (frame) { | 959 } else if (frame) { |
| 904 dstOffset = frame->left(); | 960 dstOffset = frame->left(); |
| 905 srcWidth = frame->width(); | 961 srcWidth = frame->width(); |
| 906 } | 962 } |
| 907 | 963 |
| 908 return new SkSwizzler(fastProc, proc, ctable, srcOffset, srcWidth, dstOffset , dstWidth, | 964 return new SkSwizzler(proc, fastProcs, ctable, srcOffset, srcWidth, dstOffse t, dstWidth, |
| 909 srcBPP, dstBPP); | 965 srcBPP, dstBPP); |
| 910 } | 966 } |
| 911 | 967 |
| 912 SkSwizzler::SkSwizzler(RowProc fastProc, RowProc proc, const SkPMColor* ctable, int srcOffset, | 968 SkSwizzler::SkSwizzler(RowProc proc, const FastProcs& fastProcs, const SkPMColor * ctable, |
| 913 int srcWidth, int dstOffset, int dstWidth, int srcBPP, int dstBPP) | 969 int srcOffset, int srcWidth, int dstOffset, int dstWidth, int srcBPP, in t dstBPP) |
| 914 : fFastProc(fastProc) | 970 : fSlowProc(proc) |
| 915 , fSlowProc(proc) | 971 , fFastProcs(fastProcs) |
| 916 , fActualProc(fFastProc ? fFastProc : fSlowProc) | 972 , fActualProc(fFastProcs.fSampleSize1 ? fFastProcs.fSampleSize1 : fSlowProc) |
| 917 , fColorTable(ctable) | 973 , fColorTable(ctable) |
| 918 , fSrcOffset(srcOffset) | 974 , fSrcOffset(srcOffset) |
| 919 , fDstOffset(dstOffset) | 975 , fDstOffset(dstOffset) |
| 920 , fSrcOffsetUnits(srcOffset * srcBPP) | 976 , fSrcOffsetUnits(srcOffset * srcBPP) |
| 921 , fDstOffsetBytes(dstOffset * dstBPP) | 977 , fDstOffsetBytes(dstOffset * dstBPP) |
| 922 , fSrcWidth(srcWidth) | 978 , fSrcWidth(srcWidth) |
| 923 , fDstWidth(dstWidth) | 979 , fDstWidth(dstWidth) |
| 924 , fSwizzleWidth(srcWidth) | 980 , fSwizzleWidth(srcWidth) |
| 925 , fAllocatedWidth(dstWidth) | 981 , fAllocatedWidth(dstWidth) |
| 926 , fSampleX(1) | 982 , fSampleX(1) |
| 927 , fSrcBPP(srcBPP) | 983 , fSrcBPP(srcBPP) |
| 928 , fDstBPP(dstBPP) | 984 , fDstBPP(dstBPP) |
| 929 {} | 985 {} |
| 930 | 986 |
| 931 int SkSwizzler::onSetSampleX(int sampleX) { | 987 int SkSwizzler::onSetSampleX(int sampleX) { |
| 932 SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be | 988 SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be |
| 933 // way to report failure? | 989 // way to report failure? |
| 934 fSampleX = sampleX; | 990 fSampleX = sampleX; |
| 935 fSrcOffsetUnits = (get_start_coord(sampleX) + fSrcOffset) * fSrcBPP; | 991 fSrcOffsetUnits = (get_start_coord(sampleX) + fSrcOffset) * fSrcBPP; |
| 936 fDstOffsetBytes = (fDstOffset / sampleX) * fDstBPP; | 992 fDstOffsetBytes = (fDstOffset / sampleX) * fDstBPP; |
| 937 fSwizzleWidth = get_scaled_dimension(fSrcWidth, sampleX); | 993 fSwizzleWidth = get_scaled_dimension(fSrcWidth, sampleX); |
| 938 fAllocatedWidth = get_scaled_dimension(fDstWidth, sampleX); | 994 fAllocatedWidth = get_scaled_dimension(fDstWidth, sampleX); |
| 939 | 995 |
| 940 // The optimized swizzler routines do not (yet) support sampling. | 996 // Choose an optimized swizzler function (if it exists). |
| 941 if (1 == fSampleX && fFastProc) { | 997 fActualProc = nullptr; |
| 942 fActualProc = fFastProc; | 998 switch (fSampleX) { |
| 943 } else { | 999 case 1: |
| 1000 fActualProc = fFastProcs.fSampleSize1; | |
| 1001 break; | |
| 1002 case 2: | |
| 1003 fActualProc = fFastProcs.fSampleSize2; | |
| 1004 break; | |
| 1005 case 4: | |
| 1006 fActualProc = fFastProcs.fSampleSize4; | |
| 1007 break; | |
| 1008 case 8: | |
| 1009 fActualProc = fFastProcs.fSampleSize8; | |
| 1010 break; | |
| 1011 default: | |
| 1012 break; | |
| 1013 } | |
| 1014 | |
| 1015 // Otherwise, use fSlowProc. | |
| 1016 if (!fActualProc) { | |
| 944 fActualProc = fSlowProc; | 1017 fActualProc = fSlowProc; |
| 945 } | 1018 } |
| 946 | 1019 |
| 947 return fAllocatedWidth; | 1020 return fAllocatedWidth; |
| 948 } | 1021 } |
| 949 | 1022 |
| 950 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { | 1023 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { |
| 951 SkASSERT(nullptr != dst && nullptr != src); | 1024 SkASSERT(nullptr != dst && nullptr != src); |
| 952 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS rcBPP, | 1025 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS rcBPP, |
| 953 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); | 1026 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); |
| 954 } | 1027 } |
| OLD | NEW |