Non-clipping clips(wasRe: [cairo] Alpha masks)

Owen Taylor otaylor at redhat.com
Thu Jan 6 16:07:37 PST 2005


On Thu, 2005-01-06 at 13:38 -0800, Keith Packard wrote:

> Before we get much further in this discussion, I think we really need to
> address the clip operand and it's interaction with compositing operators
> for which the alpha value in the source doesn't limit the affected pixel 
> set in the destination.

Looked at this some. Restricting the discussion to the core
Porter-Duff operators, there are 8 that clip properly:

 Dst, Over, OverReverse, OutReverse, Atop, Xor, Add, Saturate

And 6 that don't:

 Clear, Src, In, InReverse, Out, AtopReverse

For the non-core, there are 12 that clip properly, and 12 that don't.

> Carl and I discussed this a bit last year and came up with a very simple 
> proposal, which is well defined, but may not be as useful as we'd like.  
> 
> That is to simply treat the 'clip' as another part of the 'mask' and 
> accept the fact that areas beyond the clip will be modified in the 
> destination.  All of the operations remain well defined, although their 
> utility may be strongly compromised in some cases.  Do an 'IN' operation 
> with an empty clip and the entire destination surface will be erased.

I think it's very unexpected that if you set a clip that drawing isn't
clipped to that clip. Imagine I'm doing a partial redraw: I set the
clip, fill the background with Src, then draw some objects with 
Over. The background fill isn't clipped, the objects are. 

What's the right way to do it? First clear the background using
OutReverse and a solid source color, then use Add to copy in the source
image. That's not exactly intuitive.

The intuitively expected definition of how the clip operates follows 
from that:

 ((src Op dest) In clip) Add (dest Out clip)

[ src here would be 'src In mask' for Cairo ]

That definition turns out to be the same as the current one for 7/8
of the well-behaved core operators ... 

  Dst, Over, OverReverse, OutReverse, Atop, Xor, Add

It's slightly different for Saturate and the well behaved
Conjoint/Disjoint operators. It's of course, different for the
badly behaved operators, but seems to match expectations.
E.g., Clear clears to the clip, Src copies the source image
to the clipped area, 

Question: are there alternate 2-operand operators missing from the
current set that would allow getting the desired effects? I don't
think so ... to get "copy the source clipped" we need both the 
original alpha channel and the clip mask alpha channel, so 
(src IN (mask IN clip)) can't allow it. 

Question: What if you replaced the RENDER equation of 
'(src In mask) op Dest' with 
'((src Op dest) In mask) Add (dest Out mask)' ... that is,
view the above as an alternate 3-operand equation and remerge
mask and clip? Advantage - using Src or Clear with a path
works as expected. Disadvantage - using InReverse with a 
path does nothing, and it's hard to get that effect.

> Is the ease of specification and consistency in the API worth the 
> degredation of expected functionality?  Does anyone have an alternative 
> specification which works for the full range of alpha values?

I'm pretty happy with the above ... Cairo should be able to implement
it on top of the current RENDER pretty efficiently (Even Saturate isn't
that bad...  it can be done as

((src DisjointOut dest) in Clip) Add Dest

Which just requires one intermediate surface; like the current
definition)

Opinions?
					Owen

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050106/5b5b6674/attachment.pgp


More information about the cairo mailing list