From 8609a7ff436c5911e2ea6651eca381f2c1b88b05 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Thu, 14 Sep 2023 22:18:18 +1200 Subject: [PATCH 1/4] Add various new literals for typing annotations. --- colour/adaptation/vonkries.py | 38 +- colour/characterisation/aces_it.py | 47 +-- colour/corresponding/prediction.py | 24 +- colour/hints/__init__.py | 358 ++++++++++++++++++ colour/models/rgb/common.py | 36 +- colour/models/rgb/derivation.py | 22 +- colour/models/rgb/ictcp.py | 37 +- colour/models/rgb/rgb_colourspace.py | 90 +---- .../models/rgb/transfer_functions/__init__.py | 265 +------------ colour/plotting/common.py | 22 +- colour/plotting/models.py | 91 ++--- colour/plotting/section.py | 119 +----- colour/plotting/volume.py | 67 +--- colour/volume/rgb.py | 32 +- docs/colour.hints.rst | 56 +-- tasks.py | 54 ++- 16 files changed, 552 insertions(+), 806 deletions(-) diff --git a/colour/adaptation/vonkries.py b/colour/adaptation/vonkries.py index 1a9c0d25d..94a490641 100644 --- a/colour/adaptation/vonkries.py +++ b/colour/adaptation/vonkries.py @@ -20,7 +20,11 @@ from colour.adaptation import CHROMATIC_ADAPTATION_TRANSFORMS from colour.algebra import matrix_dot, vector_dot, sdiv, sdiv_mode -from colour.hints import ArrayLike, Literal, NDArrayFloat +from colour.hints import ( + ArrayLike, + LiteralChromaticAdaptationTransform, + NDArrayFloat, +) from colour.utilities import ( from_range_1, row_as_diagonal, @@ -44,21 +48,7 @@ def matrix_chromatic_adaptation_VonKries( XYZ_w: ArrayLike, XYZ_wr: ArrayLike, - transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] - | str = "CAT02", + transform: LiteralChromaticAdaptationTransform | str = "CAT02", ) -> NDArrayFloat: """ Compute the *chromatic adaptation* matrix from test viewing conditions @@ -145,21 +135,7 @@ def chromatic_adaptation_VonKries( XYZ: ArrayLike, XYZ_w: ArrayLike, XYZ_wr: ArrayLike, - transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] - | str = "CAT02", + transform: LiteralChromaticAdaptationTransform | str = "CAT02", ) -> NDArrayFloat: """ Adapt given stimulus from test viewing conditions to reference viewing diff --git a/colour/characterisation/aces_it.py b/colour/characterisation/aces_it.py index e268424ae..fda37b438 100644 --- a/colour/characterisation/aces_it.py +++ b/colour/characterisation/aces_it.py @@ -86,7 +86,7 @@ ArrayLike, Callable, DTypeFloat, - Literal, + LiteralChromaticAdaptationTransform, Mapping, NDArrayFloat, Tuple, @@ -160,20 +160,7 @@ def sd_to_aces_relative_exposure_values( sd: SpectralDistribution, illuminant: SpectralDistribution | None = None, - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str | None = "CAT02", **kwargs, @@ -665,20 +652,7 @@ def training_data_sds_to_XYZ( training_data: MultiSpectralDistributions, cmfs: MultiSpectralDistributions, illuminant: SpectralDistribution, - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str | None = "CAT02", ) -> NDArrayFloat: @@ -1022,20 +996,7 @@ def matrix_idt( cmfs: MultiSpectralDistributions | None = None, optimisation_factory: Callable = optimisation_factory_rawtoaces_v1, optimisation_kwargs: dict | None = None, - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str | None = "CAT02", additional_data: bool = False, diff --git a/colour/corresponding/prediction.py b/colour/corresponding/prediction.py index 6d59747cc..34860c31c 100644 --- a/colour/corresponding/prediction.py +++ b/colour/corresponding/prediction.py @@ -52,7 +52,13 @@ BRENEMAN_EXPERIMENTS, BRENEMAN_EXPERIMENT_PRIMARIES_CHROMATICITIES, ) -from colour.hints import Any, ArrayLike, Literal, Tuple +from colour.hints import ( + Any, + ArrayLike, + Literal, + LiteralChromaticAdaptationTransform, + Tuple, +) from colour.models import ( Luv_to_uv, Luv_uv_to_xy, @@ -513,21 +519,7 @@ def corresponding_chromaticities_prediction_CMCCAT2000( def corresponding_chromaticities_prediction_VonKries( experiment: Literal[1, 2, 3, 4, 6, 8, 9, 11, 12] | CorrespondingColourDataset = 1, - transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] - | str = "CAT02", + transform: LiteralChromaticAdaptationTransform | str = "CAT02", ) -> Tuple[CorrespondingChromaticitiesPrediction, ...]: """ Return the corresponding chromaticities prediction for *Von Kries* diff --git a/colour/hints/__init__.py b/colour/hints/__init__.py index fcb42f509..283eea485 100644 --- a/colour/hints/__init__.py +++ b/colour/hints/__init__.py @@ -94,6 +94,19 @@ "ProtocolExtrapolator", "ProtocolLUTSequenceItem", "LiteralWarning", + "LiteralChromaticAdaptationTransform", + "LiteralColourspaceModel", + "LiteralRGBColourspace", + "LiteralLogEncoding", + "LiteralLogDecoding", + "LiteralOETF", + "LiteralOETFInverse", + "LiteralEOTF", + "LiteralEOTFInverse", + "LiteralCCTFEncoding", + "LiteralCCTFDecoding", + "LiteralOOTF", + "LiteralOOTFInverse", ] RegexFlag = NewType("RegexFlag", re.RegexFlag) @@ -177,6 +190,351 @@ def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArray: # noqa: D102 "default", "error", "ignore", "always", "module", "once" ] +# NOTE: The following literals are automatically generated by the *invoke* +# *literalise* task. Please do not edit this section manually! + +# LITERALISE::BEGIN +LiteralChromaticAdaptationTransform = Literal[ + "Bianco 2010", + "Bianco PC 2010", + "Bradford", + "CAT02", + "CAT02 Brill 2008", + "CAT16", + "CMCCAT2000", + "CMCCAT97", + "Fairchild", + "Sharp", + "Von Kries", + "XYZ Scaling", +] +LiteralColourspaceModel = Literal[ + "CAM02LCD", + "CAM02SCD", + "CAM02UCS", + "CAM16LCD", + "CAM16SCD", + "CAM16UCS", + "CIE Lab", + "CIE Luv", + "CIE UCS", + "CIE UVW", + "CIE XYZ", + "CIE xyY", + "DIN99", + "Hunter Lab", + "Hunter Rdab", + "ICaCb", + "ICtCp", + "IPT", + "IPT Ragoo 2021", + "IgPgTg", + "Jzazbz", + "OSA UCS", + "Oklab", + "Yrg", + "hdr-CIELAB", + "hdr-IPT", +] +LiteralRGBColourspace = Literal[ + "ACES2065-1", + "ACEScc", + "ACEScct", + "ACEScg", + "ACESproxy", + "ALEXA Wide Gamut", + "ARRI Wide Gamut 3", + "ARRI Wide Gamut 4", + "Adobe RGB (1998)", + "Adobe Wide Gamut RGB", + "Apple RGB", + "Best RGB", + "Beta RGB", + "Blackmagic Wide Gamut", + "CIE RGB", + "Cinema Gamut", + "ColorMatch RGB", + "DCDM XYZ", + "DCI-P3", + "DCI-P3-P", + "DJI D-Gamut", + "DRAGONcolor", + "DRAGONcolor2", + "DaVinci Wide Gamut", + "Display P3", + "Don RGB 4", + "EBU Tech. 3213-E", + "ECI RGB v2", + "ERIMM RGB", + "Ekta Space PS 5", + "F-Gamut", + "FilmLight E-Gamut", + "ITU-R BT.2020", + "ITU-R BT.470 - 525", + "ITU-R BT.470 - 625", + "ITU-R BT.709", + "ITU-T H.273 - 22 Unspecified", + "ITU-T H.273 - Generic Film", + "Max RGB", + "N-Gamut", + "NTSC (1953)", + "NTSC (1987)", + "P3-D65", + "PLASA ANSI E1.54", + "Pal/Secam", + "ProPhoto RGB", + "Protune Native", + "REDWideGamutRGB", + "REDcolor", + "REDcolor2", + "REDcolor3", + "REDcolor4", + "RIMM RGB", + "ROMM RGB", + "Russell RGB", + "S-Gamut", + "S-Gamut3", + "S-Gamut3.Cine", + "SMPTE 240M", + "SMPTE C", + "Sharp RGB", + "V-Gamut", + "Venice S-Gamut3", + "Venice S-Gamut3.Cine", + "Xtreme RGB", + "aces", + "adobe1998", + "prophoto", + "sRGB", +] +LiteralLogEncoding = Literal[ + "ACEScc", + "ACEScct", + "ACESproxy", + "ARRI LogC3", + "ARRI LogC4", + "Canon Log", + "Canon Log 2", + "Canon Log 3", + "Cineon", + "D-Log", + "ERIMM RGB", + "F-Log", + "F-Log2", + "Filmic Pro 6", + "L-Log", + "Log2", + "Log3G10", + "Log3G12", + "N-Log", + "PLog", + "Panalog", + "Protune", + "REDLog", + "REDLogFilm", + "S-Log", + "S-Log2", + "S-Log3", + "T-Log", + "V-Log", + "ViperLog", +] +LiteralLogDecoding = Literal[ + "ACEScc", + "ACEScct", + "ACESproxy", + "ARRI LogC3", + "ARRI LogC4", + "Canon Log", + "Canon Log 2", + "Canon Log 3", + "Cineon", + "D-Log", + "ERIMM RGB", + "F-Log", + "F-Log2", + "Filmic Pro 6", + "L-Log", + "Log2", + "Log3G10", + "Log3G12", + "N-Log", + "PLog", + "Panalog", + "Protune", + "REDLog", + "REDLogFilm", + "S-Log", + "S-Log2", + "S-Log3", + "T-Log", + "V-Log", + "ViperLog", +] +LiteralOETF = Literal[ + "ARIB STD-B67", + "Blackmagic Film Generation 5", + "DaVinci Intermediate", + "ITU-R BT.2020", + "ITU-R BT.2100 HLG", + "ITU-R BT.2100 PQ", + "ITU-R BT.601", + "ITU-R BT.709", + "ITU-T H.273 IEC 61966-2", + "ITU-T H.273 Log", + "ITU-T H.273 Log Sqrt", + "SMPTE 240M", +] +LiteralOETFInverse = Literal[ + "ARIB STD-B67", + "Blackmagic Film Generation 5", + "DaVinci Intermediate", + "ITU-R BT.2020", + "ITU-R BT.2100 HLG", + "ITU-R BT.2100 PQ", + "ITU-R BT.601", + "ITU-R BT.709", + "ITU-T H.273 IEC 61966-2", + "ITU-T H.273 Log", + "ITU-T H.273 Log Sqrt", +] +LiteralEOTF = Literal[ + "DCDM", + "DICOM GSDF", + "ITU-R BT.1886", + "ITU-R BT.2100 HLG", + "ITU-R BT.2100 PQ", + "ITU-T H.273 ST.428-1", + "SMPTE 240M", + "ST 2084", + "sRGB", +] +LiteralEOTFInverse = Literal[ + "DCDM", + "DICOM GSDF", + "ITU-R BT.1886", + "ITU-R BT.2100 HLG", + "ITU-R BT.2100 PQ", + "ITU-T H.273 ST.428-1", + "ST 2084", + "sRGB", +] +LiteralCCTFEncoding = Literal[ + "ACEScc", + "ACEScct", + "ACESproxy", + "ARIB STD-B67", + "ARRI LogC3", + "ARRI LogC4", + "Blackmagic Film Generation 5", + "Canon Log", + "Canon Log 2", + "Canon Log 3", + "Cineon", + "D-Log", + "DCDM", + "DICOM GSDF", + "DaVinci Intermediate", + "ERIMM RGB", + "F-Log", + "F-Log2", + "Filmic Pro 6", + "Gamma 2.2", + "Gamma 2.4", + "Gamma 2.6", + "ITU-R BT.1886", + "ITU-R BT.2020", + "ITU-R BT.2100 HLG", + "ITU-R BT.2100 PQ", + "ITU-R BT.601", + "ITU-R BT.709", + "ITU-T H.273 IEC 61966-2", + "ITU-T H.273 Log", + "ITU-T H.273 Log Sqrt", + "ITU-T H.273 ST.428-1", + "L-Log", + "Log2", + "Log3G10", + "Log3G12", + "N-Log", + "PLog", + "Panalog", + "ProPhoto RGB", + "Protune", + "REDLog", + "REDLogFilm", + "RIMM RGB", + "ROMM RGB", + "S-Log", + "S-Log2", + "S-Log3", + "SMPTE 240M", + "ST 2084", + "T-Log", + "V-Log", + "ViperLog", + "sRGB", +] +LiteralCCTFDecoding = Literal[ + "ACEScc", + "ACEScct", + "ACESproxy", + "ARIB STD-B67", + "ARRI LogC3", + "ARRI LogC4", + "Blackmagic Film Generation 5", + "Canon Log", + "Canon Log 2", + "Canon Log 3", + "Cineon", + "D-Log", + "DCDM", + "DICOM GSDF", + "DaVinci Intermediate", + "ERIMM RGB", + "F-Log", + "F-Log2", + "Filmic Pro 6", + "Gamma 2.2", + "Gamma 2.4", + "Gamma 2.6", + "ITU-R BT.1886", + "ITU-R BT.2020", + "ITU-R BT.2100 HLG", + "ITU-R BT.2100 PQ", + "ITU-R BT.601", + "ITU-R BT.709", + "ITU-T H.273 IEC 61966-2", + "ITU-T H.273 Log", + "ITU-T H.273 Log Sqrt", + "ITU-T H.273 ST.428-1", + "L-Log", + "Log2", + "Log3G10", + "Log3G12", + "N-Log", + "PLog", + "Panalog", + "ProPhoto RGB", + "Protune", + "REDLog", + "REDLogFilm", + "RIMM RGB", + "ROMM RGB", + "S-Log", + "S-Log2", + "S-Log3", + "SMPTE 240M", + "ST 2084", + "T-Log", + "V-Log", + "ViperLog", + "sRGB", +] +LiteralOOTF = Literal["ITU-R BT.2100 HLG", "ITU-R BT.2100 PQ"] +LiteralOOTFInverse = Literal["ITU-R BT.2100 HLG", "ITU-R BT.2100 PQ"] +# LITERALISE::END + def arraylike(a: ArrayLike) -> NDArray: # noqa: ARG001 ... diff --git a/colour/models/rgb/common.py b/colour/models/rgb/common.py index d5276c759..6ca47d453 100644 --- a/colour/models/rgb/common.py +++ b/colour/models/rgb/common.py @@ -8,7 +8,11 @@ from __future__ import annotations from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import ArrayLike, Literal, NDArrayFloat +from colour.hints import ( + ArrayLike, + LiteralChromaticAdaptationTransform, + NDArrayFloat, +) from colour.models.rgb import RGB_COLOURSPACES, RGB_to_XYZ, XYZ_to_RGB __author__ = "Colour Developers" @@ -29,20 +33,7 @@ def XYZ_to_sRGB( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str | None = "CAT02", apply_cctf_encoding: bool = True, @@ -103,20 +94,7 @@ def sRGB_to_XYZ( illuminant: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str | None = "CAT02", apply_cctf_decoding: bool = True, diff --git a/colour/models/rgb/derivation.py b/colour/models/rgb/derivation.py index 82c4133e0..88760d584 100644 --- a/colour/models/rgb/derivation.py +++ b/colour/models/rgb/derivation.py @@ -28,7 +28,12 @@ import numpy as np from colour.adaptation import chromatic_adaptation_VonKries -from colour.hints import ArrayLike, Literal, NDArrayFloat, Tuple +from colour.hints import ( + ArrayLike, + LiteralChromaticAdaptationTransform, + NDArrayFloat, + Tuple, +) from colour.models import XYZ_to_xy, XYZ_to_xyY, xy_to_XYZ from colour.utilities import as_float, as_float_array, ones, tsplit @@ -129,20 +134,7 @@ def chromatically_adapted_primaries( primaries: ArrayLike, whitepoint_t: ArrayLike, whitepoint_r: ArrayLike, - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str = "CAT02", ) -> NDArrayFloat: """ diff --git a/colour/models/rgb/ictcp.py b/colour/models/rgb/ictcp.py index 2eb65f2b8..dcd1dc4e1 100644 --- a/colour/models/rgb/ictcp.py +++ b/colour/models/rgb/ictcp.py @@ -31,7 +31,12 @@ from colour.algebra import vector_dot from colour.colorimetry import CCS_ILLUMINANTS -from colour.hints import ArrayLike, Literal, NDArrayFloat +from colour.hints import ( + ArrayLike, + Literal, + LiteralChromaticAdaptationTransform, + NDArrayFloat, +) from colour.models.rgb import RGB_COLOURSPACES, RGB_to_XYZ, XYZ_to_RGB from colour.models.rgb.transfer_functions import ( eotf_ST2084, @@ -400,20 +405,7 @@ def ICtCp_to_RGB( def XYZ_to_ICtCp( XYZ: ArrayLike, illuminant=CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"]["D65"], - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str | None = "CAT02", method: Literal[ @@ -532,20 +524,7 @@ def XYZ_to_ICtCp( def ICtCp_to_XYZ( ICtCp: ArrayLike, illuminant=CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"]["D65"], - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str | None = "CAT02", method: Literal[ diff --git a/colour/models/rgb/rgb_colourspace.py b/colour/models/rgb/rgb_colourspace.py index bf6ab3a63..60ee19eff 100644 --- a/colour/models/rgb/rgb_colourspace.py +++ b/colour/models/rgb/rgb_colourspace.py @@ -34,7 +34,8 @@ Any, ArrayLike, Callable, - Literal, + LiteralChromaticAdaptationTransform, + LiteralRGBColourspace, NDArrayFloat, cast, ) @@ -843,20 +844,7 @@ def chromatically_adapt( self, whitepoint: ArrayLike, whitepoint_name: str | None = None, - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str = "CAT02", ) -> RGB_Colourspace: """ @@ -949,22 +937,9 @@ def copy(self) -> RGB_Colourspace: def XYZ_to_RGB( XYZ: ArrayLike, - colourspace: RGB_Colourspace | str, + colourspace: RGB_Colourspace | LiteralRGBColourspace | str, illuminant: ArrayLike | None = None, - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str | None = "CAT02", apply_cctf_encoding: bool = False, @@ -1097,22 +1072,9 @@ def XYZ_to_RGB( def RGB_to_XYZ( RGB: ArrayLike, - colourspace: RGB_Colourspace | str, + colourspace: RGB_Colourspace | LiteralRGBColourspace | str, illuminant: ArrayLike | None = None, - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str | None = "CAT02", apply_cctf_decoding: bool = False, @@ -1244,22 +1206,9 @@ def RGB_to_XYZ( def matrix_RGB_to_RGB( - input_colourspace: RGB_Colourspace | str, - output_colourspace: RGB_Colourspace | str, - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + input_colourspace: RGB_Colourspace | LiteralRGBColourspace | str, + output_colourspace: RGB_Colourspace | LiteralRGBColourspace | str, + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str | None = "CAT02", ) -> NDArrayFloat: @@ -1341,22 +1290,9 @@ def matrix_RGB_to_RGB( def RGB_to_RGB( RGB: ArrayLike, - input_colourspace: RGB_Colourspace | str, - output_colourspace: RGB_Colourspace | str, - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + input_colourspace: RGB_Colourspace | LiteralRGBColourspace | str, + output_colourspace: RGB_Colourspace | LiteralRGBColourspace | str, + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str | None = "CAT02", apply_cctf_decoding: bool = False, diff --git a/colour/models/rgb/transfer_functions/__init__.py b/colour/models/rgb/transfer_functions/__init__.py index 7e4570038..e7d58e9e6 100644 --- a/colour/models/rgb/transfer_functions/__init__.py +++ b/colour/models/rgb/transfer_functions/__init__.py @@ -5,7 +5,16 @@ ArrayLike, NDArrayFloat, NDArrayInt, - Literal, + LiteralLogEncoding, + LiteralLogDecoding, + LiteralOETF, + LiteralOETFInverse, + LiteralEOTF, + LiteralEOTFInverse, + LiteralCCTFEncoding, + LiteralCCTFDecoding, + LiteralOOTF, + LiteralOOTFInverse, Union, ) from colour.utilities import ( @@ -404,41 +413,7 @@ def log_encoding( value: ArrayLike, - function: Union[ - Literal[ - "ACEScc", - "ACEScct", - "ACESproxy", - "ARRI LogC3", - "ARRI LogC4", - "Canon Log 2", - "Canon Log 3", - "Canon Log", - "Cineon", - "D-Log", - "ERIMM RGB", - "F-Log", - "F-Log2", - "Filmic Pro 6", - "L-Log", - "Log2", - "Log3G10", - "Log3G12", - "N-Log", - "PLog", - "Panalog", - "Protune", - "REDLog", - "REDLogFilm", - "S-Log", - "S-Log2", - "S-Log3", - "T-Log", - "V-Log", - "ViperLog", - ], - str, - ] = "Cineon", + function: Union[LiteralLogEncoding, str] = "Cineon", **kwargs: Any ) -> Union[NDArrayFloat, NDArrayInt]: """ @@ -557,41 +532,7 @@ def log_encoding( def log_decoding( value: Union[ArrayLike, ArrayLike], - function: Union[ - Literal[ - "ACEScc", - "ACEScct", - "ACESproxy", - "ARRI LogC3", - "ARRI LogC4", - "Canon Log 2", - "Canon Log 3", - "Canon Log", - "Cineon", - "D-Log", - "ERIMM RGB", - "F-Log", - "F-Log2", - "Filmic Pro 6", - "L-Log", - "Log2", - "Log3G10", - "Log3G12", - "N-Log", - "PLog", - "Panalog", - "Protune", - "REDLog", - "REDLogFilm", - "S-Log", - "S-Log2", - "S-Log3", - "T-Log", - "V-Log", - "ViperLog", - ], - str, - ] = "Cineon", + function: Union[LiteralLogDecoding, str] = "Cineon", **kwargs: Any ) -> NDArrayFloat: """ @@ -703,23 +644,7 @@ def log_decoding( def oetf( value: ArrayLike, - function: Union[ - Literal[ - "ARIB STD-B67", - "Blackmagic Film Generation 5", - "DaVinci Intermediate", - "ITU-R BT.2020", - "ITU-R BT.2100 HLG", - "ITU-R BT.2100 PQ", - "ITU-R BT.601", - "ITU-R BT.709", - "ITU-T H.273 Log", - "ITU-T H.273 Log Sqrt", - "ITU-T H.273 IEC 61966-2", - "SMPTE 240M", - ], - str, - ] = "ITU-R BT.709", + function: Union[LiteralOETF, str] = "ITU-R BT.709", **kwargs: Any ) -> NDArrayFloat: """ @@ -794,22 +719,7 @@ def oetf( def oetf_inverse( value: ArrayLike, - function: Union[ - Literal[ - "ARIB STD-B67", - "Blackmagic Film Generation 5", - "DaVinci Intermediate", - "ITU-R BT.2020", - "ITU-R BT.2100 HLG", - "ITU-R BT.2100 PQ", - "ITU-R BT.601", - "ITU-R BT.709", - "ITU-T H.273 Log", - "ITU-T H.273 Log Sqrt", - "ITU-T H.273 IEC 61966-2", - ], - str, - ] = "ITU-R BT.709", + function: Union[LiteralOETFInverse, str] = "ITU-R BT.709", **kwargs: Any ) -> NDArrayFloat: """ @@ -884,20 +794,7 @@ def oetf_inverse( def eotf( value: Union[ArrayLike, ArrayLike], - function: Union[ - Literal[ - "DCDM", - "DICOM GSDF", - "ITU-R BT.1886", - "ITU-R BT.2100 HLG", - "ITU-R BT.2100 PQ", - "ITU-T H.273 ST.428-1", - "SMPTE 240M", - "ST 2084", - "sRGB", - ], - str, - ] = "ITU-R BT.1886", + function: Union[LiteralEOTF, str] = "ITU-R BT.1886", **kwargs: Any ) -> NDArrayFloat: """ @@ -968,19 +865,7 @@ def eotf( def eotf_inverse( value: ArrayLike, - function: Union[ - Literal[ - "DCDM", - "DICOM GSDF", - "ITU-R BT.1886", - "ITU-R BT.2100 HLG", - "ITU-R BT.2100 PQ", - "ITU-T H.273 ST.428-1", - "ST 2084", - "sRGB", - ], - str, - ] = "ITU-R BT.1886", + function: Union[LiteralEOTFInverse, str] = "ITU-R BT.1886", **kwargs ) -> Union[NDArrayFloat, NDArrayInt]: """ @@ -1079,60 +964,7 @@ def eotf_inverse( def cctf_encoding( value: ArrayLike, - function: Union[ - Literal[ - "ACEScc", - "ACEScct", - "ACESproxy", - "ARRI LogC3", - "ARRI LogC4", - "ARIB STD-B67", - "Blackmagic Film Generation 5", - "Canon Log 2", - "Canon Log 3", - "Canon Log", - "Cineon", - "D-Log", - "DCDM", - "DICOM GSDF", - "DaVinci Intermediate", - "ERIMM RGB", - "F-Log", - "F-Log2", - "Filmic Pro 6", - "Gamma 2.2", - "Gamma 2.4", - "Gamma 2.6", - "ITU-R BT.1886", - "ITU-R BT.2020", - "ITU-R BT.2100 HLG", - "ITU-R BT.2100 PQ", - "ITU-R BT.601", - "ITU-R BT.709", - "Log2", - "Log3G10", - "Log3G12", - "N-Log", - "PLog", - "Panalog", - "ProPhoto RGB", - "Protune", - "REDLog", - "REDLogFilm", - "RIMM RGB", - "ROMM RGB", - "S-Log", - "S-Log2", - "S-Log3", - "SMPTE 240M", - "ST 2084", - "T-Log", - "V-Log", - "ViperLog", - "sRGB", - ], - str, - ] = "sRGB", + function: Union[LiteralCCTFEncoding, str] = "sRGB", **kwargs: Any ) -> Union[NDArrayFloat, NDArrayInt]: """ @@ -1236,60 +1068,7 @@ def cctf_encoding( def cctf_decoding( value: Union[ArrayLike, ArrayLike], - function: Union[ - Literal[ - "ACEScc", - "ACEScct", - "ACESproxy", - "ARRI LogC3", - "ARRI LogC4", - "ARIB STD-B67", - "Blackmagic Film Generation 5", - "Canon Log 2", - "Canon Log 3", - "Canon Log", - "Cineon", - "D-Log", - "DCDM", - "DICOM GSDF", - "DaVinci Intermediate", - "ERIMM RGB", - "F-Log", - "F-Log2", - "Filmic Pro 6", - "Gamma 2.2", - "Gamma 2.4", - "Gamma 2.6", - "ITU-R BT.1886", - "ITU-R BT.2020", - "ITU-R BT.2100 HLG", - "ITU-R BT.2100 PQ", - "ITU-R BT.601", - "ITU-R BT.709", - "Log2", - "Log3G10", - "Log3G12", - "N-Log", - "PLog", - "Panalog", - "ProPhoto RGB", - "Protune", - "REDLog", - "REDLogFilm", - "RIMM RGB", - "ROMM RGB", - "S-Log", - "S-Log2", - "S-Log3", - "SMPTE 240M", - "ST 2084", - "T-Log", - "V-Log", - "ViperLog", - "sRGB", - ], - str, - ] = "sRGB", + function: Union[LiteralCCTFDecoding, str] = "sRGB", **kwargs: Any ) -> NDArrayFloat: """ @@ -1377,9 +1156,7 @@ def cctf_decoding( def ootf( value: ArrayLike, - function: Union[ - Literal["ITU-R BT.2100 HLG", "ITU-R BT.2100 PQ"], str - ] = "ITU-R BT.2100 PQ", + function: Union[LiteralOOTF, str] = "ITU-R BT.2100 PQ", **kwargs: Any ) -> NDArrayFloat: """ @@ -1437,9 +1214,7 @@ def ootf( def ootf_inverse( value: ArrayLike, - function: Union[ - Literal["ITU-R BT.2100 HLG", "ITU-R BT.2100 PQ"], str - ] = "ITU-R BT.2100 PQ", + function: Union[LiteralOOTFInverse, str] = "ITU-R BT.2100 PQ", **kwargs: Any ) -> NDArrayFloat: """ diff --git a/colour/plotting/common.py b/colour/plotting/common.py index dc7fdca91..0873fc9d6 100644 --- a/colour/plotting/common.py +++ b/colour/plotting/common.py @@ -54,6 +54,8 @@ Dict, List, Literal, + LiteralChromaticAdaptationTransform, + LiteralRGBColourspace, Mapping, NDArrayFloat, Sequence, @@ -341,20 +343,7 @@ def wrapped(*args: Any, **kwargs: Any) -> Any: def XYZ_to_plotting_colourspace( XYZ: ArrayLike, illuminant: ArrayLike = RGB_COLOURSPACES["sRGB"].whitepoint, - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str | None = "CAT02", apply_cctf_encoding: bool = True, @@ -934,7 +923,10 @@ class instance, then the lower, slugified and canonical keys are also def filter_RGB_colourspaces( - filterers: RGB_Colourspace | str | Sequence[RGB_Colourspace | str], + filterers: RGB_Colourspace + | LiteralRGBColourspace + | str + | Sequence[RGB_Colourspace | LiteralRGBColourspace | str], allow_non_siblings: bool = True, ) -> Dict[str, RGB_Colourspace]: """ diff --git a/colour/plotting/models.py b/colour/plotting/models.py index 4cfea6b3f..56c10c646 100644 --- a/colour/plotting/models.py +++ b/colour/plotting/models.py @@ -63,6 +63,8 @@ Dict, List, Literal, + LiteralColourspaceModel, + LiteralRGBColourspace, NDArrayFloat, Sequence, Tuple, @@ -186,37 +188,7 @@ def colourspace_model_axis_reorder( a: ArrayLike, - model: Literal[ - "CAM02LCD", - "CAM02SCD", - "CAM02UCS", - "CAM16LCD", - "CAM16SCD", - "CAM16UCS", - "CIE XYZ", - "CIE xyY", - "CIE Lab", - "CIE LCHab", - "CIE Luv", - "CIE LCHuv", - "CIE UCS", - "CIE UVW", - "DIN99", - "Hunter Lab", - "Hunter Rdab", - "ICaCb", - "ICtCp", - "IPT", - "IPT Ragoo 2021", - "IgPgTg", - "Jzazbz", - "OSA UCS", - "Oklab", - "hdr-CIELAB", - "hdr-IPT", - "Yrg", - ] - | str, + model: LiteralColourspaceModel | str, direction: Literal["Forward", "Inverse"] | str = "Forward", ) -> NDArrayFloat: """ @@ -429,7 +401,10 @@ def xy_to_ij(xy: NDArrayFloat) -> NDArrayFloat: @override_style() def plot_RGB_colourspaces_in_chromaticity_diagram( - colourspaces: RGB_Colourspace | str | Sequence[RGB_Colourspace | str], + colourspaces: RGB_Colourspace + | LiteralRGBColourspace + | str + | Sequence[RGB_Colourspace | LiteralRGBColourspace | str], cmfs: MultiSpectralDistributions | str | Sequence[ @@ -665,7 +640,10 @@ def xy_to_ij(xy: NDArrayFloat) -> NDArrayFloat: @override_style() def plot_RGB_colourspaces_in_chromaticity_diagram_CIE1931( - colourspaces: RGB_Colourspace | str | Sequence[RGB_Colourspace | str], + colourspaces: RGB_Colourspace + | LiteralRGBColourspace + | str + | Sequence[RGB_Colourspace | LiteralRGBColourspace | str], cmfs: MultiSpectralDistributions | str | Sequence[ @@ -757,7 +735,10 @@ def plot_RGB_colourspaces_in_chromaticity_diagram_CIE1931( @override_style() def plot_RGB_colourspaces_in_chromaticity_diagram_CIE1960UCS( - colourspaces: RGB_Colourspace | str | Sequence[RGB_Colourspace | str], + colourspaces: RGB_Colourspace + | LiteralRGBColourspace + | str + | Sequence[RGB_Colourspace | LiteralRGBColourspace | str], cmfs: MultiSpectralDistributions | str | Sequence[ @@ -850,7 +831,10 @@ def plot_RGB_colourspaces_in_chromaticity_diagram_CIE1960UCS( @override_style() def plot_RGB_colourspaces_in_chromaticity_diagram_CIE1976UCS( - colourspaces: RGB_Colourspace | str | Sequence[RGB_Colourspace | str], + colourspaces: RGB_Colourspace + | LiteralRGBColourspace + | str + | Sequence[RGB_Colourspace | LiteralRGBColourspace | str], cmfs: MultiSpectralDistributions | str | Sequence[ @@ -946,7 +930,7 @@ def plot_RGB_chromaticities_in_chromaticity_diagram( RGB: ArrayLike, colourspace: RGB_Colourspace | str - | Sequence[RGB_Colourspace | str] = "sRGB", + | Sequence[RGB_Colourspace | LiteralRGBColourspace | str] = "sRGB", chromaticity_diagram_callable: Callable = ( plot_RGB_colourspaces_in_chromaticity_diagram ), @@ -1087,7 +1071,7 @@ def plot_RGB_chromaticities_in_chromaticity_diagram_CIE1931( RGB: ArrayLike, colourspace: RGB_Colourspace | str - | Sequence[RGB_Colourspace | str] = "sRGB", + | Sequence[RGB_Colourspace | LiteralRGBColourspace | str] = "sRGB", chromaticity_diagram_callable_CIE1931: Callable = ( plot_RGB_colourspaces_in_chromaticity_diagram_CIE1931 ), @@ -1165,7 +1149,7 @@ def plot_RGB_chromaticities_in_chromaticity_diagram_CIE1960UCS( RGB: ArrayLike, colourspace: RGB_Colourspace | str - | Sequence[RGB_Colourspace | str] = "sRGB", + | Sequence[RGB_Colourspace | LiteralRGBColourspace | str] = "sRGB", chromaticity_diagram_callable_CIE1960UCS: Callable = ( plot_RGB_colourspaces_in_chromaticity_diagram_CIE1960UCS ), @@ -1245,7 +1229,7 @@ def plot_RGB_chromaticities_in_chromaticity_diagram_CIE1976UCS( RGB: ArrayLike, colourspace: RGB_Colourspace | str - | Sequence[RGB_Colourspace | str] = "sRGB", + | Sequence[RGB_Colourspace | LiteralRGBColourspace | str] = "sRGB", chromaticity_diagram_callable_CIE1976UCS: Callable = ( plot_RGB_colourspaces_in_chromaticity_diagram_CIE1976UCS ), @@ -1823,34 +1807,7 @@ def plot_multi_cctfs( @override_style() def plot_constant_hue_loci( data: ArrayLike, - model: Literal[ - "CAM02LCD", - "CAM02SCD", - "CAM02UCS", - "CAM16LCD", - "CAM16SCD", - "CAM16UCS", - "CIE XYZ", - "CIE xyY", - "CIE Lab", - "CIE Luv", - "CIE UCS", - "CIE UVW", - "DIN99", - "Hunter Lab", - "Hunter Rdab", - "ICaCb", - "ICtCp", - "IPT", - "IPT Ragoo 2021", - "IgPgTg", - "Jzazbz", - "OSA UCS", - "Oklab", - "hdr-CIELAB", - "hdr-IPT", - ] - | str = "CIE Lab", + model: LiteralColourspaceModel | str = "CIE Lab", scatter_kwargs: dict | None = None, convert_kwargs: dict | None = None, **kwargs: Any, diff --git a/colour/plotting/section.py b/colour/plotting/section.py index 42a40acd9..61772df7e 100644 --- a/colour/plotting/section.py +++ b/colour/plotting/section.py @@ -30,6 +30,8 @@ ArrayLike, Dict, Literal, + LiteralColourspaceModel, + LiteralRGBColourspace, Real, Sequence, Tuple, @@ -91,33 +93,7 @@ @override_style() def plot_hull_section_colours( hull: trimesh.Trimesh, # pyright: ignore # noqa: F821 - model: Literal[ - "CAM02LCD", - "CAM02SCD", - "CAM02UCS", - "CAM16LCD", - "CAM16SCD", - "CAM16UCS", - "CIE XYZ", - "CIE xyY", - "CIE Lab", - "CIE Luv", - "CIE UCS", - "CIE UVW", - "DIN99", - "Hunter Lab", - "Hunter Rdab", - "ICaCb", - "ICtCp", - "IPT", - "IgPgTg", - "Jzazbz", - "OSA UCS", - "Oklab", - "hdr-CIELAB", - "hdr-IPT", - ] - | str = "CIE xyY", + model: LiteralColourspaceModel | str = "CIE xyY", axis: Literal["+z", "+x", "+y"] | str = "+z", origin: float = 0.5, normalise: bool = True, @@ -297,33 +273,7 @@ def plot_hull_section_colours( @override_style() def plot_hull_section_contour( hull: trimesh.Trimesh, # pyright: ignore # noqa: F821 - model: Literal[ - "CAM02LCD", - "CAM02SCD", - "CAM02UCS", - "CAM16LCD", - "CAM16SCD", - "CAM16UCS", - "CIE XYZ", - "CIE xyY", - "CIE Lab", - "CIE Luv", - "CIE UCS", - "CIE UVW", - "DIN99", - "Hunter Lab", - "Hunter Rdab", - "ICaCb", - "ICtCp", - "IPT", - "IgPgTg", - "Jzazbz", - "OSA UCS", - "Oklab", - "hdr-CIELAB", - "hdr-IPT", - ] - | str = "CIE xyY", + model: LiteralColourspaceModel | str = "CIE xyY", axis: Literal["+z", "+x", "+y"] | str = "+z", origin: float = 0.5, normalise: bool = True, @@ -471,33 +421,7 @@ def plot_visible_spectrum_section( MultiSpectralDistributions | str ] = "CIE 1931 2 Degree Standard Observer", illuminant: SpectralDistribution | str = "D65", - model: Literal[ - "CAM02LCD", - "CAM02SCD", - "CAM02UCS", - "CAM16LCD", - "CAM16SCD", - "CAM16UCS", - "CIE XYZ", - "CIE xyY", - "CIE Lab", - "CIE Luv", - "CIE UCS", - "CIE UVW", - "DIN99", - "Hunter Lab", - "Hunter Rdab", - "ICaCb", - "ICtCp", - "IPT", - "IgPgTg", - "Jzazbz", - "OSA UCS", - "Oklab", - "hdr-CIELAB", - "hdr-IPT", - ] - | str = "CIE xyY", + model: LiteralColourspaceModel | str = "CIE xyY", axis: Literal["+z", "+x", "+y"] | str = "+z", origin: float = 0.5, normalise: bool = True, @@ -643,34 +567,11 @@ def plot_visible_spectrum_section( @required("trimesh") @override_style() def plot_RGB_colourspace_section( - colourspace: RGB_Colourspace | str | Sequence[RGB_Colourspace | str], - model: Literal[ - "CAM02LCD", - "CAM02SCD", - "CAM02UCS", - "CAM16LCD", - "CAM16SCD", - "CAM16UCS", - "CIE XYZ", - "CIE xyY", - "CIE Lab", - "CIE Luv", - "CIE UCS", - "CIE UVW", - "DIN99", - "Hunter Lab", - "Hunter Rdab", - "ICaCb", - "ICtCp", - "IPT", - "IgPgTg", - "Jzazbz", - "OSA UCS", - "Oklab", - "hdr-CIELAB", - "hdr-IPT", - ] - | str = "CIE xyY", + colourspace: RGB_Colourspace + | LiteralRGBColourspace + | str + | Sequence[RGB_Colourspace | LiteralRGBColourspace | str], + model: LiteralColourspaceModel | str = "CIE xyY", axis: Literal["+z", "+x", "+y"] | str = "+z", origin: float = 0.5, normalise: bool = True, diff --git a/colour/plotting/volume.py b/colour/plotting/volume.py index a92737513..22d2b4c11 100644 --- a/colour/plotting/volume.py +++ b/colour/plotting/volume.py @@ -27,6 +27,8 @@ ArrayLike, List, Literal, + LiteralColourspaceModel, + LiteralRGBColourspace, NDArrayFloat, Sequence, Tuple, @@ -418,34 +420,11 @@ def RGB_identity_cube( @override_style() def plot_RGB_colourspaces_gamuts( - colourspaces: RGB_Colourspace | str | Sequence[RGB_Colourspace | str], - model: Literal[ - "CAM02LCD", - "CAM02SCD", - "CAM02UCS", - "CAM16LCD", - "CAM16SCD", - "CAM16UCS", - "CIE XYZ", - "CIE xyY", - "CIE Lab", - "CIE Luv", - "CIE UCS", - "CIE UVW", - "DIN99", - "Hunter Lab", - "Hunter Rdab", - "ICaCb", - "ICtCp", - "IPT", - "IgPgTg", - "Jzazbz", - "OSA UCS", - "Oklab", - "hdr-CIELAB", - "hdr-IPT", - ] - | str = "CIE xyY", + colourspaces: RGB_Colourspace + | LiteralRGBColourspace + | str + | Sequence[RGB_Colourspace | LiteralRGBColourspace | str], + model: LiteralColourspaceModel | str = "CIE xyY", segments: int = 8, show_grid: bool = True, grid_segments: int = 10, @@ -694,37 +673,11 @@ def plot_RGB_scatter( RGB: ArrayLike, colourspace: RGB_Colourspace | str - | Sequence[RGB_Colourspace | str] = "sRGB", - model: Literal[ - "CAM02LCD", - "CAM02SCD", - "CAM02UCS", - "CAM16LCD", - "CAM16SCD", - "CAM16UCS", - "CIE XYZ", - "CIE xyY", - "CIE Lab", - "CIE Luv", - "CIE UCS", - "CIE UVW", - "DIN99", - "Hunter Lab", - "Hunter Rdab", - "ICaCb", - "ICtCp", - "IPT", - "IgPgTg", - "Jzazbz", - "OSA UCS", - "Oklab", - "hdr-CIELAB", - "hdr-IPT", - ] - | str = "CIE xyY", + | Sequence[RGB_Colourspace | LiteralRGBColourspace | str] = "sRGB", + model: LiteralColourspaceModel | str = "CIE xyY", colourspaces: RGB_Colourspace | str - | Sequence[RGB_Colourspace | str] + | Sequence[RGB_Colourspace | LiteralRGBColourspace | str] | None = None, segments: int = 8, show_grid: bool = True, diff --git a/colour/volume/rgb.py b/colour/volume/rgb.py index 627d0ded0..7a717c138 100644 --- a/colour/volume/rgb.py +++ b/colour/volume/rgb.py @@ -22,7 +22,7 @@ from colour.hints import ( ArrayLike, Callable, - Literal, + LiteralChromaticAdaptationTransform, NDArrayFloat, ) from colour.models import ( @@ -78,20 +78,7 @@ def sample_RGB_colourspace_volume_MonteCarlo( illuminant_Lab: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str | None = "CAT02", random_generator: Callable = random_triplet_generator, @@ -219,20 +206,7 @@ def RGB_colourspace_volume_MonteCarlo( illuminant_Lab: ArrayLike = CCS_ILLUMINANTS[ "CIE 1931 2 Degree Standard Observer" ]["D65"], - chromatic_adaptation_transform: Literal[ - "Bianco 2010", - "Bianco PC 2010", - "Bradford", - "CAT02 Brill 2008", - "CAT02", - "CAT16", - "CMCCAT2000", - "CMCCAT97", - "Fairchild", - "Sharp", - "Von Kries", - "XYZ Scaling", - ] + chromatic_adaptation_transform: LiteralChromaticAdaptationTransform | str | None = "CAT02", random_generator: Callable = random_triplet_generator, diff --git a/docs/colour.hints.rst b/docs/colour.hints.rst index e8aeaebec..b0e03bf41 100644 --- a/docs/colour.hints.rst +++ b/docs/colour.hints.rst @@ -56,46 +56,16 @@ Annotation Type Hints ProtocolExtrapolator ProtocolLUTSequenceItem LiteralWarning - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + LiteralChromaticAdaptationTransform + LiteralColourspaceModel + LiteralRGBColourspace + LiteralLogEncoding + LiteralLogDecoding + LiteralOETF + LiteralOETFInverse + LiteralEOTF + LiteralEOTFInverse + LiteralCCTFEncoding + LiteralCCTFDecoding + LiteralOOTF + LiteralOOTFInverse diff --git a/tasks.py b/tasks.py index 5ee923bf9..6b38a42d2 100644 --- a/tasks.py +++ b/tasks.py @@ -11,6 +11,7 @@ import os import re import uuid +from textwrap import dedent import colour from colour.utilities import message_box @@ -37,6 +38,7 @@ "PYPI_PACKAGE_NAME", "PYPI_ARCHIVE_NAME", "BIBLIOGRAPHY_NAME", + "literalise", "clean", "formatting", "quality", @@ -66,6 +68,56 @@ BIBLIOGRAPHY_NAME: str = "BIBLIOGRAPHY.bib" +@task +def literalise(ctx: Context): + """ + Write various literals in the `colour.hints` module. + + Parameters + ---------- + ctx + Context. + """ + + path_hints = os.path.join( + os.path.dirname(__file__), "colour", "hints", "__init__.py" + ) + + with open(path_hints) as file_hints: + content = file_hints.read() + + content = re.sub( + "# LITERALISE::BEGIN.*?# LITERALISE::END", + dedent( + f""" + # LITERALISE::BEGIN + LiteralChromaticAdaptationTransform = \ + Literal{sorted(colour.CHROMATIC_ADAPTATION_TRANSFORMS)} + LiteralColourspaceModel = Literal{sorted(colour.COLOURSPACE_MODELS)} + LiteralRGBColourspace = Literal{sorted(colour.RGB_COLOURSPACES.keys())} + LiteralLogEncoding = Literal{sorted(colour.LOG_ENCODINGS)} + LiteralLogDecoding = Literal{sorted(colour.LOG_DECODINGS)} + LiteralOETF = Literal{sorted(colour.OETFS)} + LiteralOETFInverse = Literal{sorted(colour.OETF_INVERSES)} + LiteralEOTF = Literal{sorted(colour.EOTFS)} + LiteralEOTFInverse = Literal{sorted(colour.EOTF_INVERSES)} + LiteralCCTFEncoding = Literal{sorted(colour.CCTF_ENCODINGS)} + LiteralCCTFDecoding = Literal{sorted(colour.CCTF_DECODINGS)} + LiteralOOTF = Literal{sorted(colour.OOTFS)} + LiteralOOTFInverse = Literal{sorted(colour.OOTF_INVERSES)} + # LITERALISE::END + """ + ).strip(), + content, + flags=re.DOTALL, + ) + + with open(path_hints, "w") as file_hints: + file_hints.write(content) + + ctx.run(f"pre-commit run --files {path_hints}") + + @task def clean( ctx: Context, @@ -347,7 +399,7 @@ def requirements(ctx: Context): ) -@task(clean, preflight, docs, todo, requirements) +@task(literalise, clean, preflight, docs, todo, requirements) def build(ctx: Context): """ Build the project and runs dependency tasks, i.e. *docs*, *todo*, and From b6ff8637e5d13204df3002e52808d9cf76c818ab Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Fri, 15 Sep 2023 15:17:22 +1200 Subject: [PATCH 2/4] Implement `literalise` run via pre-commit hooks. --- ...tinuous-integration-quality-unit-tests.yml | 2 + .pre-commit-config.yaml | 8 ++ tasks.py | 54 +----------- utilities/literalise.py | 84 +++++++++++++++++++ 4 files changed, 95 insertions(+), 53 deletions(-) create mode 100755 utilities/literalise.py diff --git a/.github/workflows/continuous-integration-quality-unit-tests.yml b/.github/workflows/continuous-integration-quality-unit-tests.yml index 3e2b92354..98d9213bc 100644 --- a/.github/workflows/continuous-integration-quality-unit-tests.yml +++ b/.github/workflows/continuous-integration-quality-unit-tests.yml @@ -63,6 +63,8 @@ jobs: ln -s /usr/local/Cellar/openimageio/*/lib/python*/site-packages/OpenImageIO/OpenImageIO*.so /Library/Frameworks/Python.framework/Versions/${{ matrix.python-version }}/lib/python${{ matrix.python-version }}/site-packages/OpenImageIO.so shell: bash - name: Pre-Commit (All Files) + # "poetry" is not available on Windows from within "pre-commit". + if: matrix.os == 'macOS-latest' || matrix.os == 'ubuntu-22.04' run: | poetry run pre-commit run --all-files shell: bash diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b527df66f..510e31749 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,12 @@ repos: +- repo: local + hooks: + - id: literalise + name: literalise + entry: poetry run python utilities/literalise.py + always_run: true + language: system + types: [ python ] - repo: https://github.com/ikamensh/flynt/ rev: '1.0.1' hooks: diff --git a/tasks.py b/tasks.py index 6b38a42d2..5ee923bf9 100644 --- a/tasks.py +++ b/tasks.py @@ -11,7 +11,6 @@ import os import re import uuid -from textwrap import dedent import colour from colour.utilities import message_box @@ -38,7 +37,6 @@ "PYPI_PACKAGE_NAME", "PYPI_ARCHIVE_NAME", "BIBLIOGRAPHY_NAME", - "literalise", "clean", "formatting", "quality", @@ -68,56 +66,6 @@ BIBLIOGRAPHY_NAME: str = "BIBLIOGRAPHY.bib" -@task -def literalise(ctx: Context): - """ - Write various literals in the `colour.hints` module. - - Parameters - ---------- - ctx - Context. - """ - - path_hints = os.path.join( - os.path.dirname(__file__), "colour", "hints", "__init__.py" - ) - - with open(path_hints) as file_hints: - content = file_hints.read() - - content = re.sub( - "# LITERALISE::BEGIN.*?# LITERALISE::END", - dedent( - f""" - # LITERALISE::BEGIN - LiteralChromaticAdaptationTransform = \ - Literal{sorted(colour.CHROMATIC_ADAPTATION_TRANSFORMS)} - LiteralColourspaceModel = Literal{sorted(colour.COLOURSPACE_MODELS)} - LiteralRGBColourspace = Literal{sorted(colour.RGB_COLOURSPACES.keys())} - LiteralLogEncoding = Literal{sorted(colour.LOG_ENCODINGS)} - LiteralLogDecoding = Literal{sorted(colour.LOG_DECODINGS)} - LiteralOETF = Literal{sorted(colour.OETFS)} - LiteralOETFInverse = Literal{sorted(colour.OETF_INVERSES)} - LiteralEOTF = Literal{sorted(colour.EOTFS)} - LiteralEOTFInverse = Literal{sorted(colour.EOTF_INVERSES)} - LiteralCCTFEncoding = Literal{sorted(colour.CCTF_ENCODINGS)} - LiteralCCTFDecoding = Literal{sorted(colour.CCTF_DECODINGS)} - LiteralOOTF = Literal{sorted(colour.OOTFS)} - LiteralOOTFInverse = Literal{sorted(colour.OOTF_INVERSES)} - # LITERALISE::END - """ - ).strip(), - content, - flags=re.DOTALL, - ) - - with open(path_hints, "w") as file_hints: - file_hints.write(content) - - ctx.run(f"pre-commit run --files {path_hints}") - - @task def clean( ctx: Context, @@ -399,7 +347,7 @@ def requirements(ctx: Context): ) -@task(literalise, clean, preflight, docs, todo, requirements) +@task(clean, preflight, docs, todo, requirements) def build(ctx: Context): """ Build the project and runs dependency tasks, i.e. *docs*, *todo*, and diff --git a/utilities/literalise.py b/utilities/literalise.py new file mode 100755 index 000000000..91022275e --- /dev/null +++ b/utilities/literalise.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python +""" +Literalise +========== +""" + +from __future__ import annotations + +import os +import re +from textwrap import dedent + +import sys +import subprocess + +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) + +import colour # noqa: E402 + +__copyright__ = "Copyright 2013 Colour Developers" +__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause" +__maintainer__ = "Colour Developers" +__email__ = "colour-developers@colour-science.org" +__status__ = "Production" + +__all__ = [ + "PATH_MODULE_HINTS", + "literalise", +] + +PATH_MODULE_HINTS = os.path.join( + os.path.dirname(__file__), "..", "colour", "hints", "__init__.py" +) + + +def literalise(path_module_hints: str = PATH_MODULE_HINTS): + """ + Write various literals in the `colour.hints` module. + + Parameters + ---------- + path_module_hints + Path to the hints module. + """ + + with open(path_module_hints) as file_module_hints: + content = file_module_hints.read() + + content = re.sub( + "# LITERALISE::BEGIN.*?# LITERALISE::END", + dedent( + f""" + # LITERALISE::BEGIN + LiteralChromaticAdaptationTransform = \ + Literal{sorted(colour.CHROMATIC_ADAPTATION_TRANSFORMS)} + LiteralColourspaceModel = Literal{sorted(colour.COLOURSPACE_MODELS)} + LiteralRGBColourspace = Literal{sorted(colour.RGB_COLOURSPACES.keys())} + LiteralLogEncoding = Literal{sorted(colour.LOG_ENCODINGS)} + LiteralLogDecoding = Literal{sorted(colour.LOG_DECODINGS)} + LiteralOETF = Literal{sorted(colour.OETFS)} + LiteralOETFInverse = Literal{sorted(colour.OETF_INVERSES)} + LiteralEOTF = Literal{sorted(colour.EOTFS)} + LiteralEOTFInverse = Literal{sorted(colour.EOTF_INVERSES)} + LiteralCCTFEncoding = Literal{sorted(colour.CCTF_ENCODINGS)} + LiteralCCTFDecoding = Literal{sorted(colour.CCTF_DECODINGS)} + LiteralOOTF = Literal{sorted(colour.OOTFS)} + LiteralOOTFInverse = Literal{sorted(colour.OOTF_INVERSES)} + # LITERALISE::END + """ + ).strip(), + content, + flags=re.DOTALL, + ) + + with open(path_module_hints, "w") as file_module_hints: + file_module_hints.write(content) + + subprocess.run(["black", PATH_MODULE_HINTS]) # noqa: PLW1510, S603, S607 + + +if __name__ == "__main__": + os.chdir(os.path.dirname(__file__)) + + literalise() From effcdfec8f8e436fa0d6fd84bd25457233f59166 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Fri, 15 Sep 2023 18:16:38 +1200 Subject: [PATCH 3/4] Revert to use `invoke` triggered `literalise`. --- ...tinuous-integration-quality-unit-tests.yml | 2 -- .pre-commit-config.yaml | 8 ------- tasks.py | 21 ++++++++++++++++++- utilities/literalise.py | 3 --- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.github/workflows/continuous-integration-quality-unit-tests.yml b/.github/workflows/continuous-integration-quality-unit-tests.yml index 98d9213bc..3e2b92354 100644 --- a/.github/workflows/continuous-integration-quality-unit-tests.yml +++ b/.github/workflows/continuous-integration-quality-unit-tests.yml @@ -63,8 +63,6 @@ jobs: ln -s /usr/local/Cellar/openimageio/*/lib/python*/site-packages/OpenImageIO/OpenImageIO*.so /Library/Frameworks/Python.framework/Versions/${{ matrix.python-version }}/lib/python${{ matrix.python-version }}/site-packages/OpenImageIO.so shell: bash - name: Pre-Commit (All Files) - # "poetry" is not available on Windows from within "pre-commit". - if: matrix.os == 'macOS-latest' || matrix.os == 'ubuntu-22.04' run: | poetry run pre-commit run --all-files shell: bash diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 510e31749..b527df66f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,4 @@ repos: -- repo: local - hooks: - - id: literalise - name: literalise - entry: poetry run python utilities/literalise.py - always_run: true - language: system - types: [ python ] - repo: https://github.com/ikamensh/flynt/ rev: '1.0.1' hooks: diff --git a/tasks.py b/tasks.py index 5ee923bf9..8987b028e 100644 --- a/tasks.py +++ b/tasks.py @@ -37,6 +37,7 @@ "PYPI_PACKAGE_NAME", "PYPI_ARCHIVE_NAME", "BIBLIOGRAPHY_NAME", + "literalise", "clean", "formatting", "quality", @@ -66,6 +67,24 @@ BIBLIOGRAPHY_NAME: str = "BIBLIOGRAPHY.bib" +@task +def literalise(ctx: Context): + """ + Write various literals in the `colour.hints` module. + + Parameters + ---------- + ctx + Context. + """ + + message_box("Literalising...") + with ctx.cd("utilities"): + ctx.run("./literalise.py") + + ctx.run("pre-commit run --files colour/hints/__init__.py", warn=True) + + @task def clean( ctx: Context, @@ -347,7 +366,7 @@ def requirements(ctx: Context): ) -@task(clean, preflight, docs, todo, requirements) +@task(literalise, clean, preflight, docs, todo, requirements) def build(ctx: Context): """ Build the project and runs dependency tasks, i.e. *docs*, *todo*, and diff --git a/utilities/literalise.py b/utilities/literalise.py index 91022275e..c436ed23a 100755 --- a/utilities/literalise.py +++ b/utilities/literalise.py @@ -11,7 +11,6 @@ from textwrap import dedent import sys -import subprocess sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) @@ -75,8 +74,6 @@ def literalise(path_module_hints: str = PATH_MODULE_HINTS): with open(path_module_hints, "w") as file_module_hints: file_module_hints.write(content) - subprocess.run(["black", PATH_MODULE_HINTS]) # noqa: PLW1510, S603, S607 - if __name__ == "__main__": os.chdir(os.path.dirname(__file__)) From 1d0caf65dcd28788242398864a4ee5a879f37acb Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Fri, 15 Sep 2023 19:40:01 +1200 Subject: [PATCH 4/4] Fix various broken unit and doctests under "Matplotlib" 3.8.0. --- colour/plotting/volume.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colour/plotting/volume.py b/colour/plotting/volume.py index 22d2b4c11..f949c260d 100644 --- a/colour/plotting/volume.py +++ b/colour/plotting/volume.py @@ -805,7 +805,7 @@ def plot_RGB_scatter( points[..., 0], points[..., 1], points[..., 2], - color=np.reshape(RGB, (-1, 3)), + c=np.reshape(RGB, (-1, 3)), s=points_size, zorder=CONSTANTS_COLOUR_STYLE.zorder.midground_scatter, )