e16e5fe2a1a2d475c7e8d0db523f107aee71f1f3
[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=None,
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     if aliases is None:
489         aliases = []
490
491     cs = ColorSpace(name)
492     cs.description = 'The %s color space' % name
493     cs.aliases = aliases
494     cs.equality_group = name
495     cs.family = 'Utility'
496     cs.is_data = False
497
498     ctls = [os.path.join(
499         aces_ctl_directory,
500         'utilities',
501         'ACESlib.Log2_to_Lin_param.a1.0.0.ctl')]
502     lut = '%s_to_linear.spi1d' % name
503
504     lut = sanitize(lut)
505
506     generate_1d_LUT_from_CTL(
507         os.path.join(lut_directory, lut),
508         ctls,
509         lut_resolution_1d,
510         'float',
511         input_scale,
512         1,
513         {'middleGrey': middle_grey,
514          'minExposure': min_exposure,
515          'maxExposure': max_exposure},
516         cleanup,
517         aces_ctl_directory,
518         min_value,
519         max_value,
520         1)
521
522     cs.to_reference_transforms = []
523     cs.to_reference_transforms.append({
524         'type': 'lutFile',
525         'path': lut,
526         'interpolation': 'linear',
527         'direction': 'forward'})
528
529     cs.from_reference_transforms = []
530     return cs
531
532
533 # -------------------------------------------------------------------------
534 # *base Dolby PQ Transform*
535 # -------------------------------------------------------------------------
536 def create_Dolby_PQ(aces_ctl_directory,
537                    lut_directory,
538                    lut_resolution_1d,
539                    cleanup,
540                    name='pq',
541                    aliases=None,
542                    min_value=0.0,
543                    max_value=1.0,
544                    input_scale=1.0):
545     if aliases is None:
546         aliases = []
547
548     cs = ColorSpace(name)
549     cs.description = 'The %s color space' % name
550     cs.aliases = aliases
551     cs.equality_group = name
552     cs.family = 'Utility'
553     cs.is_data = False
554
555     ctls = [os.path.join(
556         aces_ctl_directory,
557         'utilities',
558         'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl')]
559     lut = '%s_to_linear.spi1d' % name
560
561     lut = sanitize(lut)
562
563     generate_1d_LUT_from_CTL(
564         os.path.join(lut_directory, lut),
565         ctls,
566         lut_resolution_1d,
567         'float',
568         input_scale,
569         1.0,
570         {},
571         cleanup,
572         aces_ctl_directory,
573         min_value,
574         max_value)
575
576     cs.to_reference_transforms = []
577     cs.to_reference_transforms.append({
578         'type': 'lutFile',
579         'path': lut,
580         'interpolation': 'linear',
581         'direction': 'forward'})
582
583     cs.from_reference_transforms = []
584     return cs
585
586
587 # -------------------------------------------------------------------------
588 # *Dolby PQ Transform that considers a fixed linear range*
589 # -------------------------------------------------------------------------
590 def create_Dolby_PQ_scaled(aces_ctl_directory,
591                           lut_directory,
592                           lut_resolution_1d,
593                           cleanup,
594                           name='pq',
595                           aliases=None,
596                           min_value=0.0,
597                           max_value=1.0,
598                           input_scale=1.0,
599                           middle_grey=0.18,
600                           min_exposure=-6.0,
601                           max_exposure=6.5):
602     if aliases is None:
603         aliases = []
604
605     cs = ColorSpace(name)
606     cs.description = 'The %s color space' % name
607     cs.aliases = aliases
608     cs.equality_group = name
609     cs.family = 'Utility'
610     cs.is_data = False
611
612     ctls = [os.path.join(
613         aces_ctl_directory,
614         'utilities',
615         'ACESlib.DolbyPQ_to_lin_param.a1.0.0.ctl')]
616     lut = '%s_to_linear.spi1d' % name
617
618     lut = sanitize(lut)
619
620     generate_1d_LUT_from_CTL(
621         os.path.join(lut_directory, lut),
622         ctls,
623         lut_resolution_1d,
624         'float',
625         input_scale,
626         1.0,
627         {'middleGrey': middle_grey,
628          'minExposure': min_exposure,
629          'maxExposure': max_exposure},
630         cleanup,
631         aces_ctl_directory,
632         min_value,
633         max_value)
634
635     cs.to_reference_transforms = []
636     cs.to_reference_transforms.append({
637         'type': 'lutFile',
638         'path': lut,
639         'interpolation': 'linear',
640         'direction': 'forward'})
641
642     cs.from_reference_transforms = []
643     return cs
644
645
646 # -------------------------------------------------------------------------
647 # *Individual LMT*
648 # -------------------------------------------------------------------------
649 def create_ACES_LMT(lmt_name,
650                     lmt_values,
651                     shaper_info,
652                     aces_ctl_directory,
653                     lut_directory,
654                     lut_resolution_1d=1024,
655                     lut_resolution_3d=64,
656                     cleanup=True,
657                     aliases=None):
658     """
659     Creates the *ACES LMT* colorspace.
660
661     Parameters
662     ----------
663     parameter : type
664         Parameter description.
665
666     Returns
667     -------
668     Colorspace
669          *ACES LMT* colorspace.
670     """
671
672     if aliases is None:
673         aliases = []
674
675     cs = ColorSpace('%s' % lmt_name)
676     cs.description = 'The ACES Look Transform: %s' % lmt_name
677     cs.aliases = aliases
678     cs.equality_group = ''
679     cs.family = 'Look'
680     cs.is_data = False
681     cs.allocation_type = ocio.Constants.ALLOCATION_LG2
682     cs.allocation_vars = [-8, 5, 0.00390625]
683     cs.aces_transform_id = lmt_values['transformID']
684
685     pprint.pprint(lmt_values)
686
687     # Generating the *shaper* transform.
688     (shaper_name,
689      shaper_to_aces_ctl,
690      shaper_from_aces_ctl,
691      shaper_input_scale,
692      shaper_params) = shaper_info
693
694     # Add the shaper transform
695     shaper_lut = '%s_to_linear.spi1d' % shaper_name
696     shaper_lut = sanitize(shaper_lut)
697
698     shaper_ocio_transform = {
699         'type': 'lutFile',
700         'path': shaper_lut,
701         'interpolation': 'linear',
702         'direction': 'inverse'}
703
704     # Generating the forward transform.
705     cs.from_reference_transforms = []
706
707     if 'transformCTL' in lmt_values:
708         ctls = [shaper_to_aces_ctl % aces_ctl_directory,
709                 os.path.join(aces_ctl_directory,
710                              lmt_values['transformCTL'])]
711         lut = '%s.%s.spi3d' % (shaper_name, lmt_name)
712
713         lut = sanitize(lut)
714
715         generate_3d_LUT_from_CTL(
716             os.path.join(lut_directory, lut),
717             ctls,
718             lut_resolution_3d,
719             'float',
720             1 / shaper_input_scale,
721             1,
722             shaper_params,
723             cleanup,
724             aces_ctl_directory)
725
726         cs.from_reference_transforms.append(shaper_ocio_transform)
727         cs.from_reference_transforms.append({
728             'type': 'lutFile',
729             'path': lut,
730             'interpolation': 'tetrahedral',
731             'direction': 'forward'})
732
733     # Generating the inverse transform.
734     cs.to_reference_transforms = []
735
736     if 'transformCTLInverse' in lmt_values:
737         ctls = [os.path.join(aces_ctl_directory,
738                              lmt_values['transformCTLInverse']),
739                 shaper_from_aces_ctl % aces_ctl_directory]
740         lut = 'Inverse.%s.%s.spi3d' % (odt_name, shaper_name)
741
742         lut = sanitize(lut)
743
744         generate_3d_LUT_from_CTL(
745             os.path.join(lut_directory, lut),
746             ctls,
747             lut_resolution_3d,
748             'half',
749             1,
750             shaper_input_scale,
751             shaper_params,
752             cleanup,
753             aces_ctl_directory,
754             0)
755
756         cs.to_reference_transforms.append({
757             'type': 'lutFile',
758             'path': lut,
759             'interpolation': 'tetrahedral',
760             'direction': 'forward'})
761
762         shaper_inverse = shaper_ocio_transform.copy()
763         shaper_inverse['direction'] = 'forward'
764         cs.to_reference_transforms.append(shaper_inverse)
765
766     return cs
767
768
769 # -------------------------------------------------------------------------
770 # *LMTs*
771 # -------------------------------------------------------------------------
772 def create_LMTs(aces_ctl_directory,
773                 lut_directory,
774                 lut_resolution_1d,
775                 lut_resolution_3d,
776                 lmt_info,
777                 shaper_name,
778                 cleanup):
779     """
780     Object description.
781
782     Parameters
783     ----------
784     parameter : type
785         Parameter description.
786
787     Returns
788     -------
789     type
790          Return value description.
791     """
792
793     colorspaces = []
794
795     # -------------------------------------------------------------------------
796     # *LMT Shaper*
797     # -------------------------------------------------------------------------
798     lmt_lut_resolution_1d = max(4096, lut_resolution_1d)
799     lmt_lut_resolution_3d = max(65, lut_resolution_3d)
800
801     # Defining the *Log 2* shaper.
802     lmt_shaper_name = 'LMT Shaper'
803     lmt_shaper_name_aliases = ['crv_lmtshaper']
804     lmt_params = {
805         'middleGrey': 0.18,
806         'minExposure': -10,
807         'maxExposure': 6.5}
808
809     lmt_shaper = create_generic_log(aces_ctl_directory,
810                                     lut_directory,
811                                     lmt_lut_resolution_1d,
812                                     cleanup,
813                                     name=lmt_shaper_name,
814                                     middle_grey=lmt_params['middleGrey'],
815                                     min_exposure=lmt_params['minExposure'],
816                                     max_exposure=lmt_params['maxExposure'],
817                                     aliases=lmt_shaper_name_aliases)
818     colorspaces.append(lmt_shaper)
819
820     shaper_input_scale_generic_log2 = 1
821
822     # *Log 2* shaper name and *CTL* transforms bundled up.
823     lmt_shaper_data = [
824         lmt_shaper_name,
825         os.path.join('%s',
826                      'utilities',
827                      'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
828         os.path.join('%s',
829                      'utilities',
830                      'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
831         shaper_input_scale_generic_log2,
832         lmt_params]
833
834     sorted_lmts = sorted(lmt_info.iteritems(), key=lambda x: x[1])
835     print(sorted_lmts)
836     for lmt in sorted_lmts:
837         lmt_name, lmt_values = lmt
838         lmt_aliases = ['look_%s' % compact(lmt_values['transformUserName'])]
839         cs = create_ACES_LMT(
840             lmt_values['transformUserName'],
841             lmt_values,
842             lmt_shaper_data,
843             aces_ctl_directory,
844             lut_directory,
845             lmt_lut_resolution_1d,
846             lmt_lut_resolution_3d,
847             cleanup,
848             lmt_aliases)
849         colorspaces.append(cs)
850
851     return colorspaces
852
853
854 # -------------------------------------------------------------------------
855 # *ACES RRT* with supplied *ODT*.
856 # -------------------------------------------------------------------------
857 def create_ACES_RRT_plus_ODT(odt_name,
858                              odt_values,
859                              shaper_info,
860                              aces_ctl_directory,
861                              lut_directory,
862                              lut_resolution_1d=1024,
863                              lut_resolution_3d=64,
864                              cleanup=True,
865                              aliases=None):
866     """
867     Object description.
868
869     Parameters
870     ----------
871     parameter : type
872         Parameter description.
873
874     Returns
875     -------
876     type
877          Return value description.
878     """
879
880     if aliases is None:
881         aliases = []
882
883     cs = ColorSpace('%s' % odt_name)
884     cs.description = '%s - %s Output Transform' % (
885         odt_values['transformUserNamePrefix'], odt_name)
886     cs.aliases = aliases
887     cs.equality_group = ''
888     cs.family = 'Output'
889     cs.is_data = False
890
891     cs.aces_transform_id = odt_values['transformID']
892
893     pprint.pprint(odt_values)
894
895     # Generating the *shaper* transform.
896     (shaper_name,
897      shaper_to_aces_ctl,
898      shaper_from_aces_ctl,
899      shaper_input_scale,
900      shaper_params) = shaper_info
901
902     if 'legalRange' in odt_values:
903         shaper_params['legalRange'] = odt_values['legalRange']
904     else:
905         shaper_params['legalRange'] = 0
906
907     # Add the shaper transform
908     shaper_lut = '%s_to_linear.spi1d' % shaper_name
909     shaper_lut = sanitize(shaper_lut)
910
911     shaper_ocio_transform = {
912         'type': 'lutFile',
913         'path': shaper_lut,
914         'interpolation': 'linear',
915         'direction': 'inverse'}
916
917     # Generating the *forward* transform.
918     cs.from_reference_transforms = []
919
920     if 'transformLUT' in odt_values:
921         transform_lut_file_name = os.path.basename(
922             odt_values['transformLUT'])
923         lut = os.path.join(lut_directory, transform_lut_file_name)
924         shutil.copy(odt_values['transformLUT'], lut)
925
926         cs.from_reference_transforms.append(shaper_ocio_transform)
927         cs.from_reference_transforms.append({
928             'type': 'lutFile',
929             'path': transform_lut_file_name,
930             'interpolation': 'tetrahedral',
931             'direction': 'forward'})
932     elif 'transformCTL' in odt_values:
933         ctls = [
934             shaper_to_aces_ctl % aces_ctl_directory,
935             os.path.join(aces_ctl_directory,
936                          'rrt',
937                          'RRT.a1.0.0.ctl'),
938             os.path.join(aces_ctl_directory,
939                          'odt',
940                          odt_values['transformCTL'])]
941         lut = '%s.RRT.a1.0.0.%s.spi3d' % (shaper_name, odt_name)
942
943         lut = sanitize(lut)
944
945         generate_3d_LUT_from_CTL(
946             os.path.join(lut_directory, lut),
947             # shaperLUT,
948             ctls,
949             lut_resolution_3d,
950             'float',
951             1 / shaper_input_scale,
952             1,
953             shaper_params,
954             cleanup,
955             aces_ctl_directory)
956
957         cs.from_reference_transforms.append(shaper_ocio_transform)
958         cs.from_reference_transforms.append({
959             'type': 'lutFile',
960             'path': lut,
961             'interpolation': 'tetrahedral',
962             'direction': 'forward'})
963
964     # Generating the *inverse* transform.
965     cs.to_reference_transforms = []
966
967     if 'transformLUTInverse' in odt_values:
968         transform_lut_inverse_file_name = os.path.basename(
969             odt_values['transformLUTInverse'])
970         lut = os.path.join(lut_directory, transform_lut_inverse_file_name)
971         shutil.copy(odt_values['transformLUTInverse'], lut)
972
973         cs.to_reference_transforms.append({
974             'type': 'lutFile',
975             'path': transform_lut_inverse_file_name,
976             'interpolation': 'tetrahedral',
977             'direction': 'forward'})
978
979         shaper_inverse = shaper_ocio_transform.copy()
980         shaper_inverse['direction'] = 'forward'
981         cs.to_reference_transforms.append(shaper_inverse)
982     elif 'transformCTLInverse' in odt_values:
983         ctls = [os.path.join(aces_ctl_directory,
984                              'odt',
985                              odt_values['transformCTLInverse']),
986                 os.path.join(aces_ctl_directory,
987                              'rrt',
988                              'InvRRT.a1.0.0.ctl'),
989                 shaper_from_aces_ctl % aces_ctl_directory]
990         lut = 'InvRRT.a1.0.0.%s.%s.spi3d' % (odt_name, shaper_name)
991
992         lut = sanitize(lut)
993
994         generate_3d_LUT_from_CTL(
995             os.path.join(lut_directory, lut),
996             # None,
997             ctls,
998             lut_resolution_3d,
999             'half',
1000             1,
1001             shaper_input_scale,
1002             shaper_params,
1003             cleanup,
1004             aces_ctl_directory)
1005
1006         cs.to_reference_transforms.append({
1007             'type': 'lutFile',
1008             'path': lut,
1009             'interpolation': 'tetrahedral',
1010             'direction': 'forward'})
1011
1012         shaper_inverse = shaper_ocio_transform.copy()
1013         shaper_inverse['direction'] = 'forward'
1014         cs.to_reference_transforms.append(shaper_inverse)
1015
1016     return cs
1017
1018
1019 # -------------------------------------------------------------------------
1020 # *ODTs*
1021 # -------------------------------------------------------------------------
1022 def create_ODTs(aces_ctl_directory,
1023                 lut_directory,
1024                 lut_resolution_1d,
1025                 lut_resolution_3d,
1026                 odt_info,
1027                 shaper_name,
1028                 cleanup,
1029                 linear_display_space,
1030                 log_display_space):
1031     """
1032     Object description.
1033
1034     Parameters
1035     ----------
1036     parameter : type
1037         Parameter description.
1038
1039     Returns
1040     -------
1041     type
1042          Return value description.
1043     """
1044
1045     colorspaces = []
1046     displays = {}
1047
1048     # -------------------------------------------------------------------------
1049     # *RRT / ODT* Shaper Options
1050     # -------------------------------------------------------------------------
1051     shaper_data = {}
1052
1053     # Defining the *Log 2* shaper.
1054     log2_shaper_name = shaper_name
1055     log2_shaper_name_aliases = ['crv_%s' % compact(log2_shaper_name)]
1056     log2_params = {
1057         'middleGrey': 0.18,
1058         'minExposure': -6,
1059         'maxExposure': 6.5}
1060
1061     log2_shaper_colorspace = create_generic_log(
1062         aces_ctl_directory,
1063         lut_directory,
1064         lut_resolution_1d,
1065         cleanup,
1066         name=log2_shaper_name,
1067         middle_grey=log2_params['middleGrey'],
1068         min_exposure=log2_params['minExposure'],
1069         max_exposure=log2_params['maxExposure'],
1070         aliases=log2_shaper_name_aliases)
1071     colorspaces.append(log2_shaper_colorspace)
1072
1073     shaper_input_scale_generic_log2 = 1
1074
1075     # *Log 2* shaper name and *CTL* transforms bundled up.
1076     log2_shaper_data = [
1077         log2_shaper_name,
1078         os.path.join('%s',
1079                      'utilities',
1080                      'ACESlib.Log2_to_Lin_param.a1.0.0.ctl'),
1081         os.path.join('%s',
1082                      'utilities',
1083                      'ACESlib.Lin_to_Log2_param.a1.0.0.ctl'),
1084         shaper_input_scale_generic_log2,
1085         log2_params]
1086
1087     shaper_data[log2_shaper_name] = log2_shaper_data
1088
1089     # Space with a more user-friendly name. Direct copy otherwise.
1090     log2_shaper_copy_name = 'Log2 Shaper'
1091     log2_shaper_copy_colorspace = ColorSpace(log2_shaper_copy_name)
1092     log2_shaper_copy_colorspace.description = (
1093         'The %s color space' % log2_shaper_copy_name)
1094     log2_shaper_copy_colorspace.aliases = [
1095         'crv_%s' % compact(log2_shaper_copy_name)]
1096     log2_shaper_copy_colorspace.equality_group = log2_shaper_copy_name
1097     log2_shaper_copy_colorspace.family = log2_shaper_colorspace.family
1098     log2_shaper_copy_colorspace.is_data = log2_shaper_colorspace.is_data
1099     log2_shaper_copy_colorspace.to_reference_transforms = list(
1100         log2_shaper_colorspace.to_reference_transforms)
1101     log2_shaper_copy_colorspace.from_reference_transforms = list(
1102         log2_shaper_colorspace.from_reference_transforms)
1103     colorspaces.append(log2_shaper_copy_colorspace)
1104
1105     # Defining the *Log2 shaper that includes the AP1* primaries.
1106     log2_shaper_api1_name = '%s - AP1' % 'Log2 Shaper'
1107     log2_shaper_api1_colorspace = ColorSpace(log2_shaper_api1_name)
1108     log2_shaper_api1_colorspace.description = (
1109         'The %s color space' % log2_shaper_api1_name)
1110     log2_shaper_api1_colorspace.aliases = [
1111         '%s_ap1' % compact(log2_shaper_copy_name)]
1112     log2_shaper_api1_colorspace.equality_group = log2_shaper_api1_name
1113     log2_shaper_api1_colorspace.family = log2_shaper_colorspace.family
1114     log2_shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1115     log2_shaper_api1_colorspace.to_reference_transforms = list(
1116         log2_shaper_colorspace.to_reference_transforms)
1117     log2_shaper_api1_colorspace.from_reference_transforms = list(
1118         log2_shaper_colorspace.from_reference_transforms)
1119
1120     # *AP1* primaries to *AP0* primaries.
1121     log2_shaper_api1_colorspace.to_reference_transforms.append({
1122         'type': 'matrix',
1123         'matrix': mat44_from_mat33(ACES_AP1_TO_AP0),
1124         'direction': 'forward'
1125     })
1126     colorspaces.append(log2_shaper_api1_colorspace)
1127
1128     # Defining the *Log2 shaper that includes the AP1* primaries.
1129     # Named with 'shaper_name' variable. Needed for some LUT baking steps.
1130     shaper_api1_name = '%s - AP1' % shaper_name
1131     shaper_api1_colorspace = ColorSpace(shaper_api1_name)
1132     shaper_api1_colorspace.description = (
1133         'The %s color space' % shaper_api1_name)
1134     shaper_api1_colorspace.aliases = ['%s_ap1' % compact(shaper_name)]
1135     shaper_api1_colorspace.equality_group = shaper_api1_name
1136     shaper_api1_colorspace.family = log2_shaper_colorspace.family
1137     shaper_api1_colorspace.is_data = log2_shaper_colorspace.is_data
1138     shaper_api1_colorspace.to_reference_transforms = list(
1139         log2_shaper_api1_colorspace.to_reference_transforms)
1140     shaper_api1_colorspace.from_reference_transforms = list(
1141         log2_shaper_api1_colorspace.from_reference_transforms)
1142     colorspaces.append(shaper_api1_colorspace)
1143
1144     # Define the base *Dolby PQ Shaper*
1145     #
1146     dolbypq_shaper_name = 'Dolby PQ 10000'
1147     dolbypq_shaper_name_aliases = ['crv_%s' % 'dolbypq_10000']
1148
1149     dolbypq_shaper_colorspace = create_Dolby_PQ(
1150         aces_ctl_directory,
1151         lut_directory,
1152         lut_resolution_1d,
1153         cleanup,
1154         name=dolbypq_shaper_name,
1155         aliases=dolbypq_shaper_name_aliases)
1156     colorspaces.append(dolbypq_shaper_colorspace)
1157
1158     # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1159     dolbypq_shaper_data = [
1160         dolbypq_shaper_name,
1161         os.path.join('%s',
1162                      'utilities',
1163                      'ACESlib.DolbyPQ_to_Lin.a1.0.0.ctl'),
1164         os.path.join('%s',
1165                      'utilities',
1166                      'ACESlib.Lin_to_DolbyPQ.a1.0.0.ctl'),
1167         1.0,
1168         {}]
1169
1170     shaper_data[dolbypq_shaper_name] = dolbypq_shaper_data
1171
1172     # Define the *Dolby PQ Shaper that considers a fixed linear range*
1173     #
1174     dolbypq_scaled_shaper_name = 'Dolby PQ Scaled'
1175     dolbypq_scaled_shaper_name_aliases = ['crv_%s' % 'dolbypq_scaled']
1176
1177     dolbypq_scaled_shaper_colorspace = create_Dolby_PQ_scaled(
1178         aces_ctl_directory,
1179         lut_directory,
1180         lut_resolution_1d,
1181         cleanup,
1182         name=dolbypq_scaled_shaper_name,
1183         aliases=dolbypq_scaled_shaper_name_aliases)
1184     colorspaces.append(dolbypq_scaled_shaper_colorspace)
1185
1186     # *Dolby PQ* shaper name and *CTL* transforms bundled up.
1187     dolbypq_scaled_shaper_data = [
1188         dolbypq_scaled_shaper_name,
1189         os.path.join('%s',
1190                      'utilities',
1191                      'ACESlib.DolbyPQ_to_Lin_param.a1.0.0.ctl'),
1192         os.path.join('%s',
1193                      'utilities',
1194                      'ACESlib.Lin_to_DolbyPQ_param.a1.0.0.ctl'),
1195         1.0,
1196         log2_params]
1197
1198     shaper_data[dolbypq_scaled_shaper_name] = dolbypq_scaled_shaper_data
1199
1200     #
1201     # Pick a specific shaper
1202     #
1203     rrt_shaper = log2_shaper_data
1204     # rrt_shaper = dolbypq_scaled_shaper_data
1205
1206     # *RRT + ODT* combinations.
1207     sorted_odts = sorted(odt_info.iteritems(), key=lambda x: x[1])
1208     print(sorted_odts)
1209     for odt in sorted_odts:
1210         (odt_name, odt_values) = odt
1211
1212         # Generating only full range transform for *ODTs* that can generate 
1213         # either *legal* or *full* output.
1214
1215         # Uncomment these lines and the lower section and
1216         # flip the 'legalRange' value to 1 to recover the old behavior,
1217         # where both legal and full range LUTs were generated.
1218         if odt_values['transformHasFullLegalSwitch']:
1219             # odt_name_legal = '%s - Legal' % odt_values['transformUserName']
1220             odt_legal['legalRange'] = 0
1221         # else:
1222         #    odt_name_legal = odt_values['transformUserName']
1223
1224         odt_name_legal = odt_values['transformUserName']
1225
1226         odt_legal = odt_values.copy()
1227
1228         odt_aliases = ['out_%s' % compact(odt_name_legal)]
1229
1230         cs = create_ACES_RRT_plus_ODT(
1231             odt_name_legal,
1232             odt_legal,
1233             rrt_shaper,
1234             aces_ctl_directory,
1235             lut_directory,
1236             lut_resolution_1d,
1237             lut_resolution_3d,
1238             cleanup,
1239             odt_aliases)
1240         colorspaces.append(cs)
1241
1242         displays[odt_name_legal] = {
1243             'Raw': linear_display_space,
1244             'Log': log_display_space,
1245             'Output Transform': cs}
1246
1247         """
1248         # Generating full range transform for *ODTs* that can generate 
1249         # either *legal* or *full* output.
1250         if odt_values['transformHasFullLegalSwitch']:
1251             print('Generating full range ODT for %s' % odt_name)
1252
1253             odt_name_full = '%s - Full' % odt_values['transformUserName']
1254             odt_full = odt_values.copy()
1255             odt_full['legalRange'] = 0
1256
1257             odt_full_aliases = ['out_%s' % compact(odt_name_full)]
1258
1259             cs_full = create_ACES_RRT_plus_ODT(
1260                 odt_name_full,
1261                 odt_full,
1262                 rrt_shaper,
1263                 aces_ctl_directory,
1264                 lut_directory,
1265                 lut_resolution_1d,
1266                 lut_resolution_3d,
1267                 cleanup,
1268                 odt_full_aliases)
1269             colorspaces.append(cs_full)
1270
1271             displays[odt_name_full] = {
1272                 'Raw': linear_display_space,
1273                 'Log': log_display_space,
1274                 'Output Transform': cs_full}
1275         """
1276
1277     return colorspaces, displays
1278
1279
1280 def get_transform_info(ctl_transform):
1281     """
1282     Object description.
1283
1284     Parameters
1285     ----------
1286     parameter : type
1287         Parameter description.
1288
1289     Returns
1290     -------
1291     type
1292          Return value description.
1293     """
1294
1295     with open(ctl_transform, 'rb') as fp:
1296         lines = fp.readlines()
1297
1298     # Retrieving the *transform ID* and *User Name*.
1299     transform_id = lines[1][3:].split('<')[1].split('>')[1].strip()
1300     transform_user_name = '-'.join(
1301         lines[2][3:].split('<')[1].split('>')[1].split('-')[1:]).strip()
1302     transform_user_name_prefix = (
1303         lines[2][3:].split('<')[1].split('>')[1].split('-')[0].strip())
1304
1305     # Figuring out if this transform has options
1306     # for processing full and legal range.
1307     transform_full_legal_switch = False
1308     for line in lines:
1309         if line.strip() == 'input varying int legalRange = 0':
1310             # print( '%s has legal range flag' % transform_user_name)
1311             transform_full_legal_switch = True
1312             break
1313
1314     return (transform_id, transform_user_name, transform_user_name_prefix,
1315             transform_full_legal_switch)
1316
1317
1318 def get_ODTs_info(aces_ctl_directory):
1319     """
1320     Object description.
1321
1322     For versions after WGR9.
1323
1324     Parameters
1325     ----------
1326     parameter : type
1327         Parameter description.
1328
1329     Returns
1330     -------
1331     type
1332          Return value description.
1333     """
1334
1335     # TODO: Investigate usage of *files_walker* definition here.
1336     # Credit to *Alex Fry* for the original approach here.
1337     odt_dir = os.path.join(aces_ctl_directory, 'odt')
1338     all_odt = []
1339     for dir_name, subdir_list, file_list in os.walk(odt_dir):
1340         for fname in file_list:
1341             all_odt.append((os.path.join(dir_name, fname)))
1342
1343     odt_ctls = [x for x in all_odt if
1344                 ('InvODT' not in x) and (os.path.split(x)[-1][0] != '.')]
1345
1346     odts = {}
1347
1348     for odt_ctl in odt_ctls:
1349         odt_tokens = os.path.split(odt_ctl)
1350
1351         # Handling nested directories.
1352         odt_path_tokens = os.path.split(odt_tokens[-2])
1353         odt_dir = odt_path_tokens[-1]
1354         while odt_path_tokens[-2][-3:] != 'odt':
1355             odt_path_tokens = os.path.split(odt_path_tokens[-2])
1356             odt_dir = os.path.join(odt_path_tokens[-1], odt_dir)
1357
1358         # Building full name,
1359         transform_ctl = odt_tokens[-1]
1360         odt_name = string.join(transform_ctl.split('.')[1:-1], '.')
1361
1362         # Finding id, user name and user name prefix.
1363         (transform_id,
1364          transform_user_name,
1365          transform_user_name_prefix,
1366          transform_full_legal_switch) = get_transform_info(
1367             os.path.join(aces_ctl_directory, 'odt', odt_dir, transform_ctl))
1368
1369         # Finding inverse.
1370         transform_ctl_inverse = 'InvODT.%s.ctl' % odt_name
1371         if not os.path.exists(
1372                 os.path.join(odt_tokens[-2], transform_ctl_inverse)):
1373             transform_ctl_inverse = None
1374
1375         # Add to list of ODTs
1376         odts[odt_name] = {}
1377         odts[odt_name]['transformCTL'] = os.path.join(odt_dir, transform_ctl)
1378         if transform_ctl_inverse is not None:
1379             odts[odt_name]['transformCTLInverse'] = os.path.join(
1380                 odt_dir, transform_ctl_inverse)
1381
1382         odts[odt_name]['transformID'] = transform_id
1383         odts[odt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1384         odts[odt_name]['transformUserName'] = transform_user_name
1385         odts[odt_name][
1386             'transformHasFullLegalSwitch'] = transform_full_legal_switch
1387
1388         forward_ctl = odts[odt_name]['transformCTL']
1389
1390         print('ODT : %s' % odt_name)
1391         print('\tTransform ID               : %s' % transform_id)
1392         print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1393         print('\tTransform User Name        : %s' % transform_user_name)
1394         print(
1395             '\tHas Full / Legal Switch    : %s' % transform_full_legal_switch)
1396         print('\tForward ctl                : %s' % forward_ctl)
1397         if 'transformCTLInverse' in odts[odt_name]:
1398             inverse_ctl = odts[odt_name]['transformCTLInverse']
1399             print('\tInverse ctl                : %s' % inverse_ctl)
1400         else:
1401             print('\tInverse ctl                : %s' % 'None')
1402
1403     print('\n')
1404
1405     return odts
1406
1407
1408 def get_LMTs_info(aces_ctl_directory):
1409     """
1410     Object description.
1411
1412     For versions after WGR9.
1413
1414     Parameters
1415     ----------
1416     parameter : type
1417         Parameter description.
1418
1419     Returns
1420     -------
1421     type
1422          Return value description.
1423     """
1424
1425     # TODO: Investigate refactoring with previous definition.
1426
1427     # Credit to Alex Fry for the original approach here
1428     lmt_dir = os.path.join(aces_ctl_directory, 'lmt')
1429     all_lmt = []
1430     for dir_name, subdir_list, file_list in os.walk(lmt_dir):
1431         for fname in file_list:
1432             all_lmt.append((os.path.join(dir_name, fname)))
1433
1434     lmt_ctls = [x for x in all_lmt if
1435                 ('InvLMT' not in x) and ('README' not in x) and (
1436                     os.path.split(x)[-1][0] != '.')]
1437
1438     lmts = {}
1439
1440     for lmt_ctl in lmt_ctls:
1441         lmt_tokens = os.path.split(lmt_ctl)
1442
1443         # Handlimg nested directories.
1444         lmt_path_tokens = os.path.split(lmt_tokens[-2])
1445         lmt_dir = lmt_path_tokens[-1]
1446         while lmt_path_tokens[-2][-3:] != 'ctl':
1447             lmt_path_tokens = os.path.split(lmt_path_tokens[-2])
1448             lmt_dir = os.path.join(lmt_path_tokens[-1], lmt_dir)
1449
1450         # Building full name.
1451         transform_CTL = lmt_tokens[-1]
1452         lmt_name = string.join(transform_CTL.split('.')[1:-1], '.')
1453
1454         # Finding id, user name and user name prefix.
1455         (transform_id,
1456          transform_user_name,
1457          transform_user_name_prefix,
1458          transform_full_legal_switch) = get_transform_info(
1459             os.path.join(aces_ctl_directory, lmt_dir, transform_CTL))
1460
1461         # Finding inverse.
1462         transform_ctl_inverse = 'InvLMT.%s.ctl' % lmt_name
1463         if not os.path.exists(
1464                 os.path.join(lmt_tokens[-2], transform_ctl_inverse)):
1465             transform_ctl_inverse = None
1466
1467         lmts[lmt_name] = {}
1468         lmts[lmt_name]['transformCTL'] = os.path.join(lmt_dir, transform_CTL)
1469         if transform_ctl_inverse is not None:
1470             lmts[lmt_name]['transformCTLInverse'] = os.path.join(
1471                 lmt_dir, transform_ctl_inverse)
1472
1473         lmts[lmt_name]['transformID'] = transform_id
1474         lmts[lmt_name]['transformUserNamePrefix'] = transform_user_name_prefix
1475         lmts[lmt_name]['transformUserName'] = transform_user_name
1476
1477         forward_ctl = lmts[lmt_name]['transformCTL']
1478
1479         print('LMT : %s' % lmt_name)
1480         print('\tTransform ID               : %s' % transform_id)
1481         print('\tTransform User Name Prefix : %s' % transform_user_name_prefix)
1482         print('\tTransform User Name        : %s' % transform_user_name)
1483         print('\t Forward ctl               : %s' % forward_ctl)
1484         if 'transformCTLInverse' in lmts[lmt_name]:
1485             inverse_ctl = lmts[lmt_name]['transformCTLInverse']
1486             print('\t Inverse ctl                : %s' % inverse_ctl)
1487         else:
1488             print('\t Inverse ctl                : %s' % 'None')
1489
1490     print('\n')
1491
1492     return lmts
1493
1494
1495 def create_colorspaces(aces_ctl_directory,
1496                        lut_directory,
1497                        lut_resolution_1d,
1498                        lut_resolution_3d,
1499                        lmt_info,
1500                        odt_info,
1501                        shaper_name,
1502                        cleanup):
1503     """
1504     Generates the colorspace conversions.
1505
1506     Parameters
1507     ----------
1508     parameter : type
1509         Parameter description.
1510
1511     Returns
1512     -------
1513     type
1514          Return value description.
1515     """
1516
1517     colorspaces = []
1518
1519     ACES = create_ACES()
1520
1521     ACEScc = create_ACEScc(aces_ctl_directory, lut_directory,
1522                            lut_resolution_1d, cleanup,
1523                            min_value=-0.35840, max_value=1.468)
1524     colorspaces.append(ACEScc)
1525
1526     ACESproxy = create_ACESproxy(aces_ctl_directory, lut_directory,
1527                                  lut_resolution_1d, cleanup)
1528     colorspaces.append(ACESproxy)
1529
1530     ACEScg = create_ACEScg(aces_ctl_directory, lut_directory,
1531                            lut_resolution_1d, cleanup)
1532     colorspaces.append(ACEScg)
1533
1534     ADX10 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=10)
1535     colorspaces.append(ADX10)
1536
1537     ADX16 = create_ADX(lut_directory, lut_resolution_1d, bit_depth=16)
1538     colorspaces.append(ADX16)
1539
1540     lmts = create_LMTs(aces_ctl_directory,
1541                        lut_directory,
1542                        lut_resolution_1d,
1543                        lut_resolution_3d,
1544                        lmt_info,
1545                        shaper_name,
1546                        cleanup)
1547     colorspaces.extend(lmts)
1548
1549     odts, displays = create_ODTs(aces_ctl_directory,
1550                                  lut_directory,
1551                                  lut_resolution_1d,
1552                                  lut_resolution_3d,
1553                                  odt_info,
1554                                  shaper_name,
1555                                  cleanup,
1556                                  ACES,
1557                                  ACEScc)
1558     colorspaces.extend(odts)
1559
1560     # Wish there was an automatic way to get this from the CTL
1561     default_display = 'sRGB (D60 sim.)'
1562
1563     roles = {'color_picking': ACEScg.name,
1564              'color_timing': ACEScc.name,
1565              'compositing_log': ACEScc.name,
1566              'data': '',
1567              'default': ACES.name,
1568              'matte_paint': ACEScc.name,
1569              'reference': '',
1570              'scene_linear': ACEScg.name,
1571              'texture_paint': ''}
1572
1573     return ACES, colorspaces, displays, ACEScc, roles, default_display