diff options
author | reed <reed@google.com> | 2016-01-30 18:52:31 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-30 18:52:31 -0800 |
commit | 395eabeb0e72334c45324874c6e009b54634df21 (patch) | |
tree | b6ff3f497e98db84417c3c6f6e8e2235c277101b /src/core/SkPM4fPriv.h | |
parent | afd25f703d9bbc9cd80b03b63b30abd14db4911d (diff) |
float components in xfermodes
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1623483002
TBR=mtklein
Review URL: https://codereview.chromium.org/1634273002
Diffstat (limited to 'src/core/SkPM4fPriv.h')
-rw-r--r-- | src/core/SkPM4fPriv.h | 77 |
1 files changed, 5 insertions, 72 deletions
diff --git a/src/core/SkPM4fPriv.h b/src/core/SkPM4fPriv.h index a4cec5c449..81aff7013c 100644 --- a/src/core/SkPM4fPriv.h +++ b/src/core/SkPM4fPriv.h @@ -27,12 +27,12 @@ static inline Sk4f to_4f(uint32_t b4) { return SkNx_cast<float>(Sk4b::Load((const uint8_t*)&b4)); } -static inline Sk4f s2l(const Sk4f& s4) { +static inline Sk4f srgb_to_linear(const Sk4f& s4) { return set_alpha(s4 * s4, get_alpha(s4)); } -static inline Sk4f l2s(const Sk4f& l4) { - return set_alpha(l4.rsqrt1() * l4, get_alpha(l4)); +static inline Sk4f linear_to_srgb(const Sk4f& l4) { + return set_alpha(l4.sqrt(), get_alpha(l4)); } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -42,7 +42,7 @@ static inline Sk4f Sk4f_fromL32(uint32_t src) { } static inline Sk4f Sk4f_fromS32(uint32_t src) { - return s2l(to_4f(src) * Sk4f(1.0f/255)); + return srgb_to_linear(to_4f(src) * Sk4f(1.0f/255)); } static inline uint32_t Sk4f_toL32(const Sk4f& x4) { @@ -50,72 +50,5 @@ static inline uint32_t Sk4f_toL32(const Sk4f& x4) { } static inline uint32_t Sk4f_toS32(const Sk4f& x4) { - return to_4b(l2s(x4) * Sk4f(255) + Sk4f(0.5f)); + return to_4b(linear_to_srgb(x4) * Sk4f(255) + Sk4f(0.5f)); } - -/////////////////////////////////////////////////////////////////////////////////////////////////// - -static Sk4f unit_to_l255_round(const SkPM4f& pm4) { - return Sk4f::Load(pm4.fVec) * Sk4f(255) + Sk4f(0.5f); -} - -static Sk4f unit_to_s255_round(const SkPM4f& pm4) { - return l2s(Sk4f::Load(pm4.fVec)) * Sk4f(255) + Sk4f(0.5f); -} - -static inline void SkPM4f_l32_src_mode(SkPMColor dst[], const SkPM4f src[], int count) { - for (int i = 0; i < (count >> 2); ++i) { - SkASSERT(src[0].isUnit()); - SkASSERT(src[1].isUnit()); - SkASSERT(src[2].isUnit()); - SkASSERT(src[3].isUnit()); - Sk4f_ToBytes((uint8_t*)dst, - unit_to_l255_round(src[0]), unit_to_l255_round(src[1]), - unit_to_l255_round(src[2]), unit_to_l255_round(src[3])); - src += 4; - dst += 4; - } - count &= 3; - for (int i = 0; i < count; ++i) { - SkASSERT(src[i].isUnit()); - SkNx_cast<uint8_t>(unit_to_l255_round(src[i])).store((uint8_t*)&dst[i]); - } -} - -static inline void SkPM4f_l32_srcover_mode(SkPMColor dst[], const SkPM4f src[], int count) { - for (int i = 0; i < count; ++i) { - SkASSERT(src[i].isUnit()); - Sk4f s4 = Sk4f::Load(src[i].fVec); - Sk4f d4 = Sk4f_fromL32(dst[i]); - dst[i] = Sk4f_toL32(s4 + d4 * Sk4f(1 - get_alpha(s4))); - } -} - -static inline void SkPM4f_s32_src_mode(SkPMColor dst[], const SkPM4f src[], int count) { - for (int i = 0; i < (count >> 2); ++i) { - SkASSERT(src[0].isUnit()); - SkASSERT(src[1].isUnit()); - SkASSERT(src[2].isUnit()); - SkASSERT(src[3].isUnit()); - Sk4f_ToBytes((uint8_t*)dst, - unit_to_s255_round(src[0]), unit_to_s255_round(src[1]), - unit_to_s255_round(src[2]), unit_to_s255_round(src[3])); - src += 4; - dst += 4; - } - count &= 3; - for (int i = 0; i < count; ++i) { - SkASSERT(src[i].isUnit()); - SkNx_cast<uint8_t>(unit_to_s255_round(src[i])).store((uint8_t*)&dst[i]); - } -} - -static inline void SkPM4f_s32_srcover_mode(SkPMColor dst[], const SkPM4f src[], int count) { - for (int i = 0; i < count; ++i) { - SkASSERT(src[i].isUnit()); - Sk4f s4 = Sk4f::Load(src[i].fVec); - Sk4f d4 = Sk4f_fromS32(dst[i]); - dst[i] = Sk4f_toS32(s4 + d4 * Sk4f(1 - get_alpha(s4))); - } -} - |