Carl wrote: > On Tue, 15 May 2007 10:33:24 +0100, Bill Spitzak wrote: > > This is not as complicated as everybody is making out. > > ALL(*) cairo operators are equivalent to: > > > > (src OP dest) * mask + dest * (1-mask). > > That's not correct, (not for IN, OUT, DEST_IN, nor DEST_ATOP in > addition to SATURATE). > > I'm looking forward to getting the math nicely documented soon > so we can stop revisiting it in threads like this. > > Here's Owen's original description that led to the current > implementation: > > http://article.gmane.org/gmane.comp.lib.cairo/4791 > > And here's the crux of what he wrote: > > So, the proposal here is to logically divide the operators > into 4 groups by what definition we use: > > OVER, ATOP, DEST, DEST_OVER, DEST_OUT, XOR, ADD > > All definitions equivalent > > SOURCE, CLEAR > > (mask IN clip) ? src OP dest : dest > > IN, OUT, DEST_IN, DEST_ATOP > > clip ? (src IN mask) OP dest : dest > > SATURATE > > (src IN mask IN clip) OP dest > > And yes, it is quite ugly that we basically have 3 different > fundamental equations. And it can be quite confusing that for > the most common (and default) operator of OVER, the 3 equations > yield identical results. > > -Carl This is a somewhat interesting topic. In my limited experience of having played with these a bit, I've found that it seems to matter what the 'context' is in which the 'operations' are considred as being applied -- ie. wether one is considering an op as 'drawing' a (possibly patterned) geometric figure, or as 'compositing' some color data (to a 'dst'). Intuitively, it seems to me that if one were being asked to 'draw' a patterned, closed geometric figure with some 'op' (component-alpha-wise or not), to some 'dst', then the exterior of the figure should not affect the dst -- regardless of the 'op'. Thus, if the figure were converted to a mask so that areas in the exterior are assigned a mask value of 0, then one would be lead to something of the form: result = (dst * (1 - mask)) + (op(pattern, dst) * mask) If one further wants to be able to "clip" the patterned figure by some clip_mask (wether alpha only or not), then one would be lead to use the above replacing mask by mask*clip_mask. One might also be lead to restricting the set of such ops to ones which would have a good intuitive result when applied in this context (eg. it's possible that some 'reverse' kinds of things might not be all that intuitive in this context). However, if one is considering "ops" for 'compositing' (or painting) some color data (possibly arising as the result of 'drawing' figures), then one would seem to be led to an algebra of such which does indeed allow for affecting the dst when 'mask' values are 0. Confusion would easily arise from the use of the same name "op" when applied to the context of 'drawing' geometric figures, vs. the context of 'compositing' color data. jose.