From df566f145ee289b201cf729e0c36384c97d2d4ae Mon Sep 17 00:00:00 2001 From: facelessuser Date: Sun, 11 Feb 2024 13:41:58 -0700 Subject: [PATCH] Avoid needless two-step color conversion at the start of gamut mapping Fixes #425 --- src/toGamut.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/toGamut.js b/src/toGamut.js index 0ff9a48be..e2637715a 100644 --- a/src/toGamut.js +++ b/src/toGamut.js @@ -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); } @@ -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 @@ -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