1414import logging
1515import re
1616from collections import defaultdict
17- from collections .abc import Callable , Mapping
17+ from collections .abc import Callable
1818from pathlib import Path
1919from typing import Any
2020
4242)
4343from opencolorio_config_aces .config .reference import (
4444 DescriptionStyle ,
45+ filter_amf_components ,
4546 generate_config_aces ,
4647)
4748from 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:
170170def 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(
300278def 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(
367339def 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(
437405def 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(
547511def 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 (
0 commit comments