Skip to content

Commit

Permalink
Implement support for RGB colourspace model and keywords argument p…
Browse files Browse the repository at this point in the history
…assing to the `colour.convert` definition.
  • Loading branch information
KelSolaar committed Oct 25, 2023
1 parent 6787559 commit 31a2fe3
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 11 deletions.
29 changes: 21 additions & 8 deletions colour_visuals/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

from __future__ import annotations

import numpy as np
import re

import numpy as np
from colour.graph import convert
from colour.hints import (
ArrayLike,
Expand All @@ -21,7 +22,6 @@
from colour.models import (
XYZ_to_ICtCp,
XYZ_to_Jzazbz,
XYZ_to_OSA_UCS,
)
from colour.utilities import full

Expand Down Expand Up @@ -53,6 +53,7 @@ def XYZ_to_colourspace_model(
XYZ: ArrayLike,
illuminant: ArrayLike,
model: LiteralColourspaceModel | str = "CIE xyY",
normalise_model: bool = True,
**kwargs,
) -> NDArray:
"""
Expand All @@ -69,6 +70,19 @@ def XYZ_to_colourspace_model(
model
Colourspace model, see :attr:`colour.COLOURSPACE_MODELS` attribute for
the list of supported colourspace models.
normalise_model
Whether to normalise colourspace models such as :math:`IC_TC_P` and
:math:`J_za_zb_z`.
Other Parameters
----------------
kwargs
See the documentation of the supported conversion definitions.
Returns
-------
Any
Converted *CIE XYZ* tristimulus values.
"""

ijk = convert(
Expand All @@ -80,12 +94,11 @@ def XYZ_to_colourspace_model(
**kwargs,
)

if model == "ICtCp":
ijk /= XYZ_to_ICtCp([1, 1, 1])[0]
elif model == "JzAzBz":
ijk /= XYZ_to_Jzazbz([1, 1, 1])[0]
elif model == "OSA UCS":
ijk /= XYZ_to_OSA_UCS([1, 1, 1])[0]
if normalise_model:
if model == "ICtCp":
ijk /= XYZ_to_ICtCp([1, 1, 1])[0]
elif model == "JzAzBz":
ijk /= XYZ_to_Jzazbz([1, 1, 1])[0]

return ijk

Expand Down
8 changes: 7 additions & 1 deletion colour_visuals/diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ class VisualSpectralLocus3D(gfx.Line):
thickness
Thickness of the visual lines.
Other Parameters
----------------
kwargs
See the documentation of the supported conversion definitions.
Examples
--------
>>> import os
Expand Down Expand Up @@ -323,6 +328,7 @@ def __init__(
colours: ArrayLike | None = None,
opacity: float = 1,
thickness: float = 1,
**kwargs,
):
super().__init__()

Expand All @@ -334,7 +340,7 @@ def __init__(

positions = colourspace_model_axis_reorder(
XYZ_to_colourspace_model(
cmfs.values, colourspace.whitepoint, model
cmfs.values, colourspace.whitepoint, model, **kwargs
),
model,
)
Expand Down
7 changes: 7 additions & 0 deletions colour_visuals/pointer_gamut.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ class VisualPointerGamut3D(gfx.Line):
thickness
Thickness of the visual lines.
Other Parameters
----------------
kwargs
See the documentation of the supported conversion definitions.
Examples
--------
>>> import os
Expand Down Expand Up @@ -203,6 +208,7 @@ def __init__(
colours: ArrayLike | None = None,
opacity: float = 0.5,
thickness: float = 1,
**kwargs,
):
super().__init__()

Expand Down Expand Up @@ -232,6 +238,7 @@ def __init__(
sections,
CCS_ILLUMINANT_POINTER_GAMUT,
model,
**kwargs,
),
model,
).reshape([-1, 3])
Expand Down
11 changes: 11 additions & 0 deletions colour_visuals/rgb_colourspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ class VisualRGBColourspace3D(gfx.Mesh):
segments
Edge segments count for the *RGB* colourspace cube.
Other Parameters
----------------
kwargs
See the documentation of the supported conversion definitions.
Examples
--------
>>> import os
Expand Down Expand Up @@ -243,6 +248,7 @@ def __init__(
material: Type[gfx.MeshAbstractMaterial] = gfx.MeshBasicMaterial,
wireframe: bool = False,
segments: int = 16,
**kwargs,
):
colourspace = cast(
RGB_Colourspace,
Expand Down Expand Up @@ -271,6 +277,7 @@ def __init__(
RGB_to_XYZ(positions, colourspace),
colourspace.whitepoint,
model,
**kwargs,
),
model,
)
Expand Down Expand Up @@ -336,4 +343,8 @@ def __init__(
visual_6.local.position = np.array([4.5, 0, 0])
scene.add(visual_6)

visual_7 = VisualRGBColourspace3D(model="RGB")
visual_7.local.position = np.array([5.5, 0, 0])
scene.add(visual_7)

gfx.show(scene, up=np.array([0, 0, 1]))
13 changes: 12 additions & 1 deletion colour_visuals/rgb_scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class VisualRGBScatter3D(gfx.Points):
size
Size of the visual points
Other Parameters
----------------
kwargs
See the documentation of the supported conversion definitions.
Examples
--------
>>> import os
Expand Down Expand Up @@ -107,6 +112,7 @@ def __init__(
colours: ArrayLike | None = None,
opacity: float = 1,
size: float = 2,
**kwargs,
):
colourspace = cast(
RGB_Colourspace,
Expand All @@ -120,7 +126,12 @@ def __init__(
XYZ = RGB_to_XYZ(RGB, colourspace)

positions = colourspace_model_axis_reorder(
XYZ_to_colourspace_model(XYZ, colourspace.whitepoint, model),
XYZ_to_colourspace_model(
XYZ,
colourspace.whitepoint,
model,
**kwargs,
),
model,
)

Expand Down
13 changes: 12 additions & 1 deletion colour_visuals/rosch_macadam.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class VisualRoschMacAdam(gfx.Line):
thickness
Thickness of the visual lines.
Other Parameters
----------------
kwargs
See the documentation of the supported conversion definitions.
Examples
--------
>>> import os
Expand Down Expand Up @@ -119,6 +124,7 @@ def __init__(
colours: ArrayLike | None = None,
opacity: float = 1,
thickness: float = 1,
**kwargs,
):
super().__init__()

Expand All @@ -142,7 +148,12 @@ def __init__(
XYZ[XYZ == 0] = EPSILON

positions = colourspace_model_axis_reorder(
XYZ_to_colourspace_model(XYZ, colourspace.whitepoint, model),
XYZ_to_colourspace_model(
XYZ,
colourspace.whitepoint,
model,
**kwargs,
),
model,
)
positions = np.concatenate(
Expand Down

0 comments on commit 31a2fe3

Please sign in to comment.