Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions gamut-mapping/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ const MAX_CHROMA = 0.4;
// result is still out of gamut. A method that returns an out-of-gamut color
// implicitly consents to this clip; it keeps the reported deltas honest, since
// they're measured against the color the browser can actually display rather
// than an out-of-gamut value the swatch would silently clip.
// than an out-of-gamut value the swatch would silently clip. Additionally,
// ensure all colors are normalized such that the return space matches the input space.
function normalize (compute) {
return (color) => {
let space = color.space;
let input = color.to("oklch").set({ c: c => Math.min(c, MAX_CHROMA) });
let result = compute(input);
let result = compute(input).to(space);
return result.inGamut("p3") ? result : clipToGamut(result);
};
}
Expand Down
7 changes: 7 additions & 0 deletions gamut-mapping/methods/oklch-cubic.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ export function compute (color) {
color = color.to("oklch");
let [L, C, H] = color.coords;

if (L >= 1) {
return new Color({ space: "oklch", coords: [1, 0, 0] });
}
else if (L <= 0) {
return new Color({ space: "oklch", coords: [0, 0, 0] });
}

Comment thread
facelessuser marked this conversation as resolved.
// Achromatic (or NaN chroma) is always in gamut: nothing to reduce.
if (!(C > 0)) {
return color;
Expand Down