[babl] util, sse2-float: make sure 1 maps to 1 in linear -> gamma conversions



commit 7d9c2609d32efd5575d3f961deb4bb38dbc28ddf
Author: Ell <ell_se yahoo com>
Date:   Thu Jan 11 09:19:50 2018 -0500

    util, sse2-float: make sure 1 maps to 1 in linear -> gamma conversions
    
    Add a small offset to the result of the linear -> gamma
    conversions, such that an input value of 1.0 maps to an output
    value of 1.0, exactly.

 babl/base/util.h        |    7 ++++++-
 extensions/sse2-float.c |    5 ++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/babl/base/util.h b/babl/base/util.h
index e273087..50bba74 100644
--- a/babl/base/util.h
+++ b/babl/base/util.h
@@ -81,7 +81,12 @@ static inline float
 babl_linear_to_gamma_2_2f (float value)
 {
   if (value > 0.003130804954f)
-    return 1.055f * babl_pow_1_24f (value) - 0.055f;
+    {
+      return 1.055f * babl_pow_1_24f (value) -
+             (0.055f                         -
+              3.0f / (float) (1 << 24));
+              /* ^ offset the result such that 1 maps to 1 */
+    }
   return 12.92f * value;
 }
 
diff --git a/extensions/sse2-float.c b/extensions/sse2-float.c
index 223f85c..41a00b2 100644
--- a/extensions/sse2-float.c
+++ b/extensions/sse2-float.c
@@ -304,7 +304,10 @@ sse_pow_24 (__v4sf x)
 static inline __v4sf
 linear_to_gamma_2_2_sse2 (__v4sf x)
 {
-  __v4sf curve = sse_pow_1_24 (x) * splat4f (1.055f) - splat4f (0.055f);
+  __v4sf curve = sse_pow_1_24 (x) * splat4f (1.055f) -
+                 splat4f (0.055f                     -
+                          3.0f / (float) (1 << 24));
+                          /* ^ offset the result such that 1 maps to 1 */
   __v4sf line = x * splat4f (12.92f);
   __v4sf mask = _mm_cmpgt_ps (x, splat4f (0.003130804954f));
   return _mm_or_ps (_mm_and_ps (mask, curve), _mm_andnot_ps (mask, line));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]