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