Skip to content

Commit

Permalink
Avoid needless two-step color conversion at the start of gamut mapping
Browse files Browse the repository at this point in the history
Fixes #425
  • Loading branch information
facelessuser committed Feb 11, 2024
1 parent decf024 commit df566f1
Showing 1 changed file with 5 additions and 2 deletions.
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

0 comments on commit df566f1

Please sign in to comment.