Skip to content
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

Switch to husl colours? #2492

Closed
matthijsmelissen opened this issue Dec 5, 2016 · 8 comments
Closed

Switch to husl colours? #2492

matthijsmelissen opened this issue Dec 5, 2016 · 8 comments

Comments

@matthijsmelissen
Copy link
Collaborator

Our colours are defined in rgb, with sometimes annotations in Lch.

CartoCSS now supports the husl colour space, but not the Lch colour space. Should we switch to husl?

@nebulon42
Copy link
Contributor

I'm going to let others comment first because I'm a bit biased here.

Just to explain why LCh is not directly supported by CartoCSS: All colours have to be converted to RGB for Mapnik in the end. Therefore, working with colours that possibly can have a gamut outside of RGB is a bit tedious. The best example for that is the road colour generation script. If you play with the colours there you frequently run into the "outside of RGB" error and have to start again.

@imagico
Copy link
Collaborator

imagico commented Dec 5, 2016

IMO colors should normally be developed in a perceptually uniform color space. Lch as a polar coordinate version of Lab qualifies as such, husl as far as i see it does not. For rendering specifying colors in something other than 3x8 bit sRGB (that is the usual hex color notation) has little added value unless the rendering engine processes colors with more than 8 bit accuracy or in other color spaces which AFAIK mapnik does not.

If there is a decent online converter that allows easy conversion including husl (i mostly use http://davidjohnstone.net/pages/lch-lab-colour-gradient-picker) i would not have any problem with colors specified in husl myself but it probably would create an additional entry barrier for contributors. As @nebulon42 explained in #2462 the advantage to have non-distorting lightenp() and darkenp() functions is also available if you specify colors in sRGB - i am still sceptical about doing mix() or other functions performing color interpolation between different chromas (like in the road color script) in husl with its fairly arbitrary non-linear 'chroma' stretching. To be frank i get that carto wants to offer husl to the user for specifying colors but i see no good reason why not also offer Lch and possibly other color spaces and why not performing color functions by default in Lab.

Is there a precise mathematical definition of husl somewhere by the way? Looking at https://github.com/husl-colors/husl-python/blob/master/husl.py the core of the definition seems to be the function max_chroma_for_LH() which seems to sample the edge of the sRGB color space is some way to determine the maximum chroma. But as far as i can see this is an approximative method. This does not really appear that trustworthy as an universal and precise definition.

@nebulon42
Copy link
Contributor

@imagico I'm open to other colour spaces in carto. So I invite you to open a ticket there and let's discuss the details further. I'm especially interested how you want to spare users a trial-and-error process and how you would handle edge cases - colour clipping?

@pnorman
Copy link
Collaborator

pnorman commented Dec 6, 2016

👎 to using hsul, 👍 to using a perceptual colour space.

For mixing colours you should use Lab, for defining them,, use Lch. Interpolations can be in either depending on needs. If you can't do that (as we can't right now), then use hex values and don't try to read any meaning into what the RGB values mean or do calculations with them.

CartoCSS had mapbox/carto#354 about supporting perceptual colour spaces, but was closed without implementing any.

@nebulon42
Copy link
Contributor

nebulon42 commented Dec 6, 2016

IMO Husl is still a perceptual colour space. Regarding the math, maybe @boronine has some insight?
I have reopened the carto issue. I welcome pull requests!! (Don't expect me to implement it for you.)

@matthijsmelissen
Copy link
Collaborator Author

Closing the issue here as nothing can be done on our side currently.

@nebulon42
Copy link
Contributor

@math1985 Is the question whether to switch to husl or not already answered for you?

@imagico
Copy link
Collaborator

imagico commented Dec 6, 2016

Perceptually uniform color space means differences between colors as measured in the color space in question are proportional to humanly perceived differences between those colors. This is not the case with husl obviously since it is scaled in chroma based on the sRGB limits which have no physical or physiological basis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants