X-Git-Url: http://users.mur.at/ms/git/gitweb/?a=blobdiff_plain;f=aces_1.0.0%2Fpython%2Faces_ocio%2Faces_config.py;h=7c067ce48e89533058a024c96e3fcc9fa7813e0b;hb=7a4fc682918ad7556041773dad14802cd73d15e7;hp=9272908e5b87d94a48c78f5a625d8bfcef4a0a3f;hpb=0aab7ba4cf1b56cdc40fe839b47cdcafb06d6641;p=OpenColorIO-Configs.git diff --git a/aces_1.0.0/python/aces_ocio/aces_config.py b/aces_1.0.0/python/aces_ocio/aces_config.py index 9272908..7c067ce 100755 --- a/aces_1.0.0/python/aces_ocio/aces_config.py +++ b/aces_1.0.0/python/aces_ocio/aces_config.py @@ -23,7 +23,12 @@ from aces_ocio.colorspaces import red from aces_ocio.colorspaces import sony from aces_ocio.process import Process -from aces_ocio.utilities import replace, ColorSpace, compact +from aces_ocio.utilities import ( + ColorSpace, + colorspace_prefixed_name, + compact, + replace, + unpack_default) __author__ = 'ACES Developers' __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers' @@ -113,15 +118,15 @@ def set_config_default_roles(config, # 'rendering' and 'compositing_linear' roles default to the 'scene_linear' # value if not set explicitly if rendering: - config.setRole("rendering", rendering) + config.setRole('rendering', rendering) if compositing_linear: - config.setRole("compositing_linear", compositing_linear) + config.setRole('compositing_linear', compositing_linear) if scene_linear: config.setRole(ocio.Constants.ROLE_SCENE_LINEAR, scene_linear) if not rendering: - config.setRole("rendering", scene_linear) + config.setRole('rendering', scene_linear) if not compositing_linear: - config.setRole("compositing_linear", scene_linear) + config.setRole('compositing_linear', scene_linear) return True @@ -168,11 +173,6 @@ def generate_OCIO_transform(transforms): Return value description. """ - interpolation_options = { - 'linear': ocio.Constants.INTERP_LINEAR, - 'nearest': ocio.Constants.INTERP_NEAREST, - 'tetrahedral': ocio.Constants.INTERP_TETRAHEDRAL} - direction_options = { 'forward': ocio.Constants.TRANSFORM_DIR_FORWARD, 'inverse': ocio.Constants.TRANSFORM_DIR_INVERSE} @@ -277,7 +277,7 @@ def generate_OCIO_transform(transforms): # unknown type else: - print("Ignoring unknown transform type : %s" % transform['type']) + print('Ignoring unknown transform type : %s' % transform['type']) if len(ocio_transforms) > 1: group_transform = ocio.GroupTransform() @@ -290,10 +290,11 @@ def generate_OCIO_transform(transforms): return transform -def add_colorspace_alias(config, - reference_colorspace, - colorspace, - colorspace_alias_names): +def add_colorspace_aliases(config, + reference_colorspace, + colorspace, + colorspace_alias_names, + family='Aliases'): """ Object description. @@ -310,18 +311,20 @@ def add_colorspace_alias(config, for alias_name in colorspace_alias_names: if alias_name.lower() == colorspace.name.lower(): - print('Skipping alias creation for %s, alias %s, because lower cased names match' % ( - colorspace.name, alias_name) ) - return + print('Skipping alias creation for %s, alias %s, ' + 'because lower cased names match' % ( + colorspace.name, alias_name)) + continue print('Adding alias colorspace space %s, alias to %s' % ( alias_name, colorspace.name)) - compact_family_name = 'Aliases' + compact_family_name = family description = colorspace.description if colorspace.aces_transform_id: - description += "\n\nACES Transform ID : %s" % colorspace.aces_transform_id + description += ( + '\n\nACES Transform ID : %s' % colorspace.aces_transform_id) ocio_colorspace_alias = ocio.ColorSpace( name=alias_name, @@ -357,17 +360,12 @@ def add_colorspace_alias(config, config.addColorSpace(ocio_colorspace_alias) -def colorspace_prefixed_name(colorspace): - prefix = colorspace.family.replace("/", " - ") - return "%s - %s" % (prefix, colorspace.name) def add_look(config, look, - prefix, custom_lut_dir, reference_name, - config_data, - multiple_displays=False): + config_data): """ Object description. @@ -382,34 +380,29 @@ def add_look(config, Return value description. """ - look_name = look[0] - look_colorspace = look[1] - look_lut = look[2] - look_cccid = None - if len(look) == 4: - look_cccid = look[3] + look_name, look_colorspace, look_lut, look_cccid = unpack_default(look, 4) - print('Adding look %s - %s' % (look_name, ", ".join(look)) ) + print('Adding look %s - %s' % (look_name, ', '.join(look))) # # Copy look lut # if custom_lut_dir: - if not '$' in look_lut: - print( "Getting ready to copy look lut : %s" % look_lut ) + if '$' not in look_lut: + print('Getting ready to copy look lut : %s' % look_lut) shutil.copy2(look_lut, custom_lut_dir) look_lut = os.path.split(look_lut)[1] else: - print( "Skipping LUT copy because path contains a context variable" ) + print('Skipping LUT copy because path contains a context variable') # # Create OCIO Look # # Look 1 - print('Adding look to config' ) + print('Adding look to config') lk1 = ocio.Look() - lk1.setName( look_name ) - lk1.setProcessSpace( look_colorspace ) + lk1.setName(look_name) + lk1.setProcessSpace(look_colorspace) keys = {'type': 'lutFile', 'path': look_lut, @@ -418,29 +411,29 @@ def add_look(config, keys['cccid'] = look_cccid ocio_transform = generate_OCIO_transform([keys]) - lk1.setTransform( ocio_transform ) + lk1.setTransform(ocio_transform) # add to config - config.addLook( lk1 ) + config.addLook(lk1) - print( "Creating aliased colorspace") + print('Creating aliased colorspace') # # Create OCIO colorspace that references that look # - Needed for some implementations that don't process looks well # - Also needed for some implementations that don't expose looks well # - look_aliases = ["look_%s" % compact(look_name)] + look_aliases = ['look_%s' % compact(look_name)] colorspace = ColorSpace(look_name, - aliases=look_aliases, - description="The %s Look colorspace" % look_name, - family='Look') + aliases=look_aliases, + description='The %s Look colorspace' % look_name, + family='Look') colorspace.from_reference_transforms = [{'type': 'look', - 'look': look_name, - 'src': reference_name, - 'dst': reference_name, - 'direction': 'forward'}] + 'look': look_name, + 'src': reference_name, + 'dst': reference_name, + 'direction': 'forward'}] print('Adding colorspace %s, alias to look %s to config data' % ( look_name, look_name)) @@ -448,10 +441,10 @@ def add_look(config, # Add this colorspace into the main list of colorspaces config_data['colorSpaces'].append(colorspace) - print("") + print() + -def integrate_looks_into_views(config, - looks, +def integrate_looks_into_views(looks, reference_name, config_data, multiple_displays=False): @@ -468,7 +461,7 @@ def integrate_looks_into_views(config, type Return value description. """ - look_names = [look[0] for look in looks] + look_names = [look[0] for look in looks] # Option 1 - Add a 'look' to each Display # - Assumes there is a Display for each ACES Output Transform @@ -483,64 +476,76 @@ def integrate_looks_into_views(config, # - Add these new copied colorspaces for the Displays / Views else: for display, view_list in config_data['displays'].iteritems(): - output_colorspace_copy = None - look_names_string = "" + output_colorspace_c = None + look_names_string = '' for view_name, output_colorspace in view_list.iteritems(): - if view_name == "Output Transform": + if view_name == 'Output Transform': - print( "Adding new View that incorporates looks" ) + print('Adding new View that incorporates looks') # Make a copy of the output colorspace - output_colorspace_copy = copy.deepcopy(output_colorspace) + output_colorspace_c = copy.deepcopy(output_colorspace) - #for look_name in look_names: - for i in range(len(look_names)): + # for look_name in look_names: + for i, look_name in enumerate(look_names): look_name = look_names[i] - # Add the LookTransform to the head of the from_reference transform list - if output_colorspace_copy.from_reference_transforms: - output_colorspace_copy.from_reference_transforms.insert(i, {'type': 'look', - 'look': look_name, - 'src': reference_name, - 'dst': reference_name, - 'direction': 'forward'}) - - # Add the LookTransform to the end of the to_reference transform list - if output_colorspace_copy.to_reference_transforms: - inverse_look_name = look_names[len(look_names) -1 -i] - - output_colorspace_copy.to_reference_transforms.append({'type': 'look', - 'look': inverse_look_name, - 'src': reference_name, - 'dst': reference_name, - 'direction': 'inverse'}) - - if not look_name in config_data['looks']: + # Add the LookTransform to the head of the + # from_reference transform list. + if output_colorspace_c.from_reference_transforms: + output_colorspace_c.from_reference_transforms.insert( + i, {'type': 'look', + 'look': look_name, + 'src': reference_name, + 'dst': reference_name, + 'direction': 'forward'}) + + # Add the LookTransform to the end of + # the to_reference transform list. + if output_colorspace_c.to_reference_transforms: + inverse_look_name = look_names[ + len(look_names) - 1 - i] + + output_colorspace_c.to_reference_transforms.append( + {'type': 'look', + 'look': inverse_look_name, + 'src': reference_name, + 'dst': reference_name, + 'direction': 'inverse'}) + + if look_name not in config_data['looks']: config_data['looks'].append(look_name) - look_names_string = ", ".join(look_names) - output_colorspace_copy.name = "%s with %s" % (output_colorspace.name, look_names_string) - output_colorspace_copy.aliases = ["out_%s" % compact(output_colorspace_copy.name)] + look_names_string = ', '.join(look_names) + output_colorspace_c.name = '%s with %s' % ( + output_colorspace.name, look_names_string) + output_colorspace_c.aliases = [ + 'out_%s' % compact(output_colorspace_c.name)] - print( "Colorspace that incorporates looks created : %s" % output_colorspace_copy.name ) + print('Colorspace that incorporates looks ' + 'created : %s' % output_colorspace_c.name) - config_data['colorSpaces'].append(output_colorspace_copy) + config_data['colorSpaces'].append(output_colorspace_c) - if output_colorspace_copy: - print( "Adding colorspace that incorporates looks into view list" ) + if output_colorspace_c: + print('Adding colorspace that incorporates looks ' + 'into view list') # Change the name of the View - view_list["Output Transform with %s" % look_names_string] = output_colorspace_copy + view_list['Output Transform with %s' % look_names_string] = ( + output_colorspace_c) config_data['displays'][display] = view_list - #print( "Display : %s, View List : %s" % (display, ", ".join(view_list)) ) + # print('Display : %s, View List : %s' % ( + # display, ', '.join(view_list)) ) -def create_config(config_data, - aliases=False, - prefix=False, - multiple_displays=False, - look_info=[], - custom_lut_dir=None): + +def create_config(config_data, + aliases=False, + prefix=False, + multiple_displays=False, + look_info=None, + custom_lut_dir=None): """ Object description. @@ -555,6 +560,9 @@ def create_config(config_data, Return value description. """ + if look_info is None: + look_info = [] + prefixed_names = {} alias_colorspaces = [] @@ -565,10 +573,10 @@ def create_config(config_data, config.setDescription('An ACES config generated from python') # Setting configuration search path. - searchPath = ['luts'] + search_path = ['luts'] if custom_lut_dir: - searchPath.append('custom') - config.setSearchPath(':'.join(searchPath)) + search_path.append('custom') + config.setSearchPath(':'.join(search_path)) # Defining the reference colorspace. reference_data = config_data['referenceColorSpace'] @@ -596,42 +604,42 @@ def create_config(config_data, # Add alias if aliases: - if reference_data.aliases != []: - #add_colorspace_alias(config, reference_data, + if reference_data.aliases: + # add_colorspace_alias(config, reference_data, # reference_data, reference_data.aliases) - # defer adding alias colorspaces until end. Helps with some applications - alias_colorspaces.append([reference_data, reference_data, reference_data.aliases]) - + # defer adding alias colorspaces until end. + # Helps with some applications. + alias_colorspaces.append( + [reference_data, reference_data, reference_data.aliases]) - print("") + print() - #print( "color spaces : %s" % [x.name for x in sorted(config_data['colorSpaces'])]) + # print('color spaces : %s' % [ + # x.name for x in sorted(config_data['colorSpaces'])]) # # Add Looks and Look colorspaces # - if look_info != []: + if look_info: print('Adding looks') config_data['looks'] = [] # Add looks and colorspaces for look in look_info: - add_look(config, - look, - prefix, - custom_lut_dir, - reference_data.name, - config_data) + add_look(config, + look, + custom_lut_dir, + reference_data.name, + config_data) # Integrate looks with displays, views - integrate_looks_into_views(config, - look_info, - reference_data.name, - config_data, - multiple_displays) + integrate_looks_into_views(look_info, + reference_data.name, + config_data, + multiple_displays) - print("") + print() print('Adding the regular color spaces') @@ -648,7 +656,8 @@ def create_config(config_data, description = colorspace.description if colorspace.aces_transform_id: - description += "\n\nACES Transform ID : %s" % colorspace.aces_transform_id + description += ( + '\n\nACES Transform ID : %s' % colorspace.aces_transform_id) ocio_colorspace = ocio.ColorSpace( name=colorspace.name, @@ -682,72 +691,176 @@ def create_config(config_data, # Add alias to normal colorspace, using compact name # if aliases: - if colorspace.aliases != []: - #add_colorspace_alias(config, reference_data, + if colorspace.aliases: + # add_colorspace_alias(config, reference_data, # colorspace, colorspace.aliases) - # defer adding alias colorspaces until end. Helps with some applications - alias_colorspaces.append([reference_data, colorspace, colorspace.aliases]) + # defer adding alias colorspaces until end. + # Helps with some applications. + alias_colorspaces.append( + [reference_data, colorspace, colorspace.aliases]) + + print() + + print() + + # + # We add roles early so we can create alias colorspaces with the names + # of the roles before the rest of the colorspace aliases are added + # to the config. + print('Setting the roles') + + if prefix: + set_config_default_roles( + config, + color_picking=prefixed_names[ + config_data['roles']['color_picking']], + color_timing=prefixed_names[config_data['roles']['color_timing']], + compositing_log=prefixed_names[ + config_data['roles']['compositing_log']], + data=prefixed_names[config_data['roles']['data']], + default=prefixed_names[config_data['roles']['default']], + matte_paint=prefixed_names[config_data['roles']['matte_paint']], + reference=prefixed_names[config_data['roles']['reference']], + scene_linear=prefixed_names[config_data['roles']['scene_linear']], + texture_paint=prefixed_names[ + config_data['roles']['texture_paint']]) + + # Not allowed for the moment. role names can not overlap + # with colorspace names. + """ + # Add the aliased colorspaces for each role + for role_name, role_colorspace_name in config_data['roles'].iteritems(): + role_colorspace_prefixed_name = prefixed_names[role_colorspace_name] + + print( 'Finding colorspace : %s' % role_colorspace_prefixed_name ) + # Find the colorspace pointed to by the role + role_colorspaces = [colorspace + for colorspace in config_data['colorSpaces'] + if colorspace.name == role_colorspace_prefixed_name] + role_colorspace = None + if len(role_colorspaces) > 0: + role_colorspace = role_colorspaces[0] + else: + if reference_data.name == role_colorspace_prefixed_name: + role_colorspace = reference_data - print('') + if role_colorspace: + print( 'Adding an alias colorspace named %s, pointing to %s' % ( + role_name, role_colorspace.name)) - print("") + add_colorspace_aliases( + config, reference_data, role_colorspace, [role_name], 'Roles') + """ - # We add these at the end as some applications use the order of the colorspaces - # definitions in the config to order the colorspaces in their selection lists. - # Other go alphabetically. This should keep the alias colorspaces out of the way - # for the apps that use the order of definition in the config. + else: + set_config_default_roles( + config, + color_picking=config_data['roles']['color_picking'], + color_timing=config_data['roles']['color_timing'], + compositing_log=config_data['roles']['compositing_log'], + data=config_data['roles']['data'], + default=config_data['roles']['default'], + matte_paint=config_data['roles']['matte_paint'], + reference=config_data['roles']['reference'], + scene_linear=config_data['roles']['scene_linear'], + texture_paint=config_data['roles']['texture_paint']) + + # Not allowed for the moment. role names can not overlap + # with colorspace names. + """ + # Add the aliased colorspaces for each role + for role_name, role_colorspace_name in config_data['roles'].iteritems(): + # Find the colorspace pointed to by the role + role_colorspaces = [colorspace + for colorspace in config_data['colorSpaces'] + if colorspace.name == role_colorspace_name] + role_colorspace = None + if len(role_colorspaces) > 0: + role_colorspace = role_colorspaces[0] + else: + if reference_data.name == role_colorspace_name: + role_colorspace = reference_data + + if role_colorspace: + print( 'Adding an alias colorspace named %s, pointing to %s' % ( + role_name, role_colorspace.name)) + + add_colorspace_aliases( + config, reference_data, role_colorspace, [role_name], 'Roles') + """ + + print() + + # We add these at the end as some applications use the order of the + # colorspaces definitions in the config to order the colorspaces + # in their selection lists. + # Other go alphabetically. This should keep the alias colorspaces out + # of the way for the apps that use the order of definition in the config. print('Adding the alias colorspaces') for reference, colorspace, aliases in alias_colorspaces: - add_colorspace_alias(config, reference, colorspace, aliases) + add_colorspace_aliases(config, reference, colorspace, aliases) - print("") + print() print('Adding the diplays and views') + # Set the color_picking role to be + # the first Display's Output Transform View. + default_display_name = config_data['defaultDisplay'] + default_display_views = config_data['displays'][default_display_name] + default_display_colorspace = default_display_views['Output Transform'] + + set_config_default_roles( + config, + color_picking=default_display_colorspace.name) + # Defining the *views* and *displays*. displays = [] views = [] - # Defining a *generic* *display* and *view* setup. if multiple_displays: # Built list of looks to add to Displays looks = config_data['looks'] if ('looks' in config_data) else [] - looks = ", ".join(looks) - print( "Creating multiple displays, with looks : %s" % looks) + looks = ', '.join(looks) + print('Creating multiple displays, with looks : %s' % looks) + + # Note: We don't reorder the Displays to put the 'defaultDisplay' first + # because OCIO will order them alphabetically + # when the config is written to disk. # Create Displays, Views for display, view_list in config_data['displays'].iteritems(): for view_name, colorspace in view_list.iteritems(): config.addDisplay(display, view_name, colorspace.name, looks) - if 'Output Transform' in view_name and looks != "": + if 'Output Transform' in view_name and looks != '': # Add normal View, without looks config.addDisplay(display, view_name, colorspace.name) # Add View with looks - view_name_with_looks = "%s with %s" % (view_name, looks) - config.addDisplay(display, view_name_with_looks, colorspace.name, looks) + view_name_with_looks = '%s with %s' % (view_name, looks) + config.addDisplay(display, view_name_with_looks, + colorspace.name, looks) else: config.addDisplay(display, view_name, colorspace.name) if not (view_name in views): views.append(view_name) displays.append(display) + # Defining the set of *views* and *displays* useful in a *GUI* context. else: - # Defining the set of *views* and *displays* useful in a *GUI* context. - #display_name = 'ACES' - single_display_name = config_data['roles']['scene_linear'] + single_display_name = 'ACES' + # single_display_name = config_data['roles']['scene_linear'] displays.append(single_display_name) - display_names = sorted(config_data['displays']) - # Make sure the default display is first - default_display = config_data['defaultDisplay'] - display_names.insert(0, display_names.pop(display_names.index(default_display))) + display_names = sorted(config_data['displays']) + display_names.insert(0, display_names.pop( + display_names.index(default_display_name))) # Built list of looks to add to Displays looks = config_data['looks'] if ('looks' in config_data) else [] - look_names = ", ".join(looks) + look_names = ', '.join(looks) displays_views_colorspaces = [] @@ -756,29 +869,34 @@ def create_config(config_data, view_list = config_data['displays'][display] for view_name, colorspace in view_list.iteritems(): if 'Output Transform' in view_name: - #print( "Adding view for %s" % view_name ) - - # Maya 2016 doesn't like parentheses in View names - display_cleaned = replace(display, {')': '', '(': ''}) + # print( 'Adding view for %s' % colorspace.name ) # We use the Display names as the View names in this case # as there is a single Display that contains all views. - # This works for more applications than not, as of the time of this implementation. + # This works for more applications than not, + # as of the time of this implementation. + + # Maya 2016 doesn't like parentheses in View names + display_cleaned = replace(display, {')': '', '(': ''}) # If View includes looks if 'with' in view_name: # Integrate looks into view name - display_cleaned = "%s with %s" % (display_cleaned, look_names) + display_cleaned = '%s with %s' % ( + display_cleaned, look_names) - viewsWithLooksAtEnd = False - # Storing combo of display, view and colorspace name in a list so we can - # add them to the end of the list - if viewsWithLooksAtEnd: - displays_views_colorspaces.append([single_display_name, display_cleaned, colorspace.name]) + views_with_looks_at_end = False + # Storing combo of display, view and colorspace name + # in a list so we can add them to the end of the list. + if views_with_looks_at_end: + displays_views_colorspaces.append( + [single_display_name, display_cleaned, + colorspace.name]) # Or add as normal else: - config.addDisplay(single_display_name, display_cleaned, colorspace.name) + config.addDisplay(single_display_name, + display_cleaned, colorspace.name) # Add to views list if not (display_cleaned in views): @@ -786,18 +904,23 @@ def create_config(config_data, # A normal View else: - config.addDisplay(single_display_name, display_cleaned, colorspace.name) + config.addDisplay(single_display_name, display_cleaned, + colorspace.name) # Add to views list if not (display_cleaned in views): views.append(display_cleaned) - # Add to config any display, view combinations that were saved for later + # Add to config any display, view combinations that were saved + # for later. This list will be empty unless views_with_looks_at_end is + # set to True above. for display_view_colorspace in displays_views_colorspaces: - single_display_name, display_cleaned, colorspace_name = display_view_colorspace + single_display_name, display_cleaned, colorspace_name = ( + display_view_colorspace) # Add to config - config.addDisplay(single_display_name, display_cleaned, colorspace_name) + config.addDisplay(single_display_name, display_cleaned, + colorspace_name) # Add to views list if not (display_cleaned in views): @@ -808,12 +931,12 @@ def create_config(config_data, # single_display_name = 'Utility' # displays.append(single_display_name) - raw_display_space_name = config_data['roles']['data'] + raw_display_space_name = config_data['roles']['data'] log_display_space_name = config_data['roles']['compositing_log'] # Find the newly-prefixed colorspace names if prefix: - #print( prefixed_names ) + # print( prefixed_names ) raw_display_space_name = prefixed_names[raw_display_space_name] log_display_space_name = prefixed_names[log_display_space_name] @@ -826,36 +949,7 @@ def create_config(config_data, config.setActiveDisplays(','.join(sorted(displays))) config.setActiveViews(','.join(views)) - print("") - - print('Setting the roles') - - if prefix: - set_config_default_roles( - config, - color_picking=prefixed_names[config_data['roles']['color_picking']], - color_timing=prefixed_names[config_data['roles']['color_timing']], - compositing_log=prefixed_names[config_data['roles']['compositing_log']], - data=prefixed_names[config_data['roles']['data']], - default=prefixed_names[config_data['roles']['default']], - matte_paint=prefixed_names[config_data['roles']['matte_paint']], - reference=prefixed_names[config_data['roles']['reference']], - scene_linear=prefixed_names[config_data['roles']['scene_linear']], - texture_paint=prefixed_names[config_data['roles']['texture_paint']]) - else: - set_config_default_roles( - config, - color_picking=config_data['roles']['color_picking'], - color_timing=config_data['roles']['color_timing'], - compositing_log=config_data['roles']['compositing_log'], - data=config_data['roles']['data'], - default=config_data['roles']['default'], - matte_paint=config_data['roles']['matte_paint'], - reference=config_data['roles']['reference'], - scene_linear=config_data['roles']['scene_linear'], - texture_paint=config_data['roles']['texture_paint']) - - print("") + print() # Make sure we didn't create a bad config config.sanityCheck() @@ -867,12 +961,24 @@ def create_config(config_data, for original, prefixed in prefixed_names.iteritems(): prefixed_names_inverse[prefixed] = original - # Reet the reference colorspace name + # Reset the reference colorspace name reference_data.name = prefixed_names_inverse[reference_data.name] # Reset the rest of the colorspace names - for colorspace in config_data['colorSpaces']: - colorspace.name = prefixed_names_inverse[colorspace.name] + try: + for colorspace in config_data['colorSpaces']: + colorspace.name = prefixed_names_inverse[colorspace.name] + except: + print('Prefixed names') + for original, prefixed in prefixed_names.iteritems(): + print('%s, %s' % (original, prefixed)) + + print('\n') + + print('Inverse Lookup of Prefixed names') + for prefixed, original in prefixed_names_inverse.iteritems(): + print('%s, %s' % (prefixed, original)) + raise return config @@ -944,9 +1050,9 @@ def generate_LUTs(odt_info, # ------------------------------------------------------------------------- # *ARRI Log-C* to *ACES*. - arri_colorSpaces = arri.create_colorspaces(lut_directory, + arri_colorspaces = arri.create_colorspaces(lut_directory, lut_resolution_1d) - for cs in arri_colorSpaces: + for cs in arri_colorspaces: config_data['colorSpaces'].append(cs) # *Canon-Log* to *ACES*. @@ -962,9 +1068,9 @@ def generate_LUTs(odt_info, config_data['colorSpaces'].append(cs) # *Panasonic V-Log* to *ACES*. - panasonic_colorSpaces = panasonic.create_colorspaces(lut_directory, + panasonic_colorspaces = panasonic.create_colorspaces(lut_directory, lut_resolution_1d) - for cs in panasonic_colorSpaces: + for cs in panasonic_colorspaces: config_data['colorSpaces'].append(cs) # *RED* colorspaces to *ACES*. @@ -974,18 +1080,17 @@ def generate_LUTs(odt_info, config_data['colorSpaces'].append(cs) # *S-Log* to *ACES*. - sony_colorSpaces = sony.create_colorspaces(lut_directory, + sony_colorspaces = sony.create_colorspaces(lut_directory, lut_resolution_1d) - for cs in sony_colorSpaces: + for cs in sony_colorspaces: config_data['colorSpaces'].append(cs) # ------------------------------------------------------------------------- # General Color Spaces # ------------------------------------------------------------------------- - general_colorSpaces = general.create_colorspaces(lut_directory, - lut_resolution_1d, - lut_resolution_3d) - for cs in general_colorSpaces: + general_colorspaces = general.create_colorspaces(lut_directory, + lut_resolution_1d) + for cs in general_colorspaces: config_data['colorSpaces'].append(cs) # The *Raw* color space @@ -1005,7 +1110,6 @@ def generate_baked_LUTs(odt_info, shaper_name, baked_directory, config_path, - lut_resolution_1d, lut_resolution_3d, lut_resolution_shaper=1024, prefix=False): @@ -1023,8 +1127,13 @@ def generate_baked_LUTs(odt_info, Return value description. """ - # Create two entries for ODTs that have full and legal range support odt_info_C = dict(odt_info) + + # Uncomment if you would like to support the older behavior where ODTs + # that have support for full and legal range output generate + # a LUT for each. + """ + # Create two entries for ODTs that have full and legal range support for odt_ctl_name, odt_values in odt_info.iteritems(): if odt_values['transformHasFullLegalSwitch']: odt_name = odt_values['transformUserName'] @@ -1038,6 +1147,7 @@ def generate_baked_LUTs(odt_info, odt_info_C['%s - Full' % odt_ctl_name] = odt_values_full del (odt_info_C[odt_ctl_name]) + """ # Generate appropriate LUTs for each ODT for odt_ctl_name, odt_values in odt_info_C.iteritems(): @@ -1049,8 +1159,8 @@ def generate_baked_LUTs(odt_info, args = ['--iconfig', config_path, '-v'] if prefix: - args += ['--inputspace', "ACES - %s" % input_space] - args += ['--outputspace', "Output - %s" % odt_name] + args += ['--inputspace', 'ACES - %s' % input_space] + args += ['--outputspace', 'Output - %s' % odt_name] else: args += ['--inputspace', input_space] args += ['--outputspace', odt_name] @@ -1060,7 +1170,7 @@ def generate_baked_LUTs(odt_info, odt_name, input_space)] if prefix: - args += ['--shaperspace', "Utility - %s" % shaper_name, + args += ['--shaperspace', 'Utility - %s' % shaper_name, '--shapersize', str(lut_resolution_shaper)] else: args += ['--shaperspace', shaper_name, @@ -1082,8 +1192,8 @@ def generate_baked_LUTs(odt_info, args = ['--iconfig', config_path, '-v'] if prefix: - args += ['--inputspace', "ACES - %s" % input_space] - args += ['--outputspace', "Output - %s" % odt_name] + args += ['--inputspace', 'ACES - %s' % input_space] + args += ['--outputspace', 'Output - %s' % odt_name] else: args += ['--inputspace', input_space] args += ['--outputspace', odt_name] @@ -1091,7 +1201,7 @@ def generate_baked_LUTs(odt_info, '%s - %s for %s data' % ( odt_prefix, odt_name, input_space)] if prefix: - args += ['--shaperspace', "Utility - %s" % shaper_name, + args += ['--shaperspace', 'Utility - %s' % shaper_name, '--shapersize', str(lut_resolution_shaper)] else: args += ['--shaperspace', shaper_name, @@ -1125,8 +1235,8 @@ def generate_baked_LUTs(odt_info, args = ['--iconfig', config_path, '-v'] if prefix: - args += ['--inputspace', "ACES - %s" % input_space] - args += ['--outputspace', "Output - %s" % odt_name] + args += ['--inputspace', 'ACES - %s' % input_space] + args += ['--outputspace', 'Output - %s' % odt_name] else: args += ['--inputspace', input_space] args += ['--outputspace', odt_name] @@ -1134,11 +1244,11 @@ def generate_baked_LUTs(odt_info, '%s - %s for %s data' % ( odt_prefix, odt_name, input_space)] if input_space == 'ACEScg': - lin_shaper_name = "%s - AP1" % shaper_name + lin_shaper_name = '%s - AP1' % shaper_name else: lin_shaper_name = shaper_name if prefix: - lin_shaper_name = "Utility - %s" % lin_shaper_name + lin_shaper_name = 'Utility - %s' % lin_shaper_name args += ['--shaperspace', lin_shaper_name, '--shapersize', str(lut_resolution_shaper)] @@ -1167,8 +1277,8 @@ def generate_baked_LUTs(odt_info, bake_lut.execute() -def create_config_dir(config_directory, - bake_secondary_LUTs=False, +def create_config_dir(config_directory, + bake_secondary_luts=False, custom_lut_dir=None): """ Object description. @@ -1187,7 +1297,7 @@ def create_config_dir(config_directory, lut_directory = os.path.join(config_directory, 'luts') dirs = [config_directory, lut_directory] - if bake_secondary_LUTs: + if bake_secondary_luts: dirs.extend([os.path.join(config_directory, 'baked'), os.path.join(config_directory, 'baked', 'flame'), os.path.join(config_directory, 'baked', 'photoshop'), @@ -1208,9 +1318,9 @@ def create_ACES_config(aces_ctl_directory, config_directory, lut_resolution_1d=4096, lut_resolution_3d=64, - bake_secondary_LUTs=True, + bake_secondary_luts=True, multiple_displays=False, - look_info=[], + look_info=None, copy_custom_luts=True, cleanup=True, prefix_colorspaces_with_family_names=True): @@ -1228,13 +1338,16 @@ def create_ACES_config(aces_ctl_directory, Return value description. """ + if look_info is None: + look_info = [] + # Directory for custom LUTs custom_lut_dir = None if copy_custom_luts: - custom_lut_dir = os.path.join(config_directory, "custom") + custom_lut_dir = os.path.join(config_directory, 'custom') - lut_directory = create_config_dir(config_directory, - bake_secondary_LUTs, + lut_directory = create_config_dir(config_directory, + bake_secondary_luts, custom_lut_dir) odt_info = aces.get_ODTs_info(aces_ctl_directory) @@ -1251,23 +1364,22 @@ def create_ACES_config(aces_ctl_directory, cleanup) print('Creating config - with prefixes, with aliases') - config = create_config(config_data, - prefix=prefix_colorspaces_with_family_names, - aliases=True, - multiple_displays=multiple_displays, - look_info=look_info, - custom_lut_dir=custom_lut_dir) + config = create_config(config_data, + prefix=prefix_colorspaces_with_family_names, + aliases=True, + multiple_displays=multiple_displays, + look_info=look_info, + custom_lut_dir=custom_lut_dir) print('\n\n\n') write_config(config, os.path.join(config_directory, 'config.ocio')) - if bake_secondary_LUTs: + if bake_secondary_luts: generate_baked_LUTs(odt_info, shaper_name, os.path.join(config_directory, 'baked'), os.path.join(config_directory, 'config.ocio'), - lut_resolution_1d, lut_resolution_3d, lut_resolution_1d, prefix=prefix_colorspaces_with_family_names) @@ -1292,50 +1404,74 @@ def main(): import optparse - usage = '%prog [options]\n' + usage = '%prog [options]\n' usage += '\n' usage += 'An OCIO config generation script for ACES 1.0\n' usage += '\n' usage += 'Command line examples' usage += '\n' - usage += 'Create a GUI-friendly ACES 1.0 config with no secondary, baked LUTs : \n' - usage += '\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl --lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 --dontBakeSecondaryLUTs' + usage += ('Create a GUI-friendly ACES 1.0 config with no secondary, ' + 'baked LUTs : \n') + usage += ('\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl ' + '--lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 ' + '--dontBakeSecondaryLUTs') usage += '\n' usage += 'Create a more OCIO-compliant ACES 1.0 config : \n' - usage += '\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl --lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 --createMultipleDisplays' + usage += ('\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl ' + '--lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 ' + '--createMultipleDisplays') usage += '\n' usage += '\n' usage += 'Adding custom looks' usage += '\n' - usage += 'Create a GUI-friendly ACES 1.0 config with an ACES-style CDL (will be applied in the ACEScc colorspace): \n' - usage += '\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl --lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 \n\t\t--addACESLookCDL ACESCDLName /path/to/SampleCDL.ccc cc03345' + usage += ('Create a GUI-friendly ACES 1.0 config with an ACES-style CDL ' + '(will be applied in the ACEScc colorspace): \n') + usage += ('\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl ' + '--lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 ' + '\n\t\t--addACESLookCDL ACESCDLName ' + '/path/to/SampleCDL.ccc cc03345') usage += '\n' usage += 'Create a GUI-friendly ACES 1.0 config with an general CDL: \n' - usage += '\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl --lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 \n\t\t--addCustomLookCDL CustomCDLName "ACES - ACEScc" /path/to/SampleCDL.ccc cc03345' + usage += ('\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl ' + '--lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 ' + '\n\t\t--addCustomLookCDL CustomCDLName "ACES - ACEScc" ' + '/path/to/SampleCDL.ccc cc03345') usage += '\n' - usage += '\tIn this example, the CDL will be applied in the ACEScc colorspace, but the user could choose other spaces by changing the argument after the name of the look. \n' + usage += ('\tIn this example, the CDL will be applied in the ' + 'ACEScc colorspace, but the user could choose other spaces ' + 'by changing the argument after the name of the look. \n') usage += '\n' - usage += 'Create a GUI-friendly ACES 1.0 config with an ACES-style LUT (will be applied in the ACEScc colorspace): \n' - usage += '\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl --lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 \n\t\t--addACESLookLUT ACESLUTName /path/to/SampleCDL.ccc cc03345' + usage += ('Create a GUI-friendly ACES 1.0 config with an ACES-style LUT ' + '(will be applied in the ACEScc colorspace): \n') + usage += ('\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl ' + '--lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 ' + '\n\t\t--addACESLookLUT ACESLUTName ' + '/path/to/SampleCDL.ccc cc03345') usage += '\n' usage += 'Create a GUI-friendly ACES 1.0 config with an general LUT: \n' - usage += '\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl --lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 \n\t\t--addCustomLookLUT CustomLUTName "ACES - ACEScc" /path/to/SampleCDL.ccc cc03345' + usage += ('\tcreate_aces_config -a /path/to/aces-dev/transforms/ctl ' + '--lutResolution1d 1024 --lutResolution3d 33 -c aces_1.0.0 ' + '\n\t\t--addCustomLookLUT CustomLUTName "ACES - ACEScc" ' + '/path/to/SampleCDL.ccc cc03345') usage += '\n' - usage += '\tIn this example, the LUT will be applied in the ACEScc colorspace, but the user could choose other spaces by changing the argument after the name of the look. \n' + usage += ('\tIn this example, the LUT will be applied in the ' + 'ACEScc colorspace, but the user could choose other spaces ' + 'by changing the argument after the name of the look. \n') usage += '\n' look_info = [] + def look_info_callback(option, opt_str, value, parser): - print( "look_info_callback" ) - print( option, opt_str, value, parser ) - if opt_str == "--addCustomLookCDL": + print('look_info_callback') + print(option, opt_str, value, parser) + if opt_str == '--addCustomLookCDL': look_info.append(value) - elif opt_str == "--addCustomLookLUT": + elif opt_str == '--addCustomLookLUT': look_info.append(value) - elif opt_str == "--addACESLookCDL": - look_info.append([value[0], "ACES - ACEScc", value[1], value[2]]) - elif opt_str == "--addACESLookLUT": - look_info.append([value[0], "ACES - ACEScc", value[1]]) + elif opt_str == '--addACESLookCDL': + look_info.append([value[0], 'ACES - ACEScc', value[1], value[2]]) + elif opt_str == '--addACESLookLUT': + look_info.append([value[0], 'ACES - ACEScc', value[1]]) p = optparse.OptionParser(description='', prog='create_aces_config', @@ -1350,16 +1486,17 @@ def main(): p.add_option('--dontBakeSecondaryLUTs', action='store_true', default=False) p.add_option('--keepTempImages', action='store_true', default=False) - p.add_option('--createMultipleDisplays', action='store_true', default=False) - - p.add_option('--addCustomLookLUT', '', type='string', nargs=3, - action="callback", callback=look_info_callback) - p.add_option('--addCustomLookCDL', '', type='string', nargs=4, - action="callback", callback=look_info_callback) - p.add_option('--addACESLookLUT', '', type='string', nargs=2, - action="callback", callback=look_info_callback) - p.add_option('--addACESLookCDL', '', type='string', nargs=3, - action="callback", callback=look_info_callback) + p.add_option('--createMultipleDisplays', action='store_true', + default=False) + + p.add_option('--addCustomLookLUT', '', type='string', nargs=3, + action='callback', callback=look_info_callback) + p.add_option('--addCustomLookCDL', '', type='string', nargs=4, + action='callback', callback=look_info_callback) + p.add_option('--addACESLookLUT', '', type='string', nargs=2, + action='callback', callback=look_info_callback) + p.add_option('--addACESLookCDL', '', type='string', nargs=3, + action='callback', callback=look_info_callback) p.add_option('--copyCustomLUTs', action='store_true', default=False) options, arguments = p.parse_args() @@ -1373,15 +1510,7 @@ def main(): multiple_displays = options.createMultipleDisplays copy_custom_luts = options.copyCustomLUTs - print( look_info ) - - # TODO: Investigate the following statements. - try: - args_start = sys.argv.index('--') + 1 - args = sys.argv[args_start:] - except: - args_start = len(sys.argv) + 1 - args = [] + print(look_info) print('command line : \n%s\n' % ' '.join(sys.argv)) @@ -1405,5 +1534,6 @@ def main(): copy_custom_luts, cleanup_temp_images) + if __name__ == '__main__': main()