[babl] babl: simplify logic in babl_epsilon_for_zero
- From: Øyvind "pippin" Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl] babl: simplify logic in babl_epsilon_for_zero
- Date: Fri, 16 Aug 2019 21:48:43 +0000 (UTC)
commit 1124c691f445defea27c770160a4df08e3fe3f9c
Author: Øyvind Kolås <pippin gimp org>
Date: Fri Aug 16 23:45:18 2019 +0200
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.
babl/base/util.h | 26 ++++++--------------------
docs/SymmetricAlpha-static.html | 15 +++++----------
2 files changed, 11 insertions(+), 30 deletions(-)
---
diff --git a/babl/base/util.h b/babl/base/util.h
index 123e55627..aba9c61f3 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 1a6d6e334..959f0db7c 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;
}
</pre>
<p>And an example use of this clamping function that is consistent with babls behavior:</p>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]