6060__all__ = [
6161 "URL_EXPORT_TRANSFORMS_MAPPING_FILE_CG" ,
6262 "PATH_TRANSFORMS_MAPPING_FILE_CG" ,
63+ "is_reference" ,
6364 "clf_transform_to_description" ,
6465 "clf_transform_to_colorspace" ,
6566 "clf_transform_to_named_transform" ,
9596"""
9697
9798
99+ def is_reference (name ):
100+ """
101+ Return whether given name represent a reference linear-like space.
102+
103+ Parameters
104+ ----------
105+ name : str
106+ Name.
107+
108+ Returns
109+ -------
110+ str
111+ Whether given name represent a reference linear-like space.
112+ """
113+
114+ return name .lower () in (
115+ COLORSPACE_SCENE_ENCODING_REFERENCE .lower (),
116+ "ap0" ,
117+ "linear" ,
118+ )
119+
120+
98121def clf_transform_to_colorspace_name (clf_transform ):
99122 """
100123 Generate the *OpenColorIO* `Colorspace` name for given *CLF* transform.
@@ -110,11 +133,7 @@ def clf_transform_to_colorspace_name(clf_transform):
110133 *OpenColorIO* `Colorspace` name.
111134 """
112135
113- if clf_transform .source in (
114- COLORSPACE_SCENE_ENCODING_REFERENCE ,
115- "AP0" ,
116- "Linear" ,
117- ):
136+ if is_reference (clf_transform .source ):
118137 name = clf_transform .target
119138 else :
120139 name = clf_transform .source
@@ -192,8 +211,8 @@ def clf_transform_to_colorspace(
192211 describe : bool, optional
193212 Whether to use the full *CLF* transform description or just its ID.
194213 signature_only : bool, optional
195- Whether to return the *OpenColorIO* `Colorspace` signature only, i.e. the
196- arguments for its instantiation.
214+ Whether to return the *OpenColorIO* `Colorspace` signature only, i.e.
215+ the arguments for its instantiation.
197216
198217 Other Parameters
199218 ----------------
@@ -215,12 +234,18 @@ def clf_transform_to_colorspace(
215234 f"{ clf_transform .clf_transform_id .namespace } "
216235 ),
217236 "description" : clf_transform_to_description (clf_transform , describe ),
218- "from_reference" : {
219- "transform_type" : "FileTransform" ,
220- "transform_factory" : "CLF Transform to Group Transform" ,
221- "src" : clf_transform .path ,
222- },
223237 }
238+
239+ file_transform = {
240+ "transform_type" : "FileTransform" ,
241+ "transform_factory" : "CLF Transform to Group Transform" ,
242+ "src" : clf_transform .path ,
243+ }
244+ if is_reference (clf_transform .source ):
245+ signature ["from_reference" ] = file_transform
246+ else :
247+ signature ["to_reference" ] = file_transform
248+
224249 signature .update (kwargs )
225250
226251 signature ["aliases" ] = list (
@@ -276,12 +301,18 @@ def clf_transform_to_named_transform(
276301 f"{ clf_transform .clf_transform_id .namespace } "
277302 ),
278303 "description" : clf_transform_to_description (clf_transform , describe ),
279- "forward_transform" : {
280- "transform_type" : "FileTransform" ,
281- "transform_factory" : "CLF Transform to Group Transform" ,
282- "src" : clf_transform .path ,
283- },
284304 }
305+
306+ file_transform = {
307+ "transform_type" : "FileTransform" ,
308+ "transform_factory" : "CLF Transform to Group Transform" ,
309+ "src" : clf_transform .path ,
310+ }
311+ if is_reference (clf_transform .source ):
312+ signature ["forward_transform" ] = file_transform
313+ else :
314+ signature ["inverse_transform" ] = file_transform
315+
285316 signature .update (kwargs )
286317
287318 signature ["aliases" ] = list (
@@ -334,6 +365,7 @@ def style_to_colorspace(
334365 *OpenColorIO* `Colorspace` or its signature for given style.
335366 """
336367
368+ # TODO: Implement "BuiltinTransform" name beautification.
337369 builtin_transform = ocio .BuiltinTransform (style )
338370
339371 description = None
@@ -357,13 +389,25 @@ def style_to_colorspace(
357389 clf_transform , signature_only = True , ** kwargs
358390 )
359391 )
392+ source = clf_transform .source
393+ else :
394+ # TODO: Implement solid "BuiltinTransform" source detection.
395+ source = style .lower ().split (" - " , 1 )[- 1 ].split ("_to_" )[0 ]
360396
361- signature .update (
362- {
363- "to_reference" : builtin_transform ,
364- "description" : description ,
365- }
366- )
397+ if is_reference (source ):
398+ signature .update (
399+ {
400+ "from_reference" : builtin_transform ,
401+ "description" : description ,
402+ }
403+ )
404+ else :
405+ signature .update (
406+ {
407+ "to_reference" : builtin_transform ,
408+ "description" : description ,
409+ }
410+ )
367411 signature .update (** kwargs )
368412
369413 signature ["aliases" ] = list (
@@ -373,10 +417,15 @@ def style_to_colorspace(
373417 )
374418
375419 if signature_only :
376- signature [ "to_reference" ] = {
420+ builtin_transform = {
377421 "transform_type" : "BuiltinTransform" ,
378422 "style" : style ,
379423 }
424+ if is_reference (source ):
425+ signature ["from_reference" ] = builtin_transform
426+ else :
427+ signature ["to_reference" ] = builtin_transform
428+
380429 return signature
381430 else :
382431 colorspace = colorspace_factory (** signature )
@@ -420,6 +469,7 @@ def style_to_named_transform(
420469 *OpenColorIO* `NamedTransform` or its signature for given style.
421470 """
422471
472+ # TODO: Implement "BuiltinTransform" name beautification.
423473 builtin_transform = ocio .BuiltinTransform (style )
424474
425475 description = None
@@ -444,13 +494,25 @@ def style_to_named_transform(
444494 )
445495 )
446496 signature .pop ("from_reference" , None )
497+ source = clf_transform .source
498+ else :
499+ # TODO: Implement solid "BuiltinTransform" source detection.
500+ source = style .lower ().split (" - " , 1 )[- 1 ].split ("_to_" )[0 ]
447501
448- signature .update (
449- {
450- "forward_transform" : builtin_transform ,
451- "description" : description ,
452- }
453- )
502+ if is_reference (source ):
503+ signature .update (
504+ {
505+ "forward_transform" : builtin_transform ,
506+ "description" : description ,
507+ }
508+ )
509+ else :
510+ signature .update (
511+ {
512+ "inverse_transform" : builtin_transform ,
513+ "description" : description ,
514+ }
515+ )
454516 signature .update (** kwargs )
455517
456518 signature ["aliases" ] = list (
@@ -460,10 +522,15 @@ def style_to_named_transform(
460522 )
461523
462524 if signature_only :
463- signature [ "forward_transform" ] = {
525+ builtin_transform = {
464526 "transform_type" : "BuiltinTransform" ,
465527 "style" : style ,
466528 }
529+ if is_reference (source ):
530+ signature ["forward_transform" ] = builtin_transform
531+ else :
532+ signature ["inverse_transform" ] = builtin_transform
533+
467534 return signature
468535 else :
469536 colorspace = named_transform_factory (** signature )
@@ -681,7 +748,6 @@ def generate_config_cg(
681748 builtin_transforms = [
682749 builtin for builtin in ocio .BuiltinTransformRegistry ()
683750 ]
684-
685751 logger .debug (f'Using { builtin_transforms } "Builtin" transforms...' )
686752
687753 def transform_aliases (transform_data ):
0 commit comments