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 "SkScaledCodec.h" | 10 #include "SkScaledCodec.h" |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
707 // check that fX0 is less than original width | 707 // check that fX0 is less than original width |
708 SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX); | 708 SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX); |
709 } | 709 } |
710 | 710 |
711 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) { | 711 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) { |
712 SkASSERT(nullptr != dst && nullptr != src); | 712 SkASSERT(nullptr != dst && nullptr != src); |
713 return fRowProc(dst, src, fDstInfo.width(), fDeltaSrc, fSampleX * fDeltaSrc, | 713 return fRowProc(dst, src, fDstInfo.width(), fDeltaSrc, fSampleX * fDeltaSrc, |
714 fX0 * fDeltaSrc, fColorTable); | 714 fX0 * fDeltaSrc, fColorTable); |
715 } | 715 } |
716 | 716 |
717 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes, | 717 void SkSwizzler::Fill(void* fillDst, const SkImageInfo& fillInfo, size_t rowByte s, |
718 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable, | 718 uint32_t colorOrIndex, SkCodec::ZeroInitialized zeroInit) { |
719 SkCodec::ZeroInitialized zeroInit) { | 719 SkASSERT(fillDst != nullptr); |
720 SkASSERT(dstStartRow != nullptr); | |
721 SkASSERT(numRows <= (uint32_t) dstInfo.height()); | |
722 | 720 |
723 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded. | 721 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded. |
724 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS ize(dstRowBytes); | 722 const size_t bytesToFill = fillInfo.getSafeSize(rowBytes); |
725 | 723 |
726 // Use the proper memset routine to fill the remaining bytes | 724 // Use the proper memset routine to fill the remaining bytes |
727 switch(dstInfo.colorType()) { | 725 switch(fillInfo.colorType()) { |
scroggo
2015/10/01 14:48:32
nit: space between "switch" and "("
msarett
2015/10/01 18:14:14
Done.
| |
728 case kN32_SkColorType: | 726 case kN32_SkColorType: { |
729 // Assume input is an index if we have a color table | |
730 uint32_t color; | |
731 if (nullptr != colorTable) { | |
732 color = colorTable[(uint8_t) colorOrIndex]; | |
733 // Otherwise, assume the input is a color | |
734 } else { | |
735 color = colorOrIndex; | |
736 } | |
737 | |
738 // If memory is zero initialized, we may not need to fill | 727 // If memory is zero initialized, we may not need to fill |
728 uint32_t color = colorOrIndex; | |
739 if (SkCodec::kYes_ZeroInitialized == zeroInit && 0 == color) { | 729 if (SkCodec::kYes_ZeroInitialized == zeroInit && 0 == color) { |
740 return; | 730 return; |
741 } | 731 } |
742 | 732 |
743 // We must fill row by row in the case of unaligned row bytes | 733 // We must fill row by row in the case of unaligned row bytes |
744 if (SkIsAlign4((size_t) dstStartRow) && SkIsAlign4(dstRowBytes)) { | 734 if (SkIsAlign4((size_t) fillDst) && SkIsAlign4(rowBytes)) { |
745 sk_memset32((uint32_t*) dstStartRow, color, | 735 sk_memset32((uint32_t*) fillDst, color, |
746 (uint32_t) bytesToFill / sizeof(SkPMColor)); | 736 (uint32_t) bytesToFill / sizeof(SkPMColor)); |
747 } else { | 737 } else { |
748 // This is an unlikely, slow case | 738 // We must fill row by row in the case of unaligned row bytes. This is an |
739 // unlikely, slow case. | |
749 SkCodecPrintf("Warning: Strange number of row bytes, fill will b e slow.\n"); | 740 SkCodecPrintf("Warning: Strange number of row bytes, fill will b e slow.\n"); |
750 uint32_t* dstRow = (uint32_t*) dstStartRow; | 741 uint32_t* dstRow = (uint32_t*) fillDst; |
751 for (uint32_t row = 0; row < numRows; row++) { | 742 for (uint32_t row = 0; row < fillInfo.height(); row++) { |
752 for (int32_t col = 0; col < dstInfo.width(); col++) { | 743 for (int32_t col = 0; col < fillInfo.width(); col++) { |
753 dstRow[col] = color; | 744 dstRow[col] = color; |
754 } | 745 } |
755 dstRow = SkTAddOffset<uint32_t>(dstRow, dstRowBytes); | 746 dstRow = SkTAddOffset<uint32_t>(dstRow, rowBytes); |
756 } | 747 } |
757 } | 748 } |
758 break; | 749 break; |
759 case kRGB_565_SkColorType: | 750 } |
751 case kRGB_565_SkColorType: { | |
760 // If the destination is k565, the caller passes in a 16-bit color. | 752 // If the destination is k565, the caller passes in a 16-bit color. |
761 // We will not assert that the high bits of colorOrIndex must be zer oed. | 753 // We will not assert that the high bits of colorOrIndex must be zer oed. |
762 // This allows us to take advantage of the fact that the low 16 bits of an | 754 // This allows us to take advantage of the fact that the low 16 bits of an |
763 // SKPMColor may be a valid a 565 color. For example, the low 16 | 755 // SKPMColor may be a valid a 565 color. For example, the low 16 |
764 // bits of SK_ColorBLACK are identical to the 565 representation | 756 // bits of SK_ColorBLACK are identical to the 565 representation |
765 // for black. | 757 // for black. |
766 // If we ever want to fill with colorOrIndex != 0, we will probably need | 758 |
767 // to implement this with sk_memset16(). | 759 // If memory is zero initialized, we may not need to fill |
768 SkASSERT((uint16_t) colorOrIndex == (uint8_t) colorOrIndex); | 760 uint16_t color = (uint16_t) colorOrIndex; |
769 // Fall through | 761 if (SkCodec::kYes_ZeroInitialized == zeroInit && 0 == color) { |
762 return; | |
763 } | |
764 | |
765 if (SkIsAlign2((size_t) fillDst) && SkIsAlign2(rowBytes)) { | |
766 sk_memset16((uint16_t*) fillDst, color, (uint32_t) bytesToFill / sizeof(uint16_t)); | |
767 } else { | |
768 // We must fill row by row in the case of unaligned row bytes. This is an | |
769 // unlikely, slow case. | |
770 SkCodecPrintf("Warning: Strange number of row bytes, fill will b e slow.\n"); | |
771 uint16_t* dstRow = (uint16_t*) fillDst; | |
772 for (uint32_t row = 0; row < fillInfo.height(); row++) { | |
773 for (int32_t col = 0; col < fillInfo.width(); col++) { | |
774 dstRow[col] = color; | |
775 } | |
776 dstRow = SkTAddOffset<uint16_t>(dstRow, rowBytes); | |
777 } | |
778 } | |
779 break; | |
780 } | |
770 case kIndex_8_SkColorType: | 781 case kIndex_8_SkColorType: |
771 // On an index destination color type, always assume the input is an index. | 782 // On an index destination color type, always assume the input is an index. |
772 // Fall through | 783 // Fall through |
773 case kGray_8_SkColorType: | 784 case kGray_8_SkColorType: |
774 // If the destination is kGray, the caller passes in an 8-bit color. | 785 // If the destination is kGray, the caller passes in an 8-bit color. |
775 // We will not assert that the high bits of colorOrIndex must be zer oed. | 786 // We will not assert that the high bits of colorOrIndex must be zer oed. |
776 // This allows us to take advantage of the fact that the low 8 bits of an | 787 // This allows us to take advantage of the fact that the low 8 bits of an |
777 // SKPMColor may be a valid a grayscale color. For example, the low 8 | 788 // SKPMColor may be a valid a grayscale color. For example, the low 8 |
778 // bits of SK_ColorBLACK are identical to the grayscale representati on | 789 // bits of SK_ColorBLACK are identical to the grayscale representati on |
779 // for black. | 790 // for black. |
780 | 791 |
781 // If memory is zero initialized, we may not need to fill | 792 // If memory is zero initialized, we may not need to fill |
782 if (SkCodec::kYes_ZeroInitialized == zeroInit && 0 == (uint8_t) colo rOrIndex) { | 793 if (SkCodec::kYes_ZeroInitialized == zeroInit && 0 == (uint8_t) colo rOrIndex) { |
783 return; | 794 return; |
784 } | 795 } |
785 | 796 |
786 memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill); | 797 memset(fillDst, (uint8_t) colorOrIndex, bytesToFill); |
787 break; | 798 break; |
788 default: | 799 default: |
789 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); | 800 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); |
790 SkASSERT(false); | 801 SkASSERT(false); |
791 break; | 802 break; |
792 } | 803 } |
793 } | 804 } |
OLD | NEW |