From: Øyvind Kolås Date: Fri, 16 Aug 2019 21:45:18 +0000 (+0200) Subject: babl: simplify logic in babl_epsilon_for_zero X-Git-Tag: archive/raspbian/1%0.1.106-3+rpi1^2~15^2~11^2~17 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=1124c691f445defea27c770160a4df08e3fe3f9c;p=babl.git babl: simplify logic in babl_epsilon_for_zero 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. --- diff --git a/babl/base/util.h b/babl/base/util.h index 123e556..aba9c61 100644 --- a/babl/base/util.h +++ b/babl/base/util.h @@ -47,17 +47,13 @@ } -#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 diff --git a/docs/SymmetricAlpha-static.html b/docs/SymmetricAlpha-static.html index 1a6d6e3..959f0db 100644 --- a/docs/SymmetricAlpha-static.html +++ b/docs/SymmetricAlpha-static.html @@ -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 <= BABL_ALPHA_FLOOR_F) - { - /* for performance one could directly retun BABL_ALPHA_FLOOR_F here - and dropping handling negative values consistently. */ - if (value >= 0.0f) - return BABL_ALPHA_FLOOR_F; - else if (value >= -BABL_ALPHA_FLOOR_F) - return -BABL_ALPHA_FLOOR_F; - } - return value; /* most common case, return input value */ + if (value <= BABL_ALPHA_FLOOR_F && + value >= -BABL_ALPHA_FLOOR_F) + return BABL_ALPHA_FLOOR_F; + else + return value; }

And an example use of this clamping function that is consistent with babls behavior: