tmsk = *mask->color;
if (mask->size)
{
- color_correct (mask->format->format, &tmsk);
+ round_color (mask->format->format, &tmsk);
if (component_alpha &&
PIXMAN_FORMAT_R (mask->format->format) == 0)
get_pixel (dst->image, dst->format->format, &result);
tdst = *dst->color;
- color_correct (dst->format->format, &tdst);
+ round_color (dst->format->format, &tdst);
tsrc = *src->color;
if (src->size)
- color_correct (src->format->format, &tsrc);
+ round_color (src->format->format, &tsrc);
do_composite (op->op, &tsrc, mask ? &tmsk : NULL, &tdst,
&expected, component_alpha);
- color_correct (dst->format->format, &expected);
+ round_color (dst->format->format, &expected);
diff = eval_diff (&expected, &result, dst->format->format);
}
}
-void
-color_correct (pixman_format_code_t format,
- color_t *color)
+static double
+round_channel (double p, int m)
{
-#define MASK(x) ((1 << (x)) - 1)
-#define round_pix(pix, m) \
- ((int)((pix) * (MASK(m)) + .5) / (double) (MASK(m)))
+ int t;
+ double r;
+
+ t = p * ((1 << m));
+ t -= t >> m;
+
+ r = t / (double)((1 << m) - 1);
+
+ return r;
+}
+void
+round_color (pixman_format_code_t format, color_t *color)
+{
if (PIXMAN_FORMAT_R (format) == 0)
{
color->r = 0.0;
}
else
{
- color->r = round_pix (color->r, PIXMAN_FORMAT_R (format));
- color->g = round_pix (color->g, PIXMAN_FORMAT_G (format));
- color->b = round_pix (color->b, PIXMAN_FORMAT_B (format));
+ color->r = round_channel (color->r, PIXMAN_FORMAT_R (format));
+ color->g = round_channel (color->g, PIXMAN_FORMAT_G (format));
+ color->b = round_channel (color->b, PIXMAN_FORMAT_B (format));
}
if (PIXMAN_FORMAT_A (format) == 0)
- color->a = 1.0;
+ color->a = 1;
else
- color->a = round_pix (color->a, PIXMAN_FORMAT_A (format));
-
-#undef round_pix
-#undef MASK
+ color->a = round_channel (color->a, PIXMAN_FORMAT_A (format));
}