Code formatting.
[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 not nuke:
333         if reference_data.aliases != []:
334             add_colorspace_alias(config, reference_data,
335                                  reference_data, reference_data.aliases)
336
337     print("")
338
339     # Creating the remaining colorspaces.
340     for colorspace in sorted(config_data['colorSpaces']):
341         print('Creating new color space : %s' % colorspace.name)
342
343         ocio_colorspace = ocio.ColorSpace(
344             name=colorspace.name,
345             bitDepth=colorspace.bit_depth,
346             description=colorspace.description,
347             equalityGroup=colorspace.equality_group,
348             family=colorspace.family,
349             isData=colorspace.is_data,
350             allocation=colorspace.allocation_type,
351             allocationVars=colorspace.allocation_vars)
352
353         if colorspace.to_reference_transforms:
354             print('Generating To-Reference transforms')
355             ocio_transform = generate_OCIO_transform(
356                 colorspace.to_reference_transforms)
357             ocio_colorspace.setTransform(
358                 ocio_transform,
359                 ocio.Constants.COLORSPACE_DIR_TO_REFERENCE)
360
361         if colorspace.from_reference_transforms:
362             print('Generating From-Reference transforms')
363             ocio_transform = generate_OCIO_transform(
364                 colorspace.from_reference_transforms)
365             ocio_colorspace.setTransform(
366                 ocio_transform,
367                 ocio.Constants.COLORSPACE_DIR_FROM_REFERENCE)
368
369         config.addColorSpace(ocio_colorspace)
370
371         #
372         # Add alias to normal colorspace, using compact name
373         #
374         if not nuke:
375             if colorspace.aliases != []:
376                 add_colorspace_alias(config, reference_data,
377                                      colorspace, colorspace.aliases)
378
379         print('')
380
381     # Defining the *views* and *displays*.
382     displays = []
383     views = []
384
385     # Defining a *generic* *display* and *view* setup.
386     if not nuke:
387         for display, view_list in config_data['displays'].iteritems():
388             for view_name, colorspace in view_list.iteritems():
389                 config.addDisplay(display, view_name, colorspace.name)
390                 if not (view_name in views):
391                     views.append(view_name)
392             displays.append(display)
393
394     # Defining the *Nuke* specific set of *views* and *displays*.
395     else:
396         display_name = 'ACES'
397         displays.append(display_name)
398
399         display_names = sorted(config_data['displays'])
400         for display in display_names:
401             view_list = config_data['displays'][display]
402             for view_name, colorspace in view_list.iteritems():
403                 if view_name == 'Output Transform':
404                     config.addDisplay(display_name, display, colorspace.name)
405                     if not (display in views):
406                         views.append(display)
407
408         # Works with Nuke Studio and Mari, but not Nuke
409         # display_name = 'Utility'
410         #displays.append(display_name)
411
412         linear_display_space_name = config_data['linearDisplaySpace'].name
413         log_display_space_name = config_data['logDisplaySpace'].name
414
415         config.addDisplay(display_name, 'Linear', linear_display_space_name)
416         views.append('Linear')
417         config.addDisplay(display_name, 'Log', log_display_space_name)
418         views.append('Log')
419
420     # Setting the active *displays* and *views*.
421     config.setActiveDisplays(','.join(sorted(displays)))
422     config.setActiveViews(','.join(views))
423
424     set_config_default_roles(
425         config,
426         color_picking=config_data['roles']['color_picking'],
427         color_timing=config_data['roles']['color_timing'],
428         compositing_log=config_data['roles']['compositing_log'],
429         data=config_data['roles']['data'],
430         default=config_data['roles']['default'],
431         matte_paint=config_data['roles']['matte_paint'],
432         reference=config_data['roles']['reference'],
433         scene_linear=config_data['roles']['scene_linear'],
434         texture_paint=config_data['roles']['texture_paint'])
435
436     config.sanityCheck()
437
438     return config
439
440
441 def generate_LUTs(odt_info,
442                   lmt_info,
443                   shaper_name,
444                   aces_ctl_directory,
445                   lut_directory,
446                   lut_resolution_1d=4096,
447                   lut_resolution_3d=64,
448                   cleanup=True):
449     """
450     Object description.
451
452     Parameters
453     ----------
454     parameter : type
455         Parameter description.
456
457     Returns
458     -------
459     dict
460          Colorspaces and transforms converting between those colorspaces and
461          the reference colorspace, *ACES*.
462     """
463
464     print('generateLUTs - begin')
465     config_data = {}
466
467     # Initialize a few variables
468     config_data['displays'] = {}
469     config_data['colorSpaces'] = []
470
471     # -------------------------------------------------------------------------
472     # *ACES Color Spaces*
473     # -------------------------------------------------------------------------
474
475     # *ACES* colorspaces
476     (aces_reference,
477      aces_colorspaces,
478      aces_displays,
479      aces_log_display_space,
480      aces_roles) = aces.create_colorspaces(aces_ctl_directory,
481                                            lut_directory,
482                                            lut_resolution_1d,
483                                            lut_resolution_3d,
484                                            lmt_info,
485                                            odt_info,
486                                            shaper_name,
487                                            cleanup)
488
489     config_data['referenceColorSpace'] = aces_reference
490     config_data['roles'] = aces_roles
491
492     for cs in aces_colorspaces:
493         config_data['colorSpaces'].append(cs)
494
495     for name, data in aces_displays.iteritems():
496         config_data['displays'][name] = data
497
498     config_data['linearDisplaySpace'] = aces_reference
499     config_data['logDisplaySpace'] = aces_log_display_space
500
501     # -------------------------------------------------------------------------
502     # *Camera Input Transforms*
503     # -------------------------------------------------------------------------
504
505     # *ARRI Log-C* to *ACES*.
506     arri_colorSpaces = arri.create_colorspaces(lut_directory,
507                                                lut_resolution_1d)
508     for cs in arri_colorSpaces:
509         config_data['colorSpaces'].append(cs)
510
511     # *Canon-Log* to *ACES*.
512     canon_colorspaces = canon.create_colorspaces(lut_directory,
513                                                  lut_resolution_1d)
514     for cs in canon_colorspaces:
515         config_data['colorSpaces'].append(cs)
516
517     # *GoPro Protune* to *ACES*.
518     gopro_colorspaces = gopro.create_colorspaces(lut_directory,
519                                                  lut_resolution_1d)
520     for cs in gopro_colorspaces:
521         config_data['colorSpaces'].append(cs)
522
523     # *Panasonic V-Log* to *ACES*.
524     panasonic_colorSpaces = panasonic.create_colorspaces(lut_directory,
525                                                          lut_resolution_1d)
526     for cs in panasonic_colorSpaces:
527         config_data['colorSpaces'].append(cs)
528
529     # *RED* colorspaces to *ACES*.
530     red_colorspaces = red.create_colorspaces(lut_directory,
531                                              lut_resolution_1d)
532     for cs in red_colorspaces:
533         config_data['colorSpaces'].append(cs)
534
535     # *S-Log* to *ACES*.
536     sony_colorSpaces = sony.create_colorspaces(lut_directory,
537                                                lut_resolution_1d)
538     for cs in sony_colorSpaces:
539         config_data['colorSpaces'].append(cs)
540
541     # -------------------------------------------------------------------------
542     # General Color Spaces
543     # -------------------------------------------------------------------------
544     general_colorSpaces = general.create_colorspaces(lut_directory,
545                                                      lut_resolution_1d,
546                                                      lut_resolution_3d)
547     for cs in general_colorSpaces:
548         config_data['colorSpaces'].append(cs)
549
550     # The *Raw* color space
551     raw = general.create_raw()
552     config_data['colorSpaces'].append(raw)
553
554     # Override certain roles, for now
555     config_data['roles']['data'] = raw.name
556     config_data['roles']['reference'] = raw.name
557     config_data['roles']['texture_paint'] = raw.name
558
559     print('generateLUTs - end')
560     return config_data
561
562
563 def generate_baked_LUTs(odt_info,
564                         shaper_name,
565                         baked_directory,
566                         config_path,
567                         lut_resolution_1d,
568                         lut_resolution_3d,
569                         lut_resolution_shaper=1024):
570     """
571     Object description.
572
573     Parameters
574     ----------
575     parameter : type
576         Parameter description.
577
578     Returns
579     -------
580     type
581          Return value description.
582     """
583
584     # Create two entries for ODTs that have full and legal range support
585     odt_info_C = dict(odt_info)
586     for odt_ctl_name, odt_values in odt_info.iteritems():
587         if odt_values['transformHasFullLegalSwitch']:
588             odt_name = odt_values['transformUserName']
589
590             odt_values_legal = dict(odt_values)
591             odt_values_legal['transformUserName'] = '%s - Legal' % odt_name
592             odt_info_C['%s - Legal' % odt_ctl_name] = odt_values_legal
593
594             odt_values_full = dict(odt_values)
595             odt_values_full['transformUserName'] = '%s - Full' % odt_name
596             odt_info_C['%s - Full' % odt_ctl_name] = odt_values_full
597
598             del (odt_info_C[odt_ctl_name])
599
600     # Generate appropriate LUTs for each ODT
601     for odt_ctl_name, odt_values in odt_info_C.iteritems():
602         odt_prefix = odt_values['transformUserNamePrefix']
603         odt_name = odt_values['transformUserName']
604
605         # *Photoshop*
606         for input_space in ['ACEScc', 'ACESproxy']:
607             args = ['--iconfig', config_path,
608                     '-v',
609                     '--inputspace', input_space]
610             args += ['--outputspace', '%s' % odt_name]
611             args += ['--description',
612                      '%s - %s for %s data' % (odt_prefix,
613                                               odt_name,
614                                               input_space)]
615             args += ['--shaperspace', shaper_name,
616                      '--shapersize', str(lut_resolution_shaper)]
617             args += ['--cubesize', str(lut_resolution_3d)]
618             args += ['--format',
619                      'icc',
620                      os.path.join(baked_directory,
621                                   'photoshop',
622                                   '%s for %s.icc' % (odt_name, input_space))]
623
624             bake_lut = Process(description='bake a LUT',
625                                cmd='ociobakelut',
626                                args=args)
627             bake_lut.execute()
628
629         # *Flame*, *Lustre*
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' % (
637                          odt_prefix, odt_name, input_space)]
638             args += ['--shaperspace', shaper_name,
639                      '--shapersize', str(lut_resolution_shaper)]
640             args += ['--cubesize', str(lut_resolution_3d)]
641
642             fargs = ['--format',
643                      'flame',
644                      os.path.join(
645                          baked_directory,
646                          'flame',
647                          '%s for %s Flame.3dl' % (odt_name, input_space))]
648             bake_lut = Process(description='bake a LUT',
649                                cmd='ociobakelut',
650                                args=(args + fargs))
651             bake_lut.execute()
652
653             largs = ['--format',
654                      'lustre',
655                      os.path.join(
656                          baked_directory,
657                          'lustre',
658                          '%s for %s Lustre.3dl' % (odt_name, input_space))]
659             bake_lut = Process(description='bake a LUT',
660                                cmd='ociobakelut',
661                                args=(args + largs))
662             bake_lut.execute()
663
664         # *Maya*, *Houdini*
665         for input_space in ['ACEScg', 'ACES2065-1']:
666             args = ['--iconfig', config_path,
667                     '-v',
668                     '--inputspace', input_space]
669             args += ['--outputspace', '%s' % odt_name]
670             args += ['--description',
671                      '%s - %s for %s data' % (
672                          odt_prefix, odt_name, input_space)]
673             if input_space == 'ACEScg':
674                 lin_shaper_name = '%s - AP1' % shaper_name
675             else:
676                 lin_shaper_name = shaper_name
677             args += ['--shaperspace', lin_shaper_name,
678                      '--shapersize', str(lut_resolution_shaper)]
679
680             args += ['--cubesize', str(lut_resolution_3d)]
681
682             margs = ['--format',
683                      'cinespace',
684                      os.path.join(
685                          baked_directory,
686                          'maya',
687                          '%s for %s Maya.csp' % (odt_name, input_space))]
688             bake_lut = Process(description='bake a LUT',
689                                cmd='ociobakelut',
690                                args=(args + margs))
691             bake_lut.execute()
692
693             hargs = ['--format',
694                      'houdini',
695                      os.path.join(
696                          baked_directory,
697                          'houdini',
698                          '%s for %s Houdini.lut' % (odt_name, input_space))]
699             bake_lut = Process(description='bake a LUT',
700                                cmd='ociobakelut',
701                                args=(args + hargs))
702             bake_lut.execute()
703
704
705 def create_config_dir(config_directory, bake_secondary_LUTs):
706     """
707     Object description.
708
709     Parameters
710     ----------
711     parameter : type
712         Parameter description.
713
714     Returns
715     -------
716     type
717          Return value description.
718     """
719
720     lut_directory = os.path.join(config_directory, 'luts')
721     dirs = [config_directory, lut_directory]
722     if bake_secondary_LUTs:
723         dirs.extend([os.path.join(config_directory, 'baked'),
724                      os.path.join(config_directory, 'baked', 'flame'),
725                      os.path.join(config_directory, 'baked', 'photoshop'),
726                      os.path.join(config_directory, 'baked', 'houdini'),
727                      os.path.join(config_directory, 'baked', 'lustre'),
728                      os.path.join(config_directory, 'baked', 'maya')])
729
730     for d in dirs:
731         not os.path.exists(d) and os.mkdir(d)
732
733     return lut_directory
734
735
736 def create_ACES_config(aces_ctl_directory,
737                        config_directory,
738                        lut_resolution_1d=4096,
739                        lut_resolution_3d=64,
740                        bake_secondary_LUTs=True,
741                        cleanup=True):
742     """
743     Creates the ACES configuration.
744
745     Parameters
746     ----------
747     parameter : type
748         Parameter description.
749
750     Returns
751     -------
752     type
753          Return value description.
754     """
755
756     lut_directory = create_config_dir(config_directory, bake_secondary_LUTs)
757
758     odt_info = aces.get_ODTs_info(aces_ctl_directory)
759     lmt_info = aces.get_LMTs_info(aces_ctl_directory)
760
761     shaper_name = 'Output Shaper'
762     config_data = generate_LUTs(odt_info,
763                                 lmt_info,
764                                 shaper_name,
765                                 aces_ctl_directory,
766                                 lut_directory,
767                                 lut_resolution_1d,
768                                 lut_resolution_3d,
769                                 cleanup)
770
771     print('Creating "generic" config')
772     config = create_config(config_data)
773     print('\n\n\n')
774
775     write_config(config,
776                  os.path.join(config_directory, 'config.ocio'))
777
778     print('Creating "Nuke" config')
779     nuke_config = create_config(config_data, nuke=True)
780     print('\n\n\n')
781
782     write_config(nuke_config,
783                  os.path.join(config_directory, 'nuke_config.ocio'))
784
785     if bake_secondary_LUTs:
786         generate_baked_LUTs(odt_info,
787                             shaper_name,
788                             os.path.join(config_directory, 'baked'),
789                             os.path.join(config_directory, 'config.ocio'),
790                             lut_resolution_1d,
791                             lut_resolution_3d,
792                             lut_resolution_1d)
793
794     return True
795
796
797 def main():
798     """
799     Object description.
800
801     Parameters
802     ----------
803     parameter : type
804         Parameter description.
805
806     Returns
807     -------
808     type
809          Return value description.
810     """
811
812     import optparse
813
814     p = optparse.OptionParser(description='An OCIO config generation script',
815                               prog='createACESConfig',
816                               version='createACESConfig 0.1',
817                               usage='%prog [options]')
818     p.add_option('--acesCTLDir', '-a', default=os.environ.get(
819         ACES_OCIO_CTL_DIRECTORY_ENVIRON, None))
820     p.add_option('--configDir', '-c', default=os.environ.get(
821         ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON, None))
822     p.add_option('--lutResolution1d', default=4096)
823     p.add_option('--lutResolution3d', default=64)
824     p.add_option('--dontBakeSecondaryLUTs', action='store_true')
825     p.add_option('--keepTempImages', action='store_true')
826
827     options, arguments = p.parse_args()
828
829     aces_ctl_directory = options.acesCTLDir
830     config_directory = options.configDir
831     lut_resolution_1d = int(options.lutResolution1d)
832     lut_resolution_3d = int(options.lutResolution3d)
833     bake_secondary_luts = not options.dontBakeSecondaryLUTs
834     cleanup_temp_images = not options.keepTempImages
835
836     # TODO: Investigate the following statements.
837     try:
838         args_start = sys.argv.index('--') + 1
839         args = sys.argv[args_start:]
840     except:
841         args_start = len(sys.argv) + 1
842         args = []
843
844     print('command line : \n%s\n' % ' '.join(sys.argv))
845
846     assert aces_ctl_directory is not None, (
847         'process: No "{0}" environment variable defined or no "ACES CTL" '
848         'directory specified'.format(
849             ACES_OCIO_CTL_DIRECTORY_ENVIRON))
850
851     assert config_directory is not None, (
852         'process: No "{0}" environment variable defined or no configuration '
853         'directory specified'.format(
854             ACES_OCIO_CONFIGURATION_DIRECTORY_ENVIRON))
855
856     return create_ACES_config(aces_ctl_directory,
857                               config_directory,
858                               lut_resolution_1d,
859                               lut_resolution_3d,
860                               bake_secondary_luts,
861                               cleanup_temp_images)
862
863
864 if __name__ == '__main__':
865     main()