Only the full range output will be used for Output Transforms that support either...
[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
30 __author__ = 'ACES Developers'
31 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
32 __license__ = ''
33 __maintainer__ = 'ACES Developers'
34 __email__ = 'aces@oscars.org'
35 __status__ = 'Production'
36
37 __all__ = ['ACES_AP1_TO_AP0',
38            'ACES_AP0_TO_XYZ',
39            'create_ACES',
40            'create_ACEScc',
41            'create_ACESproxy',
42            'create_ACEScg',
43            'create_ADX',
44            'create_ACES_LMT',
45            'create_ACES_RRT_plus_ODT',
46            'create_generic_log',
47            'create_LMTs',
48            'create_ODTs',
49            'get_transform_info',
50            'get_ODTs_info',
51            'get_LMTs_info',
52            'create_colorspaces']
53
54 # Matrix converting *ACES AP1* primaries to *ACES AP0*.
55 ACES_AP1_TO_AP0 = [0.6954522414, 0.1406786965, 0.1638690622,
56                    0.0447945634, 0.8596711185, 0.0955343182,
57                    -0.0055258826, 0.0040252103, 1.0015006723]
58
59 # Matrix converting *ACES AP0* primaries to *ACES AP1*.
60 ACES_AP0_TO_AP1 = [1.4514393161, -0.2365107469, -0.2149285693,
61                    -0.0765537734, 1.1762296998, -0.0996759264,
62                    0.0083161484, -0.0060324498, 0.9977163014]
63
64 # Matrix converting *ACES AP0* primaries to *XYZ*.
65 ACES_AP0_TO_XYZ = [0.9525523959, 0.0000000000, 0.0000936786,
66                    0.3439664498, 0.7281660966, -0.0721325464,
67                    0.0000000000, 0.0000000000, 1.0088251844]
68
69 # Matrix converting *ACES AP0* primaries to *XYZ*.
70 ACES_XYZ_TO_AP0 = [1.0498110175, 0.0000000000, -0.0000974845,
71                    -0.4959030231, 1.3733130458, 0.0982400361,
72                    0.0000000000, 0.0000000000, 0.9912520182]
73
74
75 def create_ACES():
76     """
77     Object description.
78
79     Parameters
80     ----------
81     parameter : type
82         Parameter description.
83
84     Returns
85     -------
86     type
87          Return value description.
88     """
89
90     # Defining the reference colorspace.
91     aces2065_1 = ColorSpace('ACES2065-1')
92     aces2065_1.description = (
93         'The Academy Color Encoding System reference color space')
94     aces2065_1.equality_group = ''
95     aces2065_1.aliases = ["lin_ap0", "aces"]
96     aces2065_1.family = 'ACES'
97     aces2065_1.is_data = False
98     aces2065_1.allocation_type = ocio.Constants.ALLOCATION_LG2
99     aces2065_1.allocation_vars = [-8, 5, 0.00390625]
100
101     return aces2065_1
102
103
104 def create_ACEScc(aces_ctl_directory,
105                   lut_directory,
106                   lut_resolution_1d,
107                   cleanup,
108                   name='ACEScc',
109                   min_value=0,
110                   max_value=1,
111                   input_scale=1):
112     """
113     Creates the *ACEScc* colorspace.
114
115     Parameters
116     ----------
117     parameter : type
118         Parameter description.
119
120     Returns
121     -------
122     Colorspace
123          *ACEScc* colorspace.
124     """
125
126     cs = ColorSpace(name)
127     cs.description = 'The %s color space' % name
128     cs.aliases = ["acescc", "acescc_ap1"]
129     cs.equality_group = ''
130     cs.family = 'ACES'
131     cs.is_data = False
132     cs.allocation_type = ocio.Constants.ALLOCATION_UNIFORM
133     cs.allocation_vars = [min_value, max_value]
134     cs.aces_transform_id = "ACEScsc.ACEScc_to_ACES.a1.0.0"
135
136     ctls = [os.path.join(aces_ctl_directory,
137                          'ACEScc',
138                          'ACEScsc.ACEScc_to_ACES.a1.0.0.ctl'),
139             # This transform gets back to the *AP1* primaries.
140             # Useful as the 1d LUT is only covering the transfer function.
141             # The primaries switch is covered by the matrix below:
142             os.path.join(aces_ctl_directory,
143                          'ACEScg',
144                          'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
145     lut = '%s_to_linear.spi1d' % name
146
147     lut = sanitize(lut)
148
149     generate_1d_LUT_from_CTL(
150         os.path.join(lut_directory, lut),
151         ctls,
152         lut_resolution_1d,
153         'float',
154         input_scale,
155         1,
156         {},
157         cleanup,
158         aces_ctl_directory,
159         min_value,
160         max_value,
161         1)
162
163     cs.to_reference_transforms = []
164     cs.to_reference_transforms.append({
165         'type': 'lutFile',
166         'path': lut,
167         'interpolation': 'linear',
168         'direction': 'forward'})
169
170     # *AP1* primaries to *AP0* primaries.
171     cs.to_reference_transforms.append({
172         'type': 'matrix',
173         'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
174         'direction': 'forward'})
175
176     cs.from_reference_transforms = []
177     return cs
178
179
180 def create_ACESproxy(aces_ctl_directory,
181                      lut_directory,
182                      lut_resolution_1d,
183                      cleanup,
184                      name='ACESproxy'):
185     """
186     Creates the *ACESproxy* colorspace.
187
188     Parameters
189     ----------
190     parameter : type
191         Parameter description.
192
193     Returns
194     -------
195     Colorspace
196          *ACESproxy* colorspace.
197     """
198
199     cs = ColorSpace(name)
200     cs.description = 'The %s color space' % name
201     cs.aliases = ["acesproxy", "acesproxy_ap1"]
202     cs.equality_group = ''
203     cs.family = 'ACES'
204     cs.is_data = False
205
206     cs.aces_transform_id = "ACEScsc.ACESproxy10i_to_ACES.a1.0.0"
207
208     ctls = [os.path.join(aces_ctl_directory,
209                          'ACESproxy',
210                          'ACEScsc.ACESproxy10i_to_ACES.a1.0.0.ctl'),
211             # This transform gets back to the *AP1* primaries.
212             # Useful as the 1d LUT is only covering the transfer function.
213             # The primaries switch is covered by the matrix below:
214             os.path.join(aces_ctl_directory,
215                          'ACEScg',
216                          'ACEScsc.ACES_to_ACEScg.a1.0.0.ctl')]
217     lut = '%s_to_linear.spi1d' % name
218
219     lut = sanitize(lut)
220
221     generate_1d_LUT_from_CTL(
222         os.path.join(lut_directory, lut),
223         ctls,
224         lut_resolution_1d,
225         'float',
226         1,
227         1,
228         {},
229         cleanup,
230         aces_ctl_directory,
231         0,
232         1,
233         1)
234
235     cs.to_reference_transforms = []
236     cs.to_reference_transforms.append({
237         'type': 'lutFile',
238         'path': lut,
239         'interpolation': 'linear',
240         'direction': 'forward'})
241
242     # *AP1* primaries to *AP0* primaries.
243     cs.to_reference_transforms.append({
244         'type': 'matrix',
245         'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
246         'direction': 'forward'})
247
248     cs.from_reference_transforms = []
249     return cs
250
251
252 # -------------------------------------------------------------------------
253 # *ACEScg*
254 # -------------------------------------------------------------------------
255 def create_ACEScg(aces_ctl_directory,
256                   lut_directory,
257                   lut_resolution_1d,
258                   cleanup,
259                   name='ACEScg'):
260     """
261     Creates the *ACEScg* colorspace.
262
263     Parameters
264     ----------
265     parameter : type
266         Parameter description.
267
268     Returns
269     -------
270     Colorspace
271          *ACEScg* colorspace.
272     """
273
274     cs = ColorSpace(name)
275     cs.description = 'The %s color space' % name
276     cs.aliases = ["acescg", "lin_ap1"]
277     cs.equality_group = ''
278     cs.family = 'ACES'
279     cs.is_data = False
280     cs.allocation_type = ocio.Constants.ALLOCATION_LG2
281     cs.allocation_vars = [-8, 5, 0.00390625]
282
283     cs.aces_transform_id = "ACEScsc.ACEScg_to_ACES.a1.0.0"
284
285     cs.to_reference_transforms = []
286
287     # *AP1* primaries to *AP0* primaries.
288     cs.to_reference_transforms.append({
289         'type': 'matrix',
290         'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
291         'direction': 'forward'})
292
293     cs.from_reference_transforms = []
294
295     # *AP1* primaries to *AP0* primaries.
296     cs.from_reference_transforms.append({
297         'type': 'matrix',
298         'matrix': mat44_from_mat33(ACES_AP0_TO_AP1),
299         'direction': 'forward'})
300
301     return cs
302
303
304 # -------------------------------------------------------------------------
305 # *ADX*
306 # -------------------------------------------------------------------------
307 def create_ADX(lut_directory,
308                lut_resolution_1d,
309                bit_depth=10,
310                name='ADX'):
311     """
312     Creates the *ADX* colorspace.
313
314     Parameters
315     ----------
316     parameter : type
317         Parameter description.
318
319     Returns
320     -------
321     Colorspace
322          *ADX* colorspace.
323     """
324
325     name = '%s%s' % (name, bit_depth)
326     cs = ColorSpace(name)
327     cs.description = '%s color space - used for film scans' % name
328     cs.aliases = ["adx%s" % str(bit_depth)]
329     cs.equality_group = ''
330     cs.family = 'ADX'
331     cs.is_data = False
332
333     if bit_depth == 10:
334         cs.aces_transform_id = "ACEScsc.ADX10_to_ACES.a1.0.0"
335
336         cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT10
337         ADX_to_CDD = [1023 / 500, 0, 0, 0,
338                       0, 1023 / 500, 0, 0,
339                       0, 0, 1023 / 500, 0,
340                       0, 0, 0, 1]
341         offset = [-95 / 500, -95 / 500, -95 / 500, 0]
342     elif bit_depth == 16:
343         cs.aces_transform_id = "ACEScsc.ADX16_to_ACES.a1.0.0"
344
345         cs.bit_depth = ocio.Constants.BIT_DEPTH_UINT16
346         ADX_to_CDD = [65535 / 8000, 0, 0, 0,
347                       0, 65535 / 8000, 0, 0,
348                       0, 0, 65535 / 8000, 0,
349                       0, 0, 0, 1]
350         offset = [-1520 / 8000, -1520 / 8000, -1520 / 8000, 0]
351
352     cs.to_reference_transforms = []
353
354     # Converting from *ADX* to *Channel-Dependent Density*.
355     cs.to_reference_transforms.append({
356         'type': 'matrix',
357         'matrix': ADX_to_CDD,
358         'offset': offset,
359         'direction': 'forward'})
360
361     # Convert from Channel-Dependent Density to Channel-Independent Density
362     cs.to_reference_transforms.append({
363         'type': 'matrix',
364         'matrix': [0.75573, 0.22197, 0.02230, 0,
365                    0.05901, 0.96928, -0.02829, 0,
366                    0.16134, 0.07406, 0.76460, 0,
367                    0, 0, 0, 1],
368         'direction': 'forward'})
369
370     # Copied from *Alex Fry*'s *adx_cid_to_rle.py*
371     def create_CID_to_RLE_LUT():
372
373         def interpolate_1D(x, xp, fp):
374             return numpy.interp(x, xp, fp)
375
376         LUT_1D_xp = [-0.190000000000000,
377                      0.010000000000000,
378                      0.028000000000000,
379                      0.054000000000000,
380                      0.095000000000000,
381                      0.145000000000000,
382                      0.220000000000000,
383                      0.300000000000000,
384                      0.400000000000000,
385                      0.500000000000000,
386                      0.600000000000000]
387
388         LUT_1D_fp = [-6.000000000000000,
389                      -2.721718645000000,
390                      -2.521718645000000,
391                      -2.321718645000000,
392                      -2.121718645000000,
393                      -1.921718645000000,
394                      -1.721718645000000,
395                      -1.521718645000000,
396                      -1.321718645000000,
397                      -1.121718645000000,
398                      -0.926545676714876]
399
400         REF_PT = ((7120 - 1520) / 8000 * (100 / 55) -
401                   math.log(0.18, 10))
402
403         def cid_to_rle(x):
404             if x <= 0.6:
405                 return interpolate_1D(x, LUT_1D_xp, LUT_1D_fp)
406             return (100 / 55) * x - REF_PT
407
408         def fit(value, from_min, from_max, to_min, to_max):
409             if from_min == from_max:
410                 raise ValueError('from_min == from_max')
411             return (value - from_min) / (from_max - from_min) * (
412                 to_max - to_min) + to_min
413
414         num_samples = 2 ** 12
415         domain = (-0.19, 3)
416         data = []
417         for i in xrange(num_samples):
418             x = i / (num_samples - 1)
419             x = fit(x, 0, 1, domain[0], domain[1])
420             data.append(cid_to_rle(x))
421
422         lut = 'ADX_CID_to_RLE.spi1d'
423         write_SPI_1d(os.path.join(lut_directory, lut),
424                      domain[0],
425                      domain[1],
426                      data,
427                      num_samples, 1)
428
429         return lut
430
431     # Converting *Channel Independent Density* values to
432     # *Relative Log Exposure* values.
433     lut = create_CID_to_RLE_LUT()
434     cs.to_reference_transforms.append({
435         'type': 'lutFile',
436         'path': lut,
437         'interpolation': 'linear',
438         'direction': 'forward'})
439
440     # Converting *Relative Log Exposure* values to
441     # *Relative Exposure* values.
442     cs.to_reference_transforms.append({
443         'type': 'log',
444         'base': 10,
445         'direction': 'inverse'})
446
447     # Convert *Relative Exposure* values to *ACES* values.
448     cs.to_reference_transforms.append({
449         'type': 'matrix',
450         'matrix': [0.72286, 0.12630, 0.15084, 0,
451                    0.11923, 0.76418, 0.11659, 0,
452                    0.01427, 0.08213, 0.90359, 0,
453                    0, 0, 0, 1],
454         'direction': 'forward'})
455
456     cs.from_reference_transforms = []
457     return cs
458
459
460 # -------------------------------------------------------------------------
461 # *Generic Log Transform*
462 # -------------------------------------------------------------------------
463 def create_generic_log(aces_ctl_directory,
464                        lut_directory,
465                        lut_resolution_1d,
466                        cleanup,
467                        name='log',
468                        aliases=[],
469                        min_value=0,
470                        max_value=1,
471                        input_scale=1,
472                        middle_grey=0.18,
473                        min_exposure=-6,
474                        max_exposure=6.5):
475     """
476     Creates the *Generic Log* colorspace.
477
478     Parameters
479     ----------
480     parameter : type
481         Parameter description.
482
483     Returns
484     -------
485     Colorspace
486          *Generic Log* colorspace.
487     """
488
489     cs = ColorSpace(name)
490     cs.description = 'The %s color space' % name
491     cs.aliases = aliases
492     cs.equality_group = name
493     cs.family = 'Utility'
494     cs.is_data = False
495
496     ctls = [os.path.join(
497         aces_ctl_directory,
498         'utilities',
499         'ACESlib.Log2_to_Lin_param.a1.0.0.ctl')]
500     lut = '%s_to_linear.spi1d' % name
501
502     lut = sanitize(lut)
503
504     generate_1d_LUT_from_CTL(
505         os.path.join(lut_directory, lut),
506         ctls,
507         lut_resolution_1d,
508         'float',
509         input_scale,
510         1,
511         {'middleGrey': middle_grey,
512          'minExposure': min_exposure,
513          'maxExposure': max_exposure},
514         cleanup,
515         aces_ctl_directory,
516         min_value,
517         max_value,
518         1)
519
520     cs.to_reference_transforms = []
521     cs.to_reference_transforms.append({
522         'type': 'lutFile',
523         'path': lut,
524         'interpolation': 'linear',
525         'direction': 'forward'})
526
527     cs.from_reference_transforms = []
528     return cs
529
530
531 # -------------------------------------------------------------------------
532 # *base Dolby PQ Transform*
533 # -------------------------------------------------------------------------
534 def create_dolbypq(aces_CTL_directory,
535                    lut_directory,
536                    lut_resolution_1d,
537                    cleanup,
538                    name='pq',
539                    aliases=[],
540                    min_value=0.0,
541                    max_value=1.0,
542                    input_scale=1.0):
543     cs = ColorSpace(name)
544     cs.description = 'The %s color space' % name
545     cs.aliases = aliases
546     cs.equality_group = name
547     cs.family = 'Utility'
548     cs.is_data = False
549
550     ctls = [os.path.join(
551         aces_CTL_directory,
552         'utilities',
553         'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl')]
554     lut = '%s_to_linear.spi1d' % name
555
556     lut = sanitize(lut)
557
558     generate_1d_LUT_from_CTL(
559         os.path.join(lut_directory, lut),
560         ctls,
561         lut_resolution_1d,
562         'float',
563         input_scale,
564         1.0,
565         {},
566         cleanup,
567         aces_CTL_directory,
568         min_value,
569         max_value)
570
571     cs.to_reference_transforms = []
572     cs.to_reference_transforms.append({
573         'type': 'lutFile',
574         'path': lut,
575         'interpolation': 'linear',
576         'direction': 'forward'})
577
578     cs.from_reference_transforms = []
579     return cs
580
581
582 # -------------------------------------------------------------------------
583 # *Dolby PQ Transform that considers a fixed linear range*
584 # -------------------------------------------------------------------------
585 def create_dolbypq_scaled(aces_CTL_directory,
586                           lut_directory,
587                           lut_resolution_1d,
588                           cleanup,
589                           name='pq',
590                           aliases=[],
591                           min_value=0.0,
592                           max_value=1.0,
593                           input_scale=1.0,
594                           middle_grey=0.18,
595                           min_exposure=-6.0,
596                           max_exposure=6.5):
597     cs = ColorSpace(name)
598     cs.description = 'The %s color space' % name
599     cs.aliases = aliases
600     cs.equality_group = name
601     cs.family = 'Utility'
602     cs.is_data = False
603
604     ctls = [os.path.join(
605         aces_CTL_directory,
606         'utilities',
607         'ACESlib.DolbyPQ_to_lin_param.a1.0.0.ctl')]
608     lut = '%s_to_linear.spi1d' % name
609
610     lut = sanitize(lut)
611
612     generate_1d_LUT_from_CTL(
613         os.path.join(lut_directory, lut),
614         ctls,
615         lut_resolution_1d,
616         'float',
617         input_scale,
618         1.0,
619         {'middleGrey': middle_grey,
620          'minExposure': min_exposure,
621          'maxExposure': max_exposure},
622         cleanup,
623         aces_CTL_directory,
624         min_value,
625         max_value)
626
627     cs.to_reference_transforms = []
628     cs.to_reference_transforms.append({
629         'type': 'lutFile',
630         'path': lut,
631         'interpolation': 'linear',
632         'direction': 'forward'})
633
634     cs.from_reference_transforms = []
635     return cs
636
637
638 # -------------------------------------------------------------------------
639 # *Individual LMT*
640 # -------------------------------------------------------------------------
641 def create_ACES_LMT(lmt_name,
642                     lmt_values,
643                     shaper_info,
644                     aces_ctl_directory,
645                     lut_directory,
646                     lut_resolution_1d=1024,
647                     lut_resolution_3d=64,
648                     cleanup=True,
649                     aliases=None):
650     """
651     Creates the *ACES LMT* colorspace.
652
653     Parameters
654     ----------
655     parameter : type
656         Parameter description.
657
658     Returns
659     -------
660     Colorspace
661          *ACES LMT* colorspace.
662     """
663
664     if aliases is None:
665         aliases = []
666
667     cs = ColorSpace('%s' % lmt_name)
668     cs.description = 'The ACES Look Transform: %s' % lmt_name
669     cs.aliases = aliases
670     cs.equality_group = ''
671     cs.family = 'Look'
672     cs.is_data = False
673     cs.allocation_type = ocio.Constants.ALLOCATION_LG2
674     cs.allocation_vars = [-8, 5, 0.00390625]
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 = ["crv_%s" % compact(log2_shaper_copy_name)]
1087     log2_shaper_copy_colorspace.equality_group = log2_shaper_copy_name
1088     log2_shaper_copy_colorspace.family = log2_shaper_colorspace.family
1089     log2_shaper_copy_colorspace.is_data = log2_shaper_colorspace.is_data
1090     log2_shaper_copy_colorspace.to_reference_transforms = list(
1091         log2_shaper_colorspace.to_reference_transforms)
1092     log2_shaper_copy_colorspace.from_reference_transforms = list(
1093         log2_shaper_colorspace.from_reference_transforms)
1094     colorspaces.append(log2_shaper_copy_colorspace)
1095
1096     # Defining the *Log2 shaper that includes the AP1* primaries.
1097     log2_shaper_api1_name = "%s - AP1" % "Log2 Shaper"
1098     log2_shaper_api1_colorspace = ColorSpace(log2_shaper_api1_name)
1099     log2_shaper_api1_colorspace.description = 'The %s color space' % log2_shaper_api1_name
1100     log2_shaper_api1_colorspace.aliases = [
1101         "%s_ap1" % compact(log2_shaper_copy_name)]
1102     log2_shaper_api1_colorspace.equality_group = log2_shaper_api1_name
1103     log2_shaper_api1_colorspace.family = log2_shaper_colorspace.family
1104     log2_shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1105     log2_shaper_api1_colorspace.to_reference_transforms = list(
1106         log2_shaper_colorspace.to_reference_transforms)
1107     log2_shaper_api1_colorspace.from_reference_transforms = list(
1108         log2_shaper_colorspace.from_reference_transforms)
1109
1110     # *AP1* primaries to *AP0* primaries.
1111     log2_shaper_api1_colorspace.to_reference_transforms.append({
1112         'type': 'matrix',
1113         'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
1114         'direction': 'forward'
1115     })
1116     colorspaces.append(log2_shaper_api1_colorspace)
1117
1118     # Defining the *Log2 shaper that includes the AP1* primaries.
1119     # Named with 'shaper_name' variable. Needed for some LUT baking steps.
1120     shaper_api1_name = "%s - AP1" % shaper_name
1121     shaper_api1_colorspace = ColorSpace(shaper_api1_name)
1122     shaper_api1_colorspace.description = 'The %s color space' % shaper_api1_name
1123     shaper_api1_colorspace.aliases = ["%s_ap1" % compact(shaper_name)]
1124     shaper_api1_colorspace.equality_group = shaper_api1_name
1125     shaper_api1_colorspace.family = log2_shaper_colorspace.family
1126     shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1127     shaper_api1_colorspace.to_reference_transforms = list(
1128         log2_shaper_api1_colorspace.to_reference_transforms)
1129     shaper_api1_colorspace.from_reference_transforms = list(
1130         log2_shaper_api1_colorspace.from_reference_transforms)
1131     colorspaces.append(shaper_api1_colorspace)
1132
1133     # Define the base *Dolby PQ Shaper*
1134     #
1135     dolbypq_shaper_name = "Dolby PQ 10000"
1136     dolbypq_shaper_name_aliases = ["crv_%s" % "dolbypq_10000"]
1137
1138     dolbypq_shaper_colorspace = create_dolbypq(
1139         aces_ctl_directory,
1140         lut_directory,
1141         lut_resolution_1d,
1142         cleanup,
1143         name=dolbypq_shaper_name,
1144         aliases=dolbypq_shaper_name_aliases)
1145     colorspaces.append(dolbypq_shaper_colorspace)
1146
1147     # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1148     dolbypq_shaper_data = [
1149         dolbypq_shaper_name,
1150         os.path.join('%s',
1151                      'utilities',
1152                      'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl'),
1153         os.path.join('%s',
1154                      'utilities',
1155                      'ACESlib.Lin_to_DolbyPQ.a1.0.0.ctl'),
1156         1.0,
1157         {}]
1158
1159     shaper_data[dolbypq_shaper_name] = dolbypq_shaper_data
1160
1161     # Define the *Dolby PQ Shaper that considers a fixed linear range*
1162     #
1163     dolbypq_scaled_shaper_name = "Dolby PQ Scaled"
1164     dolbypq_scaled_shaper_name_aliases = ["crv_%s" % "dolbypq_scaled"]
1165
1166     dolbypq_scaled_shaper_colorspace = create_dolbypq_scaled(
1167         aces_ctl_directory,
1168         lut_directory,
1169         lut_resolution_1d,
1170         cleanup,
1171         name=dolbypq_scaled_shaper_name,
1172         aliases=dolbypq_scaled_shaper_name_aliases)
1173     colorspaces.append(dolbypq_scaled_shaper_colorspace)
1174
1175     # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1176     dolbypq_scaled_shaper_data = [
1177         dolbypq_scaled_shaper_name,
1178         os.path.join('%s',
1179                      'utilities',
1180                      'ACESlib.DolbyPQ_to_Lin_param.a1.0.0.ctl'),
1181         os.path.join('%s',
1182                      'utilities',
1183                      'ACESlib.Lin_to_DolbyPQ_param.a1.0.0.ctl'),
1184         1.0,
1185         log2_params]
1186
1187     shaper_data[dolbypq_scaled_shaper_name] = dolbypq_scaled_shaper_data
1188
1189     #
1190     # Pick a specific shaper
1191     #
1192     rrt_shaper = log2_shaper_data
1193     # rrt_shaper = dolbypq_scaled_shaper_data
1194
1195     # *RRT + ODT* combinations.
1196     sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1])
1197     print(sorted_odts)
1198     for odt in sorted_odts:
1199         (odt_name, odt_values) = odt
1200
1201         # Generating only full range transform for *ODTs* that can generate 
1202         # either *legal* or *full* output.
1203
1204         # Uncomment these lines and the lower section and flip the 'legalRange' value to 1
1205         # to recover the old behavior, where both legal and full range LUTs were generated
1206         if odt_values['transformHasFullLegalSwitch']:
1207             #odt_name_legal = '%s - Legal' % odt_values['transformUserName']
1208             odt_legal['legalRange'] = 0
1209         #else:
1210         #    odt_name_legal = odt_values['transformUserName']
1211  
1212         odt_name_legal = odt_values['transformUserName']
1213
1214         odt_legal = odt_values.copy()
1215
1216         odt_aliases = ["out_%s" % compact(odt_name_legal)]
1217
1218         cs = create_ACES_RRT_plus_ODT(
1219             odt_name_legal,
1220             odt_legal,
1221             rrt_shaper,
1222             aces_ctl_directory,
1223             lut_directory,
1224             lut_resolution_1d,
1225             lut_resolution_3d,
1226             cleanup,
1227             odt_aliases)
1228         colorspaces.append(cs)
1229
1230         displays[odt_name_legal] = {
1231             'Raw': linear_display_space,
1232             'Log': log_display_space,
1233             'Output Transform': cs}
1234
1235         '''
1236         # Generating full range transform for *ODTs* that can generate 
1237         # either *legal* or *full* output.
1238         if odt_values['transformHasFullLegalSwitch']:
1239             print('Generating full range ODT for %s' % odt_name)
1240
1241             odt_name_full = '%s - Full' % odt_values['transformUserName']
1242             odt_full = odt_values.copy()
1243             odt_full['legalRange'] = 0
1244
1245             odt_full_aliases = ["out_%s" % compact(odt_name_full)]
1246
1247             cs_full = create_ACES_RRT_plus_ODT(
1248                 odt_name_full,
1249                 odt_full,
1250                 rrt_shaper,
1251                 aces_ctl_directory,
1252                 lut_directory,
1253                 lut_resolution_1d,
1254                 lut_resolution_3d,
1255                 cleanup,
1256                 odt_full_aliases)
1257             colorspaces.append(cs_full)
1258
1259             displays[odt_name_full] = {
1260                 'Raw': linear_display_space,
1261                 'Log': log_display_space,
1262                 'Output Transform': cs_full}
1263         '''
1264
1265     return (colorspaces, displays)
1266
1267
1268 def get_transform_info(ctl_transform):
1269     """
1270     Object description.
1271
1272     Parameters
1273     ----------
1274     parameter : type
1275         Parameter description.
1276
1277     Returns
1278     -------
1279     type
1280          Return value description.
1281     """
1282
1283     with open(ctl_transform, 'rb') as fp:
1284         lines = fp.readlines()
1285
1286     # Retrieving the *transform ID* and *User Name*.
1287     transform_id = lines[1][3:].split('<')[1].split('>')[1].strip()
1288     transform_user_name = '-'.join(
1289         lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip()
1290     transform_user_name_prefix = (
1291         lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
1292
1293     # Figuring out if this transform has options for processing full and legal range
1294     transform_full_legal_switch = False
1295     for line in lines:
1296         if line.strip() == "input varying int legalRange = 0":
1297             # print( "%s has legal range flag" % transform_user_name)
1298             transform_full_legal_switch = True
1299             break
1300
1301     return (transform_id, transform_user_name, transform_user_name_prefix,
1302             transform_full_legal_switch)
1303
1304
1305 def get_ODTs_info(aces_ctl_directory):
1306     """
1307     Object description.
1308
1309     For versions after WGR9.
1310
1311     Parameters
1312     ----------
1313     parameter : type
1314         Parameter description.
1315
1316     Returns
1317     -------
1318     type
1319          Return value description.
1320     """
1321
1322     # TODO: Investigate usage of *files_walker* definition here.
1323     # Credit to *Alex Fry* for the original approach here.
1324     odt_dir = os.path.join(aces_ctl_directory, 'odt')
1325     all_odt = []
1326     for dir_name, subdir_list, file_list in os.walk(odt_dir):
1327         for fname in file_list:
1328             all_odt.append((os.path.join(dir_name, fname)))
1329
1330     odt_CTLs = [x for x in all_odt if
1331                 ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')]
1332
1333     odts = {}
1334
1335     for odt_CTL in odt_CTLs:
1336         odt_tokens = os.path.split(odt_CTL)
1337
1338         # Handling nested directories.
1339         odt_path_tokens = os.path.split(odt_tokens[-2])
1340         odt_dir = odt_path_tokens[-1]
1341         while odt_path_tokens[-2][-3:] != 'odt':
1342             odt_path_tokens = os.path.split(odt_path_tokens[-2])
1343             odt_dir = os.path.join(odt_path_tokens[-1], odt_dir)
1344
1345         # Building full name,
1346         transform_CTL = odt_tokens[-1]
1347         odt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1348
1349         # Finding id, user name and user name prefix.
1350         (transform_ID,
1351          transform_user_name,
1352          transform_user_name_prefix,
1353          transform_full_legal_switch) = get_transform_info(
1354             os.path.join(aces_ctl_directory, 'odt', odt_dir, transform_CTL))
1355
1356         # Finding inverse.
1357         transform_CTL_inverse = 'InvODT.%s.ctl' % odt_name
1358         if not os.path.exists(
1359                 os.path.join(odt_tokens[-2], transform_CTL_inverse)):
1360             transform_CTL_inverse = None
1361
1362         # Add to list of ODTs
1363         odts[odt_name] = {}
1364         odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_CTL)
1365         if transform_CTL_inverse is not None:
1366             odts[odt_name]['transformCTLInverse'] = os.path.join(
1367                 odt_dir, transform_CTL_inverse)
1368
1369         odts[odt_name]['transformID'] = transform_ID
1370         odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1371         odts[odt_name]['transformUserName'] = transform_user_name
1372         odts[odt_name][
1373             'transformHasFullLegalSwitch'] = transform_full_legal_switch
1374
1375         forward_CTL = odts[odt_name]['transformCTL']
1376
1377         print('ODT : %s' % odt_name)
1378         print('\tTransform ID               : %s' % transform_ID)
1379         print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1380         print('\tTransform User Name        : %s' % transform_user_name)
1381         print(
1382             '\tHas Full / Legal Switch    : %s' % transform_full_legal_switch)
1383         print('\tForward ctl                : %s' % forward_CTL)
1384         if 'transformCTLInverse' in odts[odt_name]:
1385             inverse_CTL = odts[odt_name]['transformCTLInverse']
1386             print('\tInverse ctl                : %s' % inverse_CTL)
1387         else:
1388             print('\tInverse ctl                : %s' % 'None')
1389
1390     print('\n')
1391
1392     return odts
1393
1394
1395 def get_LMTs_info(aces_ctl_directory):
1396     """
1397     Object description.
1398
1399     For versions after WGR9.
1400
1401     Parameters
1402     ----------
1403     parameter : type
1404         Parameter description.
1405
1406     Returns
1407     -------
1408     type
1409          Return value description.
1410     """
1411
1412     # TODO: Investigate refactoring with previous definition.
1413
1414     # Credit to Alex Fry for the original approach here
1415     lmt_dir = os.path.join(aces_ctl_directory, 'lmt')
1416     all_lmt = []
1417     for dir_name, subdir_list, file_list in os.walk(lmt_dir):
1418         for fname in file_list:
1419             all_lmt.append((os.path.join(dir_name, fname)))
1420
1421     lmt_CTLs = [x for x in all_lmt if
1422                 ('InvLMT' not in x) and ('README' not in x) and (
1423                     os.path.split(x)[-1][0] != '.')]
1424
1425     lmts = {}
1426
1427     for lmt_CTL in lmt_CTLs:
1428         lmt_tokens = os.path.split(lmt_CTL)
1429
1430         # Handlimg nested directories.
1431         lmt_path_tokens = os.path.split(lmt_tokens[-2])
1432         lmt_dir = lmt_path_tokens[-1]
1433         while lmt_path_tokens[-2][-3:] != 'ctl':
1434             lmt_path_tokens = os.path.split(lmt_path_tokens[-2])
1435             lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir)
1436
1437         # Building full name.
1438         transform_CTL = lmt_tokens[-1]
1439         lmt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1440
1441         # Finding id, user name and user name prefix.
1442         (transform_ID,
1443          transform_user_name,
1444          transform_user_name_prefix,
1445          transform_full_legal_switch) = get_transform_info(
1446             os.path.join(aces_ctl_directory, lmt_dir, transform_CTL))
1447
1448         # Finding inverse.
1449         transform_CTL_inverse = 'InvLMT.%s.ctl' % lmt_name
1450         if not os.path.exists(
1451                 os.path.join(lmt_tokens[-2], transform_CTL_inverse)):
1452             transform_CTL_inverse = None
1453
1454         lmts[lmt_name] = {}
1455         lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_CTL)
1456         if transform_CTL_inverse is not None:
1457             lmts[lmt_name]['transformCTLInverse'] = os.path.join(
1458                 lmt_dir, transform_CTL_inverse)
1459
1460         lmts[lmt_name]['transformID'] = transform_ID
1461         lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1462         lmts[lmt_name]['transformUserName'] = transform_user_name
1463
1464         forward_CTL = lmts[lmt_name]['transformCTL']
1465
1466         print('LMT : %s' % lmt_name)
1467         print('\tTransform ID               : %s' % transform_ID)
1468         print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1469         print('\tTransform User Name        : %s' % transform_user_name)
1470         print('\t Forward ctl               : %s' % forward_CTL)
1471         if 'transformCTLInverse' in lmts[lmt_name]:
1472             inverse_CTL = lmts[lmt_name]['transformCTLInverse']
1473             print('\t Inverse ctl                : %s' % inverse_CTL)
1474         else:
1475             print('\t Inverse ctl                : %s' % 'None')
1476
1477     print('\n')
1478
1479     return lmts
1480
1481
1482 def create_colorspaces(aces_ctl_directory,
1483                        lut_directory,
1484                        lut_resolution_1d,
1485                        lut_resolution_3d,
1486                        lmt_info,
1487                        odt_info,
1488                        shaper_name,
1489                        cleanup):
1490     """
1491     Generates the colorspace conversions.
1492
1493     Parameters
1494     ----------
1495     parameter : type
1496         Parameter description.
1497
1498     Returns
1499     -------
1500     type
1501          Return value description.
1502     """
1503
1504     colorspaces = []
1505
1506     ACES = create_ACES()
1507
1508     ACEScc = create_ACEScc(aces_ctl_directory, lut_directory,
1509                            lut_resolution_1d, cleanup,
1510                            min_value=-0.35840, max_value=1.468)
1511     colorspaces.append(ACEScc)
1512
1513     ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory,
1514                                  lut_resolution_1d, cleanup)
1515     colorspaces.append(ACESproxy)
1516
1517     ACEScg = create_ACEScg(aces_ctl_directory, lut_directory,
1518                            lut_resolution_1d, cleanup)
1519     colorspaces.append(ACEScg)
1520
1521     ADX10 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=10)
1522     colorspaces.append(ADX10)
1523
1524     ADX16 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=16)
1525     colorspaces.append(ADX16)
1526
1527     lmts = create_LMTs(aces_ctl_directory,
1528                        lut_directory,
1529                        lut_resolution_1d,
1530                        lut_resolution_3d,
1531                        lmt_info,
1532                        shaper_name,
1533                        cleanup)
1534     colorspaces.extend(lmts)
1535
1536     odts, displays = create_ODTs(aces_ctl_directory,
1537                                  lut_directory,
1538                                  lut_resolution_1d,
1539                                  lut_resolution_3d,
1540                                  odt_info,
1541                                  shaper_name,
1542                                  cleanup,
1543                                  ACES,
1544                                  ACEScc)
1545     colorspaces.extend(odts)
1546
1547     # Wish there was an automatic way to get this from the CTL
1548     defaultDisplay = "sRGB (D60 sim.)"
1549
1550     roles = {'color_picking': ACEScg.name,
1551              'color_timing': ACEScc.name,
1552              'compositing_log': ACEScc.name,
1553              'data': '',
1554              'default': ACES.name,
1555              'matte_paint': ACEScc.name,
1556              'reference': '',
1557              'scene_linear': ACEScg.name,
1558              'texture_paint': ''}
1559
1560     return ACES, colorspaces, displays, ACEScc, roles, defaultDisplay