diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2010-06-10 14:13:53 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2010-06-10 14:18:11 +0100 |
commit | ef5f9b5c61750207947587173d21b46e2d299f33 (patch) | |
tree | 870f2c154c35f14c2f8850a735312b25833b4441 | |
parent | 8d67186cb291cb877e52b987e2ac18c2a1175a57 (diff) |
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.
-rw-r--r-- | test/Makefile.am | 2 | ||||
-rw-r--r-- | test/partial-coverage-half-reference.ref.png | bin | 0 -> 189 bytes | |||
-rw-r--r-- | test/partial-coverage-half-triangles.ref.png | bin | 0 -> 189 bytes | |||
-rw-r--r-- | test/partial-coverage.c | 98 |
4 files changed, 96 insertions, 4 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 8403adfc..3105bad6 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 Binary files differnew file mode 100644 index 00000000..17f4ff06 --- /dev/null +++ b/test/partial-coverage-half-reference.ref.png diff --git a/test/partial-coverage-half-triangles.ref.png b/test/partial-coverage-half-triangles.ref.png Binary files differnew file mode 100644 index 00000000..17f4ff06 --- /dev/null +++ b/test/partial-coverage-half-triangles.ref.png diff --git a/test/partial-coverage.c b/test/partial-coverage.c index 9df87d46..561ff39c 100644 --- a/test/partial-coverage.c +++ b/test/partial-coverage.c @@ -99,6 +99,24 @@ reference (cairo_t *cr, int width, int height) } 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) { uint8_t *occupancy; @@ -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) |