Fix SkSwizzler bug
authormsarett <msarett@google.com>
Fri, 16 Oct 2015 17:54:12 +0000 (10:54 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 16 Oct 2015 17:54:12 +0000 (10:54 -0700)
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

src/codec/SkMaskSwizzler.cpp
src/codec/SkMaskSwizzler.h
src/codec/SkSwizzler.cpp
src/codec/SkSwizzler.h
tests/CodexTest.cpp

index 72dca28..958df61 100644 (file)
@@ -367,11 +367,11 @@ SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(const SkImageInfo& dstInfo,
  * 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 @@ int SkMaskSwizzler::onSetSampleX(int sampleX) {
                            // 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;
 }
 
index 9aea5d8..e5da723 100644 (file)
@@ -53,7 +53,7 @@ private:
     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 @@ private:
     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;
index ce2c946..de69124 100644 (file)
@@ -693,13 +693,14 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
     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 @@ int SkSwizzler::onSetSampleX(int sampleX) {
                            // 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;
 }
 
index 058044e..fd20588 100644 (file)
@@ -178,7 +178,7 @@ private:
                                           // 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 @@ private:
                                           // 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;
 
index 91fb689..5ef1f8a 100644 (file)
@@ -220,6 +220,26 @@ static void check(skiatest::Reporter* r,
                 == 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 = &subset;
+
+            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);
     }