diff options
author | reed <reed@google.com> | 2016-06-10 11:41:47 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-10 11:41:47 -0700 |
commit | 6644d9353f3f0c09914385fd762e073f98d54205 (patch) | |
tree | 617f3b1d2ca2b06cc34decfb44c4c975ba903ca5 /src/core/SkPM4fPriv.h | |
parent | 7049396b65660907af5292d899053280430d929a (diff) |
respect srgb gamma when building mips
Proposed policy:
- If the target is *legacy* (e.g. L32/PMColor) ignore gamma
- If the target is S32/F16 respect gamma
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2029373004
Review-Url: https://codereview.chromium.org/2029373004
Diffstat (limited to 'src/core/SkPM4fPriv.h')
-rw-r--r-- | src/core/SkPM4fPriv.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/core/SkPM4fPriv.h b/src/core/SkPM4fPriv.h index bf5ff5a1ad..12bf7d0f36 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 |