*/
bool isLazyGenerated() const;
+ /**
+ * If |target| is supported, returns an SkImage in the |target| color space.
+ * Otherwise, returns nullptr.
+ *
+ * This will leave the image as is if it already in the |target| color space.
+ * Otherwise, it will convert the pixels from the src color space to the |target|
+ * color space. If this->colorSpace() is nullptr, the src color space will be
+ * treated as sRGB.
+ *
+ * If |premulBehavior| is kIgnore, any premultiplication or unpremultiplication will
+ * be performed in the gamma encoded space. If it is kRespect, premultiplication is
+ * assumed to be linear.
+ */
+ sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target,
+ SkTransferFunctionBehavior premulBehavior) const;
+
protected:
SkImage(int width, int height, uint32_t uniqueID);
}
sk_sp<SkImage> SkColorSpaceXformer::apply(const SkImage* src) {
- return as_IB(src)->makeColorSpace(fDst);
+ return src->makeColorSpace(fDst, SkTransferFunctionBehavior::kIgnore);
}
sk_sp<SkImage> SkColorSpaceXformer::apply(const SkBitmap& src) {
return nullptr;
}
- sk_sp<SkImage> xformed = as_IB(image)->makeColorSpace(fDst);
+ sk_sp<SkImage> xformed = image->makeColorSpace(fDst, SkTransferFunctionBehavior::kIgnore);
// We want to be sure we don't let the kNever_SkCopyPixelsMode image escape this stack frame.
SkASSERT(xformed != image);
return xformed;
return as_IB(this)->onImageInfo().colorType() == kAlpha_8_SkColorType;
}
-sk_sp<SkImage> SkImage_Base::makeColorSpace(sk_sp<SkColorSpace> target) const {
+sk_sp<SkImage> SkImage::makeColorSpace(sk_sp<SkColorSpace> target,
+ SkTransferFunctionBehavior premulBehavior) const {
+ if (SkTransferFunctionBehavior::kRespect == premulBehavior) {
+ // TODO (msarett, brianosman): Implement this.
+ return nullptr;
+ }
+
SkColorSpaceTransferFn fn;
if (!target || !target->isNumericalTransferFn(&fn)) {
return nullptr;
// (2) The color type is kAlpha8.
if ((!this->colorSpace() && target->isSRGB()) ||
SkColorSpace::Equals(this->colorSpace(), target.get()) ||
- kAlpha_8_SkColorType == this->onImageInfo().colorType()) {
- return sk_ref_sp(const_cast<SkImage_Base*>(this));
+ kAlpha_8_SkColorType == as_IB(this)->onImageInfo().colorType()) {
+ return sk_ref_sp(const_cast<SkImage*>(this));
}
- return this->onMakeColorSpace(std::move(target));
+ // TODO: We might consider making this a deferred conversion?
+ return as_IB(this)->onMakeColorSpace(std::move(target));
}
//////////////////////////////////////////////////////////////////////////////////////
fAddedToCache.store(true);
}
- // Transforms image into the input color space.
- sk_sp<SkImage> makeColorSpace(sk_sp<SkColorSpace> target) const;
-
virtual bool onPinAsTexture(GrContext*) const { return false; }
virtual void onUnpinAsTexture(GrContext*) const {}
-protected:
- virtual sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const {
- // TODO: Make this pure virtual.
- return sk_ref_sp(const_cast<SkImage_Base*>(this));
- }
+ virtual sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const = 0;
private:
// Set true by caches when they cache content that's derived from the current pixels.
*srgbBitmap.getAddr32(0, 0) = SkSwizzle_RGBA_to_PMColor(0xFF604020);
srgbBitmap.setImmutable();
sk_sp<SkImage> srgbImage = SkImage::MakeFromBitmap(srgbBitmap);
- sk_sp<SkImage> p3Image = as_IB(srgbImage)->makeColorSpace(p3);
+ sk_sp<SkImage> p3Image = srgbImage->makeColorSpace(p3, SkTransferFunctionBehavior::kIgnore);
SkBitmap p3Bitmap;
bool success = p3Image->asLegacyBitmap(&p3Bitmap, SkImage::kRO_LegacyBitmapMode);
REPORTER_ASSERT(r, success);
REPORTER_ASSERT(r, almost_equal(0x40, SkGetPackedG32(*p3Bitmap.getAddr32(0, 0))));
REPORTER_ASSERT(r, almost_equal(0x5E, SkGetPackedB32(*p3Bitmap.getAddr32(0, 0))));
- sk_sp<SkImage> adobeImage = as_IB(srgbImage)->makeColorSpace(adobeGamut);
+ sk_sp<SkImage> adobeImage = srgbImage->makeColorSpace(adobeGamut,
+ SkTransferFunctionBehavior::kIgnore);
SkBitmap adobeBitmap;
success = adobeImage->asLegacyBitmap(&adobeBitmap, SkImage::kRO_LegacyBitmapMode);
REPORTER_ASSERT(r, success);
REPORTER_ASSERT(r, almost_equal(0x4C, SkGetPackedB32(*adobeBitmap.getAddr32(0, 0))));
srgbImage = GetResourceAsImage("1x1.png");
- p3Image = as_IB(srgbImage)->makeColorSpace(p3);
+ p3Image = srgbImage->makeColorSpace(p3, SkTransferFunctionBehavior::kIgnore);
success = p3Image->asLegacyBitmap(&p3Bitmap, SkImage::kRO_LegacyBitmapMode);
REPORTER_ASSERT(r, success);
p3Bitmap.lockPixels();