[cairo] [RFC] Cairo operators expressed in shader syntax

Bill Spitzak spitzak at thefoundry.co.uk
Tue May 15 12:33:24 EEST 2007

Daniel Amelang wrote:

> That's a lot closer to OVER than SOURCE, observe them side by side:
> ; OVER
> result = src * mask.a + dst * (1.0 - src.a * mask.a)
> ; cairo SOURCE
> result = src * mask.a + dst * (1.0 - mask.a)
> Hmmm...I wonder if the shader syntax isn't fully capturing all the
> differences. Looking at the cairo SOURCE, it seems awfully strange to
> combine a premultipied source image with a dest image w/out applying
> the other side of the multiplication. Perhaps this only useful when
> the source only has an alpha component?

No, the above SOURCE is how you have to write it so that the mask 
actually means "things inside the mask get changed and things outside 
don't". Earlier versions of Cairo did just "src*mask" and made it black 
outside the mask, and everybody agreed that it was not at all what 
anybody wanted or expected.

This is not as complicated as everybody is making out. ALL(*) cairo 
operators are equivalent to:

(src OP dest) * mask + dest * (1-mask).

If you substitute the OP function you can use algebra and reduce or 
manipulate the expression to look quite different, which gives rise to 
your confusion. I think it is best to describe OP only, and then point 
out that this mask is also done to all the results.

(*) Actually the "saturate" is not equivalent to this function. It 
*looks* the same but the exact result when mask is a fraction is subtly 
different in order to preserve the purpose of "saturate". It is best to 
describe this as an exception, and point out how very close it is to the 
same expression.

More information about the cairo mailing list