[cairo] Alpha masks

Bill Spitzak spitzak at d2.com
Tue Sep 7 10:43:59 PDT 2004


On Sunday 05 September 2004 11:53 am, Owen Taylor wrote:
> I was trying to figure out how with Cairo to do the following
> simple operation:
>  
>  Given a single channel (A8) surface, draw a solid color
>  with the surface as the mask.

I would also like to know how to do this. I have to say I have spent a great 
deal of time trying to get Windows to do this and had to give up in 
frustration. The only way appears to be to create a new rgba image each time 
the color changes. The real frustration is that this operation is exactly 
what is used to draw antialiased fonts. It is a total mystery why this is not 
trivial to access!

This is very useful for imbedding other images into text output, for drawing 
"disabled" icons, and for drawing monochrome icons that will look nice even 
if the user's preferences are to reverse the label and background colors to 
an inverse-video mode.

For filling with gradients and so on, the same methods used to fill text with 
gradents can be used: draw into a temporary buffer and then use that as a 
mask. This is much more rare than filling with a solid color so it is ok if 
this is complicated.

Using the image as a mask directly may be the solution planned for Cairo, but 
requires you to know it's dimensions so that you can fill a rectangle big 
enough to cover it. This is somewhat annoying. It is also annoying if you are 
creating a mask since you now have to think about nested masks. It really 
should not be much harder than drawing a font glyph.



More information about the cairo mailing list