diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 3e525b399c..858aa9b029 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -307,10 +307,9 @@ sk_sp SkImage::makeColorSpace(sk_sp 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(this)); } diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 660c31cfca..55ceba06d2 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -914,15 +914,23 @@ sk_sp SkImage::MakeTextureFromMipMap(GrContext* ctx, const SkImageInfo& info.refColorSpace(), budgeted); } -sk_sp SkImage_Gpu::onMakeColorSpace(sk_sp colorSpace, SkColorType, +sk_sp SkImage_Gpu::onMakeColorSpace(sk_sp target, SkColorType, SkTransferFunctionBehavior premulBehavior) const { if (SkTransferFunctionBehavior::kRespect == premulBehavior) { // TODO: Implement this. return nullptr; } - sk_sp srcSpace = fColorSpace ? fColorSpace : SkColorSpace::MakeSRGB(); - auto xform = GrNonlinearColorSpaceXformEffect::Make(srcSpace.get(), colorSpace.get()); + sk_sp srcSpace = fColorSpace; + if (!fColorSpace) { + if (target->isSRGB()) { + return sk_ref_sp(const_cast((SkImage*)this)); + } + + srcSpace = SkColorSpace::MakeSRGB(); + } + + auto xform = GrNonlinearColorSpaceXformEffect::Make(srcSpace.get(), target.get()); if (!xform) { return sk_ref_sp(const_cast(this)); } @@ -949,7 +957,7 @@ sk_sp SkImage_Gpu::onMakeColorSpace(sk_sp colorSpace, SkC // MDB: this call is okay bc we know 'renderTargetContext' was exact return sk_make_sp(fContext, kNeedNewImageUniqueID, fAlphaType, renderTargetContext->asTextureProxyRef(), - std::move(colorSpace), fBudgeted); + std::move(target), fBudgeted); } diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index e0d418a129..f4f1211eb5 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -348,18 +348,22 @@ bool SkImage_Raster::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) c sk_sp SkImage_Raster::onMakeColorSpace(sk_sp 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*)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);