Ogeon / palette

A Rust library for linear color calculations and conversion
Apache License 2.0
751 stars 60 forks source link

Add Okhsv, Okhsl and Okhwb color spaces #258

Closed Ogeon closed 1 year ago

Ogeon commented 3 years ago

Description

Björn Ottosson has published more perceptually even alternatives to HSV and HSL, as described in https://bottosson.github.io/posts/colorpicker/. The conversion from other color spaces would be based on the already supported Oklab.

Motivation

Given the shortcomings of HSL, HSV and HWB, it would be nice to be able to offer some more alternatives. Not only for color pickers but also for applications like generative art, where HSLuv is already used for the same reasons, or other situations where a human isn't picking the colors.

NeverGivinUp commented 2 years ago

In my understanding the implementation of the RelativeContrast trait currently is based on the Xyz color space. Ottoson's blog post however defines an OKLab-specific lightness estimate. This would be a breaking change, as it would change the results -- all results, not just edge cases, though the 50% lightness is very similar. However it would be a worthy breaking change.

Ogeon commented 2 years ago

That's right, the trait has a very generic name but a specific meaning. I have been trying to iron out similar cases recently and I'm definitely prepared to break a few eggs to clarify what is what. I don't have a concrete plan in this case but probably by renaming the trait to something more specific, to open up for alternative definitions. I would like to have things that are based on a specification named in a way that communicates which specification it is.

NeverGivinUp commented 2 years ago

I'v added OKhsv and Okhsl and updated the XYZ<->OKlab matrices in this fork.

I don't know how to really integrate the new color spaces though with the palette macro. Also two tests fail and there are a couple of TODOs that are beyond me. Also I'v not done anything about the RelativeContrast yet.

Would you mind taking a look @Ogeon? I'v invited you, so you can directly push to the repository.

Ogeon commented 2 years ago

Nice! I will have a proper look when I'm off work but feel free to open a work in progress pull request in the meantime. It makes it easy to review and comment, and also runs the tests.