omgovich / colord

👑 A tiny yet powerful tool for high-performance color manipulations and conversions
https://colord.omgovich.ru
MIT License
1.67k stars 50 forks source link

I get wrong color output when input color is LCH #103

Open saadeghi opened 1 year ago

saadeghi commented 1 year ago

When I give an LCH color to the function, I get a different color in the output.
For example this is my color: lch(58.68% 98.6 352.06) (which is a valid P3 color)

And using toLchString I expect the same values:

colord('lch(58.68% 98.6 352.06)').toLchString()

But the result is:

lch(56.75% 87.94 348.82)

Here's a live example: https://svelte.dev/repl/14e79bf716994c98956d6b27ae0065a5?version=3.58.0

typhonrt commented 1 year ago

I can at least comment and provide some insight. As things go the intermediary format internal to colord is RGBA. Even using the various other format methods everything passes through RGBA internally and won't maintain precision for anything beyond the sRGB color space. There are also rounding / precision aspects elsewhere in the code.

I really like the colord API and structure, but it does lack in precise control.

For precise control colorjs / https://colorjs.io/ is a fair candidate though the API and general structure is less than to be desired.

In an ideal world a solution that combines the API structure of colord w/ the data & format handling of colorjs would be ideal.

typhonrt commented 1 year ago

@saadeghi; Just for curiosities sake since you mentioned Svelte I am using a slightly modified version of colord (correct a precision aspect) for a high powered Svelte color picker component; (initial dev snapshot video). Also uses container queries and I implemented the fixes / support in Svelte 3.58.0 to make that so.

You can see the code for that here which shows that colord is adequate for a sRGB color space / picker; still required some work arounds. Internally the picker works w/ HSV. Code here: https://github.com/typhonjs-fvtt-lib/svelte-standard/tree/main/src/component/standard/color/picker-colord