Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(984)

Unified Diff: src/codec/SkCodec.cpp

Issue 1332053002: Fill incomplete images in SkCodec parent class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Response to comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/codec/SkCodec.cpp
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp
index d12de21f515e45c861f6793cdd0b73b4bcc8055f..009db033cbbc32d1a38318636b9839d0d27be4f2 100644
--- a/src/codec/SkCodec.cpp
+++ b/src/codec/SkCodec.cpp
@@ -79,6 +79,7 @@ SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream)
: fInfo(info)
, fStream(stream)
, fNeedsRewind(false)
+ , fIncompleteScanlines(0)
{}
SkCodec::~SkCodec() {}
@@ -137,11 +138,26 @@ SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t
if (nullptr == options) {
options = &optsStorage;
}
- const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ctable, ctableCount);
+
+ // On an incomplete decode, the subclass can specify the number of scanlines that it failed
+ // to decode.
+ int incompleteScanlines = 0;
+ const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ctable, ctableCount,
+ &incompleteScanlines);
if ((kIncompleteInput == result || kSuccess == result) && ctableCount) {
SkASSERT(*ctableCount >= 0 && *ctableCount <= 256);
}
+
+ // A return value of kIncompleteInput indicates a truncated image stream.
+ // In this case, we will fill any uninitialized memory with a default value.
+ if (kIncompleteInput == result && 0 != incompleteScanlines) {
+ void* fillDst = this->getFillDst(pixels, rowBytes, info.height() - incompleteScanlines);
scroggo 2015/09/25 15:55:05 My mistake, you end up doing another subtract. If
msarett 2015/10/01 12:44:52 Acknowledged.
+ const SkImageInfo fillInfo = info.makeWH(info.width(), incompleteScanlines);
+ const uint32_t fillValue = this->getFillValue(fillInfo);
+ SkSwizzler::Fill(fillDst, fillInfo, rowBytes, fillValue, options->fZeroInitialized);
+ }
+
return result;
}

Powered by Google App Engine
This is Rietveld 408576698