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 "SkSwizzler.h" | 10 #include "SkSwizzler.h" |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
587 src += deltaSrc; | 587 src += deltaSrc; |
588 alphaMask &= alpha; | 588 alphaMask &= alpha; |
589 } | 589 } |
590 return alphaMask != 0xFF; | 590 return alphaMask != 0xFF; |
591 } | 591 } |
592 */ | 592 */ |
593 | 593 |
594 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, | 594 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
595 const SkPMColor* ctable, | 595 const SkPMColor* ctable, |
596 const SkImageInfo& dstInfo, | 596 const SkImageInfo& dstInfo, |
597 const SkCodec::Options& options) { | 597 const SkCodec::Options& options, |
598 const SkIRect* frame) { | |
598 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { | 599 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { |
599 return nullptr; | 600 return nullptr; |
600 } | 601 } |
601 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) | 602 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) |
602 && nullptr == ctable) { | 603 && nullptr == ctable) { |
603 return nullptr; | 604 return nullptr; |
604 } | 605 } |
605 RowProc proc = nullptr; | 606 RowProc proc = nullptr; |
606 SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized; | 607 SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized; |
607 switch (sc) { | 608 switch (sc) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
769 } | 770 } |
770 break; | 771 break; |
771 default: | 772 default: |
772 break; | 773 break; |
773 } | 774 } |
774 if (nullptr == proc) { | 775 if (nullptr == proc) { |
775 return nullptr; | 776 return nullptr; |
776 } | 777 } |
777 | 778 |
778 // Store bpp in bytes if it is an even multiple, otherwise use bits | 779 // Store bpp in bytes if it is an even multiple, otherwise use bits |
779 int bpp = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel(sc ); | 780 int srcBPP = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel (sc); |
781 int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType()); | |
780 | 782 |
781 int srcOffset = 0; | 783 int srcOffset = 0; |
782 int srcWidth = dstInfo.width(); | 784 int srcWidth = dstInfo.width(); |
785 int dstOffset = 0; | |
786 int dstWidth = dstInfo.width(); | |
scroggo
2015/11/17 14:56:26
dstWidth = srcWidth?
msarett
2015/11/17 18:00:50
Done.
| |
783 if (options.fSubset) { | 787 if (options.fSubset) { |
788 // We do not currently support subset decodes for image types that may h ave | |
scroggo
2015/11/17 14:56:26
Add a comment stating this in the header?
msarett
2015/11/17 18:00:50
Done.
| |
789 // frames (gif). | |
790 SkASSERT(!frame); | |
784 srcOffset = options.fSubset->left(); | 791 srcOffset = options.fSubset->left(); |
785 srcWidth = options.fSubset->width(); | 792 srcWidth = options.fSubset->width(); |
793 dstWidth = options.fSubset->width(); | |
scroggo
2015/11/17 14:56:26
dstWidth = srcWidth?
msarett
2015/11/17 18:00:50
Done.
| |
794 } else if (frame) { | |
795 dstOffset = frame->left(); | |
796 srcWidth = frame->width(); | |
786 } | 797 } |
787 | 798 |
788 return new SkSwizzler(proc, ctable, srcOffset, srcWidth, bpp); | 799 return new SkSwizzler(proc, ctable, srcOffset, srcWidth, dstOffset, dstWidth , srcBPP, dstBPP); |
789 } | 800 } |
790 | 801 |
791 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int subsetWidth, | 802 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int srcWidth, |
792 int bpp) | 803 int dstOffset, int dstWidth, int srcBPP, int dstBPP) |
793 : fRowProc(proc) | 804 : fRowProc(proc) |
794 , fColorTable(ctable) | 805 , fColorTable(ctable) |
795 , fSrcOffset(srcOffset) | 806 , fSrcOffset(srcOffset) |
796 , fX0(srcOffset) | 807 , fDstOffset(dstOffset) |
797 , fSubsetWidth(subsetWidth) | 808 , fSrcOffsetBytes(srcOffset * srcBPP) |
scroggo
2015/11/17 14:56:26
Won't srcBPP sometimes be in bits?
msarett
2015/11/17 18:00:50
Yes! I forgot. I'll find a better name.
| |
798 , fDstWidth(subsetWidth) | 809 , fDstOffsetBytes(dstOffset * dstBPP) |
810 , fSrcWidth(srcWidth) | |
811 , fDstWidth(dstWidth) | |
812 , fSwizzleWidth(srcWidth) | |
813 , fAllocatedWidth(dstWidth) | |
799 , fSampleX(1) | 814 , fSampleX(1) |
800 , fBPP(bpp) | 815 , fSrcBPP(srcBPP) |
816 , fDstBPP(dstBPP) | |
801 {} | 817 {} |
802 | 818 |
803 int SkSwizzler::onSetSampleX(int sampleX) { | 819 int SkSwizzler::onSetSampleX(int sampleX) { |
804 SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be | 820 SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be |
805 // way to report failure? | 821 // way to report failure? |
806 fSampleX = sampleX; | 822 fSampleX = sampleX; |
807 fX0 = get_start_coord(sampleX) + fSrcOffset; | 823 fSrcOffsetBytes = (get_start_coord(sampleX) + fSrcOffset) * fSrcBPP; |
808 fDstWidth = get_scaled_dimension(fSubsetWidth, sampleX); | 824 fDstOffsetBytes = (fDstOffset / sampleX) * fDstBPP; |
825 fSwizzleWidth = get_scaled_dimension(fSrcWidth, sampleX); | |
826 fAllocatedWidth = get_scaled_dimension(fDstWidth, sampleX); | |
809 | 827 |
810 // check that fX0 is valid | 828 return fAllocatedWidth; |
811 SkASSERT(fX0 >= 0); | |
812 return fDstWidth; | |
813 } | 829 } |
814 | 830 |
815 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) { | 831 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) { |
816 SkASSERT(nullptr != dst && nullptr != src); | 832 SkASSERT(nullptr != dst && nullptr != src); |
817 return fRowProc(dst, src, fDstWidth, fBPP, fSampleX * fBPP, fX0 * fBPP, fCol orTable); | 833 return fRowProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth , fSrcBPP, |
834 fSampleX * fSrcBPP, fSrcOffsetBytes, fColorTable); | |
818 } | 835 } |
OLD | NEW |