@@ -1193,6 +1193,120 @@ to customize color interpolation in gradients as described in [[css-color-4#inte
11931193 <dfn><side-or-corner></dfn> = [left | right] || [top | bottom]
11941194 </pre>
11951195
1196+ The effect of colorspace on interpolation can be marked.
1197+
1198+ <div class="example">
1199+ In this example, a linear gradient between the same pair of colors
1200+ #f01 and #081 is drawn in three different colorspaces.
1201+ The middle gradient uses gamma-encoded sRGB,
1202+ which was the only choice in CSS Images 3;
1203+ the result is clearly too dark at the midpoint.
1204+ The upper gradient uses CIE Lab,
1205+ giving a more perceptually uniform result;
1206+ while the lower gradient uses OKLab,
1207+ which here gives almost the same result as CIE Lab.
1208+
1209+ <ul class="lang-css">
1210+ <li> linear-gradient(in lab to right, #F01, #081)</li>
1211+ <li> linear-gradient(in srgb to right, #F01, #081)</li>
1212+ <li> linear-gradient(in oklab to right, #F01, #081)</li>
1213+ </ul>
1214+
1215+ <!-- source: images/rectangular-f01-081.html -->
1216+ <img src="images/rectangular-f01-081.png"
1217+ width="360" height="330"
1218+ alt="red to green gradient in three colorspaces" />
1219+ </div>
1220+
1221+ <div class="example">
1222+ In this example, a linear gradient between the same pair of colors
1223+ white and #01E is drawn in three different colorspaces.
1224+ The middle gradient uses gamma-encoded sRGB,
1225+ the result is again too dark at the midpoint,
1226+ is a little desaturated, and has a slight purplish cast.
1227+ The upper gradient uses CIE Lab,
1228+ which avoids the too-dark midpoint
1229+ but has a significant purple cast;
1230+ while the lower gradient uses OKLab,
1231+ giving a more perceptually uniform result
1232+ with no purple cast at all.
1233+
1234+ <ul class="lang-css">
1235+ <li><code> linear-gradient(in lab to right, white, #01E)</code></li>
1236+ <li><code> linear-gradient(in srgb to right, white, #01E)</code></li>
1237+ <li><code> linear-gradient(in oklab to right, white, #01E)</code></li>
1238+ </ul>
1239+
1240+ <!-- source: images/rectangular-fff-01e.html-->
1241+ <img src="images/rectangular-fff-01e.png"
1242+ width="360" height="330"
1243+ alt="white to blue gradient in three colorspaces" />
1244+ </div>
1245+
1246+ <div class="example">
1247+ In this example, a linear gradient between the same pair of colors
1248+ #44C and #795 is drawn in three different colorspaces.
1249+ This demonstrates that
1250+ the hue non-linearity of CIE Lab
1251+ affects all bulueish colors,
1252+ not just the gradient from saturated primary blue to white.
1253+ The middle gradient uses gamma-encoded sRGB,
1254+ the result is again too dark at the midpoint,
1255+ and has a slight purplish cast.
1256+ The upper gradient uses CIE Lab,
1257+ which avoids the too-dark midpoint
1258+ but has a significant purple cast;
1259+ while the lower gradient uses OKLab,
1260+ again giving a more perceptually uniform result
1261+ with no purple cast at all.
1262+
1263+ <ul class="lang-css">
1264+ <li><code> linear-gradient(in lab to right, #44C, #795)</code></li>
1265+ <li><code> linear-gradient(in srgb to right, #44C, #795)</code></li>
1266+ <li><code> linear-gradient(in oklab to right, #44C, #795)</code></li>
1267+ </ul>
1268+
1269+ <!-- source: images/rectangular-44c-795.html -->
1270+ <img src="images/rectangular-44c-795.png"
1271+ width="360" height="330"
1272+ alt="blue to green gradient in three colorspaces" />
1273+ </div>
1274+
1275+ Chosing a polar, rather than rectangular, colorspace
1276+ for gradient interpolation
1277+ avoids desaturation
1278+ if the hues of the color stops are far apart.
1279+ Interpolating in a polar colorspaces
1280+ is inherently chroma-preserving,
1281+ although it is easy for the intermediate colors to fall out of gamut;
1282+ they will then be gamut mapped
1283+ to bring them back into gamut.
1284+
1285+ <div class="example">
1286+ In this example, a linear gradient between the same pair of colors
1287+ #A37 and #595 is drawn in five different colorspaces,
1288+ two of them polar.
1289+ From top to bottom:
1290+ CIE LCH, CIE Lab, sRGB, OKLab, OKLCH.
1291+
1292+ The rectangular spaces have a greyish midpoint,
1293+ while the intermediate colors in the polar spaces
1294+ follow a curved, chroma-preserving path.
1295+
1296+ <ul class="lang-css">
1297+ <li><code> linear-gradient(in lch to right, #A37, #595)</code></li>
1298+ <li><code> linear-gradient(in lab to right, #A37, #595)</code></li>
1299+ <li><code> linear-gradient(in srgb to right, #A37, #595)</code></li>
1300+ <li><code> linear-gradient(in oklab to right, #A37, #595)</code></li>
1301+ <li><code> linear-gradient(in oklch to right, #A37, #595)</code></li>
1302+ </ul>
1303+
1304+ <!-- source: images/polar-a37-595.html -->
1305+ <img src="images/polar-a37-595.png"
1306+ width="360" height="538"
1307+ alt="blue to green gradient in three colorspaces" />
1308+ </div>
1309+
11961310<!--
11971311████████ ███ ████████ ████ ███ ██
11981312██ ██ ██ ██ ██ ██ ██ ██ ██ ██
0 commit comments