[cairo] Alpha masks

Carl Worth cworth at redhat.com
Thu Jan 6 08:16:01 PST 2005


On Wed, 05 Jan 2005 17:49:18 -0500, Owen Taylor wrote:
> Hmm, that makes the drawing "equation" even more complex than it is now.
> The drawn pixel is a function of 
>  
>  shape (polygon)
>  clip
>  pattern (or solid color)
>  mask
> 
> Seems to me to be simpler to use the mask in place of either shape or
> clip and keep the operands to three. Of the two, shape looks more
> logical to me.

Well, in addition to "paint solid color through mask surface", another
operation that I want to make easy is "paint surface through simple
mask". Starting with an RGB image it should be easy to composite it
translucently against the background.

We actually do have an easy way to do this now, with:

	cairo_set_alpha
	cairo_show_surface

but I don't think we have a consistent model here yet. If the surface
has its own alpha channel, is the "current alpha" also applied? What
if we're using a pattern; does the current alpha affect things there
as well?

My idea was that adding a mask to the graphics state would make it
easier to sort things out as well as to explain and understand them. I
don't think it complements the implementation, as we already have an
unused mask parameter ready in the backend, (at least for the
no-clipping case---clipping is a slightly awkward fit with the
backends as currently implemented).
> 
> > > My expectation would be that showing a RGB or RGBA surface would ignore the pattern,
> > > showing a A-only surface would use the surface as a mask for the pattern. Does this
> > > make sense to other people?
> > 
> > That strikes me as inconsistent. 
[...] 
> I don't really quite understand the claim of inconsistency

It just depends on whether the model includes color information in the
notion of a mask.

> Using a separate operator does allow ARGB masks, likely making some
> people happy.

The whole issue here is what operations we make easy. One requirement
is that convenience functions such as show_surface need to have
straightforward definitions in terms of more fundamental operators.

> What's the interpretation of show_surface() with an A-only image? Does
> it draw in black always? Does it act like show_surface_mask()?
> 
> What's the interpretation of show_surface_mask() with a RGB-surface?
> Just the rectangular surface bounds?

I think we can make these two operations act sensibly. So show_surface
with A-only could get color from the pattern, (making it act like
show_surface_mask). And show_surface_mask could assume a constant
alpha value from the current alpha within the rectangular bounds.

But clearly, the motivation for separate functions is most easily
understood for resolving the ambiguity of ARGB surfaces.

And we can add show_surface_mask without adding any explicit mask in
the graphics state, so we don't actually need to complicate the
rendering equation.

-Carl



More information about the cairo mailing list