Fix SkSwizzler bug
Now, that we are subsetting, fX0 is not necessarily less than
fSrcWidth (since fSrcWidth is really the subset width).
Ex: We may want a 10 pixel subset starting twenty pixels from the
left edge. In that case, fX0=20 and fSrcWidth=10.
Let's rename the width as fSubsetWidth to avoid confusion
and remove the check.
BUG=skia:
Review URL: https://codereview.chromium.org/1407603003
diff --git a/src/codec/SkMaskSwizzler.cpp b/src/codec/SkMaskSwizzler.cpp
index 72dca28..958df61 100644
--- a/src/codec/SkMaskSwizzler.cpp
+++ b/src/codec/SkMaskSwizzler.cpp
@@ -367,11 +367,11 @@
* Constructor for mask swizzler
*
*/
-SkMaskSwizzler::SkMaskSwizzler(SkMasks* masks, RowProc proc, int srcOffset, int srcWidth)
+SkMaskSwizzler::SkMaskSwizzler(SkMasks* masks, RowProc proc, int srcOffset, int subsetWidth)
: fMasks(masks)
, fRowProc(proc)
- , fSrcWidth(srcWidth)
- , fDstWidth(srcWidth)
+ , fSubsetWidth(subsetWidth)
+ , fDstWidth(subsetWidth)
, fSampleX(1)
, fSrcOffset(srcOffset)
, fX0(srcOffset)
@@ -383,10 +383,10 @@
// way to report failure?
fSampleX = sampleX;
fX0 = get_start_coord(sampleX) + fSrcOffset;
- fDstWidth = get_scaled_dimension(fSrcWidth, sampleX);
+ fDstWidth = get_scaled_dimension(fSubsetWidth, sampleX);
- // check that fX0 is less than original width
- SkASSERT(fX0 >= 0 && fX0 < fSrcWidth);
+ // check that fX0 is valid
+ SkASSERT(fX0 >= 0);
return fDstWidth;
}
diff --git a/src/codec/SkMaskSwizzler.h b/src/codec/SkMaskSwizzler.h
index 9aea5d8..e5da723 100644
--- a/src/codec/SkMaskSwizzler.h
+++ b/src/codec/SkMaskSwizzler.h
@@ -53,7 +53,7 @@
typedef SkSwizzler::ResultAlpha (*RowProc)(void* dstRow, const uint8_t* srcRow, int width,
SkMasks* masks, uint32_t startX, uint32_t sampleX);
- SkMaskSwizzler(SkMasks* masks, RowProc proc, int srcWidth, int srcOffset);
+ SkMaskSwizzler(SkMasks* masks, RowProc proc, int subsetWidth, int srcOffset);
int onSetSampleX(int) override;
@@ -61,7 +61,7 @@
const RowProc fRowProc;
// FIXME: Can this class share more with SkSwizzler? These variables are all the same.
- const int fSrcWidth; // Width of the source - i.e. before any sampling.
+ const int fSubsetWidth; // Width of the subset of source before any sampling.
int fDstWidth; // Width of dst, which may differ with sampling.
int fSampleX;
int fSrcOffset;
diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp
index ce2c946..de69124 100644
--- a/src/codec/SkSwizzler.cpp
+++ b/src/codec/SkSwizzler.cpp
@@ -693,13 +693,14 @@
return new SkSwizzler(proc, ctable, srcOffset, srcWidth, bpp);
}
-SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int srcWidth, int bpp)
+SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int subsetWidth,
+ int bpp)
: fRowProc(proc)
, fColorTable(ctable)
, fSrcOffset(srcOffset)
, fX0(srcOffset)
- , fSrcWidth(srcWidth)
- , fDstWidth(srcWidth)
+ , fSubsetWidth(subsetWidth)
+ , fDstWidth(subsetWidth)
, fSampleX(1)
, fBPP(bpp)
{}
@@ -709,10 +710,10 @@
// way to report failure?
fSampleX = sampleX;
fX0 = get_start_coord(sampleX) + fSrcOffset;
- fDstWidth = get_scaled_dimension(fSrcWidth, sampleX);
+ fDstWidth = get_scaled_dimension(fSubsetWidth, sampleX);
- // check that fX0 is less than original width
- SkASSERT(fX0 >= 0 && fX0 < fSrcWidth);
+ // check that fX0 is valid
+ SkASSERT(fX0 >= 0);
return fDstWidth;
}
diff --git a/src/codec/SkSwizzler.h b/src/codec/SkSwizzler.h
index 058044e..fd20588 100644
--- a/src/codec/SkSwizzler.h
+++ b/src/codec/SkSwizzler.h
@@ -178,7 +178,7 @@
// scanline decodes.
int fX0; // Start coordinate for the src, may be different than
// fSrcOffset if we are sampling.
- const int fSrcWidth; // Width of the source - i.e. before any sampling.
+ const int fSubsetWidth; // Width of the subset of the source before any sampling.
int fDstWidth; // Width of dst, which may differ with sampling.
int fSampleX; // step between X samples
const int fBPP; // if bitsPerPixel % 8 == 0
@@ -186,7 +186,7 @@
// else
// fBPP is bitsPerPixel
- SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int srcWidth, int bpp);
+ SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int subsetWidth, int bpp);
int onSetSampleX(int) override;
diff --git a/tests/CodexTest.cpp b/tests/CodexTest.cpp
index 91fb689..5ef1f8a 100644
--- a/tests/CodexTest.cpp
+++ b/tests/CodexTest.cpp
@@ -220,6 +220,26 @@
== 0);
REPORTER_ASSERT(r, codec->skipScanlines(1)
== 0);
+
+ // Test partial scanline decodes
+ if (supports_scaled_codec(path) && info.width() >= 3) {
+ SkCodec::Options options;
+ int width = info.width();
+ int height = info.height();
+ SkIRect subset = SkIRect::MakeXYWH(2 * (width / 3), 0, width / 3, height);
+ options.fSubset = ⊂
+
+ const SkCodec::Result partialStartResult = codec->startScanlineDecode(info, &options,
+ nullptr, nullptr);
+ REPORTER_ASSERT(r, partialStartResult == SkCodec::kSuccess);
+
+ for (int y = 0; y < height; y++) {
+ const int lines = codec->getScanlines(bm.getAddr(0, y), 1, 0);
+ if (!isIncomplete) {
+ REPORTER_ASSERT(r, 1 == lines);
+ }
+ }
+ }
} else {
REPORTER_ASSERT(r, startResult == SkCodec::kUnimplemented);
}