[cairo] Alpha masks
Owen Taylor
otaylor at redhat.com
Sun Sep 5 11:53:03 PDT 2004
I was trying to figure out how with Cairo to do the following
simple operation:
Given a single channel (A8) surface, draw a solid color
with the surface as the mask.
What I came up with was:
image_pattern = cairo_pattern_create_for_surface (image_surface);
tmp_surface = cairo_surface_create_similar (cairo_current_target_surface (cr),
CAIRO_FORMAT_RGB24, 1, 1);
cairo_surface_set_repeat (tmp_surface, 1);
cairo_save (cr);
cairo_set_target_surface (cr, tmp_surface);
cairo_rectangle (context, 0, 0, 1, 1);
cairo_fill (cr);
cairo_restore (cr);
cairo_set_pattern (cr, image_pattern);
cairo_show_surface (cr, tmp_surface, width, height);
cairo_restore (cr);
cairo_pattern_destroy (image_pattern);
Which more or less works (I think there are some bugs in the cairo_gstate_show_surface()
transform fun), but feels clumsy to me, and not particularly natural either. Why is the
pattern being used as the *mask*? The prototypical pattern doesn't have a alpha
channel at all.
My expectation would be that showing a RGB or RGBA surface would ignore the pattern,
showing a A-only surface would use the surface as a mask for the pattern. Does this
make sense to other people?
I suppose the utility of the current interface is that you can easily use
gradient-with-alpha to blend an image, but that operation seems rare by comparison.
(You *could* make A-only images use the image as the mask and RGB-images use the
pattern as the mask, but that would be a rather peculiar interface.)
Regards,
Owen
(Currently showing a A-only surface bad-matches in the Xlib backend, but the code
isn't going to do anything useful in any case.)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/cairo/attachments/20040905/5abc7472/attachment.pgp
More information about the cairo
mailing list