facelessuser / coloraide

A library to aid in using colors
https://facelessuser.github.io/coloraide
MIT License
195 stars 12 forks source link

Bugfix/achroma #296

Closed facelessuser closed 1 year ago

facelessuser commented 1 year ago

This issue kind of led me on a number of tangents, but achromatic handling has been reworked. This fixes #288 and handles achromatic colors in CAM16 (and friends) and HCT much better. The accuracy at which we can detect achromatic colors in CAM16 isn't quite as nice as I'd like, but it is much better and gives more sane results.

Undefined values for chroma, hue, and Lab a/b values may not always be zero. For all CSS spaces and most spaces for that matter, zero will be returned for undefined values. There are a few that have dynamic achromatic responses: CAM16 spaces, HCT, Jzazbz, and JzCzhz, and three are some other Lab spaces that just do not yield chroma == 0 for achromatic colors due to a lower level of accuracy (IPT and IgPgTg). For spaces that require it, we will recognize and replace undefined channels with achromatic values that make sense. This is to ensure good interpolation in these spaces.

Additionally, recent changes allow us to fix #269 and ACEScct will now return the achromatic value for black when undefined as zero is out of gamut for that color space.

We fixed some IPT and IgPgTg alias issues, we added ways to get undefined values as defined values via get, set. We added coords and alpha to get just color coordinates or the alpha value. We update normalize to allow specifying whether achromatic normalization is desired. To speed things up internally, we now allow update and convert to turn off achromatic normalization via norm=False. We added a new way to check if any color is achromatic via is_achromatic()., this changed a number of things in the Space pluign.


Lastly, the unrelated tangents.

Many functions like interpolation and such used to "magically" return colors in the same space as the first color input. Personally, I think this is a little unintuitive. Especially when you are interpolating lots of colors. To make things simple and easier to understand, we now return colors in the working color space. out_space can still be used to force output in a particular color space. Functions that did not support out_space that need it now support it.

We match browsers now and allow compose to apply separable blend modes in any RGB space provided, but we now error out if a non RGBish space is used.

We now create all RGBish spaces with an RGBish class. Additionally, we have HSVish and HSLish classes now.

Interpolation used to force gamut mapping on HSL/HSV/HWB, but they can technically interpolate in wide gamuts, they suck in HDR ranges. We no longer force gamut mapping, that is on the user to do.

Lastly, we improved Oklab/OkLCh/Okhsl/Okhsv conversions. A new higher precision Oklab matrix is used. Achromatic colors will now have near 0 chroma and Okhsl colors will have tighter conversions.

Fixes #288 Fixes #269

facelessuser commented 1 year ago

@gir-bot lgtm