[cairo] Alpha masks

Bill Spitzak spitzak at d2.com
Wed Jan 5 15:21:00 PST 2005


On Wednesday 05 January 2005 02:49 pm, Owen Taylor wrote:
>  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.

I absolutely agree that this should be the "shape".

Why? Because ***This is the same interface as is used to draw letters.***

Try to think about drawing an antialiased letter in Cairo. Anything you can 
do with a letter should be doable with this. Anything you can't do with a 
letter does not need to be done by this.

This would be vastly useful for inserting symbols into text without having to 
define a font. It is also really useful for modernist-style user interfaces 
where the icons are monochrome but the user can change the ui colors.

Here is what I would like to see as an interface:

A surface/image/whatever always acts like it has 4 channels: rgba. If there 
is a way to create it from one channel, it acts exactly like all four 
channels are equal.

The surface can be used as the source of a pattern. That is exactly like it 
is now.

The surface can also be used as the "shape". This is a new call, unrelated to 
the use as a pattern, that actually draws things, like fillpath or drawtext. 
It then draws exactly the same thing as if you drew a glyph in the current 
font where the rendering of that glyph happened to produce the exact same 
pixel values as the alpha channel has. The rgb of the surface is ignored.

If you are worried about memory space it might help if internally it realized 
that a surface's rgba are all identical, or that rgb is a constant and only a 
changes. But this is strictly an implementation issue and should be invisible 
to the api.

I'm not sure if a surface can be selected as the pattern in a way that 
ignores the alpha. If it can, then doing this and reusing the alpha as the 
shape will allow you to draw non-premultiplied images.

PS: I have tried every way I can find to fool Win32 into doing this, and it 
appears hopeless. I actually have to create a new rgba image for each 
different color I want to draw a glyph in. Stupid! Let's see if Cairo can do 
better!




More information about the cairo mailing list