2009-11-17 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / cairo / test / mask-transformed-image.c
blob84901e7e8b42b5fe7aa8500f6e20c1e121194c45
1 /*
2 * Copyright 2008 Kai-Uwe Behrmann
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Kai-Uwe Behrmann not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Kai-Uwe Behrmann makes no representations about the
12 * suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * KAI_UWE BEHRMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL KAI_UWE BEHRMANN BE LIABLE FOR ANY SPECIAL,
18 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: Kai-Uwe Behrmann <ku.b@gmx.de>
24 * Chris Wilson <chris@chris-wilson.co.uk>
27 #include "cairo-test.h"
29 static cairo_test_draw_function_t draw;
30 static const char png_filename[] = "romedalen.png";
32 static const cairo_test_t test = {
33 "mask-transformed-image",
34 "Test that cairo_mask() is affected properly by the CTM and not the image",
35 80, 80,
36 draw
39 static cairo_surface_t *
40 create_mask (cairo_t *dst, int width, int height)
42 cairo_surface_t *mask;
43 cairo_t *cr;
45 mask = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
46 cr = cairo_create (mask);
47 cairo_surface_destroy (mask);
49 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
50 cairo_rectangle (cr, width/4, height/4, width/2, height/2);
51 cairo_fill (cr);
53 mask = cairo_surface_reference (cairo_get_target (cr));
54 cairo_destroy (cr);
56 return mask;
59 static cairo_test_status_t
60 draw (cairo_t *cr, int width, int height)
62 const cairo_test_context_t *ctx = cairo_test_get_context (cr);
63 cairo_surface_t *image, *mask;
65 image = cairo_test_create_surface_from_png (ctx, png_filename);
66 mask = create_mask (cr, 40, 40);
68 /* opaque background */
69 cairo_paint (cr);
71 /* center */
72 cairo_translate (cr,
73 (width - cairo_image_surface_get_width (image)) / 2.,
74 (height - cairo_image_surface_get_height (image)) / 2.);
76 /* rotate 30 degree around the center */
77 cairo_translate (cr, width/2., height/2.);
78 cairo_rotate (cr, -30 * 2 * M_PI / 360);
79 cairo_translate (cr, -width/2., -height/2.);
81 /* place the image on our surface */
82 cairo_set_source_surface (cr, image, 0, 0);
84 /* reset the drawing matrix */
85 cairo_identity_matrix (cr);
87 /* fill nicely */
88 cairo_scale (cr, width / 40., height / 40.);
90 /* apply the mask */
91 cairo_mask_surface (cr, mask, 0, 0);
93 cairo_surface_destroy (mask);
94 cairo_surface_destroy (image);
96 return CAIRO_TEST_SUCCESS;
99 int
100 main (void)
102 return cairo_test (&test);