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:
Mike Reed 2017-05-22 13:41:36 -04:00 committed by Skia Commit-Bot
parent ffc2e4b64d
commit edf8a76219
3 changed files with 24 additions and 7 deletions

View File

@ -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() {}
};

View File

@ -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>

View File

@ -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;
}