[cairo] Alpha masks
Owen Taylor
otaylor at redhat.com
Thu Jan 6 08:58:51 PST 2005
On Thu, 2005-01-06 at 11:16 -0500, Carl Worth wrote:
> 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.
Well, with the "mask is shape model", then the natural way to represent
that for arbitrary masks is using the surface as a pattern and drawing
the mask.
> 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?
I think this questions are very closely tied to the question:
"If I have a pattern with/without an alpha channel, and fill a path,
what is the effect of the cairo_set_alpha() value"
A simple way of handling the alpha value is simply say that it provides
the alpha for source solid colors and for patterns without an alpha
value, but is ignored for patterns with an alpha value.
That means that taking an alpha-image and drawing it partially
translucent wouldn't be possible with show_surface() ... you'd have to
create a temporary A8 surface, draw a rectangle on there, then use that
as a mask for a pattern. A bit blecherous.
Another possibility is that the alpha value *multiplies* the alpha value
for patterns
with an alpha value. That complicates implementation, but probably less
so than the
generalizing the alpha to a mask operand.
So the drawing equation becomes something like:
((PATTERN IN ALPHA) IN (SHAPE IN CLIP)) OP DEST
PATTERN IN ALPHA being optimizable in the case where PATTERN is a solid,
or ALPHA is 1.0.
[Of course, we still need to deal with the issue that of clips that
don't clip for
certain operators]
[...]
> 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.
The idea that show_surface() is just a convenience function for setting
the surface as a pattern and and drawing a rectangle with the bounds of
the surface is appealing to me.
Which is another strong argument for a separate show_surface_mask()
operator, rather than just wedging it into the unused corners of
show_surface().
I don't think show_surface_mask() is decomposable into other operators,
unless we
add a separate mask operand. (And I wouldn't recommend doing that.)
Regards,
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/e30f44fa/attachment.pgp
More information about the cairo
mailing list