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:
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.
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.