CaptainCodeman / svelte-color-select

Okhsv color select for Svelte
https://captaincodeman.github.io/svelte-color-select/
Other
29 stars 1 forks source link

Clamp RGB to sRGB gamut #10

Closed drwpow closed 2 weeks ago

drwpow commented 1 year ago

Changes

Fixes #9. Clamps colors to the RGB range.

CleanShot 2023-09-03 at 16 01 06

Worth noting that this is the “bad” way to clamp; Björn Ottosen outlines keeping hue consistent and clamping lightness and chroma, which culori has implemented in their clampChroma(… 'oklch') method. I instead took the lazier approach of just clamping to (0, 1) as a first pass.

Culori’s clampRGB() function also takes the same lazy approach, but loads a bunch of converter methods for a total of 3.6 kB for what ends up being the same end result.

Alternative method

The alternate way of doing it the “right” way has a couple caveats:

But if the alternate method is preferred, it’s an easy swap

Reviewing