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

[FEATURE]: Add "Oklch" colourspace. #1183

Open
dofuuz opened this issue Jul 19, 2023 · 8 comments
Open

[FEATURE]: Add "Oklch" colourspace. #1183

dofuuz opened this issue Jul 19, 2023 · 8 comments

Comments

@dofuuz
Copy link

dofuuz commented Jul 19, 2023

Description

Oklab and Oklch has been added to CSS Color Module Level 4. But, only Oklab is available for Colour.

Adding Oklch will be great for convenience.

@KelSolaar
Copy link
Member

Hi @dofuuz,

There is already an issue for this here: #868

Cheers,

Thomas

@dofuuz
Copy link
Author

dofuuz commented Jul 19, 2023

@KelSolaar Oklch is different from Okhsl or Okhsv. So it's not a duplicate.

@KelSolaar
Copy link
Member

KelSolaar commented Jul 19, 2023

Ah yes sorry, my bad! I misread the space name... We probably won't implement this one because it is a simple polar representation that we can perform on any "Jab" like spaces: https://github.com/colour-science/colour/blob/develop/colour/models/common.py#L163

my_oklch = colour.models.Jab_to_JCh(my_oklab)

@dofuuz
Copy link
Author

dofuuz commented Jul 19, 2023

@KelSolaar
Oh, I didn't know that conversion function exists. I searched for 'lab to lch'. 🤣

Anyway, providing 'Oklch' would be nice for convenience.
I'll leave the decision to the contributors.

@KelSolaar
Copy link
Member

This is a good discussion. If we do it for Oklab or JzAzBz, we might as well do it for IPT, ICtCp, ICaCb, ProLab, etc... we have so much opponent-based spaces that it becomes quite a maintenance burden as we ideally need to write tests, docs, etc.., this is why I rolled the colour.models.Jab_to_JCh and its inverse definitions.

@tjdcs
Copy link
Contributor

tjdcs commented Jul 19, 2023

i agree that there is value in doing this. But I wonder if it can be done by decoration with a "metaclass" or some other meta programming. (please forgive the reference to a very specific C++ concept in a much more general meaning)

@KelSolaar KelSolaar changed the title [FEATURE]: Add Oklch colourspace [FEATURE]: Add "Oklch" colourspace. Jul 19, 2023
@KelSolaar
Copy link
Member

Something along those lines would work for example but it gets close to a steam factory rapidly:

import colour
import sys
from colour.models import Jab_to_JCh, JCh_to_Jab
from colour.utilities import copy_definition

__all__ = []

CALLABLES_LCH = {
    "Oklab_to_Oklch": (Jab_to_JCh, "The docstring..."),
    "Oklch_to_Oklab": (JCh_to_Jab, "The docstring..."),
}

for name, (callable_, docstring) in CALLABLES_LCH.items():
    callable_.__doc__ = docstring
    _module = sys.modules["colour.models"]
    setattr(_module, name, copy_definition(callable_, name))

print(colour.models.JCh_to_Jab)
print(colour.models.JCh_to_Jab.__name__)

print(colour.models.Oklch_to_Oklab)
print(colour.models.Oklch_to_Oklab.__name__)
<function JCh_to_Jab at 0x13c204220>
JCh_to_Jab
<function JCh_to_Jab at 0x11ce60680>
Oklch_to_Oklab

We have something magic like that here actually: https://github.com/colour-science/colour-datasets/blob/develop/colour_datasets/loaders/kuopio.py#L498

@tjdcs
Copy link
Contributor

tjdcs commented Jul 19, 2023

I think there is something you could do in the oklab module to automatically define the variable names too. Something like

add_polar_conversion_this_module("Oklab", "Oklch")

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

No branches or pull requests

3 participants