SkImage::makeColorSpace(): Fix nullptr->sRGB bug with picture images

Bug: 729352
Change-Id: I5ad5e2121ce87dc154528bfd9ec0f3e9253ed792
Reviewed-on: https://skia-review.googlesource.com/18590
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>
This commit is contained in:
Matt Sarett 2017-06-05 10:45:30 -04:00 committed by Skia Commit-Bot
parent d81fed9ce2
commit d3df9ec874
3 changed files with 22 additions and 11 deletions

View File

@ -307,10 +307,9 @@ sk_sp<SkImage> SkImage::makeColorSpace(sk_sp<SkColorSpace> target,
}
// No need to create a new image if:
// (1) The color spaces are equal (nullptr is considered to be sRGB).
// (1) The color spaces are equal.
// (2) The color type is kAlpha8.
if ((!this->colorSpace() && target->isSRGB()) ||
SkColorSpace::Equals(this->colorSpace(), target.get()) ||
if (SkColorSpace::Equals(this->colorSpace(), target.get()) ||
kAlpha_8_SkColorType == as_IB(this)->onImageInfo().colorType()) {
return sk_ref_sp(const_cast<SkImage*>(this));
}

View File

@ -914,15 +914,23 @@ sk_sp<SkImage> SkImage::MakeTextureFromMipMap(GrContext* ctx, const SkImageInfo&
info.refColorSpace(), budgeted);
}
sk_sp<SkImage> SkImage_Gpu::onMakeColorSpace(sk_sp<SkColorSpace> colorSpace, SkColorType,
sk_sp<SkImage> SkImage_Gpu::onMakeColorSpace(sk_sp<SkColorSpace> target, SkColorType,
SkTransferFunctionBehavior premulBehavior) const {
if (SkTransferFunctionBehavior::kRespect == premulBehavior) {
// TODO: Implement this.
return nullptr;
}
sk_sp<SkColorSpace> srcSpace = fColorSpace ? fColorSpace : SkColorSpace::MakeSRGB();
auto xform = GrNonlinearColorSpaceXformEffect::Make(srcSpace.get(), colorSpace.get());
sk_sp<SkColorSpace> srcSpace = fColorSpace;
if (!fColorSpace) {
if (target->isSRGB()) {
return sk_ref_sp(const_cast<SkImage*>((SkImage*)this));
}
srcSpace = SkColorSpace::MakeSRGB();
}
auto xform = GrNonlinearColorSpaceXformEffect::Make(srcSpace.get(), target.get());
if (!xform) {
return sk_ref_sp(const_cast<SkImage_Gpu*>(this));
}
@ -949,7 +957,7 @@ sk_sp<SkImage> SkImage_Gpu::onMakeColorSpace(sk_sp<SkColorSpace> colorSpace, SkC
// MDB: this call is okay bc we know 'renderTargetContext' was exact
return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID,
fAlphaType, renderTargetContext->asTextureProxyRef(),
std::move(colorSpace), fBudgeted);
std::move(target), fBudgeted);
}

View File

@ -348,18 +348,22 @@ bool SkImage_Raster::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) c
sk_sp<SkImage> SkImage_Raster::onMakeColorSpace(sk_sp<SkColorSpace> target,
SkColorType targetColorType,
SkTransferFunctionBehavior premulBehavior) const {
SkImageInfo dstInfo = fBitmap.info().makeColorType(targetColorType).makeColorSpace(target);
SkBitmap dst;
dst.allocPixels(dstInfo);
SkPixmap src;
SkAssertResult(fBitmap.peekPixels(&src));
// Treat nullptr srcs as sRGB.
if (!src.colorSpace()) {
if (target->isSRGB()) {
return sk_ref_sp(const_cast<SkImage*>((SkImage*)this));
}
src.setColorSpace(SkColorSpace::MakeSRGB());
}
SkImageInfo dstInfo = fBitmap.info().makeColorType(targetColorType).makeColorSpace(target);
SkBitmap dst;
dst.allocPixels(dstInfo);
SkAssertResult(dst.writePixels(src, 0, 0, premulBehavior));
dst.setImmutable();
return SkImage::MakeFromBitmap(dst);