[cairo] XOR drawing and color replacements
otte at redhat.com
Sat Jun 19 11:48:26 PDT 2010
On Sat, 2010-06-19 at 15:31 +0200, Krzysztof Kosiński wrote:
> I am porting Inkscape to use Cairo drawing everywhere, and I have two questions.
Woohoo, I had hoped this would happen. I bet we et many performance
problems from that. And I love useful performance tests :)
> 1. We draw some UI elements (notably control points used for path
> nodes) using XOR drawing. The definition of this operation for each
> color channel is as follows, and alpha of the destination is
> #define COMPOSE_X(b,f,a) ( FAST_DIVIDE<255>( ((guchar) b) * ((guchar)
> (0xff - a)) + ((guchar) ((b ^ ~f) + b/4 - (b>127? 63 : 0))) *
> ((guchar) a) ) )
> I found a mail on this list that said that this kind of XOR drawing is
> not possible with cairo. If that's indeed the case, can anyone suggest
> a different method of drawing the control points in a way that makes
> them visible regardless of the color of the underlying drawing?
I'm very sure it is not possible with Cairo's current stable 1.8
If you use cairo 1.9, using CAIRO_OPERATOR_DIFFERENCE and a solid white
source should give you an xor effect for 0xFF. If you want to just xor
some bits, I don't think that's possible with any of the PDF operators.
> 2. I have an .xpm file that has only 3 color values: 100% transparent,
> white, and black. Transparent should be left alone, white should be
> replaced by one user-defined color, and black by a different
> user-defined color. Can this be done without directly accessing the
> surface data?
I'd probably construct 2 CAIRO_FORMAT_A1 alpha masks from the XPM, one
for the first color, one for the second color and then do 2 cairo_mask()
More information about the cairo