Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compositing-1][compositing-2]I am looking for a concrete example of the application of the simple alpha blending formula #517

Open
letochagone opened this issue Dec 9, 2022 · 1 comment

Comments

@letochagone
Copy link

in the following example I cannot determine the color obtained from the formula
explained in the note at the end of the following chapter:
https://www.w3.org/TR/compositing-1/#blending

In the following example I will try to apply the formula from the link above to calculate the color obtained

<div style="width: 200px;height:200px;
            background-color:rgb(0,0,0);">

  <div style="width: 200px;height: 200px;
              background-color: rgba(150,50,100,0.4);">

    <div style="width:200px;height: 200px;
                mix-blend-mode: difference;
                background-color: rgba(100,200,60,0.7);">
    </div>
  </div>
</div>

co = as x (1 - ab) x Cs + as x ab x B(Cb, Cs) + (1 - as) x ab x Cb

as= 0.7
Cs= [100/255, 200/255, 60/255]
ab= 0.4
Cb=[150/255, 50/255, 100/255]

B = | Cb - Cs | = ( 50/255 , 150/255 , 40/255 )

co = as * (1 - ab) * Cs + as * ab * B + (1 - as) * ab * Cb
ao= as+ ab*(1-as)

co = [ 0.29 , 0.52, 0.19 ]
ao = 0.82

Co = co/ao
Co = 0.35 0.63 0.23

this color does not match the one read with a screenshot

@johannesodland
Copy link

I suspect that the color spaces used for composition and blending has something to do with this.

I did a quick test to check which color space is used for blending, by setting alpha to 1:
https://codepen.io/johannesodland/pen/rNKbENO

It seems like both Safari and Chrome (with experimental web features flag turned on) on my mac does blending in a color space that yields similar results as if blending was done in display-p3. Adding a filter property like filter: contrast(100%) seems to force the blending to happen in srgb.

It seems like the color space used for blending varies both depending on the UA, the output device and on properties like filter, yielding very different results.

It would be helpful if the spec stated which color space blending and composition should be done in, or explicitly stated that it's undefined behaviour. Maybe authors could explicitly set which color space blending and composition should be done in through a property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants