Index: src/core/SkSRGB.h |
diff --git a/src/core/SkSRGB.h b/src/core/SkSRGB.h |
index d567a962d84a598ab24fd60994085761bfb6f5a9..b1b845680af15c3a91e319bcc5bfda63987cab69 100644 |
--- a/src/core/SkSRGB.h |
+++ b/src/core/SkSRGB.h |
@@ -30,21 +30,22 @@ extern const float sk_linear_from_srgb[256]; |
static inline Sk4f sk_linear_to_srgb(const Sk4f& x) { |
// Approximation of the sRGB gamma curve (within 1 when scaled to 8-bit pixels). |
- // For 0.00000f <= x < 0.00349f, 12.92 * x |
- // For 0.00349f <= x <= 1.00000f, 0.679*(x.^0.5) + 0.423*x.^(0.25) - 0.101 |
- // Note that 0.00349 was selected because it is a point where both functions produce the |
- // same pixel value when rounded. |
+ // Tuned by brute force to minimize the number of bytes that fail to round trip, here 0. |
+ // |
+ // TODO: It was easy enough to find these constants that we should probably further tune |
+ // to find one that round trips all bytes correctly while minimizing some overall error. |
mtklein
2016/07/20 00:57:50
Another thought for a follow up:
12.93, -0.097, 0
|
+ |
auto rsqrt = x.rsqrt(), |
sqrt = rsqrt.invert(), |
ftrt = rsqrt.rsqrt(); |
- auto lo = (12.92f * 255.0f) * x; |
+ auto lo = (12.31f * 255.0f) * x; |
- auto hi = (-0.101115084998961f * 255.0f) + |
- (+0.678513029959381f * 255.0f) * sqrt + |
- (+0.422602055039580f * 255.0f) * ftrt; |
+ auto hi = (-0.099f * 255.0f) |
+ + (+0.689f * 255.0f) * sqrt |
+ + (+0.411f * 255.0f) * ftrt; |
- return (x < 0.00349f).thenElse(lo, hi); |
+ return (x < 0.005f).thenElse(lo, hi); |
} |
#endif//SkSRGB_DEFINED |