#include "cairo-test.h"
#define WIDTH 60
#define HEIGHT 40
static const struct color {
double red, green, blue;
} color[] = {
{ 1, 1, 1 },
{ 0, 0, 0 },
{ 1, 0, 0 },
{ 0, 1, 0 },
{ 0, 0, 1 },
{ 1, 1, 0 },
{ 0, 1, 1 },
{ 1, 0, 1 },
{ .5, .5, .5 },
};
#define NUM_COLORS (sizeof (color) / sizeof (color[0]))
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
static void
object (cairo_t *cr, const struct color *fg, const struct color *bg)
{
cairo_set_source_rgb (cr, bg->red, bg->green, bg->blue);
cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
cairo_fill (cr);
cairo_set_source_rgb (cr, fg->red, fg->green, fg->blue);
cairo_save (cr);
cairo_scale (cr, WIDTH, HEIGHT);
cairo_arc (cr, .5, .5, .5 - 4. / MAX (WIDTH, HEIGHT), 0, 2 * M_PI);
cairo_fill (cr);
cairo_arc (cr, .5, .5, .5 - 2. / MAX (WIDTH, HEIGHT), 0, 2 * M_PI);
cairo_restore (cr);
cairo_set_line_width (cr, 1.);
cairo_stroke (cr);
cairo_set_source_rgb (cr, bg->red, bg->green, bg->blue);
cairo_set_line_width (cr, 4.);
cairo_move_to (cr, 4, HEIGHT-4);
cairo_line_to (cr, WIDTH-12, 4);
cairo_move_to (cr, 12, HEIGHT-4);
cairo_line_to (cr, WIDTH-4, 4);
cairo_stroke (cr);
}
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
unsigned int i, j;
for (i = 0; i < NUM_COLORS; i++) {
for (j = 0; j < NUM_COLORS; j++) {
cairo_save (cr);
cairo_translate (cr, i * WIDTH, j * HEIGHT);
object (cr, &color[i], &color[j]);
cairo_restore (cr);
}
}
return CAIRO_TEST_SUCCESS;
}
CAIRO_TEST (aliasing,
"Check for subpixel aliasing and color fringing",
"rasterisation",
"target=raster",
NUM_COLORS * WIDTH, NUM_COLORS * HEIGHT,
NULL, draw)