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 57a61e1
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 10 deletions.
25 changes: 19 additions & 6 deletions colour_visuals/common.py
Original file line number Diff line number Diff line change
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
9 changes: 8 additions & 1 deletion 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 @@ -231,7 +237,8 @@ def __init__(
XYZ_to_colourspace_model(
sections,
CCS_ILLUMINANT_POINTER_GAMUT,
model,
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]))
9 changes: 8 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,8 @@ 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
12 changes: 11 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,11 @@ 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 57a61e1

Please sign in to comment.