[cairo] Question about CAIRO_OPERATOR_SOURCE if paint operation doesn't cover whole target surface

Boris Zbarsky bzbarsky at mit.edu
Thu Nov 30 11:14:36 PST 2006


I have the following code, more or less:

    unsigned char* data = new unsigned char[height * stride];
    cairo_surface_t *target =
         cairo_image_surface_create_for_data(data, format,
                                             width, height,
                                             stride);
    cairo_t* cr = cairo_create(target);
    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE)
    cairo_set_source_surface(cr, src, 0, 0);
    cairo_mask(cr, pattern)

In this case, |src| is an RGB24 image surface and |pattern| is an A1 image 
surface.  The goal here is to end up with an image surface that has some 
transparent pixels (a GIF image, to be precise).

The question I have is whether I need to paint the target surface with rgba(0, 
0, 0, 0) first, given that |data| is not initialized, that 
cairo_image_surface_create_for_data does not initialize the buffer in any way, 
that I'm masking out part of the paint, and that the source surface may be 
smaller than the target surface in this case.  Or does using 
CAIRO_OPERATOR_SOURCE just set all pixels that are not being painted to 
transparent?  There doesn't seem to be much documentation on the different 
operators at 
<http://www.cairographics.org/manual/cairo-cairo-t.html#cairo-operator-t>, 
unfortunately.

Thanks in advance for your help,
-Boris


More information about the cairo mailing list