Mischback / colorizer

A simple web-based colorscheme builder which focuses on contrast values.
https://mischback.github.io/colorizer/
MIT License
1 stars 0 forks source link

``CIE XYZ`` to ``OkLCH`` conversion #36

Open Mischback opened 1 year ago

Mischback commented 1 year ago

While playing around with the color-form, it appears that a RGB input of 255, 0, 0 is not a pure red in OkLCH (visually).

evilmartians' converter returns oklch(62.8% 0.25768330773615683 29.2338851923426).

Potential Problem

Our implementation assumes that the value range of C is [0..1]. The value of the conversion function https://github.com/Mischback/colorizer/blob/4d13b7ff3938e55b15fa332086589fd704522a5b/src/script/utility/color-processing.ts#L213

is then converted to a percent-based value https://github.com/Mischback/colorizer/blob/4d13b7ff3938e55b15fa332086589fd704522a5b/src/script/colorizer/interface/color-form/input-methods.ts#L564 which is plainly WRONG, as W3C CSS Color Module 4 explicitly states, that the range for the C component is 0% = 0; 100% = 0.4.

Additionally, in the conversion function, hue is calculated like this: const hue = (Math.atan2(oklab.b, oklab.a) * 180) / Math.PI;, while the implementation source has const hue = Math.atan2(oklab.b, oklab.a) * 180 / Math.PI;. I'm humble enough to state that I'm not sure about the brackets here! Needs verification!

Possible Fix

Change input-methods.ts#L564 to either

This should be documented in all OkLCH-related functions!