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

Daniel Amelang daniel.amelang at gmail.com
Wed May 16 08:07:11 EEST 2007


On 5/15/07, Bill Spitzak <spitzak at thefoundry.co.uk> wrote:
> 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 as you say, ALL (except saturate) cairo operators are equivalent to
that expression, then the following example doesn't make sense (to
me).

Say we want a src IN mask IN dst. Using your conjecture above, we can
rewrite it this way:

result = (src * dst.a) * mask.a + dst * (1 - mask.a)

Which is very different than what I have current for the "src IN mask
IN dst" shader ATM:

result = src * mask.a * dst.a

OUT looks just as strange, too. So I guess you're saying that in the
presence of a mask, all cairo operators end up being part of a
blending operation. Dest will always "show through" in the result,
unless the mask is absent or entirely opaque.

In that case, maybe certain operators just don't make sense in
combination with a mask, specifically the ones that are meant to
entirely "reshape" the dest, such as IN, OUT and friends?

Dan


More information about the cairo mailing list