[cairo-commit] test/coverage.c test/coverage-rectangles.ref.png test/coverage-triangles.ref.png test/Makefile.am test/Makefile.sources

Chris Wilson ickle at kemper.freedesktop.org
Fri Jun 11 02:30:43 PDT 2010


 test/Makefile.am                 |    2 
 test/Makefile.sources            |    1 
 test/coverage-rectangles.ref.png |binary
 test/coverage-triangles.ref.png  |binary
 test/coverage.c                  |  135 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 138 insertions(+)

New commits:
commit cf426bce8ebd3aff5d50c6a54bbd731132b3d312
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jun 11 10:05:09 2010 +0100

    test: Add a simple coverage test.
    
    This test case should be much clearer than half-coverage over what it
    purports to actually test. In each pixel, it draws a single geometric
    primitive that coverages a known percentage of the pixel and then we
    measure how close the rasterisers are to that ideal.

diff --git a/test/Makefile.am b/test/Makefile.am
index 2063f40..96cf4e9 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -332,6 +332,8 @@ REFERENCE_IMAGES = \
 	copy-path.ps2.ref.png \
 	copy-path.ps3.ref.png \
 	copy-path.ref.png \
+	coverage-rectangles.ref.png \
+	coverage-triangles.ref.png \
 	create-from-png-stream.ref.png \
 	create-from-png.alpha.ref.png \
 	create-from-png.gray-alpha.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 6d11ade..6ef3457 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -50,6 +50,7 @@ test_sources = \
 	composite-integer-translate-over.c		\
 	composite-integer-translate-over-repeat.c	\
 	copy-path.c					\
+	coverage.c					\
 	create-for-stream.c				\
 	create-from-png.c				\
 	create-from-png-stream.c			\
diff --git a/test/coverage-rectangles.ref.png b/test/coverage-rectangles.ref.png
new file mode 100644
index 0000000..cc1d31c
Binary files /dev/null and b/test/coverage-rectangles.ref.png differ
diff --git a/test/coverage-triangles.ref.png b/test/coverage-triangles.ref.png
new file mode 100644
index 0000000..f56cb55
Binary files /dev/null and b/test/coverage-triangles.ref.png differ
diff --git a/test/coverage.c b/test/coverage.c
new file mode 100644
index 0000000..ebb13da
--- /dev/null
+++ b/test/coverage.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2010 Intel Corporation
+ *
+ * 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: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+
+/* Test the fidelity of the rasterisation, because Cairo is my favourite
+ * driver test suite.
+ */
+
+#define WIDTH 256
+#define HEIGHT 40
+
+#include "../src/cairo-fixed-type-private.h"
+#define PRECISION (1 << CAIRO_FIXED_FRAC_BITS)
+
+static uint32_t state;
+
+static uint32_t
+hars_petruska_f54_1_random (void)
+{
+#define rol(x,k) ((x << k) | (x >> (32-k)))
+    return state = (state ^ rol (state, 5) ^ rol (state, 24)) + 0x37798849;
+#undef rol
+}
+
+static double
+random_offset (int range)
+{
+    double x = hars_petruska_f54_1_random() / (double) UINT32_MAX * range / WIDTH;
+    return floor (x * PRECISION) / PRECISION;
+}
+
+static cairo_test_status_t
+rectangles (cairo_t *cr, int width, int height)
+{
+    int x, y, channel;
+
+    state = 0x12345678;
+
+    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+    cairo_paint (cr);
+
+    cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
+    for (channel = 0; channel < 3; channel++) {
+	switch (channel) {
+	default:
+	case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
+	case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
+	case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
+	}
+
+	for (x = 0; x < WIDTH; x++) {
+	    for (y = 0; y < HEIGHT; y++) {
+		double dx = random_offset (WIDTH - x);
+		double dy = random_offset (WIDTH - x);
+		cairo_rectangle (cr, x + dx, y + dy, x / (double) WIDTH, x / (double) WIDTH);
+	    }
+	}
+	cairo_fill (cr);
+    }
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+static cairo_test_status_t
+triangles (cairo_t *cr, int width, int height)
+{
+    int x, y, channel;
+
+    state = 0x12345678;
+
+    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+    cairo_paint (cr);
+
+    cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
+    for (channel = 0; channel < 3; channel++) {
+	switch (channel) {
+	default:
+	case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
+	case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
+	case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
+	}
+
+	for (x = 0; x < WIDTH; x++) {
+	    for (y = 0; y < HEIGHT; y++) {
+		double dx = random_offset (WIDTH - x);
+		double dy = random_offset (WIDTH - x);
+		cairo_move_to (cr, x + dx, y + dy);
+		cairo_rel_line_to (cr, x / (double) WIDTH, 0);
+		cairo_rel_line_to (cr, 0, x / (double) WIDTH);
+		cairo_close_path (cr);
+	    }
+	}
+	cairo_fill (cr);
+    }
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (coverage_rectangles,
+	    "Check the fidelity of the rasterisation.",
+	    NULL, /* keywords */
+	    "raster", /* requirements */
+	    WIDTH, HEIGHT,
+	    NULL, rectangles)
+
+CAIRO_TEST (coverage_triangles,
+	    "Check the fidelity of the rasterisation.",
+	    NULL, /* keywords */
+	    "raster", /* requirements */
+	    WIDTH, HEIGHT,
+	    NULL, triangles)


More information about the cairo-commit mailing list