2 * Copyright © 2005 Red Hat, Inc.
3 * Copyright © 2006 Red Hat, Inc.
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.
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.
24 * Author: Carl D. Worth <cworth@cworth.org>
27 #include "cairo-test.h"
29 static uint32_t data[16] = {
30 0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000,
31 0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000,
33 0xff00ff00, 0xff00ff00, 0xff0000ff, 0xff0000ff,
34 0xff00ff00, 0xff00ff00, 0xff0000ff, 0xff0000ff
36 static cairo_test_status_t
37 draw (cairo_t *cr, int width, int height)
39 cairo_surface_t *surface;
41 surface = cairo_image_surface_create_for_data ((unsigned char *) data,
42 CAIRO_FORMAT_RGB24, 4, 4, 16);
44 cairo_test_paint_checkered (cr);
46 cairo_scale (cr, 4, 4);
48 cairo_set_source_surface (cr, surface, 2 , 2);
49 cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
50 cairo_paint_with_alpha (cr, 0.5);
52 cairo_surface_finish (surface); /* data will go out of scope */
53 cairo_surface_destroy (surface);
55 return CAIRO_TEST_SUCCESS;
58 static cairo_test_status_t
59 draw_solid_clip (cairo_t *cr, int width, int height)
61 cairo_test_paint_checkered (cr);
63 cairo_rectangle (cr, 2.5, 2.5, 27, 27);
66 cairo_set_source_rgb (cr, 1., 0.,0.);
67 cairo_paint_with_alpha (cr, 0.5);
69 return CAIRO_TEST_SUCCESS;
72 static cairo_test_status_t
73 draw_clip (cairo_t *cr, int width, int height)
75 cairo_surface_t *surface;
77 surface = cairo_image_surface_create_for_data ((unsigned char *) data,
78 CAIRO_FORMAT_RGB24, 4, 4, 16);
80 cairo_test_paint_checkered (cr);
82 cairo_rectangle (cr, 10.5, 10.5, 11, 11);
85 cairo_scale (cr, 4, 4);
87 cairo_set_source_surface (cr, surface, 2 , 2);
88 cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
89 cairo_paint_with_alpha (cr, 0.5);
91 cairo_surface_finish (surface); /* data will go out of scope */
92 cairo_surface_destroy (surface);
94 return CAIRO_TEST_SUCCESS;
97 static cairo_test_status_t
98 draw_clip_mask (cairo_t *cr, int width, int height)
100 cairo_surface_t *surface;
102 surface = cairo_image_surface_create_for_data ((unsigned char *) data,
103 CAIRO_FORMAT_RGB24, 4, 4, 16);
105 cairo_test_paint_checkered (cr);
107 cairo_move_to (cr, 16, 5);
108 cairo_line_to (cr, 5, 16);
109 cairo_line_to (cr, 16, 27);
110 cairo_line_to (cr, 27, 16);
113 cairo_scale (cr, 4, 4);
115 cairo_set_source_surface (cr, surface, 2 , 2);
116 cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
117 cairo_paint_with_alpha (cr, 0.5);
119 cairo_surface_finish (surface); /* data will go out of scope */
120 cairo_surface_destroy (surface);
122 return CAIRO_TEST_SUCCESS;
125 CAIRO_TEST (paint_with_alpha,
126 "Simple test of cairo_paint_with_alpha",
127 "paint, alpha", /* keywords */
128 NULL, /* requirements */
131 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 */
136 NULL, draw_solid_clip)
137 CAIRO_TEST (paint_with_alpha_clip,
138 "Simple test of cairo_paint_with_alpha+unaligned clip",
139 "paint, alpha, clip", /* keywords */
140 NULL, /* requirements */
143 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 */
148 NULL, draw_clip_mask)