Skip to content

Commit

Permalink
Update colour.XYZ_to_RGB and colour.RGB_to_XYZ definition signatu…
Browse files Browse the repository at this point in the history
…res.

References #1127
  • Loading branch information
KelSolaar committed Mar 31, 2023
1 parent ac209ef commit da73927
Show file tree
Hide file tree
Showing 19 changed files with 342 additions and 285 deletions.
28 changes: 12 additions & 16 deletions colour/characterisation/aces_it.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@
from colour.io import read_sds_from_csv_file
from colour.models import XYZ_to_Jzazbz, XYZ_to_Lab, XYZ_to_xy, xy_to_XYZ
from colour.models.rgb import (
RGB_Colourspace,
RGB_COLOURSPACE_ACES2065_1,
RGB_to_XYZ,
XYZ_to_RGB,
normalised_primary_matrix,
)
from colour.temperature import CCT_to_xy_CIE_D
from colour.utilities import (
Expand Down Expand Up @@ -259,23 +259,18 @@ def k(x: NDArrayFloat, y: NDArrayFloat) -> DTypeFloat:
E_rgb *= S_FLARE_FACTOR

if chromatic_adaptation_transform is not None:
xy = XYZ_to_xy(sd_to_XYZ(illuminant) / 100)
NPM = normalised_primary_matrix(
RGB_COLOURSPACE_ACES2065_1.primaries, xy
)
XYZ = RGB_to_XYZ(
E_rgb,
xy,
RGB_Colourspace(
"~ACES2065-1",
RGB_COLOURSPACE_ACES2065_1.primaries,
XYZ_to_xy(sd_to_XYZ(illuminant) / 100),
illuminant.name,
),
RGB_COLOURSPACE_ACES2065_1.whitepoint,
NPM,
chromatic_adaptation_transform,
)
E_rgb = XYZ_to_RGB(
XYZ,
RGB_COLOURSPACE_ACES2065_1.whitepoint,
RGB_COLOURSPACE_ACES2065_1.whitepoint,
RGB_COLOURSPACE_ACES2065_1.matrix_XYZ_to_RGB,
)
E_rgb = XYZ_to_RGB(XYZ, RGB_COLOURSPACE_ACES2065_1)

return from_range_1(E_rgb)

Expand Down Expand Up @@ -864,9 +859,10 @@ def matrix_idt(
| str
| None = "CAT02",
additional_data: bool = False,
) -> Tuple[NDArrayFloat, NDArrayFloat, NDArrayFloat, NDArrayFloat] | Tuple[
NDArrayFloat, NDArrayFloat
]:
) -> (
Tuple[NDArrayFloat, NDArrayFloat, NDArrayFloat, NDArrayFloat]
| Tuple[NDArrayFloat, NDArrayFloat]
):
"""
Compute an *Input Device Transform* (IDT) matrix for given camera *RGB*
spectral sensitivities, illuminant, training data, standard observer colour
Expand Down
5 changes: 2 additions & 3 deletions colour/examples/characterisation/examples_colour_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@
for name, xyY in data.items():
RGB = colour.XYZ_to_RGB(
colour.xyY_to_XYZ(xyY),
colour.RGB_COLOURSPACES["sRGB"],
illuminant,
colour.CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"]["D65"],
colour.RGB_COLOURSPACES["sRGB"].matrix_XYZ_to_RGB,
"Bradford",
colour.RGB_COLOURSPACES["sRGB"].cctf_encoding,
apply_cctf_encoding=True,
)

RGB_i = [int(round(x * 255)) if x >= 0 else 0 for x in np.ravel(RGB)]
Expand Down
14 changes: 2 additions & 12 deletions colour/examples/models/examples_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@
D65 = colour.CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"]["D65"]
print(
colour.XYZ_to_RGB(
XYZ,
D65,
colour.RGB_COLOURSPACES["sRGB"].whitepoint,
colour.RGB_COLOURSPACES["sRGB"].matrix_XYZ_to_RGB,
"Bradford",
colour.RGB_COLOURSPACES["sRGB"].cctf_encoding,
XYZ, colour.RGB_COLOURSPACES["sRGB"], D65, "Bradford", True
)
)

Expand All @@ -85,12 +80,7 @@
)
print(
colour.RGB_to_XYZ(
RGB,
colour.RGB_COLOURSPACES["sRGB"].whitepoint,
D65,
colour.RGB_COLOURSPACES["sRGB"].matrix_RGB_to_XYZ,
"Bradford",
colour.RGB_COLOURSPACES["sRGB"].cctf_decoding,
RGB, colour.RGB_COLOURSPACES["sRGB"], D65, "Bradford", True
)
)

Expand Down
14 changes: 2 additions & 12 deletions colour/graph/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,22 +756,12 @@ def mired_to_CCT_D_uv(mired: ArrayLike) -> NDArrayFloat:
(
"CIE XYZ",
"RGB",
partial(
XYZ_to_RGB,
illuminant_XYZ=_RGB_COLOURSPACE_DEFAULT.whitepoint,
illuminant_RGB=_RGB_COLOURSPACE_DEFAULT.whitepoint,
matrix_XYZ_to_RGB=_RGB_COLOURSPACE_DEFAULT.matrix_XYZ_to_RGB,
),
partial(XYZ_to_RGB, colourspace=_RGB_COLOURSPACE_DEFAULT),
),
(
"RGB",
"CIE XYZ",
partial(
RGB_to_XYZ,
illuminant_RGB=_RGB_COLOURSPACE_DEFAULT.whitepoint,
illuminant_XYZ=_RGB_COLOURSPACE_DEFAULT.whitepoint,
matrix_RGB_to_XYZ=_RGB_COLOURSPACE_DEFAULT.matrix_RGB_to_XYZ,
),
partial(RGB_to_XYZ, colourspace=_RGB_COLOURSPACE_DEFAULT),
),
(
"RGB",
Expand Down
14 changes: 4 additions & 10 deletions colour/models/rgb/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,12 @@ def XYZ_to_sRGB(
array([ 0.7057393..., 0.1924826..., 0.2235416...])
"""

sRGB = RGB_COLOURSPACES["sRGB"]

return XYZ_to_RGB(
XYZ,
RGB_COLOURSPACES["sRGB"],
illuminant,
sRGB.whitepoint,
sRGB.matrix_XYZ_to_RGB,
chromatic_adaptation_transform,
sRGB.cctf_encoding if apply_cctf_encoding else None,
apply_cctf_encoding,
)


Expand Down Expand Up @@ -166,13 +163,10 @@ def sRGB_to_XYZ(
array([ 0.2065429..., 0.1219794..., 0.0513714...])
"""

sRGB = RGB_COLOURSPACES["sRGB"]

return RGB_to_XYZ(
RGB,
sRGB.whitepoint,
RGB_COLOURSPACES["sRGB"],
illuminant,
sRGB.matrix_RGB_to_XYZ,
chromatic_adaptation_transform,
sRGB.cctf_decoding if apply_cctf_decoding else None,
apply_cctf_decoding,
)
10 changes: 2 additions & 8 deletions colour/models/rgb/ictcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,13 +519,10 @@ def XYZ_to_ICtCp(
array([ 0.5924279..., -0.0374073..., 0.2512267...])
"""

BT2020 = RGB_COLOURSPACES["ITU-R BT.2020"]

RGB = XYZ_to_RGB(
XYZ,
RGB_COLOURSPACES["ITU-R BT.2020"],
illuminant,
BT2020.whitepoint,
BT2020.matrix_XYZ_to_RGB,
chromatic_adaptation_transform,
)

Expand Down Expand Up @@ -655,13 +652,10 @@ def ICtCp_to_XYZ(

RGB = ICtCp_to_RGB(ICtCp, method, L_p)

BT2020 = RGB_COLOURSPACES["ITU-R BT.2020"]

XYZ = RGB_to_XYZ(
RGB,
BT2020.whitepoint,
RGB_COLOURSPACES["ITU-R BT.2020"],
illuminant,
BT2020.matrix_RGB_to_XYZ,
chromatic_adaptation_transform,
)

Expand Down
Loading

0 comments on commit da73927

Please sign in to comment.