[cairo] How to blur one of the r, g or b channels into the alpha channel?

Travis Griggs tgriggs at cincom.com
Mon Nov 12 15:01:20 PST 2007


On Nov 12, 2007, at 12:37, Leon Woestenberg wrote:

> Hello,
>
> I would like to blur one of the r, g or b channels into the alpha  
> channel.
>
> for each x,y: alpha(x,y) = blur3(x,y)
> where blur3 is a 3x3 blurring filter
>
> What's the most efficient way to achieve this with cairo?
>
> My application is that I would like to "feather" a thick stroke.

I did something like this a little while back and blogged about it  
with a big ol' wink cast.

http://www.cincomsmalltalk.com/userblogs/travis/blogView? 
showComments=true&printTitle=Taking_Stock_In_Cairo&entry=3361198981

I'm not aware of general blur function myself. I would love to hear  
if there is one. The way I achieved those "glowing" or "feathered"  
lines was to do a loop like this:

for (int i = 17; i > 0; i-=2)
{
	line_width(cr, i);
	source_rgba(cr, r, g, b, 1.0 / i);
	stroke_preserve(cr);
}

pardon the psuedo code and probably misremembered function names (I'm  
going from memory and translating for the Smalltalk binding). The  
trick I found was setting alpha to the reciprocal of a the stroke width.

--
Travis Griggs
Objologist
"It’s actually much easier to get around on ice than it is on dry land 
—if you use skates." - Paul Graham




More information about the cairo mailing list