Re: Compositing math in SVG

On Sat, Jul 21, 2012 at 1:26 PM, Calculemus <calculemus1988@gmail.com>wrote:

> Having problems with the formulas from SVG spec...
>
> I tested the blend modes and my results match
> perfectly Photoshop and GIMP results, but only
> for regions in the image where alpha values
> are either 0 or 1 for the input images.
>
> If the top image for example has Opacity, or
> alpha 0.5 then my results are darker for some reason
> I can't figure out whole day.
>
> I am using the formulas for blend modes and Over compositing
> from SVG spec:
>
> http://www.w3.org/TR/SVGCompositing/
>
> What could possibly be the reason for this behaviour?
>
> The general formula is:
>
> A*aa*(1-ba) + B*ba*(1-aa) + aa*ba*Blend(A, B)
>

This formula will return you the color in premultiplied alpha.
I think you still need to calculate alpha of the end result and matte with
white to get the final color.

See example 4 in
https://dvcs.w3.org/hg/FXTF/rawfile/tip/compositing/index.html#backdropexamples


>
> where A and B are non-premultiplied color values and aa and ba
> are alpha values.
>
> When aa and ba are both 1 my results are fine, the formula reduces
> to Blend(A,B). This confirms that I have all formulas
> for blend modes correct. It is the other part before
> Blend(A,B) that must somehow causing this problem.
>
> So, this is the case for all blend modes, not just for one or two.
> I wonder if the formula for compositing is correct?
> The blend formulas are correct  though.
>

Received on Saturday, 21 July 2012 22:03:27 UTC