Removed Rec.2020 12 bit curve and colorspace to simplify matters.
[OpenColorIO-Configs.git] / aces_1.0.0 / python / aces_ocio / aces_config.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """
5 Defines objects creating the *ACES* configuration.
6 """
7
8 from __future__ import division
9
10 import os
11 import sys
12
13 import PyOpenColorIO as ocio
14 from aces_ocio.colorspaces import aces
15 from aces_ocio.colorspaces import arri
16 from aces_ocio.colorspaces import canon
17 from aces_ocio.colorspaces import general
18 from aces_ocio.colorspaces import gopro
19 from aces_ocio.colorspaces import panasonic
20 from aces_ocio.colorspaces import red
21 from aces_ocio.colorspaces import sony
22 from aces_ocio.process import Process
23
24
25 __author__ = 'ACES Developers'
26 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
27 __license__ = ''
28 __maintainer__ = 'ACES Developers'
29 __email__ = 'aces@oscars.org'
30 __status__ = 'Production'
31
32 __all__ = ['ACES_OCIO_CTL_DIRECTORY_ENVIRON',
33            'ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON',
34            'set_config_default_roles',
35            'write_config',
36            'generate_OCIO_transform',
37            'add_colorspace_alias',
38            'create_config',
39            'generate_LUTs',
40            'generate_baked_LUTs',
41            'create_config_dir',
42            'create_ACES_config',
43            'main']
44
45 ACES_OCIO_CTL_DIRECTORY_ENVIRON = 'ACES_OCIO_CTL_DIRECTORY'
46 ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON = 'ACES_OCIO_CONFIGURATION_DIRECTORY'
47
48
49 def set_config_default_roles(config,
50                              color_picking='',
51                              color_timing='',
52                              compositing_log='',
53                              data='',
54                              default='',
55                              matte_paint='',
56                              reference='',
57                              scene_linear='',
58                              texture_paint='',
59                              rendering='',
60                              compositing_linear=''):
61     """
62     Sets given *OCIO* configuration default roles.
63
64     Parameters
65     ----------
66     config : config
67         *OCIO* configuration.
68     color_picking : str or unicode
69         Color picking role title.
70     color_timing : str or unicode
71         Color timing role title.
72     compositing_log : str or unicode
73         Compositing log role title.
74     data : str or unicode
75         Data role title.
76     default : str or unicode
77         Default role title.
78     matte_paint : str or unicode
79         Matte painting role title.
80     reference : str or unicode
81         Reference role title.
82     scene_linear : str or unicode
83         Scene linear role title.
84     texture_paint : str or unicode
85         Texture painting role title.
86
87     Returns
88     -------
89     bool
90          Definition success.
91     """
92
93     if color_picking:
94         config.setRole(ocio.Constants.ROLE_COLOR_PICKING, color_picking)
95     if color_timing:
96         config.setRole(ocio.Constants.ROLE_COLOR_TIMING, color_timing)
97     if compositing_log:
98         config.setRole(ocio.Constants.ROLE_COMPOSITING_LOG, compositing_log)
99     if data:
100         config.setRole(ocio.Constants.ROLE_DATA, data)
101     if default:
102         config.setRole(ocio.Constants.ROLE_DEFAULT, default)
103     if matte_paint:
104         config.setRole(ocio.Constants.ROLE_MATTE_PAINT, matte_paint)
105     if reference:
106         config.setRole(ocio.Constants.ROLE_REFERENCE, reference)
107     if texture_paint:
108         config.setRole(ocio.Constants.ROLE_TEXTURE_PAINT, texture_paint)
109
110     # 'rendering' and 'compositing_linear' roles default to the 'scene_linear'
111     # value if not set explicitly
112     if rendering:
113         config.setRole("rendering", rendering)
114     if compositing_linear:
115         config.setRole("compositing_linear", compositing_linear)
116     if scene_linear:
117         config.setRole(ocio.Constants.ROLE_SCENE_LINEAR, scene_linear)
118         if not rendering:
119             config.setRole("rendering", scene_linear)
120         if not compositing_linear:
121             config.setRole("compositing_linear", scene_linear)
122
123     return True
124
125
126 def write_config(config, config_path, sanity_check=True):
127     """
128     Writes the configuration to given path.
129
130     Parameters
131     ----------
132     parameter : type
133         Parameter description.
134
135     Returns
136     -------
137     type
138          Return value description.
139     """
140
141     if sanity_check:
142         try:
143             config.sanityCheck()
144         except Exception, e:
145             print e
146             print 'Configuration was not written due to a failed Sanity Check'
147             return
148
149     with open(config_path, mode='w') as fp:
150         fp.write(config.serialize())
151
152
153 def generate_OCIO_transform(transforms):
154     """
155     Object description.
156
157     Parameters
158     ----------
159     parameter : type
160         Parameter description.
161
162     Returns
163     -------
164     type
165          Return value description.
166     """
167
168     interpolation_options = {
169         'linear': ocio.Constants.INTERP_LINEAR,
170         'nearest': ocio.Constants.INTERP_NEAREST,
171         'tetrahedral': ocio.Constants.INTERP_TETRAHEDRAL}
172
173     direction_options = {
174         'forward': ocio.Constants.TRANSFORM_DIR_FORWARD,
175         'inverse': ocio.Constants.TRANSFORM_DIR_INVERSE}
176
177     ocio_transforms = []
178
179     for transform in transforms:
180
181         # lutFile transform
182         if transform['type'] == 'lutFile':
183             ocio_transform = ocio.FileTransform(
184                 src=transform['path'],
185                 interpolation=interpolation_options[
186                     transform['interpolation']],
187                 direction=direction_options[transform['direction']])
188             ocio_transforms.append(ocio_transform)
189
190         # matrix transform
191         elif transform['type'] == 'matrix':
192             ocio_transform = ocio.MatrixTransform()
193             # MatrixTransform member variables can't be initialized directly.
194             # Each must be set individually.
195             ocio_transform.setMatrix(transform['matrix'])
196
197             if 'offset' in transform:
198                 ocio_transform.setOffset(transform['offset'])
199
200             if 'direction' in transform:
201                 ocio_transform.setDirection(
202                     direction_options[transform['direction']])
203
204             ocio_transforms.append(ocio_transform)
205
206         # exponent transform
207         elif transform['type'] == 'exponent':
208             ocio_transform = ocio.ExponentTransform()
209             ocio_transform.setValue(transform['value'])
210             ocio_transforms.append(ocio_transform)
211
212         # log transform
213         elif transform['type'] == 'log':
214             ocio_transform = ocio.LogTransform(
215                 base=transform['base'],
216                 direction=direction_options[transform['direction']])
217
218             ocio_transforms.append(ocio_transform)
219
220         # color space transform
221         elif transform['type'] == 'colorspace':
222             ocio_transform = ocio.ColorSpaceTransform(src=transform['src'],
223                                                       dst=transform['dst'],
224                                                       direction=
225                                                       direction_options[
226                                                           'forward'])
227             ocio_transforms.append(ocio_transform)
228         # unknown type
229         else:
230             print("Ignoring unknown transform type : %s" % transform['type'])
231
232     if len(ocio_transforms) > 1:
233         group_transform = ocio.GroupTransform()
234         for transform in ocio_transforms:
235             group_transform.push_back(transform)
236         transform = group_transform
237     else:
238         transform = ocio_transforms[0]
239
240     return transform
241
242
243 def add_colorspace_alias(config,
244                          reference_colorspace,
245                          colorspace,
246                          colorspace_alias_names):
247     """
248     Object description.
249
250     Parameters
251     ----------
252     parameter : type
253         Parameter description.
254
255     Returns
256     -------
257     type
258          Return value description.
259     """
260
261     for alias_name in colorspace_alias_names:
262         if alias_name.lower() == colorspace.name.lower():
263             print('Skipping alias creation for %s, alias %s, because lower cased names match' % (
264                 colorspace.name, alias_name) )
265             return
266
267         print('Adding alias colorspace space %s, alias to %s' % (
268             alias_name, colorspace.name))
269
270         compact_family_name = 'Aliases'
271
272         ocio_colorspace_alias = ocio.ColorSpace(
273             name=alias_name,
274             bitDepth=colorspace.bit_depth,
275             description=colorspace.description,
276             equalityGroup=colorspace.equality_group,
277             family=compact_family_name,
278             isData=colorspace.is_data,
279             allocation=colorspace.allocation_type,
280             allocationVars=colorspace.allocation_vars)
281
282         if colorspace.to_reference_transforms:
283             print('Generating To-Reference transforms')
284             ocio_transform = generate_OCIO_transform(
285                 [{'type': 'colorspace',
286                   'src': colorspace.name,
287                   'dst': reference_colorspace.name,
288                   'direction': 'forward'}])
289             ocio_colorspace_alias.setTransform(
290                 ocio_transform,
291                 ocio.Constants.COLORSPACE_DIR_TO_REFERENCE)
292
293         if colorspace.from_reference_transforms:
294             print('Generating From-Reference transforms')
295             ocio_transform = generate_OCIO_transform(
296                 [{'type': 'colorspace',
297                   'src': reference_colorspace.name,
298                   'dst': colorspace.name,
299                   'direction': 'forward'}])
300             ocio_colorspace_alias.setTransform(
301                 ocio_transform,
302                 ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE)
303
304         config.addColorSpace(ocio_colorspace_alias)
305
306
307 def create_config(config_data, gui=False):
308     """
309     Object description.
310
311     Parameters
312     ----------
313     parameter : type
314         Parameter description.
315
316     Returns
317     -------
318     type
319          Return value description.
320     """
321
322     # Creating the *OCIO* configuration.
323     config = ocio.Config()
324
325     # Setting configuration overall values.
326     config.setDescription('An ACES config generated from python')
327     config.setSearchPath('luts')
328
329     # Defining the reference colorspace.
330     reference_data = config_data['referenceColorSpace']
331     print('Adding the reference color space : %s' % reference_data.name)
332
333     reference = ocio.ColorSpace(
334         name=reference_data.name,
335         bitDepth=reference_data.bit_depth,
336         description=reference_data.description,
337         equalityGroup=reference_data.equality_group,
338         family=reference_data.family,
339         isData=reference_data.is_data,
340         allocation=reference_data.allocation_type,
341         allocationVars=reference_data.allocation_vars)
342
343     config.addColorSpace(reference)
344
345     # Add alias
346     #if not gui:
347     if reference_data.aliases != []:
348         add_colorspace_alias(config, reference_data,
349                              reference_data, reference_data.aliases)
350
351     print("")
352
353     #print( "color spaces : %s" % [x.name for x in sorted(config_data['colorSpaces'])])
354
355     # Creating the remaining colorspaces.
356     for colorspace in sorted(config_data['colorSpaces']):
357         print('Creating new color space : %s' % colorspace.name)
358
359         ocio_colorspace = ocio.ColorSpace(
360             name=colorspace.name,
361             bitDepth=colorspace.bit_depth,
362             description=colorspace.description,
363             equalityGroup=colorspace.equality_group,
364             family=colorspace.family,
365             isData=colorspace.is_data,
366             allocation=colorspace.allocation_type,
367             allocationVars=colorspace.allocation_vars)
368
369         if colorspace.to_reference_transforms:
370             print('Generating To-Reference transforms')
371             ocio_transform = generate_OCIO_transform(
372                 colorspace.to_reference_transforms)
373             ocio_colorspace.setTransform(
374                 ocio_transform,
375                 ocio.Constants.COLORSPACE_DIR_TO_REFERENCE)
376
377         if colorspace.from_reference_transforms:
378             print('Generating From-Reference transforms')
379             ocio_transform = generate_OCIO_transform(
380                 colorspace.from_reference_transforms)
381             ocio_colorspace.setTransform(
382                 ocio_transform,
383                 ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE)
384
385         config.addColorSpace(ocio_colorspace)
386
387         #
388         # Add alias to normal colorspace, using compact name
389         #
390         #if not gui:
391         if colorspace.aliases != []:
392             #print('Adding alias color spaces : %s' % colorspace.aliases)
393             add_colorspace_alias(config, reference_data,
394                                  colorspace, colorspace.aliases)
395
396         print('')
397
398     # Defining the *views* and *displays*.
399     displays = []
400     views = []
401
402     # Defining a *generic* *display* and *view* setup.
403     if not gui:
404         for display, view_list in config_data['displays'].iteritems():
405             for view_name, colorspace in view_list.iteritems():
406                 config.addDisplay(display, view_name, colorspace.name)
407                 if not (view_name in views):
408                     views.append(view_name)
409             displays.append(display)
410
411     # Defining the set of *views* and *displays* useful in a *GUI* context.
412     else:
413         display_name = 'ACES'
414         displays.append(display_name)
415
416         display_names = sorted(config_data['displays'])
417
418         # Make sure the default display is first
419         default_display = config_data['defaultDisplay']
420         display_names.insert(0, display_names.pop(display_names.index(default_display)))
421
422         for display in display_names:
423             view_list = config_data['displays'][display]
424             for view_name, colorspace in view_list.iteritems():
425                 if view_name == 'Output Transform':
426                     config.addDisplay(display_name, display, colorspace.name)
427                     if not (display in views):
428                         views.append(display)
429
430         # Works with Nuke Studio and Mari, but not Nuke
431         # display_name = 'Utility'
432         # displays.append(display_name)
433
434         linear_display_space_name = config_data['roles']['scene_linear']
435         log_display_space_name = config_data['roles']['compositing_log']
436
437         config.addDisplay(display_name, 'Linear', linear_display_space_name)
438         views.append('Linear')
439         config.addDisplay(display_name, 'Log', log_display_space_name)
440         views.append('Log')
441
442     # Setting the active *displays* and *views*.
443     config.setActiveDisplays(','.join(sorted(displays)))
444     config.setActiveViews(','.join(views))
445
446     set_config_default_roles(
447         config,
448         color_picking=config_data['roles']['color_picking'],
449         color_timing=config_data['roles']['color_timing'],
450         compositing_log=config_data['roles']['compositing_log'],
451         data=config_data['roles']['data'],
452         default=config_data['roles']['default'],
453         matte_paint=config_data['roles']['matte_paint'],
454         reference=config_data['roles']['reference'],
455         scene_linear=config_data['roles']['scene_linear'],
456         texture_paint=config_data['roles']['texture_paint'])
457
458     config.sanityCheck()
459
460     return config
461
462
463 def generate_LUTs(odt_info,
464                   lmt_info,
465                   shaper_name,
466                   aces_ctl_directory,
467                   lut_directory,
468                   lut_resolution_1d=4096,
469                   lut_resolution_3d=64,
470                   cleanup=True):
471     """
472     Object description.
473
474     Parameters
475     ----------
476     parameter : type
477         Parameter description.
478
479     Returns
480     -------
481     dict
482          Colorspaces and transforms converting between those colorspaces and
483          the reference colorspace, *ACES*.
484     """
485
486     print('generateLUTs - begin')
487     config_data = {}
488
489     # Initialize a few variables
490     config_data['displays'] = {}
491     config_data['colorSpaces'] = []
492
493     # -------------------------------------------------------------------------
494     # *ACES Color Spaces*
495     # -------------------------------------------------------------------------
496
497     # *ACES* colorspaces
498     (aces_reference,
499      aces_colorspaces,
500      aces_displays,
501      aces_log_display_space,
502      aces_roles,
503      aces_default_display) = aces.create_colorspaces(aces_ctl_directory,
504                                                      lut_directory,
505                                                      lut_resolution_1d,
506                                                      lut_resolution_3d,
507                                                      lmt_info,
508                                                      odt_info,
509                                                      shaper_name,
510                                                      cleanup)
511
512     config_data['referenceColorSpace'] = aces_reference
513     config_data['roles'] = aces_roles
514
515     for cs in aces_colorspaces:
516         config_data['colorSpaces'].append(cs)
517
518     for name, data in aces_displays.iteritems():
519         config_data['displays'][name] = data
520
521     config_data['defaultDisplay'] = aces_default_display
522     config_data['linearDisplaySpace'] = aces_reference
523     config_data['logDisplaySpace'] = aces_log_display_space
524
525     # -------------------------------------------------------------------------
526     # *Camera Input Transforms*
527     # -------------------------------------------------------------------------
528
529     # *ARRI Log-C* to *ACES*.
530     arri_colorSpaces = arri.create_colorspaces(lut_directory,
531                                                lut_resolution_1d)
532     for cs in arri_colorSpaces:
533         config_data['colorSpaces'].append(cs)
534
535     # *Canon-Log* to *ACES*.
536     canon_colorspaces = canon.create_colorspaces(lut_directory,
537                                                  lut_resolution_1d)
538     for cs in canon_colorspaces:
539         config_data['colorSpaces'].append(cs)
540
541     # *GoPro Protune* to *ACES*.
542     gopro_colorspaces = gopro.create_colorspaces(lut_directory,
543                                                  lut_resolution_1d)
544     for cs in gopro_colorspaces:
545         config_data['colorSpaces'].append(cs)
546
547     # *Panasonic V-Log* to *ACES*.
548     panasonic_colorSpaces = panasonic.create_colorspaces(lut_directory,
549                                                          lut_resolution_1d)
550     for cs in panasonic_colorSpaces:
551         config_data['colorSpaces'].append(cs)
552
553     # *RED* colorspaces to *ACES*.
554     red_colorspaces = red.create_colorspaces(lut_directory,
555                                              lut_resolution_1d)
556     for cs in red_colorspaces:
557         config_data['colorSpaces'].append(cs)
558
559     # *S-Log* to *ACES*.
560     sony_colorSpaces = sony.create_colorspaces(lut_directory,
561                                                lut_resolution_1d)
562     for cs in sony_colorSpaces:
563         config_data['colorSpaces'].append(cs)
564
565     # -------------------------------------------------------------------------
566     # General Color Spaces
567     # -------------------------------------------------------------------------
568     general_colorSpaces = general.create_colorspaces(lut_directory,
569                                                      lut_resolution_1d,
570                                                      lut_resolution_3d)
571     for cs in general_colorSpaces:
572         config_data['colorSpaces'].append(cs)
573
574     # The *Raw* color space
575     raw = general.create_raw()
576     config_data['colorSpaces'].append(raw)
577
578     # Override certain roles, for now
579     config_data['roles']['data'] = raw.name
580     config_data['roles']['reference'] = raw.name
581     config_data['roles']['texture_paint'] = raw.name
582
583     print('generateLUTs - end')
584     return config_data
585
586
587 def generate_baked_LUTs(odt_info,
588                         shaper_name,
589                         baked_directory,
590                         config_path,
591                         lut_resolution_1d,
592                         lut_resolution_3d,
593                         lut_resolution_shaper=1024):
594     """
595     Object description.
596
597     Parameters
598     ----------
599     parameter : type
600         Parameter description.
601
602     Returns
603     -------
604     type
605          Return value description.
606     """
607
608     # Create two entries for ODTs that have full and legal range support
609     odt_info_C = dict(odt_info)
610     for odt_ctl_name, odt_values in odt_info.iteritems():
611         if odt_values['transformHasFullLegalSwitch']:
612             odt_name = odt_values['transformUserName']
613
614             odt_values_legal = dict(odt_values)
615             odt_values_legal['transformUserName'] = '%s - Legal' % odt_name
616             odt_info_C['%s - Legal' % odt_ctl_name] = odt_values_legal
617
618             odt_values_full = dict(odt_values)
619             odt_values_full['transformUserName'] = '%s - Full' % odt_name
620             odt_info_C['%s - Full' % odt_ctl_name] = odt_values_full
621
622             del (odt_info_C[odt_ctl_name])
623
624     # Generate appropriate LUTs for each ODT
625     for odt_ctl_name, odt_values in odt_info_C.iteritems():
626         odt_prefix = odt_values['transformUserNamePrefix']
627         odt_name = odt_values['transformUserName']
628
629         # *Photoshop*
630         for input_space in ['ACEScc', 'ACESproxy']:
631             args = ['--iconfig', config_path,
632                     '-v',
633                     '--inputspace', input_space]
634             args += ['--outputspace', '%s' % odt_name]
635             args += ['--description',
636                      '%s - %s for %s data' % (odt_prefix,
637                                               odt_name,
638                                               input_space)]
639             args += ['--shaperspace', shaper_name,
640                      '--shapersize', str(lut_resolution_shaper)]
641             args += ['--cubesize', str(lut_resolution_3d)]
642             args += ['--format',
643                      'icc',
644                      os.path.join(baked_directory,
645                                   'photoshop',
646                                   '%s for %s.icc' % (odt_name, input_space))]
647
648             bake_lut = Process(description='bake a LUT',
649                                cmd='ociobakelut',
650                                args=args)
651             bake_lut.execute()
652
653         # *Flame*, *Lustre*
654         for input_space in ['ACEScc', 'ACESproxy']:
655             args = ['--iconfig', config_path,
656                     '-v',
657                     '--inputspace', input_space]
658             args += ['--outputspace', '%s' % odt_name]
659             args += ['--description',
660                      '%s - %s for %s data' % (
661                          odt_prefix, odt_name, input_space)]
662             args += ['--shaperspace', shaper_name,
663                      '--shapersize', str(lut_resolution_shaper)]
664             args += ['--cubesize', str(lut_resolution_3d)]
665
666             fargs = ['--format',
667                      'flame',
668                      os.path.join(
669                          baked_directory,
670                          'flame',
671                          '%s for %s Flame.3dl' % (odt_name, input_space))]
672             bake_lut = Process(description='bake a LUT',
673                                cmd='ociobakelut',
674                                args=(args + fargs))
675             bake_lut.execute()
676
677             largs = ['--format',
678                      'lustre',
679                      os.path.join(
680                          baked_directory,
681                          'lustre',
682                          '%s for %s Lustre.3dl' % (odt_name, input_space))]
683             bake_lut = Process(description='bake a LUT',
684                                cmd='ociobakelut',
685                                args=(args + largs))
686             bake_lut.execute()
687
688         # *Maya*, *Houdini*
689         for input_space in ['ACEScg', 'ACES2065-1']:
690             args = ['--iconfig', config_path,
691                     '-v',
692                     '--inputspace', input_space]
693             args += ['--outputspace', '%s' % odt_name]
694             args += ['--description',
695                      '%s - %s for %s data' % (
696                          odt_prefix, odt_name, input_space)]
697             if input_space == 'ACEScg':
698                 lin_shaper_name = '%s - AP1' % shaper_name
699             else:
700                 lin_shaper_name = shaper_name
701             args += ['--shaperspace', lin_shaper_name,
702                      '--shapersize', str(lut_resolution_shaper)]
703
704             args += ['--cubesize', str(lut_resolution_3d)]
705
706             margs = ['--format',
707                      'cinespace',
708                      os.path.join(
709                          baked_directory,
710                          'maya',
711                          '%s for %s Maya.csp' % (odt_name, input_space))]
712             bake_lut = Process(description='bake a LUT',
713                                cmd='ociobakelut',
714                                args=(args + margs))
715             bake_lut.execute()
716
717             hargs = ['--format',
718                      'houdini',
719                      os.path.join(
720                          baked_directory,
721                          'houdini',
722                          '%s for %s Houdini.lut' % (odt_name, input_space))]
723             bake_lut = Process(description='bake a LUT',
724                                cmd='ociobakelut',
725                                args=(args + hargs))
726             bake_lut.execute()
727
728
729 def create_config_dir(config_directory, bake_secondary_LUTs):
730     """
731     Object description.
732
733     Parameters
734     ----------
735     parameter : type
736         Parameter description.
737
738     Returns
739     -------
740     type
741          Return value description.
742     """
743
744     lut_directory = os.path.join(config_directory, 'luts')
745     dirs = [config_directory, lut_directory]
746     if bake_secondary_LUTs:
747         dirs.extend([os.path.join(config_directory, 'baked'),
748                      os.path.join(config_directory, 'baked', 'flame'),
749                      os.path.join(config_directory, 'baked', 'photoshop'),
750                      os.path.join(config_directory, 'baked', 'houdini'),
751                      os.path.join(config_directory, 'baked', 'lustre'),
752                      os.path.join(config_directory, 'baked', 'maya')])
753
754     for d in dirs:
755         not os.path.exists(d) and os.mkdir(d)
756
757     return lut_directory
758
759
760 def create_ACES_config(aces_ctl_directory,
761                        config_directory,
762                        lut_resolution_1d=4096,
763                        lut_resolution_3d=64,
764                        bake_secondary_LUTs=True,
765                        cleanup=True):
766     """
767     Creates the ACES configuration.
768
769     Parameters
770     ----------
771     parameter : type
772         Parameter description.
773
774     Returns
775     -------
776     type
777          Return value description.
778     """
779
780     lut_directory = create_config_dir(config_directory, bake_secondary_LUTs)
781
782     odt_info = aces.get_ODTs_info(aces_ctl_directory)
783     lmt_info = aces.get_LMTs_info(aces_ctl_directory)
784
785     shaper_name = 'Output Shaper'
786     config_data = generate_LUTs(odt_info,
787                                 lmt_info,
788                                 shaper_name,
789                                 aces_ctl_directory,
790                                 lut_directory,
791                                 lut_resolution_1d,
792                                 lut_resolution_3d,
793                                 cleanup)
794
795     '''
796     print('Creating "generic" config')
797     config = create_config(config_data)
798     print('\n\n\n')
799
800     write_config(config,
801                  os.path.join(config_directory, 'config.ocio'))
802     '''
803
804     print('Creating "GUI" config')
805     gui_config = create_config(config_data, gui=True)
806     print('\n\n\n')
807
808     write_config(gui_config,
809                  os.path.join(config_directory, 'config.ocio'))
810
811     if bake_secondary_LUTs:
812         generate_baked_LUTs(odt_info,
813                             shaper_name,
814                             os.path.join(config_directory, 'baked'),
815                             os.path.join(config_directory, 'config.ocio'),
816                             lut_resolution_1d,
817                             lut_resolution_3d,
818                             lut_resolution_1d)
819
820     return True
821
822
823 def main():
824     """
825     Object description.
826
827     Parameters
828     ----------
829     parameter : type
830         Parameter description.
831
832     Returns
833     -------
834     type
835          Return value description.
836     """
837
838     import optparse
839
840     p = optparse.OptionParser(description='An OCIO config generation script',
841                               prog='createACESConfig',
842                               version='createACESConfig 0.1',
843                               usage='%prog [options]')
844     p.add_option('--acesCTLDir', '-a', default=os.environ.get(
845         ACES_OCIO_CTL_DIRECTORY_ENVIRON, None))
846     p.add_option('--configDir', '-c', default=os.environ.get(
847         ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON, None))
848     p.add_option('--lutResolution1d', default=4096)
849     p.add_option('--lutResolution3d', default=64)
850     p.add_option('--dontBakeSecondaryLUTs', action='store_true')
851     p.add_option('--keepTempImages', action='store_true')
852
853     options, arguments = p.parse_args()
854
855     aces_ctl_directory = options.acesCTLDir
856     config_directory = options.configDir
857     lut_resolution_1d = int(options.lutResolution1d)
858     lut_resolution_3d = int(options.lutResolution3d)
859     bake_secondary_luts = not options.dontBakeSecondaryLUTs
860     cleanup_temp_images = not options.keepTempImages
861
862     # TODO: Investigate the following statements.
863     try:
864         args_start = sys.argv.index('--') + 1
865         args = sys.argv[args_start:]
866     except:
867         args_start = len(sys.argv) + 1
868         args = []
869
870     print('command line : \n%s\n' % ' '.join(sys.argv))
871
872     assert aces_ctl_directory is not None, (
873         'process: No "{0}" environment variable defined or no "ACES CTL" '
874         'directory specified'.format(
875             ACES_OCIO_CTL_DIRECTORY_ENVIRON))
876
877     assert config_directory is not None, (
878         'process: No "{0}" environment variable defined or no configuration '
879         'directory specified'.format(
880             ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON))
881
882     return create_ACES_config(aces_ctl_directory,
883                               config_directory,
884                               lut_resolution_1d,
885                               lut_resolution_3d,
886                               bake_secondary_luts,
887                               cleanup_temp_images)
888
889
890 if __name__ == '__main__':
891     main()