Skip to content

Commit f4f6f92

Browse files
committed
Implement support for amf_transform_ids.
Closes #154. Signed-off-by: Thomas Mansencal <[email protected]>
1 parent d4cd7d0 commit f4f6f92

File tree

10 files changed

+121
-210
lines changed

10 files changed

+121
-210
lines changed

docs/opencolorio_config_aces.config.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Reference Configuration
8282
version_aces_dev
8383
classify_aces_ctl_transforms
8484
discover_aces_ctl_transforms
85+
filter_amf_components
8586
filter_ctl_transforms
8687
generate_amf_components
8788
print_aces_taxonomy

opencolorio_config_aces/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
conversion_path,
5050
ctl_transform_to_node,
5151
discover_aces_ctl_transforms,
52+
filter_amf_components,
5253
filter_ctl_transforms,
5354
filter_nodes,
5455
generate_amf_components,
@@ -108,6 +109,7 @@
108109
"conversion_path",
109110
"ctl_transform_to_node",
110111
"discover_aces_ctl_transforms",
112+
"filter_amf_components",
111113
"filter_ctl_transforms",
112114
"filter_nodes",
113115
"generate_amf_components",

opencolorio_config_aces/config/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
conversion_path,
3131
ctl_transform_to_node,
3232
discover_aces_ctl_transforms,
33+
filter_amf_components,
3334
filter_ctl_transforms,
3435
filter_nodes,
3536
generate_amf_components,
@@ -75,6 +76,7 @@
7576
"conversion_path",
7677
"ctl_transform_to_node",
7778
"discover_aces_ctl_transforms",
79+
"filter_amf_components",
7880
"filter_ctl_transforms",
7981
"filter_nodes",
8082
"generate_amf_components",

opencolorio_config_aces/config/cg/generate/config.py

Lines changed: 41 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import logging
1515
import re
1616
from collections import defaultdict
17-
from collections.abc import Callable, Mapping
17+
from collections.abc import Callable
1818
from pathlib import Path
1919
from typing import Any
2020

@@ -42,11 +42,11 @@
4242
)
4343
from opencolorio_config_aces.config.reference import (
4444
DescriptionStyle,
45+
filter_amf_components,
4546
generate_config_aces,
4647
)
4748
from opencolorio_config_aces.config.reference.generate.config import (
4849
COLORSPACE_SCENE_ENCODING_REFERENCE,
49-
HEADER_AMF_COMPONENTS,
5050
TEMPLATE_ACES_TRANSFORM_ID,
5151
format_optional_prefix,
5252
transform_data_aliases,
@@ -170,7 +170,6 @@ def clf_transform_to_colorspace_name(clf_transform: CLFTransform) -> str:
170170
def clf_transform_to_description(
171171
clf_transform: CLFTransform,
172172
describe: DescriptionStyle = DescriptionStyle.LONG_UNION,
173-
amf_components: Mapping[str, Any] | None = None,
174173
direction: str = "Forward",
175174
) -> str | None:
176175
"""
@@ -184,9 +183,6 @@ def clf_transform_to_description(
184183
describe : bool, optional
185184
Whether to use the full *CLF* transform description or just the
186185
first line.
187-
amf_components : mapping, optional
188-
*ACES* *AMF* components used to extend the *ACES* *CTL* transform
189-
description.
190186
direction : str, optional
191187
Direction of transform -- determines order of transform descriptors.
192188
{"Forward", "Reverse"}
@@ -198,8 +194,6 @@ def clf_transform_to_description(
198194
*OpenColorIO* `Colorspace` or `NamedTransform` description.
199195
"""
200196

201-
amf_components = optional(amf_components, {})
202-
203197
description = None
204198
if describe != DescriptionStyle.NONE:
205199
description = []
@@ -242,22 +236,6 @@ def clf_transform_to_description(
242236
aces_transform_id = aces_transform_id.aces_transform_id
243237
description.append(TEMPLATE_ACES_TRANSFORM_ID.format(aces_transform_id))
244238

245-
if describe in (
246-
DescriptionStyle.AMF,
247-
DescriptionStyle.SHORT_UNION,
248-
DescriptionStyle.LONG_UNION,
249-
):
250-
amf_components_description = [
251-
TEMPLATE_ACES_TRANSFORM_ID.format(amf_aces_transform_id)
252-
for amf_aces_transform_id in amf_components.get(
253-
aces_transform_id, []
254-
)
255-
]
256-
if amf_components_description:
257-
description.append("")
258-
description.append(HEADER_AMF_COMPONENTS)
259-
description.extend(amf_components_description)
260-
261239
description = "\n".join(description).strip()
262240

263241
return description
@@ -300,7 +278,6 @@ def clf_transform_to_family(
300278
def clf_transform_to_colorspace(
301279
clf_transform: CLFTransform,
302280
describe: DescriptionStyle = DescriptionStyle.LONG_UNION,
303-
amf_components: Mapping[str, Any] | None = None,
304281
signature_only: bool = False,
305282
**kwargs: Any,
306283
) -> dict[str, Any] | ocio.ColorSpace:
@@ -313,9 +290,6 @@ def clf_transform_to_colorspace(
313290
*CLF* transform.
314291
describe : bool, optional
315292
*CLF* transform description style.
316-
amf_components : mapping, optional
317-
*ACES* *AMF* components used to extend the *ACES* *CTL* transform
318-
description.
319293
signature_only : bool, optional
320294
Whether to return the *OpenColorIO* `Colorspace` signature only, i.e.,
321295
the arguments for its instantiation.
@@ -335,9 +309,7 @@ def clf_transform_to_colorspace(
335309
signature = {
336310
"name": clf_transform_to_colorspace_name(clf_transform),
337311
"family": clf_transform_to_family(clf_transform),
338-
"description": clf_transform_to_description(
339-
clf_transform, describe, amf_components, "Forward"
340-
),
312+
"description": clf_transform_to_description(clf_transform, describe, "Forward"),
341313
}
342314

343315
file_transform = {
@@ -367,7 +339,6 @@ def clf_transform_to_colorspace(
367339
def clf_transform_to_named_transform(
368340
clf_transform: CLFTransform,
369341
describe: DescriptionStyle = DescriptionStyle.LONG_UNION,
370-
amf_components: Mapping[str, Any] | None = None,
371342
signature_only: bool = False,
372343
**kwargs: Any,
373344
) -> dict[str, Any] | ocio.NamedTransform:
@@ -380,9 +351,6 @@ def clf_transform_to_named_transform(
380351
*CLF* transform.
381352
describe : bool, optional
382353
*CLF* transform description style.
383-
amf_components : mapping, optional
384-
*ACES* *AMF* components used to extend the *ACES* *CTL* transform
385-
description.
386354
signature_only : bool, optional
387355
Whether to return the *OpenColorIO* `NamedTransform` signature only,
388356
i.e., the arguments for its instantiation.
@@ -412,12 +380,12 @@ def clf_transform_to_named_transform(
412380
if is_reference(clf_transform.source):
413381
signature["inverse_transform"] = file_transform # pyright: ignore
414382
signature["description"] = clf_transform_to_description( # pyright: ignore
415-
clf_transform, describe, amf_components, direction="Reverse"
383+
clf_transform, describe, direction="Reverse"
416384
)
417385
else:
418386
signature["forward_transform"] = file_transform # pyright: ignore
419387
signature["description"] = clf_transform_to_description( # pyright: ignore
420-
clf_transform, describe, amf_components, direction="Forward"
388+
clf_transform, describe, direction="Forward"
421389
)
422390

423391
signature.update(kwargs)
@@ -437,7 +405,6 @@ def clf_transform_to_named_transform(
437405
def style_to_colorspace(
438406
style: str,
439407
describe: DescriptionStyle = DescriptionStyle.LONG_UNION,
440-
amf_components: Mapping[str, Any] | None = None,
441408
signature_only: bool = False,
442409
scheme: str = "Modern 1", # noqa: ARG001
443410
**kwargs: Any,
@@ -452,9 +419,6 @@ def style_to_colorspace(
452419
describe : int, optional
453420
Any value from the
454421
:class:`opencolorio_config_aces.DescriptionStyle` enum.
455-
amf_components : mapping, optional
456-
*ACES* *AMF* components used to extend the *ACES* *CTL* transform
457-
description.
458422
signature_only : bool, optional
459423
Whether to return the *OpenColorIO* view `Colorspace` signature only,
460424
i.e., the arguments for its instantiation.
@@ -494,7 +458,7 @@ def style_to_colorspace(
494458
clf_transform = kwargs.pop("clf_transform", None)
495459
if clf_transform:
496460
colorspace_signature = clf_transform_to_colorspace(
497-
clf_transform, describe, amf_components, True, **kwargs
461+
clf_transform, describe, True, **kwargs
498462
)
499463
description = colorspace_signature["description"]
500464
signature.update(colorspace_signature)
@@ -547,7 +511,6 @@ def style_to_colorspace(
547511
def style_to_named_transform(
548512
style: str,
549513
describe: DescriptionStyle = DescriptionStyle.LONG_UNION,
550-
amf_components: Mapping[str, Any] | None = None,
551514
signature_only: bool = False,
552515
scheme: str = "Modern 1", # noqa: ARG001
553516
**kwargs: Any,
@@ -562,9 +525,6 @@ def style_to_named_transform(
562525
describe : int, optional
563526
Any value from the
564527
:class:`opencolorio_config_aces.DescriptionStyle` enum.
565-
amf_components : mapping, optional
566-
*ACES* *AMF* components used to extend the *ACES* *CTL* transform
567-
description.
568528
signature_only : bool, optional
569529
Whether to return the *OpenColorIO* view `Colorspace` signature only,
570530
i.e., the arguments for its instantiation.
@@ -604,15 +564,14 @@ def style_to_named_transform(
604564
clf_transform = kwargs.pop("clf_transform", None)
605565
if clf_transform:
606566
colorspace_signature = clf_transform_to_colorspace(
607-
clf_transform, describe, amf_components, True, **kwargs
567+
clf_transform, describe, True, **kwargs
608568
)
609569
signature.update(colorspace_signature)
610570
signature.pop("from_reference", None)
611571
source = clf_transform.source
612572
description = clf_transform_to_description(
613573
clf_transform,
614574
describe,
615-
amf_components,
616575
"Reverse" if is_reference(source) else "Forward",
617576
)
618577
else:
@@ -1190,7 +1149,6 @@ def remove_existing_named_transform(name: str) -> None:
11901149

11911150
kwargs = {
11921151
"describe": describe,
1193-
"amf_components": amf_components,
11941152
"signature_only": True,
11951153
"aliases": transform_data_aliases(transform_data),
11961154
"encoding": transform_data.get("encoding"),
@@ -1202,10 +1160,25 @@ def remove_existing_named_transform(name: str) -> None:
12021160
clf_transform_id = transform_data["clf_transform_id"]
12031161

12041162
if style:
1163+
clf_transform = clf_transform_from_style(style)
1164+
1165+
filtered_amf_components = None
1166+
if (
1167+
aces_transform_id := clf_transform.information.get( # pyright: ignore
1168+
"ACEStransformID"
1169+
)
1170+
) is not None:
1171+
filtered_amf_components = filter_amf_components(
1172+
amf_components, aces_transform_id.aces_transform_id
1173+
)
1174+
12051175
kwargs.update(
12061176
{
12071177
"style": style,
1208-
"clf_transform": clf_transform_from_style(style),
1178+
"clf_transform": clf_transform,
1179+
"interchange_mapping": None
1180+
if filtered_amf_components is None
1181+
else {"amf_transform_ids": "\n".join(filtered_amf_components)},
12091182
}
12101183
)
12111184

@@ -1250,7 +1223,24 @@ def remove_existing_named_transform(name: str) -> None:
12501223
f'"{clf_transform_id}" "CLF" transform does not exist!',
12511224
)
12521225

1253-
kwargs["clf_transform"] = clf_transform
1226+
filtered_amf_components = None
1227+
if (
1228+
aces_transform_id := clf_transform.information.get( # pyright: ignore
1229+
"ACEStransformID"
1230+
)
1231+
) is not None:
1232+
filtered_amf_components = filter_amf_components(
1233+
amf_components, aces_transform_id.aces_transform_id
1234+
)
1235+
1236+
kwargs.update(
1237+
{
1238+
"clf_transform": clf_transform,
1239+
"interchange_mapping": None
1240+
if filtered_amf_components is None
1241+
else {"amf_transform_ids": "\n".join(filtered_amf_components)},
1242+
}
1243+
)
12541244

12551245
if transform_data["interface"] == "NamedTransform":
12561246
LOGGER.info(

opencolorio_config_aces/config/generation/configuration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,19 @@ def extended_fields(self) -> dict[str, str]:
9191
BuildConfiguration(
9292
aces=Version(2, 0),
9393
colorspaces=Version(3, 0, 0),
94-
ocio=Version(2, 4),
94+
ocio=Version(2, 5),
9595
variant="",
9696
),
9797
BuildConfiguration(
9898
aces=Version(2, 0),
9999
colorspaces=Version(3, 0, 0),
100-
ocio=Version(2, 4),
100+
ocio=Version(2, 5),
101101
variant="D60 Views",
102102
),
103103
BuildConfiguration(
104104
aces=Version(2, 0),
105105
colorspaces=Version(3, 0, 0),
106-
ocio=Version(2, 4),
106+
ocio=Version(2, 5),
107107
variant="All Views",
108108
),
109109
]

opencolorio_config_aces/config/generation/factories.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def colorspace_factory(
125125
is_data: bool | None = None,
126126
reference_space: str | int | None = None,
127127
interop_id: str | None = None,
128+
interchange_mapping: dict[str, str] | None = None,
128129
base_colorspace: Mapping[str, Any] | ocio.ColorSpace | None = None,
129130
**kwargs: Any,
130131
) -> ocio.ColorSpace:
@@ -166,6 +167,9 @@ def colorspace_factory(
166167
See https://github.com/AcademySoftwareFoundation/ColorInterop/blob/\
167168
5aebc3f37ac192c86694a47bb92fa65cc95e4e67/Recommendations/\
168169
01_TextureAssetColorSpaces/TextureAssetColorSpaces.md
170+
interchange_mapping : dict, optional
171+
Mapping of key and value pairs for interchange, e.g.,
172+
`amf_transform_ids` or `icc_profile_name`.
169173
base_colorspace : dict or ColorSpace, optional
170174
*OpenColorIO* base `Colorspace` inherited for initial attribute values.
171175
@@ -261,6 +265,10 @@ def colorspace_factory(
261265
if interop_id is not None:
262266
colorspace.setInteropID(interop_id) # pyright: ignore
263267

268+
if interchange_mapping is not None:
269+
for key, value in interchange_mapping.items():
270+
colorspace.setInterchangeAttribute(key, value) # pyright: ignore
271+
264272
return colorspace
265273

266274

opencolorio_config_aces/config/reference/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
discover_aces_ctl_transforms,
77
classify_aces_ctl_transforms,
88
unclassify_ctl_transforms,
9+
filter_amf_components,
910
filter_ctl_transforms,
1011
generate_amf_components,
1112
print_aces_taxonomy,
@@ -26,6 +27,7 @@
2627
"discover_aces_ctl_transforms",
2728
"classify_aces_ctl_transforms",
2829
"unclassify_ctl_transforms",
30+
"filter_amf_components",
2931
"filter_ctl_transforms",
3032
"generate_amf_components",
3133
"print_aces_taxonomy",

opencolorio_config_aces/config/reference/discover/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
discover_aces_ctl_transforms,
77
classify_aces_ctl_transforms,
88
unclassify_ctl_transforms,
9+
filter_amf_components,
910
filter_ctl_transforms,
1011
generate_amf_components,
1112
print_aces_taxonomy,
@@ -24,6 +25,7 @@
2425
"discover_aces_ctl_transforms",
2526
"classify_aces_ctl_transforms",
2627
"unclassify_ctl_transforms",
28+
"filter_amf_components",
2729
"filter_ctl_transforms",
2830
"generate_amf_components",
2931
"print_aces_taxonomy",

0 commit comments

Comments
 (0)