summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2012-09-17 06:50:49 -0400
committerSøren Sandmann Pedersen <ssp@redhat.com>2012-09-21 18:36:35 -0400
commit858fed3f97f6d039b08f947159b528a94083e2f1 (patch)
tree886cc61b348920b17c661896f163aa94328116ad
parentc749987ea68bbdc86e1733df17e172c7ef9059c6 (diff)
CLAMP divisions
and go back to clamping in test as well. Note that there are various other cases, blend_dodge() for example, where we can end up dividing by zero. Conflicts: pixman/pixman-combine-float.c
-rw-r--r--pixman/pixman-combine-float.c59
1 files changed, 44 insertions, 15 deletions
diff --git a/pixman/pixman-combine-float.c b/pixman/pixman-combine-float.c
index 9617e240..bd190901 100644
--- a/pixman/pixman-combine-float.c
+++ b/pixman/pixman-combine-float.c
@@ -159,55 +159,84 @@ typedef enum
ONE_MINUS_INV_SA_OVER_DA
} combine_factor_t;
+#define CLAMP(f) \
+ (((f) < 0)? 0 : (((f) > 1.0) ? 1.0 : (f)))
+
+#define IS_ZERO(f) ((f) == 0.0f) /* FIXME? */
+
static force_inline float
get_factor (combine_factor_t factor, float sa, float da)
{
+ float f = -1;
+
switch (factor)
{
case ZERO:
- return 0.0f;
+ f = 0.0f;
+ break;
case ONE:
- return 1.0f;
+ f = 1.0f;
+ break;
case SRC_ALPHA:
- return sa;
+ f = sa;
+ break;
case DEST_ALPHA:
- return da;
+ f = da;
+ break;
case INV_SA:
- return 1 - sa;
+ f = 1 - sa;
+ break;
case INV_DA:
- return 1 - da;
+ f = 1 - da;
+ break;
case SA_OVER_DA:
- return da <= sa ? 1.0f : sa / da;
+ f = IS_ZERO (da)? 1.0f : sa / da;
+ f = CLAMP (f);
+ break;
case DA_OVER_SA:
- return sa <= da ? 1.0f : da / sa;
+ f = IS_ZERO (sa) ? 1.0f : da / sa;
+ f = CLAMP (f);
+ break;
case INV_SA_OVER_DA:
- return da <= 1.0f - sa ? 1.0f : (1.0f - sa) / da;
+ f = IS_ZERO (da) ? 1.0f : (1.0f - sa) / da;
+ f = CLAMP (f);
+ break;
case INV_DA_OVER_SA:
- return sa <= 1.0f - da ? 1.0f : (1.0f - da) / sa;
+ f = IS_ZERO (sa) ? 1.0f : (1.0f - da) / sa;
+ f = CLAMP (f);
+ break;
case ONE_MINUS_SA_OVER_DA:
- return da <= sa ? 0.0f : 1.0f - sa / da;
+ f = IS_ZERO (da) ? 0.0f : 1.0f - sa / da;
+ f = CLAMP (f);
+ break;
case ONE_MINUS_DA_OVER_SA:
- return sa <= da ? 0.0f : 1.0f - da / sa;
+ f = IS_ZERO (sa) ? 0.0f : 1.0f - da / sa;
+ f = CLAMP (f);
+ break;
case ONE_MINUS_INV_DA_OVER_SA:
- return sa <= 1.0f - da ? 0.0f : 1.0f - (1.0f - da) / sa;
+ f = IS_ZERO (sa) ? 0.0f : 1.0f - (1.0f - da) / sa;
+ f = CLAMP (f);
+ break;
case ONE_MINUS_INV_SA_OVER_DA:
- return da <= 1.0f - sa ? 0.0f : 1.0f - (1.0f - sa) / da;
+ f = IS_ZERO (da) ? 0.0f : 1.0f - (1.0f - sa) / da;
+ f = CLAMP (f);
+ break;
}
- return -1;
+ return f;
}
#define MAKE_PD_COMBINERS(name, a, b) \