[cairo] Trying a new operator type
Carlos López González
genetita at gmail.com
Mon Oct 1 13:06:50 PDT 2012
I'm trying to create new operators for a custom drawing application,
using the current Cairo operators and its compositing abilities.
So far I want an operator that (using the same nomenclature than in
alpha= float value to be used
aR= (aA*-aB)*alpha+aB = aA*alpha + (1.0-alpha)*aB
xR=((xaA-xaB)*alpha+xaB)/aR = (xaA*alpha+(1.0-alpha)*xaB)/aR
So when alpha =1 then aR=aA and so xR = xA
It is like a mixture between SOURCE and OVER.
To try this I've written a code like this:
Notice that the section commented with "Draw the surface over itself
is going to be part of a external function that would receive a
cairo_t* an the alpha value as arguments.
This function doesn't know anything about the state of cairo_t* and
the state of its surface.
In the most general case the cairo_t* has commands already added and
surface could come from
other portion of code that has drawn things on it. Like in the example code
The result I have when run that code is strange. The rectangle's alpha
outside the overlapping area is not 0.65 or near (due to rounding to
Instead of that the rectangle's alpha in that area is 0.773.
The circle's alpha outside the overlapping area is not correct but has
So I have two questions:
1) What's the best way to perform the desired operations
2) Why the rectangle's alpha is wrong?
Thank you in advance.
More information about the cairo