W3C home > Mailing lists > Public > public-svg-wg@w3.org > October to December 2008

Re: ISSUE-2095 (soft-light blend mode): Algorithm for soft-light blend mode [Module: Filters]

From: Alex Danilo <alex@abbra.com>
Date: Fri, 10 Oct 2008 08:31:46 +1100
Message-Id: <YGQH8K.YSKKVIHE4TPL@abbra.com>
To: "Benjamin Otte" <otte@gnome.org>
Cc: "SVG Working Group WG" <public-svg-wg@w3.org>

Thanks Benjamin!

--Original Message--:
>So I've spent the day looking up the bled-mode formulas, implementing
>them and testing them against various applications to make sure
>they're correct. It turns out that not only soft-light, but also
>color-dodge and color-burn are incorrect. I'll post the correct
>versions, taken from the ISO32000 PDF specification at
>http://www.adobe.com/devnet/acrobat/pdfs/PDF32000_2008.pdf and adapted
>to the syntax used in the SVG spec:

It would have been nice if we had that spec. back in 2002!
In the soft-light below the SQRT is back. Does that mean
it was needed in the end?

Anyway, good work.

Cheers,
Alex

>Color Dodge:
>if Sca == Sa and Dca == 0
>    Dca' = Sca.(1 - Da) + Dca.(1 - Sa)
>otherwise if Sca == Sa
>  Dca' = Sa.Da + Sca.(1 - Da) + Dca.(1 - Sa)
>otherwise
>  Dca' = Da.Sa. min (Dca / Da / (1 - Sca/Sa))
>Note that the first term is not part of the PDF, but implemented by
>all PDF applications.
>
>Color Burn:
>if Sca. == 0 and Dca == Da
>  Dca' = SaDa + Sca.(1 - Da) + Dca.(1 - Sa)
>otherwise if Sca == 0
>  Dca' = Sca.(1 - Da) + Dca.(1 - Sa)
>otherwise
>  Dca' = Sa.Da.(1 - min (1, (1 - Dca/Da).Sa / Sca)) + Sca.(1 - Da) +
>Dca.(1 - Sa)
>Again the first term is not part of the specification, but implemented
>by PDF applications.
>
>Soft Light:
>if (2.Sca <= Sa)
>  Dca' = Dca.(Sa - (1 - Dca/Da).(2.Sca - Sa)) + Sca.(1 - Da) + Dca.(1 - Sa)
>otherwise if Dca.4 <= Da
>  Dca' = Dca.(Sa + (2.Sca - Sa).((16.Dca/Da - 12).Dca/Da + 3) + Sc.(1
>- Da) + Dca.(1 - Sa)
>otherwise
>  Dca' = (Dca.Sa + (SQRT (Dca/Da).Da - Dca).(2.Sca - Sa)) + Sca.(1 -
>Da) + Dca.(1 - Sa)
>
>For more details about my experiments and wich apps I tested, see
>http://lists.freedesktop.org/archives/cairo/2008-October/015362.html
>
>Cheers,
>Benjamin
>
>
>On Thu, Oct 9, 2008 at 12:22 PM, Alex Danilo <alex@abbra.com> wrote:
>> Hi Benjamin,
>>
>>
>>        In that case you should use that as the definitive formula.
>> As I said, we had to try to work it out by help of others reverse
>> engineering work. A pixel by pixel comparison of all input values
>> against the PDF viewer should be used to verify that it's correct.
>>
>>        _But_, as I said before we had to extend the formulas
>> to take into account alpha. There's no alpha in the formulas
>> you quoted, so you will need to derive the correct formulas
>> based on source and destination alpha to give the correct
>> result for the general case. Opaque blends are just a subset
>> of what is needed.
>>
>> Alex
>>
>> --Original Message--:
>>>Adobe has published the blend modes used in PDF at
>>>http://www.adobe.com/devnet/pdf/pdfs/blend_modes.pdf
>>>It defines soft-light as
>>>
>>>if (Sc <= 0.5)
>>>  Dc' = Dc - (1 - 2.Sc).Dc.(1-Dc)
>>>otherwise
>>>  Dc' = Dc + (2.Sc - 1) . (F(Dc) - Dc)
>>>
>>>with
>>>if (x <= 0.25)
>>>  F(x) = ((16.x - 12).x + 4).x
>>>otherwise
>>>  F(x) = x
>>>
>>>which is slightly different from the formula you presented.
>>>It is also easier to implement as it doesn't involve square roots.
>>>
>>>Cheers,
>>>Benjamin
>>>
>>>
>>>On Thu, Oct 9, 2008 at 6:30 AM, Alex Danilo <alex@abbra.com> wrote:
>>>>
>>>> Hi All,
>>>>
>>>> --Original Message--:
>>>>>ISSUE-2095 (soft-light blend mode): Algorithm for soft-light blend mode [Module: Filters]
>>>>>
>>>>>http://www.w3.org/Graphics/SVG/WG/track/issues/2095
>>>>>
>>>>>Raised by: Doug Schepers
>>>>>On product: Module: Filters
>>>>>
>>>>>Benjamin Otte
>>>>><http://lists.w3.org/Archives/Public/www-svg/2008Oct/0029.html>:
>>>>>[[
>>>>>I'm in the process of implementing bend modes in the Cairo imaging
>>>>>library[1]. As Cairo is used as the renderer for a wide variety of
>>>>>formats, I wanted to have an as comprehensive list of blend modes as
>>>>>possible. And it turns out that the blend mode algorithms used are
>>>>>almost always equal. However, there is one exception: soft-light. The
>>>>>latest SVG draft specifies a different algorithm than PDF.
>>>>>
>>>>>So I was wondering if it was possible to change the algorithm in SVG
>>>>>to match the one of PDF, as that would solve a lot of problems.
>>>>>]]
>>>>
>>>> If there is a discrepancy it is a mistake.
>>>>
>>>> While I was working on this, we had to deduce the functions from various
>>>> sources, since the equations were not  published. The starting point was
>>>> some Japanese site that had reverse engineered the equations from
>>>> looking at Photoshop. We extended the base equations to include
>>>> alpha correctly.
>>>>
>>>> These were always supposed to be compatible with PDF.
>>>>
>>>> Implementing this showed up bugs in compatibility which were fixed
>>>> but probably never made it out to the spec. I believe the correct equations
>>>> are:
>>>>
>>>> if 2.Sca < Sa
>>>>   Dca' = Dca.(Sa + (1 - Dca/Da).(2.Sca - Sa)) + Sca.(1 - Da) + Dca.(1 - Sa)
>>>>  otherwise if 8.Dca <= Da
>>>>   Dca' = Dca.(Sa + (1 - Dca/Da).(2.Sca - Sa).(3 - 8.Dca/Da)) + Sca.(1 - Da) + Dca.(1 - Sa)
>>>>  otherwise
>>>>   Dca' = (Dca.Sa + ((Dca/Da)^(0.5).Da - Dca).(2.Sca - Sa)) + Sca.(1 - Da) + Dca.(1 - Sa)
>>>>
>>>>  Da'  = Sa + Da - Sa.Da
>>>>
>>>> which is different to what is in the latest published spec. Adobe had an action to
>>>> check the equations many years ago which was never acted on. Hopefully the
>>>> above equation is what you expected, if not please point us to the references that
>>>> are causing issues for you.
>>>>
>>>> Thanks,
>>>> Alex
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Received on Thursday, 9 October 2008 21:32:27 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 9 October 2008 21:32:28 GMT