Skip to content

Commit 52e0f74

Browse files
committed
[css-color-5] Add RCS OKLCH example
1 parent 0b43464 commit 52e0f74

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

css-color-5/Overview.bs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,8 +1095,11 @@ the allowed [=channel keywords=] are:
10951095
However, unlike HSL, manipulations are not guaranteed to be in-gamut.
10961096

10971097
<div class="example" id="ex-wildly-oog">
1098+
In this example, the aim is to produce a new color
1099+
with the same Lightness and Chroma,
1100+
but the triad (hue differs by 120 degrees).
10981101
The origin color is inside the RGB gamut,
1099-
but rotating the hue
1102+
but rotating the hue in LCH
11001103
produces an out of gamut color.
11011104

11021105
<!-- lch(60% 90 320) = lab(60% 68.94 -57.9)
@@ -1133,6 +1136,25 @@ However, unlike HSL, manipulations are not guaranteed to be in-gamut.
11331136
The gamut-mapped <span class="swatch" style="--color: rgb(0% 64.2% 66.3%)"></span> result has much lower chroma.
11341137
</figcaption>
11351138
</figure>
1139+
1140+
Performing the same operation in HSL will return an in-gamut result.
1141+
But it is unsatisfactory in other ways:
1142+
1143+
<pre>
1144+
--mycolor: <span class="swatch" style="--color: rgb(86.1% 33.4% 97.6%)"></span> lch(60% 90 320);
1145+
hsl(from var(--mycolor) calc(h - 120) s l);
1146+
</pre>
1147+
1148+
In HSL, --mycolor is
1149+
<span class="swatch" style="--color: rgb(86.1% 33.4% 97.6%)"></span> hsl(289.18 93.136% 65.531%)
1150+
so subtracting 120 degrees gives
1151+
<span class="swatch" style="--color: rgb(33.428% 97.634% 86.056%)"></span> hsl(169.18 93.136% 65.531%).
1152+
Converting that result back to LCH
1153+
<span class="swatch" style="--color: rgb(33.428% 97.634% 86.056%)"></span> lch(89.0345% 49.3503 178.714)
1154+
we see that, due to the hue rotate in HSL,
1155+
Lightness shot up from 60% to 89%,
1156+
the Chroma has dropped from 90 to 49,
1157+
and the Hue actually changed by 141 degrees not 120.
11361158
</div>
11371159

11381160
<h3 id="relative-OKLCH">Relative OKLCH colors</h3>
@@ -1155,6 +1177,31 @@ the allowed [=channel keywords=] are:
11551177
normalized to a [0deg, 360deg) range.
11561178
* <dfn value for="oklch()">alpha</dfn> is a <<percentage>> that corresponds to the [=origin color's=] alpha transparency
11571179

1180+
<div class="example" id="ex-oklch-wildly-oog">
1181+
In this example, the aim is again to produce a new color
1182+
with the same Lightness and Chroma,
1183+
but the triad (hue differs by 120 degrees).
1184+
In this example, we will do the manipulation in OKLCH.
1185+
The origin color is inside the RGB gamut,
1186+
but rotating the hue in OKLCH
1187+
again produces an out of gamut color.
1188+
1189+
<pre>
1190+
--mycolor: <span class="swatch" style="--color: rgb(86.1% 33.4% 97.6%)"></span> lch(60% 90 320);
1191+
oklch(from var(--mycolor) l c calc(h - 120));
1192+
</pre>
1193+
1194+
--mycolor is <span class="swatch" style="--color: rgb(86.1% 33.4% 97.6%)"></span> oklch(69.012% 0.25077 319.893).
1195+
Subtracting 120 from the Hue gives a very high-chroma blue-green,
1196+
<span class="swatch oog" style="--color: grey"></span> oklch(69.012% 0.25077 199.893)
1197+
which is out of sRGB gamut,
1198+
color(srgb -0.6018 0.7621 0.8448)
1199+
as the negative red component indicates.
1200+
Bring this into gamut
1201+
by reducing OKLCH Chroma, yeilds
1202+
<span class="swatch" style="--color: rgb(0.079% 69.282% 72.067%)"></span> oklch(69.012% 0.1173 199.893).
1203+
The OKLCH chroma has dropped from 0.251 to 0.117.
1204+
</div>
11581205

11591206
<h3 id="relative-color-function">Relative color-function colors</h3>
11601207

0 commit comments

Comments
 (0)