mask-transformed-image.c [plain text]
#include "cairo-test.h"
static const char png_filename[] = "romedalen.png";
static cairo_surface_t *
create_mask (cairo_t *dst, int width, int height)
{
cairo_surface_t *mask;
cairo_t *cr;
mask = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
cr = cairo_create (mask);
cairo_surface_destroy (mask);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_rectangle (cr, width/4, height/4, width/2, height/2);
cairo_fill (cr);
mask = cairo_surface_reference (cairo_get_target (cr));
cairo_destroy (cr);
return mask;
}
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
cairo_surface_t *image, *mask;
image = cairo_test_create_surface_from_png (ctx, png_filename);
mask = create_mask (cr, 40, 40);
cairo_paint (cr);
cairo_translate (cr,
(width - cairo_image_surface_get_width (image)) / 2.,
(height - cairo_image_surface_get_height (image)) / 2.);
cairo_translate (cr, width/2., height/2.);
cairo_rotate (cr, -30 * 2 * M_PI / 360);
cairo_translate (cr, -width/2., -height/2.);
cairo_set_source_surface (cr, image, 0, 0);
cairo_identity_matrix (cr);
cairo_scale (cr, width / 40., height / 40.);
cairo_mask_surface (cr, mask, 0, 0);
cairo_surface_destroy (mask);
cairo_surface_destroy (image);
return CAIRO_TEST_SUCCESS;
}
CAIRO_TEST (mask_transformed_image,
"Test that cairo_mask() is affected properly by the CTM and not the image",
"mask",
NULL,
80, 80,
NULL, draw)