Skip to content

Commit 9de47c1

Browse files
committed
[css-color-4] clarify RGB-to-Lab & Lab-to-RGB, fix #4647
1 parent e014c68 commit 9de47c1

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

css-color-4/Overview.bs

+23-18
Original file line numberDiff line numberDiff line change
@@ -1268,10 +1268,10 @@ HSL Colors: ''hsl()'' and ''hsla()'' functions</h2>
12681268
across hues.
12691269

12701270
<div class="example">
1271-
For example, <span class="swatch" style="--color: blue"></span>&nbsp;''blue'''
1271+
For example, <span class="swatch" style="--color: blue"></span>&nbsp;''blue''
12721272
is represented in HSL as
1273-
<span class="swatch" style="--color: blue"></span>&nbsp;''hsl(240deg 100% 50%)
1274-
while <span class="swatch" style="--color: yellow"></span>&nbsp;''yellow'''
1273+
<span class="swatch" style="--color: blue"></span>&nbsp;''hsl(240deg 100% 50%)''
1274+
while <span class="swatch" style="--color: yellow"></span>&nbsp;''yellow''
12751275
is <span class="swatch" style="--color: yellow"></span>&nbsp;''hsl(60deg 100% 50%)''.
12761276
Both have an HSL Lightness of 50%,
12771277
but clearly the yellow looks much lighter than the blue.
@@ -1302,24 +1302,24 @@ HSL Colors: ''hsl()'' and ''hsla()'' functions</h2>
13021302
<span class="swatch" style="--color: hsl(220 100% 50%)"></span>&nbsp;''hsl(220deg 100% 50%)''
13031303
and
13041304
<span class="swatch" style="--color: hsl(250 100% 50%)"></span>&nbsp;''hsl(250deg 100% 50%)''
1305-
have an HSL hue difference of 30deg and look fairly similar,
1305+
have an HSL hue difference of 250-220 = <strong>30</strong>deg and look fairly similar,
13061306
while another pair of colors
13071307
<span class="swatch" style="--color: hsl(50 100% 50%)"></span>&nbsp;''hsl(50deg 100% 50%)''
13081308
and
13091309
<span class="swatch" style="--color: hsl(80 100% 50%)"></span>&nbsp;''hsl(80deg 100% 50%)'',
1310-
which also have a hue difference of 30deg, look very different.
1310+
which also have a hue difference of 80-50 = <strong>30</strong>deg, look very different.
13111311

13121312
In LCH, the same pair of colors
13131313
<span class="swatch" style="--color: hsl(220 100% 50%)"></span>&nbsp;''lch(42.1% 97.4 290.6)''
13141314
and
13151315
<span class="swatch" style="--color: hsl(250 100% 50%)"></span>&nbsp;''lch(30.8% 129.7 302.1)''
1316-
have a hue difference of 11.5deg
1316+
have a hue difference of 302.1-290.6 = <strong>11.5</strong>deg
13171317
while the second pair
13181318
<span class="swatch" style="--color: hsl(50 100% 50%)"></span>&nbsp;''lch(86.8% 86.2 87.3)''
13191319
and
13201320
<span class="swatch" style="--color: hsl(80 100% 50%)"></span>&nbsp;''lch(92.0% 98.8 119.1)''
1321-
have a hue difference of 31.8deg
1322-
reflecting the visual separation of hues.
1321+
have a hue difference of 119.1-87.3 = <strong>31.8</strong>deg,
1322+
correctly reflecting the visual separation of hues.
13231323

13241324
</div>
13251325

@@ -2253,10 +2253,10 @@ Specifying Lab and LCH: the ''lab()'' and ''lch()'' functional notations</h3>
22532253
</div>
22542254

22552255
<h3 id='rgb-to-lab'>
2256-
Converting sRGB colors to Lab colors</h3>
2256+
Converting RGB colors to Lab colors</h3>
22572257

2258-
Conversion from sRGB to Lab requires several steps,
2259-
although in practice all but the first step are linear calculations and can be combined.
2258+
Conversion from an RGB colorspace to Lab requires several steps,
2259+
although in practice all but the first step are linear calculations and can be combined. Taking sRGB as an example:
22602260

22612261
<!-- make these steps links to the appropriate section in a calculations appendix -->
22622262
<ol>
@@ -2271,20 +2271,25 @@ Converting sRGB colors to Lab colors</h3>
22712271
<li>Convert D50-adapted XYZ to Lab
22722272
</ol>
22732273

2274-
There is sample JavaScript code for this conversion in [[#color-conversion-code]].
2274+
There is sample JavaScript code for this conversion
2275+
for various RGB colorspaces, in [[#color-conversion-code]].
22752276

22762277
<h3 id='lab-to-rgb'>
2277-
Converting Lab colors to sRGB colors</h3>
2278+
Converting Lab colors to RGB colors</h3>
22782279

2279-
Conversion from Lab to sRGB also requires multiple steps,
2280-
and again in practice all but the last step are linear calculations and can be combined.
2280+
For display on a screen,
2281+
Lab colors will need to be converted
2282+
to the colorspace of the display.
2283+
2284+
Conversion from Lab to an RGB space also requires multiple steps,
2285+
and again in practice all but the last step are linear calculations and can be combined. Taking display-p3 as an example,
22812286

22822287
<ol>
22832288
<li>Convert Lab to (D50-adapted) XYZ
22842289
<li>Convert from a D50 whitepoint (used by Lab) to the D65 whitepoint used
2285-
in sRGB, with the Bradford transform
2286-
<li>Convert from (D65-adapted) CIE XYZ to linear sRGB
2287-
<li>Convert from linear-light sRGB to sRGB (do gamma encoding)
2290+
in display-p3, with the Bradford transform
2291+
<li>Convert from (D65-adapted) CIE XYZ to linear-light display-p3
2292+
<li>Convert from linear-light display-p3 to display-p3 (do gamma encoding)
22882293
</ol>
22892294

22902295
<h3 id='lab-to-lch'>

0 commit comments

Comments
 (0)