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

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: Use different options if our KTXPremultiplied flag is set to true. 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 6ff245954008fed7845d651436157240ddc2870d..c0751d5d36e7068f9191f28aad58fb545e8b12e7 100644
--- a/src/images/SkImageDecoder_ktx.cpp
+++ b/src/images/SkImageDecoder_ktx.cpp
@@ -67,14 +67,32 @@ bool SkKTXImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
return false;
}
+ // Set a flag if our source is premultiplied alpha
+ const SkString premulKey("KTXPremultipliedAlpha");
+ bool bSrcIsPremul = ktxFile.getValueForKey(premulKey) == SkString("True");
scroggo 2014/06/10 13:50:23 const
krajcevski 2014/06/10 14:47:29 Done.
+
// 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.
scroggo 2014/06/10 13:50:23 FWIW, we *could* do a second pass and unpremultipl
krajcevski 2014/06/10 14:47:29 I agree, although I believe the use case for that
+ if (bSrcIsPremul) {
+ return false;
+ }
+ } else {
+ alphaType = kPremul_SkAlphaType;
+ }
+ }
+
// Set the config...
bm->setConfig(SkBitmap::kARGB_8888_Config,
sampler.scaledWidth(), sampler.scaledHeight(),
- 0,
- ktxFile.isRGBA8()? kPremul_SkAlphaType : kOpaque_SkAlphaType);
+ 0, alphaType);
if (SkImageDecoder::kDecodeBounds_Mode == mode) {
return true;
}
@@ -136,18 +154,23 @@ bool SkKTXImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
} else if (ktxFile.isRGBA8()) {
- // 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;
- }
-
// Uncompressed RGBA data
- if (!sampler.begin(bm, SkScaledBitmapSampler::kRGBA, *this)) {
- return false;
+
+ // If we know that the image contains premultiplied alpha, then
+ // we need to turn off the premultiplier
+ if (bSrcIsPremul) {
+ SkASSERT(bm->alphaType() == kPremul_SkAlphaType);
+ SkASSERT(!this->getRequireUnpremultipliedColors());
+
+ SkScaledBitmapSampler::Options opts (*this);
scroggo 2014/06/10 13:50:23 It might be simpler to move this outside of the if
krajcevski 2014/06/10 14:47:29 Done.
+ opts.fPremultiplyAlpha = false;
+ if (!sampler.begin(bm, SkScaledBitmapSampler::kRGBA, opts)) {
+ return false;
+ }
+ } else {
+ if (!sampler.begin(bm, SkScaledBitmapSampler::kRGBA, *this)) {
+ return false;
+ }
}
// Just need to read RGBA pixels
@@ -160,11 +183,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