Skip to content

Commit ff7bb7a

Browse files
committed
Update colour.matrix_RGB_to_RGB and colour.RGB_to_RGB definition signatures.
1 parent 20e0ba0 commit ff7bb7a

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

colour/models/rgb/rgb_colourspace.py

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,8 +1238,8 @@ def RGB_to_XYZ(
12381238

12391239

12401240
def matrix_RGB_to_RGB(
1241-
input_colourspace: RGB_Colourspace,
1242-
output_colourspace: RGB_Colourspace,
1241+
input_colourspace: RGB_Colourspace | str,
1242+
output_colourspace: RGB_Colourspace | str,
12431243
chromatic_adaptation_transform: Literal[
12441244
"Bianco 2010",
12451245
"Bianco PC 2010",
@@ -1285,11 +1285,38 @@ def matrix_RGB_to_RGB(
12851285
... )
12861286
>>> matrix_RGB_to_RGB(RGB_COLOURSPACE_sRGB, RGB_COLOURSPACE_PROPHOTO_RGB)
12871287
... # doctest: +ELLIPSIS
1288+
array([[ 0.5288241..., 0.3340609..., 0.1373616...],
1289+
[ 0.0975294..., 0.8790074..., 0.0233981...],
1290+
[ 0.0163599..., 0.1066124..., 0.8772485...]])
1291+
>>> matrix_RGB_to_RGB("sRGB", "ProPhoto RGB")
1292+
... # doctest: +ELLIPSIS
12881293
array([[ 0.5288241..., 0.3340609..., 0.1373616...],
12891294
[ 0.0975294..., 0.8790074..., 0.0233981...],
12901295
[ 0.0163599..., 0.1066124..., 0.8772485...]])
12911296
"""
12921297

1298+
from colour.models import RGB_COLOURSPACES
1299+
1300+
if isinstance(input_colourspace, str):
1301+
input_colourspace = validate_method(
1302+
input_colourspace,
1303+
RGB_COLOURSPACES,
1304+
'"{0}" "RGB" colourspace is invalid, it must be one of {1}!',
1305+
)
1306+
input_colourspace = cast(
1307+
RGB_Colourspace, RGB_COLOURSPACES[input_colourspace]
1308+
)
1309+
1310+
if isinstance(output_colourspace, str):
1311+
output_colourspace = validate_method(
1312+
output_colourspace,
1313+
RGB_COLOURSPACES,
1314+
'"{0}" "RGB" colourspace is invalid, it must be one of {1}!',
1315+
)
1316+
output_colourspace = cast(
1317+
RGB_Colourspace, RGB_COLOURSPACES[output_colourspace]
1318+
)
1319+
12931320
M = input_colourspace.matrix_RGB_to_XYZ
12941321

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

13091336
def RGB_to_RGB(
13101337
RGB: ArrayLike,
1311-
input_colourspace: RGB_Colourspace,
1312-
output_colourspace: RGB_Colourspace,
1338+
input_colourspace: RGB_Colourspace | str,
1339+
output_colourspace: RGB_Colourspace | str,
13131340
chromatic_adaptation_transform: Literal[
13141341
"Bianco 2010",
13151342
"Bianco PC 2010",
@@ -1386,8 +1413,33 @@ def RGB_to_RGB(
13861413
>>> RGB_to_RGB(RGB, RGB_COLOURSPACE_sRGB, RGB_COLOURSPACE_PROPHOTO_RGB)
13871414
... # doctest: +ELLIPSIS
13881415
array([ 0.2568891..., 0.0721446..., 0.0465553...])
1416+
>>> RGB_to_RGB(RGB, "sRGB", "ProPhoto RGB")
1417+
... # doctest: +ELLIPSIS
1418+
array([ 0.2568891..., 0.0721446..., 0.0465553...])
13891419
"""
13901420

1421+
from colour.models import RGB_COLOURSPACES
1422+
1423+
if isinstance(input_colourspace, str):
1424+
input_colourspace = validate_method(
1425+
input_colourspace,
1426+
RGB_COLOURSPACES,
1427+
'"{0}" "RGB" colourspace is invalid, it must be one of {1}!',
1428+
)
1429+
input_colourspace = cast(
1430+
RGB_Colourspace, RGB_COLOURSPACES[input_colourspace]
1431+
)
1432+
1433+
if isinstance(output_colourspace, str):
1434+
output_colourspace = validate_method(
1435+
output_colourspace,
1436+
RGB_COLOURSPACES,
1437+
'"{0}" "RGB" colourspace is invalid, it must be one of {1}!',
1438+
)
1439+
output_colourspace = cast(
1440+
RGB_Colourspace, RGB_COLOURSPACES[output_colourspace]
1441+
)
1442+
13911443
RGB = to_domain_1(RGB)
13921444

13931445
if apply_cctf_decoding and input_colourspace.cctf_decoding is not None:

colour/models/rgb/tests/test_rgb_colourspace.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,12 @@ def test_matrix_RGB_to_RGB(self):
761761
decimal=7,
762762
)
763763

764+
np.testing.assert_array_almost_equal(
765+
matrix_RGB_to_RGB(aces_2065_1_colourspace, sRGB_colourspace),
766+
matrix_RGB_to_RGB("ACES2065-1", "sRGB"),
767+
decimal=7,
768+
)
769+
764770

765771
class TestRGB_to_RGB(unittest.TestCase):
766772
"""
@@ -854,6 +860,20 @@ def test_RGB_to_RGB(self):
854860
np.array([120, 59, 46]),
855861
)
856862

863+
np.testing.assert_array_almost_equal(
864+
RGB_to_RGB(
865+
np.array([0.21931722, 0.06950287, 0.04694832]),
866+
aces_2065_1_colourspace,
867+
sRGB_colourspace,
868+
),
869+
RGB_to_RGB(
870+
np.array([0.21931722, 0.06950287, 0.04694832]),
871+
"ACES2065-1",
872+
"sRGB",
873+
),
874+
decimal=7,
875+
)
876+
857877
def test_n_dimensional_RGB_to_RGB(self):
858878
"""
859879
Test :func:`colour.models.rgb.rgb_colourspace.RGB_to_RGB` definition

0 commit comments

Comments
 (0)