-
-
Notifications
You must be signed in to change notification settings - Fork 91
[Gamut mapping app] Scale LH improvements #438
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
b6bf6e2
effeb3c
1daffd0
19179bb
d932bbb
2bdee07
dc66988
03f71f5
1317647
86a31d4
8bdeb25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import Color from "../../dist/color.js"; | ||
| import { WHITES } from "../../src/adapt.js"; | ||
|
|
||
| const methods = { | ||
| "clip": { | ||
|
|
@@ -22,6 +23,38 @@ const methods = { | |
| 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.", | ||
|
jamesnw marked this conversation as resolved.
Outdated
|
||
| compute: (color) => { | ||
| if (color.inGamut("p3")) { | ||
| return color.to("p3"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not simply
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did this to match what was happening in the (Perhaps the results from all methods should be serialized in a single format- currently some are oklch, and some are p3, making them harder to compare, but that's somewhat orthogonal to the question of whether the Scale LH method should return in a consistent space). |
||
| } | ||
| 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.", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.