Hi,
Some days ago, Jasper van de Gronde asked me if I still got problem with negative values in feComposite. He pointed that I forgot about the alpha value (becoming zero) https://bugs.launchpad.net/inkscape/+bug/1044989
So I reworked my filters using his clever trick so that alpha won't reach 0 (except I used feColorMatrix instead of feComponentTransfer)
And once again I'm stuck. I try to redo the exclusion filter in photoshop using feComposite For two layers A (=sourceImage) and B (=backgroundImage) with opacities = 1, formula is supposed to be A+B - 2AB.
As feComposite (stupidly IMO) computes not only rgb channels but the alpha too I need to get rid of the alpha channel (either in earlier or later stages) until now I failed.
What I'd expected rgb(1,0,0.5, x) exclusion rgb(0,1,0.5, y) should be rgb(1,1,0.5, 1) r:1 + 0 - 2 (1*0) = 1 g:0 + 1 - 2 (0*1) = 1 b:0.5+0.5 - 2 (0.5*0.5) = 0.5
problem is the alpha coz 1 + 1 - 2(1*1) = 0
I tried the 2 following solutions
solution 1: dealing later with alpha => set alpha to 1 when everything is done. feComposite k=(-2;1;1;_) followed by colorMatrix 1 0 0 0 0 0 1 0 0 0 <= identity for rgb 0 0 1 0 0 0 0 0 0 1 <= reset alpha to 1.0 whatever it could've been before
this doesn't work, the result is full black
solution 2: dealing earlier with alpha => set alpha so that it is 1 and not 0 after composition (=set it to 0 before the feComposite) pass sourceimage through the following colormatrix to remove the alpha 1 0 0 0 0 0 1 0 0 0 <= identity for rgb 0 0 1 0 0 0 0 0 0 0 <= reset alpha to 0 run this + backgrounImage in feComposite k=(-2;1;1;_)
with this I'd expected the alpha to be ok because 0 + 1 - 2 (1*0) = 1.
but this doesn't work either (fully transparent ?)
Could anybody help ? How do you deal with alpha when using feComposite ? Does Inkscape (or svg) drop result of a filter stage if alpha is zero ? (in solution 1)
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.
participants (2)
-
Jasper van de Gronde
-
pennec victor