Skip to content

Commit

Permalink
Move colour_clf_io.ExponentStyle, colour_clf_io.LogStyle and `col…
Browse files Browse the repository at this point in the history
…our_clf_io.RangeStyle` enumerations to `colour_clf_io.values` module.
  • Loading branch information
KelSolaar committed Jan 12, 2025
1 parent 17400ec commit b053af7
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 207 deletions.
22 changes: 11 additions & 11 deletions colour_clf_io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@
Array,
CalibrationInfo,
ExponentParams,
ExponentStyle,
Info,
LogParams,
LogStyle,
RangeStyle,
SatNode,
SOPNode,
)
Expand All @@ -51,11 +48,14 @@
Range,
)
from .values import (
ASC_CDL_Style,
ASC_CDLStyle,
BitDepth,
Channel,
ExponentStyle,
Interpolation1D,
Interpolation3D,
LogStyle,
RangeStyle,
)

__author__ = "Colour Developers"
Expand All @@ -68,14 +68,11 @@
__all__ = [
"Array",
"CalibrationInfo",
"ExponentParams",
"ExponentStyle",
"SOPNode",
"SatNode",
"Info",
"LogParams",
"LogStyle",
"RangeStyle",
"SatNode",
"SOPNode",
"ExponentParams",
]
__all__ += ["ProcessList"]
__all__ += [
Expand All @@ -89,11 +86,14 @@
"Range",
]
__all__ += [
"ASC_CDL_Style",
"BitDepth",
"Channel",
"Interpolation1D",
"Interpolation3D",
"RangeStyle",
"LogStyle",
"ExponentStyle",
"ASC_CDLStyle",
]

__application_name__ = "Colour - CLF IO"
Expand Down
173 changes: 0 additions & 173 deletions colour_clf_io/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from __future__ import annotations

import enum
import typing
from dataclasses import dataclass

Expand Down Expand Up @@ -42,9 +41,6 @@
__all__ = [
"Array",
"CalibrationInfo",
"RangeStyle",
"LogStyle",
"ExponentStyle",
"SOPNode",
"SatNode",
"Info",
Expand Down Expand Up @@ -232,175 +228,6 @@ def from_xml(
return CalibrationInfo(**attributes)


class RangeStyle(enum.Enum):
"""
Represent the valid values of the *style* attribute of a
:class:`colour_clf_io.Range` *Process Node*.
Attributes
----------
- :attr:`~colour_clf_io.RangeStyle.CLAMP`
- :attr:`~colour_clf_io.RangeStyle.NO_CLAMP`
References
----------
- https://docs.acescentral.com/specifications/clf/#range
"""

CLAMP = "Clamp"
"""
Clamping is applied upon the result of the scale and offset expressed by
the result of the non-clamping Range equation."""

NO_CLAMP = "noClamp"
"""
Scale and offset is applied without clamping (i.e., values below
minOutValue or above maxOutValue are preserved).
"""


class LogStyle(enum.Enum):
"""
Represent the valid values of the *style* attribute of a
:class:`colour_clf_io.Log` *Process Node*.
Attributes
----------
- :attr:`~colour_clf_io.LogStyle.LOG_10`
- :attr:`~colour_clf_io.LogStyle.ANTI_LOG_10`
- :attr:`~colour_clf_io.LogStyle.LOG_2`
- :attr:`~colour_clf_io.LogStyle.ANTI_LOG_2`
- :attr:`~colour_clf_io.LogStyle.LIN_TO_LOG`
- :attr:`~colour_clf_io.LogStyle.LOG_TO_LIN`
- :attr:`~colour_clf_io.LogStyle.CAMERA_LIN_TO_LOG`
- :attr:`~colour_clf_io.LogStyle.CAMERA_LOG_TO_LIN`
References
----------
- https://docs.acescentral.com/specifications/clf/#processList
"""

LOG_10 = "log10"
"""Apply a base 10 logarithm."""

ANTI_LOG_10 = "antiLog10"
"""Apply a base 10 anti-logarithm."""

LOG_2 = "log2"
"""Apply a base 2 logarithm."""

ANTI_LOG_2 = "antiLog2"
"""Apply a base 2 anti-logarithm."""

LIN_TO_LOG = "linToLog"
"""Apply a logarithm."""

LOG_TO_LIN = "logToLin"
"""Apply an anti-logarithm."""

CAMERA_LIN_TO_LOG = "cameraLinToLog"
"""
Apply a piecewise function with logarithmic and linear segments on linear
values, converting them to non-linear values.
"""

CAMERA_LOG_TO_LIN = "cameraLogToLin"
"""
Applies a piecewise function with logarithmic and linear segments on
non-linear values, converting them to linear values.
"""


class ExponentStyle(enum.Enum):
"""
Represent the valid values of the *style* attribute of a
:class:`colour_clf_io.Exponent` *Process Node*.
Attributes
----------
- :attr:`~colour_clf_io.ExponentStyle.BASIC_FWD`
- :attr:`~colour_clf_io.ExponentStyle.BASIC_REV`
- :attr:`~colour_clf_io.ExponentStyle.BASIC_MIRROR_FWD`
- :attr:`~colour_clf_io.ExponentStyle.BASIC_MIRROR_REV`
- :attr:`~colour_clf_io.ExponentStyle.BASIC_PASS_THRU_FWD`
- :attr:`~colour_clf_io.ExponentStyle.BASIC_PASS_THRU_REV`
- :attr:`~colour_clf_io.ExponentStyle.MON_CURVE_FWD`
- :attr:`~colour_clf_io.ExponentStyle.MON_CURVE_REV`
- :attr:`~colour_clf_io.ExponentStyle.MON_CURVE_MIRROR_FWD`
- :attr:`~colour_clf_io.ExponentStyle.MON_CURVE_MIRROR_REV`
References
----------
- https://docs.acescentral.com/specifications/clf/#exponent
"""

BASIC_FWD = "basicFwd"
"""
Apply a power law using the exponent value specified in the ExponentParams
element.
"""

BASIC_REV = "basicRev"
"""
Apply a power law using the exponent value specified in the ExponentParams
element.
"""

BASIC_MIRROR_FWD = "basicMirrorFwd"
"""
Apply a basic power law using the exponent value specified in the
ExponentParams element for values greater than or equal to zero and mirror
the function for values less than zero (i.e., rotationally symmetric around
the origin).
"""

BASIC_MIRROR_REV = "basicMirrorRev"
"""
Apply a basic power law using the exponent value specified in the
ExponentParams element for values greater than or equal to zero and mirror
the function for values less than zero (i.e., rotationally symmetric around
the origin).
"""

BASIC_PASS_THRU_FWD = "basicPassThruFwd" # noqa: S105
"""
Apply a basic power law using the exponent value specified in the
ExponentParams element for values greater than or equal to zero and passes
values less than zero unchanged.
"""

BASIC_PASS_THRU_REV = "basicPassThruRev" # noqa: S105
"""
Apply a basic power law using the exponent value specified in the
ExponentParams element for values greater than or equal to zero and passes
values less than zero unchanged.
"""

MON_CURVE_FWD = "monCurveFwd"
"""
Apply a power law function with a linear segment near the origin.
"""

MON_CURVE_REV = "monCurveRev"
"""
Apply a power law function with a linear segment near the origin.
"""

MON_CURVE_MIRROR_FWD = "monCurveMirrorFwd"
"""
Apply a power law function with a linear segment near the origin and
mirror the function for values less than zero (i.e., rotationally symmetric
around the origin).
"""

MON_CURVE_MIRROR_REV = "monCurveMirrorRev"
"""
Apply a power law function with a linear segment near the origin and mirror
the function for values less than zero (i.e., rotationally symmetric around
the origin).
"""


@dataclass
class SOPNode(XMLParsable):
"""
Expand Down
12 changes: 6 additions & 6 deletions colour_clf_io/process_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
from colour_clf_io.elements import (
Array,
ExponentParams,
ExponentStyle,
LogParams,
LogStyle,
RangeStyle,
SatNode,
SOPNode,
)
Expand All @@ -39,10 +36,13 @@
sliding_window,
)
from colour_clf_io.values import (
ASC_CDL_Style,
ASC_CDLStyle,
BitDepth,
ExponentStyle,
Interpolation1D,
Interpolation3D,
LogStyle,
RangeStyle,
)

__author__ = "Colour Developers"
Expand Down Expand Up @@ -677,7 +677,7 @@ class ASC_CDL(ProcessNode):
- https://docs.acescentral.com/specifications/clf/#asc_cdl
"""

style: ASC_CDL_Style
style: ASC_CDLStyle
sopnode: SOPNode | None
sat_node: SatNode | None

Expand Down Expand Up @@ -717,7 +717,7 @@ def from_xml(
return None

super_args = ProcessNode.parse_attributes(xml, config)
style = ASC_CDL_Style(xml.get("style"))
style = ASC_CDLStyle(xml.get("style"))
sop_node = SOPNode.from_xml(child_element(xml, "SOPNode", config), config) # pyright: ignore
sat_node = SatNode.from_xml(child_element(xml, "SatNode", config), config) # pyright: ignore

Expand Down
14 changes: 7 additions & 7 deletions colour_clf_io/tests/test_clf_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def test_log_example_1(self) -> None:
assert node.in_bit_depth == colour_clf_io.values.BitDepth.f16
assert node.out_bit_depth == colour_clf_io.values.BitDepth.f16
assert node.description == "Base 10 Logarithm"
assert node.style == colour_clf_io.elements.LogStyle.LOG_10
assert node.style == colour_clf_io.values.LogStyle.LOG_10
assert node.log_params == []

def test_log_example_2(self) -> None:
Expand Down Expand Up @@ -365,7 +365,7 @@ def test_log_example_2(self) -> None:
assert node.in_bit_depth == colour_clf_io.values.BitDepth.f32
assert node.out_bit_depth == colour_clf_io.values.BitDepth.f32
assert node.description == "Linear to DJI D-Log"
assert node.style == colour_clf_io.elements.LogStyle.CAMERA_LIN_TO_LOG
assert node.style == colour_clf_io.values.LogStyle.CAMERA_LIN_TO_LOG
assert node.log_params[0].base is not None
np.testing.assert_allclose(node.log_params[0].base, 10.0)
assert node.log_params[0].log_side_slope is not None
Expand Down Expand Up @@ -406,7 +406,7 @@ def test_exponent_example_1(self) -> None:
assert node.in_bit_depth == colour_clf_io.values.BitDepth.f32
assert node.out_bit_depth == colour_clf_io.values.BitDepth.f32
assert node.description == "Basic 2.2 Gamma"
assert node.style == colour_clf_io.elements.ExponentStyle.BASIC_FWD
assert node.style == colour_clf_io.values.ExponentStyle.BASIC_FWD
np.testing.assert_allclose(node.exponent_params[0].exponent, 2.2)

def test_exponent_example_2(self) -> None:
Expand Down Expand Up @@ -434,7 +434,7 @@ def test_exponent_example_2(self) -> None:
assert node.in_bit_depth == colour_clf_io.values.BitDepth.f32
assert node.out_bit_depth == colour_clf_io.values.BitDepth.f32
assert node.description == "EOTF (sRGB)"
assert node.style, colour_clf_io.elements.ExponentStyle.MON_CURVE_FWD
assert node.style, colour_clf_io.values.ExponentStyle.MON_CURVE_FWD
assert node.exponent_params[0].exponent is not None
np.testing.assert_allclose(node.exponent_params[0].exponent, 2.4)
assert node.exponent_params[0].offset is not None
Expand Down Expand Up @@ -465,7 +465,7 @@ def test_exponent_example_3(self) -> None:
assert node.in_bit_depth == colour_clf_io.values.BitDepth.f32
assert node.out_bit_depth == colour_clf_io.values.BitDepth.f32
assert node.description == "CIE L*"
assert node.style == colour_clf_io.elements.ExponentStyle.MON_CURVE_REV
assert node.style == colour_clf_io.values.ExponentStyle.MON_CURVE_REV
assert node.exponent_params[0].exponent is not None
np.testing.assert_allclose(node.exponent_params[0].exponent, 3.0)
assert node.exponent_params[0].offset is not None
Expand Down Expand Up @@ -496,7 +496,7 @@ def test_exponent_example_4(self) -> None:
assert node.in_bit_depth == colour_clf_io.values.BitDepth.f32
assert node.out_bit_depth == colour_clf_io.values.BitDepth.f32
assert node.description == "Rec. 709 OETF"
assert node.style == colour_clf_io.elements.ExponentStyle.MON_CURVE_REV
assert node.style == colour_clf_io.values.ExponentStyle.MON_CURVE_REV
assert node.exponent_params[0].exponent is not None
np.testing.assert_allclose(node.exponent_params[0].exponent, 2.2222222222222222)
assert node.exponent_params[0].offset is not None
Expand Down Expand Up @@ -534,7 +534,7 @@ def test_ASC_CDL_example(self) -> None:
assert node.in_bit_depth == colour_clf_io.values.BitDepth.f16
assert node.out_bit_depth == colour_clf_io.values.BitDepth.f16
assert node.description == "scene 1 exterior look"
assert node.style == colour_clf_io.values.ASC_CDL_Style.FWD
assert node.style == colour_clf_io.values.ASC_CDLStyle.FWD
assert node.sopnode is not None
assert node.sopnode.slope == (1.000000, 1.000000, 0.900000)
assert node.sopnode.offset == (-0.030000, -0.020000, 0.000000)
Expand Down
Loading

0 comments on commit b053af7

Please sign in to comment.