Fix issue in image decoders where the bitmap config was not properly set.

R=scroggo@google.com

Review URL: https://codereview.chromium.org/167763003

git-svn-id: http://skia.googlecode.com/svn/trunk@13503 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
djsollen@google.com 2014-02-19 21:45:35 +00:00
parent d58c9c8b81
commit 446cf71426
2 changed files with 21 additions and 8 deletions

View File

@ -333,6 +333,11 @@ bool SkPNGImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* decodedBitmap,
SkScaledBitmapSampler sampler(origWidth, origHeight, sampleSize);
decodedBitmap->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight());
// we should communicate alphaType, even if we early-return in bounds-only-mode.
if (this->getRequireUnpremultipliedColors()) {
decodedBitmap->setAlphaType(kUnpremul_SkAlphaType);
}
if (SkImageDecoder::kDecodeBounds_Mode == mode) {
return true;
}
@ -478,15 +483,9 @@ bool SkPNGImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* decodedBitmap,
}
}
SkAlphaType alphaType = kOpaque_SkAlphaType;
if (reallyHasAlpha) {
if (this->getRequireUnpremultipliedColors()) {
alphaType = kUnpremul_SkAlphaType;
} else {
alphaType = kPremul_SkAlphaType;
}
if (!reallyHasAlpha) {
decodedBitmap->setAlphaType(kOpaque_SkAlphaType);
}
decodedBitmap->setAlphaType(alphaType);
return true;
}

View File

@ -30,6 +30,10 @@ SkImageRef::SkImageRef(const SkImageInfo& info, SkStreamRewindable* stream,
fPrev = fNext = NULL;
fFactory = NULL;
// This sets the colortype/alphatype to exactly match our info, so that this
// can get communicated down to the codec.
fBitmap.setConfig(info);
#ifdef DUMP_IMAGEREF_LIFECYCLE
SkDebugf("add ImageRef %p [%d] data=%d\n",
this, this->info().fColorType, (int)stream->getLength());
@ -118,6 +122,12 @@ bool SkImageRef::prepareBitmap(SkImageDecoder::Mode mode) {
codec->setSampleSize(fSampleSize);
codec->setDitherImage(fDoDither);
if (this->onDecode(codec, fStream, &fBitmap, fBitmap.config(), mode)) {
if (kOpaque_SkAlphaType == fBitmap.alphaType()) {
this->changeAlphaType(kOpaque_SkAlphaType);
}
SkASSERT(this->info().fColorType == fBitmap.colorType());
SkASSERT(this->info().fWidth == fBitmap.width());
SkASSERT(this->info().fHeight == fBitmap.height());
return true;
}
}
@ -178,6 +188,10 @@ SkImageRef::SkImageRef(SkReadBuffer& buffer, SkBaseMutex* mutex)
fPrev = fNext = NULL;
fFactory = NULL;
// This sets the colortype/alphatype to exactly match our info, so that this
// can get communicated down to the codec.
fBitmap.setConfig(this->info());
}
void SkImageRef::flatten(SkWriteBuffer& buffer) const {