[Pixman] [PATCH 3/4] Move the IS_ZERO() to pixman-private.h and rename to FLOAT_IS_ZERO()

Søren Sandmann sandmann at cs.au.dk
Fri Mar 15 22:34:54 PDT 2013


From: Søren Sandmann Pedersen <ssp at redhat.com>

Some upcoming changes to pixman-gradient-walker.c will need this
macro.
---
 pixman/pixman-combine-float.c |   34 ++++++++++++++++------------------
 pixman/pixman-private.h       |    4 ++++
 2 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/pixman/pixman-combine-float.c b/pixman/pixman-combine-float.c
index 06ce203..5ea739f 100644
--- a/pixman/pixman-combine-float.c
+++ b/pixman/pixman-combine-float.c
@@ -42,8 +42,6 @@
 #define force_inline __inline__
 #endif
 
-#define IS_ZERO(f)     (-FLT_MIN < (f) && (f) < FLT_MIN)
-
 typedef float (* combine_channel_t) (float sa, float s, float da, float d);
 
 static force_inline void
@@ -203,56 +201,56 @@ get_factor (combine_factor_t factor, float sa, float da)
 	break;
 
     case SA_OVER_DA:
-	if (IS_ZERO (da))
+	if (FLOAT_IS_ZERO (da))
 	    f = 1.0f;
 	else
 	    f = CLAMP (sa / da);
 	break;
 
     case DA_OVER_SA:
-	if (IS_ZERO (sa))
+	if (FLOAT_IS_ZERO (sa))
 	    f = 1.0f;
 	else
 	    f = CLAMP (da / sa);
 	break;
 
     case INV_SA_OVER_DA:
-	if (IS_ZERO (da))
+	if (FLOAT_IS_ZERO (da))
 	    f = 1.0f;
 	else
 	    f = CLAMP ((1.0f - sa) / da);
 	break;
 
     case INV_DA_OVER_SA:
-	if (IS_ZERO (sa))
+	if (FLOAT_IS_ZERO (sa))
 	    f = 1.0f;
 	else
 	    f = CLAMP ((1.0f - da) / sa);
 	break;
 
     case ONE_MINUS_SA_OVER_DA:
-	if (IS_ZERO (da))
+	if (FLOAT_IS_ZERO (da))
 	    f = 0.0f;
 	else
 	    f = CLAMP (1.0f - sa / da);
 	break;
 
     case ONE_MINUS_DA_OVER_SA:
-	if (IS_ZERO (sa))
+	if (FLOAT_IS_ZERO (sa))
 	    f = 0.0f;
 	else
 	    f = CLAMP (1.0f - da / sa);
 	break;
 
     case ONE_MINUS_INV_DA_OVER_SA:
-	if (IS_ZERO (sa))
+	if (FLOAT_IS_ZERO (sa))
 	    f = 0.0f;
 	else
 	    f = CLAMP (1.0f - (1.0f - da) / sa);
 	break;
 
     case ONE_MINUS_INV_SA_OVER_DA:
-	if (IS_ZERO (da))
+	if (FLOAT_IS_ZERO (da))
 	    f = 0.0f;
 	else
 	    f = CLAMP (1.0f - (1.0f - sa) / da);
@@ -405,11 +403,11 @@ blend_lighten (float sa, float s, float da, float d)
 static force_inline float
 blend_color_dodge (float sa, float s, float da, float d)
 {
-    if (IS_ZERO (d))
+    if (FLOAT_IS_ZERO (d))
 	return 0.0f;
     else if (d * sa >= sa * da - s * da)
 	return sa * da;
-    else if (IS_ZERO (sa - s))
+    else if (FLOAT_IS_ZERO (sa - s))
 	return sa * da;
     else
 	return sa * sa * d / (sa - s);
@@ -422,7 +420,7 @@ blend_color_burn (float sa, float s, float da, float d)
 	return sa * da;
     else if (sa * (da - d) >= s * da)
 	return 0.0f;
-    else if (IS_ZERO (s))
+    else if (FLOAT_IS_ZERO (s))
 	return 0.0f;
     else
 	return sa * (da - sa * (da - d) / s);
@@ -442,14 +440,14 @@ blend_soft_light (float sa, float s, float da, float d)
 {
     if (2 * s < sa)
     {
-	if (IS_ZERO (da))
+	if (FLOAT_IS_ZERO (da))
 	    return d * sa;
 	else
 	    return d * sa - d * (da - d) * (sa - 2 * s) / da;
     }
     else
     {
-	if (IS_ZERO (da))
+	if (FLOAT_IS_ZERO (da))
 	{
 	    return 0.0f;
 	}
@@ -658,7 +656,7 @@ clip_color (rgb_t *color, float a)
     if (n < 0.0f)
     {
 	t = l - n;
-	if (IS_ZERO (t))
+	if (FLOAT_IS_ZERO (t))
 	{
 	    color->r = 0.0f;
 	    color->g = 0.0f;
@@ -674,7 +672,7 @@ clip_color (rgb_t *color, float a)
     if (x > a)
     {
 	t = x - l;
-	if (IS_ZERO (t))
+	if (FLOAT_IS_ZERO (t))
 	{
 	    color->r = a;
 	    color->g = a;
@@ -758,7 +756,7 @@ set_sat (rgb_t *src, float sat)
 
     t = *max - *min;
 
-    if (IS_ZERO (t))
+    if (FLOAT_IS_ZERO (t))
     {
 	*mid = *max = 0.0f;
     }
diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h
index 181ab5c..91e329f 100644
--- a/pixman/pixman-private.h
+++ b/pixman/pixman-private.h
@@ -1,3 +1,5 @@
+#include <float.h>
+
 #ifndef PIXMAN_PRIVATE_H
 #define PIXMAN_PRIVATE_H
 
@@ -879,6 +881,8 @@ pixman_list_move_to_front (pixman_list_t *list, pixman_link_t *link)
 
 #define CLIP(v, low, high) ((v) < (low) ? (low) : ((v) > (high) ? (high) : (v)))
 
+#define FLOAT_IS_ZERO(f)     (-FLT_MIN < (f) && (f) < FLT_MIN)
+
 /* Conversion between 8888 and 0565 */
 
 static force_inline uint16_t
-- 
1.7.4



More information about the Pixman mailing list