[cairo] Trying a new operator type

Carlos López González genetita at gmail.com
Tue Oct 2 12:03:59 PDT 2012

finally I figured out how to preform the new Cairo operator. I would
be glad if someone finds other way to perform the same operator with a
simplest and effective code:


In the pasted code it is explained what does the new operation do.

2012/10/1 Carlos López González <genetita at gmail.com>:
> Hi,
> 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
> the tutorials):
> A= source
> B= destination
> R= result
> 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:
> http://pastebin.com/x7hxmbBf
> Notice that the section commented with "Draw the surface over itself
> with 1.0-alpha"
> 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
> char).
> 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
> sense (0.80).
> 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.
> Cheers!
> --
> Carlos
> http://synfig.org


More information about the cairo mailing list