sk_sp<SkImage> SkImage::makeColorSpace(sk_sp<SkColorSpace> target, SkTransferFunctionBehavior premulBehavior) const { SkColorSpaceTransferFn fn; if (!target || !target->isNumericalTransferFn(&fn)) { return nullptr; } // No need to create a new image if: // (1) The color spaces are equal. // (2) The color type is kAlpha8. if (SkColorSpace::Equals(this->colorSpace(), target.get()) || kAlpha_8_SkColorType == as_IB(this)->onImageInfo().colorType()) { return sk_ref_sp(const_cast<SkImage*>(this)); } SkColorType targetColorType = kN32_SkColorType; if (SkTransferFunctionBehavior::kRespect == premulBehavior && target->gammaIsLinear()) { targetColorType = kRGBA_F16_SkColorType; } // TODO: We might consider making this a deferred conversion? return as_IB(this)->onMakeColorSpace(std::move(target), targetColorType, premulBehavior); }