Linear RBG and feComposite "arithmetic"

From: Thomas E Deweese <thomas.deweese@kodak.com>
Date: Mon, 10 Sep 2001 11:37:15 -0400
Message-ID: <15260.56875.339041.54208@gargle.gargle.HOWL>
To: Thomas E Deweese <thomas.deweese@kodak.com>
Cc: Jim Mork <jmork@jasc.com>, "'www-svg@w3.org'" <www-svg@w3.org>
```>>>>> "TD" == Thomas E Deweese <thomas.deweese@kodak.com> writes:

>>>>> "JM" == Jim Mork <jmork@jasc.com> writes:

JM> An SVG sample is included at the end of this message.  The sample
JM> is the result of reducing the composite example in the test suite
JM> down to elements essential to demonstrating the problem.  The
JM> example consists of two overlapping rectangles--one solid cyan
JM> (R=0,G=255,B=255,A=255) and one solid magenta
JM> (R=255,G=0,B=255,A=255).  The feComposite "arithmetic" filter
JM> effect is applied using "SourceGraphic" (magenta rectangle) and
JM> "BackgroundImage" (part of cyan rectangle) as inputs.  Each image
JM> is multiplied by the coefficent 0.5--add half of each together.

TD>     [...]

JM> I'm not sure which is the correct result.  Adobe's plug-in returns
JM> (128, 128, 255, 255) but if that result is converted back to sRGB
JM> from linearRGB, the result is (186, 186, 255, 255).  Perhaps I've
JM> missed something in the spec and/or I doing something wrong, but
JM> that is the result I get when my effect processing is consisted in
JM> its use of linear RGB.

JM> Any help or suggestions will be much appreciated!

TD>     Once I add a 'g' element with 'enable-background="new"' (you
TD> did not have any thing turning on the background image) around the
TD> rectangles, Batik give's (188, 188, 255) for the middle rectangle,
TD> I assume the 2 code value difference is due to Batik using the
TD> more complete Gamma calculation.  It's possible that part of the
TD> problem is the lack of enable-background, but I don't think so...

Actually this was the problem.  Without the enable-background
present, you end up 'compositing' the magenta rect with transparent
black (0, 0, 0, 0). The result of the combine is:

(.5, 0, .5, .5)

Because the operation works on pre-multiplied versions of the
components when you undo the sRGB->linear you get (using math from

(0.73, 0, 0.73, 0.5)

Note that this violates the Alpha-Premultiplied rules because the
color channels have values greater than the alpha channel.  Thus these
values get clipped to the alpha channel value:

(0.5, 0, 0.5, 0.5)

Ie, a 50% opaque Magenta rectangle...

This is then composited with srcOver on top of the cyan rectangle
in sRGB, the result is:

(0.5, 0.5, 1.0, 1.0)

Giving the result you saw.
```
Received on Monday, 10 September 2001 11:37:18 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 March 2017 09:46:51 UTC