Re: [csswg-drafts] [css-color-6] color-contrast() should take transparency into account (#7358)

The CSS Working Group just discussed `transparency`, and agreed to the following:

* `RESOLVED: When calculating color contrast between pairs of semi transparent colors, if the background is opaque, UAs should alpha blend the foreground on the background and use that as the foreground color. If the background is also semi-transparent, it would be alpha blended first with an opaque version of the foreground`
* `RESOLVED: Amend previous resolution, the canvas color in previous resolution is TBD`
* `RESOLVED: (rather than opaque version of foreground)`

<details><summary>The full IRC log of that discussion</summary>
&lt;fantasai> Subtopic: transparency<br>
&lt;fantasai> github: https://github.com/w3c/csswg-drafts/issues/7358<br>
&lt;emilio> lea: current draft doesn't mention transparency<br>
&lt;emilio> ... most contrast arguments ignore it<br>
&lt;emilio> ... if fg is semi-transparent some algorithms make it work, otherwise ignore it<br>
&lt;emilio> ... when you have a range of contrasts there's no answer<br>
&lt;emilio> ... one option would be using the minimum contrast<br>
&lt;emilio> ... for wcag there's work to compute min/max contrast<br>
&lt;florian> q+<br>
&lt;astearns> ack florian<br>
&lt;emilio> ... if foreground is transparent but bg is opaque you can alphablend but in the bg case it's not so clear cut...<br>
&lt;lea> q+<br>
&lt;chris> q+ to wonder about mixed domain backgrounds<br>
&lt;astearns> ack dbaron<br>
&lt;emilio> florian: for fg there's an answer, for background... it's trickier, it's not terribly convenient to find the whole color, but if you're trying what's the best contrasting color against transparent this is not answerable<br>
&lt;emilio> dbaron: first intuition is that having a bg that's not opaque should be a syntax error<br>
&lt;emilio> ... wrt contrast ranges, maybe alpha-compositing bg with alpha over foreground with no alpha might give you the minimum contrast, but might vary per algo<br>
&lt;astearns> ack fantasai<br>
&lt;emilio> fantasai: was gonna suggest the same, composite semi-transparent bg over foreground color would give you the worst case scenario<br>
&lt;emilio> ... if both semi-transparent it gets extra-exciting, maybe composite against black?<br>
&lt;astearns> ack lea<br>
&lt;emilio> lea: not sure how we'd specify this so that colors are semi-transparent<br>
&lt;emilio> q+<br>
&lt;emilio> lea: compositing on black might give you the max contrast<br>
&lt;astearns> ack chris<br>
&lt;Zakim> chris, you wanted to wonder about mixed domain backgrounds<br>
&lt;fantasai> s/so that colors are semi-transparent/so that semi-transparent is invalid<br>
&lt;emilio> chris: if you have stuff like iframes that are transparent, does that allow you to find the background behind the iframe<br>
&lt;fantasai> i/lea: compositing/TabAtkins: in prose/<br>
&lt;astearns> ack em<br>
&lt;emilio> TabAtkins: not doing that, there's no way to know what the color will be used on<br>
&lt;fantasai> emilio: Making it invalid at syntax time sounds nice, but not possible in current impl<br>
&lt;dbaron> s/current impl/the presence of currentColor/<br>
&lt;fantasai> emilio: Offhand, I don't expect this to be a super common thing to hapen<br>
&lt;florian_irc> s/for background... it's trickier, it's not terribly convenient to find the whole color, but if you're trying what's the best contrasting color against transparent this is not answerable/For background, what authors should be supplying is not the possibly semi-transparent background color of the element, but rather the composited background against which the foreground will be seen. It's not necessarily easy for authors to figure<br>
&lt;florian_irc> what that is, but that's the only thing that makes sense. The color-mix function might help./<br>
&lt;fantasai> emilio: doing what fantasai and dbaron suggested seems a reasonable compromise to me<br>
&lt;astearns> ack dbaron<br>
&lt;lea> q+<br>
&lt;emilio> dbaron: what I was suggesting if they are both not opaque was to take the foreground, modify alpha to be 1, then composite the bg on top<br>
&lt;florian> s_what that is, but that's the only thing that makes sense. The color-mix function might help./__<br>
&lt;emilio> ... then compare fg composited against that<br>
&lt;emilio> ... that was my intuition for the worst case<br>
&lt;emilio> fantasai: [sanity-checks that]<br>
&lt;florian> s_to figure_to figure what that is, but that's the only thing that makes sense. The color-mix function might help._<br>
&lt;TabAtkins> composite fg over bg over (fg with alpha set to 1)<br>
&lt;lea> no need for color-mix(), relative color syntax can do that: lab(from foreground l a b / 1)<br>
&lt;emilio> dbaron: new_bg = alpha(fg, 1.0);  bg = composite(bg, new_bg);<br>
&lt;fantasai> emilio: the goal is to make both opaque<br>
&lt;fantasai> emilio: so you need to composit on top of the new background that's opaque<br>
&lt;emilio> dbaron: this is sort of speculative, we should work it out in an issue<br>
&lt;emilio> astearns: well this would be the issue<br>
&lt;emilio> dbaron: underlying question is "does this give you the worst case?"<br>
&lt;emilio> lea: intuitively it seems like it might<br>
&lt;emilio> fantasai: so generically, we have a canvas that is the foreground with alpha 1, then we draw the background, then the foreground<br>
&lt;TabAtkins> fg compared against (bg on top of opaque fg)<br>
&lt;emilio> ... if everything is opaque then it all works out<br>
&lt;florian> q?<br>
&lt;fantasai> s/works out works out easily, otherwise you need to do some compositing/<br>
&lt;emilio> florian: sounds like it gives a clear answer<br>
&lt;emilio> TabAtkins: how can you get a less contrasting color with the foreground than the foreground itself<br>
&lt;astearns> ack lea<br>
&lt;emilio> q+<br>
&lt;florian> s/clear answer/, not sure it's a great answer/<br>
&lt;dbaron>  It's probably not the absolute minimum for all algorithms, but it's probably close.<br>
&lt;astearns> ack emilio<br>
&lt;florian> q+<br>
&lt;fantasai> emilio: I'm not sure it'll be the least contrasting color<br>
&lt;fantasai> emilio: the least contrasting option would be the compositing the background with the foreground maxed out<br>
&lt;fantasai> TabAtkins: that's the suggestion<br>
&lt;fantasai> emilio: but that's not quite the same<br>
&lt;fantasai> emilio: the least conrasting option with the foreground is the foreground itself<br>
&lt;fantasai> emilio: okay, yeah<br>
&lt;fantasai> emilio: if you apply the background, then, yes, that should give you the worst. Nevermind<br>
&lt;emilio> dbaron: I'm not sure it's the least contrasting. if you state it like fantasai where you have three layers<br>
&lt;lea> FWIW this was the research I had done 10+ years ago on min/max WCAG contrast: https://lists.w3.org/Archives/Public/w3c-wai-ig/2012OctDec/0011.html<br>
&lt;lea> I can't at a glance tell if the formula for min contrast is what dbaron is proposing<br>
&lt;emilio> dbaron: the contrast aren't uniform with blending<br>
&lt;astearns> ack florian<br>
&lt;emilio> ... so I think there's variations where this might not work<br>
&lt;lea> +1 fantasai<br>
&lt;emilio> florian: other concern is that if we manage to find the least contrasting situation, we might fall back to black / white unnecessarily<br>
&lt;emilio> fantasai: I think dbaron's proposal is the best option, I propose to spec it and let people tell us why we're wrong<br>
&lt;fantasai> emilio: I think what I was thinking is along the lines of what dbaron thought earlier<br>
&lt;florian> s/unnecessarily/unnecessarily, as what's behind the semi-transparent background might not at all be that worse case scenario/<br>
&lt;fantasai> emilio: the worst contrast is when the blend of the color and the color below it is exactly the foreground<br>
&lt;fantasai> emilio: using the foreground color itself doesn't give you the worst one<br>
&lt;fantasai> emilio: suppose you have a red foreground, opaque red<br>
&lt;fantasai> emilio: and you have semitransparent white bg<br>
&lt;dbaron> s/of the color/of the background color/<br>
&lt;fantasai> emilio: can you get a way such that compositing semitransparent white will end up red?<br>
&lt;lea> RESOLVED: When calculating color contrast between pairs of semi transparent colors, if the background is opaque, UAs should alpha blend the foreground on the background and use that as the foreground color. If the background is also semi-transparent, it would be alpha blended first with an opaque version of the foreground<br>
&lt;fantasai> TabAtkins: a medium gray foreground, half-transparent black background, clearly the worst contrast is putting it over white<br>
&lt;fantasai> TabAtkins: putting over medium gray is not as bad<br>
&lt;fantasai> emilio: it's probably good enough<br>
&lt;fantasai> florian: could also just put white or black as the backdrop, depending on color scheme<br>
&lt;fantasai> emilio: [missed]<br>
&lt;fantasai> emilio: Gecko does have some contrast checks for selection<br>
&lt;fantasai> emilio: what we do in the case of semintransparent backgrounds is using the default background<br>
&lt;TabAtkins> Notably the worst case here is 50% transparent bg. as it gets more or less transparent, the answer becomes easier<br>
&lt;fantasai> emilio: basically composit with canvas, can guarantee it's opaque<br>
&lt;fantasai> emilio: simpler answer, maybe more correct<br>
&lt;fantasai> TabAtkins: how about we resolve for now that we'll adopt this approach with a color TBD<br>
&lt;fantasai> TabAtkins: could still use examples and thought<br>
&lt;fantasai> RESOLVED: Amend previous resolution, the canvas color in previous resolution is TBD<br>
&lt;dbaron> (rather than opaque version of foreground)<br>
&lt;TabAtkins> RESOLVED: (rather than opaque version of foreground)<br>
</details>


-- 
GitHub Notification of comment by css-meeting-bot
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7358#issuecomment-1203133122 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 2 August 2022 19:35:21 UTC