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

Unified Diff: dm/DMSrcSink.cpp

Issue 978413002: DM: Use the new non-fatal errors for invalid color conversions. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update nonfatal error message. Created 5 years, 10 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 | no next file » | no next file with comments »
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 d99f0115b3ad108bbc368361303d0daa9babfefb..5ca66c50e207c4809f41396e907d354d4d78a17d 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));
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698