Default file rules behaviour is counter intuitive and possibly broken.
Hi,
As I started to poke at OCIO 2 for the new ACES config, I wanted to test the new ExponentWithLinearTransform transform.
Upon validation I get the well deserved:
CRITICAL:root:Only config version 2 (or higher) can have ExponentWithLinearTransform.
All good, I set my major version to 2:
config.setMajorVersion(2)
After which:
CRITICAL:root:Config failed validation. File rules failed with: File rules: rule named 'Default' is referencing color space 'default' that does not exist.
Which can be fixed by creating a new default ColorSpace but then because I don't like the default name and I remember #893 and specifically:
file_rules:
!<Rule> {name: LogC, extension="*", pattern="*LogC*", colorspace=ARRI LogC}
!<Rule> {name: OpenEXR, extension="[eE][xX][rR]", pattern="*", colorspace=ACEScg}
!<Rule> {name: TIFF, regex=".*\.TIF?F$", colorspace=sRGB}
!<Rule> {name: ColorSpaceNamePathSearch}
!<Rule> {name: Default, colorspace=Raw}
I decided to add my own which raised the following exception:
Traceback (most recent call last):
File "/Users/kelsolaar/Documents/Development/colour-science/ampas/OpenColorIO-Config-ACES/opencolorio_config_aces/config/generate/config.py", line 297, in <module>
generate_config(data, 'config.ocio')
File "/Users/kelsolaar/Documents/Development/colour-science/ampas/OpenColorIO-Config-ACES/opencolorio_config_aces/config/generate/config.py", line 236, in generate_config
file_rules.insertRule(
PyOpenColorIO.Exception: File rules: A rule named 'Default' already exists.
Hi Thomas,
The FileRules object always has a Default rule, so you cannot use insertRule in that case. In other words, the Default rule cannot be added or removed. There is a method called setDefaultRuleColorSpace that does what you are looking for.
As discussed elsewhere, I agree it would be helpful to have an example to illustrate the usage.
It makes things a bit more convoluted than one would wish but this works!
Given this data:
file_rules=[
{
'name': 'Default',
'colorspace': 'Gamut - sRGB'
},
{
'name': 'Linear - sRGB',
'colorspace': 'Gamut - sRGB',
'regex': '_[sS][rR][gG][bB]\\.([eE][xX][rR]|[hH][dD][rR])$'
},
{
'name': 'EOTF - sRGB',
'colorspace': 'CCTF - sRGB',
'regex': '_[sS][rR][gG][bB]\\.([pP][nN][gG]|[tT][iI][fF])$'
},
],
Here is what I came up with:
file_rules = ocio.FileRules()
rule_index = 0
for file_rule in data.file_rules[::-1]:
name = file_rule['name']
colorspace = file_rule['colorspace']
regex = file_rule.get('regex', '')
pattern = file_rule.get('pattern', '')
extension = file_rule.get('extension', '')
if name == 'Default':
file_rules.setDefaultRuleColorSpace(colorspace)
elif regex:
file_rules.insertRule(rule_index, name, colorspace, regex)
rule_index += 1
else:
file_rules.insertRule(rule_index, name, colorspace, pattern,
extension)
rule_index += 1
config.setFileRules(file_rules)