Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping to OKLab and back significantly changes the color. #41

Open
gcr opened this issue Jun 18, 2024 · 2 comments
Open

Mapping to OKLab and back significantly changes the color. #41

gcr opened this issue Jun 18, 2024 · 2 comments

Comments

@gcr
Copy link

gcr commented Jun 18, 2024

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 blue -> #1A89CC blue
#B543B5 blue -> #E9A8E6 blue
#DBCA21 blue -> #F1EF99 blue
#28B837 blue -> #9CE9A0 blue
#E254E2 blue -> #FBB5F8 blue
#5103BC blue -> #B06BF8 blue
#3F51B2 blue -> #A0B0E7 blue
#DB26C5 blue -> #0196EF blue
#B44D3E blue -> #EAAEA1 blue
#803A22 blue -> #D09E86 blue

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.

@gcr
Copy link
Author

gcr commented Jun 18, 2024

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 blue -> #42B5DE blue
#F85C71 blue -> #F85C71 blue
#249550 blue -> #249550 blue
#B75EE3 blue -> #B75EE3 blue
#FBE114 blue -> #FBE114 blue
#1D31AC blue -> #1D31AC blue
#707F97 blue -> #707F97 blue
#B05B48 blue -> #B05B48 blue
#97BD88 blue -> #97BD88 blue
#6C5BD9 blue -> #6C5BD9 blue

@charles-esterbrook
Copy link

You can point nimble to a commit, such as the most recent:

# foo.nimble
# ...
requires "chroma#c19d5d9545164aa1e29c5d8ed82e1dec500b719a"

HTH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants