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