#include "cairo-test.h"
#define GENERATE_REFERENCE 0
#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, int precise)
{
double x = hars_petruska_f54_1_random() / (double) UINT32_MAX * range / WIDTH;
if (precise)
x = floor (x * PRECISION) / PRECISION;
return x;
}
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);
#if GENERATE_REFERENCE
for (x = 0; x < WIDTH; x++) {
cairo_set_source_rgba (cr, 1, 1, 1, x * x * 1.0 / (WIDTH * WIDTH));
cairo_rectangle (cr, x, 0, 1, HEIGHT);
cairo_fill (cr);
}
#else
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, TRUE);
double dy = random_offset (WIDTH - x, TRUE);
cairo_rectangle (cr, x + dx, y + dy, x / (double) WIDTH, x / (double) WIDTH);
}
}
cairo_fill (cr);
}
#endif
return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
intersecting_quads (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);
#if GENERATE_REFERENCE
for (x = 0; x < WIDTH; x++) {
cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.5 / (WIDTH * WIDTH));
cairo_rectangle (cr, x, 0, 1, HEIGHT);
cairo_fill (cr);
}
#else
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++) {
double step = x / (double) WIDTH;
for (y = 0; y < HEIGHT; y++) {
double dx = random_offset (WIDTH - x, TRUE);
double dy = random_offset (WIDTH - x, TRUE);
cairo_move_to (cr, x + dx, y + dy);
cairo_rel_line_to (cr, step, step);
cairo_rel_line_to (cr, 0, -step);
cairo_rel_line_to (cr, -step, step);
cairo_close_path (cr);
}
}
cairo_fill (cr);
}
#endif
return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
intersecting_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);
#if GENERATE_REFERENCE
for (x = 0; x < WIDTH; x++) {
cairo_set_source_rgba (cr, 1, 1, 1, x * 0.75 / WIDTH);
cairo_rectangle (cr, x, 0, 1, HEIGHT);
cairo_fill (cr);
}
#else
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++) {
double step = x / (double) WIDTH;
for (y = 0; y < HEIGHT; y++) {
double dx = random_offset (WIDTH - x, TRUE);
double dy = random_offset (WIDTH - x, TRUE);
cairo_move_to (cr, x + dx, y + dy);
cairo_rel_line_to (cr, 0, step);
cairo_rel_line_to (cr, step, 0);
cairo_close_path (cr);
cairo_move_to (cr, x + dx + step, y + dy + step);
cairo_rel_line_to (cr, 0, -step);
cairo_rel_line_to (cr, -step, step);
cairo_close_path (cr);
}
}
cairo_fill (cr);
}
#endif
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);
#if GENERATE_REFERENCE
for (x = 0; x < WIDTH; x++) {
cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.5 / (WIDTH * WIDTH));
cairo_rectangle (cr, x, 0, 1, HEIGHT);
cairo_fill (cr);
}
#else
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, TRUE);
double dy = random_offset (WIDTH - x, TRUE);
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);
}
#endif
return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
column_triangles (cairo_t *cr, int width, int height)
{
int x, y, i, channel;
state = 0x12345678;
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
cairo_paint (cr);
#if GENERATE_REFERENCE
for (x = 0; x < WIDTH; x++) {
cairo_set_source_rgba (cr, 1, 1, 1, x * 0.5 / WIDTH);
cairo_rectangle (cr, x, 0, 1, HEIGHT);
cairo_fill (cr);
}
#else
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++) {
double step = x / (double) (2 * WIDTH);
for (y = 0; y < HEIGHT; y++) {
for (i = 0; i < PRECISION; i++) {
double dy = random_offset (WIDTH - x, FALSE);
cairo_move_to (cr, x + i / (double) PRECISION, y + dy);
cairo_rel_line_to (cr, 0, step);
cairo_rel_line_to (cr, 1 / (double) PRECISION, step);
cairo_rel_line_to (cr, 0, -step);
cairo_close_path (cr);
}
cairo_fill (cr);
}
}
}
#endif
return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
row_triangles (cairo_t *cr, int width, int height)
{
int x, y, i, channel;
state = 0x12345678;
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
cairo_paint (cr);
#if GENERATE_REFERENCE
for (x = 0; x < WIDTH; x++) {
cairo_set_source_rgba (cr, 1, 1, 1, x * 0.5 / WIDTH);
cairo_rectangle (cr, x, 0, 1, HEIGHT);
cairo_fill (cr);
}
#else
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++) {
double step = x / (double) (2 * WIDTH);
for (y = 0; y < HEIGHT; y++) {
for (i = 0; i < PRECISION; i++) {
double dx = random_offset (WIDTH - x, FALSE);
cairo_move_to (cr, x + dx, y + i / (double) PRECISION);
cairo_rel_line_to (cr, step, 0);
cairo_rel_line_to (cr, step, 1 / (double) PRECISION);
cairo_rel_line_to (cr, -step, 0);
cairo_close_path (cr);
}
cairo_fill (cr);
}
}
}
#endif
return CAIRO_TEST_SUCCESS;
}
CAIRO_TEST (coverage_rectangles,
"Check the fidelity of the rasterisation.",
NULL,
"target=raster slow",
WIDTH, HEIGHT,
NULL, rectangles)
CAIRO_TEST (coverage_intersecting_quads,
"Check the fidelity of the rasterisation.",
NULL,
"target=raster slow",
WIDTH, HEIGHT,
NULL, intersecting_quads)
CAIRO_TEST (coverage_intersecting_triangles,
"Check the fidelity of the rasterisation.",
NULL,
"target=raster slow",
WIDTH, HEIGHT,
NULL, intersecting_triangles)
CAIRO_TEST (coverage_row_triangles,
"Check the fidelity of the rasterisation.",
NULL,
"target=raster slow",
WIDTH, HEIGHT,
NULL, row_triangles)
CAIRO_TEST (coverage_column_triangles,
"Check the fidelity of the rasterisation.",
NULL,
"target=raster slow",
WIDTH, HEIGHT,
NULL, column_triangles)
CAIRO_TEST (coverage_triangles,
"Check the fidelity of the rasterisation.",
NULL,
"target=raster slow",
WIDTH, HEIGHT,
NULL, triangles)