[cairo] Alpha masks

Bill Spitzak spitzak at d2.com
Thu Jan 6 18:25:26 PST 2005


On Thursday 06 January 2005 12:22 pm, Owen Taylor wrote:
>  That's why show_surface_mask() should
> replace 'path' in the above.
>
> (Replacing 'path' also makes it very natural to do path arithmetic
> on a temporary surface and then use the result as a path-like object)

Yes please make single-channel alpha be identical to path.

More importatly it should be identical to drawing text glyphs. As far as I 
know Cairo does not allow you to clip glyphs to a path, you have to set the 
clip region for that. So there is no reason to intesect the pattern with the 
path, either. If there was, then drawing text should allow this too.

As I see it now, the correct math is this:

	dst = (src*color*mask op dst) * clip + dst * (1-clip)

src = rgba pixel from pattern or source image, or 1111 if no source. Assummed
to be premultiplied. When setting the source, you can indicate that it should 
ignore the alpha and treat it as 1.

color = rgba constant color. This is seperate from src to allow "tinting", in 
particular to allow the source image to be multiplied by a constant alpha in 
order to fade it out, which is needed for Win32 GDI emulation. Don't forget 
to set your color to 1111 before drawing images!

mask = scaler per pixel, depending on the drawing command being executed.
Fill and stroke use the path, drawtext uses the values from the glyphs, and 
the new "draw surface mask" operator uses the alpha from a surface. It would 
also be useful to have an "erase" drawing operator that makes this 1 
everywhere.

clip = one alpha channel indicating the clip region. Seperated out here as 
another post recommended to allow op to modify areas where alpha == 0.

Notice that you cannot use the path to clip the "draw surface mask" operator, 
but that matches how drawtext works.

You can draw non-premultiplied images by specifying it as the source but with 
the flag that makes it pretend the alpha is 1, and then using the same 
surface as the mask.

-- 
                   ,~,~,~,~ ~ ~ ~ ~
     /\_       _|_========___         Bill Spitzak
 ~~~/\/\\~~~~~~\____________/~~~~~~~~ spitzak at d2.com




More information about the cairo mailing list