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