ajalt / colormath

Multiplatform Kotlin color conversion and manipulation
https://ajalt.github.io/colormath/
MIT License
308 stars 21 forks source link

OKLCH to sRGB produces negative red value #39

Closed sebj closed 1 year ago

sebj commented 1 year ago

Creating the following OKLCH color then converting it to sRGB produces a negative red value, which is then considered invalid at the point of use in UI:

Oklch(l=0.6654f, c=0.18875f, h=220.0f, alpha=1.0f).toSRGB()RGB(r=-1.8260071, g=0.6672399, b=0.888032, alpha=1.0, space=sRGB).

As far as I can see, this is something to do with the fact that the red value would otherwise be clipped in this conversion. Is there a more elegant way this could be handled whilst still producing a valid sRGB color?

For context, we're defining a color palette using OKLCH in a Kotlin Multiplatform module, and then converting to sRGB for Android Jetpack Compose and Display P3 for iOS (SwiftUI) at the moment.

sebj commented 1 year ago

I think this is our problem, not this library's!