1
/*
2
 * Copyright 2010 Intel Corporation
3
 *
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use, copy,
8
 * modify, merge, publish, distribute, sublicense, and/or sell copies
9
 * of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be
13
 * included in all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 *
24
 * Author: Chris Wilson <chris@chris-wilson.co.uk>
25
 */
26

            
27
#include "cairo-test.h"
28

            
29
/* A fun little test to explore color fringing in various experimental
30
 * subpixel rasterisation techniques.
31
 */
32

            
33
#define WIDTH 60
34
#define HEIGHT 40
35

            
36
static const  struct color {
37
    double red, green, blue;
38
} color[] = {
39
    { 1, 1, 1 },
40
    { 0, 0, 0 },
41
    { 1, 0, 0 },
42
    { 0, 1, 0 },
43
    { 0, 0, 1 },
44
    { 1, 1, 0 },
45
    { 0, 1, 1 },
46
    { 1, 0, 1 },
47
    { .5, .5, .5 },
48
};
49

            
50
#define NUM_COLORS ARRAY_LENGTH (color)
51

            
52
static void
53
243
object (cairo_t *cr, const struct color *fg, const struct color *bg)
54
{
55
243
    cairo_set_source_rgb (cr, bg->red, bg->green, bg->blue);
56
243
    cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
57
243
    cairo_fill (cr);
58

            
59
243
    cairo_set_source_rgb (cr, fg->red, fg->green, fg->blue);
60
243
    cairo_save (cr);
61
243
    cairo_scale (cr, WIDTH, HEIGHT);
62
243
    cairo_arc (cr, .5, .5, .5 - 4. / MAX (WIDTH, HEIGHT), 0, 2 * M_PI);
63
243
    cairo_fill (cr);
64
243
    cairo_arc (cr, .5, .5, .5 - 2. / MAX (WIDTH, HEIGHT), 0, 2 * M_PI);
65
243
    cairo_restore (cr);
66
243
    cairo_set_line_width (cr, 1.);
67
243
    cairo_stroke (cr);
68

            
69
243
    cairo_set_source_rgb (cr, bg->red, bg->green, bg->blue);
70
243
    cairo_set_line_width (cr, 4.);
71
243
    cairo_move_to (cr, 4, HEIGHT-4);
72
243
    cairo_line_to (cr, WIDTH-12, 4);
73
243
    cairo_move_to (cr, 12, HEIGHT-4);
74
243
    cairo_line_to (cr, WIDTH-4, 4);
75
243
    cairo_stroke (cr);
76
243
}
77

            
78
static cairo_test_status_t
79
3
draw (cairo_t *cr, int width, int height)
80
{
81
    unsigned int i, j;
82

            
83
30
    for (i = 0; i < NUM_COLORS; i++) {
84
270
	for (j = 0; j < NUM_COLORS; j++) {
85
243
	    cairo_save (cr);
86
243
	    cairo_translate (cr, i * WIDTH, j * HEIGHT);
87
243
	    object (cr, &color[i], &color[j]);
88
243
	    cairo_restore (cr);
89
	}
90
    }
91

            
92
3
    return CAIRO_TEST_SUCCESS;
93
}
94

            
95
1
CAIRO_TEST (aliasing,
96
	    "Check for subpixel aliasing and color fringing",
97
	    "rasterisation", /* keywords */
98
	    "target=raster", /* requirements */
99
	    NUM_COLORS * WIDTH, NUM_COLORS * HEIGHT,
100
	    NULL, draw)