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

Unified Diff: dm/DMSrcSink.cpp

Issue 1332053002: Fill incomplete images in SkCodec parent class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
« no previous file with comments | « no previous file | gyp/tools.gyp » ('j') | include/codec/SkCodec.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dm/DMSrcSink.cpp
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 981e47d6c0bf84690c25c8a49392fa2e3abadc18..5229abdf5e909913aafdc7a273951cf9ac65a83a 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -352,35 +352,33 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
return Error::Nonfatal("Could not start scanline decoder");
}
- SkCodec::Result result = SkCodec::kUnimplemented;
+ uint32_t lines = 0;
scroggo 2015/09/22 18:02:48 Maybe this should be linesDecoded?
msarett 2015/09/23 13:22:39 Done.
switch (scanlineDecoder->getScanlineOrder()) {
case SkScanlineDecoder::kTopDown_SkScanlineOrder:
case SkScanlineDecoder::kBottomUp_SkScanlineOrder:
case SkScanlineDecoder::kNone_SkScanlineOrder:
- result = scanlineDecoder->getScanlines(bitmap.getAddr(0, 0),
+ lines = scanlineDecoder->getScanlines(bitmap.getAddr(0, 0),
decodeInfo.height(), bitmap.rowBytes());
break;
case SkScanlineDecoder::kOutOfOrder_SkScanlineOrder: {
for (int y = 0; y < decodeInfo.height(); y++) {
int dstY = scanlineDecoder->getY();
void* dstPtr = bitmap.getAddr(0, dstY);
- result = scanlineDecoder->getScanlines(dstPtr, 1, bitmap.rowBytes());
- if (SkCodec::kSuccess != result && SkCodec::kIncompleteInput != result) {
- return SkStringPrintf("%s failed with error message %d",
- fPath.c_str(), (int) result);
+ uint32_t line = scanlineDecoder->getScanlines(dstPtr, 1, bitmap.rowBytes());
+ if (1 != line) {
+ break;
}
+ lines += line;
}
break;
}
}
-
- switch (result) {
- case SkCodec::kSuccess:
- case SkCodec::kIncompleteInput:
- break;
- default:
- return SkStringPrintf("%s failed with error message %d",
- fPath.c_str(), (int) result);
+ if ((int) lines < decodeInfo.height()) {
+ // We have not implemented a function in SkScanlineDecoder to fill remaining
+ // scanlines on an incomplete decode. As long as we are the only client that
+ // uses SkScanlineDecoder, I think this is ok. If this changes, maybe we want
+ // to consider providing an API for this?
+ return Error::Nonfatal("Image is incomplete, could not get scanlines");
}
canvas->drawBitmap(bitmap, 0, 0);
break;
@@ -443,14 +441,9 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
}
}
//skip to first line of subset
- const SkCodec::Result skipResult = decoder->skipScanlines(y);
- switch (skipResult) {
- case SkCodec::kSuccess:
- case SkCodec::kIncompleteInput:
- break;
- default:
- return SkStringPrintf("%s failed after attempting to skip %d scanlines"
- "with error message %d", fPath.c_str(), y, (int) skipResult);
+ int lines = decoder->skipScanlines(y);
+ if (lines < y) {
+ return Error::Nonfatal("Image is incomplete, could not get scanlines");
}
//create and set size of subsetBm
SkBitmap subsetBm;
@@ -458,15 +451,9 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
bounds.setXYWH(0, 0, currentSubsetWidth, currentSubsetHeight);
SkAssertResult(largestSubsetBm.extractSubset(&subsetBm, bounds));
SkAutoLockPixels autlockSubsetBm(subsetBm, true);
- const SkCodec::Result subsetResult =
- decoder->getScanlines(buffer, currentSubsetHeight, rowBytes);
- switch (subsetResult) {
- case SkCodec::kSuccess:
- case SkCodec::kIncompleteInput:
- break;
- default:
- return SkStringPrintf("%s failed with error message %d",
- fPath.c_str(), (int) subsetResult);
+ lines = decoder->getScanlines(buffer, currentSubsetHeight, rowBytes);
+ if (lines < currentSubsetHeight) {
+ return Error::Nonfatal("Image is incomplete, could not get scanlines");
scroggo 2015/09/22 18:02:48 This is going to change the behavior, right? Previ
msarett 2015/09/23 13:22:39 Yes I should have been more explicit about behavio
scroggo 2015/09/25 15:55:05 Sure we can. We just need to make DM fill the buff
msarett 2015/10/01 12:44:51 kScanlineSubset_Mode now fills on incomplete image
}
const size_t bpp = decodeInfo.bytesPerPixel();
/*
@@ -508,30 +495,23 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
// to run this test for image types that do not have this scanline ordering.
return Error::Nonfatal("Could not start top-down scanline decoder");
}
+ int lines;
scroggo 2015/09/22 18:02:48 I would lean towards removing this variable and in
msarett 2015/09/23 13:22:39 Done.
for (int i = 0; i < numStripes; i += 2) {
// Skip a stripe
const int linesToSkip = SkTMin(stripeHeight, height - i * stripeHeight);
- SkCodec::Result result = decoder->skipScanlines(linesToSkip);
- switch (result) {
- case SkCodec::kSuccess:
- case SkCodec::kIncompleteInput:
- break;
- default:
- return SkStringPrintf("Cannot skip scanlines for %s.", fPath.c_str());
+ lines = decoder->skipScanlines(linesToSkip);
+ if (lines < linesToSkip) {
+ return Error::Nonfatal("Image is incomplete, could not get scanlines");
}
// Read a stripe
const int startY = (i + 1) * stripeHeight;
const int linesToRead = SkTMin(stripeHeight, height - startY);
if (linesToRead > 0) {
- result = decoder->getScanlines(bitmap.getAddr(0, startY),
- linesToRead, bitmap.rowBytes());
- switch (result) {
- case SkCodec::kSuccess:
- case SkCodec::kIncompleteInput:
- break;
- default:
- return SkStringPrintf("Cannot get scanlines for %s.", fPath.c_str());
+ lines = decoder->getScanlines(bitmap.getAddr(0, startY), linesToRead,
+ bitmap.rowBytes());
+ if (lines < linesToRead) {
+ return Error::Nonfatal("Image is incomplete, could not get scanlines");
}
}
}
@@ -546,26 +526,18 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
// Read a stripe
const int startY = i * stripeHeight;
const int linesToRead = SkTMin(stripeHeight, height - startY);
- SkCodec::Result result = decoder->getScanlines(bitmap.getAddr(0, startY),
- linesToRead, bitmap.rowBytes());
- switch (result) {
- case SkCodec::kSuccess:
- case SkCodec::kIncompleteInput:
- break;
- default:
- return SkStringPrintf("Cannot get scanlines for %s.", fPath.c_str());
+ lines = decoder->getScanlines(bitmap.getAddr(0, startY), linesToRead,
+ bitmap.rowBytes());
+ if (lines < linesToRead) {
+ return Error::Nonfatal("Image is incomplete, could not get scanlines");
}
// Skip a stripe
const int linesToSkip = SkTMin(stripeHeight, height - (i + 1) * stripeHeight);
if (linesToSkip > 0) {
- result = decoder->skipScanlines(linesToSkip);
- switch (result) {
- case SkCodec::kSuccess:
- case SkCodec::kIncompleteInput:
- break;
- default:
- return SkStringPrintf("Cannot skip scanlines for %s.", fPath.c_str());
+ lines = decoder->skipScanlines(linesToSkip);
+ if (lines < linesToSkip) {
+ return Error::Nonfatal("Image is incomplete, could not get scanlines");
}
}
}
« no previous file with comments | « no previous file | gyp/tools.gyp » ('j') | include/codec/SkCodec.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698