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

Hi, Anthony-

It's best to post public messages to www-svg, instead of public-svg-wg,
so that the replies aren't moderated.

Benjamin, you can reply directly to this email to get your message
posted to the www-archives.

Regards-
-Doug

Anthony Grasso wrote (on 2/12/09 4:32 PM):
> 
> Hi Benjamin,
> 
> Benjamin Otte wrote:
>>
>>
>>
>> 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:
>>
> 
> Thank you very much for taking the time to chase down the PDF
> specification and the correct equations! :)
> 
> The SVG Working Group raised an issue (ISSUE-2095) about the incorrect
> Soft Light blend mode equation [1] and as a result I was assigned an
> action (ACTION-2427) [2] to update the SVG Compositing Module [3] with
> the correct equations.
> 
> Using the equations and links you provided for the PDF specification [4]
> I have updated the SVG Compositing Module specification.
> 
> I understand how the full alpha Color Dodge and Color Burn were derived
> from the PDF specification, however I've miss understood how you derived
> the Soft Light equation. Using the PDF specification I attempted to
> derive the full alpha equation for Soft Light. This is the equation I
> derived.
> 
> PDF Soft Light
> --------------
> if 2.Sc <= 1
>   f(Sc,Dc) = Dc - (1 - 2.Sc).Dc.(1 - Dc)
> otherwise if 2.Sc > 1 and 4.Dc <= 1
>   f(Sc,Dc) = Dc + (2.Sc - 1).((((16.Dc - 12).Dc + 4).Dc) - Dc)
> otherwise if 2.Sc > 1 and 4.Dc > 1
>   f(Sc,Dc) = Dc + (2.Sc - 1).(SQRT(Dc) - Dc)
> X        = 1
> Y        = 1
> Z        = 1
> 
> Derived Soft Light with Alpha
> -----------------------------
> if 2.Sca <= Sa
>   Dca' = Dca.Sa - (Sa.Da - 2.Sca.Da).Dca.Sa.(Sa.Da - Dca.Sa) + Sca.(1 -
> Da) + Dca.(1 - Sa)
> 
> otherwise if 2.Sca > Sa and 4.Dca <= Da
>   Dca' = Dca.Sa + (2.Sca.Da - Sa.Da).((((16.Dsa.Sa - 12).Dsa.Sa +
> 4).Dsa.Da) - Dsa.Da) + Sca.(1 - Da) + Dca.(1 - Sa)
> 
> otherwise if 2.Sca > Sa and 4.Dca > Da
>   Dca' = Dca.Sa + (2.Sca.Da - Sa.Da).(SQRT(Dca.Sa) - Dca.Sa) + Sca.(1 -
> Da) + Dca.(1 - Sa)
> 
> 
>>
>> 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
>>
>>
> 
> Testing has shown my equation result is different to your equation
> result - unfortunately :(
> 
> I'm unsure if my derivation is correct, so I guess my question is do you
> have an expanded version of your equations or if you have time would it
> be possible to show me how you derived your equation please?
> 
> Any further information or help you can provide on this issue would be
> greatly appreciated.
> 
> Kind Regards,
> 
> Anthony Grasso
> 
> [1] http://www.w3.org/Graphics/SVG/WG/track/issues/2095
> [2] http://www.w3.org/Graphics/SVG/WG/track/actions/2427
> [3]
> http://dev.w3.org/SVG/modules/compositing/master/SVGCompositingPrimer.html
> [4] http://www.adobe.com/devnet/pdf/pdfs/blend_modes.pdf
> 
>> 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 Friday, 13 February 2009 00:51:13 UTC