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