aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-10-30 13:47:41 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-31 14:55:14 +0000
commitf06ead925c631c42fae734de1e7c72237a2e91f4 (patch)
treed2ae0175607b41087df6bcc55d6fe4342eecc739 /include
parent761f44853fcead7e7a105e1870cb970646814058 (diff)
Add support for transfer functions to GrColorSpaceXform
With this change, untagged sources (eg N32) are treated as sRGB data, which causes a huge number of GMs to render more correctly in GPU sRGB/F16/etc... configs. Also, because the sources are treated as having a color space, we actually do gamut conversion for wide or narrow gamut outputs. This change also applies the transfer function math to individual colors in the case of gradient stops and color shaders. (The CPU backend doesn't do this yet, but I think we've decided there's no reason not to support it). Bug: skia: Change-Id: If76e9e4a268f9f74110ff4bbe4fe189ba5d19d9f Reviewed-on: https://skia-review.googlesource.com/64100 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'include')
-rw-r--r--include/core/SkColorSpace.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/core/SkColorSpace.h b/include/core/SkColorSpace.h
index 5b2d86b175..962253243d 100644
--- a/include/core/SkColorSpace.h
+++ b/include/core/SkColorSpace.h
@@ -54,6 +54,20 @@ struct SK_API SkColorSpaceTransferFn {
* this one.
*/
SkColorSpaceTransferFn invert() const;
+
+ /**
+ * Transform a single float by this transfer function.
+ * For negative inputs, returns sign(x) * f(abs(x)).
+ */
+ float operator()(float x) {
+ SkScalar s = SkScalarSignAsScalar(x);
+ x = sk_float_abs(x);
+ if (x >= fD) {
+ return s * (powf(fA * x + fB, fG) + fE);
+ } else {
+ return s * (fC * x + fF);
+ }
+ }
};
class SK_API SkColorSpace : public SkRefCnt {