Fix "PEP8" naming convention violations.
[OpenColorIO-Configs.git] / aces_1.0.0 / python / aces_ocio / colorspaces / aces.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """
5 Implements support for *ACES* colorspaces conversions and transfer functions.
6 """
7
8 from __future__ import division
9
10 import math
11 import numpy
12 import os
13 import pprint
14 import string
15 import shutil
16
17 import PyOpenColorIO as ocio
18
19 from aces_ocio.lut import (
20     generate_1d_LUT_from_CTL,
21     generate_3d_LUT_from_CTL,
22     write_SPI_1d)
23 from aces_ocio.utilities import (
24     ColorSpace,
25     mat44_from_mat33,
26     sanitize,
27     compact)
28
29 __author__ = 'ACES Developers'
30 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
31 __license__ = ''
32 __maintainer__ = 'ACES Developers'
33 __email__ = 'aces@oscars.org'
34 __status__ = 'Production'
35
36 __all__ = ['ACES_AP1_TO_AP0',
37            'ACES_AP0_TO_AP1',
38            'ACES_AP0_TO_XYZ',
39            'ACES_XYZ_TO_AP0',
40            'create_ACES',
41            'create_ACEScc',
42            'create_ACESproxy',
43            'create_ACEScg',
44            'create_ADX',
45            'create_generic_log',
46            'create_Dolby_PQ',
47            'create_Dolby_PQ_scaled',
48            'create_ACES_LMT',
49            'create_LMTs',
50            'create_ACES_RRT_plus_ODT',
51            'create_ODTs',
52            'get_transform_info',
53            'get_ODTs_info',
54            'get_LMTs_info',
55            'create_colorspaces']
56
57 # Matrix converting *ACES AP1* primaries to *ACES AP0*.
58 ACES_AP1_TO_AP0 = [0.6954522414, 0.1406786965, 0.1638690622,
59                    0.0447945634, 0.8596711185, 0.0955343182,
60                    -0.0055258826, 0.0040252103, 1.0015006723]
61
62 # Matrix converting *ACES AP0* primaries to *ACES AP1*.
63 ACES_AP0_TO_AP1 = [1.4514393161, -0.2365107469, -0.2149285693,
64                    -0.0765537734, 1.1762296998, -0.0996759264,
65                    0.0083161484, -0.0060324498, 0.9977163014]
66
67 # Matrix converting *ACES AP0* primaries to *XYZ*.
68 ACES_AP0_TO_XYZ = [0.9525523959, 0.0000000000, 0.0000936786,
69                    0.3439664498, 0.7281660966, -0.0721325464,
70                    0.0000000000, 0.0000000000, 1.0088251844]
71
72 # Matrix converting *ACES AP0* primaries to *XYZ*.
73 ACES_XYZ_TO_AP0 = [1.0498110175, 0.0000000000, -0.0000974845,
74                    -0.4959030231, 1.3733130458, 0.0982400361,
75                    0.0000000000, 0.0000000000, 0.9912520182]
76
77
78 def create_ACES():
79     """
80     Object description.
81
82     Parameters
83     ----------
84     parameter : type
85         Parameter description.
86
87     Returns
88     -------
89     type
90          Return value description.
91     """
92
93     # Defining the reference colorspace.
94     aces2065_1 = ColorSpace('ACES2065-1')
95     aces2065_1.description = (
96         'The Academy Color Encoding System reference color space')
97     aces2065_1.equality_group = ''
98     aces2065_1.aliases = ['lin_ap0', 'aces']
99     aces2065_1.family = 'ACES'
100     aces2065_1.is_data = False
101     aces2065_1.allocation_type = ocio.Constants.ALLOCATION_LG2
102     aces2065_1.allocation_vars = [-8, 5, 0.00390625]
103
104     return aces2065_1
105
106
107 def create_ACEScc(aces_ctl_directory,
108                   lut_directory,
109                   lut_resolution_1d,
110                   cleanup,
111                   name='ACEScc',
112                   min_value=0,
113                   max_value=1,
114                   input_scale=1):
115     """
116     Creates the *ACEScc* colorspace.
117
118     Parameters
119     ----------
120     parameter : type
121         Parameter description.
122
123     Returns
124     -------
125     Colorspace
126          *ACEScc* colorspace.
127     """
128
129     cs = ColorSpace(name)
130     cs.description = 'The %s color space' % name
131     cs.aliases = ['acescc', 'acescc_ap1']
132     cs.equality_group = ''
133     cs.family = 'ACES'
134     cs.is_data = False
135     cs.allocation_type = ocio.Constants.ALLOCATION_UNIFORM
136     cs.allocation_vars = [min_value, max_value]
137     cs.aces_transform_id = 'ACEScsc.ACEScc_to_ACES.a1.0.0'
138
139     ctls = [os.path.join(aces_ctl_directory,
140                          'ACEScc',
141                          'ACEScsc.ACEScc_to_ACES.a1.0.0.ctl'),
142             # This transform gets back to the *AP1* primaries.
143             # Useful as the 1d LUT is only covering the transfer function.
144             # The primaries switch is covered by the matrix below:
145             os.path.join(aces_ctl_directory,
146                          'ACEScg',
147                          'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
148     lut = '%s_to_linear.spi1d' % name
149
150     lut = sanitize(lut)
151
152     generate_1d_LUT_from_CTL(
153         os.path.join(lut_directory, lut),
154         ctls,
155         lut_resolution_1d,
156         'float',
157         input_scale,
158         1,
159         {},
160         cleanup,
161         aces_ctl_directory,
162         min_value,
163         max_value,
164         1)
165
166     cs.to_reference_transforms = []
167     cs.to_reference_transforms.append({
168         'type': 'lutFile',
169         'path': lut,
170         'interpolation': 'linear',
171         'direction': 'forward'})
172
173     # *AP1* primaries to *AP0* primaries
174     cs.to_reference_transforms.append({
175         'type': 'matrix',
176         'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
177         'direction': 'forward'})
178
179     cs.from_reference_transforms = []
180     return cs
181
182
183 def create_ACESproxy(aces_ctl_directory,
184                      lut_directory,
185                      lut_resolution_1d,
186                      cleanup,
187                      name='ACESproxy'):
188     """
189     Creates the *ACESproxy* colorspace.
190
191     Parameters
192     ----------
193     parameter : type
194         Parameter description.
195
196     Returns
197     -------
198     Colorspace
199          *ACESproxy* colorspace.
200     """
201
202     cs = ColorSpace(name)
203     cs.description = 'The %s color space' % name
204     cs.aliases = ['acesproxy', 'acesproxy_ap1']
205     cs.equality_group = ''
206     cs.family = 'ACES'
207     cs.is_data = False
208
209     cs.aces_transform_id = 'ACEScsc.ACESproxy10i_to_ACES.a1.0.0'
210
211     ctls = [os.path.join(aces_ctl_directory,
212                          'ACESproxy',
213                          'ACEScsc.ACESproxy10i_to_ACES.a1.0.0.ctl'),
214             # This transform gets back to the *AP1* primaries.
215             # Useful as the 1d LUT is only covering the transfer function.
216             # The primaries switch is covered by the matrix below:
217             os.path.join(aces_ctl_directory,
218                          'ACEScg',
219                          'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
220     lut = '%s_to_linear.spi1d' % name
221
222     lut = sanitize(lut)
223
224     generate_1d_LUT_from_CTL(
225         os.path.join(lut_directory, lut),
226         ctls,
227         lut_resolution_1d,
228         'float',
229         1,
230         1,
231         {},
232         cleanup,
233         aces_ctl_directory,
234         0,
235         1,
236         1)
237
238     cs.to_reference_transforms = []
239     cs.to_reference_transforms.append({
240         'type': 'lutFile',
241         'path': lut,
242         'interpolation': 'linear',
243         'direction': 'forward'})
244
245     # *AP1* primaries to *AP0* primaries
246     cs.to_reference_transforms.append({
247         'type': 'matrix',
248         'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
249         'direction': 'forward'})
250
251     cs.from_reference_transforms = []
252     return cs
253
254
255 # -------------------------------------------------------------------------
256 # *ACEScg*
257 # -------------------------------------------------------------------------
258 def create_ACEScg():
259     """
260     Creates the *ACEScg* colorspace.
261
262     Parameters
263     ----------
264     parameter : type
265         Parameter description.
266
267     Returns
268     -------
269     Colorspace
270          *ACEScg* colorspace.
271     """
272
273     name = 'ACEScg'
274
275     cs = ColorSpace(name)
276     cs.description = 'The %s color space' % name
277     cs.aliases = ['acescg', 'lin_ap1']
278     cs.equality_group = ''
279     cs.family = 'ACES'
280     cs.is_data = False
281     cs.allocation_type = ocio.Constants.ALLOCATION_LG2
282     cs.allocation_vars = [-8, 5, 0.00390625]
283
284     cs.aces_transform_id = 'ACEScsc.ACEScg_to_ACES.a1.0.0'
285
286     cs.to_reference_transforms = []
287
288     # *AP1* primaries to *AP0* primaries
289     cs.to_reference_transforms.append({
290         'type': 'matrix',
291         'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
292         'direction': 'forward'})
293
294     cs.from_reference_transforms = []
295
296     # *AP1* primaries to *AP0* primaries
297     cs.from_reference_transforms.append({
298         'type': 'matrix',
299         'matrix': mat44_from_mat33(ACES_AP0_TO_AP1),
300         'direction': 'forward'})
301
302     return cs
303
304
305 # -------------------------------------------------------------------------
306 # *ADX*
307 # -------------------------------------------------------------------------
308 def create_ADX(lut_directory,
309                bit_depth=10,
310                name='ADX'):
311     """
312     Creates the *ADX* colorspace.
313
314     Parameters
315     ----------
316     parameter : type
317         Parameter description.
318
319     Returns
320     -------
321     Colorspace
322          *ADX* colorspace.
323     """
324
325     name = '%s%s' % (name, bit_depth)
326     cs = ColorSpace(name)
327     cs.description = '%s color space - used for film scans' % name
328     cs.aliases = ['adx%s' % str(bit_depth)]
329     cs.equality_group = ''
330     cs.family = 'ADX'
331     cs.is_data = False
332
333     if bit_depth == 10:
334         cs.aces_transform_id = 'ACEScsc.ADX10_to_ACES.a1.0.0'
335
336         cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT10
337         ADX_to_CDD = [1023 / 500, 0, 0, 0,
338                       0, 1023 / 500, 0, 0,
339                       0, 0, 1023 / 500, 0,
340                       0, 0, 0, 1]
341         offset = [-95 / 500, -95 / 500, -95 / 500, 0]
342     elif bit_depth == 16:
343         cs.aces_transform_id = 'ACEScsc.ADX16_to_ACES.a1.0.0'
344
345         cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT16
346         ADX_to_CDD = [65535 / 8000, 0, 0, 0,
347                       0, 65535 / 8000, 0, 0,
348                       0, 0, 65535 / 8000, 0,
349                       0, 0, 0, 1]
350         offset = [-1520 / 8000, -1520 / 8000, -1520 / 8000, 0]
351
352     cs.to_reference_transforms = []
353
354     # Converting from *ADX* to *Channel-Dependent Density*.
355     cs.to_reference_transforms.append({
356         'type': 'matrix',
357         'matrix': ADX_to_CDD,
358         'offset': offset,
359         'direction': 'forward'})
360
361     # Converting from *Channel-Dependent Density* to
362     # *Channel-Independent Density*.
363     cs.to_reference_transforms.append({
364         'type': 'matrix',
365         'matrix': [0.75573, 0.22197, 0.02230, 0,
366                    0.05901, 0.96928, -0.02829, 0,
367                    0.16134, 0.07406, 0.76460, 0,
368                    0, 0, 0, 1],
369         'direction': 'forward'})
370
371     # Copied from *Alex Fry*'s *adx_cid_to_rle.py*
372     def create_CID_to_RLE_LUT():
373
374         def interpolate_1d(x, xp, fp):
375             return numpy.interp(x, xp, fp)
376
377         LUT_1D_XP = [-0.190000000000000,
378                      0.010000000000000,
379                      0.028000000000000,
380                      0.054000000000000,
381                      0.095000000000000,
382                      0.145000000000000,
383                      0.220000000000000,
384                      0.300000000000000,
385                      0.400000000000000,
386                      0.500000000000000,
387                      0.600000000000000]
388
389         LUT_1D_FP = [-6.000000000000000,
390                      -2.721718645000000,
391                      -2.521718645000000,
392                      -2.321718645000000,
393                      -2.121718645000000,
394                      -1.921718645000000,
395                      -1.721718645000000,
396                      -1.521718645000000,
397                      -1.321718645000000,
398                      -1.121718645000000,
399                      -0.926545676714876]
400
401         REF_PT = ((7120 - 1520) / 8000 * (100 / 55) -
402                   math.log(0.18, 10))
403
404         def cid_to_rle(x):
405             if x <= 0.6:
406                 return interpolate_1d(x, LUT_1D_XP, LUT_1D_FP)
407             return (100 / 55) * x - REF_PT
408
409         def fit(value, from_min, from_max, to_min, to_max):
410             if from_min == from_max:
411                 raise ValueError('from_min == from_max')
412             return (value - from_min) / (from_max - from_min) * (
413                 to_max - to_min) + to_min
414
415         num_samples = 2 ** 12
416         domain = (-0.19, 3)
417         data = []
418         for i in xrange(num_samples):
419             x = i / (num_samples - 1)
420             x = fit(x, 0, 1, domain[0], domain[1])
421             data.append(cid_to_rle(x))
422
423         lut = 'ADX_CID_to_RLE.spi1d'
424         write_SPI_1d(os.path.join(lut_directory, lut),
425                      domain[0],
426                      domain[1],
427                      data,
428                      num_samples, 1)
429
430         return lut
431
432     # Converting *Channel Independent Density* values to
433     # *Relative Log Exposure* values.
434     lut = create_CID_to_RLE_LUT()
435     cs.to_reference_transforms.append({
436         'type': 'lutFile',
437         'path': lut,
438         'interpolation': 'linear',
439         'direction': 'forward'})
440
441     # Converting *Relative Log Exposure* values to
442     # *Relative Exposure* values.
443     cs.to_reference_transforms.append({
444         'type': 'log',
445         'base': 10,
446         'direction': 'inverse'})
447
448     # Convert *Relative Exposure* values to *ACES* values.
449     cs.to_reference_transforms.append({
450         'type': 'matrix',
451         'matrix': [0.72286, 0.12630, 0.15084, 0,
452                    0.11923, 0.76418, 0.11659, 0,
453                    0.01427, 0.08213, 0.90359, 0,
454                    0, 0, 0, 1],
455         'direction': 'forward'})
456
457     cs.from_reference_transforms = []
458     return cs
459
460
461 # -------------------------------------------------------------------------
462 # Generic *Log* Transform
463 # -------------------------------------------------------------------------
464 def create_generic_log(aces_ctl_directory,
465                        lut_directory,
466                        lut_resolution_1d,
467                        cleanup,
468                        name='log',
469                        aliases=None,
470                        min_value=0,
471                        max_value=1,
472                        input_scale=1,
473                        middle_grey=0.18,
474                        min_exposure=-6,
475                        max_exposure=6.5):
476     """
477     Creates the *Generic Log* colorspace.
478
479     Parameters
480     ----------
481     parameter : type
482         Parameter description.
483
484     Returns
485     -------
486     Colorspace
487          *Generic Log* colorspace.
488     """
489
490     if aliases is None:
491         aliases = []
492
493     cs = ColorSpace(name)
494     cs.description = 'The %s color space' % name
495     cs.aliases = aliases
496     cs.equality_group = name
497     cs.family = 'Utility'
498     cs.is_data = False
499
500     ctls = [os.path.join(
501         aces_ctl_directory,
502         'utilities',
503         'ACESlib.Log2_to_Lin_param.a1.0.0.ctl')]
504     lut = '%s_to_linear.spi1d' % name
505
506     lut = sanitize(lut)
507
508     generate_1d_LUT_from_CTL(
509         os.path.join(lut_directory, lut),
510         ctls,
511         lut_resolution_1d,
512         'float',
513         input_scale,
514         1,
515         {'middleGrey': middle_grey,
516          'minExposure': min_exposure,
517          'maxExposure': max_exposure},
518         cleanup,
519         aces_ctl_directory,
520         min_value,
521         max_value,
522         1)
523
524     cs.to_reference_transforms = []
525     cs.to_reference_transforms.append({
526         'type': 'lutFile',
527         'path': lut,
528         'interpolation': 'linear',
529         'direction': 'forward'})
530
531     cs.from_reference_transforms = []
532     return cs
533
534
535 # -------------------------------------------------------------------------
536 # Base *Dolby PQ* Transform
537 # -------------------------------------------------------------------------
538 def create_Dolby_PQ(aces_ctl_directory,
539                     lut_directory,
540                     lut_resolution_1d,
541                     cleanup,
542                     name='pq',
543                     aliases=None,
544                     min_value=0.0,
545                     max_value=1.0,
546                     input_scale=1.0):
547     if aliases is None:
548         aliases = []
549
550     cs = ColorSpace(name)
551     cs.description = 'The %s color space' % name
552     cs.aliases = aliases
553     cs.equality_group = name
554     cs.family = 'Utility'
555     cs.is_data = False
556
557     ctls = [os.path.join(
558         aces_ctl_directory,
559         'utilities',
560         'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl')]
561     lut = '%s_to_linear.spi1d' % name
562
563     lut = sanitize(lut)
564
565     generate_1d_LUT_from_CTL(
566         os.path.join(lut_directory, lut),
567         ctls,
568         lut_resolution_1d,
569         'float',
570         input_scale,
571         1.0,
572         {},
573         cleanup,
574         aces_ctl_directory,
575         min_value,
576         max_value)
577
578     cs.to_reference_transforms = []
579     cs.to_reference_transforms.append({
580         'type': 'lutFile',
581         'path': lut,
582         'interpolation': 'linear',
583         'direction': 'forward'})
584
585     cs.from_reference_transforms = []
586     return cs
587
588
589 # -------------------------------------------------------------------------
590 # *Dolby PQ* Transform - Fixed Linear Range
591 # -------------------------------------------------------------------------
592 def create_Dolby_PQ_scaled(aces_ctl_directory,
593                            lut_directory,
594                            lut_resolution_1d,
595                            cleanup,
596                            name='pq',
597                            aliases=None,
598                            min_value=0.0,
599                            max_value=1.0,
600                            input_scale=1.0,
601                            middle_grey=0.18,
602                            min_exposure=-6.0,
603                            max_exposure=6.5):
604     if aliases is None:
605         aliases = []
606
607     cs = ColorSpace(name)
608     cs.description = 'The %s color space' % name
609     cs.aliases = aliases
610     cs.equality_group = name
611     cs.family = 'Utility'
612     cs.is_data = False
613
614     ctls = [os.path.join(
615         aces_ctl_directory,
616         'utilities',
617         'ACESlib.DolbyPQ_to_lin_param.a1.0.0.ctl')]
618     lut = '%s_to_linear.spi1d' % name
619
620     lut = sanitize(lut)
621
622     generate_1d_LUT_from_CTL(
623         os.path.join(lut_directory, lut),
624         ctls,
625         lut_resolution_1d,
626         'float',
627         input_scale,
628         1.0,
629         {'middleGrey': middle_grey,
630          'minExposure': min_exposure,
631          'maxExposure': max_exposure},
632         cleanup,
633         aces_ctl_directory,
634         min_value,
635         max_value)
636
637     cs.to_reference_transforms = []
638     cs.to_reference_transforms.append({
639         'type': 'lutFile',
640         'path': lut,
641         'interpolation': 'linear',
642         'direction': 'forward'})
643
644     cs.from_reference_transforms = []
645     return cs
646
647
648 # -------------------------------------------------------------------------
649 # Individual *LMT*
650 # -------------------------------------------------------------------------
651 def create_ACES_LMT(lmt_name,
652                     lmt_values,
653                     shaper_info,
654                     aces_ctl_directory,
655                     lut_directory,
656                     lut_resolution_3d=64,
657                     cleanup=True,
658                     aliases=None):
659     """
660     Creates the *ACES LMT* colorspace.
661
662     Parameters
663     ----------
664     parameter : type
665         Parameter description.
666
667     Returns
668     -------
669     Colorspace
670          *ACES LMT* colorspace.
671     """
672
673     if aliases is None:
674         aliases = []
675
676     cs = ColorSpace('%s' % lmt_name)
677     cs.description = 'The ACES Look Transform: %s' % lmt_name
678     cs.aliases = aliases
679     cs.equality_group = ''
680     cs.family = 'Look'
681     cs.is_data = False
682     cs.allocation_type = ocio.Constants.ALLOCATION_LG2
683     cs.allocation_vars = [-8, 5, 0.00390625]
684     cs.aces_transform_id = lmt_values['transformID']
685
686     pprint.pprint(lmt_values)
687
688     # Generating the *shaper* transform.
689     (shaper_name,
690      shaper_to_aces_ctl,
691      shaper_from_aces_ctl,
692      shaper_input_scale,
693      shaper_params) = shaper_info
694
695     shaper_lut = '%s_to_linear.spi1d' % shaper_name
696     shaper_lut = sanitize(shaper_lut)
697
698     shaper_ocio_transform = {
699         'type': 'lutFile',
700         'path': shaper_lut,
701         'interpolation': 'linear',
702         'direction': 'inverse'}
703
704     # Generating the forward transform.
705     cs.from_reference_transforms = []
706
707     if 'transformCTL' in lmt_values:
708         ctls = [shaper_to_aces_ctl % aces_ctl_directory,
709                 os.path.join(aces_ctl_directory,
710                              lmt_values['transformCTL'])]
711         lut = '%s.%s.spi3d' % (shaper_name, lmt_name)
712
713         lut = sanitize(lut)
714
715         generate_3d_LUT_from_CTL(
716             os.path.join(lut_directory, lut),
717             ctls,
718             lut_resolution_3d,
719             'float',
720             1 / shaper_input_scale,
721             1,
722             shaper_params,
723             cleanup,
724             aces_ctl_directory)
725
726         cs.from_reference_transforms.append(shaper_ocio_transform)
727         cs.from_reference_transforms.append({
728             'type': 'lutFile',
729             'path': lut,
730             'interpolation': 'tetrahedral',
731             'direction': 'forward'})
732
733     # Generating the inverse transform.
734     cs.to_reference_transforms = []
735
736     if 'transformCTLInverse' in lmt_values:
737         ctls = [os.path.join(aces_ctl_directory,
738                              lmt_values['transformCTLInverse']),
739                 shaper_from_aces_ctl % aces_ctl_directory]
740         # TODO: Investigate unresolved `odt_name` reference.
741         lut = 'Inverse.%s.%s.spi3d' % (odt_name, shaper_name)
742
743         lut = sanitize(lut)
744
745         generate_3d_LUT_from_CTL(
746             os.path.join(lut_directory, lut),
747             ctls,
748             lut_resolution_3d,
749             'half',
750             1,
751             shaper_input_scale,
752             shaper_params,
753             cleanup,
754             aces_ctl_directory,
755             0)
756
757         cs.to_reference_transforms.append({
758             'type': 'lutFile',
759             'path': lut,
760             'interpolation': 'tetrahedral',
761             'direction': 'forward'})
762
763         shaper_inverse = shaper_ocio_transform.copy()
764         shaper_inverse['direction'] = 'forward'
765         cs.to_reference_transforms.append(shaper_inverse)
766
767     return cs
768
769
770 # -------------------------------------------------------------------------
771 # *LMTs*
772 # -------------------------------------------------------------------------
773 def create_LMTs(aces_ctl_directory,
774                 lut_directory,
775                 lut_resolution_1d,
776                 lut_resolution_3d,
777                 lmt_info,
778                 cleanup):
779     """
780     Object description.
781
782     Parameters
783     ----------
784     parameter : type
785         Parameter description.
786
787     Returns
788     -------
789     type
790          Return value description.
791     """
792
793     colorspaces = []
794
795     # -------------------------------------------------------------------------
796     # *LMT Shaper*
797     # -------------------------------------------------------------------------
798     lmt_lut_resolution_1d = max(4096, lut_resolution_1d)
799     lmt_lut_resolution_3d = max(65, lut_resolution_3d)
800
801     # Defining the *Log 2* shaper.
802     lmt_shaper_name = 'LMT Shaper'
803     lmt_shaper_name_aliases = ['crv_lmtshaper']
804     lmt_params = {
805         'middleGrey': 0.18,
806         'minExposure': -10,
807         'maxExposure': 6.5}
808
809     lmt_shaper = create_generic_log(aces_ctl_directory,
810                                     lut_directory,
811                                     lmt_lut_resolution_1d,
812                                     cleanup,
813                                     name=lmt_shaper_name,
814                                     middle_grey=lmt_params['middleGrey'],
815                                     min_exposure=lmt_params['minExposure'],
816                                     max_exposure=lmt_params['maxExposure'],
817                                     aliases=lmt_shaper_name_aliases)
818     colorspaces.append(lmt_shaper)
819
820     shaper_input_scale_generic_log2 = 1
821
822     # *Log 2* shaper name and *CTL* transforms bundled up.
823     lmt_shaper_data = [
824         lmt_shaper_name,
825         os.path.join('%s',
826                      'utilities',
827                      'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
828         os.path.join('%s',
829                      'utilities',
830                      'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
831         shaper_input_scale_generic_log2,
832         lmt_params]
833
834     sorted_lmts = sorted(lmt_info.iteritems(), key=lambda x: x[1])
835     print(sorted_lmts)
836     for lmt in sorted_lmts:
837         lmt_name, lmt_values = lmt
838         lmt_aliases = ['look_%s' % compact(lmt_values['transformUserName'])]
839         cs = create_ACES_LMT(
840             lmt_values['transformUserName'],
841             lmt_values,
842             lmt_shaper_data,
843             aces_ctl_directory,
844             lut_directory,
845             lmt_lut_resolution_3d,
846             cleanup,
847             lmt_aliases)
848         colorspaces.append(cs)
849
850     return colorspaces
851
852
853 # -------------------------------------------------------------------------
854 # *ACES RRT* with supplied *ODT*.
855 # -------------------------------------------------------------------------
856 def create_ACES_RRT_plus_ODT(odt_name,
857                              odt_values,
858                              shaper_info,
859                              aces_ctl_directory,
860                              lut_directory,
861                              lut_resolution_3d=64,
862                              cleanup=True,
863                              aliases=None):
864     """
865     Object description.
866
867     Parameters
868     ----------
869     parameter : type
870         Parameter description.
871
872     Returns
873     -------
874     type
875          Return value description.
876     """
877
878     if aliases is None:
879         aliases = []
880
881     cs = ColorSpace('%s' % odt_name)
882     cs.description = '%s - %s Output Transform' % (
883         odt_values['transformUserNamePrefix'], odt_name)
884     cs.aliases = aliases
885     cs.equality_group = ''
886     cs.family = 'Output'
887     cs.is_data = False
888
889     cs.aces_transform_id = odt_values['transformID']
890
891     pprint.pprint(odt_values)
892
893     # Generating the *shaper* transform.
894     (shaper_name,
895      shaper_to_aces_ctl,
896      shaper_from_aces_ctl,
897      shaper_input_scale,
898      shaper_params) = shaper_info
899
900     if 'legalRange' in odt_values:
901         shaper_params['legalRange'] = odt_values['legalRange']
902     else:
903         shaper_params['legalRange'] = 0
904
905     shaper_lut = '%s_to_linear.spi1d' % shaper_name
906     shaper_lut = sanitize(shaper_lut)
907
908     shaper_ocio_transform = {
909         'type': 'lutFile',
910         'path': shaper_lut,
911         'interpolation': 'linear',
912         'direction': 'inverse'}
913
914     # Generating the *forward* transform.
915     cs.from_reference_transforms = []
916
917     if 'transformLUT' in odt_values:
918         transform_lut_file_name = os.path.basename(
919             odt_values['transformLUT'])
920         lut = os.path.join(lut_directory, transform_lut_file_name)
921         shutil.copy(odt_values['transformLUT'], lut)
922
923         cs.from_reference_transforms.append(shaper_ocio_transform)
924         cs.from_reference_transforms.append({
925             'type': 'lutFile',
926             'path': transform_lut_file_name,
927             'interpolation': 'tetrahedral',
928             'direction': 'forward'})
929     elif 'transformCTL' in odt_values:
930         ctls = [
931             shaper_to_aces_ctl % aces_ctl_directory,
932             os.path.join(aces_ctl_directory,
933                          'rrt',
934                          'RRT.a1.0.0.ctl'),
935             os.path.join(aces_ctl_directory,
936                          'odt',
937                          odt_values['transformCTL'])]
938         lut = '%s.RRT.a1.0.0.%s.spi3d' % (shaper_name, odt_name)
939
940         lut = sanitize(lut)
941
942         generate_3d_LUT_from_CTL(
943             os.path.join(lut_directory, lut),
944             ctls,
945             lut_resolution_3d,
946             'float',
947             1 / shaper_input_scale,
948             1,
949             shaper_params,
950             cleanup,
951             aces_ctl_directory)
952
953         cs.from_reference_transforms.append(shaper_ocio_transform)
954         cs.from_reference_transforms.append({
955             'type': 'lutFile',
956             'path': lut,
957             'interpolation': 'tetrahedral',
958             'direction': 'forward'})
959
960     # Generating the *inverse* transform.
961     cs.to_reference_transforms = []
962
963     if 'transformLUTInverse' in odt_values:
964         transform_lut_inverse_file_name = os.path.basename(
965             odt_values['transformLUTInverse'])
966         lut = os.path.join(lut_directory, transform_lut_inverse_file_name)
967         shutil.copy(odt_values['transformLUTInverse'], lut)
968
969         cs.to_reference_transforms.append({
970             'type': 'lutFile',
971             'path': transform_lut_inverse_file_name,
972             'interpolation': 'tetrahedral',
973             'direction': 'forward'})
974
975         shaper_inverse = shaper_ocio_transform.copy()
976         shaper_inverse['direction'] = 'forward'
977         cs.to_reference_transforms.append(shaper_inverse)
978     elif 'transformCTLInverse' in odt_values:
979         ctls = [os.path.join(aces_ctl_directory,
980                              'odt',
981                              odt_values['transformCTLInverse']),
982                 os.path.join(aces_ctl_directory,
983                              'rrt',
984                              'InvRRT.a1.0.0.ctl'),
985                 shaper_from_aces_ctl % aces_ctl_directory]
986         lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name)
987
988         lut = sanitize(lut)
989
990         generate_3d_LUT_from_CTL(
991             os.path.join(lut_directory, lut),
992             ctls,
993             lut_resolution_3d,
994             'half',
995             1,
996             shaper_input_scale,
997             shaper_params,
998             cleanup,
999             aces_ctl_directory)
1000
1001         cs.to_reference_transforms.append({
1002             'type': 'lutFile',
1003             'path': lut,
1004             'interpolation': 'tetrahedral',
1005             'direction': 'forward'})
1006
1007         shaper_inverse = shaper_ocio_transform.copy()
1008         shaper_inverse['direction'] = 'forward'
1009         cs.to_reference_transforms.append(shaper_inverse)
1010
1011     return cs
1012
1013
1014 # -------------------------------------------------------------------------
1015 # *ODTs*
1016 # -------------------------------------------------------------------------
1017 def create_ODTs(aces_ctl_directory,
1018                 lut_directory,
1019                 lut_resolution_1d,
1020                 lut_resolution_3d,
1021                 odt_info,
1022                 shaper_name,
1023                 cleanup,
1024                 linear_display_space,
1025                 log_display_space):
1026     """
1027     Object description.
1028
1029     Parameters
1030     ----------
1031     parameter : type
1032         Parameter description.
1033
1034     Returns
1035     -------
1036     type
1037          Return value description.
1038     """
1039
1040     colorspaces = []
1041     displays = {}
1042
1043     # -------------------------------------------------------------------------
1044     # *RRT / ODT* Shaper Options
1045     # -------------------------------------------------------------------------
1046     shaper_data = {}
1047
1048     # Defining the *Log 2* shaper.
1049     log2_shaper_name = shaper_name
1050     log2_shaper_name_aliases = ['crv_%s' % compact(log2_shaper_name)]
1051     log2_params = {
1052         'middleGrey': 0.18,
1053         'minExposure': -6,
1054         'maxExposure': 6.5}
1055
1056     log2_shaper_colorspace = create_generic_log(
1057         aces_ctl_directory,
1058         lut_directory,
1059         lut_resolution_1d,
1060         cleanup,
1061         name=log2_shaper_name,
1062         middle_grey=log2_params['middleGrey'],
1063         min_exposure=log2_params['minExposure'],
1064         max_exposure=log2_params['maxExposure'],
1065         aliases=log2_shaper_name_aliases)
1066     colorspaces.append(log2_shaper_colorspace)
1067
1068     shaper_input_scale_generic_log2 = 1
1069
1070     # *Log 2* shaper name and *CTL* transforms bundled up.
1071     log2_shaper_data = [
1072         log2_shaper_name,
1073         os.path.join('%s',
1074                      'utilities',
1075                      'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
1076         os.path.join('%s',
1077                      'utilities',
1078                      'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
1079         shaper_input_scale_generic_log2,
1080         log2_params]
1081
1082     shaper_data[log2_shaper_name] = log2_shaper_data
1083
1084     # Space with a more user-friendly name. Direct copy otherwise.
1085     log2_shaper_copy_name = 'Log2 Shaper'
1086     log2_shaper_copy_colorspace = ColorSpace(log2_shaper_copy_name)
1087     log2_shaper_copy_colorspace.description = (
1088         'The %s color space' % log2_shaper_copy_name)
1089     log2_shaper_copy_colorspace.aliases = [
1090         'crv_%s' % compact(log2_shaper_copy_name)]
1091     log2_shaper_copy_colorspace.equality_group = log2_shaper_copy_name
1092     log2_shaper_copy_colorspace.family = log2_shaper_colorspace.family
1093     log2_shaper_copy_colorspace.is_data = log2_shaper_colorspace.is_data
1094     log2_shaper_copy_colorspace.to_reference_transforms = list(
1095         log2_shaper_colorspace.to_reference_transforms)
1096     log2_shaper_copy_colorspace.from_reference_transforms = list(
1097         log2_shaper_colorspace.from_reference_transforms)
1098     colorspaces.append(log2_shaper_copy_colorspace)
1099
1100     # Defining the *Log2 shaper that includes the AP1* primaries.
1101     log2_shaper_api1_name = '%s - AP1' % 'Log2 Shaper'
1102     log2_shaper_api1_colorspace = ColorSpace(log2_shaper_api1_name)
1103     log2_shaper_api1_colorspace.description = (
1104         'The %s color space' % log2_shaper_api1_name)
1105     log2_shaper_api1_colorspace.aliases = [
1106         '%s_ap1' % compact(log2_shaper_copy_name)]
1107     log2_shaper_api1_colorspace.equality_group = log2_shaper_api1_name
1108     log2_shaper_api1_colorspace.family = log2_shaper_colorspace.family
1109     log2_shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1110     log2_shaper_api1_colorspace.to_reference_transforms = list(
1111         log2_shaper_colorspace.to_reference_transforms)
1112     log2_shaper_api1_colorspace.from_reference_transforms = list(
1113         log2_shaper_colorspace.from_reference_transforms)
1114
1115     # *AP1* primaries to *AP0* primaries
1116     log2_shaper_api1_colorspace.to_reference_transforms.append({
1117         'type': 'matrix',
1118         'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
1119         'direction': 'forward'
1120     })
1121     colorspaces.append(log2_shaper_api1_colorspace)
1122
1123     # Defining the *Log2* shaper that includes the *AP1* primaries.
1124     # Named with `shaper_name` variable and needed for some *LUT* baking steps.
1125     shaper_api1_name = '%s - AP1' % shaper_name
1126     shaper_api1_colorspace = ColorSpace(shaper_api1_name)
1127     shaper_api1_colorspace.description = (
1128         'The %s color space' % shaper_api1_name)
1129     shaper_api1_colorspace.aliases = ['%s_ap1' % compact(shaper_name)]
1130     shaper_api1_colorspace.equality_group = shaper_api1_name
1131     shaper_api1_colorspace.family = log2_shaper_colorspace.family
1132     shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1133     shaper_api1_colorspace.to_reference_transforms = list(
1134         log2_shaper_api1_colorspace.to_reference_transforms)
1135     shaper_api1_colorspace.from_reference_transforms = list(
1136         log2_shaper_api1_colorspace.from_reference_transforms)
1137     colorspaces.append(shaper_api1_colorspace)
1138
1139     # Define the base *Dolby PQ Shaper*
1140     #
1141     dolby_pq_shaper_name = 'Dolby PQ 10000'
1142     dolby_pq_shaper_name_aliases = ['crv_%s' % 'dolbypq_10000']
1143
1144     dolby_pq_shaper_colorspace = create_Dolby_PQ(
1145         aces_ctl_directory,
1146         lut_directory,
1147         lut_resolution_1d,
1148         cleanup,
1149         name=dolby_pq_shaper_name,
1150         aliases=dolby_pq_shaper_name_aliases)
1151     colorspaces.append(dolby_pq_shaper_colorspace)
1152
1153     # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1154     dolby_pq_shaper_data = [
1155         dolby_pq_shaper_name,
1156         os.path.join('%s',
1157                      'utilities',
1158                      'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl'),
1159         os.path.join('%s',
1160                      'utilities',
1161                      'ACESlib.Lin_to_DolbyPQ.a1.0.0.ctl'),
1162         1.0,
1163         {}]
1164
1165     shaper_data[dolby_pq_shaper_name] = dolby_pq_shaper_data
1166
1167     # Define the *Dolby PQ Shaper that considers a fixed linear range*
1168     dolby_pq_scaled_shaper_name = 'Dolby PQ Scaled'
1169     dolby_pq_scaled_shaper_name_aliases = ['crv_%s' % 'dolbypq_scaled']
1170
1171     dolby_pq_scaled_shaper_colorspace = create_Dolby_PQ_scaled(
1172         aces_ctl_directory,
1173         lut_directory,
1174         lut_resolution_1d,
1175         cleanup,
1176         name=dolby_pq_scaled_shaper_name,
1177         aliases=dolby_pq_scaled_shaper_name_aliases)
1178     colorspaces.append(dolby_pq_scaled_shaper_colorspace)
1179
1180     # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1181     dolby_pq_scaled_shaper_data = [
1182         dolby_pq_scaled_shaper_name,
1183         os.path.join('%s',
1184                      'utilities',
1185                      'ACESlib.DolbyPQ_to_Lin_param.a1.0.0.ctl'),
1186         os.path.join('%s',
1187                      'utilities',
1188                      'ACESlib.Lin_to_DolbyPQ_param.a1.0.0.ctl'),
1189         1.0,
1190         log2_params]
1191
1192     shaper_data[dolby_pq_scaled_shaper_name] = dolby_pq_scaled_shaper_data
1193
1194     rrt_shaper = log2_shaper_data
1195     # rrt_shaper = dolby_pq_scaled_shaper_data
1196
1197     # *RRT + ODT* combinations.
1198     sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1])
1199     print(sorted_odts)
1200     for odt in sorted_odts:
1201         (odt_name, odt_values) = odt
1202
1203         # Defining full range transform for *ODTs* that can only generate
1204         # either *legal* or *full* output.
1205
1206         # Uncomment these lines and the lower section and
1207         # flip the `legalRange` value to 1 to restore the old behavior,
1208         # where both *legal* or *full* range *LUTs* were generated.
1209         if odt_values['transformHasFullLegalSwitch']:
1210             # odt_name_legal = '%s - Legal' % odt_values['transformUserName']
1211             odt_legal['legalRange'] = 0
1212         # else:
1213         #    odt_name_legal = odt_values['transformUserName']
1214
1215         odt_name_legal = odt_values['transformUserName']
1216
1217         odt_legal = odt_values.copy()
1218
1219         odt_aliases = ['out_%s' % compact(odt_name_legal)]
1220
1221         cs = create_ACES_RRT_plus_ODT(
1222             odt_name_legal,
1223             odt_legal,
1224             rrt_shaper,
1225             aces_ctl_directory,
1226             lut_directory,
1227             lut_resolution_3d,
1228             cleanup,
1229             odt_aliases)
1230         colorspaces.append(cs)
1231
1232         displays[odt_name_legal] = {
1233             'Raw': linear_display_space,
1234             'Log': log_display_space,
1235             'Output Transform': cs}
1236
1237         """
1238         # Generating full range transform for *ODTs* that can generate 
1239         # either *legal* or *full* output.
1240         if odt_values['transformHasFullLegalSwitch']:
1241             print('Generating full range ODT for %s' % odt_name)
1242
1243             odt_name_full = '%s - Full' % odt_values['transformUserName']
1244             odt_full = odt_values.copy()
1245             odt_full['legalRange'] = 0
1246
1247             odt_full_aliases = ['out_%s' % compact(odt_name_full)]
1248
1249             cs_full = create_ACES_RRT_plus_ODT(
1250                 odt_name_full,
1251                 odt_full,
1252                 rrt_shaper,
1253                 aces_ctl_directory,
1254                 lut_directory,
1255                 lut_resolution_1d,
1256                 lut_resolution_3d,
1257                 cleanup,
1258                 odt_full_aliases)
1259             colorspaces.append(cs_full)
1260
1261             displays[odt_name_full] = {
1262                 'Raw': linear_display_space,
1263                 'Log': log_display_space,
1264                 'Output Transform': cs_full}
1265         """
1266
1267     return colorspaces, displays
1268
1269
1270 def get_transform_info(ctl_transform):
1271     """
1272     Object description.
1273
1274     Parameters
1275     ----------
1276     parameter : type
1277         Parameter description.
1278
1279     Returns
1280     -------
1281     type
1282          Return value description.
1283     """
1284
1285     with open(ctl_transform, 'rb') as fp:
1286         lines = fp.readlines()
1287
1288     # Retrieving the *transform ID* and *User Name*.
1289     transform_id = lines[1][3:].split('<')[1].split('>')[1].strip()
1290     transform_user_name = '-'.join(
1291         lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip()
1292     transform_user_name_prefix = (
1293         lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
1294
1295     # Figuring out if this transform has options for processing *full* and
1296     # *legal* ranges.
1297     transform_full_legal_switch = False
1298     for line in lines:
1299         if line.strip() == 'input varying int legalRange = 0':
1300             # print( '%s has legal range flag' % transform_user_name)
1301             transform_full_legal_switch = True
1302             break
1303
1304     return (transform_id,
1305             transform_user_name,
1306             transform_user_name_prefix,
1307             transform_full_legal_switch)
1308
1309
1310 def get_ODTs_info(aces_ctl_directory):
1311     """
1312     Object description.
1313
1314     For versions after WGR9.
1315
1316     Parameters
1317     ----------
1318     parameter : type
1319         Parameter description.
1320
1321     Returns
1322     -------
1323     type
1324          Return value description.
1325     """
1326
1327     # TODO: Investigate usage of *files_walker* definition here.
1328     # Credit to *Alex Fry* for the original approach here.
1329     odt_dir = os.path.join(aces_ctl_directory, 'odt')
1330     all_odt = []
1331     for dir_name, subdir_list, file_list in os.walk(odt_dir):
1332         for fname in file_list:
1333             all_odt.append((os.path.join(dir_name, fname)))
1334
1335     odt_ctls = [x for x in all_odt if
1336                 ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')]
1337
1338     odts = {}
1339
1340     for odt_ctl in odt_ctls:
1341         odt_tokens = os.path.split(odt_ctl)
1342
1343         # Handling nested directories.
1344         odt_path_tokens = os.path.split(odt_tokens[-2])
1345         odt_dir = odt_path_tokens[-1]
1346         while odt_path_tokens[-2][-3:] != 'odt':
1347             odt_path_tokens = os.path.split(odt_path_tokens[-2])
1348             odt_dir = os.path.join(odt_path_tokens[-1], odt_dir)
1349
1350         # Building full name.
1351         transform_ctl = odt_tokens[-1]
1352         odt_name = string.join(transform_ctl.split('.')[1:-1], '.')
1353
1354         # Finding id, user name and user name prefix.
1355         (transform_id,
1356          transform_user_name,
1357          transform_user_name_prefix,
1358          transform_full_legal_switch) = get_transform_info(
1359             os.path.join(aces_ctl_directory, 'odt', odt_dir, transform_ctl))
1360
1361         # Finding inverse.
1362         transform_ctl_inverse = 'InvODT.%s.ctl' % odt_name
1363         if not os.path.exists(
1364                 os.path.join(odt_tokens[-2], transform_ctl_inverse)):
1365             transform_ctl_inverse = None
1366
1367         # Adding to list of *ODTs*.
1368         odts[odt_name] = {}
1369         odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_ctl)
1370         if transform_ctl_inverse is not None:
1371             odts[odt_name]['transformCTLInverse'] = os.path.join(
1372                 odt_dir, transform_ctl_inverse)
1373
1374         odts[odt_name]['transformID'] = transform_id
1375         odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1376         odts[odt_name]['transformUserName'] = transform_user_name
1377         odts[odt_name][
1378             'transformHasFullLegalSwitch'] = transform_full_legal_switch
1379
1380         forward_ctl = odts[odt_name]['transformCTL']
1381
1382         print('ODT : %s' % odt_name)
1383         print('\tTransform ID               : %s' % transform_id)
1384         print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1385         print('\tTransform User Name        : %s' % transform_user_name)
1386         print(
1387             '\tHas Full / Legal Switch    : %s' % transform_full_legal_switch)
1388         print('\tForward ctl                : %s' % forward_ctl)
1389         if 'transformCTLInverse' in odts[odt_name]:
1390             inverse_ctl = odts[odt_name]['transformCTLInverse']
1391             print('\tInverse ctl                : %s' % inverse_ctl)
1392         else:
1393             print('\tInverse ctl                : %s' % 'None')
1394
1395     print('\n')
1396
1397     return odts
1398
1399
1400 def get_LMTs_info(aces_ctl_directory):
1401     """
1402     Object description.
1403
1404     For versions after WGR9.
1405
1406     Parameters
1407     ----------
1408     parameter : type
1409         Parameter description.
1410
1411     Returns
1412     -------
1413     type
1414          Return value description.
1415     """
1416
1417     # TODO: Investigate refactoring with previous definition.
1418
1419     # Credit to Alex Fry for the original approach here
1420     lmt_dir = os.path.join(aces_ctl_directory, 'lmt')
1421     all_lmt = []
1422     for dir_name, subdir_list, file_list in os.walk(lmt_dir):
1423         for fname in file_list:
1424             all_lmt.append((os.path.join(dir_name, fname)))
1425
1426     lmt_ctls = [x for x in all_lmt if
1427                 ('InvLMT' not in x) and ('README' not in x) and (
1428                     os.path.split(x)[-1][0] != '.')]
1429
1430     lmts = {}
1431
1432     for lmt_ctl in lmt_ctls:
1433         lmt_tokens = os.path.split(lmt_ctl)
1434
1435         # Handlimg nested directories.
1436         lmt_path_tokens = os.path.split(lmt_tokens[-2])
1437         lmt_dir = lmt_path_tokens[-1]
1438         while lmt_path_tokens[-2][-3:] != 'ctl':
1439             lmt_path_tokens = os.path.split(lmt_path_tokens[-2])
1440             lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir)
1441
1442         # Building full name.
1443         transform_ctl = lmt_tokens[-1]
1444         lmt_name = string.join(transform_ctl.split('.')[1:-1], '.')
1445
1446         # Finding id, user name and user name prefix.
1447         (transform_id,
1448          transform_user_name,
1449          transform_user_name_prefix,
1450          transform_full_legal_switch) = get_transform_info(
1451             os.path.join(aces_ctl_directory, lmt_dir, transform_ctl))
1452
1453         # Finding inverse.
1454         transform_ctl_inverse = 'InvLMT.%s.ctl' % lmt_name
1455         if not os.path.exists(
1456                 os.path.join(lmt_tokens[-2], transform_ctl_inverse)):
1457             transform_ctl_inverse = None
1458
1459         lmts[lmt_name] = {}
1460         lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_ctl)
1461         if transform_ctl_inverse is not None:
1462             lmts[lmt_name]['transformCTLInverse'] = os.path.join(
1463                 lmt_dir, transform_ctl_inverse)
1464
1465         lmts[lmt_name]['transformID'] = transform_id
1466         lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1467         lmts[lmt_name]['transformUserName'] = transform_user_name
1468
1469         forward_ctl = lmts[lmt_name]['transformCTL']
1470
1471         print('LMT : %s' % lmt_name)
1472         print('\tTransform ID               : %s' % transform_id)
1473         print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1474         print('\tTransform User Name        : %s' % transform_user_name)
1475         print('\t Forward ctl               : %s' % forward_ctl)
1476         if 'transformCTLInverse' in lmts[lmt_name]:
1477             inverse_ctl = lmts[lmt_name]['transformCTLInverse']
1478             print('\t Inverse ctl                : %s' % inverse_ctl)
1479         else:
1480             print('\t Inverse ctl                : %s' % 'None')
1481
1482     print('\n')
1483
1484     return lmts
1485
1486
1487 def create_colorspaces(aces_ctl_directory,
1488                        lut_directory,
1489                        lut_resolution_1d,
1490                        lut_resolution_3d,
1491                        lmt_info,
1492                        odt_info,
1493                        shaper_name,
1494                        cleanup):
1495     """
1496     Generates the colorspace conversions.
1497
1498     Parameters
1499     ----------
1500     parameter : type
1501         Parameter description.
1502
1503     Returns
1504     -------
1505     type
1506          Return value description.
1507     """
1508
1509     colorspaces = []
1510
1511     ACES = create_ACES()
1512
1513     ACEScc = create_ACEScc(aces_ctl_directory, lut_directory,
1514                            lut_resolution_1d, cleanup,
1515                            min_value=-0.35840, max_value=1.468)
1516     colorspaces.append(ACEScc)
1517
1518     ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory,
1519                                  lut_resolution_1d, cleanup)
1520     colorspaces.append(ACESproxy)
1521
1522     ACEScg = create_ACEScg()
1523     colorspaces.append(ACEScg)
1524
1525     ADX10 = create_ADX(lut_directory, bit_depth=10)
1526     colorspaces.append(ADX10)
1527
1528     ADX16 = create_ADX(lut_directory, bit_depth=16)
1529     colorspaces.append(ADX16)
1530
1531     lmts = create_LMTs(aces_ctl_directory,
1532                        lut_directory,
1533                        lut_resolution_1d,
1534                        lut_resolution_3d,
1535                        lmt_info,
1536                        cleanup)
1537     colorspaces.extend(lmts)
1538
1539     odts, displays = create_ODTs(aces_ctl_directory,
1540                                  lut_directory,
1541                                  lut_resolution_1d,
1542                                  lut_resolution_3d,
1543                                  odt_info,
1544                                  shaper_name,
1545                                  cleanup,
1546                                  ACES,
1547                                  ACEScc)
1548     colorspaces.extend(odts)
1549
1550     # TODO: Investigate if there is a way to retrieve the value from *CTL*.
1551     default_display = 'sRGB (D60 sim.)'
1552
1553     roles = {'color_picking': ACEScg.name,
1554              'color_timing': ACEScc.name,
1555              'compositing_log': ACEScc.name,
1556              'data': '',
1557              'default': ACES.name,
1558              'matte_paint': ACEScc.name,
1559              'reference': '',
1560              'scene_linear': ACEScg.name,
1561              'texture_paint': ''}
1562
1563     return ACES, colorspaces, displays, ACEScc, roles, default_display