babl: simplify logic in babl_epsilon_for_zero
authorØyvind Kolås <pippin@gimp.org>
Fri, 16 Aug 2019 21:45:18 +0000 (23:45 +0200)
committerØyvind Kolås <pippin@gimp.org>
Fri, 16 Aug 2019 21:45:21 +0000 (23:45 +0200)
We do not need to treate positive/negative avoided infinities differently,
the result is the same as long as we are consistent, and only using the
positive epsilon value leads to slightly simpler per-pixel conversion code
in both directions.

babl/base/util.h
docs/SymmetricAlpha-static.html

index 123e55627b90b4f955e8c91cb1eb7396212a23db..aba9c61f34c9ebade018d43a7ffdd23f60f27c05 100644 (file)
   }
 
 
-#if 1
-
 static inline double
 babl_epsilon_for_zero (double value)
 {
- if (value <= BABL_ALPHA_FLOOR)
+ if (value <=  BABL_ALPHA_FLOOR &&
+     value >= -BABL_ALPHA_FLOOR)
  {
-   if (value >= 0.0)
-     return BABL_ALPHA_FLOOR;
-   else if (value >= -BABL_ALPHA_FLOOR)
-     return -BABL_ALPHA_FLOOR;
+   return BABL_ALPHA_FLOOR;
  }
  return value;
 }
@@ -65,24 +61,14 @@ babl_epsilon_for_zero (double value)
 static inline float
 babl_epsilon_for_zero_float (float value)
 {
- if (value <= BABL_ALPHA_FLOOR_F)
+ if (value <= BABL_ALPHA_FLOOR_F &&
+     value >= -BABL_ALPHA_FLOOR_F)
  {
-   if (value >= 0.0f)
-     return BABL_ALPHA_FLOOR_F;
-   else if (value >= -BABL_ALPHA_FLOOR_F)
-     return -BABL_ALPHA_FLOOR_F;
+   return BABL_ALPHA_FLOOR_F;
  }
  return value;
 }
 
-#else
-
-#define babl_alpha_avoid_zero(a) \
-  (a)<=BABL_ALPHA_FLOOR?(a)>=0.0?BABL_ALPHA_FLOOR:(a)>=-BABL_ALPHA_FLOOR?-BABL_ALPHA_FLOOR:(a):(a)
-
-#endif
-
-
 
 #define BABL_USE_SRGB_GAMMA
 
index 1a6d6e334f4fcccf98a0b372550fa0e54970fe67..959f0db7c95ffe279762ce8f0f589706fb1b8aac 100644 (file)
@@ -54,16 +54,11 @@ and 16bit extensions of pixel format conversions are needed.
 static inline float
 babl_epsilon_for_zero_float (float value)
 {
- if (value &lt;= BABL_ALPHA_FLOOR_F)
- {
-   /* for performance one could directly retun BABL_ALPHA_FLOOR_F here
-      and dropping handling negative values consistently. */
-   if (value &gt;= 0.0f)
-     return BABL_ALPHA_FLOOR_F;
-   else if (value &gt;= -BABL_ALPHA_FLOOR_F)
-     return -BABL_ALPHA_FLOOR_F;
- }
- return value;  /* most common case, return input value */
+ if (value &lt;= BABL_ALPHA_FLOOR_F &amp;&amp;
+     value &gt;= -BABL_ALPHA_FLOOR_F)
+   return BABL_ALPHA_FLOOR_F;
+ else
+   return value;
 }
 </pre>
 <p>And an example use of this clamping function that is consistent with babls behavior:</p>