Re: Compositing math in SVG

Let's do the math!
For an example, take a pixel that is RGB(0,1,0,.5) that is on top of
RGB(1,0,0,1) with a multiply blend mode. (This is how photoshop/gimp are
treating your example)

First you alpha composite the pixel with its backdrop, so:

co = Cs x ás + Cb x áb x (1 - ás)

   = RGB(0,1,0) x .5 + RGB(1,0,0) x 1 x (1-.5)

   = RGB(.5,.5,0)

áo = ás + áb x (1 - ás) = .5 + 1 x (1 - .5) = 1

Now you blend this:

B(Cb, Cs) = Cb x Cs = RGB(.5,.5,0) x RGB(1,0,0) = RGB(.5,0,0)

Feed this into the full compositing formula:

c0 = ás x (1 - áb) x Cs + ás x áb x B(Cb, Cs) + (1 - ás) x áb x Cb

   = 1 x (1-1) x RGB(.5,0,0) + 1 x 1 x RGB(.5,0,0) + (1-1) x 1 x RGB(1,0,0)

   = 0 + RGB(.5,0,0) + 0 = RGB(.5,0,0)

Now take a pixel that is RGB(0,1,0,1) that is on top of RGB(1,0,0,1) with a
multiply blend mode and alpha of .5. (This is how you are doing the math)

First you blend this:

B(Cb, Cs) = Cb x Cs = RGB(0,1,0) x RGB(1,0,0) = RGB(0,0,0)

Feed this into the full compositing formula:

c0 = ás x ((1 - áb) x Cs + áb x B(Cb, Cs)) + (1 - ás) x áb x Cb

   = .5 x (1-1) x RGB(0,1,0) + 1 x RGB(0,0,0) + (1-.5) x 1 x RGB(1,0,0)

   = RGB(0,.5,0) + RGB(0,0,0) + RGB(.5,0,0) = RGB(.5,.5,0)

Notice that in the first example, you have to composite twice.

Rik

On Fri, Jul 27, 2012 at 4:44 PM, Calculemus <calculemus1988@gmail.com>wrote:

> Rik,
>
> 1. "Where is the alpha coming from? Is it already in the image that you're
> applying blending to?"
>
> I created the images A and B in Photoshop, A has opacity
> 75% and B has 100%, so the alpha is coming
> from the images yes.
>
> 2. "If so, you need to alpha blend with the background first and then
> blend."
>
> You mean alpha blend the top image A with bottom/background image B?
> And then blend with...? I am confused, so I am not supposed to use that
> formula?
>
> Thanks
>

Received on Saturday, 28 July 2012 19:53:13 UTC