1
/*
2
 * Copyright © 2005 Red Hat, Inc.
3
 * Copyright © 2006 Red Hat, Inc.
4
 *
5
 * Permission to use, copy, modify, distribute, and sell this software
6
 * and its documentation for any purpose is hereby granted without
7
 * fee, provided that the above copyright notice appear in all copies
8
 * and that both that copyright notice and this permission notice
9
 * appear in supporting documentation, and that the name of
10
 * Red Hat, Inc. not be used in advertising or publicity pertaining to
11
 * distribution of the software without specific, written prior
12
 * permission. Red Hat, Inc. makes no representations about the
13
 * suitability of this software for any purpose.  It is provided "as
14
 * is" without express or implied warranty.
15
 *
16
 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18
 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
19
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
22
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23
 *
24
 * Author: Carl D. Worth <cworth@cworth.org>
25
 */
26

            
27
#include "cairo-test.h"
28

            
29
static uint32_t data[16] = {
30
    0xffffffff, 0xffffffff,		0xffff0000, 0xffff0000,
31
    0xffffffff, 0xffffffff,		0xffff0000, 0xffff0000,
32

            
33
    0xff00ff00, 0xff00ff00,		0xff0000ff, 0xff0000ff,
34
    0xff00ff00, 0xff00ff00,		0xff0000ff, 0xff0000ff
35
};
36
static cairo_test_status_t
37
3
draw (cairo_t *cr, int width, int height)
38
{
39
    cairo_surface_t *surface;
40

            
41
3
    surface = cairo_image_surface_create_for_data ((unsigned char *) data,
42
						   CAIRO_FORMAT_RGB24, 4, 4, 16);
43

            
44
3
    cairo_test_paint_checkered (cr);
45

            
46
3
    cairo_scale (cr, 4, 4);
47

            
48
3
    cairo_set_source_surface (cr, surface, 2 , 2);
49
3
    cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
50
3
    cairo_paint_with_alpha (cr, 0.5);
51

            
52
3
    cairo_surface_finish (surface); /* data will go out of scope */
53
3
    cairo_surface_destroy (surface);
54

            
55
3
    return CAIRO_TEST_SUCCESS;
56
}
57

            
58
static cairo_test_status_t
59
3
draw_solid_clip (cairo_t *cr, int width, int height)
60
{
61
3
    cairo_test_paint_checkered (cr);
62

            
63
3
    cairo_rectangle (cr, 2.5, 2.5, 27, 27);
64
3
    cairo_clip (cr);
65

            
66
3
    cairo_set_source_rgb (cr, 1., 0.,0.);
67
3
    cairo_paint_with_alpha (cr, 0.5);
68

            
69
3
    return CAIRO_TEST_SUCCESS;
70
}
71

            
72
static cairo_test_status_t
73
3
draw_clip (cairo_t *cr, int width, int height)
74
{
75
    cairo_surface_t *surface;
76

            
77
3
    surface = cairo_image_surface_create_for_data ((unsigned char *) data,
78
						   CAIRO_FORMAT_RGB24, 4, 4, 16);
79

            
80
3
    cairo_test_paint_checkered (cr);
81

            
82
3
    cairo_rectangle (cr, 10.5, 10.5, 11, 11);
83
3
    cairo_clip (cr);
84

            
85
3
    cairo_scale (cr, 4, 4);
86

            
87
3
    cairo_set_source_surface (cr, surface, 2 , 2);
88
3
    cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
89
3
    cairo_paint_with_alpha (cr, 0.5);
90

            
91
3
    cairo_surface_finish (surface); /* data will go out of scope */
92
3
    cairo_surface_destroy (surface);
93

            
94
3
    return CAIRO_TEST_SUCCESS;
95
}
96

            
97
static cairo_test_status_t
98
3
draw_clip_mask (cairo_t *cr, int width, int height)
99
{
100
    cairo_surface_t *surface;
101

            
102
3
    surface = cairo_image_surface_create_for_data ((unsigned char *) data,
103
						   CAIRO_FORMAT_RGB24, 4, 4, 16);
104

            
105
3
    cairo_test_paint_checkered (cr);
106

            
107
3
    cairo_move_to (cr, 16, 5);
108
3
    cairo_line_to (cr, 5, 16);
109
3
    cairo_line_to (cr, 16, 27);
110
3
    cairo_line_to (cr, 27, 16);
111
3
    cairo_clip (cr);
112

            
113
3
    cairo_scale (cr, 4, 4);
114

            
115
3
    cairo_set_source_surface (cr, surface, 2 , 2);
116
3
    cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
117
3
    cairo_paint_with_alpha (cr, 0.5);
118

            
119
3
    cairo_surface_finish (surface); /* data will go out of scope */
120
3
    cairo_surface_destroy (surface);
121

            
122
3
    return CAIRO_TEST_SUCCESS;
123
}
124

            
125
1
CAIRO_TEST (paint_with_alpha,
126
	    "Simple test of cairo_paint_with_alpha",
127
	    "paint, alpha", /* keywords */
128
	    NULL, /* requirements */
129
	    32, 32,
130
	    NULL, draw)
131
1
CAIRO_TEST (paint_with_alpha_solid_clip,
132
	    "Simple test of cairo_paint_with_alpha+unaligned clip",
133
	    "paint, alpha, clip", /* keywords */
134
	    NULL, /* requirements */
135
	    32, 32,
136
	    NULL, draw_solid_clip)
137
1
CAIRO_TEST (paint_with_alpha_clip,
138
	    "Simple test of cairo_paint_with_alpha+unaligned clip",
139
	    "paint, alpha, clip", /* keywords */
140
	    NULL, /* requirements */
141
	    32, 32,
142
	    NULL, draw_clip)
143
1
CAIRO_TEST (paint_with_alpha_clip_mask,
144
	    "Simple test of cairo_paint_with_alpha+unaligned clip",
145
	    "paint, alpha, clip", /* keywords */
146
	    NULL, /* requirements */
147
	    32, 32,
148
	    NULL, draw_clip_mask)