From b6bf6e24e9fadf4dd0cb63ed0e39a42f6745189f Mon Sep 17 00:00:00 2001 From: James Stuckey Weber Date: Wed, 14 Feb 2024 11:48:00 -0500 Subject: [PATCH 1/6] Add scale lh2 method --- apps/gamut-mapping/index.html | 2 +- apps/gamut-mapping/methods.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/apps/gamut-mapping/index.html b/apps/gamut-mapping/index.html index 4a169a50a..d5e6765af 100644 --- a/apps/gamut-mapping/index.html +++ b/apps/gamut-mapping/index.html @@ -59,7 +59,7 @@

Gamut mapped

-
+
Δ{{ c }}
{ + if (color.inGamut("p3")) { + return color.to("p3"); + } + let [lightness] = color.to("oklch").coords; + if (lightness >= 1) { + return new Color({ space: "xyz-d65", coords: WHITES["D65"] }).to("p3"); + } + else if (lightness <= 0) { + return new Color({ space: "xyz-d65", coords: [0, 0, 0] }).to("p3"); + } + let mappedColor = methods.scale.compute(color); + let lch = color.to("oklch").coords; + mappedColor.set({ + "oklch.l": lch[0], + "oklch.h": lch[2] + }); + // Do not early return if in-gamut already at this point. + // The second scale step gets the color closer to the original. + mappedColor = methods.scale.compute(mappedColor); + if (mappedColor.inGamut("p3")) { + return mappedColor; + } + // Are we mathematically guaranteed to be in gamut at this point? + // If not, would a clip suffice? + return mappedColor; + + } + }, "scale": { label: "Scale", description: "Using a midpoint of 0.5, scale the color to fit within the linear P3 gamut.", From d932bbb5a307f55b0590c0e2a5fd94a6d7e5a1a3 Mon Sep 17 00:00:00 2001 From: James Stuckey Weber Date: Mon, 19 Feb 2024 11:59:32 -0500 Subject: [PATCH 2/6] Show deltas for in gamut colors --- apps/gamut-mapping/map-color.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/gamut-mapping/map-color.js b/apps/gamut-mapping/map-color.js index eeae25607..cc56918c0 100644 --- a/apps/gamut-mapping/map-color.js +++ b/apps/gamut-mapping/map-color.js @@ -180,7 +180,7 @@ export default {
-
+
Δ{{ c }}
Date: Tue, 27 Feb 2024 15:20:55 -0500 Subject: [PATCH 4/6] Separate out delta display --- apps/gamut-mapping/map-color.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/gamut-mapping/map-color.js b/apps/gamut-mapping/map-color.js index cc56918c0..eeae25607 100644 --- a/apps/gamut-mapping/map-color.js +++ b/apps/gamut-mapping/map-color.js @@ -180,7 +180,7 @@ export default {
-
+
Δ{{ c }}
{ - let mappedColor = methods.scale.compute(color); - let lch = color.to("oklch").coords; - mappedColor.set({ - "oklch.l": lch[0], - "oklch.h": lch[2], - }); - return methods.scale.compute(mappedColor); - }, - }, - "scale-lh2": { - label: "Scale LH 2", - description: "Identical to Scale LH 2, and handles L=0/1, and noop if already in gamut.", - compute: (color) => { - if (color.inGamut("p3")) { + if (color.inGamut("p3", { epsilon: 0 })) { return color.to("p3"); } let [lightness] = color.to("oklch").coords; @@ -52,16 +39,7 @@ const methods = { "oklch.l": lch[0], "oklch.h": lch[2], }); - // Do not early return if in-gamut already at this point. - // The second scale step gets the color closer to the original. - mappedColor = methods.scale.compute(mappedColor); - if (mappedColor.inGamut("p3")) { - return mappedColor; - } - // Are we mathematically guaranteed to be in gamut at this point? - // If not, would a clip suffice? - return mappedColor; - + return methods.scale.compute(mappedColor); }, }, "scale": { From 8bdeb25aa272f81916f08cdaeb0a7a0550155b32 Mon Sep 17 00:00:00 2001 From: James Stuckey Weber Date: Thu, 29 Feb 2024 17:06:16 -0500 Subject: [PATCH 6/6] Remove white/black, conversion --- apps/gamut-mapping/methods.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/apps/gamut-mapping/methods.js b/apps/gamut-mapping/methods.js index 7dcc75fd3..519e37e44 100644 --- a/apps/gamut-mapping/methods.js +++ b/apps/gamut-mapping/methods.js @@ -24,14 +24,7 @@ const methods = { description: "Runs Scale, sets L, H to those of the original color, then runs Scale again.", compute: (color) => { if (color.inGamut("p3", { epsilon: 0 })) { - return color.to("p3"); - } - let [lightness] = color.to("oklch").coords; - if (lightness >= 1) { - return new Color({ space: "xyz-d65", coords: WHITES["D65"] }).to("p3"); - } - else if (lightness <= 0) { - return new Color({ space: "xyz-d65", coords: [0, 0, 0] }).to("p3"); + return color; } let mappedColor = methods.scale.compute(color); let lch = color.to("oklch").coords;