def test_using_rules(self): """ Test Config.setFileRiles() & Config.getColorSpaceFromFilepath(). """ cfg = OCIO.Config.CreateRaw() cs = OCIO.ColorSpace(name='cs1') cfg.addColorSpace(cs) cs = OCIO.ColorSpace(name='cs2') cfg.addColorSpace(cs) cs = OCIO.ColorSpace(name='cs3') cfg.addColorSpace(cs) rules = OCIO.FileRules() rules.insertRule(0, 'A', 'cs1', '*', 'jpg') rules.insertRule(1, 'B', 'cs2', '*', 'png') rules.insertRule(2, 'C', 'cs3', '*', 'exr') cfg.setFileRules(rules) cfg_rules = cfg.getFileRules() self.assertEqual(cfg_rules.getNumEntries(), 4) csName, ruleIndex = cfg.getColorSpaceFromFilepath(filePath='test.png') self.assertEqual(csName, 'cs2') self.assertEqual(ruleIndex, 1) csName, ruleIndex = cfg.getColorSpaceFromFilepath(filePath='pic.exr') self.assertEqual(csName, 'cs3') self.assertEqual(ruleIndex, 2) csName, ruleIndex = cfg.getColorSpaceFromFilepath(filePath='pic.txt') self.assertEqual(csName, 'default') self.assertEqual(ruleIndex, 3) rules.removeRule(0) rules.removeRule(0) rules.removeRule(0) rules.insertRule(0, 'exr files', 'cs1', '*', '[eE][xX][r]') cfg.setFileRules(rules) csName, ruleIndex = cfg.getColorSpaceFromFilepath( '/An/Arbitrary/Path/MyFile.exr') self.assertEqual(ruleIndex, 0) csName, ruleIndex = cfg.getColorSpaceFromFilepath( '/An/Arbitrary/Path/MyFile.eXr') self.assertEqual(ruleIndex, 0) csName, ruleIndex = cfg.getColorSpaceFromFilepath( '/An/Arbitrary/Path/MyFile.EXR') self.assertEqual(ruleIndex, 1) # Default rule. R must be lower case. csName, ruleIndex = cfg.getColorSpaceFromFilepath( '/An/Arbitrary/Path/MyFileexr') self.assertEqual(ruleIndex, 1) # Default rule. csName, ruleIndex = cfg.getColorSpaceFromFilepath( '/An/Arbitrary/Path/MyFile.jpeg') self.assertEqual(ruleIndex, 1) # Default rule. csName, ruleIndex = cfg.getColorSpaceFromFilepath( '/An/Arbitrary.exr/Path/MyFileexr') self.assertEqual(ruleIndex, 1) # Default rule. csName, ruleIndex = cfg.getColorSpaceFromFilepath('') self.assertEqual(ruleIndex, 1) # Default rule.
def aces_rec709_output(): """ACES Rec. 709 output""" col_space = OCIO.ColorSpace(name="Output - ACES Rec. 709", family="Output") col_space.setDescription("ACES Rec. 709 output transform") col_space.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) group_xform = OCIO.GroupTransform() group_xform.push_back( OCIO.FileTransform("Log2_48_nits_Shaper_to_linear.spi1d", interpolation=OCIO.Constants.INTERP_LINEAR, direction=OCIO.Constants.TRANSFORM_DIR_INVERSE)) group_xform.push_back( OCIO.FileTransform("Log2_48_nits_Shaper.RRT.Rec.709.spi3d", interpolation=OCIO.Constants.INTERP_TETRAHEDRAL)) col_space.setTransform(group_xform, OCIO.Constants.COLORSPACE_DIR_FROM_REFERENCE) group_xform = OCIO.GroupTransform() group_xform.push_back( OCIO.FileTransform("InvRRT.Rec.709.Log2_48_nits_Shaper.spi3d", interpolation=OCIO.Constants.INTERP_TETRAHEDRAL)) group_xform.push_back( OCIO.FileTransform("Log2_48_nits_Shaper_to_linear.spi1d", interpolation=OCIO.Constants.INTERP_LINEAR, direction=OCIO.Constants.TRANSFORM_DIR_FORWARD)) col_space.setTransform(group_xform, OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE) return col_space
def ncd_colorspace(): """Non-color data""" col_space = OCIO.ColorSpace(name="ncd", family="Data") col_space.setDescription("Non-color data") col_space.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) col_space.setIsData(True) return col_space
def test_canonical_name(self): # Test these Config function: getCanonicalName. cfg = OCIO.Config().CreateRaw() # add a named transform and a color space. nt = OCIO.NamedTransform(name='nt1', aliases=['alias1', 'test1'], forwardTransform=OCIO.RangeTransform()) cfg.addNamedTransform(nt) cs = OCIO.ColorSpace(name='cs1', aliases=['cs test', 'other']) cs.setTransform(OCIO.RangeTransform(), OCIO.COLORSPACE_DIR_TO_REFERENCE) cfg.addColorSpace(cs) cfg.setRole('role', 'cs1') self.assertEqual(cfg.getCanonicalName(''), '') self.assertEqual(cfg.getCanonicalName('not found'), '') self.assertEqual(cfg.getCanonicalName('roLE'), 'cs1') self.assertEqual(cfg.getCanonicalName('CS1'), 'cs1') self.assertEqual(cfg.getCanonicalName('Other'), 'cs1') self.assertEqual(cfg.getCanonicalName('CS test'), 'cs1') self.assertEqual(cfg.getCanonicalName('NT1'), 'nt1') self.assertEqual(cfg.getCanonicalName('Alias1'), 'nt1') self.assertEqual(cfg.getCanonicalName('Test1'), 'nt1')
def make_exp_color_space(cs_name="gm24_min_0_max_1", description="experiment color space", allocation=OCIO.Constants.ALLOCATION_UNIFORM, allocationVars=[0, 1], eotf_lut_file=LUT_FILE_GAMMA24, is_3dlut=False): cs = OCIO.ColorSpace(name=cs_name) cs.setDescription(description) cs.setFamily("experiment") cs.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) cs.setAllocation(allocation) cs.setAllocationVars(allocationVars) # to reference file_to_ref = OCIO.FileTransform(eotf_lut_file, direction=DIRECTION_OPS['forward'], interpolation=INTERPOLATION_OPS['linear']) cs.setTransform(file_to_ref, COLOR_SPACE_DIRECTION['to_reference']) # from reference if is_3dlut: file_from_ref = OCIO.FileTransform( eotf_lut_file, direction=DIRECTION_OPS['forward'], interpolation=INTERPOLATION_OPS['linear']) cs.setTransform(file_from_ref, COLOR_SPACE_DIRECTION['from_reference']) else: file_from_ref = OCIO.FileTransform( eotf_lut_file, direction=DIRECTION_OPS['inverse'], interpolation=INTERPOLATION_OPS['linear']) cs.setTransform(file_from_ref, COLOR_SPACE_DIRECTION['from_reference']) return cs
def test_constructor_without_keyword(self): """ Test ColorSpace constructor without keywords and validate its values. """ cs = OCIO.ColorSpace(OCIO.REFERENCE_SPACE_SCENE, 'test', ['alias1', 'alias2'], 'ocio family', 'scene-linear', 'My_Equality', 'This is a test colourspace!', OCIO.BIT_DEPTH_F32, False, OCIO.ALLOCATION_LG2, [0.0, 1.0]) self.assertEqual(cs.getName(), 'test') aliases = cs.getAliases() self.assertEqual(len(aliases), 2) self.assertEqual(aliases[0], 'alias1') self.assertEqual(aliases[1], 'alias2') self.assertEqual(cs.getFamily(), 'ocio family') self.assertEqual(cs.getEncoding(), 'scene-linear') self.assertEqual(cs.getEqualityGroup(), 'My_Equality') self.assertEqual(cs.getDescription(), 'This is a test colourspace!') self.assertEqual(cs.getBitDepth(), OCIO.BIT_DEPTH_F32) self.assertFalse(cs.isData()) self.assertEqual(cs.getAllocation(), OCIO.ALLOCATION_LG2) self.assertEqual(cs.getAllocationVars(), [0.0, 1.0])
def raw_colorspace(): """Raw""" col_space = OCIO.ColorSpace(name="Utility - Raw", family="Utility") col_space.setDescription("Raw data") col_space.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) col_space.setIsData(True) return col_space
def make_raw_color_space(): cs = OCIO.ColorSpace(name='raw') cs.setDescription("raw") cs.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) cs.setAllocation(OCIO.Constants.ALLOCATION_UNIFORM) cs.setAllocationVars([0, 1]) return cs
def test_constructor_with_keyword(self): """ Test ColorSpace constructor with keywords and validate its values. """ # With keywords in their proper order. cs = OCIO.ColorSpace(name='test', family='ocio family', encoding='scene-linear', equalityGroup='My_Equality', description='This is a test colourspace!', bitDepth=OCIO.BIT_DEPTH_F32, isData=False, allocation=OCIO.ALLOCATION_LG2, allocationVars=[0.0, 1.0]) self.assertEqual(cs.getName(), 'test') self.assertEqual(cs.getFamily(), 'ocio family') self.assertEqual(cs.getEncoding(), 'scene-linear') self.assertEqual(cs.getEqualityGroup(), 'My_Equality') self.assertEqual(cs.getDescription(), 'This is a test colourspace!') self.assertEqual(cs.getBitDepth(), OCIO.BIT_DEPTH_F32) self.assertFalse(cs.isData()) self.assertEqual(cs.getAllocation(), OCIO.ALLOCATION_LG2) self.assertEqual(cs.getAllocationVars(), [0.0, 1.0]) # With keyword not in their proper order. cs2 = OCIO.ColorSpace(family='ocio family', name='test', isData=False, allocationVars=[0.0, 1.0], allocation=OCIO.ALLOCATION_LG2, description='This is a test colourspace!', equalityGroup='My_Equality', encoding='scene-linear', bitDepth=OCIO.BIT_DEPTH_F32) self.assertEqual(cs2.getName(), 'test') self.assertEqual(cs2.getFamily(), 'ocio family') self.assertEqual(cs2.getEncoding(), 'scene-linear') self.assertEqual(cs2.getEqualityGroup(), 'My_Equality') self.assertEqual(cs2.getDescription(), 'This is a test colourspace!') self.assertEqual(cs2.getBitDepth(), OCIO.BIT_DEPTH_F32) self.assertFalse(cs2.isData()) self.assertEqual(cs2.getAllocation(), OCIO.ALLOCATION_LG2) self.assertEqual(cs2.getAllocationVars(), [0.0, 1.0])
def aces_2065_1_colorspace(): """ACES 2065-1""" col_space = OCIO.ColorSpace(name="ACES - ACES2065-1", family="ACES") col_space.setDescription("Scene-linear, high dynamic range, AP0 primaries") col_space.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) col_space.setAllocationVars([-8.0, 5.0, 0.00390625]) col_space.setAllocation(OCIO.Constants.ALLOCATION_LG2) return col_space
def test_aliases(self): """ Test NamedTransform aliases. """ cs = OCIO.ColorSpace() self.assertEqual(cs.getName(), '') aliases = cs.getAliases() self.assertEqual(len(aliases), 0) cs.addAlias('alias1') aliases = cs.getAliases() self.assertEqual(len(aliases), 1) self.assertEqual(aliases[0], 'alias1') cs.addAlias('alias2') aliases = cs.getAliases() self.assertEqual(len(aliases), 2) self.assertEqual(aliases[0], 'alias1') self.assertEqual(aliases[1], 'alias2') # Alias is already there, not added. cs.addAlias('Alias2') aliases = cs.getAliases() self.assertEqual(len(aliases), 2) self.assertEqual(aliases[0], 'alias1') self.assertEqual(aliases[1], 'alias2') # Name might remove an alias. cs.setName('name') aliases = cs.getAliases() self.assertEqual(len(aliases), 2) cs.setName('alias2') aliases = cs.getAliases() self.assertEqual(len(aliases), 1) self.assertEqual(aliases[0], 'alias1') # Removing an alias. cs.addAlias('to remove') aliases = cs.getAliases() self.assertEqual(len(aliases), 2) cs.removeAlias('not found') aliases = cs.getAliases() self.assertEqual(len(aliases), 2) cs.removeAlias('to REMOVE') aliases = cs.getAliases() self.assertEqual(len(aliases), 1) cs.clearAliases() aliases = cs.getAliases() self.assertEqual(len(aliases), 0)
def aces_colorspace(): """The Academy Color Encoding System reference color space (ACES 2065-1)""" col_space = OCIO.ColorSpace(name="aces", family="ACES") col_space.setDescription( "The Academy Color Encoding System reference color space (ACES 2065-1)" ) col_space.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) col_space.setAllocationVars([-8.0, 5.0, 0.00390625]) col_space.setAllocation(OCIO.Constants.ALLOCATION_LG2) return col_space
def test_get_processor_errors(self): """ Test the getProcessor function failures. """ cfg = OCIO.Config().CreateRaw() pipeline = OCIO.LegacyViewingPipeline() # No DisplayViewTransform. with self.assertRaises(OCIO.Exception): pipeline.getProcessor(cfg) # DisplayViewTransform refers to elements that are not part of config. dvt = OCIO.DisplayViewTransform(src='colorspace1', display='sRGB', view='view1') pipeline.setDisplayViewTransform(dvt) with self.assertRaises(OCIO.Exception): pipeline.getProcessor(cfg) # Add display and view. cfg.addDisplayView(display='sRGB', view='view1', colorSpaceName='colorspace1') with self.assertRaises(OCIO.Exception): pipeline.getProcessor(cfg) # Add color space. cs = OCIO.ColorSpace(name='colorspace1') cfg.addColorSpace(cs) # Processor can now be created. pipeline.getProcessor(cfg) mat = OCIO.MatrixTransform() mat.setOffset([0.1, 0.2, 0.3, 0.]) pipeline.setLinearCC(mat) # Scene_linear role is missing. with self.assertRaises(OCIO.Exception): pipeline.getProcessor(cfg) cfg.setRole(role='scene_linear', colorSpaceName='colorspace1') # Processor can now be created. pipeline.getProcessor(cfg) # Print the pipeline. self.assertEqual(str(pipeline), ( 'DisplayViewTransform: <DisplayViewTransform direction=forward, ' 'src=colorspace1, display=sRGB, view=view1, , looksBypass=1>, ' 'LinearCC: <MatrixTransform direction=forward, fileindepth=unknown, ' 'fileoutdepth=unknown, matrix=1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1, offset=0.1 0.2 0.3 0>' ))
def get_camera_colorspaces(family=""): colorspaces = [] # get Camera Log colorspaces from Builtins for name, description in ocio.BuiltinTransformRegistry().getBuiltins(): if name.endswith("to_ACES2065-1"): colorspaces.append( ocio.ColorSpace( name=description.split("Convert ")[-1].split(" to ")[0], family=family, encoding="log", toReference=ocio.BuiltinTransform(name), )) return colorspaces
def test_copy(self): """ Test the deepcopy() method. """ cfg = OCIO.Config.CreateRaw() cfg.setMajorVersion(2) cfg.setMinorVersion(1) cfg.setName('test config') cfg.setDescription('test description') cfg.addColorSpace( OCIO.ColorSpace(OCIO.REFERENCE_SPACE_DISPLAY, "display_cs", toReference=OCIO.CDLTransform(sat=1.5))) cfg.addColorSpace( OCIO.ColorSpace(OCIO.REFERENCE_SPACE_SCENE, "raw", isData=True)) rules = OCIO.FileRules() rules.insertRule(0, 'A', 'raw', '*', 'exr') rules.insertRule(1, 'B', 'display_cs', '*', 'png') cfg.setFileRules(rules) other = copy.deepcopy(cfg) self.assertFalse(other is cfg) self.assertEqual(other.getMajorVersion(), cfg.getMajorVersion()) self.assertEqual(other.getMinorVersion(), cfg.getMinorVersion()) self.assertEqual(other.getName(), cfg.getName()) self.assertEqual(other.getDescription(), cfg.getDescription()) self.assertEqual(list(other.getColorSpaceNames()), list(cfg.getColorSpaceNames())) self.assertEqual(other.getFileRules().getNumEntries(), cfg.getFileRules().getNumEntries()) # Check that the file rules are not shared between the two config instances. rules.removeRule(0) other.setFileRules(rules) self.assertEqual(other.getFileRules().getNumEntries(), cfg.getFileRules().getNumEntries() - 1)
def acescg_colorspace(): """ACEScg""" col_space = OCIO.ColorSpace(name="ACES - ACEScg", family="ACES") col_space.setDescription("Scene-linear, high dynamic range, AP1 primaries") col_space.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) col_space.setAllocationVars([-8.0, 5.0, 0.00390625]) col_space.setAllocation(OCIO.Constants.ALLOCATION_LG2) group_xform = OCIO.GroupTransform() group_xform.push_back( OCIO.FileTransform("AP1_to_AP0.spimtx", direction=OCIO.Constants.TRANSFORM_DIR_FORWARD)) col_space.setTransform(group_xform, OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE) return col_space
def test_constructor_without_parameter(self): """ Test ColorSpace default constructor and validate its values. """ cs = OCIO.ColorSpace() self.assertEqual(cs.getName(), '') self.assertEqual(cs.getFamily(), '') self.assertEqual(cs.getEqualityGroup(), '') self.assertEqual(cs.getDescription(), '') self.assertEqual(cs.getBitDepth(), OCIO.BIT_DEPTH_UNKNOWN) self.assertFalse(cs.isData()) self.assertEqual(cs.getAllocation(), OCIO.ALLOCATION_UNIFORM) self.assertEqual(cs.getAllocationVars(), [])
def acesproxy_colorspace(): """ACESproxy""" col_space = OCIO.ColorSpace(name="ACES - ACESproxy", family="ACES") col_space.setDescription("ACESproxy colorspace, gamma and primaries") col_space.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) col_space.setAllocationVars([0, 1]) col_space.setAllocation(OCIO.Constants.ALLOCATION_UNIFORM) group_xform = OCIO.GroupTransform() group_xform.push_back( OCIO.FileTransform("ACESproxy_to_linear.spi1d", interpolation=OCIO.Constants.INTERP_LINEAR, direction=OCIO.Constants.TRANSFORM_DIR_FORWARD)) group_xform.push_back( OCIO.FileTransform("AP1_to_AP0.spimtx", direction=OCIO.Constants.TRANSFORM_DIR_FORWARD)) col_space.setTransform(group_xform, OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE) return col_space
def rec709_colorspace(): """Rec. 709""" col_space = OCIO.ColorSpace(name="Input - Rec. 709", family="Input") col_space.setDescription( "Rec. 709 colorspace, Rec. 1886 gamma, Rec. 709 primaries") col_space.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) col_space.setAllocationVars([0, 1]) col_space.setAllocation(OCIO.Constants.ALLOCATION_UNIFORM) group_xform = OCIO.GroupTransform() group_xform.push_back( OCIO.FileTransform("rec1886_to_linear.spi1d", interpolation=OCIO.Constants.INTERP_LINEAR, direction=OCIO.Constants.TRANSFORM_DIR_FORWARD)) group_xform.push_back( OCIO.FileTransform("sRGB_to_AP0.spimtx", direction=OCIO.Constants.TRANSFORM_DIR_FORWARD)) col_space.setTransform(group_xform, OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE) return col_space
def add_colourspace( config, family, name, description, transforms=None, aliases=[], direction=PyOpenColorIO.ColorSpaceDirection. COLORSPACE_DIR_FROM_REFERENCE, referencespace=PyOpenColorIO.ReferenceSpaceType.REFERENCE_SPACE_SCENE, isdata=False, debug=False): colourspace_family = family colourspace_name = name colourspace_description = description colourspace = PyOpenColorIO.ColorSpace(referenceSpace=referencespace, family=colourspace_family, name=colourspace_name, aliases=aliases, isData=isdata) colourspace.setDescription(colourspace_description) if transforms is not None: if len(transforms) > 1: transforms = PyOpenColorIO.GroupTransform(transforms) else: transforms = transforms[0] colourspace.setTransform(transforms, direction) if debug is True: # DEBUG shader_desc = PyOpenColorIO.GpuShaderDesc.CreateShaderDesc( language=PyOpenColorIO.GPU_LANGUAGE_GLSL_4_0) processor = config.getProcessor(transforms).getDefaultGPUProcessor() processor.extractGpuShaderInfo(shader_desc) print("*****[{}]:\n{}".format(name, shader_desc.getShaderText())) config.addColorSpace(colourspace) return config, colourspace
def make_typical_color_space(cs_name=BT1886_CS, description="bt1886", allocation=OCIO.Constants.ALLOCATION_UNIFORM, allocationVars=[0, 1], eotf_lut_file=LUT_FILE_GAMMA24, to_ref_mtx=BT709_TO_ACES2065_1_MTX, from_ref_mtx=ACES2065_1_TO_BT709_MTX): """ 典型的な Color Space を作成する。 """ cs = OCIO.ColorSpace(name=get_colorspace_name(cs_name)) cs.setDescription(description) cs.setFamily(get_eotf_name(cs_name)) cs.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) cs.setAllocation(allocation) cs.setAllocationVars(allocationVars) # to reference file_to_ref = OCIO.FileTransform(eotf_lut_file, direction=DIRECTION_OPS['forward'], interpolation=INTERPOLATION_OPS['linear']) matrix_to_ref = OCIO.MatrixTransform(matrix=to_ref_mtx, direction=DIRECTION_OPS['forward']) group_to_ref = OCIO.GroupTransform([file_to_ref, matrix_to_ref]) cs.setTransform(group_to_ref, COLOR_SPACE_DIRECTION['to_reference']) # from reference file_from_ref = OCIO.FileTransform( eotf_lut_file, direction=DIRECTION_OPS['inverse'], interpolation=INTERPOLATION_OPS['linear']) matrix_from_ref = OCIO.MatrixTransform(matrix=from_ref_mtx, direction=DIRECTION_OPS['forward']) group_from_ref = OCIO.GroupTransform([matrix_from_ref, file_from_ref]) cs.setTransform(group_from_ref, COLOR_SPACE_DIRECTION['from_reference']) return cs
def test_interface(self): cs = OCIO.ColorSpace() cs.setName("mynewcolspace") self.assertEqual("mynewcolspace", cs.getName()) cs.setFamily("fam1") self.assertEqual("fam1", cs.getFamily()) cs.setEqualityGroup("match1") self.assertEqual("match1", cs.getEqualityGroup()) cs.setDescription("this is a test") self.assertEqual("this is a test", cs.getDescription()) cs.setBitDepth(OCIO.Constants.BIT_DEPTH_F16) self.assertEqual(OCIO.Constants.BIT_DEPTH_F16, cs.getBitDepth()) cs.setIsData(False) self.assertEqual(False, cs.isData()) cs.setAllocation(OCIO.Constants.ALLOCATION_LG2) self.assertEqual(OCIO.Constants.ALLOCATION_LG2, cs.getAllocation()) cs.setAllocationVars([0.1, 0.2, 0.3]) self.assertEqual(3, len(cs.getAllocationVars())) lt = OCIO.LogTransform() lt.setBase(10.0) cs.setTransform(lt, OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE) ott = cs.getTransform(OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE) self.assertEquals(10.0, ott.getBase())
def flog_colorspace(): """Fujifilm F-Log color space""" col_space = OCIO.ColorSpace(name="flog", family="Fujifilm") col_space.setDescription("Fujifilm F-Log color space") col_space.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) col_space.setAllocationVars([0, 1]) col_space.setAllocation(OCIO.Constants.ALLOCATION_UNIFORM) group_xform = OCIO.GroupTransform() group_xform.push_back( OCIO.FileTransform( "flog_to_linear.cube", interpolation=OCIO.Constants.INTERP_LINEAR, direction=OCIO.Constants.TRANSFORM_DIR_FORWARD, ) ) group_xform.push_back( OCIO.FileTransform( "rec2020_to_ap0.cat02.spimtx", direction=OCIO.Constants.TRANSFORM_DIR_FORWARD, ) ) col_space.setTransform(group_xform, OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE) return col_space
def OCIOCreateTransforms(config, transforms): # for name, description, family, isdata, allocationvars, bitdepth, type, \ # variables, direction in transforms: for transform_details in transforms: colorspace = PyOpenColorIO.ColorSpace() colorspace.setName(transform_details["name"]) colorspace.setDescription(transform_details["description"]) colorspace.setFamily(transform_details["family"]) colorspace.setIsData(transform_details["isdata"]) colorspace.setAllocationVars([ transform_details["allocationvars"]["from"], transform_details["allocationvars"]["to"] ]) colorspace.setAllocation(transform_details["allocationvars"]["type"]) colorspace.setBitDepth(transform_details["bitdepth"]) if transform_details["type"] is "ExponentTransform": transform = PyOpenColorIO.ExponentTransform([ transform_details["variables"]["exponentR"], transform_details["variables"]["exponentG"], transform_details["variables"]["exponentB"], transform_details["variables"]["exponentA"] ]) colorspace.setTransform(transform, transform_details["direction"]) config.addColorSpace(colorspace)
def colorspace_factory(name, family=None, encoding=None, categories=None, description=None, equality_group=None, bit_depth=None, allocation=None, allocation_vars=None, to_reference_transform=None, from_reference_transform=None, is_data=None, base_colorspace=None): """ *OpenColorIO* colorspace factory. Parameters ---------- name : unicode *OpenColorIO* colorspace name. family : unicode, optional *OpenColorIO* colorspace family. encoding : unicode, optional *OpenColorIO* colorspace encoding. categories : array_like, optional *OpenColorIO* colorspace categories. description : unicode, optional *OpenColorIO* colorspace description. equality_group : unicode, optional *OpenColorIO* colorspace equality_group. bit_depth : int, optional *OpenColorIO* colorspace bit depth. allocation : int, optional *OpenColorIO* colorspace allocation type. allocation_vars : tuple, optional *OpenColorIO* colorspace allocation variables. to_reference_transform : object, optional *To Reference* *OpenColorIO* colorspace transform. from_reference_transform : object, optional *From Reference* *OpenColorIO* colorspace transform. is_data : bool, optional Whether the colorspace represents data. base_colorspace : ColorSpace, optional *OpenColorIO* base colorspace inherited for bit depth, allocation, allocation variables, and to/from reference transforms. Returns ------- ColorSpace *OpenColorIO* colorspace. """ import PyOpenColorIO as ocio if categories is None: categories = [] if bit_depth is None: bit_depth = ocio.BIT_DEPTH_F32 if base_colorspace is not None: colorspace = base_colorspace else: colorspace = ocio.ColorSpace() colorspace.setBitDepth(bit_depth) if allocation is not None: colorspace.setAllocation(allocation) if allocation_vars is not None: colorspace.setAllocationVars(allocation_vars) if to_reference_transform is not None: colorspace.setTransform(to_reference_transform, ocio.COLORSPACE_DIR_TO_REFERENCE) if from_reference_transform is not None: colorspace.setTransform(from_reference_transform, ocio.COLORSPACE_DIR_FROM_REFERENCE) colorspace.setName(name) if family is not None: colorspace.setFamily(family) if encoding is not None: colorspace.setEncoding(encoding) for category in categories: colorspace.addCategory(category) if description is not None: colorspace.setDescription(description) if equality_group is not None: colorspace.setEqualityGroup(equality_group) if is_data is not None: colorspace.setIsData(is_data) return colorspace
def setUp(self): self.colorspace = OCIO.ColorSpace() self.log_tr = OCIO.LogTransform(10)
def test_interface(self): _cfg = OCIO.Config().CreateFromStream(self.SIMPLE_PROFILE) _cfge = _cfg.createEditableCopy() _cfge.clearEnvironmentVars() self.assertEqual(0, _cfge.getNumEnvironmentVars()) _cfge.addEnvironmentVar("FOO", "test1") _cfge.addEnvironmentVar("FOO2", "test2${FOO}") self.assertEqual(2, _cfge.getNumEnvironmentVars()) self.assertEqual("FOO", _cfge.getEnvironmentVarNameByIndex(0)) self.assertEqual("FOO2", _cfge.getEnvironmentVarNameByIndex(1)) self.assertEqual("test1", _cfge.getEnvironmentVarDefault("FOO")) self.assertEqual("test2${FOO}", _cfge.getEnvironmentVarDefault("FOO2")) self.assertEqual("test2test1", _cfge.getCurrentContext().resolveStringVar("${FOO2}")) self.assertEqual({ 'FOO': 'test1', 'FOO2': 'test2${FOO}' }, _cfge.getEnvironmentVarDefaults()) _cfge.clearEnvironmentVars() self.assertEqual(0, _cfge.getNumEnvironmentVars()) self.assertEqual("luts", _cfge.getSearchPath()) _cfge.setSearchPath("otherdir") self.assertEqual("otherdir", _cfge.getSearchPath()) _cfge.sanityCheck() _cfge.setDescription("testdesc") self.assertEqual("testdesc", _cfge.getDescription()) self.assertEqual(self.SIMPLE_PROFILE, _cfg.serialize()) #self.assertEqual("$07d1fb1509eeae1837825fd4242f8a69:$885ad1683add38a11f7bbe34e8bf9ac0", # _cfg.getCacheID()) con = _cfg.getCurrentContext() self.assertNotEqual(0, con.getNumStringVars()) #self.assertEqual("", _cfg.getCacheID(con)) #self.assertEqual("", _cfge.getWorkingDir()) _cfge.setWorkingDir("/foobar") self.assertEqual("/foobar", _cfge.getWorkingDir()) self.assertEqual(3, _cfge.getNumColorSpaces()) self.assertEqual("lnh", _cfge.getColorSpaceNameByIndex(1)) lnh = _cfge.getColorSpace("lnh") self.assertEqual("ln", lnh.getFamily()) self.assertEqual(0, _cfge.getIndexForColorSpace("foobar")) cs = OCIO.ColorSpace() cs.setName("blah") _cfge.addColorSpace(cs) self.assertEqual(3, _cfge.getIndexForColorSpace("blah")) #_cfge.clearColorSpaces() #_cfge.parseColorSpaceFromString("foo") self.assertEqual(False, _cfg.isStrictParsingEnabled()) _cfge.setStrictParsingEnabled(True) self.assertEqual(True, _cfge.isStrictParsingEnabled()) self.assertEqual(2, _cfge.getNumRoles()) self.assertEqual(False, _cfg.hasRole("foo")) _cfge.setRole("foo", "vd8") self.assertEqual(3, _cfge.getNumRoles()) self.assertEqual(True, _cfge.hasRole("foo")) self.assertEqual("foo", _cfge.getRoleName(1)) self.assertEqual("sRGB", _cfge.getDefaultDisplay()) self.assertEqual(1, _cfge.getNumDisplays()) self.assertEqual("sRGB", _cfge.getDisplay(0)) self.assertEqual("Film1D", _cfge.getDefaultView("sRGB")) self.assertEqual(2, _cfge.getNumViews("sRGB")) self.assertEqual("Raw", _cfge.getView("sRGB", 1)) self.assertEqual("vd8", _cfge.getDisplayColorSpaceName("sRGB", "Film1D")) self.assertEqual("", _cfg.getDisplayLooks("sRGB", "Film1D")) _cfge.addDisplay("foo", "bar", "foo", "wee") _cfge.clearDisplays() _cfge.setActiveDisplays("sRGB") self.assertEqual("sRGB", _cfge.getActiveDisplays()) _cfge.setActiveViews("Film1D") self.assertEqual("Film1D", _cfge.getActiveViews()) luma = _cfge.getDefaultLumaCoefs() self.assertAlmostEqual(0.2126, luma[0], delta=1e-8) _cfge.setDefaultLumaCoefs([0.1, 0.2, 0.3]) tnewluma = _cfge.getDefaultLumaCoefs() self.assertAlmostEqual(0.1, tnewluma[0], delta=1e-8) self.assertEqual(0, _cfge.getNumLooks()) lk = OCIO.Look() lk.setName("coollook") lk.setProcessSpace("somespace") et = OCIO.ExponentTransform() et.setValue([0.1, 0.2, 0.3, 0.4]) lk.setTransform(et) iet = OCIO.ExponentTransform() iet.setValue([-0.1, -0.2, -0.3, -0.4]) lk.setInverseTransform(iet) _cfge.addLook(lk) self.assertEqual(1, _cfge.getNumLooks()) self.assertEqual("coollook", _cfge.getLookNameByIndex(0)) glk = _cfge.getLook("coollook") self.assertEqual("somespace", glk.getProcessSpace()) _cfge.clearLooks() self.assertEqual(0, _cfge.getNumLooks()) #getProcessor(context, srcColorSpace, dstColorSpace) #getProcessor(context, srcName,dstName); #getProcessor(transform); #getProcessor(transform, direction); #getProcessor(context, transform, direction); _proc = _cfg.getProcessor("lnh", "vd8") self.assertEqual(False, _proc.isNoOp()) self.assertEqual(True, _proc.hasChannelCrosstalk()) #float packedpix[] = new float[]{0.48f, 0.18f, 0.9f, 1.0f, # 0.48f, 0.18f, 0.18f, 1.0f, # 0.48f, 0.18f, 0.18f, 1.0f, # 0.48f, 0.18f, 0.18f, 1.0f }; #FloatBuffer buf = ByteBuffer.allocateDirect(2 * 2 * 4 * Float.SIZE / 8).asFloatBuffer(); #buf.put(packedpix); #PackedImageDesc foo = new PackedImageDesc(buf, 2, 2, 4); #_proc.apply(foo); #FloatBuffer wee = foo.getData(); #self.assertEqual(-2.4307251581696764E-35f, wee.get(2), 1e-8); # TODO: these should work in-place rgbfoo = _proc.applyRGB([0.48, 0.18, 0.18]) self.assertAlmostEqual(1.9351075, rgbfoo[0], delta=1e-7) # TODO: these should work in-place rgbafoo = _proc.applyRGBA([0.48, 0.18, 0.18, 1.0]) self.assertAlmostEqual(1.0, rgbafoo[3], delta=1e-8) #self.assertEqual("$a92ef63abd9edf61ad5a7855da064648", _proc.getCpuCacheID()) del _cfge del _cfg
config.setRole(PyOpenColorIO.Constants.ROLE_COLOR_PICKING, config_name + " Log") config.setRole(PyOpenColorIO.Constants.ROLE_DATA, "Non-Colour Data") config.setRole(PyOpenColorIO.Constants.ROLE_DEFAULT, config_name + " Log") config.setRole(PyOpenColorIO.Constants.ROLE_MATTE_PAINT, config_name + " Log") config.setRole(PyOpenColorIO.Constants.ROLE_TEXTURE_PAINT, config_name + " Log") # Basic BT.2020 scene referred linear colourspace colorspace = PyOpenColorIO.ColorSpace(family="Colorimetry", name="BT.2020 SR Linear") colorspace.setDescription("REC.2020 scene referred linear") colorspace.setBitDepth(PyOpenColorIO.Constants.BIT_DEPTH_F32) colorspace.setAllocationVars([ numpy.log2(calculate_ev_to_sr(minimum_exposure, sr_middle_grey)), numpy.log2(calculate_ev_to_sr(maximum_exposure, sr_middle_grey)) ]) colorspace.setAllocation(PyOpenColorIO.Constants.ALLOCATION_LG2) config.addColorSpace(colorspace) colorspace = PyOpenColorIO.ColorSpace(family="Core", name="Non-Colour Data") colorspace.setDescription("Non-Colour Data") colorspace.setBitDepth(PyOpenColorIO.Constants.BIT_DEPTH_F32)
#!/usr/bin/env python from __future__ import print_function import sys import PyOpenColorIO as OCIO config = OCIO.Config() config.setSearchPath(":".join(["luts"])) # ACES transforms cs = OCIO.ColorSpace(name="ACES - ACES2065-1", family="ACES") cs.setDescription("Scene-linear, high dynamic range, AP0 primaries") cs.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) cs.setAllocationVars([-8.0, 5.0, 0.00390625]) cs.setAllocation(OCIO.Constants.ALLOCATION_LG2) config.addColorSpace(cs) cs = OCIO.ColorSpace(name="ACES - ACEScg", family="ACES") cs.setDescription("Scene-linear, high dynamic range, AP1 primaries") cs.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) cs.setAllocationVars([-8.0, 5.0, 0.00390625]) cs.setAllocation(OCIO.Constants.ALLOCATION_LG2) gt = OCIO.GroupTransform() gt.push_back( OCIO.FileTransform("AP1_to_AP0.spimtx", direction=OCIO.Constants.TRANSFORM_DIR_FORWARD)) cs.setTransform(gt, OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE) config.addColorSpace(cs) cs = OCIO.ColorSpace(name="ACES - ACESproxy", family="ACES") cs.setDescription("ACESproxy colorspace, gamma and primaries") cs.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) cs.setAllocationVars([0, 1])
def convertImage(filename=__FILEIN__, fileOutName=__FILEOUT__, format='tif'): # open the file inputFile = oiio.ImageInput.open(filename) # check if the input file is valid if not inputFile: print 'Could not open: "' + filename + '"' print '\tError: "', oiio.geterror() return # get the spec of the input file spec = inputFile.spec() nchans = spec.nchannels # read the image and return the pixels as array type pixels = inputFile.read_image(oiio.FLOAT) # check that the pixels are ok if not pixels: print 'Could not read:', inputFile.geterror() return inputFile.close() #we're done with the file at this point # open the OCIO config config = OCIO.GetCurrentConfig() # get the processor to transform from linear to Asterix2_Film space newConfig = OCIO.Config() colorspace = OCIO.ColorSpace(name='rawInput') group = OCIO.GroupTransform() main_lut = OCIO.FileTransform( '/s/prodanim/asterix2/_sandbox/duda/tmp/ocioLut/test.csp', interpolation=OCIO.Constants.INTERP_LINEAR, direction=OCIO.Constants.TRANSFORM_DIR_FORWARD) group.push_back(main_lut) colorspace.setTransform(group, OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE) newConfig.addColorSpace(colorspace) colorspace = OCIO.ColorSpace(name='srgb8') group = OCIO.GroupTransform() main_lut = OCIO.FileTransform( '/s/prodanim/asterix2/_sandbox/duda/tmp/ocioLut/linTosrgbA2.csp', interpolation=OCIO.Constants.INTERP_LINEAR, direction=OCIO.Constants.TRANSFORM_DIR_FORWARD) group.push_back(main_lut) colorspace.setTransform(group, OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE) newConfig.addColorSpace(colorspace) colorspace = OCIO.ColorSpace(name='processedOutput') newConfig.addColorSpace(colorspace) newProccessor = newConfig.getProcessor( 'rawInput', 'srgb8', ) # apply the transform buf = newProccessor.applyRGBA(pixels) #processor = config.getProcessor('Asterix2_Film','srgb8') #buf = processor.applyRGBA(pixels) # convert the list to an array type imgTrans = array('f', [0, 0, 0, 0]) imgTrans.fromlist(buf) # create an output image output = oiio.ImageOutput.create(__FILEOUT__) # if tif format output as 16bit otherwise 8bit if format != 'tif': spec.set_format(oiio.UINT8) else: spec.set_format(oiio.UINT16) # open and write the data transformed output.open(__FILEOUT__, spec, oiio.Create) output.write_image(imgTrans) output.close()