diff options
author | scroggo <scroggo@chromium.org> | 2016-10-10 11:35:01 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-10-10 11:35:01 -0700 |
commit | ff9f7bbef6fdbd2ae7965ff18981aa8df33abd96 (patch) | |
tree | 4bca9d23a8c3c01adc2b9051d8c5ded18202bda8 /src/codec | |
parent | 76bcd4f189b43e0235e496c0eddf7b3e9f4167f5 (diff) |
Simplify rowsDecoded returned by incrementalDecode
When sampling, we previously had to figure out the number of rows that
were written to the output based on the value reported by
incrementalDecode. (We also messed up the first time - see the fix in
crrev.com/2343153003.)
Instead, make incrementalDecode report the actual number of rows
written to. This can be provided directly to fill.
Make SkPngCodec report the correct number of rows, by incrementing its
count when it actually writes to the destination.
This also will simplify my in progress GIF change.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2407543002
Review-Url: https://codereview.chromium.org/2407543002
Diffstat (limited to 'src/codec')
-rw-r--r-- | src/codec/SkPngCodec.cpp | 28 | ||||
-rw-r--r-- | src/codec/SkSampledCodec.cpp | 5 |
2 files changed, 22 insertions, 11 deletions
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp index 1f3a8d96a4..dde49d037d 100644 --- a/src/codec/SkPngCodec.cpp +++ b/src/codec/SkPngCodec.cpp @@ -517,6 +517,7 @@ public: SkPngChunkReader* reader, png_structp png_ptr, png_infop info_ptr, int bitDepth) : INHERITED(info, imageInfo, stream, reader, png_ptr, info_ptr, bitDepth) , fLinesDecoded(0) + , fRowsWrittenToOutput(0) , fDst(nullptr) , fRowBytes(0) , fFirstRow(0) @@ -538,7 +539,13 @@ public: #endif private: - int fLinesDecoded; // FIXME: Move to baseclass? + // This represents the number of lines reported by libpng, minus any we skipped at the + // beginning. Only used when we are skipping lines (i.e. not in decodeAllRows). + int fLinesDecoded; + // While fLinesDecoded include lines that we skipped, this only includes lines written to the + // output so we can report it to the caller for filling. + // FIXME: Can we remove fLinesDecoded and just rely on fRowsWrittenToOutput? + int fRowsWrittenToOutput; void* fDst; size_t fRowBytes; @@ -562,26 +569,26 @@ private: fDst = dst; fRowBytes = rowBytes; - fLinesDecoded = 0; + fRowsWrittenToOutput = 0; fFirstRow = 0; fLastRow = height - 1; this->processData(); - if (fLinesDecoded == height) { + if (fRowsWrittenToOutput == height) { return SkCodec::kSuccess; } if (rowsDecoded) { - *rowsDecoded = fLinesDecoded; + *rowsDecoded = fRowsWrittenToOutput; } return SkCodec::kIncompleteInput; } void allRowsCallback(png_bytep row, int rowNum) { - SkASSERT(rowNum == fLinesDecoded); - fLinesDecoded++; + SkASSERT(rowNum == fRowsWrittenToOutput); + fRowsWrittenToOutput++; this->applyXformRow(fDst, row); fDst = SkTAddOffset<void>(fDst, fRowBytes); } @@ -597,6 +604,7 @@ private: fDst = dst; fRowBytes = rowBytes; fLinesDecoded = 0; + fRowsWrittenToOutput = 0; } SkCodec::Result decode(int* rowsDecoded) override { @@ -607,7 +615,7 @@ private: } if (rowsDecoded) { - *rowsDecoded = fLinesDecoded; + *rowsDecoded = fRowsWrittenToOutput; } return SkCodec::kIncompleteInput; @@ -625,6 +633,7 @@ private: if (!this->swizzler() || this->swizzler()->rowNeeded(fLinesDecoded)) { this->applyXformRow(fDst, row); fDst = SkTAddOffset<void>(fDst, fRowBytes); + fRowsWrittenToOutput++; } fLinesDecoded++; @@ -774,6 +783,8 @@ private: const int lastRow = fLinesDecoded + fFirstRow - 1; SkASSERT(lastRow <= fLastRow); + int rowsWrittenToOutput = 0; + // FIXME: For resuming interlace, we may swizzle a row that hasn't changed. But it // may be too tricky/expensive to handle that correctly. png_bytep srcRow = fInterlaceBuffer.get(); @@ -783,6 +794,7 @@ private: this->applyXformRow(dst, srcRow); dst = SkTAddOffset<void>(dst, fRowBytes); srcRow = SkTAddOffset<png_byte>(srcRow, fPng_rowbytes * sampleY); + rowsWrittenToOutput++; } if (fInterlacedComplete) { @@ -790,7 +802,7 @@ private: } if (rowsDecoded) { - *rowsDecoded = fLinesDecoded; + *rowsDecoded = rowsWrittenToOutput; } return SkCodec::kIncompleteInput; } diff --git a/src/codec/SkSampledCodec.cpp b/src/codec/SkSampledCodec.cpp index cca26000d6..46286cff9d 100644 --- a/src/codec/SkSampledCodec.cpp +++ b/src/codec/SkSampledCodec.cpp @@ -258,10 +258,9 @@ SkCodec::Result SkSampledCodec::sampledDecode(const SkImageInfo& info, void* pix } SkASSERT(incResult == SkCodec::kIncompleteInput); - // Count the rows that we decoded, and also did not skip. - const int trueRowsDecoded = (rowsDecoded + sampleY - 1) / sampleY; + SkASSERT(rowsDecoded <= info.height()); this->codec()->fillIncompleteImage(info, pixels, rowBytes, options.fZeroInitialized, - info.height(), trueRowsDecoded); + info.height(), rowsDecoded); return SkCodec::kIncompleteInput; } else if (startResult != SkCodec::kUnimplemented) { return startResult; |