Index: src/core/SkPM4fPriv.h |
diff --git a/src/core/SkPM4fPriv.h b/src/core/SkPM4fPriv.h |
index bf5ff5a1ad44b4914caf36d005653dad4e20c5da..12bf7d0f36bb2b8bd608ebf56ea12e11e3862ca5 100644 |
--- a/src/core/SkPM4fPriv.h |
+++ b/src/core/SkPM4fPriv.h |
@@ -52,6 +52,48 @@ static inline float linear_to_srgb(float x) { |
return sqrtf(x); |
} |
+static void assert_unit(float x) { |
+ SkASSERT(x >= 0 && x <= 1); |
+} |
+ |
+static inline float exact_srgb_to_linear(float x) { |
+ assert_unit(x); |
+ float linear; |
+ if (x <= 0.04045) { |
+ linear = x / 12.92f; |
+ } else { |
+ linear = powf((x + 0.055f) / 1.055f, 2.4f); |
+ } |
+ assert_unit(linear); |
+ return linear; |
+} |
+ |
+static inline float exact_linear_to_srgb(float x) { |
+ assert_unit(x); |
+ float srgb; |
+ if (x <= 0.0031308f) { |
+ srgb = x * 12.92f; |
+ } else { |
+ srgb = 1.055f * powf(x, 0.41666667f) - 0.055f; |
+ } |
+ assert_unit(srgb); |
+ return srgb; |
+} |
+ |
+static inline Sk4f exact_srgb_to_linear(const Sk4f& x) { |
+ Sk4f linear(exact_srgb_to_linear(x[0]), |
+ exact_srgb_to_linear(x[1]), |
+ exact_srgb_to_linear(x[2]), 1); |
+ return set_alpha(linear, get_alpha(x)); |
+} |
+ |
+static inline Sk4f exact_linear_to_srgb(const Sk4f& x) { |
+ Sk4f srgb(exact_linear_to_srgb(x[0]), |
+ exact_linear_to_srgb(x[1]), |
+ exact_linear_to_srgb(x[2]), 1); |
+ return set_alpha(srgb, get_alpha(x)); |
+} |
+ |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
static inline Sk4f Sk4f_fromL32(uint32_t src) { |
@@ -77,4 +119,11 @@ static inline uint32_t Sk4f_toS32(const Sk4f& x4) { |
return to_4b(linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f)); |
} |
+static inline Sk4f exact_Sk4f_fromS32(uint32_t src) { |
+ return exact_srgb_to_linear(to_4f(src) * Sk4f(1.0f/255)); |
+} |
+static inline uint32_t exact_Sk4f_toS32(const Sk4f& x4) { |
+ return to_4b(exact_linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f)); |
+} |
+ |
#endif |