gravitystorm / openstreetmap-carto

A general-purpose OpenStreetMap mapnik style, in CartoCSS
Other
1.54k stars 823 forks source link

Switch to husl colours? #2492

Closed matthijsmelissen closed 7 years ago

matthijsmelissen commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

👎 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 commented 7 years ago

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 commented 7 years ago

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

nebulon42 commented 7 years ago

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

imagico commented 7 years ago

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.