[cairo] OPERATOR_SRC and no input

Carl Worth cworth at redhat.com
Tue Jan 11 11:12:51 PST 2005


On Sun, 09 Jan 2005 17:38:39 -0500, Owen Taylor wrote:
> On Sun, 2005-01-09 at 13:33 +0100, Stefan Krause wrote:
> > // now paint my path
> >   cairo_set_operator (cr, CAIRO_OPERATOR_SRC);
> >   cairo_set_alpha (cr, 1.0);
> >   cairo_set_rgb_color (cr, 1.0, 0.0, 1.0);
> >   cairo_move_to (cr, 100, 0);
> >   cairo_line_to (cr, 200, 100);
> >   cairo_line_to (cr, 100, 200);
> >   cairo_line_to (cr, 0, 100);
> >   cairo_close_path(cr);
> >   cairo_fill(cr);
> 
> What actually *should* have happened is for the entire surface to be
> filled with black except for the path. The appearance of the bounding
> box is a bug. Though that probably wasn't what you were looking for.

That's correct.

What Stefan actually wanted, (drawing a path with a source color
independent of the pre-existing destination color), is quite
reasonable of course. And it's easy to get just by using
CAIRO_OPERATOR_OVER with alpha==1.0.

The tricker case is to do the same thing with alpha!=1.0, (which might
be useful in constructing a mask for instance). Then, OVER won't work
anymore since it will blend with the background. SRC is the natural
thing to try, but it has the problem of erasing the destination
everywhere outside the path.

I spent some time today looking once again at whether we could merge
the path with the clip to make this case easier. But this ends up
complicating more than it helps. The IN_REVERSE and OUT_REVERSE end up
doing less-than-useful things and they are hard to fix.

Fortunately, there is an easy way to perform the desired operation
without any change to the (new) rendering equation. Here it is:

	/* create path */
	cairo_set_alpha (cr, 0.5);
	cairo_clip (cr);
	cairo_fill (cr);

And of course, there may be an extra cairo_save/restore pair needed to
remove the effects of the clip.

The above code won't have the desired effect now, since we haven't
yet implemented clip according to the new equation.

But I'm pretty convinced now that we're on the right track here.

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050111/cbd04980/attachment.pgp


More information about the cairo mailing list