add helper static to SkColorSpaceXform
Bug: skia: Change-Id: I62525b392dfbae3d7075cf7f14e30780bad41279 Reviewed-on: https://skia-review.googlesource.com/17485 Reviewed-by: Matt Sarett <msarett@google.com> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
ffc2e4b64d
commit
edf8a76219
@ -60,6 +60,15 @@ public:
|
||||
|
||||
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() {}
|
||||
};
|
||||
|
@ -1137,6 +1137,18 @@ bool SkColorSpaceXform::apply(ColorFormat dstColorFormat, void* dst, ColorFormat
|
||||
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>
|
||||
|
@ -402,15 +402,11 @@ static SkPM4f* convert_colors(const SkColor src[], int count, SkColorSpace* devi
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user