Code formatting.
[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(aces_ctl_directory,
255                   lut_directory,
256                   lut_resolution_1d,
257                   cleanup,
258                   name='ACEScg'):
259     """
260     Creates the *ACEScg* colorspace.
261
262     Parameters
263     ----------
264     parameter : type
265         Parameter description.
266
267     Returns
268     -------
269     Colorspace
270          *ACEScg* colorspace.
271     """
272
273     cs = ColorSpace(name)
274     cs.description = 'The %s color space' % name
275     cs.aliases = ["acescg", "lin_ap1"]
276     cs.equality_group = ''
277     cs.family = 'ACES'
278     cs.is_data = False
279     cs.allocation_type = ocio.Constants.ALLOCATION_LG2
280     cs.allocation_vars = [-8, 5, 0.00390625]
281
282     cs.aces_transform_id = "ACEScsc.ACEScg_to_ACES.a1.0.0"
283
284     cs.to_reference_transforms = []
285
286     # *AP1* primaries to *AP0* primaries.
287     cs.to_reference_transforms.append({
288         'type': 'matrix',
289         'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
290         'direction': 'forward'})
291
292     cs.from_reference_transforms = []
293
294     # *AP1* primaries to *AP0* primaries.
295     cs.from_reference_transforms.append({
296         'type': 'matrix',
297         'matrix': mat44_from_mat33(ACES_AP0_TO_AP1),
298         'direction': 'forward'})
299
300     return cs
301
302
303 # -------------------------------------------------------------------------
304 # *ADX*
305 # -------------------------------------------------------------------------
306 def create_ADX(lut_directory,
307                lut_resolution_1d,
308                bit_depth=10,
309                name='ADX'):
310     """
311     Creates the *ADX* colorspace.
312
313     Parameters
314     ----------
315     parameter : type
316         Parameter description.
317
318     Returns
319     -------
320     Colorspace
321          *ADX* colorspace.
322     """
323
324     name = '%s%s' % (name, bit_depth)
325     cs = ColorSpace(name)
326     cs.description = '%s color space - used for film scans' % name
327     cs.aliases = ["adx%s" % str(bit_depth)]
328     cs.equality_group = ''
329     cs.family = 'ADX'
330     cs.is_data = False
331
332     if bit_depth == 10:
333         cs.aces_transform_id = "ACEScsc.ADX10_to_ACES.a1.0.0"
334
335         cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT10
336         ADX_to_CDD = [1023 / 500, 0, 0, 0,
337                       0, 1023 / 500, 0, 0,
338                       0, 0, 1023 / 500, 0,
339                       0, 0, 0, 1]
340         offset = [-95 / 500, -95 / 500, -95 / 500, 0]
341     elif bit_depth == 16:
342         cs.aces_transform_id = "ACEScsc.ADX16_to_ACES.a1.0.0"
343
344         cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT16
345         ADX_to_CDD = [65535 / 8000, 0, 0, 0,
346                       0, 65535 / 8000, 0, 0,
347                       0, 0, 65535 / 8000, 0,
348                       0, 0, 0, 1]
349         offset = [-1520 / 8000, -1520 / 8000, -1520 / 8000, 0]
350
351     cs.to_reference_transforms = []
352
353     # Converting from *ADX* to *Channel-Dependent Density*.
354     cs.to_reference_transforms.append({
355         'type': 'matrix',
356         'matrix': ADX_to_CDD,
357         'offset': offset,
358         'direction': 'forward'})
359
360     # Convert from Channel-Dependent Density to Channel-Independent Density
361     cs.to_reference_transforms.append({
362         'type': 'matrix',
363         'matrix': [0.75573, 0.22197, 0.02230, 0,
364                    0.05901, 0.96928, -0.02829, 0,
365                    0.16134, 0.07406, 0.76460, 0,
366                    0, 0, 0, 1],
367         'direction': 'forward'})
368
369     # Copied from *Alex Fry*'s *adx_cid_to_rle.py*
370     def create_CID_to_RLE_LUT():
371
372         def interpolate_1D(x, xp, fp):
373             return numpy.interp(x, xp, fp)
374
375         LUT_1D_xp = [-0.190000000000000,
376                      0.010000000000000,
377                      0.028000000000000,
378                      0.054000000000000,
379                      0.095000000000000,
380                      0.145000000000000,
381                      0.220000000000000,
382                      0.300000000000000,
383                      0.400000000000000,
384                      0.500000000000000,
385                      0.600000000000000]
386
387         LUT_1D_fp = [-6.000000000000000,
388                      -2.721718645000000,
389                      -2.521718645000000,
390                      -2.321718645000000,
391                      -2.121718645000000,
392                      -1.921718645000000,
393                      -1.721718645000000,
394                      -1.521718645000000,
395                      -1.321718645000000,
396                      -1.121718645000000,
397                      -0.926545676714876]
398
399         REF_PT = ((7120 - 1520) / 8000 * (100 / 55) -
400                   math.log(0.18, 10))
401
402         def cid_to_rle(x):
403             if x <= 0.6:
404                 return interpolate_1D(x, LUT_1D_xp, LUT_1D_fp)
405             return (100 / 55) * x - REF_PT
406
407         def fit(value, from_min, from_max, to_min, to_max):
408             if from_min == from_max:
409                 raise ValueError('from_min == from_max')
410             return (value - from_min) / (from_max - from_min) * (
411                 to_max - to_min) + to_min
412
413         num_samples = 2 ** 12
414         domain = (-0.19, 3)
415         data = []
416         for i in xrange(num_samples):
417             x = i / (num_samples - 1)
418             x = fit(x, 0, 1, domain[0], domain[1])
419             data.append(cid_to_rle(x))
420
421         lut = 'ADX_CID_to_RLE.spi1d'
422         write_SPI_1d(os.path.join(lut_directory, lut),
423                      domain[0],
424                      domain[1],
425                      data,
426                      num_samples, 1)
427
428         return lut
429
430     # Converting *Channel Independent Density* values to
431     # *Relative Log Exposure* values.
432     lut = create_CID_to_RLE_LUT()
433     cs.to_reference_transforms.append({
434         'type': 'lutFile',
435         'path': lut,
436         'interpolation': 'linear',
437         'direction': 'forward'})
438
439     # Converting *Relative Log Exposure* values to
440     # *Relative Exposure* values.
441     cs.to_reference_transforms.append({
442         'type': 'log',
443         'base': 10,
444         'direction': 'inverse'})
445
446     # Convert *Relative Exposure* values to *ACES* values.
447     cs.to_reference_transforms.append({
448         'type': 'matrix',
449         'matrix': [0.72286, 0.12630, 0.15084, 0,
450                    0.11923, 0.76418, 0.11659, 0,
451                    0.01427, 0.08213, 0.90359, 0,
452                    0, 0, 0, 1],
453         'direction': 'forward'})
454
455     cs.from_reference_transforms = []
456     return cs
457
458
459 # -------------------------------------------------------------------------
460 # *Generic Log Transform*
461 # -------------------------------------------------------------------------
462 def create_generic_log(aces_ctl_directory,
463                        lut_directory,
464                        lut_resolution_1d,
465                        cleanup,
466                        name='log',
467                        aliases=[],
468                        min_value=0,
469                        max_value=1,
470                        input_scale=1,
471                        middle_grey=0.18,
472                        min_exposure=-6,
473                        max_exposure=6.5):
474     """
475     Creates the *Generic Log* colorspace.
476
477     Parameters
478     ----------
479     parameter : type
480         Parameter description.
481
482     Returns
483     -------
484     Colorspace
485          *Generic Log* colorspace.
486     """
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_dolbypq(aces_CTL_directory,
534                    lut_directory,
535                    lut_resolution_1d,
536                    cleanup,
537                    name='pq',
538                    aliases=[],
539                    min_value=0.0,
540                    max_value=1.0,
541                    input_scale=1.0):
542     cs = ColorSpace(name)
543     cs.description = 'The %s color space' % name
544     cs.aliases = aliases
545     cs.equality_group = name
546     cs.family = 'Utility'
547     cs.is_data = False
548
549     ctls = [os.path.join(
550         aces_CTL_directory,
551         'utilities',
552         'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl')]
553     lut = '%s_to_linear.spi1d' % name
554
555     lut = sanitize(lut)
556
557     generate_1d_LUT_from_CTL(
558         os.path.join(lut_directory, lut),
559         ctls,
560         lut_resolution_1d,
561         'float',
562         input_scale,
563         1.0,
564         {},
565         cleanup,
566         aces_CTL_directory,
567         min_value,
568         max_value)
569
570     cs.to_reference_transforms = []
571     cs.to_reference_transforms.append({
572         'type': 'lutFile',
573         'path': lut,
574         'interpolation': 'linear',
575         'direction': 'forward'})
576
577     cs.from_reference_transforms = []
578     return cs
579
580
581 # -------------------------------------------------------------------------
582 # *Dolby PQ Transform that considers a fixed linear range*
583 # -------------------------------------------------------------------------
584 def create_dolbypq_scaled(aces_CTL_directory,
585                           lut_directory,
586                           lut_resolution_1d,
587                           cleanup,
588                           name='pq',
589                           aliases=[],
590                           min_value=0.0,
591                           max_value=1.0,
592                           input_scale=1.0,
593                           middle_grey=0.18,
594                           min_exposure=-6.0,
595                           max_exposure=6.5):
596     cs = ColorSpace(name)
597     cs.description = 'The %s color space' % name
598     cs.aliases = aliases
599     cs.equality_group = name
600     cs.family = 'Utility'
601     cs.is_data = False
602
603     ctls = [os.path.join(
604         aces_CTL_directory,
605         'utilities',
606         'ACESlib.DolbyPQ_to_lin_param.a1.0.0.ctl')]
607     lut = '%s_to_linear.spi1d' % name
608
609     lut = sanitize(lut)
610
611     generate_1d_LUT_from_CTL(
612         os.path.join(lut_directory, lut),
613         ctls,
614         lut_resolution_1d,
615         'float',
616         input_scale,
617         1.0,
618         {'middleGrey': middle_grey,
619          'minExposure': min_exposure,
620          'maxExposure': max_exposure},
621         cleanup,
622         aces_CTL_directory,
623         min_value,
624         max_value)
625
626     cs.to_reference_transforms = []
627     cs.to_reference_transforms.append({
628         'type': 'lutFile',
629         'path': lut,
630         'interpolation': 'linear',
631         'direction': 'forward'})
632
633     cs.from_reference_transforms = []
634     return cs
635
636
637 # -------------------------------------------------------------------------
638 # *Individual LMT*
639 # -------------------------------------------------------------------------
640 def create_ACES_LMT(lmt_name,
641                     lmt_values,
642                     shaper_info,
643                     aces_ctl_directory,
644                     lut_directory,
645                     lut_resolution_1d=1024,
646                     lut_resolution_3d=64,
647                     cleanup=True,
648                     aliases=None):
649     """
650     Creates the *ACES LMT* colorspace.
651
652     Parameters
653     ----------
654     parameter : type
655         Parameter description.
656
657     Returns
658     -------
659     Colorspace
660          *ACES LMT* colorspace.
661     """
662
663     if aliases is None:
664         aliases = []
665
666     cs = ColorSpace('%s' % lmt_name)
667     cs.description = 'The ACES Look Transform: %s' % lmt_name
668     cs.aliases = aliases
669     cs.equality_group = ''
670     cs.family = 'Look'
671     cs.is_data = False
672     cs.allocation_type = ocio.Constants.ALLOCATION_LG2
673     cs.allocation_vars = [-8, 5, 0.00390625]
674     cs.aces_transform_id = lmt_values['transformID']
675
676     pprint.pprint(lmt_values)
677
678     # Generating the *shaper* transform.
679     (shaper_name,
680      shaper_to_ACES_CTL,
681      shaper_from_ACES_CTL,
682      shaper_input_scale,
683      shaper_params) = shaper_info
684
685     # Add the shaper transform
686     shaper_lut = '%s_to_linear.spi1d' % shaper_name
687     shaper_lut = sanitize(shaper_lut)
688
689     shaper_OCIO_transform = {
690         'type': 'lutFile',
691         'path': shaper_lut,
692         'interpolation': 'linear',
693         'direction': 'inverse'}
694
695     # Generating the forward transform.
696     cs.from_reference_transforms = []
697
698     if 'transformCTL' in lmt_values:
699         ctls = [shaper_to_ACES_CTL % aces_ctl_directory,
700                 os.path.join(aces_ctl_directory,
701                              lmt_values['transformCTL'])]
702         lut = '%s.%s.spi3d' % (shaper_name, lmt_name)
703
704         lut = sanitize(lut)
705
706         generate_3d_LUT_from_CTL(
707             os.path.join(lut_directory, lut),
708             ctls,
709             lut_resolution_3d,
710             'float',
711             1 / shaper_input_scale,
712             1,
713             shaper_params,
714             cleanup,
715             aces_ctl_directory)
716
717         cs.from_reference_transforms.append(shaper_OCIO_transform)
718         cs.from_reference_transforms.append({
719             'type': 'lutFile',
720             'path': lut,
721             'interpolation': 'tetrahedral',
722             'direction': 'forward'})
723
724     # Generating the inverse transform.
725     cs.to_reference_transforms = []
726
727     if 'transformCTLInverse' in lmt_values:
728         ctls = [os.path.join(aces_ctl_directory,
729                              lmt_values['transformCTLInverse']),
730                 shaper_from_ACES_CTL % aces_ctl_directory]
731         lut = 'Inverse.%s.%s.spi3d' % (odt_name, shaper_name)
732
733         lut = sanitize(lut)
734
735         generate_3d_LUT_from_CTL(
736             os.path.join(lut_directory, lut),
737             ctls,
738             lut_resolution_3d,
739             'half',
740             1,
741             shaper_input_scale,
742             shaper_params,
743             cleanup,
744             aces_ctl_directory,
745             0,
746             1,
747             1)
748
749         cs.to_reference_transforms.append({
750             'type': 'lutFile',
751             'path': lut,
752             'interpolation': 'tetrahedral',
753             'direction': 'forward'})
754
755         shaper_inverse = shaper_OCIO_transform.copy()
756         shaper_inverse['direction'] = 'forward'
757         cs.to_reference_transforms.append(shaper_inverse)
758
759     return cs
760
761
762 # -------------------------------------------------------------------------
763 # *LMTs*
764 # -------------------------------------------------------------------------
765 def create_LMTs(aces_ctl_directory,
766                 lut_directory,
767                 lut_resolution_1d,
768                 lut_resolution_3d,
769                 lmt_info,
770                 shaper_name,
771                 cleanup):
772     """
773     Object description.
774
775     Parameters
776     ----------
777     parameter : type
778         Parameter description.
779
780     Returns
781     -------
782     type
783          Return value description.
784     """
785
786     colorspaces = []
787
788     # -------------------------------------------------------------------------
789     # *LMT Shaper*
790     # -------------------------------------------------------------------------
791     lmt_lut_resolution_1d = max(4096, lut_resolution_1d)
792     lmt_lut_resolution_3d = max(65, lut_resolution_3d)
793
794     # Defining the *Log 2* shaper.
795     lmt_shaper_name = 'LMT Shaper'
796     lmt_shaper_name_aliases = ['crv_lmtshaper']
797     lmt_params = {
798         'middleGrey': 0.18,
799         'minExposure': -10,
800         'maxExposure': 6.5}
801
802     lmt_shaper = create_generic_log(aces_ctl_directory,
803                                     lut_directory,
804                                     lmt_lut_resolution_1d,
805                                     cleanup,
806                                     name=lmt_shaper_name,
807                                     middle_grey=lmt_params['middleGrey'],
808                                     min_exposure=lmt_params['minExposure'],
809                                     max_exposure=lmt_params['maxExposure'],
810                                     aliases=lmt_shaper_name_aliases)
811     colorspaces.append(lmt_shaper)
812
813     shaper_input_scale_generic_log2 = 1
814
815     # *Log 2* shaper name and *CTL* transforms bundled up.
816     lmt_shaper_data = [
817         lmt_shaper_name,
818         os.path.join('%s',
819                      'utilities',
820                      'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
821         os.path.join('%s',
822                      'utilities',
823                      'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
824         shaper_input_scale_generic_log2,
825         lmt_params]
826
827     sorted_LMTs = sorted(lmt_info.iteritems(), key=lambda x: x[1])
828     print(sorted_LMTs)
829     for lmt in sorted_LMTs:
830         lmt_name, lmt_values = lmt
831         lmt_aliases = ["look_%s" % compact(lmt_values['transformUserName'])]
832         cs = create_ACES_LMT(
833             lmt_values['transformUserName'],
834             lmt_values,
835             lmt_shaper_data,
836             aces_ctl_directory,
837             lut_directory,
838             lmt_lut_resolution_1d,
839             lmt_lut_resolution_3d,
840             cleanup,
841             lmt_aliases)
842         colorspaces.append(cs)
843
844     return colorspaces
845
846
847 # -------------------------------------------------------------------------
848 # *ACES RRT* with supplied *ODT*.
849 # -------------------------------------------------------------------------
850 def create_ACES_RRT_plus_ODT(odt_name,
851                              odt_values,
852                              shaper_info,
853                              aces_ctl_directory,
854                              lut_directory,
855                              lut_resolution_1d=1024,
856                              lut_resolution_3d=64,
857                              cleanup=True,
858                              aliases=None):
859     """
860     Object description.
861
862     Parameters
863     ----------
864     parameter : type
865         Parameter description.
866
867     Returns
868     -------
869     type
870          Return value description.
871     """
872
873     if aliases is None:
874         aliases = []
875
876     cs = ColorSpace('%s' % odt_name)
877     cs.description = '%s - %s Output Transform' % (
878         odt_values['transformUserNamePrefix'], odt_name)
879     cs.aliases = aliases
880     cs.equality_group = ''
881     cs.family = 'Output'
882     cs.is_data = False
883
884     cs.aces_transform_id = odt_values['transformID']
885
886     pprint.pprint(odt_values)
887
888     # Generating the *shaper* transform.
889     (shaper_name,
890      shaper_to_ACES_CTL,
891      shaper_from_ACES_CTL,
892      shaper_input_scale,
893      shaper_params) = shaper_info
894
895     if 'legalRange' in odt_values:
896         shaper_params['legalRange'] = odt_values['legalRange']
897     else:
898         shaper_params['legalRange'] = 0
899
900     # Add the shaper transform
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             # shaperLUT,
941             ctls,
942             lut_resolution_3d,
943             'float',
944             1 / shaper_input_scale,
945             1,
946             shaper_params,
947             cleanup,
948             aces_ctl_directory)
949
950         cs.from_reference_transforms.append(shaper_OCIO_transform)
951         cs.from_reference_transforms.append({
952             'type': 'lutFile',
953             'path': lut,
954             'interpolation': 'tetrahedral',
955             'direction': 'forward'})
956
957     # Generating the *inverse* transform.
958     cs.to_reference_transforms = []
959
960     if 'transformLUTInverse' in odt_values:
961         transform_LUT_inverse_file_name = os.path.basename(
962             odt_values['transformLUTInverse'])
963         lut = os.path.join(lut_directory, transform_LUT_inverse_file_name)
964         shutil.copy(odt_values['transformLUTInverse'], lut)
965
966         cs.to_reference_transforms.append({
967             'type': 'lutFile',
968             'path': transform_LUT_inverse_file_name,
969             'interpolation': 'tetrahedral',
970             'direction': 'forward'})
971
972         shaper_inverse = shaper_OCIO_transform.copy()
973         shaper_inverse['direction'] = 'forward'
974         cs.to_reference_transforms.append(shaper_inverse)
975     elif 'transformCTLInverse' in odt_values:
976         ctls = [os.path.join(aces_ctl_directory,
977                              'odt',
978                              odt_values['transformCTLInverse']),
979                 os.path.join(aces_ctl_directory,
980                              'rrt',
981                              'InvRRT.a1.0.0.ctl'),
982                 shaper_from_ACES_CTL % aces_ctl_directory]
983         lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name)
984
985         lut = sanitize(lut)
986
987         generate_3d_LUT_from_CTL(
988             os.path.join(lut_directory, lut),
989             # None,
990             ctls,
991             lut_resolution_3d,
992             'half',
993             1,
994             shaper_input_scale,
995             shaper_params,
996             cleanup,
997             aces_ctl_directory)
998
999         cs.to_reference_transforms.append({
1000             'type': 'lutFile',
1001             'path': lut,
1002             'interpolation': 'tetrahedral',
1003             'direction': 'forward'})
1004
1005         shaper_inverse = shaper_OCIO_transform.copy()
1006         shaper_inverse['direction'] = 'forward'
1007         cs.to_reference_transforms.append(shaper_inverse)
1008
1009     return cs
1010
1011
1012 # -------------------------------------------------------------------------
1013 # *ODTs*
1014 # -------------------------------------------------------------------------
1015 def create_ODTs(aces_ctl_directory,
1016                 lut_directory,
1017                 lut_resolution_1d,
1018                 lut_resolution_3d,
1019                 odt_info,
1020                 shaper_name,
1021                 cleanup,
1022                 linear_display_space,
1023                 log_display_space):
1024     """
1025     Object description.
1026
1027     Parameters
1028     ----------
1029     parameter : type
1030         Parameter description.
1031
1032     Returns
1033     -------
1034     type
1035          Return value description.
1036     """
1037
1038     colorspaces = []
1039     displays = {}
1040
1041     # -------------------------------------------------------------------------
1042     # *RRT / ODT* Shaper Options
1043     # -------------------------------------------------------------------------
1044     shaper_data = {}
1045
1046     # Defining the *Log 2* shaper.
1047     log2_shaper_name = shaper_name
1048     log2_shaper_name_aliases = ["crv_%s" % compact(log2_shaper_name)]
1049     log2_params = {
1050         'middleGrey': 0.18,
1051         'minExposure': -6,
1052         'maxExposure': 6.5}
1053
1054     log2_shaper_colorspace = create_generic_log(
1055         aces_ctl_directory,
1056         lut_directory,
1057         lut_resolution_1d,
1058         cleanup,
1059         name=log2_shaper_name,
1060         middle_grey=log2_params['middleGrey'],
1061         min_exposure=log2_params['minExposure'],
1062         max_exposure=log2_params['maxExposure'],
1063         aliases=log2_shaper_name_aliases)
1064     colorspaces.append(log2_shaper_colorspace)
1065
1066     shaper_input_scale_generic_log2 = 1
1067
1068     # *Log 2* shaper name and *CTL* transforms bundled up.
1069     log2_shaper_data = [
1070         log2_shaper_name,
1071         os.path.join('%s',
1072                      'utilities',
1073                      'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
1074         os.path.join('%s',
1075                      'utilities',
1076                      'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
1077         shaper_input_scale_generic_log2,
1078         log2_params]
1079
1080     shaper_data[log2_shaper_name] = log2_shaper_data
1081
1082     # Space with a more user-friendly name. Direct copy otherwise.
1083     log2_shaper_copy_name = "Log2 Shaper"
1084     log2_shaper_copy_colorspace = ColorSpace(log2_shaper_copy_name)
1085     log2_shaper_copy_colorspace.description = 'The %s color space' % log2_shaper_copy_name
1086     log2_shaper_copy_colorspace.aliases = [
1087         "crv_%s" % compact(log2_shaper_copy_name)]
1088     log2_shaper_copy_colorspace.equality_group = log2_shaper_copy_name
1089     log2_shaper_copy_colorspace.family = log2_shaper_colorspace.family
1090     log2_shaper_copy_colorspace.is_data = log2_shaper_colorspace.is_data
1091     log2_shaper_copy_colorspace.to_reference_transforms = list(
1092         log2_shaper_colorspace.to_reference_transforms)
1093     log2_shaper_copy_colorspace.from_reference_transforms = list(
1094         log2_shaper_colorspace.from_reference_transforms)
1095     colorspaces.append(log2_shaper_copy_colorspace)
1096
1097     # Defining the *Log2 shaper that includes the AP1* primaries.
1098     log2_shaper_api1_name = "%s - AP1" % "Log2 Shaper"
1099     log2_shaper_api1_colorspace = ColorSpace(log2_shaper_api1_name)
1100     log2_shaper_api1_colorspace.description = '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. 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 = 'The %s color space' % shaper_api1_name
1124     shaper_api1_colorspace.aliases = ["%s_ap1" % compact(shaper_name)]
1125     shaper_api1_colorspace.equality_group = shaper_api1_name
1126     shaper_api1_colorspace.family = log2_shaper_colorspace.family
1127     shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1128     shaper_api1_colorspace.to_reference_transforms = list(
1129         log2_shaper_api1_colorspace.to_reference_transforms)
1130     shaper_api1_colorspace.from_reference_transforms = list(
1131         log2_shaper_api1_colorspace.from_reference_transforms)
1132     colorspaces.append(shaper_api1_colorspace)
1133
1134     # Define the base *Dolby PQ Shaper*
1135     #
1136     dolbypq_shaper_name = "Dolby PQ 10000"
1137     dolbypq_shaper_name_aliases = ["crv_%s" % "dolbypq_10000"]
1138
1139     dolbypq_shaper_colorspace = create_dolbypq(
1140         aces_ctl_directory,
1141         lut_directory,
1142         lut_resolution_1d,
1143         cleanup,
1144         name=dolbypq_shaper_name,
1145         aliases=dolbypq_shaper_name_aliases)
1146     colorspaces.append(dolbypq_shaper_colorspace)
1147
1148     # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1149     dolbypq_shaper_data = [
1150         dolbypq_shaper_name,
1151         os.path.join('%s',
1152                      'utilities',
1153                      'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl'),
1154         os.path.join('%s',
1155                      'utilities',
1156                      'ACESlib.Lin_to_DolbyPQ.a1.0.0.ctl'),
1157         1.0,
1158         {}]
1159
1160     shaper_data[dolbypq_shaper_name] = dolbypq_shaper_data
1161
1162     # Define the *Dolby PQ Shaper that considers a fixed linear range*
1163     #
1164     dolbypq_scaled_shaper_name = "Dolby PQ Scaled"
1165     dolbypq_scaled_shaper_name_aliases = ["crv_%s" % "dolbypq_scaled"]
1166
1167     dolbypq_scaled_shaper_colorspace = create_dolbypq_scaled(
1168         aces_ctl_directory,
1169         lut_directory,
1170         lut_resolution_1d,
1171         cleanup,
1172         name=dolbypq_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         dolbypq_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[dolbypq_scaled_shaper_name] = dolbypq_scaled_shaper_data
1189
1190     #
1191     # Pick a specific shaper
1192     #
1193     rrt_shaper = log2_shaper_data
1194     # rrt_shaper = dolbypq_scaled_shaper_data
1195
1196     # *RRT + ODT* combinations.
1197     sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1])
1198     print(sorted_odts)
1199     for odt in sorted_odts:
1200         (odt_name, odt_values) = odt
1201
1202         # Generating only full range transform for *ODTs* that can generate 
1203         # either *legal* or *full* output.
1204
1205         # Uncomment these lines and the lower section and flip the 'legalRange' value to 1
1206         # to recover the old behavior, where both legal and full range LUTs were generated
1207         if odt_values['transformHasFullLegalSwitch']:
1208             # odt_name_legal = '%s - Legal' % odt_values['transformUserName']
1209             odt_legal['legalRange'] = 0
1210         # else:
1211         #    odt_name_legal = odt_values['transformUserName']
1212
1213         odt_name_legal = odt_values['transformUserName']
1214
1215         odt_legal = odt_values.copy()
1216
1217         odt_aliases = ["out_%s" % compact(odt_name_legal)]
1218
1219         cs = create_ACES_RRT_plus_ODT(
1220             odt_name_legal,
1221             odt_legal,
1222             rrt_shaper,
1223             aces_ctl_directory,
1224             lut_directory,
1225             lut_resolution_1d,
1226             lut_resolution_3d,
1227             cleanup,
1228             odt_aliases)
1229         colorspaces.append(cs)
1230
1231         displays[odt_name_legal] = {
1232             'Raw': linear_display_space,
1233             'Log': log_display_space,
1234             'Output Transform': cs}
1235
1236         '''
1237         # Generating full range transform for *ODTs* that can generate 
1238         # either *legal* or *full* output.
1239         if odt_values['transformHasFullLegalSwitch']:
1240             print('Generating full range ODT for %s' % odt_name)
1241
1242             odt_name_full = '%s - Full' % odt_values['transformUserName']
1243             odt_full = odt_values.copy()
1244             odt_full['legalRange'] = 0
1245
1246             odt_full_aliases = ["out_%s" % compact(odt_name_full)]
1247
1248             cs_full = create_ACES_RRT_plus_ODT(
1249                 odt_name_full,
1250                 odt_full,
1251                 rrt_shaper,
1252                 aces_ctl_directory,
1253                 lut_directory,
1254                 lut_resolution_1d,
1255                 lut_resolution_3d,
1256                 cleanup,
1257                 odt_full_aliases)
1258             colorspaces.append(cs_full)
1259
1260             displays[odt_name_full] = {
1261                 'Raw': linear_display_space,
1262                 'Log': log_display_space,
1263                 'Output Transform': cs_full}
1264         '''
1265
1266     return (colorspaces, displays)
1267
1268
1269 def get_transform_info(ctl_transform):
1270     """
1271     Object description.
1272
1273     Parameters
1274     ----------
1275     parameter : type
1276         Parameter description.
1277
1278     Returns
1279     -------
1280     type
1281          Return value description.
1282     """
1283
1284     with open(ctl_transform, 'rb') as fp:
1285         lines = fp.readlines()
1286
1287     # Retrieving the *transform ID* and *User Name*.
1288     transform_id = lines[1][3:].split('<')[1].split('>')[1].strip()
1289     transform_user_name = '-'.join(
1290         lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip()
1291     transform_user_name_prefix = (
1292         lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
1293
1294     # Figuring out if this transform has options for processing full and legal range
1295     transform_full_legal_switch = False
1296     for line in lines:
1297         if line.strip() == "input varying int legalRange = 0":
1298             # print( "%s has legal range flag" % transform_user_name)
1299             transform_full_legal_switch = True
1300             break
1301
1302     return (transform_id, transform_user_name, transform_user_name_prefix,
1303             transform_full_legal_switch)
1304
1305
1306 def get_ODTs_info(aces_ctl_directory):
1307     """
1308     Object description.
1309
1310     For versions after WGR9.
1311
1312     Parameters
1313     ----------
1314     parameter : type
1315         Parameter description.
1316
1317     Returns
1318     -------
1319     type
1320          Return value description.
1321     """
1322
1323     # TODO: Investigate usage of *files_walker* definition here.
1324     # Credit to *Alex Fry* for the original approach here.
1325     odt_dir = os.path.join(aces_ctl_directory, 'odt')
1326     all_odt = []
1327     for dir_name, subdir_list, file_list in os.walk(odt_dir):
1328         for fname in file_list:
1329             all_odt.append((os.path.join(dir_name, fname)))
1330
1331     odt_CTLs = [x for x in all_odt if
1332                 ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')]
1333
1334     odts = {}
1335
1336     for odt_CTL in odt_CTLs:
1337         odt_tokens = os.path.split(odt_CTL)
1338
1339         # Handling nested directories.
1340         odt_path_tokens = os.path.split(odt_tokens[-2])
1341         odt_dir = odt_path_tokens[-1]
1342         while odt_path_tokens[-2][-3:] != 'odt':
1343             odt_path_tokens = os.path.split(odt_path_tokens[-2])
1344             odt_dir = os.path.join(odt_path_tokens[-1], odt_dir)
1345
1346         # Building full name,
1347         transform_CTL = odt_tokens[-1]
1348         odt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1349
1350         # Finding id, user name and user name prefix.
1351         (transform_ID,
1352          transform_user_name,
1353          transform_user_name_prefix,
1354          transform_full_legal_switch) = get_transform_info(
1355             os.path.join(aces_ctl_directory, 'odt', odt_dir, transform_CTL))
1356
1357         # Finding inverse.
1358         transform_CTL_inverse = 'InvODT.%s.ctl' % odt_name
1359         if not os.path.exists(
1360                 os.path.join(odt_tokens[-2], transform_CTL_inverse)):
1361             transform_CTL_inverse = None
1362
1363         # Add to list of ODTs
1364         odts[odt_name] = {}
1365         odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_CTL)
1366         if transform_CTL_inverse is not None:
1367             odts[odt_name]['transformCTLInverse'] = os.path.join(
1368                 odt_dir, transform_CTL_inverse)
1369
1370         odts[odt_name]['transformID'] = transform_ID
1371         odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1372         odts[odt_name]['transformUserName'] = transform_user_name
1373         odts[odt_name][
1374             'transformHasFullLegalSwitch'] = transform_full_legal_switch
1375
1376         forward_CTL = odts[odt_name]['transformCTL']
1377
1378         print('ODT : %s' % odt_name)
1379         print('\tTransform ID               : %s' % transform_ID)
1380         print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1381         print('\tTransform User Name        : %s' % transform_user_name)
1382         print(
1383             '\tHas Full / Legal Switch    : %s' % transform_full_legal_switch)
1384         print('\tForward ctl                : %s' % forward_CTL)
1385         if 'transformCTLInverse' in odts[odt_name]:
1386             inverse_CTL = odts[odt_name]['transformCTLInverse']
1387             print('\tInverse ctl                : %s' % inverse_CTL)
1388         else:
1389             print('\tInverse ctl                : %s' % 'None')
1390
1391     print('\n')
1392
1393     return odts
1394
1395
1396 def get_LMTs_info(aces_ctl_directory):
1397     """
1398     Object description.
1399
1400     For versions after WGR9.
1401
1402     Parameters
1403     ----------
1404     parameter : type
1405         Parameter description.
1406
1407     Returns
1408     -------
1409     type
1410          Return value description.
1411     """
1412
1413     # TODO: Investigate refactoring with previous definition.
1414
1415     # Credit to Alex Fry for the original approach here
1416     lmt_dir = os.path.join(aces_ctl_directory, 'lmt')
1417     all_lmt = []
1418     for dir_name, subdir_list, file_list in os.walk(lmt_dir):
1419         for fname in file_list:
1420             all_lmt.append((os.path.join(dir_name, fname)))
1421
1422     lmt_CTLs = [x for x in all_lmt if
1423                 ('InvLMT' not in x) and ('README' not in x) and (
1424                     os.path.split(x)[-1][0] != '.')]
1425
1426     lmts = {}
1427
1428     for lmt_CTL in lmt_CTLs:
1429         lmt_tokens = os.path.split(lmt_CTL)
1430
1431         # Handlimg nested directories.
1432         lmt_path_tokens = os.path.split(lmt_tokens[-2])
1433         lmt_dir = lmt_path_tokens[-1]
1434         while lmt_path_tokens[-2][-3:] != 'ctl':
1435             lmt_path_tokens = os.path.split(lmt_path_tokens[-2])
1436             lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir)
1437
1438         # Building full name.
1439         transform_CTL = lmt_tokens[-1]
1440         lmt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1441
1442         # Finding id, user name and user name prefix.
1443         (transform_ID,
1444          transform_user_name,
1445          transform_user_name_prefix,
1446          transform_full_legal_switch) = get_transform_info(
1447             os.path.join(aces_ctl_directory, lmt_dir, transform_CTL))
1448
1449         # Finding inverse.
1450         transform_CTL_inverse = 'InvLMT.%s.ctl' % lmt_name
1451         if not os.path.exists(
1452                 os.path.join(lmt_tokens[-2], transform_CTL_inverse)):
1453             transform_CTL_inverse = None
1454
1455         lmts[lmt_name] = {}
1456         lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_CTL)
1457         if transform_CTL_inverse is not None:
1458             lmts[lmt_name]['transformCTLInverse'] = os.path.join(
1459                 lmt_dir, transform_CTL_inverse)
1460
1461         lmts[lmt_name]['transformID'] = transform_ID
1462         lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1463         lmts[lmt_name]['transformUserName'] = transform_user_name
1464
1465         forward_CTL = lmts[lmt_name]['transformCTL']
1466
1467         print('LMT : %s' % lmt_name)
1468         print('\tTransform ID               : %s' % transform_ID)
1469         print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1470         print('\tTransform User Name        : %s' % transform_user_name)
1471         print('\t Forward ctl               : %s' % forward_CTL)
1472         if 'transformCTLInverse' in lmts[lmt_name]:
1473             inverse_CTL = lmts[lmt_name]['transformCTLInverse']
1474             print('\t Inverse ctl                : %s' % inverse_CTL)
1475         else:
1476             print('\t Inverse ctl                : %s' % 'None')
1477
1478     print('\n')
1479
1480     return lmts
1481
1482
1483 def create_colorspaces(aces_ctl_directory,
1484                        lut_directory,
1485                        lut_resolution_1d,
1486                        lut_resolution_3d,
1487                        lmt_info,
1488                        odt_info,
1489                        shaper_name,
1490                        cleanup):
1491     """
1492     Generates the colorspace conversions.
1493
1494     Parameters
1495     ----------
1496     parameter : type
1497         Parameter description.
1498
1499     Returns
1500     -------
1501     type
1502          Return value description.
1503     """
1504
1505     colorspaces = []
1506
1507     ACES = create_ACES()
1508
1509     ACEScc = create_ACEScc(aces_ctl_directory, lut_directory,
1510                            lut_resolution_1d, cleanup,
1511                            min_value=-0.35840, max_value=1.468)
1512     colorspaces.append(ACEScc)
1513
1514     ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory,
1515                                  lut_resolution_1d, cleanup)
1516     colorspaces.append(ACESproxy)
1517
1518     ACEScg = create_ACEScg(aces_ctl_directory, lut_directory,
1519                            lut_resolution_1d, cleanup)
1520     colorspaces.append(ACEScg)
1521
1522     ADX10 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=10)
1523     colorspaces.append(ADX10)
1524
1525     ADX16 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=16)
1526     colorspaces.append(ADX16)
1527
1528     lmts = create_LMTs(aces_ctl_directory,
1529                        lut_directory,
1530                        lut_resolution_1d,
1531                        lut_resolution_3d,
1532                        lmt_info,
1533                        shaper_name,
1534                        cleanup)
1535     colorspaces.extend(lmts)
1536
1537     odts, displays = create_ODTs(aces_ctl_directory,
1538                                  lut_directory,
1539                                  lut_resolution_1d,
1540                                  lut_resolution_3d,
1541                                  odt_info,
1542                                  shaper_name,
1543                                  cleanup,
1544                                  ACES,
1545                                  ACEScc)
1546     colorspaces.extend(odts)
1547
1548     # Wish there was an automatic way to get this from the CTL
1549     defaultDisplay = "sRGB (D60 sim.)"
1550
1551     roles = {'color_picking': ACEScg.name,
1552              'color_timing': ACEScc.name,
1553              'compositing_log': ACEScc.name,
1554              'data': '',
1555              'default': ACES.name,
1556              'matte_paint': ACEScc.name,
1557              'reference': '',
1558              'scene_linear': ACEScg.name,
1559              'texture_paint': ''}
1560
1561     return ACES, colorspaces, displays, ACEScc, roles, defaultDisplay