Skip to content

Commit

Permalink
Update colour.matrix_RGB_to_RGB and colour.RGB_to_RGB definition …
Browse files Browse the repository at this point in the history
…signatures.
  • Loading branch information
KelSolaar committed Mar 31, 2023
1 parent f4642eb commit cc2e33f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 4 deletions.
60 changes: 56 additions & 4 deletions colour/models/rgb/rgb_colourspace.py
Expand Up @@ -1238,8 +1238,8 @@ def RGB_to_XYZ(


def matrix_RGB_to_RGB(
input_colourspace: RGB_Colourspace,
output_colourspace: RGB_Colourspace,
input_colourspace: RGB_Colourspace | str,
output_colourspace: RGB_Colourspace | str,
chromatic_adaptation_transform: Literal[
"Bianco 2010",
"Bianco PC 2010",
Expand Down Expand Up @@ -1285,11 +1285,38 @@ def matrix_RGB_to_RGB(
... )
>>> matrix_RGB_to_RGB(RGB_COLOURSPACE_sRGB, RGB_COLOURSPACE_PROPHOTO_RGB)
... # doctest: +ELLIPSIS
array([[ 0.5288241..., 0.3340609..., 0.1373616...],
[ 0.0975294..., 0.8790074..., 0.0233981...],
[ 0.0163599..., 0.1066124..., 0.8772485...]])
>>> matrix_RGB_to_RGB("sRGB", "ProPhoto RGB")
... # doctest: +ELLIPSIS
array([[ 0.5288241..., 0.3340609..., 0.1373616...],
[ 0.0975294..., 0.8790074..., 0.0233981...],
[ 0.0163599..., 0.1066124..., 0.8772485...]])
"""

from colour.models import RGB_COLOURSPACES

if isinstance(input_colourspace, str):
input_colourspace = validate_method(
input_colourspace,
RGB_COLOURSPACES,
'"{0}" "RGB" colourspace is invalid, it must be one of {1}!',
)
input_colourspace = cast(
RGB_Colourspace, RGB_COLOURSPACES[input_colourspace]
)

if isinstance(output_colourspace, str):
output_colourspace = validate_method(
output_colourspace,
RGB_COLOURSPACES,
'"{0}" "RGB" colourspace is invalid, it must be one of {1}!',
)
output_colourspace = cast(
RGB_Colourspace, RGB_COLOURSPACES[output_colourspace]
)

M = input_colourspace.matrix_RGB_to_XYZ

if chromatic_adaptation_transform is not None:
Expand All @@ -1308,8 +1335,8 @@ def matrix_RGB_to_RGB(

def RGB_to_RGB(
RGB: ArrayLike,
input_colourspace: RGB_Colourspace,
output_colourspace: RGB_Colourspace,
input_colourspace: RGB_Colourspace | str,
output_colourspace: RGB_Colourspace | str,
chromatic_adaptation_transform: Literal[
"Bianco 2010",
"Bianco PC 2010",
Expand Down Expand Up @@ -1386,8 +1413,33 @@ def RGB_to_RGB(
>>> RGB_to_RGB(RGB, RGB_COLOURSPACE_sRGB, RGB_COLOURSPACE_PROPHOTO_RGB)
... # doctest: +ELLIPSIS
array([ 0.2568891..., 0.0721446..., 0.0465553...])
>>> RGB_to_RGB(RGB, "sRGB", "ProPhoto RGB")
... # doctest: +ELLIPSIS
array([ 0.2568891..., 0.0721446..., 0.0465553...])
"""

from colour.models import RGB_COLOURSPACES

if isinstance(input_colourspace, str):
input_colourspace = validate_method(
input_colourspace,
RGB_COLOURSPACES,
'"{0}" "RGB" colourspace is invalid, it must be one of {1}!',
)
input_colourspace = cast(
RGB_Colourspace, RGB_COLOURSPACES[input_colourspace]
)

if isinstance(output_colourspace, str):
output_colourspace = validate_method(
output_colourspace,
RGB_COLOURSPACES,
'"{0}" "RGB" colourspace is invalid, it must be one of {1}!',
)
output_colourspace = cast(
RGB_Colourspace, RGB_COLOURSPACES[output_colourspace]
)

RGB = to_domain_1(RGB)

if apply_cctf_decoding and input_colourspace.cctf_decoding is not None:
Expand Down
20 changes: 20 additions & 0 deletions colour/models/rgb/tests/test_rgb_colourspace.py
Expand Up @@ -761,6 +761,12 @@ def test_matrix_RGB_to_RGB(self):
decimal=7,
)

np.testing.assert_array_almost_equal(
matrix_RGB_to_RGB(aces_2065_1_colourspace, sRGB_colourspace),
matrix_RGB_to_RGB("ACES2065-1", "sRGB"),
decimal=7,
)


class TestRGB_to_RGB(unittest.TestCase):
"""
Expand Down Expand Up @@ -854,6 +860,20 @@ def test_RGB_to_RGB(self):
np.array([120, 59, 46]),
)

np.testing.assert_array_almost_equal(
RGB_to_RGB(
np.array([0.21931722, 0.06950287, 0.04694832]),
aces_2065_1_colourspace,
sRGB_colourspace,
),
RGB_to_RGB(
np.array([0.21931722, 0.06950287, 0.04694832]),
"ACES2065-1",
"sRGB",
),
decimal=7,
)

def test_n_dimensional_RGB_to_RGB(self):
"""
Test :func:`colour.models.rgb.rgb_colourspace.RGB_to_RGB` definition
Expand Down

0 comments on commit cc2e33f

Please sign in to comment.