aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar scroggo <scroggo@google.com>2015-03-05 11:46:40 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-03-05 11:46:40 -0800
commit56e25ddf6e2c1f85c5addbe498a082268ebee6ea (patch)
tree6b9334460709c6ac4b7f9d940bbd9623a2ccb487
parent548bf38b28986fab6770350b72247d7114d98184 (diff)
DM: Use the new non-fatal errors for invalid color conversions.
Also allow incomplete to be considered successful. Do not attempt to draw transparent images on 565. BUG=skia:3475 Review URL: https://codereview.chromium.org/978413002
-rw-r--r--dm/DMSrcSink.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index d99f0115b3..5ca66c50e2 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -70,14 +70,27 @@ Error ImageSrc::draw(SkCanvas* canvas) const {
SkAutoLockPixels alp(bitmap);
const SkImageGenerator::Result result = codec->getPixels(info, bitmap.getPixels(),
bitmap.rowBytes());
- if (result != SkImageGenerator::kSuccess) {
- return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
+ switch (result) {
+ case SkImageGenerator::kSuccess:
+ // We consider incomplete to be valid, since we should still decode what is
+ // available.
+ case SkImageGenerator::kIncompleteInput:
+ break;
+ case SkImageGenerator::kInvalidConversion:
+ return Error::Nonfatal("Incompatible colortype conversion");
+ default:
+ // Everything else is considered a failure.
+ return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
}
} else {
if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap,
dstColorType, SkImageDecoder::kDecodePixels_Mode)) {
return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
}
+ if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) {
+ // Do not draw a bitmap with alpha to a destination without alpha.
+ return Error::Nonfatal("Uninteresting to decode image with alpha into 565.");
+ }
}
encoded.reset((SkData*)NULL); // Might as well drop this when we're done with it.
canvas->drawBitmap(bitmap, 0,0);
@@ -110,6 +123,15 @@ Error ImageSrc::draw(SkCanvas* canvas) const {
return SkStringPrintf("Could not decode subset (%d, %d, %d, %d).",
x, y, x+subsetWidth, y+subsetHeight);
}
+ if (kRGB_565_SkColorType == dstColorType && !subset.isOpaque()) {
+ // Do not draw a bitmap with alpha to a destination without alpha.
+ // This is not an error, but there is nothing interesting to show.
+
+ // This should only happen on the first iteration through the loop.
+ SkASSERT(0 == x && 0 == y);
+
+ return Error::Nonfatal("Uninteresting to decode image with alpha into 565.");
+ }
canvas->drawBitmap(subset, SkIntToScalar(x), SkIntToScalar(y));
}
}