Skip to content

Commit

Permalink
Rename chromium to baked in, clip to rec2020, return if in gamut
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnw committed Mar 14, 2024
1 parent c8a9060 commit 7a93af8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/gamut-mapping/gradients.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let app = createApp({
const urlToColor = params.get("to");
const from = urlFromColor || "oklch(90% .8 250)";
const to = urlToColor || "oklch(40% .1 20)";
const methods = ["none", "clip", "scale-lh", "css", "raytrace", "edge-seeker", "chromium"];
const methods = ["none", "clip", "scale-lh", "css", "raytrace", "edge-seeker", "baked-in"];
const runResults = {};
methods.forEach(method => runResults[method] = []);
return {
Expand Down
16 changes: 12 additions & 4 deletions apps/gamut-mapping/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ const methods = {
return new Color("p3-linear", scaledCoords).to("p3");
},
},
"chromium": {
label: "Chromium",
description: "A port of the Chromium implementation",
"baked-in": {
label: "Baked in",
description: "A port of the Chromium implementation, mapping to an approximation of the rec2020 gamut.",
compute: (color) => {
// Implementation difference: The reference algorithm does not appear to
// return early for in-gamut colors.
if (color.inGamut("rec2020")) {
return color;
}
const oklab = color.to("oklab");
const [l, a, b] = oklab.coords;
// Constants for the normal vector of the plane formed by white, black, and
Expand Down Expand Up @@ -167,7 +172,10 @@ const methods = {
}

// Attenuate the ab coordinate by alpha.
return oklab.set({a: alpha * a, b: alpha * b});
return oklab.set({a: alpha * a, b: alpha * b})
// Implementation difference: The reference algorithm does not include a
// final clip, so some colors may be outside of `rec2020`.
.toGamut({method: "clip", space: "rec2020"});
},
},
"raytrace": {
Expand Down

0 comments on commit 7a93af8

Please sign in to comment.