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