Mapping to OKLab and back significantly changes the color.
hii!
i'm struggling to use this library for some image processing and palette mapping tasks. I've found that transforming to oklab and back significantly brightens and desaturates colors.
import chroma
echo parseHex("F8DB57").to(ColorOklab).to(ColorRGB).color.toHex()
# output: FCF4BA
Color #F8DB57 turns into #FCF4BA.
Here's some assorted roundtrips:
import chroma
import random
import strformat
proc chip(c: ColorRGB): string =
## nice-looking color chip for github-flavored markdown
let hex = c.color.toHex()
fmt"`#{hex}` <img valign='middle' alt='blue' src='https://readme-swatches.vercel.app/{hex}'/>"
randomize()
for _ in 1..10:
let color = ColorRGB(
r: random.rand(255).uint8,
g: random.rand(255).uint8,
b: random.rand(255).uint8,
)
let color2 = color.to(ColorOklab).to(ColorRGB)
echo fmt"{color.chip} -> {color2.chip}"
Output:
#FF1580 ->
#1A89CC
#B543B5 ->
#E9A8E6
#DBCA21 ->
#F1EF99
#28B837 ->
#9CE9A0
#E254E2 ->
#FBB5F8
#5103BC ->
#B06BF8
#3F51B2 ->
#A0B0E7
#DB26C5 ->
#0196EF
#B44D3E ->
#EAAEA1
#803A22 ->
#D09E86
Each pair of colors should be identical (before converting to OkLab and after). But for many of these pairs, even the hue is wildly off.
Nevermind - this is fixed at HEAD. I resolved this in my project temporarily by cloning this repository and running nimble install from the root folder.
Once #42 is fixed, this will be too.
Roundtrips at HEAD look good:
#42B5DE ->
#42B5DE
#F85C71 ->
#F85C71
#249550 ->
#249550
#B75EE3 ->
#B75EE3
#FBE114 ->
#FBE114
#1D31AC ->
#1D31AC
#707F97 ->
#707F97
#B05B48 ->
#B05B48
#97BD88 ->
#97BD88
#6C5BD9 ->
#6C5BD9
You can point nimble to a commit, such as the most recent:
# foo.nimble
# ...
requires "chroma#c19d5d9545164aa1e29c5d8ed82e1dec500b719a"
HTH
I think this was fixed with: https://github.com/treeform/chroma/pull/39
Feel free to reopen if its still an issue.