[cairo] Help: Question on Cairo::OPERATOR_XOR of set_operator?

Carl Worth cworth at cworth.org
Mon Oct 13 10:25:19 PDT 2008


On Wed, 2008-10-08 at 08:16 -0700, Travis Griggs wrote:
> Will, the operator applies to the alpha channel, not the rgb channels.  
> I was surprised by this too. IIRC, the operator modes were basically  
> lifted from one of the other specs (PDF maybe?).

The original set of cairo operators, (including CAIRO_OPERATOR_XOR),
match the set of operators from the X Render extension, which in turn
came from the set of compositing operators defined by Porter and Duff in
their 1984 paper "Compositing Digital Images":

	http://keithp.com/~keithp/porterduff/

This name with XOR in it has caused confusion for some that are looking
to draw graphics twice with a bitwise XOR in order to do some temporary
drawing, (such as a rubber-band effect).
 
>  And someone once  
> explained to me why an RGB xor mode would be difficult. IIRC, it was  
> basically that not all backends have a byte based color spec on the  
> backend. E.g. if the model's uses color descriptions 0.0 - 1.0 (rather  
> than 0 - 255), what does an xor mean?

Yes, as you mention, with cairo's multi-device output and being able to
target things like PDF and SVG, there's just no way to do operations
that perform bitwise operations on a per-pixel basis. With PDF and SVG
output there aren't any pixels in the first place.

And this is ignoring the fact that bitwise XOR is a lousy way to draw
things anyway. It results in unpredictable colors and without any
guarantee that the element you are drawing will even be visible. It's
definitely not something I'm interested in seeing added to cairo.

>  That all said... I still wish  
> there was an XOR RGB way to draw to screens and the like.

What is it that you want here? Are you attempting to emulate some other
API which requires bitwise XOR? Or are you just trying to draw and erase
something transient in a way that you know will be fast?

Doing the "erase" step by simply saving what you had before overwriting
it and then blitting it back should be plenty fast. And then you can
draw what you actually want without the unpredictable colors you would
get from bitwise XOR.

-Carl

-------------- 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.cairographics.org/archives/cairo/attachments/20081013/a69ef78b/attachment.pgp 


More information about the cairo mailing list