-
Notifications
You must be signed in to change notification settings - Fork 30
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
using clampChroma
within a conversion sequence results in invalid values
#129
Comments
Thanks for the report @Enteleform! The clamped RGB color is expected to have at least one of its channels very close to the range boundary, and in this case it seems a small conversion error is causing it to go very slightly under 0.
In this case, however, the crux of the problem seems to be that the result of let lchColor = culori.lch({mode:'oklch', l:0.5, c:0.161, h:180});
let clamped = culori.clampChroma(lchColor);
culori.displayable(clamped); // => false ...which is odd. I'll take a look to see what's going on. |
So, the |
@danburzo Awesome, thanks for the quick fix! |
@danburzo Hey I think I might have found some more issues with the chroma clamping. Video Demonstration:I wrote a small wrapper for culori that uses unit intervals [0-1] for [ If I do narrow the issue down to something within culori, I'd be open to setting up a screen sharing session with you if you think it might lead to any insights or want to check out any of the generated data. This is the function I'm calling in the demo: Color.Range({
count,
color: {h:(hue/100), c:(chroma/100), l:0},
result: "Hex6",
modify: {
l: {ease:"Linear", range:{from:(min/100), to:(max/100)}},
},
}) The
|
Ok; I rewrote what I was doing in the previous demo in its most basic form, using only native culori functions. The issues are still apparent, and are actually more pronounced in other color spaces. Also, the FindingsMy initial test on the
[ // {x:0.0}
{l:0.13, c:0.05, h:29.22 }, // #170000
{l:0.07, c:0.03, h:0.67 }, // #040001
{l:0.17, c:0.07, h:1.14 }, // #25000E
{l:0.28, c:0.11, h:0.73 }, // #4F0025
{l:0.38, c:0.15, h:0.39 }, // #7D003F
{l:0.49, c:0.2, h:0.22 }, // #AE005A
{l:0.59, c:0.24, h:0.11 }, // #E20077
{l:0.69, c:0.22, h:0.11 }, // #FF4D95
{l:0.78, c:0.14, h:0.16 }, // #FF8FB3
{l:0.87, c:0.07, h:0.16 }, // #FFC2D3
{l:0.97, c:0.02, h:359.89}, // #FFF0F3
] I then decided to write a more exhaustive test for all of the cyclic color spaces, of which I took some snapshots while increasing the chroma value to see if it revealed any relationships/patterns in the issue. I also exceeded the valid range of colors Below are some animations I put together with the snapshots, both within valid range & exceeding valid range. The only animation with a linear
|
Wow, thank you for the detailed troubleshooting! I'll look carefully into the data tomorrow morning to get to the root(s) of the issues. In the meantime I have started to make some changes in this PR:
|
Awesome, I'll try out the changes when I get a chance. Currently building out my testing sandbox a bit. Made it a bit more dynamic by exposing all of the relevant variables as Storybook controls, generalized the conversion process to allow testing of arbitrary libraries, and added some options to manipulate the layout to get different perspectives. Still got a bit of work to do, but here are a few screenshots of its current state. Don't really have a proper git/hosting/sharing workflow down yet, but lmk if you're interested in getting any particular state/data captures we can either do a screen share or I can maybe figure out the best way to share a functioning version. (I'm kinda mid-process of building out a personal stack, part of which is dynamic theming - thus the quest for perceptually uniform color generation. New to Svelte/Vite/Storybook/Tailwind/etc., so everything is only partially set up.) |
I'm currently working through the data you provided. The color table you provided with This converts the colors to When doing Now, a remaining problem in both tables is the row corresponding to the OKLCh Lightness = 1. This is due to a quirk/side-effect in OKLab, in that sRGB white has |
@danburzo Just getting started for the day, down to chat if you're available. Email me @ [email protected] if you want to exchange info & get something set up on Discord/Slack/Zoom/etc. |
I've wrote an interactive notebook to explore oklch.mp4(As mentioned in a previous comment, the chroma-clamping algorithm is not necessarily the best from a perceptual point of view) When the color's space and the chroma-finding space are different, we see a bunch of chromatic aberrations — probably due to the intermediary |
The color aberrations should be improved with the latest changes on |
Looks good, definite improvement! I am getting some deviation at the very end of the high-L range of a few spaces, but I only applied the more precise Could you provide the non-truncated values for all spaces? Might be handy for some users to have access to them via culorijs.org/color-spaces. Maybe via a It turns out that the Also, I'm still wondering:
|
The ranges are available programatically with
Oops, good catch! That's a typo.
culori.clampChroma(color, color.c !== undefined ? color.mode : 'lch'); Without the second argument,
Technically, when |
Those seem to match up with the values I had already entered from the docs. However, Other than that; I figured that maybe there was some discrepancy between what I thought were truncated values VS some more precise values that were actually in the code, which was potentially causing this issue: |
The ranges in the definition files / color-spaces page were a bit neglected because they were mostly informative. I've redone some computation and updated docs/definition files accordingly in: b3af2b5 As the code stands right now on |
Oh nice, that resolved a weird issue I was having with the Now all the colorspaces are perfectly lined up in the sandbox 😁👍 |
Issue
Using
clampChroma
within a conversion sequence results in a color object with invalid values.Expected
Post-
clampChroma
conversions result in color objects with valid values as defined by culorijs.org/color-spaces.Example
Result
oklch
>clampChroma
>rgb
r
has a negative value, which is outside of thergb
color-space's documented{min:0, max:1}
range.Other Values
oklch
oklch
>clampChroma
oklch
>rgb
The text was updated successfully, but these errors were encountered: