Add subsetting to SkScanlineDecoder
This CL allows the SkScanlineDecoder to decode partial
scanlines.
This is a first step in efficiently implementing subsetting
in SkScaledCodec.
BUG=skia:4209
Review URL: https://codereview.chromium.org/1390213002
diff --git a/src/codec/SkMaskSwizzler.cpp b/src/codec/SkMaskSwizzler.cpp
index 9772d87..72dca28 100644
--- a/src/codec/SkMaskSwizzler.cpp
+++ b/src/codec/SkMaskSwizzler.cpp
@@ -250,9 +250,9 @@
* Create a new mask swizzler
*
*/
-SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(
- const SkImageInfo& dstInfo, const SkImageInfo& srcInfo, SkMasks* masks,
- uint32_t bitsPerPixel) {
+SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(const SkImageInfo& dstInfo,
+ const SkImageInfo& srcInfo, SkMasks* masks, uint32_t bitsPerPixel,
+ const SkCodec::Options& options) {
// Choose the appropriate row procedure
RowProc proc = nullptr;
@@ -352,7 +352,14 @@
return nullptr;
}
- return new SkMaskSwizzler(dstInfo.width(), masks, proc);
+ int srcOffset = 0;
+ int srcWidth = dstInfo.width();
+ if (options.fSubset) {
+ srcOffset = options.fSubset->left();
+ srcWidth = options.fSubset->width();
+ }
+
+ return new SkMaskSwizzler(masks, proc, srcOffset, srcWidth);
}
/*
@@ -360,13 +367,14 @@
* Constructor for mask swizzler
*
*/
-SkMaskSwizzler::SkMaskSwizzler(int width, SkMasks* masks, RowProc proc)
+SkMaskSwizzler::SkMaskSwizzler(SkMasks* masks, RowProc proc, int srcOffset, int srcWidth)
: fMasks(masks)
, fRowProc(proc)
- , fSrcWidth(width)
- , fDstWidth(width)
+ , fSrcWidth(srcWidth)
+ , fDstWidth(srcWidth)
, fSampleX(1)
- , fX0(0)
+ , fSrcOffset(srcOffset)
+ , fX0(srcOffset)
{}
int SkMaskSwizzler::onSetSampleX(int sampleX) {
@@ -374,7 +382,7 @@
SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be
// way to report failure?
fSampleX = sampleX;
- fX0 = get_start_coord(sampleX);
+ fX0 = get_start_coord(sampleX) + fSrcOffset;
fDstWidth = get_scaled_dimension(fSrcWidth, sampleX);
// check that fX0 is less than original width