New helpers for converting SkColor to GrColor4f
These versions will eliminate lots of copy-pasting in various fragment processor creation code. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3787 Change-Id: I3ada2d4866e92cfc0507beeea11e05790d73757d Reviewed-on: https://skia-review.googlesource.com/3787 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
6a7287c14b
commit
72ae431e40
@ -42,6 +42,14 @@ static inline GrColor SkColorToUnpremulGrColor(SkColor c) {
|
||||
return GrColorPackRGBA(r, g, b, a);
|
||||
}
|
||||
|
||||
/** Transform an SkColor (sRGB bytes) to GrColor4f for the specified color space. */
|
||||
GrColor4f SkColorToPremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace);
|
||||
GrColor4f SkColorToUnpremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace);
|
||||
|
||||
/**
|
||||
* As above, but with explicit control over the linearization and gamut xform steps.
|
||||
* Typically used when you have easy access to a pre-computed xform.
|
||||
*/
|
||||
GrColor4f SkColorToPremulGrColor4f(SkColor c, bool gammaCorrect, GrColorSpaceXform* gamutXform);
|
||||
GrColor4f SkColorToUnpremulGrColor4f(SkColor c, bool gammaCorrect, GrColorSpaceXform* gamutXform);
|
||||
|
||||
|
@ -438,6 +438,21 @@ sk_sp<GrTexture> GrMakeCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitma
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GrColor4f SkColorToPremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace) {
|
||||
// We want to premultiply after linearizing, so this is easy:
|
||||
return SkColorToUnpremulGrColor4f(c, dstColorSpace).premul();
|
||||
}
|
||||
|
||||
GrColor4f SkColorToUnpremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace) {
|
||||
if (dstColorSpace) {
|
||||
auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
|
||||
auto gamutXform = GrColorSpaceXform::Make(srgbColorSpace.get(), dstColorSpace);
|
||||
return SkColorToUnpremulGrColor4f(c, true, gamutXform.get());
|
||||
} else {
|
||||
return SkColorToUnpremulGrColor4f(c, false, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
GrColor4f SkColorToPremulGrColor4f(SkColor c, bool gammaCorrect, GrColorSpaceXform* gamutXform) {
|
||||
// We want to premultiply after linearizing, so this is easy:
|
||||
return SkColorToUnpremulGrColor4f(c, gammaCorrect, gamutXform).premul();
|
||||
|
Loading…
Reference in New Issue
Block a user