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

Unified Diff: src/images/SkImageDecoder_ktx.cpp

Issue 322813005: Do a better job of enforcing the semantics of the setRequireUnpremultipliedColors flag (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Code review changes Created 6 years, 6 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: src/images/SkImageDecoder_ktx.cpp
diff --git a/src/images/SkImageDecoder_ktx.cpp b/src/images/SkImageDecoder_ktx.cpp
index 0dd987cef19e2e4986829afffbeba72453a5703d..fd1db5e9d2e0283df9c9f8818a56cdf16428c5f7 100644
--- a/src/images/SkImageDecoder_ktx.cpp
+++ b/src/images/SkImageDecoder_ktx.cpp
@@ -67,12 +67,30 @@ bool SkKTXImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
return false;
}
+ // Set a flag if our source is premultiplied alpha
+ const SkString premulKey("KTXPremultipliedAlpha");
+ const bool bSrcIsPremul = ktxFile.getValueForKey(premulKey) == SkString("True");
+
// Setup the sampler...
SkScaledBitmapSampler sampler(width, height, this->getSampleSize());
+ // Determine the alpha of the bitmap...
+ SkAlphaType alphaType = kOpaque_SkAlphaType;
+ if (ktxFile.isRGBA8()) {
+ if (this->getRequireUnpremultipliedColors()) {
+ alphaType = kUnpremul_SkAlphaType;
+ // If the client wants unpremul colors and we only have
+ // premul, then we cannot honor their wish.
+ if (bSrcIsPremul) {
+ return false;
+ }
+ } else {
+ alphaType = kPremul_SkAlphaType;
+ }
+ }
+
// Set the config...
- bm->setInfo(SkImageInfo::MakeN32(sampler.scaledWidth(), sampler.scaledHeight(),
- ktxFile.isRGBA8()? kPremul_SkAlphaType : kOpaque_SkAlphaType));
+ bm->setInfo(SkImageInfo::MakeN32(sampler.scaledWidth(), sampler.scaledHeight(), alphaType));
if (SkImageDecoder::kDecodeBounds_Mode == mode) {
return true;
}
@@ -134,17 +152,19 @@ bool SkKTXImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
} else if (ktxFile.isRGBA8()) {
+ // Uncompressed RGBA data
+
// If we know that the image contains premultiplied alpha, then
- // don't premultiply it upon decoding.
- bool setRequireUnpremul = false;
- const SkString premulKey("KTXPremultipliedAlpha");
- if (ktxFile.getValueForKey(premulKey) == SkString("True")) {
- this->setRequireUnpremultipliedColors(true);
- setRequireUnpremul = true;
- }
+ // we need to turn off the premultiplier
+ SkScaledBitmapSampler::Options opts (*this);
+ if (bSrcIsPremul) {
+ SkASSERT(bm->alphaType() == kPremul_SkAlphaType);
+ SkASSERT(!this->getRequireUnpremultipliedColors());
- // Uncompressed RGBA data
- if (!sampler.begin(bm, SkScaledBitmapSampler::kRGBA, *this)) {
+ opts.fPremultiplyAlpha = false;
+ }
+
+ if (!sampler.begin(bm, SkScaledBitmapSampler::kRGBA, opts)) {
return false;
}
@@ -158,11 +178,6 @@ bool SkKTXImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
srcRow += sampler.srcDY() * srcRowBytes;
}
- // Reset this in case the decoder needs to be used again.
- if (setRequireUnpremul) {
- this->setRequireUnpremultipliedColors(false);
- }
-
return true;
}
« 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