1
/*
2
 * Copyright 2008 Kai-Uwe Behrmann
3
 *
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.
14
 *
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.
22
 *
23
 * Author: Kai-Uwe Behrmann <ku.b@gmx.de>
24
 *         Chris Wilson <chris@chris-wilson.co.uk>
25
 */
26

            
27
#include "cairo-test.h"
28

            
29
static const char png_filename[] = "romedalen.png";
30

            
31
static cairo_surface_t *
32
3
create_mask (cairo_t *dst, int width, int height)
33
{
34
    cairo_surface_t *mask;
35
    cairo_t *cr;
36

            
37
3
    mask = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
38
3
    cr = cairo_create (mask);
39
3
    cairo_surface_destroy (mask);
40

            
41
3
    cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
42
3
    cairo_rectangle (cr, width/4, height/4, width/2, height/2);
43
3
    cairo_fill (cr);
44

            
45
3
    mask = cairo_surface_reference (cairo_get_target (cr));
46
3
    cairo_destroy (cr);
47

            
48
3
    return mask;
49
}
50

            
51
static cairo_test_status_t
52
3
draw (cairo_t *cr, int width, int height)
53
{
54
3
    const cairo_test_context_t *ctx = cairo_test_get_context (cr);
55
    cairo_surface_t *image, *mask;
56

            
57
3
    image = cairo_test_create_surface_from_png (ctx, png_filename);
58
3
    mask = create_mask (cr, 40, 40);
59

            
60
    /* opaque background */
61
3
    cairo_paint (cr);
62

            
63
    /* center */
64
6
    cairo_translate (cr,
65
3
	             (width - cairo_image_surface_get_width (image)) / 2.,
66
3
		     (height - cairo_image_surface_get_height (image)) / 2.);
67

            
68
    /* rotate 30 degree around the center */
69
3
    cairo_translate (cr, width/2., height/2.);
70
3
    cairo_rotate (cr, -30 * 2 * M_PI / 360);
71
3
    cairo_translate (cr, -width/2., -height/2.);
72

            
73
    /* place the image on our surface */
74
3
    cairo_set_source_surface (cr, image, 0, 0);
75

            
76
    /* reset the drawing matrix */
77
3
    cairo_identity_matrix (cr);
78

            
79
    /* fill nicely */
80
3
    cairo_scale (cr, width / 40., height / 40.);
81

            
82
    /* apply the mask */
83
3
    cairo_mask_surface (cr, mask, 0, 0);
84

            
85
3
    cairo_surface_destroy (mask);
86
3
    cairo_surface_destroy (image);
87

            
88
3
    return CAIRO_TEST_SUCCESS;
89
}
90

            
91
1
CAIRO_TEST (mask_transformed_image,
92
	    "Test that cairo_mask() is affected properly by the CTM and not the image",
93
	    "mask", /* keywords */
94
	    NULL, /* requirements */
95
	    80, 80,
96
	    NULL, draw)