diff options
author | Hendiadyoin1 <leon.a@serenityos.org> | 2022-04-01 13:49:02 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-02 18:37:38 +0200 |
commit | d03a6cc6c6e5e2791588f5601403cd94a872bf8c (patch) | |
tree | 90ad106b057c47724f2e002e1a2ccae4f7dd7ed0 /Userland/Libraries/LibGfx/Gamma.h | |
parent | 5ba5a6615d2994bd3decffba31aabbcc4e551eef (diff) | |
download | serenity-d03a6cc6c6e5e2791588f5601403cd94a872bf8c.zip |
LibGfx: Use AK's rsqrt and cast to floats earlier
Diffstat (limited to 'Userland/Libraries/LibGfx/Gamma.h')
-rw-r--r-- | Userland/Libraries/LibGfx/Gamma.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Userland/Libraries/LibGfx/Gamma.h b/Userland/Libraries/LibGfx/Gamma.h index dbb645aa18..face37f303 100644 --- a/Userland/Libraries/LibGfx/Gamma.h +++ b/Userland/Libraries/LibGfx/Gamma.h @@ -14,6 +14,7 @@ #endif #include <AK/SIMD.h> +#include <AK/SIMDMath.h> #define GAMMA 2.2 @@ -59,8 +60,8 @@ inline f32x4 linear_to_gamma4(f32x4 x) // Source for approximation: https://mimosa-pudica.net/fast-gamma/ constexpr float a = 0.00279491f; constexpr float b = 1.15907984f; - float c = (b / AK::sqrt(1.0f + a)) - 1; - return ((b * __builtin_ia32_rsqrtps(x + a)) - c) * x; + float c = (b * AK::rsqrt(1.0f + a)) - 1; + return ((b * AK::SIMD::rsqrt(x + a)) - c) * x; } // Linearize v1 and v2, lerp them by mix factor, then convert back. @@ -86,8 +87,8 @@ inline float linear_to_gamma(float x) // Source for approximation: https://mimosa-pudica.net/fast-gamma/ constexpr float a = 0.00279491; constexpr float b = 1.15907984; - float c = (b / AK::sqrt(1 + a)) - 1; - return ((b / AK::sqrt(x + a)) - c) * x; + float c = (b * AK::rsqrt(1 + a)) - 1; + return ((b * AK::rsqrt(x + a)) - c) * x; } // Linearize v1 and v2, lerp them by mix factor, then convert back. |