virtual ~SkColorSpaceXform() {}
+ enum AlphaOp {
+ kPreserve_AlphaOp, // just transfer src-alpha to dst-alpha
+ kPremul_AlphaOp, // like kPreserve, but multiplies RGB by it
+ kSrcIsOpaque_AlphaOp, // src alphas are all 1, this is a perf hint
+ };
+ static bool Apply(SkColorSpace* dstCS, ColorFormat dstFormat, void* dst,
+ SkColorSpace* srcCS, ColorFormat srcFormat, const void* src,
+ int count, AlphaOp);
+
protected:
SkColorSpaceXform() {}
};
alphaType);
}
+bool SkColorSpaceXform::Apply(SkColorSpace* dstCS, ColorFormat dstFormat, void* dst,
+ SkColorSpace* srcCS, ColorFormat srcFormat, const void* src,
+ int count, AlphaOp op) {
+ SkAlphaType at;
+ switch (op) {
+ case kPreserve_AlphaOp: at = kUnpremul_SkAlphaType; break;
+ case kPremul_AlphaOp: at = kPremul_SkAlphaType; break;
+ case kSrcIsOpaque_AlphaOp: at = kOpaque_SkAlphaType; break;
+ }
+ return New(srcCS, dstCS)->apply(dstFormat, dst, srcFormat, src, count, at);
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
template <ColorSpaceMatch kCSM>
dst[i] = SkPM4f_from_SkColor(src[i], nullptr);
}
} else {
- // For now, we want premul to happen on the colors before interplation. If we later want
- // to apply it after the interp, pass kUnpremul here.
- SkAlphaType alphaVerb = kPremul_SkAlphaType;
auto srcCS = SkColorSpace::MakeSRGB();
auto dstCS = as_CSB(deviceCS)->makeLinearGamma();
- SkColorSpaceXform::New(srcCS.get(),
- dstCS.get())->apply(SkColorSpaceXform::kRGBA_F32_ColorFormat, dst,
- SkColorSpaceXform::kBGRA_8888_ColorFormat, src,
- count, alphaVerb);
+ SkColorSpaceXform::Apply(dstCS.get(), SkColorSpaceXform::kRGBA_F32_ColorFormat, dst,
+ srcCS.get(), SkColorSpaceXform::kBGRA_8888_ColorFormat, src,
+ count, SkColorSpaceXform::kPremul_AlphaOp);
}
return dst;
}