mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-02-24 04:20:37 +01:00
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.
This commit is contained in:
parent
bd3d9ef3d1
commit
cf426bce8e
5 changed files with 138 additions and 0 deletions
|
|
@ -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 \
|
||||
|
|
|
|||
|
|
@ -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 \
|
||||
|
|
|
|||
BIN
test/coverage-rectangles.ref.png
Normal file
BIN
test/coverage-rectangles.ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 259 B |
BIN
test/coverage-triangles.ref.png
Normal file
BIN
test/coverage-triangles.ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 253 B |
135
test/coverage.c
Normal file
135
test/coverage.c
Normal file
|
|
@ -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@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)
|
||||
Loading…
Add table
Reference in a new issue