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: // 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. // (2) The color type is kAlpha8.
if ((!this->colorSpace() && target->isSRGB()) || if (SkColorSpace::Equals(this->colorSpace(), target.get()) ||
SkColorSpace::Equals(this->colorSpace(), target.get()) ||
kAlpha_8_SkColorType == as_IB(this)->onImageInfo().colorType()) { kAlpha_8_SkColorType == as_IB(this)->onImageInfo().colorType()) {
return sk_ref_sp(const_cast<SkImage*>(this)); 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); 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 { SkTransferFunctionBehavior premulBehavior) const {
if (SkTransferFunctionBehavior::kRespect == premulBehavior) { if (SkTransferFunctionBehavior::kRespect == premulBehavior) {
// TODO: Implement this. // TODO: Implement this.
return nullptr; return nullptr;
} }
sk_sp<SkColorSpace> srcSpace = fColorSpace ? fColorSpace : SkColorSpace::MakeSRGB(); sk_sp<SkColorSpace> srcSpace = fColorSpace;
auto xform = GrNonlinearColorSpaceXformEffect::Make(srcSpace.get(), colorSpace.get()); 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) { if (!xform) {
return sk_ref_sp(const_cast<SkImage_Gpu*>(this)); 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 // MDB: this call is okay bc we know 'renderTargetContext' was exact
return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID,
fAlphaType, renderTargetContext->asTextureProxyRef(), 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, sk_sp<SkImage> SkImage_Raster::onMakeColorSpace(sk_sp<SkColorSpace> target,
SkColorType targetColorType, SkColorType targetColorType,
SkTransferFunctionBehavior premulBehavior) const { SkTransferFunctionBehavior premulBehavior) const {
SkImageInfo dstInfo = fBitmap.info().makeColorType(targetColorType).makeColorSpace(target);
SkBitmap dst;
dst.allocPixels(dstInfo);
SkPixmap src; SkPixmap src;
SkAssertResult(fBitmap.peekPixels(&src)); SkAssertResult(fBitmap.peekPixels(&src));
// Treat nullptr srcs as sRGB. // Treat nullptr srcs as sRGB.
if (!src.colorSpace()) { if (!src.colorSpace()) {
if (target->isSRGB()) {
return sk_ref_sp(const_cast<SkImage*>((SkImage*)this));
}
src.setColorSpace(SkColorSpace::MakeSRGB()); src.setColorSpace(SkColorSpace::MakeSRGB());
} }
SkImageInfo dstInfo = fBitmap.info().makeColorType(targetColorType).makeColorSpace(target);
SkBitmap dst;
dst.allocPixels(dstInfo);
SkAssertResult(dst.writePixels(src, 0, 0, premulBehavior)); SkAssertResult(dst.writePixels(src, 0, 0, premulBehavior));
dst.setImmutable(); dst.setImmutable();
return SkImage::MakeFromBitmap(dst); return SkImage::MakeFromBitmap(dst);