From ef5f9b5c61750207947587173d21b46e2d299f33 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 10 Jun 2010 14:13:53 +0100 Subject: [PATCH] test: Update partial coverage. Gah, no wonder the output looked wrong for the triangles, they only covered half the pixel. So separate triangles into two cases. --- test/Makefile.am | 2 + test/partial-coverage-half-reference.ref.png | Bin 0 -> 189 bytes test/partial-coverage-half-triangles.ref.png | Bin 0 -> 189 bytes test/partial-coverage.c | 98 ++++++++++++++++++- 4 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 test/partial-coverage-half-reference.ref.png create mode 100644 test/partial-coverage-half-triangles.ref.png diff --git a/test/Makefile.am b/test/Makefile.am index 8403adfc4..3105bad6e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -862,6 +862,8 @@ REFERENCE_IMAGES = \ paint-with-alpha.ref.png \ paint-with-alpha.svg.ref.png \ paint.ref.png \ + partial-coverage-half-reference.ref.png \ + partial-coverage-half-triangles.ref.png \ partial-coverage-rectangles.ref.png \ partial-coverage-reference.ref.png \ partial-coverage-triangles.ref.png \ diff --git a/test/partial-coverage-half-reference.ref.png b/test/partial-coverage-half-reference.ref.png new file mode 100644 index 0000000000000000000000000000000000000000..17f4ff06b367b25be02a7140335f88f322ee4048 GIT binary patch literal 189 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1SD0tpLGH$wj^(N7l!{JxM1({$v}}JPZ!6K zjK;U;Hwqqb;5oeE#`oXn=LkmZWM-eh_gU85c>C|&)zt+&6%2w7ECGxz45E}#S4|(V Ydm1sDN|l^q0ou;s>FVdQ&MBb@0D8kOT>t<8 literal 0 HcmV?d00001 diff --git a/test/partial-coverage-half-triangles.ref.png b/test/partial-coverage-half-triangles.ref.png new file mode 100644 index 0000000000000000000000000000000000000000..17f4ff06b367b25be02a7140335f88f322ee4048 GIT binary patch literal 189 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1SD0tpLGH$wj^(N7l!{JxM1({$v}}JPZ!6K zjK;U;Hwqqb;5oeE#`oXn=LkmZWM-eh_gU85c>C|&)zt+&6%2w7ECGxz45E}#S4|(V Ydm1sDN|l^q0ou;s>FVdQ&MBb@0D8kOT>t<8 literal 0 HcmV?d00001 diff --git a/test/partial-coverage.c b/test/partial-coverage.c index 9df87d469..561ff39c4 100644 --- a/test/partial-coverage.c +++ b/test/partial-coverage.c @@ -98,6 +98,24 @@ reference (cairo_t *cr, int width, int height) return CAIRO_STATUS_SUCCESS; } +static cairo_test_status_t +half_reference (cairo_t *cr, int width, int height) +{ + int i; + + cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); + cairo_paint (cr); + + for (i = 0; i < SIZE*SIZE; i++) { + cairo_set_source_rgba (cr, 1., 1., 1., + .5 * i / (double) (SIZE * SIZE)); + cairo_rectangle (cr, i % SIZE, i / SIZE, 1, 1); + cairo_fill (cr); + } + + return CAIRO_STATUS_SUCCESS; +} + static cairo_test_status_t rectangles (cairo_t *cr, int width, int height) { @@ -145,7 +163,7 @@ rectangles (cairo_t *cr, int width, int height) } static cairo_test_status_t -triangles (cairo_t *cr, int width, int height) +half_triangles (cairo_t *cr, int width, int height) { uint8_t *occupancy; int i, j, channel; @@ -191,23 +209,95 @@ triangles (cairo_t *cr, int width, int height) return CAIRO_TEST_SUCCESS; } +static cairo_test_status_t +full_triangles (cairo_t *cr, int width, int height) +{ + uint8_t *occupancy; + int i, j, channel; + + state = 0x12345678; + occupancy = xmalloc (SAMPLE*SAMPLE); + + 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 (i = 0; i < SIZE*SIZE; i++) { + int xs, ys; + + compute_occupancy (occupancy, SAMPLE*SAMPLE * i / (SIZE * SIZE)); + + xs = i % SIZE * SAMPLE; + ys = i / SIZE * SAMPLE; + for (j = 0; j < SAMPLE*SAMPLE; j++) { + if (occupancy[j]) { + /* Add a tile composed of two non-overlapping triangles. + * .__. + * | /| + * |/ | + * .--. + */ + int x = j % SAMPLE + xs; + int y = j / SAMPLE + ys; + + /* top-left triangle */ + cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_line_to (cr, (x+1) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_line_to (cr, (x) / (double) SAMPLE, (y+1) / (double) SAMPLE); + cairo_close_path (cr); + + /* bottom-right triangle */ + cairo_move_to (cr, (x) / (double) SAMPLE, (y+1) / (double) SAMPLE); + cairo_line_to (cr, (x+1) / (double) SAMPLE, (y+1) / (double) SAMPLE); + cairo_line_to (cr, (x+1) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_close_path (cr); + } + } + cairo_fill (cr); + } + } + + free (occupancy); + + return CAIRO_TEST_SUCCESS; +} + CAIRO_TEST (partial_coverage_rectangles, "Check the fidelity of the rasterisation.", "coverage raster", /* keywords */ "raster", /* requirements */ SIZE, SIZE, NULL, rectangles) - CAIRO_TEST (partial_coverage_triangles, "Check the fidelity of the rasterisation.", "coverage raster", /* keywords */ "raster", /* requirements */ SIZE, SIZE, - NULL, triangles) - + NULL, full_triangles) CAIRO_TEST (partial_coverage_reference, "Check the fidelity of this test.", "coverage raster", /* keywords */ "raster", /* requirements */ SIZE, SIZE, NULL, reference) + +CAIRO_TEST (partial_coverage_half_triangles, + "Check the fidelity of the rasterisation.", + "coverage raster", /* keywords */ + "raster", /* requirements */ + SIZE, SIZE, + NULL, half_triangles) +CAIRO_TEST (partial_coverage_half_reference, + "Check the fidelity of this test.", + "coverage raster", /* keywords */ + "raster", /* requirements */ + SIZE, SIZE, + NULL, half_reference)