[cairo-commit] 5 commits - src/cairo-array.c src/cairo-image-surface.c test/clipped-group.image16.ref.png test/clipped-group.ref.png test/clip-stroke.image16.ref.png test/clip-stroke.ref.png test/Makefile.am test/Makefile.sources test/rectilinear-grid.c test/rectilinear-grid.image16.ref.png test/rectilinear-grid.ref.png

Andrea Canciani ranma42 at kemper.freedesktop.org
Sun Nov 28 10:27:15 PST 2010


 src/cairo-array.c                     |    4 -
 src/cairo-image-surface.c             |   26 +++++++----
 test/Makefile.am                      |    2 
 test/Makefile.sources                 |    1 
 test/clip-stroke.image16.ref.png      |binary
 test/clip-stroke.ref.png              |binary
 test/clipped-group.image16.ref.png    |binary
 test/clipped-group.ref.png            |binary
 test/rectilinear-grid.c               |   78 ++++++++++++++++++++++++++++++++++
 test/rectilinear-grid.image16.ref.png |binary
 test/rectilinear-grid.ref.png         |binary
 11 files changed, 100 insertions(+), 11 deletions(-)

New commits:
commit 4e60a164d42d80474d897d7e58c41fb3941bd8e2
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Sun Nov 28 16:58:20 2010 +0100

    test: Fix ref images
    
    The corners of the boxes in these ref images were not correct.

diff --git a/test/clip-stroke.image16.ref.png b/test/clip-stroke.image16.ref.png
index d0019b8..ad62af4 100644
Binary files a/test/clip-stroke.image16.ref.png and b/test/clip-stroke.image16.ref.png differ
diff --git a/test/clip-stroke.ref.png b/test/clip-stroke.ref.png
index dd5ae9a..e66cc43 100644
Binary files a/test/clip-stroke.ref.png and b/test/clip-stroke.ref.png differ
diff --git a/test/clipped-group.image16.ref.png b/test/clipped-group.image16.ref.png
index 85819fe..bf419f6 100644
Binary files a/test/clipped-group.image16.ref.png and b/test/clipped-group.image16.ref.png differ
diff --git a/test/clipped-group.ref.png b/test/clipped-group.ref.png
index c3fcbf8..fe9b8dc 100644
Binary files a/test/clipped-group.ref.png and b/test/clipped-group.ref.png differ
commit 8d7486a6ea3eff4976dacd2629d07ed5b143af23
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Sun Nov 28 14:33:41 2010 +0100

    image: Fix _pixel_to_solid
    
    An A1 image with full alpha should be opaque black, not opaque white.
    
    Use specialized solid black image instead of the generic constructor
    for an A8 image with full alpha (it is likely to be cached).

diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index e0ec561..1ebadee 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -1322,13 +1322,15 @@ _pixel_to_solid (cairo_image_surface_t *image, int x, int y)
 
     case CAIRO_FORMAT_A1:
 	pixel = *(uint8_t *) (image->data + y * image->stride + x/8);
-	return pixel & (1 << (x&7)) ? _pixman_white_image () : _pixman_transparent_image ();
+	return pixel & (1 << (x&7)) ? _pixman_black_image () : _pixman_transparent_image ();
 
     case CAIRO_FORMAT_A8:
 	color.alpha = *(uint8_t *) (image->data + y * image->stride + x);
 	color.alpha |= color.alpha << 8;
 	if (color.alpha == 0)
 	    return _pixman_transparent_image ();
+	if (color.alpha == 0xffff)
+	    return _pixman_black_image ();
 
 	color.red = color.green = color.blue = 0;
 	return pixman_image_create_solid_fill (&color);
commit 72b0a44a1f77c818921a699c55d4b2df0c1d1536
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Sun Nov 28 14:32:51 2010 +0100

    image: Fix compositing of unaligned boxes
    
    The input of _fill_unaligned_boxes is (supposed to be) composed only
    of disjoint rectangles, that can safely be passed to the rectilinear
    span converter, but this function artificially introduces intersecting
    rectangles when drawing non-aligned boxes.
    
    Using non-intersecting rectangles is easy and makes the code correct.
    
    Fixes rectilinear-grid.
    
    Reviewed-by: Uli Schlachter <psychon at znc.in>

diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 9c35d7d..e0ec561 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -2712,7 +2712,13 @@ _fill_unaligned_boxes (cairo_image_surface_t *dst,
 			     x1, y1, x2 - x1, y2 - y1,
 			     pixel);
 
-		/* top */
+		/*
+		 * Corners have to be included only once if the rects
+		 * are passed to the rectangular scan converter
+		 * because it can only handle disjoint rectangles.
+		*/
+
+		/* top (including top-left and top-right corners) */
 		if (! _cairo_fixed_is_integer (box[i].p1.y)) {
 		    b.p1.x = box[i].p1.x;
 		    b.p1.y = box[i].p1.y;
@@ -2724,31 +2730,31 @@ _fill_unaligned_boxes (cairo_image_surface_t *dst,
 			goto CLEANUP_CONVERTER;
 		}
 
-		/* left */
+		/* left (no corners) */
 		if (! _cairo_fixed_is_integer (box[i].p1.x)) {
 		    b.p1.x = box[i].p1.x;
-		    b.p1.y = box[i].p1.y;
+		    b.p1.y = _cairo_fixed_from_int (y1);
 		    b.p2.x = _cairo_fixed_from_int (x1);
-		    b.p2.y = box[i].p2.y;
+		    b.p2.y = _cairo_fixed_from_int (y2);
 
 		    status = _cairo_rectangular_scan_converter_add_box (&converter, &b, 1);
 		    if (unlikely (status))
 			goto CLEANUP_CONVERTER;
 		}
 
-		/* right */
+		/* right (no corners) */
 		if (! _cairo_fixed_is_integer (box[i].p2.x)) {
 		    b.p1.x = _cairo_fixed_from_int (x2);
-		    b.p1.y = box[i].p1.y;
+		    b.p1.y = _cairo_fixed_from_int (y1);
 		    b.p2.x = box[i].p2.x;
-		    b.p2.y = box[i].p2.y;
+		    b.p2.y = _cairo_fixed_from_int (y2);
 
 		    status = _cairo_rectangular_scan_converter_add_box (&converter, &b, 1);
 		    if (unlikely (status))
 			goto CLEANUP_CONVERTER;
 		}
 
-		/* bottom */
+		/* bottom (including bottom-left and bottom-right corners) */
 		if (! _cairo_fixed_is_integer (box[i].p2.y)) {
 		    b.p1.x = box[i].p1.x;
 		    b.p1.y = _cairo_fixed_from_int (y2);
commit 10389730832998567c3abad893c3a1274d71baa7
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Fri Nov 26 17:55:35 2010 +0100

    test: Add rectilinear-grid
    
    The rectilinear scan converter assumes disjoint rects as input, but
    cairo-image passes intersecting rectangles to it.
    
    This test shows that image and any backends passing through it for the
    rasterization (fallbacks, vector backends whose renderer is
    cairo-based) fail in compute the corners of intersecting rectangles
    correctly.

diff --git a/test/Makefile.am b/test/Makefile.am
index 01e5914..b1222de 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1066,6 +1066,8 @@ REFERENCE_IMAGES = \
 	rectilinear-dash.quartz.xfail.png \
 	rectilinear-dash.ref.png \
 	rectilinear-fill.ref.png \
+	rectilinear-grid.image16.ref.png \
+	rectilinear-grid.ref.png \
 	rectilinear-miter-limit.ps2.ref.png \
 	rectilinear-miter-limit.ps3.ref.png \
 	rectilinear-miter-limit.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index a13aea8..b6431d1 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -207,6 +207,7 @@ test_sources = \
 	random-intersections-curves-nz.c		\
 	rectangle-rounding-error.c			\
 	rectilinear-fill.c				\
+	rectilinear-grid.c				\
 	rectilinear-miter-limit.c			\
 	rectilinear-dash.c				\
 	rectilinear-stroke.c				\
diff --git a/test/rectilinear-grid.c b/test/rectilinear-grid.c
new file mode 100644
index 0000000..1baadf7
--- /dev/null
+++ b/test/rectilinear-grid.c
@@ -0,0 +1,78 @@
+/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
+/*
+ * Copyright 2010 Andrea Canciani
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Andrea Canciani <ranma42 at gmail.com>
+ */
+
+#include "cairo-test.h"
+
+#define SIZE 52
+#define OFFSET 5
+#define DISTANCE 10.25
+
+/*
+  This test checks that boxes not aligned to pixels are drawn
+  correctly.
+
+  In particular the corners of the boxes are drawn incorrectly by
+  cairo-image in cairo 1.10.0, because overlapping boxes are passed to
+  a span converter which assumes disjoint boxes as input.
+
+  This results in corners to be drawn with the wrong shade.
+*/
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    int i;
+
+    cairo_set_source_rgb (cr, 1, 1, 1);
+    cairo_paint (cr);
+
+    cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+    cairo_set_source_rgb (cr, 0, 0, 0);
+    cairo_set_line_width (cr, 4);
+    cairo_translate (cr, 2*OFFSET, 2*OFFSET);
+
+    for (i = 0; i < 4; i++) {
+	double x = i * DISTANCE;
+
+	cairo_move_to (cr, x, -OFFSET-0.75);
+	cairo_line_to (cr, x, SIZE-3*OFFSET-0.25);
+
+	cairo_move_to (cr, -OFFSET-0.75, x);
+	cairo_line_to (cr, SIZE-3*OFFSET-0.25, x);
+    }
+
+    cairo_stroke (cr);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (rectilinear_grid,
+	    "Test rectilinear rasterizer (covering partial pixels)",
+	    "rectilinear", /* keywords */
+	    NULL, /* requirements */
+	    SIZE, SIZE,
+	    NULL, draw)
diff --git a/test/rectilinear-grid.image16.ref.png b/test/rectilinear-grid.image16.ref.png
new file mode 100644
index 0000000..4d4c4da
Binary files /dev/null and b/test/rectilinear-grid.image16.ref.png differ
diff --git a/test/rectilinear-grid.ref.png b/test/rectilinear-grid.ref.png
new file mode 100644
index 0000000..8d47ef5
Binary files /dev/null and b/test/rectilinear-grid.ref.png differ
commit cfafa3924b983a38056893b5fd8e836574deee17
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Sun Nov 28 09:31:02 2010 +0100

    array: Fix comment
    
    The comment was talking about using 0 as index, but was using
    "num_elements" instead.

diff --git a/src/cairo-array.c b/src/cairo-array.c
index 673ae5e..52b283f 100644
--- a/src/cairo-array.c
+++ b/src/cairo-array.c
@@ -167,7 +167,7 @@ _cairo_array_index (cairo_array_t *array, unsigned int index)
     /* We allow an index of 0 for the no-elements case.
      * This makes for cleaner calling code which will often look like:
      *
-     *    elements = _cairo_array_index (array, num_elements);
+     *    elements = _cairo_array_index (array, 0);
      *	  for (i=0; i < num_elements; i++) {
      *        ... use elements[i] here ...
      *    }
@@ -211,7 +211,7 @@ _cairo_array_index_const (const cairo_array_t *array, unsigned int index)
     /* We allow an index of 0 for the no-elements case.
      * This makes for cleaner calling code which will often look like:
      *
-     *    elements = _cairo_array_index_const (array, num_elements);
+     *    elements = _cairo_array_index_const (array, 0);
      *	  for (i=0; i < num_elements; i++) {
      *        ... read elements[i] here ...
      *    }


More information about the cairo-commit mailing list