Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

## [Inkscape-devel] feComposite : how to deal with alpha ?

 [Inkscape-devel] feComposite : how to deal with alpha ? From: pennec victor - 2012-11-05 19:19:12 Attachments: Message as HTML     exclusionfilter.svg

 Re: [Inkscape-devel] feComposite : how to deal with alpha ? From: Jasper van de Gronde - 2012-11-06 09:20:50 ```On 05-11-12 20:19, pennec victor wrote: > ... > Could anybody help ? Essentially you want to compute the following (right?): new colour: A+B-2AB new alpha: A+B-AB (The latter is from the SVG compositing spec, and I assume in your case it's a bit flexible, as long as alpha=1 stays 1.) You have a couple of options. 1. First form source*dest. Then multiply the alpha channel by 0.5, call the result C. Then compute 0.5*(A+B), then 2*0.5*(A+B)-2*C. 2. Compute (1-A) and (1-B), but with alpha intact (use either feComponentTransfer or feColorMatrix). Then compute both (1-A)*B and (1-B)*A (as you kept alpha intact, this will work). Now sum the two results. Here you might get into a little bit of trouble, depending on how implementations handle premultiplication and clipping of the alpha channel. If you do run into trouble, just multiply the alpha channels of (1-A) and (1-B) by 0.5, I think that should fix it. Option 2 is probably better in terms of numerical precision (especially if you do not have to multiply the alpha channel by 0.5). > How do you deal with alpha when using feComposite ? You find some formula that keeps it intact. (It might not be a bad idea if this got fixed in SVG 2.) In extreme cases you can also unravel the image into its R, G, B and A components using four different alpha-only images. Then you're essentially free to do what you want. ```