From c0dee7964c4394b7963041f246855fd3b01f4ebb Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 16 Jun 2010 18:49:58 +0100 Subject: [PATCH] test: Add a1-rasterisation Check the rounding criteria when rasterising. --- test/Makefile.am | 2 + test/Makefile.sources | 1 + test/a1-rasterisation-rectangles.ref.png | Bin 0 -> 1729 bytes test/a1-rasterisation-triangles.ref.png | Bin 0 -> 1729 bytes test/a1-rasterisation.c | 101 +++++++++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 test/a1-rasterisation-rectangles.ref.png create mode 100644 test/a1-rasterisation-triangles.ref.png create mode 100644 test/a1-rasterisation.c diff --git a/test/Makefile.am b/test/Makefile.am index b76b8148f..a7f1845fc 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -137,6 +137,8 @@ REFERENCE_IMAGES = \ a1-mask.ref.png \ a1-mask-sample.ref.png \ a1-mask-sample.quartz.xfail.png \ + a1-rasterisation-rectangles.ref.png \ + a1-rasterisation-triangles.ref.png \ a1-traps-sample.ref.png \ a1-traps-sample.quartz.xfail.png \ a8-mask.ref.png \ diff --git a/test/Makefile.sources b/test/Makefile.sources index 6dd2e3eb4..243b53af5 100644 --- a/test/Makefile.sources +++ b/test/Makefile.sources @@ -3,6 +3,7 @@ test_sources = \ a1-mask.c \ a1-mask-sample.c \ a1-traps-sample.c \ + a1-rasterisation.c \ a8-mask.c \ aliasing.c \ alpha-similar.c \ diff --git a/test/a1-rasterisation-rectangles.ref.png b/test/a1-rasterisation-rectangles.ref.png new file mode 100644 index 0000000000000000000000000000000000000000..784cf873ecc483f792ddd27ca4013e3c07ba19e6 GIT binary patch literal 1729 zcmeAS@N?(olHy`uVBq!ia0y~yU~C3q4kn<88{2DFAjOvC?e4)T%V>LD(s-NAr{2ZRoegtd^Ss!3 zZpOx^6Z2(cy;z>aq&u81J=UY!U-S4yfRe&)T%V>LD(s-NAr{2ZRoegtd^Ss!3 zZpOx^6Z2(cy;z>aq&u81J=UY!U-S4yfRe& + */ + +#include "cairo-test.h" + +/* + * Test the fidelity of the rasterisation, paying careful attention to rounding. + */ + +#include "../src/cairo-fixed-type-private.h" +#define PRECISION (int)(1 << CAIRO_FIXED_FRAC_BITS) + +#define WIDTH ((PRECISION/2+1)*3) +#define HEIGHT ((PRECISION/2+1)*3) + +#define SUBPIXEL(v) ((v)/(double)(PRECISION/2)) + +static cairo_test_status_t +rectangles (cairo_t *cr, int width, int height) +{ + int x, y; + + cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); + cairo_paint (cr); + + cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); + cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); + + for (x = 0; x < WIDTH; x += 3) { + for (y = 0; y < HEIGHT; y += 3) { + cairo_rectangle (cr, x + SUBPIXEL (y/3) - .5, y + SUBPIXEL (x/3) - .5, .5, .5); + } + } + cairo_fill (cr); + + return CAIRO_TEST_SUCCESS; +} + +static cairo_test_status_t +triangles (cairo_t *cr, int width, int height) +{ + int x, y; + + cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); + cairo_paint (cr); + + cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); + cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); + + for (x = 0; x < WIDTH; x += 3) { + for (y = 0; y < HEIGHT; y += 3) { + /* a rectangle with a diagonal to force tessellation */ + cairo_move_to (cr, x + SUBPIXEL (y/3) - .5, y + SUBPIXEL (x/3) - .5); + cairo_rel_line_to (cr, .5, .5); + cairo_rel_line_to (cr, 0, -.5); + cairo_rel_line_to (cr, -.5, 0); + cairo_rel_line_to (cr, 0, .5); + cairo_rel_line_to (cr, .5, 0); + } + } + cairo_fill (cr); + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (a1_rasterisation_rectangles, + "Check the fidelity of the rasterisation.", + "rasterisation", /* keywords */ + "target=raster", /* requirements */ + WIDTH, HEIGHT, + NULL, rectangles) + +CAIRO_TEST (a1_rasterisation_triangles, + "Check the fidelity of the rasterisation.", + "rasterisation", /* keywords */ + "target=raster", /* requirements */ + WIDTH, HEIGHT, + NULL, triangles)