Remove unused locals.
[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     # Convert from Channel-Dependent Density to Channel-Independent Density
358     cs.to_reference_transforms.append({
359         'type': 'matrix',
360         'matrix': [0.75573, 0.22197, 0.02230, 0,
361                    0.05901, 0.96928, -0.02829, 0,
362                    0.16134, 0.07406, 0.76460, 0,
363                    0, 0, 0, 1],
364         'direction': 'forward'})
365
366     # Copied from *Alex Fry*'s *adx_cid_to_rle.py*
367     def create_CID_to_RLE_LUT():
368
369         def interpolate_1d(x, xp, fp):
370             return numpy.interp(x, xp, fp)
371
372         LUT_1D_XP = [-0.190000000000000,
373                      0.010000000000000,
374                      0.028000000000000,
375                      0.054000000000000,
376                      0.095000000000000,
377                      0.145000000000000,
378                      0.220000000000000,
379                      0.300000000000000,
380                      0.400000000000000,
381                      0.500000000000000,
382                      0.600000000000000]
383
384         LUT_1D_FP = [-6.000000000000000,
385                      -2.721718645000000,
386                      -2.521718645000000,
387                      -2.321718645000000,
388                      -2.121718645000000,
389                      -1.921718645000000,
390                      -1.721718645000000,
391                      -1.521718645000000,
392                      -1.321718645000000,
393                      -1.121718645000000,
394                      -0.926545676714876]
395
396         REF_PT = ((7120 - 1520) / 8000 * (100 / 55) -
397                   math.log(0.18, 10))
398
399         def cid_to_rle(x):
400             if x <= 0.6:
401                 return interpolate_1d(x, LUT_1D_XP, LUT_1D_FP)
402             return (100 / 55) * x - REF_PT
403
404         def fit(value, from_min, from_max, to_min, to_max):
405             if from_min == from_max:
406                 raise ValueError('from_min == from_max')
407             return (value - from_min) / (from_max - from_min) * (
408                 to_max - to_min) + to_min
409
410         num_samples = 2 ** 12
411         domain = (-0.19, 3)
412         data = []
413         for i in xrange(num_samples):
414             x = i / (num_samples - 1)
415             x = fit(x, 0, 1, domain[0], domain[1])
416             data.append(cid_to_rle(x))
417
418         lut = 'ADX_CID_to_RLE.spi1d'
419         write_SPI_1d(os.path.join(lut_directory, lut),
420                      domain[0],
421                      domain[1],
422                      data,
423                      num_samples, 1)
424
425         return lut
426
427     # Converting *Channel Independent Density* values to
428     # *Relative Log Exposure* values.
429     lut = create_CID_to_RLE_LUT()
430     cs.to_reference_transforms.append({
431         'type': 'lutFile',
432         'path': lut,
433         'interpolation': 'linear',
434         'direction': 'forward'})
435
436     # Converting *Relative Log Exposure* values to
437     # *Relative Exposure* values.
438     cs.to_reference_transforms.append({
439         'type': 'log',
440         'base': 10,
441         'direction': 'inverse'})
442
443     # Convert *Relative Exposure* values to *ACES* values.
444     cs.to_reference_transforms.append({
445         'type': 'matrix',
446         'matrix': [0.72286, 0.12630, 0.15084, 0,
447                    0.11923, 0.76418, 0.11659, 0,
448                    0.01427, 0.08213, 0.90359, 0,
449                    0, 0, 0, 1],
450         'direction': 'forward'})
451
452     cs.from_reference_transforms = []
453     return cs
454
455
456 # -------------------------------------------------------------------------
457 # *Generic Log Transform*
458 # -------------------------------------------------------------------------
459 def create_generic_log(aces_ctl_directory,
460                        lut_directory,
461                        lut_resolution_1d,
462                        cleanup,
463                        name='log',
464                        aliases=None,
465                        min_value=0,
466                        max_value=1,
467                        input_scale=1,
468                        middle_grey=0.18,
469                        min_exposure=-6,
470                        max_exposure=6.5):
471     """
472     Creates the *Generic Log* colorspace.
473
474     Parameters
475     ----------
476     parameter : type
477         Parameter description.
478
479     Returns
480     -------
481     Colorspace
482          *Generic Log* colorspace.
483     """
484
485     if aliases is None:
486         aliases = []
487
488     cs = ColorSpace(name)
489     cs.description = 'The %s color space' % name
490     cs.aliases = aliases
491     cs.equality_group = name
492     cs.family = 'Utility'
493     cs.is_data = False
494
495     ctls = [os.path.join(
496         aces_ctl_directory,
497         'utilities',
498         'ACESlib.Log2_to_Lin_param.a1.0.0.ctl')]
499     lut = '%s_to_linear.spi1d' % name
500
501     lut = sanitize(lut)
502
503     generate_1d_LUT_from_CTL(
504         os.path.join(lut_directory, lut),
505         ctls,
506         lut_resolution_1d,
507         'float',
508         input_scale,
509         1,
510         {'middleGrey': middle_grey,
511          'minExposure': min_exposure,
512          'maxExposure': max_exposure},
513         cleanup,
514         aces_ctl_directory,
515         min_value,
516         max_value,
517         1)
518
519     cs.to_reference_transforms = []
520     cs.to_reference_transforms.append({
521         'type': 'lutFile',
522         'path': lut,
523         'interpolation': 'linear',
524         'direction': 'forward'})
525
526     cs.from_reference_transforms = []
527     return cs
528
529
530 # -------------------------------------------------------------------------
531 # *base Dolby PQ Transform*
532 # -------------------------------------------------------------------------
533 def create_Dolby_PQ(aces_ctl_directory,
534                    lut_directory,
535                    lut_resolution_1d,
536                    cleanup,
537                    name='pq',
538                    aliases=None,
539                    min_value=0.0,
540                    max_value=1.0,
541                    input_scale=1.0):
542     if aliases is None:
543         aliases = []
544
545     cs = ColorSpace(name)
546     cs.description = 'The %s color space' % name
547     cs.aliases = aliases
548     cs.equality_group = name
549     cs.family = 'Utility'
550     cs.is_data = False
551
552     ctls = [os.path.join(
553         aces_ctl_directory,
554         'utilities',
555         'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl')]
556     lut = '%s_to_linear.spi1d' % name
557
558     lut = sanitize(lut)
559
560     generate_1d_LUT_from_CTL(
561         os.path.join(lut_directory, lut),
562         ctls,
563         lut_resolution_1d,
564         'float',
565         input_scale,
566         1.0,
567         {},
568         cleanup,
569         aces_ctl_directory,
570         min_value,
571         max_value)
572
573     cs.to_reference_transforms = []
574     cs.to_reference_transforms.append({
575         'type': 'lutFile',
576         'path': lut,
577         'interpolation': 'linear',
578         'direction': 'forward'})
579
580     cs.from_reference_transforms = []
581     return cs
582
583
584 # -------------------------------------------------------------------------
585 # *Dolby PQ Transform that considers a fixed linear range*
586 # -------------------------------------------------------------------------
587 def create_Dolby_PQ_scaled(aces_ctl_directory,
588                           lut_directory,
589                           lut_resolution_1d,
590                           cleanup,
591                           name='pq',
592                           aliases=None,
593                           min_value=0.0,
594                           max_value=1.0,
595                           input_scale=1.0,
596                           middle_grey=0.18,
597                           min_exposure=-6.0,
598                           max_exposure=6.5):
599     if aliases is None:
600         aliases = []
601
602     cs = ColorSpace(name)
603     cs.description = 'The %s color space' % name
604     cs.aliases = aliases
605     cs.equality_group = name
606     cs.family = 'Utility'
607     cs.is_data = False
608
609     ctls = [os.path.join(
610         aces_ctl_directory,
611         'utilities',
612         'ACESlib.DolbyPQ_to_lin_param.a1.0.0.ctl')]
613     lut = '%s_to_linear.spi1d' % name
614
615     lut = sanitize(lut)
616
617     generate_1d_LUT_from_CTL(
618         os.path.join(lut_directory, lut),
619         ctls,
620         lut_resolution_1d,
621         'float',
622         input_scale,
623         1.0,
624         {'middleGrey': middle_grey,
625          'minExposure': min_exposure,
626          'maxExposure': max_exposure},
627         cleanup,
628         aces_ctl_directory,
629         min_value,
630         max_value)
631
632     cs.to_reference_transforms = []
633     cs.to_reference_transforms.append({
634         'type': 'lutFile',
635         'path': lut,
636         'interpolation': 'linear',
637         'direction': 'forward'})
638
639     cs.from_reference_transforms = []
640     return cs
641
642
643 # -------------------------------------------------------------------------
644 # *Individual LMT*
645 # -------------------------------------------------------------------------
646 def create_ACES_LMT(lmt_name,
647                     lmt_values,
648                     shaper_info,
649                     aces_ctl_directory,
650                     lut_directory,
651                     lut_resolution_3d=64,
652                     cleanup=True,
653                     aliases=None):
654     """
655     Creates the *ACES LMT* colorspace.
656
657     Parameters
658     ----------
659     parameter : type
660         Parameter description.
661
662     Returns
663     -------
664     Colorspace
665          *ACES LMT* colorspace.
666     """
667
668     if aliases is None:
669         aliases = []
670
671     cs = ColorSpace('%s' % lmt_name)
672     cs.description = 'The ACES Look Transform: %s' % lmt_name
673     cs.aliases = aliases
674     cs.equality_group = ''
675     cs.family = 'Look'
676     cs.is_data = False
677     cs.allocation_type = ocio.Constants.ALLOCATION_LG2
678     cs.allocation_vars = [-8, 5, 0.00390625]
679     cs.aces_transform_id = lmt_values['transformID']
680
681     pprint.pprint(lmt_values)
682
683     # Generating the *shaper* transform.
684     (shaper_name,
685      shaper_to_aces_ctl,
686      shaper_from_aces_ctl,
687      shaper_input_scale,
688      shaper_params) = shaper_info
689
690     # Add the shaper transform
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     # Add the shaper transform
902     shaper_lut = '%s_to_linear.spi1d' % shaper_name
903     shaper_lut = sanitize(shaper_lut)
904
905     shaper_ocio_transform = {
906         'type': 'lutFile',
907         'path': shaper_lut,
908         'interpolation': 'linear',
909         'direction': 'inverse'}
910
911     # Generating the *forward* transform.
912     cs.from_reference_transforms = []
913
914     if 'transformLUT' in odt_values:
915         transform_lut_file_name = os.path.basename(
916             odt_values['transformLUT'])
917         lut = os.path.join(lut_directory, transform_lut_file_name)
918         shutil.copy(odt_values['transformLUT'], lut)
919
920         cs.from_reference_transforms.append(shaper_ocio_transform)
921         cs.from_reference_transforms.append({
922             'type': 'lutFile',
923             'path': transform_lut_file_name,
924             'interpolation': 'tetrahedral',
925             'direction': 'forward'})
926     elif 'transformCTL' in odt_values:
927         ctls = [
928             shaper_to_aces_ctl % aces_ctl_directory,
929             os.path.join(aces_ctl_directory,
930                          'rrt',
931                          'RRT.a1.0.0.ctl'),
932             os.path.join(aces_ctl_directory,
933                          'odt',
934                          odt_values['transformCTL'])]
935         lut = '%s.RRT.a1.0.0.%s.spi3d' % (shaper_name, odt_name)
936
937         lut = sanitize(lut)
938
939         generate_3d_LUT_from_CTL(
940             os.path.join(lut_directory, lut),
941             # shaperLUT,
942             ctls,
943             lut_resolution_3d,
944             'float',
945             1 / shaper_input_scale,
946             1,
947             shaper_params,
948             cleanup,
949             aces_ctl_directory)
950
951         cs.from_reference_transforms.append(shaper_ocio_transform)
952         cs.from_reference_transforms.append({
953             'type': 'lutFile',
954             'path': lut,
955             'interpolation': 'tetrahedral',
956             'direction': 'forward'})
957
958     # Generating the *inverse* transform.
959     cs.to_reference_transforms = []
960
961     if 'transformLUTInverse' in odt_values:
962         transform_lut_inverse_file_name = os.path.basename(
963             odt_values['transformLUTInverse'])
964         lut = os.path.join(lut_directory, transform_lut_inverse_file_name)
965         shutil.copy(odt_values['transformLUTInverse'], lut)
966
967         cs.to_reference_transforms.append({
968             'type': 'lutFile',
969             'path': transform_lut_inverse_file_name,
970             'interpolation': 'tetrahedral',
971             'direction': 'forward'})
972
973         shaper_inverse = shaper_ocio_transform.copy()
974         shaper_inverse['direction'] = 'forward'
975         cs.to_reference_transforms.append(shaper_inverse)
976     elif 'transformCTLInverse' in odt_values:
977         ctls = [os.path.join(aces_ctl_directory,
978                              'odt',
979                              odt_values['transformCTLInverse']),
980                 os.path.join(aces_ctl_directory,
981                              'rrt',
982                              'InvRRT.a1.0.0.ctl'),
983                 shaper_from_aces_ctl % aces_ctl_directory]
984         lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name)
985
986         lut = sanitize(lut)
987
988         generate_3d_LUT_from_CTL(
989             os.path.join(lut_directory, lut),
990             # None,
991             ctls,
992             lut_resolution_3d,
993             'half',
994             1,
995             shaper_input_scale,
996             shaper_params,
997             cleanup,
998             aces_ctl_directory)
999
1000         cs.to_reference_transforms.append({
1001             'type': 'lutFile',
1002             'path': lut,
1003             'interpolation': 'tetrahedral',
1004             'direction': 'forward'})
1005
1006         shaper_inverse = shaper_ocio_transform.copy()
1007         shaper_inverse['direction'] = 'forward'
1008         cs.to_reference_transforms.append(shaper_inverse)
1009
1010     return cs
1011
1012
1013 # -------------------------------------------------------------------------
1014 # *ODTs*
1015 # -------------------------------------------------------------------------
1016 def create_ODTs(aces_ctl_directory,
1017                 lut_directory,
1018                 lut_resolution_1d,
1019                 lut_resolution_3d,
1020                 odt_info,
1021                 shaper_name,
1022                 cleanup,
1023                 linear_display_space,
1024                 log_display_space):
1025     """
1026     Object description.
1027
1028     Parameters
1029     ----------
1030     parameter : type
1031         Parameter description.
1032
1033     Returns
1034     -------
1035     type
1036          Return value description.
1037     """
1038
1039     colorspaces = []
1040     displays = {}
1041
1042     # -------------------------------------------------------------------------
1043     # *RRT / ODT* Shaper Options
1044     # -------------------------------------------------------------------------
1045     shaper_data = {}
1046
1047     # Defining the *Log 2* shaper.
1048     log2_shaper_name = shaper_name
1049     log2_shaper_name_aliases = ['crv_%s' % compact(log2_shaper_name)]
1050     log2_params = {
1051         'middleGrey': 0.18,
1052         'minExposure': -6,
1053         'maxExposure': 6.5}
1054
1055     log2_shaper_colorspace = create_generic_log(
1056         aces_ctl_directory,
1057         lut_directory,
1058         lut_resolution_1d,
1059         cleanup,
1060         name=log2_shaper_name,
1061         middle_grey=log2_params['middleGrey'],
1062         min_exposure=log2_params['minExposure'],
1063         max_exposure=log2_params['maxExposure'],
1064         aliases=log2_shaper_name_aliases)
1065     colorspaces.append(log2_shaper_colorspace)
1066
1067     shaper_input_scale_generic_log2 = 1
1068
1069     # *Log 2* shaper name and *CTL* transforms bundled up.
1070     log2_shaper_data = [
1071         log2_shaper_name,
1072         os.path.join('%s',
1073                      'utilities',
1074                      'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
1075         os.path.join('%s',
1076                      'utilities',
1077                      'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
1078         shaper_input_scale_generic_log2,
1079         log2_params]
1080
1081     shaper_data[log2_shaper_name] = log2_shaper_data
1082
1083     # Space with a more user-friendly name. Direct copy otherwise.
1084     log2_shaper_copy_name = 'Log2 Shaper'
1085     log2_shaper_copy_colorspace = ColorSpace(log2_shaper_copy_name)
1086     log2_shaper_copy_colorspace.description = (
1087         'The %s color space' % log2_shaper_copy_name)
1088     log2_shaper_copy_colorspace.aliases = [
1089         'crv_%s' % compact(log2_shaper_copy_name)]
1090     log2_shaper_copy_colorspace.equality_group = log2_shaper_copy_name
1091     log2_shaper_copy_colorspace.family = log2_shaper_colorspace.family
1092     log2_shaper_copy_colorspace.is_data = log2_shaper_colorspace.is_data
1093     log2_shaper_copy_colorspace.to_reference_transforms = list(
1094         log2_shaper_colorspace.to_reference_transforms)
1095     log2_shaper_copy_colorspace.from_reference_transforms = list(
1096         log2_shaper_colorspace.from_reference_transforms)
1097     colorspaces.append(log2_shaper_copy_colorspace)
1098
1099     # Defining the *Log2 shaper that includes the AP1* primaries.
1100     log2_shaper_api1_name = '%s - AP1' % 'Log2 Shaper'
1101     log2_shaper_api1_colorspace = ColorSpace(log2_shaper_api1_name)
1102     log2_shaper_api1_colorspace.description = (
1103         'The %s color space' % log2_shaper_api1_name)
1104     log2_shaper_api1_colorspace.aliases = [
1105         '%s_ap1' % compact(log2_shaper_copy_name)]
1106     log2_shaper_api1_colorspace.equality_group = log2_shaper_api1_name
1107     log2_shaper_api1_colorspace.family = log2_shaper_colorspace.family
1108     log2_shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1109     log2_shaper_api1_colorspace.to_reference_transforms = list(
1110         log2_shaper_colorspace.to_reference_transforms)
1111     log2_shaper_api1_colorspace.from_reference_transforms = list(
1112         log2_shaper_colorspace.from_reference_transforms)
1113
1114     # *AP1* primaries to *AP0* primaries.
1115     log2_shaper_api1_colorspace.to_reference_transforms.append({
1116         'type': 'matrix',
1117         'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
1118         'direction': 'forward'
1119     })
1120     colorspaces.append(log2_shaper_api1_colorspace)
1121
1122     # Defining the *Log2 shaper that includes the AP1* primaries.
1123     # Named with 'shaper_name' variable. Needed for some LUT baking steps.
1124     shaper_api1_name = '%s - AP1' % shaper_name
1125     shaper_api1_colorspace = ColorSpace(shaper_api1_name)
1126     shaper_api1_colorspace.description = (
1127         'The %s color space' % shaper_api1_name)
1128     shaper_api1_colorspace.aliases = ['%s_ap1' % compact(shaper_name)]
1129     shaper_api1_colorspace.equality_group = shaper_api1_name
1130     shaper_api1_colorspace.family = log2_shaper_colorspace.family
1131     shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1132     shaper_api1_colorspace.to_reference_transforms = list(
1133         log2_shaper_api1_colorspace.to_reference_transforms)
1134     shaper_api1_colorspace.from_reference_transforms = list(
1135         log2_shaper_api1_colorspace.from_reference_transforms)
1136     colorspaces.append(shaper_api1_colorspace)
1137
1138     # Define the base *Dolby PQ Shaper*
1139     #
1140     dolbypq_shaper_name = 'Dolby PQ 10000'
1141     dolbypq_shaper_name_aliases = ['crv_%s' % 'dolbypq_10000']
1142
1143     dolbypq_shaper_colorspace = create_Dolby_PQ(
1144         aces_ctl_directory,
1145         lut_directory,
1146         lut_resolution_1d,
1147         cleanup,
1148         name=dolbypq_shaper_name,
1149         aliases=dolbypq_shaper_name_aliases)
1150     colorspaces.append(dolbypq_shaper_colorspace)
1151
1152     # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1153     dolbypq_shaper_data = [
1154         dolbypq_shaper_name,
1155         os.path.join('%s',
1156                      'utilities',
1157                      'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl'),
1158         os.path.join('%s',
1159                      'utilities',
1160                      'ACESlib.Lin_to_DolbyPQ.a1.0.0.ctl'),
1161         1.0,
1162         {}]
1163
1164     shaper_data[dolbypq_shaper_name] = dolbypq_shaper_data
1165
1166     # Define the *Dolby PQ Shaper that considers a fixed linear range*
1167     #
1168     dolbypq_scaled_shaper_name = 'Dolby PQ Scaled'
1169     dolbypq_scaled_shaper_name_aliases = ['crv_%s' % 'dolbypq_scaled']
1170
1171     dolbypq_scaled_shaper_colorspace = create_Dolby_PQ_scaled(
1172         aces_ctl_directory,
1173         lut_directory,
1174         lut_resolution_1d,
1175         cleanup,
1176         name=dolbypq_scaled_shaper_name,
1177         aliases=dolbypq_scaled_shaper_name_aliases)
1178     colorspaces.append(dolbypq_scaled_shaper_colorspace)
1179
1180     # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1181     dolbypq_scaled_shaper_data = [
1182         dolbypq_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[dolbypq_scaled_shaper_name] = dolbypq_scaled_shaper_data
1193
1194     #
1195     # Pick a specific shaper
1196     #
1197     rrt_shaper = log2_shaper_data
1198     # rrt_shaper = dolbypq_scaled_shaper_data
1199
1200     # *RRT + ODT* combinations.
1201     sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1])
1202     print(sorted_odts)
1203     for odt in sorted_odts:
1204         (odt_name, odt_values) = odt
1205
1206         # Generating only full range transform for *ODTs* that can generate 
1207         # either *legal* or *full* output.
1208
1209         # Uncomment these lines and the lower section and
1210         # flip the 'legalRange' value to 1 to recover the old behavior,
1211         # where both legal and full range LUTs were generated.
1212         if odt_values['transformHasFullLegalSwitch']:
1213             # odt_name_legal = '%s - Legal' % odt_values['transformUserName']
1214             odt_legal['legalRange'] = 0
1215         # else:
1216         #    odt_name_legal = odt_values['transformUserName']
1217
1218         odt_name_legal = odt_values['transformUserName']
1219
1220         odt_legal = odt_values.copy()
1221
1222         odt_aliases = ['out_%s' % compact(odt_name_legal)]
1223
1224         cs = create_ACES_RRT_plus_ODT(
1225             odt_name_legal,
1226             odt_legal,
1227             rrt_shaper,
1228             aces_ctl_directory,
1229             lut_directory,
1230             lut_resolution_3d,
1231             cleanup,
1232             odt_aliases)
1233         colorspaces.append(cs)
1234
1235         displays[odt_name_legal] = {
1236             'Raw': linear_display_space,
1237             'Log': log_display_space,
1238             'Output Transform': cs}
1239
1240         """
1241         # Generating full range transform for *ODTs* that can generate 
1242         # either *legal* or *full* output.
1243         if odt_values['transformHasFullLegalSwitch']:
1244             print('Generating full range ODT for %s' % odt_name)
1245
1246             odt_name_full = '%s - Full' % odt_values['transformUserName']
1247             odt_full = odt_values.copy()
1248             odt_full['legalRange'] = 0
1249
1250             odt_full_aliases = ['out_%s' % compact(odt_name_full)]
1251
1252             cs_full = create_ACES_RRT_plus_ODT(
1253                 odt_name_full,
1254                 odt_full,
1255                 rrt_shaper,
1256                 aces_ctl_directory,
1257                 lut_directory,
1258                 lut_resolution_1d,
1259                 lut_resolution_3d,
1260                 cleanup,
1261                 odt_full_aliases)
1262             colorspaces.append(cs_full)
1263
1264             displays[odt_name_full] = {
1265                 'Raw': linear_display_space,
1266                 'Log': log_display_space,
1267                 'Output Transform': cs_full}
1268         """
1269
1270     return colorspaces, displays
1271
1272
1273 def get_transform_info(ctl_transform):
1274     """
1275     Object description.
1276
1277     Parameters
1278     ----------
1279     parameter : type
1280         Parameter description.
1281
1282     Returns
1283     -------
1284     type
1285          Return value description.
1286     """
1287
1288     with open(ctl_transform, 'rb') as fp:
1289         lines = fp.readlines()
1290
1291     # Retrieving the *transform ID* and *User Name*.
1292     transform_id = lines[1][3:].split('<')[1].split('>')[1].strip()
1293     transform_user_name = '-'.join(
1294         lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip()
1295     transform_user_name_prefix = (
1296         lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
1297
1298     # Figuring out if this transform has options
1299     # for processing full and legal range.
1300     transform_full_legal_switch = False
1301     for line in lines:
1302         if line.strip() == 'input varying int legalRange = 0':
1303             # print( '%s has legal range flag' % transform_user_name)
1304             transform_full_legal_switch = True
1305             break
1306
1307     return (transform_id, transform_user_name, transform_user_name_prefix,
1308             transform_full_legal_switch)
1309
1310
1311 def get_ODTs_info(aces_ctl_directory):
1312     """
1313     Object description.
1314
1315     For versions after WGR9.
1316
1317     Parameters
1318     ----------
1319     parameter : type
1320         Parameter description.
1321
1322     Returns
1323     -------
1324     type
1325          Return value description.
1326     """
1327
1328     # TODO: Investigate usage of *files_walker* definition here.
1329     # Credit to *Alex Fry* for the original approach here.
1330     odt_dir = os.path.join(aces_ctl_directory, 'odt')
1331     all_odt = []
1332     for dir_name, subdir_list, file_list in os.walk(odt_dir):
1333         for fname in file_list:
1334             all_odt.append((os.path.join(dir_name, fname)))
1335
1336     odt_ctls = [x for x in all_odt if
1337                 ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')]
1338
1339     odts = {}
1340
1341     for odt_ctl in odt_ctls:
1342         odt_tokens = os.path.split(odt_ctl)
1343
1344         # Handling nested directories.
1345         odt_path_tokens = os.path.split(odt_tokens[-2])
1346         odt_dir = odt_path_tokens[-1]
1347         while odt_path_tokens[-2][-3:] != 'odt':
1348             odt_path_tokens = os.path.split(odt_path_tokens[-2])
1349             odt_dir = os.path.join(odt_path_tokens[-1], odt_dir)
1350
1351         # Building full name,
1352         transform_ctl = odt_tokens[-1]
1353         odt_name = string.join(transform_ctl.split('.')[1:-1], '.')
1354
1355         # Finding id, user name and user name prefix.
1356         (transform_id,
1357          transform_user_name,
1358          transform_user_name_prefix,
1359          transform_full_legal_switch) = get_transform_info(
1360             os.path.join(aces_ctl_directory, 'odt', odt_dir, transform_ctl))
1361
1362         # Finding inverse.
1363         transform_ctl_inverse = 'InvODT.%s.ctl' % odt_name
1364         if not os.path.exists(
1365                 os.path.join(odt_tokens[-2], transform_ctl_inverse)):
1366             transform_ctl_inverse = None
1367
1368         # Add to list of ODTs
1369         odts[odt_name] = {}
1370         odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_ctl)
1371         if transform_ctl_inverse is not None:
1372             odts[odt_name]['transformCTLInverse'] = os.path.join(
1373                 odt_dir, transform_ctl_inverse)
1374
1375         odts[odt_name]['transformID'] = transform_id
1376         odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1377         odts[odt_name]['transformUserName'] = transform_user_name
1378         odts[odt_name][
1379             'transformHasFullLegalSwitch'] = transform_full_legal_switch
1380
1381         forward_ctl = odts[odt_name]['transformCTL']
1382
1383         print('ODT : %s' % odt_name)
1384         print('\tTransform ID               : %s' % transform_id)
1385         print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1386         print('\tTransform User Name        : %s' % transform_user_name)
1387         print(
1388             '\tHas Full / Legal Switch    : %s' % transform_full_legal_switch)
1389         print('\tForward ctl                : %s' % forward_ctl)
1390         if 'transformCTLInverse' in odts[odt_name]:
1391             inverse_ctl = odts[odt_name]['transformCTLInverse']
1392             print('\tInverse ctl                : %s' % inverse_ctl)
1393         else:
1394             print('\tInverse ctl                : %s' % 'None')
1395
1396     print('\n')
1397
1398     return odts
1399
1400
1401 def get_LMTs_info(aces_ctl_directory):
1402     """
1403     Object description.
1404
1405     For versions after WGR9.
1406
1407     Parameters
1408     ----------
1409     parameter : type
1410         Parameter description.
1411
1412     Returns
1413     -------
1414     type
1415          Return value description.
1416     """
1417
1418     # TODO: Investigate refactoring with previous definition.
1419
1420     # Credit to Alex Fry for the original approach here
1421     lmt_dir = os.path.join(aces_ctl_directory, 'lmt')
1422     all_lmt = []
1423     for dir_name, subdir_list, file_list in os.walk(lmt_dir):
1424         for fname in file_list:
1425             all_lmt.append((os.path.join(dir_name, fname)))
1426
1427     lmt_ctls = [x for x in all_lmt if
1428                 ('InvLMT' not in x) and ('README' not in x) and (
1429                     os.path.split(x)[-1][0] != '.')]
1430
1431     lmts = {}
1432
1433     for lmt_ctl in lmt_ctls:
1434         lmt_tokens = os.path.split(lmt_ctl)
1435
1436         # Handlimg nested directories.
1437         lmt_path_tokens = os.path.split(lmt_tokens[-2])
1438         lmt_dir = lmt_path_tokens[-1]
1439         while lmt_path_tokens[-2][-3:] != 'ctl':
1440             lmt_path_tokens = os.path.split(lmt_path_tokens[-2])
1441             lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir)
1442
1443         # Building full name.
1444         transform_CTL = lmt_tokens[-1]
1445         lmt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1446
1447         # Finding id, user name and user name prefix.
1448         (transform_id,
1449          transform_user_name,
1450          transform_user_name_prefix,
1451          transform_full_legal_switch) = get_transform_info(
1452             os.path.join(aces_ctl_directory, lmt_dir, transform_CTL))
1453
1454         # Finding inverse.
1455         transform_ctl_inverse = 'InvLMT.%s.ctl' % lmt_name
1456         if not os.path.exists(
1457                 os.path.join(lmt_tokens[-2], transform_ctl_inverse)):
1458             transform_ctl_inverse = None
1459
1460         lmts[lmt_name] = {}
1461         lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_CTL)
1462         if transform_ctl_inverse is not None:
1463             lmts[lmt_name]['transformCTLInverse'] = os.path.join(
1464                 lmt_dir, transform_ctl_inverse)
1465
1466         lmts[lmt_name]['transformID'] = transform_id
1467         lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1468         lmts[lmt_name]['transformUserName'] = transform_user_name
1469
1470         forward_ctl = lmts[lmt_name]['transformCTL']
1471
1472         print('LMT : %s' % lmt_name)
1473         print('\tTransform ID               : %s' % transform_id)
1474         print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1475         print('\tTransform User Name        : %s' % transform_user_name)
1476         print('\t Forward ctl               : %s' % forward_ctl)
1477         if 'transformCTLInverse' in lmts[lmt_name]:
1478             inverse_ctl = lmts[lmt_name]['transformCTLInverse']
1479             print('\t Inverse ctl                : %s' % inverse_ctl)
1480         else:
1481             print('\t Inverse ctl                : %s' % 'None')
1482
1483     print('\n')
1484
1485     return lmts
1486
1487
1488 def create_colorspaces(aces_ctl_directory,
1489                        lut_directory,
1490                        lut_resolution_1d,
1491                        lut_resolution_3d,
1492                        lmt_info,
1493                        odt_info,
1494                        shaper_name,
1495                        cleanup):
1496     """
1497     Generates the colorspace conversions.
1498
1499     Parameters
1500     ----------
1501     parameter : type
1502         Parameter description.
1503
1504     Returns
1505     -------
1506     type
1507          Return value description.
1508     """
1509
1510     colorspaces = []
1511
1512     ACES = create_ACES()
1513
1514     ACEScc = create_ACEScc(aces_ctl_directory, lut_directory,
1515                            lut_resolution_1d, cleanup,
1516                            min_value=-0.35840, max_value=1.468)
1517     colorspaces.append(ACEScc)
1518
1519     ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory,
1520                                  lut_resolution_1d, cleanup)
1521     colorspaces.append(ACESproxy)
1522
1523     ACEScg = create_ACEScg()
1524     colorspaces.append(ACEScg)
1525
1526     ADX10 = create_ADX(lut_directory, bit_depth=10)
1527     colorspaces.append(ADX10)
1528
1529     ADX16 = create_ADX(lut_directory, bit_depth=16)
1530     colorspaces.append(ADX16)
1531
1532     lmts = create_LMTs(aces_ctl_directory,
1533                        lut_directory,
1534                        lut_resolution_1d,
1535                        lut_resolution_3d,
1536                        lmt_info,
1537                        cleanup)
1538     colorspaces.extend(lmts)
1539
1540     odts, displays = create_ODTs(aces_ctl_directory,
1541                                  lut_directory,
1542                                  lut_resolution_1d,
1543                                  lut_resolution_3d,
1544                                  odt_info,
1545                                  shaper_name,
1546                                  cleanup,
1547                                  ACES,
1548                                  ACEScc)
1549     colorspaces.extend(odts)
1550
1551     # Wish there was an automatic way to get this from the CTL
1552     default_display = 'sRGB (D60 sim.)'
1553
1554     roles = {'color_picking': ACEScg.name,
1555              'color_timing': ACEScc.name,
1556              'compositing_log': ACEScc.name,
1557              'data': '',
1558              'default': ACES.name,
1559              'matte_paint': ACEScc.name,
1560              'reference': '',
1561              'scene_linear': ACEScg.name,
1562              'texture_paint': ''}
1563
1564     return ACES, colorspaces, displays, ACEScc, roles, default_display