From 6d36f06751377459e35afe1ac26c59d33b16c730 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 29 Apr 2010 22:12:02 +0200 Subject: [PATCH] image: Round down when rendering antialiased boxes Matches Pixman's output when going via pixman_rasterize_trapezoid() --- src/cairo-fixed-private.h | 6 ++++++ src/cairo-image-surface.c | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cairo-fixed-private.h b/src/cairo-fixed-private.h index 75ecc06dc..b30879438 100644 --- a/src/cairo-fixed-private.h +++ b/src/cairo-fixed-private.h @@ -165,6 +165,12 @@ _cairo_fixed_integer_round (cairo_fixed_t f) return (f + (CAIRO_FIXED_FRAC_MASK+1)/2) >> CAIRO_FIXED_FRAC_BITS; } +static inline int +_cairo_fixed_integer_round_down (cairo_fixed_t f) +{ + return (f + CAIRO_FIXED_FRAC_MASK/2) >> CAIRO_FIXED_FRAC_BITS; +} + static inline int _cairo_fixed_fractional_part (cairo_fixed_t f) { diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c index a6953fb1b..b2b69d372 100644 --- a/src/cairo-image-surface.c +++ b/src/cairo-image-surface.c @@ -2864,10 +2864,11 @@ _composite_boxes (cairo_image_surface_t *dst, cairo_box_t *box = chunk->base; for (i = 0; i < chunk->count; i++) { - int x1 = _cairo_fixed_integer_round (box[i].p1.x); - int y1 = _cairo_fixed_integer_round (box[i].p1.y); - int x2 = _cairo_fixed_integer_round (box[i].p2.x); - int y2 = _cairo_fixed_integer_round (box[i].p2.y); + /* round down here to match Pixman's behavior when using traps. */ + int x1 = _cairo_fixed_integer_round_down (box[i].p1.x); + int y1 = _cairo_fixed_integer_round_down (box[i].p1.y); + int x2 = _cairo_fixed_integer_round_down (box[i].p2.x); + int y2 = _cairo_fixed_integer_round_down (box[i].p2.y); if (x2 == x1 || y2 == y1) continue;