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] Question: in what color space will blending occur? #427

Open
krogovin opened this issue Mar 11, 2021 · 3 comments
Open

[compositing] Question: in what color space will blending occur? #427

krogovin opened this issue Mar 11, 2021 · 3 comments

Comments

@krogovin
Copy link

Right now, blending occurs in sRGB space since everything is in sRGB space. Admittedly this is bad from a physical modeling point of view for light (a nice text to read is https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-24-importance-being-linear) for perceptual as-is it makes some sense.

But what happens with stuff in a different color space? Should the color be converted to sRGB first then blended or something else?

@svgeesus
Copy link
Contributor

As you say, for the legacy sRGB syntaxes we are limited by Web compat to do the wrong thing (operating directly on gamma-encoded values). Blending/mixing/interpolation can have an opt-in to do better things (either linear-light for physical light modelling, or perceptual uniformity, or chroma-preserving perceptual uniformity).

For the non-legacy Wide Color Gamut stuff, converting to sRGB first is absolutely not the way to go as the Interpolation section makes clear, in particular Color space for interpolation.

The work to add these opt-ins for transitions, animations, gradients, and compositing is ongoing.

@svgeesus svgeesus transferred this issue from w3c/csswg-drafts May 12, 2021
@svgeesus svgeesus changed the title [css-color-4] Question: in what color space will blending occur? [compositing] Question: in what color space will blending occur? May 12, 2021
@kepstin
Copy link

kepstin commented Jul 25, 2023

According to #517 (comment) there already exist some browsers on macOS which perform compositing in the display-p3 colourspace if the display is capable. Adding wording to the specification to state that "legacy" compositing/blending must be performed in sRGB would mean that current browsers which are capable of displaying colours outside the sRGB gamut are not in compliance with the specification.

So the "status quo" statement would be to say that "legacy" compositing/blending happens in an implementation-defined colourspace, which will typically be the colourspace of the system's display output. The specification should also note that "legacy" compositing/blending is performed without gamma correction (i.e. without first converting to a linear light or a perceptually uniform colourspace).

Note that for "Simple alpha compositing" (where the alpha channel of a sample is a value indicating the ratio within the sample coverage area of opaque colour vs full transparency), performing the compositing in linear light is generally considered to be correct.

The blending of opaque colours in other blend modes is typically used for artistic effect, and the colour space that they are performed in should be selectable since it will give noticeably different results; a non-linear or perceptual space might be preferred over linear.

@svgeesus
Copy link
Contributor

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>CSS Test: hsla()</title>
		<link rel="author" title="L. David Baron" href="https://dbaron.org/" />
		<link rel="author" title="Chris Lilley" href="https://svgees.us" />
		<link rel="author" title="Mozilla Corporation" href="http://mozilla.com/" />
		<link rel="help" href="http://www.w3.org/TR/css3-color/#hsla-color" />
		<link rel="match" href="t425-hsla-basic-a-ref.xht" />
		<meta name="assert" content="Test basic functioning of hsla() colors." />
		<style type="text/css"><![CDATA[
		html, body { background: white; }
		div { width: 12em; height: 6em; }
		#one { background-color: hsla(120, 100%, 70%, 1.0); margin-bottom: 0 }
		#two { background-color: hsla(120, 100%, 50%, 0.6); margin-top:0 }
		]]></style>
		/* 
		hsla(120, 100%, 70%, 1.0) is rgb(40% 100% 40%)
		hsla(120, 100%, 50%, 0.6) is rgb(0% 100% 0% / 0.6)
		composite rgb values at 60% over white  in sRGB = rgb(40% 100% 40%)
		BUT if compositing is done with used values, in device RGB 
		you will get a mismatch on WCG screen
		because the red and blue components will not be zero
		and the green will not be 100%
		*/
	</head>
	<body>
		<p>Test passes if you see a light green square.</p>
		<div id="one"></div>
		<div id="two"></div>
	</body>
</html>

reference is

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>CSS Test: hsla()</title>
		<link rel="author" title="L. David Baron" href="https://dbaron.org/" />
		<link rel="author" title="Chris Lilley" href="https://svgees.us" />
		<style type="text/css"><![CDATA[
		html, body { background: white; }
		div { width: 12em; height: 12em; }
		#one { background-color: hsla(120, 100%, 70%, 1.0); margin-bottom: 0 }
		]]></style>
	</head>
	<body>
		<p>Test passes if you see a light green square.</p>
		<div id="one"></div>
	</body>
</html>

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