summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2011-12-19 19:53:28 -0500
committerSøren Sandmann Pedersen <ssp@redhat.com>2012-01-10 09:04:45 -0500
commit0053a9f8694c837388b78ae26fe81979d0327d28 (patch)
treed55de21d0fe45d2ee99a9b6b2a9ffa7512aecfd8
parent55a010bf31d2eaf71126bdf93eca99fc02037535 (diff)
Rename color_correct() to round_color()
And do the rounding from float to int in the same way cairo does: by multiplying with (1 << width), then subtracting one when the input was 1.0.
-rw-r--r--test/composite.c8
-rw-r--r--test/utils.c34
-rw-r--r--test/utils.h3
3 files changed, 25 insertions, 20 deletions
diff --git a/test/composite.c b/test/composite.c
index edf7257..201c5b8 100644
--- a/test/composite.c
+++ b/test/composite.c
@@ -640,7 +640,7 @@ composite_test (image_t *dst,
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)
@@ -663,13 +663,13 @@ composite_test (image_t *dst,
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);
diff --git a/test/utils.c b/test/utils.c
index 038fd2b..17bca28 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -704,14 +704,23 @@ initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb)
}
}
-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;
@@ -720,16 +729,13 @@ color_correct (pixman_format_code_t format,
}
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));
}
diff --git a/test/utils.h b/test/utils.h
index fbbd30b..22abbc2 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -158,5 +158,4 @@ typedef struct
} color_t;
void
-color_correct (pixman_format_code_t format,
- color_t *color);
+round_color (pixman_format_code_t format, color_t *color);