Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid needless two-step color conversion at the start of gamut mapping #426

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/toGamut.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default function toGamut (
// space: space whose gamut we are mapping to
// mapSpace: space with the coord we're reducing

let spaceColor = to(color, space);
let spaceColor;
if (method === "css") {
spaceColor = to(toGamutCSS(color, { space }), color.space);
}
Expand All @@ -109,7 +109,7 @@ export default function toGamut (
}
}

let clipped = toGamut(clone(spaceColor), { method: "clip", space });
let clipped = toGamut(to(color, space), { method: "clip", space });
if (de(color, clipped) > jnd) {

// Clamp to SDR white and black if required
Expand Down Expand Up @@ -166,6 +166,9 @@ export default function toGamut (
spaceColor = clipped;
}
}
else {
spaceColor = to(color, space);
}

if (method === "clip" // Dumb coord clipping
// finish off smarter gamut mapping with clip to get rid of ε, see #17
Expand Down