Chromium Code Reviews| Index: src/core/SkPM4fPriv.h |
| diff --git a/src/core/SkPM4fPriv.h b/src/core/SkPM4fPriv.h |
| index bf5ff5a1ad44b4914caf36d005653dad4e20c5da..ea0daa8786903ac2f7426a1546d981d72e6baf1e 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.04044824) { |
|
Brian Osman
2016/06/10 13:37:14
Where did this constant come from? I've always see
reed1
2016/06/10 14:26:04
Done.
|
| + 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 |