Skip to content

Commit

Permalink
Implement initial support for "AMF" relations.
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Mansencal <[email protected]>
  • Loading branch information
KelSolaar committed Aug 12, 2023
1 parent 3a0f1cb commit dbc462e
Show file tree
Hide file tree
Showing 12 changed files with 395 additions and 125 deletions.
3 changes: 2 additions & 1 deletion docs/opencolorio_config_aces.config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Reference Configuration
classify_aces_ctl_transforms
discover_aces_ctl_transforms
filter_ctl_transforms
generate_amf_relations
print_aces_taxonomy
unclassify_ctl_transforms

Expand Down Expand Up @@ -100,7 +101,7 @@ Reference Configuration
.. autosummary::
:toctree: generated/

ColorspaceDescriptionStyle
DescriptionStyle
version_config_mapping_file
generate_config_aces

Expand Down
4 changes: 2 additions & 2 deletions opencolorio_config_aces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
version_config_mapping_file,
)
from .config import (
ColorspaceDescriptionStyle,
DescriptionStyle,
generate_config_aces,
)
from .config import generate_config_cg, generate_config_studio
Expand Down Expand Up @@ -114,7 +114,7 @@
"version_config_mapping_file",
]
__all__ += [
"ColorspaceDescriptionStyle",
"DescriptionStyle",
"generate_config_aces",
]
__all__ += ["generate_config_cg", "generate_config_studio"]
Expand Down
33 changes: 31 additions & 2 deletions opencolorio_config_aces/clf/discover/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ class CLFTransform:
*CLF* transform family, e.g. *aces*
genus : unicode, optional
*CLF* transform genus, e.g. *undefined*
siblings : array_like, optional
*CLF* transform siblings, e.g. inverse transform.
Attributes
----------
Expand All @@ -497,7 +499,10 @@ class CLFTransform:
__ne__
"""

def __init__(self, path, family=None, genus=None):
def __init__(self, path, family=None, genus=None, siblings=None):
if siblings is None:
siblings = []

self._path = os.path.abspath(os.path.normpath(path))

self._code = None
Expand All @@ -510,6 +515,7 @@ def __init__(self, path, family=None, genus=None):

self._family = family
self._genus = genus
self._siblings = siblings

self._parse()

Expand Down Expand Up @@ -692,6 +698,24 @@ def genus(self):

return self._genus

@property
def siblings(self):
"""
Getter property for the *CLF* transform siblings, e.g. inverse
transform.
Returns
-------
unicode
*CLF* transform siblings.
Notes
-----
- This property is read only.
"""

return self._siblings

def __getattr__(self, item):
"""
Reimplement the :meth:`object.__getattr__` so that unsuccessful
Expand Down Expand Up @@ -999,7 +1023,12 @@ def stem(path):
clf_transform_pairs[basename][
"inverse_transform"
] = clf_transforms[1]

clf_transform_pairs[basename]["forward_transform"].siblings.append(
clf_transform_pairs[basename]["inverse_transform"]
)
clf_transform_pairs[basename]["inverse_transform"].siblings.append(
clf_transform_pairs[basename]["forward_transform"]
)
return clf_transform_pairs


Expand Down
6 changes: 4 additions & 2 deletions opencolorio_config_aces/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
discover_aces_ctl_transforms,
filter_ctl_transforms,
filter_nodes,
generate_amf_relations,
node_to_ctl_transform,
plot_aces_conversion_graph,
print_aces_taxonomy,
Expand All @@ -38,7 +39,7 @@
version_config_mapping_file,
)
from .reference import (
ColorspaceDescriptionStyle,
DescriptionStyle,
generate_config_aces,
)
from .cg import generate_config_cg
Expand Down Expand Up @@ -73,6 +74,7 @@
"discover_aces_ctl_transforms",
"filter_ctl_transforms",
"filter_nodes",
"generate_amf_relations",
"node_to_ctl_transform",
"plot_aces_conversion_graph",
"print_aces_taxonomy",
Expand All @@ -81,7 +83,7 @@
"version_config_mapping_file",
]
__all__ += [
"ColorspaceDescriptionStyle",
"DescriptionStyle",
"generate_config_aces",
]
__all__ += ["generate_config_cg"]
Expand Down
90 changes: 49 additions & 41 deletions opencolorio_config_aces/config/cg/generate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
named_transform_factory,
)
from opencolorio_config_aces.config.reference import (
ColorspaceDescriptionStyle,
DescriptionStyle,
version_aces_dev,
version_config_mapping_file,
generate_config_aces,
Expand Down Expand Up @@ -64,6 +64,7 @@
"URL_EXPORT_TRANSFORMS_MAPPING_FILE_CG",
"PATH_TRANSFORMS_MAPPING_FILE_CG",
"FILTERED_NAMESPACES",
"DESCRIPTION_CLF_TRANSFORM_ID",
"is_reference",
"clf_transform_to_colorspace_name",
"clf_transform_to_description",
Expand Down Expand Up @@ -108,6 +109,13 @@
FILTERED_NAMESPACES : tuple
"""

DESCRIPTION_CLF_TRANSFORM_ID = "CLFtransformID: {}"
"""
Template for the description of an *CLFtransformID*.
DESCRIPTION_CLF_TRANSFORM_ID : unicode
"""


def is_reference(name):
"""
Expand Down Expand Up @@ -155,7 +163,7 @@ def clf_transform_to_colorspace_name(clf_transform):


def clf_transform_to_description(
clf_transform, describe=ColorspaceDescriptionStyle.LONG_UNION
clf_transform, describe=DescriptionStyle.LONG_UNION
):
"""
Generate the *OpenColorIO* `Colorspace` or `NamedTransform` description for
Expand All @@ -176,13 +184,13 @@ def clf_transform_to_description(
"""

description = None
if describe != ColorspaceDescriptionStyle.NONE:
if describe != DescriptionStyle.NONE:
description = []

if describe in (
ColorspaceDescriptionStyle.OPENCOLORIO,
ColorspaceDescriptionStyle.SHORT,
ColorspaceDescriptionStyle.SHORT_UNION,
DescriptionStyle.OPENCOLORIO,
DescriptionStyle.SHORT,
DescriptionStyle.SHORT_UNION,
):
if clf_transform.description is not None:
description.append(
Expand All @@ -191,16 +199,20 @@ def clf_transform_to_description(
)

elif describe in ( # noqa: SIM102
ColorspaceDescriptionStyle.OPENCOLORIO,
ColorspaceDescriptionStyle.LONG,
ColorspaceDescriptionStyle.LONG_UNION,
DescriptionStyle.OPENCOLORIO,
DescriptionStyle.LONG,
DescriptionStyle.LONG_UNION,
):
if clf_transform.description is not None:
description.append("\n" + clf_transform.description)

description.append(
f"\nCLFtransformID: "
f"{clf_transform.clf_transform_id.clf_transform_id}"
description.extend(
[
"",
DESCRIPTION_CLF_TRANSFORM_ID.format(
clf_transform.clf_transform_id.clf_transform_id
),
]
)

description = "\n".join(description).strip()
Expand Down Expand Up @@ -243,7 +255,7 @@ def clf_transform_to_family(

def clf_transform_to_colorspace(
clf_transform,
describe=ColorspaceDescriptionStyle.LONG_UNION,
describe=DescriptionStyle.LONG_UNION,
signature_only=False,
**kwargs,
):
Expand All @@ -255,7 +267,7 @@ def clf_transform_to_colorspace(
clf_transform : CLFTransform
*CLF* transform.
describe : bool, optional
Whether to use the full *CLF* transform description or just its ID.
*CLF* transform description style.
signature_only : bool, optional
Whether to return the *OpenColorIO* `Colorspace` signature only, i.e.
the arguments for its instantiation.
Expand Down Expand Up @@ -306,7 +318,7 @@ def clf_transform_to_colorspace(

def clf_transform_to_named_transform(
clf_transform,
describe=ColorspaceDescriptionStyle.LONG_UNION,
describe=DescriptionStyle.LONG_UNION,
signature_only=False,
**kwargs,
):
Expand All @@ -318,7 +330,7 @@ def clf_transform_to_named_transform(
clf_transform : CLFTransform
*CLF* transform.
describe : bool, optional
Whether to use the full *CLF* transform description or just its ID.
*CLF* transform description style.
signature_only : bool, optional
Whether to return the *OpenColorIO* `NamedTransform` signature only,
i.e. the arguments for its instantiation.
Expand Down Expand Up @@ -369,7 +381,7 @@ def clf_transform_to_named_transform(

def style_to_colorspace(
style,
describe=ColorspaceDescriptionStyle.LONG_UNION,
describe=DescriptionStyle.LONG_UNION,
signature_only=False,
scheme="Modern 1", # noqa: ARG001
**kwargs,
Expand All @@ -383,7 +395,7 @@ def style_to_colorspace(
*OpenColorIO* builtin transform style.
describe : int, optional
Any value from the
:class:`opencolorio_config_aces.ColorspaceDescriptionStyle` enum.
:class:`opencolorio_config_aces.DescriptionStyle` enum.
signature_only : bool, optional
Whether to return the *OpenColorIO* view `Colorspace` signature only,
i.e. the arguments for its instantiation.
Expand All @@ -407,13 +419,13 @@ def style_to_colorspace(
builtin_transform = ocio.BuiltinTransform(style)

description = None
if describe != ColorspaceDescriptionStyle.NONE:
if describe != DescriptionStyle.NONE:
description = []

if describe in (
ColorspaceDescriptionStyle.OPENCOLORIO,
ColorspaceDescriptionStyle.SHORT_UNION,
ColorspaceDescriptionStyle.LONG_UNION,
DescriptionStyle.OPENCOLORIO,
DescriptionStyle.SHORT_UNION,
DescriptionStyle.LONG_UNION,
):
description.append(builtin_transform.getDescription())

Expand Down Expand Up @@ -477,7 +489,7 @@ def style_to_colorspace(

def style_to_named_transform(
style,
describe=ColorspaceDescriptionStyle.LONG_UNION,
describe=DescriptionStyle.LONG_UNION,
signature_only=False,
scheme="Modern 1", # noqa: ARG001
**kwargs,
Expand All @@ -491,7 +503,7 @@ def style_to_named_transform(
*OpenColorIO* builtin transform style.
describe : int, optional
Any value from the
:class:`opencolorio_config_aces.ColorspaceDescriptionStyle` enum.
:class:`opencolorio_config_aces.DescriptionStyle` enum.
signature_only : bool, optional
Whether to return the *OpenColorIO* view `Colorspace` signature only,
i.e. the arguments for its instantiation.
Expand All @@ -515,13 +527,13 @@ def style_to_named_transform(
builtin_transform = ocio.BuiltinTransform(style)

description = None
if describe != ColorspaceDescriptionStyle.NONE:
if describe != DescriptionStyle.NONE:
description = []

if describe in (
ColorspaceDescriptionStyle.OPENCOLORIO,
ColorspaceDescriptionStyle.SHORT_UNION,
ColorspaceDescriptionStyle.LONG_UNION,
DescriptionStyle.OPENCOLORIO,
DescriptionStyle.SHORT_UNION,
DescriptionStyle.LONG_UNION,
):
description.append(builtin_transform.getDescription())

Expand Down Expand Up @@ -723,7 +735,7 @@ def generate_config_cg(
config_name=None,
profile_version=PROFILE_VERSION_DEFAULT,
validate=True,
describe=ColorspaceDescriptionStyle.SHORT_UNION,
describe=DescriptionStyle.SHORT_UNION,
config_mapping_file_path=PATH_TRANSFORMS_MAPPING_FILE_CG,
scheme="Modern 1",
additional_data=False,
Expand Down Expand Up @@ -768,7 +780,7 @@ def generate_config_cg(
Whether to validate the config.
describe : int, optional
Any value from the
:class:`opencolorio_config_aces.ColorspaceDescriptionStyle` enum.
:class:`opencolorio_config_aces.DescriptionStyle` enum.
config_mapping_file_path : unicode, optional
Path to the *CSV* mapping file used to describe the transforms mapping.
scheme : str, optional
Expand All @@ -784,12 +796,18 @@ def generate_config_cg(
:class:`opencolorio_config_aces.ConfigData` class instance.
"""

scheme = validate_method(scheme, ["Legacy", "Modern 1"])

logger.info(
'Generating "%s" config...',
config_name_cg(config_mapping_file_path, profile_version),
)

scheme = validate_method(scheme, ["Legacy", "Modern 1"])
clf_transforms = unclassify_clf_transforms(
classify_clf_transforms(discover_clf_transforms())
)

logger.debug('Using %s "CLF" transforms...', clf_transforms)

if data is None:
_config, data = generate_config_aces(
Expand All @@ -800,16 +818,6 @@ def generate_config_cg(
additional_data=True,
)

clf_transforms = unclassify_clf_transforms(
classify_clf_transforms(discover_clf_transforms())
)

logger.debug('Using %s "CLF" transforms...', clf_transforms)

logger.debug(
'Using %s "Builtin" transforms...', list(BUILTIN_TRANSFORMS.keys())
)

def clf_transform_from_id(clf_transform_id):
"""
Filter the "CLFTransform" instances matching given "CLFtransformID".
Expand Down
Loading

0 comments on commit dbc462e

Please sign in to comment.