def test_constructor_with_keyword(self): """ Test FileTransform constructor with keywords and validate its values. """ # With keywords in their proper order. file_tr = OCIO.FileTransform(src=self.TEST_SRC, cccId=self.TEST_ID, interpolation=self.TEST_INTERPOLATION, direction=self.TEST_DIRECTION) self.assertEqual(file_tr.getSrc(), self.TEST_SRC) self.assertEqual(file_tr.getCCCId(), self.TEST_ID) self.assertEqual(file_tr.getInterpolation(), self.TEST_INTERPOLATION) self.assertEqual(file_tr.getDirection(), self.TEST_DIRECTION) # With keywords not in their proper order. file_tr2 = OCIO.FileTransform(cccId=self.TEST_ID, direction=self.TEST_DIRECTION, src=self.TEST_SRC, interpolation=self.TEST_INTERPOLATION) self.assertEqual(file_tr2.getSrc(), self.TEST_SRC) self.assertEqual(file_tr2.getCCCId(), self.TEST_ID) self.assertEqual(file_tr2.getInterpolation(), self.TEST_INTERPOLATION) self.assertEqual(file_tr2.getDirection(), self.TEST_DIRECTION)
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 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 create_ocio_config(config=None): domain = np.array([-10, 15]) logarithmic_shaper = ocio.NamedTransform( name="Logarithmic Shaper", forwardTransform=ocio.AllocationTransform( vars=np.log2(0.18 * np.power(2.0, domain))), ) image_formation_transform = ocio.ViewTransform( name="Image Formation Transform", fromReference=ocio.GroupTransform([ ocio.FileTransform( src="AestheticTransferFunction.csp", interpolation=ocio.INTERP_TETRAHEDRAL, ), ]), ) named_transforms = [ logarithmic_shaper, ] view_transforms = [ image_formation_transform, ] cfg = config or ocu.baby_config() for vt in view_transforms: cfg.addViewTransform(vt) for nt in named_transforms: cfg.addNamedTransform(nt) return cfg
def load_input_transform(config, gt, base_path, input_elem): """ Add an OCIO transform to the supplied group transform to implement an ACES Input Transform. """ # # InputTransform ACES transformId case. # id_elem = input_elem.find('./aces:transformId', namespaces=NS) if id_elem is not None: aces_id = id_elem.text cs_name = search_colorspaces(config, aces_id) if cs_name is not None: print('Adding Input Transform from', cs_name, 'to ACES2065-1') gt.appendTransform( ocio.ColorSpaceTransform(cs_name, ACES, ocio.TRANSFORM_DIR_FORWARD) ) return else: raise ValueError("Could not find transform for transformId element: " + aces_id) # # InputTransform external LUT file case. # file_elem = input_elem.find('./aces:file', namespaces=NS) if file_elem is not None: lut_path = file_elem.text if lut_path is not None: lut_path = check_lut_path(base_path, lut_path) print('Adding Input Transform LUT file:', lut_path) gt.appendTransform( ocio.FileTransform(lut_path, '', ocio.INTERP_BEST, ocio.TRANSFORM_DIR_FORWARD) ) return # # InputTransform is an inverse OutputTransform case. # load_output_transform(config, gt, base_path, input_elem, is_inverse=True)
def create_builtin_transform(style): """ Creates an *OpenColorIO* builtin transform for given style. If the style does not exist, a placeholder transform is used in place of the builtin transform. Parameters ---------- style : unicode *OpenColorIO* builtin transform style Returns ------- BuiltinTransform *OpenColorIO* builtin transform for given style. """ import PyOpenColorIO as ocio builtin_transform = ocio.BuiltinTransform() try: builtin_transform.setStyle(style) except ocio.Exception: logging.warning(f'{style} style is not defined, ' f'using a placeholder "FileTransform" instead!') builtin_transform = ocio.FileTransform() builtin_transform.setSrc(style) return builtin_transform
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 test_get_processor(self): """ Test FileTransform default interpolation is valid and unknown interpolation is not valid. """ config = OCIO.Config.CreateRaw() test_file = '%s/lut1d_1.spi1d' % TEST_DATAFILES_DIR file_tr = OCIO.FileTransform(src=test_file) processor = config.getProcessor(file_tr) # INTERP_UNKNOWN is not a valid interpolation. file_tr.setInterpolation(OCIO.INTERP_UNKNOWN) with self.assertRaises(OCIO.Exception): processor = config.getProcessor(file_tr)
def test_constructor_with_positional(self): """ Test FileTransform constructor without keywords and validate its values. """ file_tr = OCIO.FileTransform(self.TEST_SRC, self.TEST_ID, self.TEST_INTERPOLATION, self.TEST_DIRECTION) self.assertEqual(file_tr.getSrc(), self.TEST_SRC) self.assertEqual(file_tr.getCCCId(), self.TEST_ID) self.assertEqual(file_tr.getInterpolation(), self.TEST_INTERPOLATION) self.assertEqual(file_tr.getDirection(), self.TEST_DIRECTION)
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 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 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_get_processor(self): """ Test that interpolation values of default and unknown do not cause a problem for getProcessor. """ config = OCIO.Config.CreateRaw() test_file = os.path.join(TEST_DATAFILES_DIR, 'lut1d_1.spi1d') file_tr = OCIO.FileTransform(src=test_file) processor = config.getProcessor(file_tr) # INTERP_UNKNOWN will be ignored by the LUT and a warning will be logged. curLogLevel = OCIO.GetLoggingLevel() OCIO.SetLoggingLevel(OCIO.LOGGING_LEVEL_NONE) file_tr.setInterpolation(OCIO.INTERP_UNKNOWN) processor = config.getProcessor(file_tr) OCIO.SetLoggingLevel(curLogLevel)
def buildLUTFilter(config, path, filter, filter_cache_id, texture_cache_id, extrapolate, force_shader_build=False): file_transform = PyOpenColorIO.FileTransform() file_transform.setSrc(path) file_transform.setInterpolation('linear') processor = config.getProcessor(file_transform) return buildProcessorFilter(processor, filter, filter_cache_id, texture_cache_id, extrapolate, force_shader_build)
def RegisterOCIOLut(): if not hasattr(mari.gl_render, "createPostFilter"): print "Error: This version of Mari does not support the mari.gl_render.createPostFilter API" return config = OCIO.Config() transform = OCIO.FileTransform( src=os.path.realpath(LUT_FILENAME), interpolation=OCIO.Constants.INTERP_LINEAR, direction=OCIO.Constants.TRANSFORM_DIR_FORWARD) processor = config.getProcessor(transform) shaderDesc = dict([('language', OCIO.Constants.GPU_LANGUAGE_GLSL_1_3), ('functionName', 'display_ocio_$ID_'), ('lut3DEdgeLen', LUT3D_SIZE)]) shaderText = processor.getGpuShaderText(shaderDesc) lut3d = processor.getGpuLut3D(shaderDesc) # Clear the existing color managment filter stack mari.gl_render.clearPostFilterStack() # Create variable pre-declarations desc = "sampler3D lut3d_ocio_$ID_;\n" desc += shaderText # Set the body of the filter body = "{ Out = display_ocio_$ID_(Out, lut3d_ocio_$ID_); }" # HACK: Increment a counter by 1 each time to force a refresh if not hasattr(mari, "ocio_lut_counter_hack"): mari.ocio_lut_counter_hack = 0 else: mari.ocio_lut_counter_hack += 1 ocio_lut_counter_hack = mari.ocio_lut_counter_hack # Create a new filter name = "OCIO %s v%d" % (os.path.basename(LUT_FILENAME), ocio_lut_counter_hack) postfilter = mari.gl_render.createPostFilter(name, desc, body) # Set the texture to use for the given sampler on this filter postfilter.setTexture3D("lut3d_ocio_$ID_", LUT3D_SIZE, LUT3D_SIZE, LUT3D_SIZE, postfilter.FORMAT_RGB, lut3d) # Append the filter to the end of the current list of filters mari.gl_render.appendPostFilter(postfilter)
def add_aesthetic_transfer_function_to_config(atf, config): min_exposure = -6.5 max_exposure = atf.ev_above_middle_grey middle_grey = atf.middle_grey_in domain = np.array([min_exposure, max_exposure]) lin_to_normalized_log_transform = ( ocio.AllocationTransform( vars=np.log2(middle_grey * np.power(2.0, domain)), allocation=ocio.ALLOCATION_LG2, ), ) normalized_log_to_lin_transform = ( ocio.AllocationTransform( vars=np.log2(middle_grey * np.power(2.0, domain)), allocation=ocio.ALLOCATION_LG2, direction=ocio.TRANSFORM_DIR_INVERSE, ), ) image_formation_transform = ocio.ViewTransform( name="Image Formation Transform", fromReference=ocio.GroupTransform( [ ocio.AllocationTransform( vars=np.log2(middle_grey * np.power(2.0, domain)), allocation=ocio.ALLOCATION_LG2, ), ocio.FileTransform( src=atf.get_filename(extension="clf"), interpolation=ocio.INTERP_TETRAHEDRAL, ), ] ), ) view_transforms = [ image_formation_transform, ] for vt in view_transforms: config.addViewTransform(vt) return config
def test_format_meta_data(self): # Test FormatMetadata related functions. cfg = OCIO.Config.CreateRaw() test_file = os.path.join(TEST_DATAFILES_DIR, 'clf', 'xyz_to_rgb.clf') file_tr = OCIO.FileTransform(src=test_file) proc = cfg.getProcessor(file_tr) # Remove the no-ops, since they are useless here. proc = proc.getOptimizedProcessor(OCIO.OPTIMIZATION_NONE) # For CTF, ProcessList metadata is added to processor FormatMetadata. proc_fmd = proc.getFormatMetadata() self.assertEqual(proc_fmd.getID(), '1d399a07-1936-49b8-9225-e6824790358c') proc_fmd_children = proc_fmd.getChildElements() self.assertEqual(len(proc_fmd_children), 1) child = next(proc_fmd_children) self.assertEqual(child.getElementName(), 'Description') self.assertEqual(child.getElementValue(), 'Example with a Matrix and Lut1D') # Each transform in the CTF file has a FormatMetadata. There are 3 transforms in this file. proc_tfmd = proc.getTransformFormatMetadata() self.assertEqual(len(proc_tfmd), 3) tfmd = next(proc_tfmd) self.assertEqual(tfmd.getID(), '72f85641-8c80-4bd6-b96b-a2f67ccb948a') tfmd_children = tfmd.getChildElements() self.assertEqual(len(tfmd_children), 1) child = next(tfmd_children) self.assertEqual(child.getElementName(), 'Description') self.assertEqual(child.getElementValue(), 'XYZ to sRGB matrix') tfmd = next(proc_tfmd) tfmd = next(proc_tfmd) self.assertEqual(tfmd.getID(), '4ed2af07-9319-430a-b18a-43368163c808') tfmd_children = tfmd.getChildElements() self.assertEqual(len(tfmd_children), 1) child = next(tfmd_children) self.assertEqual(child.getElementName(), 'Description') self.assertEqual(child.getElementValue(), 'x^1/1.8, with 0.95 and 0.9 scaling for G and B')
def load_cdl_working_space_transform(config, base_path, look_elem, is_to_direc): """ Return an OCIO transform for a CDL to/from working space transform. """ if is_to_direc: token = 'aces:toCdlWorkingSpace' else: token = 'aces:fromCdlWorkingSpace' elem = look_elem.find(token, namespaces=NS) if elem is not None: # # ACES transformId case. # id_elem = elem.find('./aces:transformId', namespaces=NS) if id_elem is not None: aces_id = id_elem.text cs_name = search_colorspaces(config, aces_id) if cs_name is not None: if is_to_direc: print(' Loading To-CDL-Working-Space Transform from ACES2065-1 to', cs_name) transform = ocio.ColorSpaceTransform(ACES, cs_name, ocio.TRANSFORM_DIR_FORWARD) else: print(' Loading From-CDL-Working-Space Transform from', cs_name, 'to ACES2065-1') transform = ocio.ColorSpaceTransform(cs_name, ACES, ocio.TRANSFORM_DIR_FORWARD) return transform else: raise ValueError("Could not find transform for transformId element: " + aces_id) # # External LUT file case. # file_elem = elem.find('./aces:file', namespaces=NS) if file_elem is not None: lut_path = file_elem.text if lut_path is not None: lut_path = check_lut_path(base_path, lut_path) if is_to_direc: print(' Loading To-CDL-Working-Space Transform file:', lut_path) else: print(' Loading From-CDL-Working-Space Transform file:', lut_path) transform = ocio.FileTransform(lut_path, '', ocio.INTERP_BEST, ocio.TRANSFORM_DIR_FORWARD) return transform return None
def test_format_meta_data(self): # Test FormatMetadata related functions. cfg = OCIO.Config.CreateRaw() test_file = '%s/clf/xyz_to_rgb.clf' % TEST_DATAFILES_DIR file_tr = OCIO.FileTransform(src=test_file) proc = cfg.getProcessor(file_tr) # For CTF, ProcessList metadata is added to processor FormatMetadata. proc_fmd = proc.getFormatMetadata() self.assertEqual(proc_fmd.getID(), '1d399a07-1936-49b8-9225-e6824790358c') proc_fmd_children = proc_fmd.getChildElements() self.assertEqual(len(proc_fmd_children), 1) child = next(proc_fmd_children) self.assertEqual(child.getElementName(), 'Description') self.assertEqual(child.getElementValue(), 'Example with a Matrix and Lut1D') # Each transform in the CTF file has a FormatMetadata. There are 2 transforms in this file. proc_tfmd = proc.getTransformFormatMetadata() self.assertEqual(len(proc_tfmd), 2) tfmd = next(proc_tfmd) self.assertEqual(tfmd.getID(), '72f85641-8c80-4bd6-b96b-a2f67ccb948a') tfmd_children = tfmd.getChildElements() self.assertEqual(len(tfmd_children), 1) child = next(tfmd_children) self.assertEqual(child.getElementName(), 'Description') self.assertEqual(child.getElementValue(), 'XYZ to sRGB matrix') tfmd = next(proc_tfmd) self.assertEqual(tfmd.getID(), '4ed2af07-9319-430a-b18a-43368163c808') tfmd_children = tfmd.getChildElements() self.assertEqual(len(tfmd_children), 1) child = next(tfmd_children) self.assertEqual(child.getElementName(), 'Description') self.assertEqual(child.getElementValue(), 'linear to approx. gamma corrected code values')
transform_colorimetry.setSrc("BT.709 SR Linear") transform_colorimetry.setDst("BT.2020 SR Linear") transform = PyOpenColorIO.GroupTransform() transform.setTransforms( [transform_transfer, transform_scale, transform_colorimetry]) colorspace.setTransform( transform, PyOpenColorIO.Constants.COLORSPACE_DIR_TO_REFERENCE) config.addColorSpace(colorspace) # Full colorimetric BT.2020 ST.2084 transform colorspace = PyOpenColorIO.ColorSpace(family="Colorimetry", name="BT.2020 ST.2084 Nonlinear") colorspace.setDescription("Colorimetric BT.2020 ST.2084 Transfer") transform_scale = PyOpenColorIO.MatrixTransform(ocio_st2084_scale) transform_transfer = PyOpenColorIO.FileTransform() transform_transfer.setSrc("st2084_to_nits.spi1d") transform_transfer.setInterpolation(PyOpenColorIO.Constants.INTERP_LINEAR) transform = PyOpenColorIO.GroupTransform() transform.setTransforms([transform_transfer, transform_scale]) colorspace.setTransform( transform, PyOpenColorIO.Constants.COLORSPACE_DIR_TO_REFERENCE) config.addColorSpace(colorspace) # Non colour data transform colorspace = PyOpenColorIO.ColorSpace(family="Core", name="Non-Colour Data") colorspace.setDescription("Non-Colour Data") colorspace.setBitDepth(PyOpenColorIO.Constants.BIT_DEPTH_F32) colorspace.setIsData(True)
# 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]) cs.setAllocation(OCIO.Constants.ALLOCATION_UNIFORM) gt = OCIO.GroupTransform() gt.push_back( OCIO.FileTransform("ACESproxy_to_linear.spi1d", interpolation=OCIO.Constants.INTERP_LINEAR, direction=OCIO.Constants.TRANSFORM_DIR_FORWARD)) gt.push_back( OCIO.FileTransform("AP1_to_AP0.spimtx",
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()
def setUp(self): self.file_tr = OCIO.FileTransform()
def process_look(config, gt, base_path, look_elem): """ Build a look transform and add it to the supplied OCIO group transform. """ if not must_apply(look_elem, 'Look'): return # # LookTransform ACES transformId case. # id_elem = look_elem.find('./aces:transformId', namespaces=NS) if id_elem is not None: aces_id = id_elem.text look_name = search_looktransforms(config, aces_id) if look_name is not None: print('Adding Look Transform:', look_name) gt.appendTransform( ocio.LookTransform(ACES, ACES, look_name, False, ocio.TRANSFORM_DIR_FORWARD) ) return else: raise ValueError("Could not find transform for transformId element: " + aces_id) # # LookTransform external LUT file case. # file_elem = look_elem.find('./aces:file', namespaces=NS) if file_elem is not None: lut_path = file_elem.text if lut_path is not None: lut_path = check_lut_path(base_path, lut_path) print('Adding Look Transform file:', lut_path) # Support CCC ID, if present, to identify which CDL in a CCC file to use. ccc_id = '' ccref_elem = look_elem.find('./cdl:ColorCorrectionRef', namespaces=NS) if ccref_elem is not None: ccc_id = ccref_elem.text print('Using CCC ID:', ccc_id) gt.appendTransform( ocio.FileTransform(lut_path, ccc_id, ocio.INTERP_BEST, ocio.TRANSFORM_DIR_FORWARD) ) return # # LookTransform ASC CDL case. # has_cdl, slopes, offsets, powers, sat = parse_cdl(look_elem) if has_cdl: ws_elem = look_elem.find('./aces:cdlWorkingSpace', namespaces=NS) if ws_elem is None: print('Adding CDL Transform') gt.appendTransform( ocio.CDLTransform(slopes, offsets, powers, sat) ) return # # Attempt to load the working space transforms. # to_transform = load_cdl_working_space_transform(config, base_path, ws_elem, True) from_transform = load_cdl_working_space_transform(config, base_path, ws_elem, False) # # Handle the four possible scenarios of working space transform availability. # if (to_transform is None) and (from_transform is None): print('Adding CDL Transform') gt.appendTransform( ocio.CDLTransform(slopes, offsets, powers, sat) ) elif (to_transform is not None) and (from_transform is not None): print('Adding To-CDL-Working-Space Transform') gt.appendTransform(to_transform) print('Adding CDL Transform') gt.appendTransform( ocio.CDLTransform(slopes, offsets, powers, sat) ) print('Adding From-CDL-Working-Space Transform') gt.appendTransform(from_transform) elif to_transform is not None: print('Adding To-CDL-Working-Space Transform') gt.appendTransform(to_transform) print('Adding CDL Transform') gt.appendTransform( ocio.CDLTransform(slopes, offsets, powers, sat) ) print(' Generating From-CDL-Working-Space Transform') to_transform.setDirection(ocio.TRANSFORM_DIR_INVERSE) print('Adding From-CDL-Working-Space Transform') gt.appendTransform(to_transform) elif from_transform is not None: print(' Generating From-CDL-Working-Space Transform') from_transform.setDirection(ocio.TRANSFORM_DIR_INVERSE) print('Adding To-CDL-Working-Space Transform') gt.appendTransform(from_transform) print('Adding CDL Transform') gt.appendTransform( ocio.CDLTransform(slopes, offsets, powers, sat) ) from_transform.setDirection(ocio.TRANSFORM_DIR_FORWARD) print('Adding From-CDL-Working-Space Transform') gt.appendTransform(from_transform)
data = [] for i in xrange(NUM_SAMPLES): x = i/(NUM_SAMPLES-1.0) x = Fit(x, 0.0, 1.0, RANGE[0], RANGE[1]) data.append(fromSRGB(x)) # Data is srgb->linear WriteSPI1D('luts/srgb.spi1d', RANGE[0], RANGE[1], data) cs = OCIO.ColorSpace(name='sRGB') cs.setDescription("Standard RGB Display Space") cs.setBitDepth(OCIO.Constants.BIT_DEPTH_F32) cs.setAllocation(OCIO.Constants.ALLOCATION_UNIFORM) cs.setAllocationVars([RANGE[0], RANGE[1]]) t = OCIO.FileTransform('srgb.spi1d', interpolation=OCIO.Constants.INTERP_LINEAR) cs.setTransform(t, OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE) config.addColorSpace(cs) NUM_SAMPLES = 2**16+25 RANGE = (-0.125, 4.875) data = [] for i in xrange(NUM_SAMPLES): x = i/(NUM_SAMPLES-1.0) x = Fit(x, 0.0, 1.0, RANGE[0], RANGE[1]) data.append(fromSRGB(x)) # Data is srgb->linear WriteSPI1D('luts/srgbf.spi1d', RANGE[0], RANGE[1], data)
def _perform(self): """ Perform the task. """ import OpenImageIO as oiio import PyOpenColorIO as ocio sourceColorSpace = self.option('sourceColorSpace') targetColorSpace = self.option('targetColorSpace') metadata = { 'sourceColorSpace': sourceColorSpace, 'targetColorSpace': targetColorSpace } # open color io configuration config = self.ocioConfig() for crawler in self.crawlers(): # resolving the lut path lut = self.templateOption('lut', crawler=crawler) # adding color space transform groupTransform = ocio.GroupTransform() groupTransform.push_back( ocio.ColorSpaceTransform(src=sourceColorSpace, dst=targetColorSpace)) # adding lut transform groupTransform.push_back( ocio.FileTransform(lut, interpolation=ocio.Constants.INTERP_LINEAR)) # source image sourceImage = oiio.ImageInput.open(crawler.var('filePath')) spec = sourceImage.spec() spec.set_format(oiio.FLOAT) metadata['lutFile'] = lut pixels = sourceImage.read_image() sourceImage.close() transformedPixels = config.getProcessor(groupTransform).applyRGB( pixels) targetFilePath = self.target(crawler) # trying to create the directory automatically in case it does not exist try: os.makedirs(os.path.dirname(targetFilePath)) except OSError: pass targetImage = oiio.ImageOutput.create(targetFilePath) # centipede metadata information UpdateImageMetadata.updateDefaultMetadata(spec, crawler, metadata) success = targetImage.open(targetFilePath, spec, oiio.Create) # saving target image if success: writePixels = array('d') writePixels.fromlist(transformedPixels) targetImage.write_image(writePixels) else: raise Exception(oiio.geterror()) # default result based on the target filePath return super(FileColorTransformation, self)._perform()
def load_output_transform(config, gt, base_path, elem, is_inverse): """ Add an OCIO transform to the supplied group transform to implement an ACES Output Transform. """ # Setup some variables based on whether it is an Output or Inverse Output Transform. if not is_inverse: transform_dir = ocio.TRANSFORM_DIR_FORWARD ot_transformId_token = './aces:transformId' ot_file_token = './aces:file' odt_token = './aces:outputDeviceTransform' rrt_token = './aces:referenceRenderingTransform' msg = 'Adding Output Transform from ACES2065-1 to display: %s and view: %s' file_msg = 'Adding Output Transform LUT file:' else: transform_dir = ocio.TRANSFORM_DIR_INVERSE ot_transformId_token = './aces:inverseOutputTransform/aces:transformId' ot_file_token = './aces:inverseOutputTransform/aces:file' odt_token = './aces:inverseOutputDeviceTransform' rrt_token = './aces:inverseReferenceRenderingTransform' msg = 'Adding Inverse Output Transform to ACES2065-1 from display %s and view: %s' file_msg = 'Adding Inverse Output Transform LUT file:' # # OutputTransform ACES transformId case. # id_elem = elem.find(ot_transformId_token, namespaces=NS) if id_elem is not None: build_output_transform_from_id_elem(config, gt, id_elem, msg, transform_dir) return # # OutputTransform external LUT file case. # file_elem = elem.find(ot_file_token, namespaces=NS) if file_elem is not None: lut_path = file_elem.text if lut_path is not None: lut_path = check_lut_path(base_path, lut_path) print(file_msg, lut_path) gt.appendTransform( ocio.FileTransform(lut_path, '', ocio.INTERP_BEST, transform_dir) ) return # # Handle referenceRenderingTransform + outputDeviceTransform case. # odt_elem = elem.find(odt_token, namespaces=NS) if odt_elem is not None: # # ACES transformId case. # id_elem = odt_elem.find('./aces:transformId', namespaces=NS) if id_elem is not None: build_output_transform_from_id_elem(config, gt, id_elem, msg, transform_dir) return # TODO: Could validate that the referenceRenderingTransform element exists and is # the expected version (although since there is only one, it is not currently used). # # External LUT file case. # file_elem = odt_elem.find('./aces:file', namespaces=NS) if file_elem is not None: odt_path = file_elem.text if odt_path is not None: odt_path = check_lut_path(base_path, odt_path) odt_transform = ocio.FileTransform(odt_path, '', ocio.INTERP_BEST, transform_dir) # NB: Only check for an external file for the RRT if the ODT is also a file. rrt_transform = None rrt_elem = elem.find(rrt_token, namespaces=NS) if rrt_elem is not None: file_elem = rrt_elem.find('./aces:file', namespaces=NS) if file_elem is not None: rrt_path = file_elem.text if rrt_path is not None: rrt_path = check_lut_path(base_path, rrt_path) rrt_transform = ocio.FileTransform(rrt_path, '', ocio.INTERP_BEST, transform_dir) if is_inverse: print('Adding Inverse ODT LUT file:', odt_path) gt.appendTransform( odt_transform ) if rrt_transform is not None: print('Adding Inverse RRT LUT file:', rrt_path) gt.appendTransform( rrt_transform ) else: if rrt_transform is not None: print('Adding RRT LUT file:', rrt_path) gt.appendTransform( rrt_transform ) print('Adding ODT LUT file:', odt_path) gt.appendTransform( odt_transform )
def test_interface(self): ### AllocationTransform ### at = OCIO.AllocationTransform() self.assertEqual(OCIO.Constants.ALLOCATION_UNIFORM, at.getAllocation()) at.setAllocation(OCIO.Constants.ALLOCATION_LG2) self.assertEqual(OCIO.Constants.ALLOCATION_LG2, at.getAllocation()) self.assertEqual(0, at.getNumVars()) at.setVars([0.1, 0.2, 0.3]) self.assertEqual(3, at.getNumVars()) newvars = at.getVars() self.assertAlmostEqual(0.2, newvars[1], delta=1e-8) at2 = OCIO.AllocationTransform(OCIO.Constants.ALLOCATION_LG2, [0.1, 0.2, 0.3], OCIO.Constants.TRANSFORM_DIR_INVERSE) self.assertEqual(OCIO.Constants.ALLOCATION_LG2, at2.getAllocation()) self.assertEqual(3, at2.getNumVars()) newvars2 = at2.getVars() for i in range(0, 3): self.assertAlmostEqual(float(i + 1) / 10.0, newvars2[i], delta=1e-7) self.assertEqual(OCIO.Constants.TRANSFORM_DIR_INVERSE, at2.getDirection()) at3 = OCIO.AllocationTransform( allocation=OCIO.Constants.ALLOCATION_LG2, vars=[0.1, 0.2, 0.3], direction=OCIO.Constants.TRANSFORM_DIR_INVERSE) self.assertEqual(OCIO.Constants.ALLOCATION_LG2, at3.getAllocation()) self.assertEqual(3, at3.getNumVars()) newvars3 = at3.getVars() for i in range(0, 3): self.assertAlmostEqual(float(i + 1) / 10.0, newvars3[i], delta=1e-7) self.assertEqual(OCIO.Constants.TRANSFORM_DIR_INVERSE, at3.getDirection()) ### Base Transform method tests ### self.assertEqual(OCIO.Constants.TRANSFORM_DIR_FORWARD, at.getDirection()) at.setDirection(OCIO.Constants.TRANSFORM_DIR_UNKNOWN) self.assertEqual(OCIO.Constants.TRANSFORM_DIR_UNKNOWN, at.getDirection()) ### CDLTransform ### cdl = OCIO.CDLTransform() CC = "<ColorCorrection id=\"foo\">" CC += "<SOPNode>" CC += "<Description>this is a descipt</Description>" CC += "<Slope>1.1 1.2 1.3</Slope><Offset>2.1 2.2 2.3</Offset>" CC += "<Power>3.1 3.2 3.3</Power>" CC += "</SOPNode>" CC += "<SatNode>" CC += "<Saturation>0.7</Saturation>" CC += "</SatNode>" CC += "</ColorCorrection>" # Don't want to deal with getting the correct path so this runs #cdlfile = OCIO.CDLTransform().CreateFromFile("../OpenColorIO/src/jniglue/tests/org/OpenColorIO/test.cc", "foo") #self.assertEqual(CC, cdlfile.getXML()) cdl.setXML(CC) self.assertEqual(CC, cdl.getXML()) match = cdl.createEditableCopy() match.setOffset([1.0, 1.0, 1.0]) self.assertEqual(False, cdl.equals(match)) cdl.setSlope([0.1, 0.2, 0.3]) cdl.setOffset([1.1, 1.2, 1.3]) cdl.setPower([2.1, 2.2, 2.3]) cdl.setSat(0.5) CC2 = "<ColorCorrection id=\"foo\">" CC2 += "<SOPNode>" CC2 += "<Description>this is a descipt</Description>" CC2 += "<Slope>0.1 0.2 0.3</Slope>" CC2 += "<Offset>1.1 1.2 1.3</Offset>" CC2 += "<Power>2.1 2.2 2.3</Power>" CC2 += "</SOPNode>" CC2 += "<SatNode>" CC2 += "<Saturation>0.5</Saturation>" CC2 += "</SatNode>" "</ColorCorrection>" self.assertEqual(CC2, cdl.getXML()) cdl.setSOP([1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9]) newsop = cdl.getSOP() self.assertAlmostEqual(1.5, newsop[4], delta=1e-8) slope = cdl.getSlope() self.assertAlmostEqual(1.2, slope[1], delta=1e-7) offset = cdl.getOffset() self.assertAlmostEqual(1.6, offset[2], delta=1e-7) power = cdl.getPower() self.assertAlmostEqual(1.7, power[0], delta=1e-7) self.assertAlmostEqual(0.5, cdl.getSat(), delta=1e-8) luma = cdl.getSatLumaCoefs() self.assertAlmostEqual(0.2126, luma[0], delta=1e-8) self.assertAlmostEqual(0.7152, luma[1], delta=1e-8) self.assertAlmostEqual(0.0722, luma[2], delta=1e-8) cdl.setID("foobar123") self.assertEqual("foobar123", cdl.getID()) cdl.setDescription("bar") self.assertEqual("bar", cdl.getDescription()) cdl2 = OCIO.CDLTransform([0.1, 0.2, 0.3], [1.1, 1.2, 1.3], [2.1, 2.2, 2.3], 0.5, OCIO.Constants.TRANSFORM_DIR_INVERSE, 'foobar123', 'bar') slope2 = cdl2.getSlope() offset2 = cdl2.getOffset() power2 = cdl2.getPower() luma2 = cdl2.getSatLumaCoefs() for i in range(0, 3): self.assertAlmostEqual(float(i + 1) / 10.0, slope2[i], delta=1e-7) self.assertAlmostEqual(float(i + 1) / 10.0 + 1, offset2[i], delta=1e-7) self.assertAlmostEqual(float(i + 1) / 10.0 + 2, power2[i], delta=1e-7) self.assertAlmostEqual(0.5, cdl2.getSat(), delta=1e-8) self.assertAlmostEqual(0.2126, luma2[0], delta=1e-8) self.assertAlmostEqual(0.7152, luma2[1], delta=1e-8) self.assertAlmostEqual(0.0722, luma2[2], delta=1e-8) self.assertEqual(OCIO.Constants.TRANSFORM_DIR_INVERSE, cdl2.getDirection()) self.assertEqual('foobar123', cdl2.getID()) self.assertEqual('bar', cdl2.getDescription()) cdl3 = OCIO.CDLTransform( slope=[0.1, 0.2, 0.3], offset=[1.1, 1.2, 1.3], power=[2.1, 2.2, 2.3], sat=0.5, direction=OCIO.Constants.TRANSFORM_DIR_INVERSE, id='foobar123', description='bar') slope3 = cdl2.getSlope() offset3 = cdl2.getOffset() power3 = cdl2.getPower() luma3 = cdl2.getSatLumaCoefs() for i in range(0, 3): self.assertAlmostEqual(float(i + 1) / 10.0, slope3[i], delta=1e-7) self.assertAlmostEqual(float(i + 1) / 10.0 + 1, offset3[i], delta=1e-7) self.assertAlmostEqual(float(i + 1) / 10.0 + 2, power3[i], delta=1e-7) self.assertAlmostEqual(0.5, cdl3.getSat(), delta=1e-8) self.assertAlmostEqual(0.2126, luma3[0], delta=1e-8) self.assertAlmostEqual(0.7152, luma3[1], delta=1e-8) self.assertAlmostEqual(0.0722, luma3[2], delta=1e-8) self.assertEqual(OCIO.Constants.TRANSFORM_DIR_INVERSE, cdl3.getDirection()) self.assertEqual('foobar123', cdl3.getID()) self.assertEqual('bar', cdl3.getDescription()) ### ColorSpaceTransform ### ct = OCIO.ColorSpaceTransform() ct.setSrc("foo") self.assertEqual("foo", ct.getSrc()) ct.setDst("bar") self.assertEqual("bar", ct.getDst()) ### DisplayTransform ### dt = OCIO.DisplayTransform() dt.setInputColorSpaceName("lin18") self.assertEqual("lin18", dt.getInputColorSpaceName()) dt.setLinearCC(ct) foo = dt.getLinearCC() dt.setColorTimingCC(cdl) blah = dt.getColorTimingCC() dt.setChannelView(at) wee = dt.getChannelView() dt.setDisplay("sRGB") self.assertEqual("sRGB", dt.getDisplay()) dt.setView("foobar") self.assertEqual("foobar", dt.getView()) cdl.setXML(CC) dt.setDisplayCC(cdl) cdldt = dt.getDisplayCC() self.assertEqual(CC, cdldt.getXML()) dt.setLooksOverride("darkgrade") self.assertEqual("darkgrade", dt.getLooksOverride()) dt.setLooksOverrideEnabled(True) self.assertEqual(True, dt.getLooksOverrideEnabled()) dt2 = OCIO.DisplayTransform("lin18", "sRGB", "foobar", OCIO.Constants.TRANSFORM_DIR_INVERSE) self.assertEqual("lin18", dt2.getInputColorSpaceName()) self.assertEqual("sRGB", dt2.getDisplay()) self.assertEqual("foobar", dt2.getView()) self.assertEqual(OCIO.Constants.TRANSFORM_DIR_INVERSE, dt2.getDirection()) dt3 = OCIO.DisplayTransform( inputColorSpaceName="lin18", display="sRGB", view="foobar", direction=OCIO.Constants.TRANSFORM_DIR_INVERSE) self.assertEqual("lin18", dt3.getInputColorSpaceName()) self.assertEqual("sRGB", dt3.getDisplay()) self.assertEqual("foobar", dt3.getView()) self.assertEqual(OCIO.Constants.TRANSFORM_DIR_INVERSE, dt3.getDirection()) ### ExponentTransform ### et = OCIO.ExponentTransform() et.setValue([0.1, 0.2, 0.3, 0.4]) evals = et.getValue() self.assertAlmostEqual(0.3, evals[2], delta=1e-7) ### FileTransform ### ft = OCIO.FileTransform() ft.setSrc("foo") self.assertEqual("foo", ft.getSrc()) ft.setCCCId("foobar") self.assertEqual("foobar", ft.getCCCId()) ft.setInterpolation(OCIO.Constants.INTERP_NEAREST) self.assertEqual(OCIO.Constants.INTERP_NEAREST, ft.getInterpolation()) self.assertEqual(17, ft.getNumFormats()) self.assertEqual("flame", ft.getFormatNameByIndex(0)) self.assertEqual("3dl", ft.getFormatExtensionByIndex(0)) ### GroupTransform ### gt = OCIO.GroupTransform() gt.push_back(et) gt.push_back(ft) self.assertEqual(2, gt.size()) self.assertEqual(False, gt.empty()) foo = gt.getTransform(0) self.assertEqual(OCIO.Constants.TRANSFORM_DIR_FORWARD, foo.getDirection()) gt.clear() self.assertEqual(0, gt.size()) ### LogTransform ### lt = OCIO.LogTransform() lt.setBase(10.0) self.assertEqual(10.0, lt.getBase()) ### LookTransform ### lkt = OCIO.LookTransform() lkt.setSrc("foo") self.assertEqual("foo", lkt.getSrc()) lkt.setDst("bar") self.assertEqual("bar", lkt.getDst()) lkt.setLooks("bar;foo") self.assertEqual("bar;foo", lkt.getLooks()) ### MatrixTransform ### mt = OCIO.MatrixTransform() mmt = mt.createEditableCopy() mt.setValue([ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6 ], [0.1, 0.2, 0.3, 0.4]) self.assertEqual(False, mt.equals(mmt)) m44_1, offset_1 = mt.getValue() self.assertAlmostEqual(0.3, m44_1[2], delta=1e-7) self.assertAlmostEqual(0.2, offset_1[1], delta=1e-7) mt.setMatrix([ 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6 ]) m44_2 = mt.getMatrix() self.assertAlmostEqual(1.3, m44_2[2], delta=1e-7) mt.setOffset([1.1, 1.2, 1.3, 1.4]) offset_2 = mt.getOffset() self.assertAlmostEqual(1.4, offset_2[3]) mt.Fit([0.1, 0.1, 0.1, 0.1], [0.9, 0.9, 0.9, 0.9], [0.0, 0.0, 0.0, 0.0], [1.1, 1.1, 1.1, 1.1]) m44_3 = mt.getMatrix() self.assertAlmostEqual(1.3, m44_3[2], delta=1e-7) m44_3, offset_2 = mt.Identity() self.assertAlmostEqual(0.0, m44_3[1], delta=1e-7) m44_2, offset_2 = mt.Sat(0.5, [0.2126, 0.7152, 0.0722]) self.assertAlmostEqual(0.3576, m44_2[1], delta=1e-7) m44_2, offset_2 = mt.Scale([0.9, 0.8, 0.7, 1.]) self.assertAlmostEqual(0.9, m44_2[0], delta=1e-7) m44_2, offset_2 = mt.View([1, 1, 1, 0], [0.2126, 0.7152, 0.0722]) self.assertAlmostEqual(0.0722, m44_2[2], delta=1e-7) mt4 = OCIO.MatrixTransform([ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6 ], [0.1, 0.2, 0.3, 0.4], OCIO.Constants.TRANSFORM_DIR_INVERSE) m44_4, offset_4 = mt4.getValue() for i in range(0, 16): self.assertAlmostEqual(float(i + 1) / 10.0, m44_4[i], delta=1e-7) for i in range(0, 4): self.assertAlmostEqual(float(i + 1) / 10.0, offset_4[i], delta=1e-7) self.assertEqual(mt4.getDirection(), OCIO.Constants.TRANSFORM_DIR_INVERSE) mt5 = OCIO.MatrixTransform( matrix=[ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6 ], offset=[0.1, 0.2, 0.3, 0.4], direction=OCIO.Constants.TRANSFORM_DIR_INVERSE) m44_5, offset_5 = mt5.getValue() for i in range(0, 16): self.assertAlmostEqual(float(i + 1) / 10.0, m44_5[i], delta=1e-7) for i in range(0, 4): self.assertAlmostEqual(float(i + 1) / 10.0, offset_5[i], delta=1e-7) self.assertEqual(mt5.getDirection(), OCIO.Constants.TRANSFORM_DIR_INVERSE) ### TruelightTransform ### """
def make_transforms(transform_path, config): sRGB_domain = numpy.array([0.0, 1.0]) sRGB_tf_to_linear_LUT = colour.LUT1D( table=models.sRGB_COLOURSPACE.cctf_decoding( colour.LUT1D.linear_table(1024, sRGB_domain)), name="sRGB to Linear", domain=sRGB_domain, comments=["sRGB CCTF to Display Linear"]) sRGB_linear_to_tf_LUT = colour.LUT1D( table=models.sRGB_COLOURSPACE.cctf_encoding( colour.LUT1D.linear_table(8192, sRGB_domain)), name="Linear to sRGB", domain=sRGB_domain, comments=["sRGB Display Linear to CCTF"]) path = os.path.join(transform_path, "sRGB_CCTF_to_Linear.spi1d") create_directory(path) io.write_LUT(LUT=sRGB_tf_to_linear_LUT, path=path, decimals=10) path = os.path.join(transform_path, "sRGB_Linear_to_CCTF.spi1d") create_directory(path) io.write_LUT(LUT=sRGB_linear_to_tf_LUT, path=path, decimals=10) # Off-domain 1D variant sRGB_domain_variant = numpy.array([-0.125, 4.875]) sRGB_tf_to_linear_LUT_variant = colour.LUT1D( table=models.sRGB_COLOURSPACE.cctf_decoding( colour.LUT1D.linear_table(1024, sRGB_domain_variant)), name="sRGB to Linear Variant", domain=sRGB_domain_variant, comments=["sRGB CCTF to Display Linear"]) sRGB_linear_to_tf_LUT_variant = colour.LUT1D( table=models.sRGB_COLOURSPACE.cctf_encoding( colour.LUT1D.linear_table(8192, sRGB_domain_variant)), name="Linear to sRGB Variant", domain=sRGB_domain_variant, comments=["sRGB Display Linear to CCTF"]) path = os.path.join(transform_path, "sRGB_CCTF_to_Linear_variant.spi1d") create_directory(path) io.write_LUT(LUT=sRGB_tf_to_linear_LUT_variant, path=path, decimals=10) path = os.path.join(transform_path, "sRGB_Linear_to_CCTF_variant.spi1d") create_directory(path) io.write_LUT(LUT=sRGB_linear_to_tf_LUT_variant, path=path, decimals=10) # Define the sRGB specification colourspace = PyOpenColorIO.ColorSpace(family="Colourspace", name="sRGB Colourspace") colourspace.setDescription("sRGB IEC 61966-2-1 Colourspace") colourspace.setBitDepth(PyOpenColorIO.Constants.BIT_DEPTH_F32) colourspace.setAllocationVars([0.0, 1.0]) colourspace.setAllocation(PyOpenColorIO.Constants.ALLOCATION_UNIFORM) transform_to = PyOpenColorIO.FileTransform( "sRGB_CCTF_to_Linear.spi1d", interpolation=PyOpenColorIO.Constants.INTERP_NEAREST) transform_from = PyOpenColorIO.FileTransform( "sRGB_Linear_to_CCTF.spi1d", interpolation=PyOpenColorIO.Constants.INTERP_NEAREST) colourspace.setTransform( transform_to, PyOpenColorIO.Constants.COLORSPACE_DIR_TO_REFERENCE) colourspace.setTransform( transform_from, PyOpenColorIO.Constants.COLORSPACE_DIR_FROM_REFERENCE) config.addColorSpace(colourspace) # Define the sRGB specification for the variation colourspace = PyOpenColorIO.ColorSpace(family="Colourspace", name="sRGB Colourspace Variant") colourspace.setDescription("sRGB IEC 61966-2-1 Colourspace variant") colourspace.setBitDepth(PyOpenColorIO.Constants.BIT_DEPTH_F32) colourspace.setAllocationVars([-0.125, 1.125]) colourspace.setAllocation(PyOpenColorIO.Constants.ALLOCATION_UNIFORM) transform_to = PyOpenColorIO.FileTransform( "sRGB_CCTF_to_Linear_variant.spi1d", interpolation=PyOpenColorIO.Constants.INTERP_NEAREST) transform_from = PyOpenColorIO.FileTransform( "sRGB_Linear_to_CCTF_variant.spi1d", interpolation=PyOpenColorIO.Constants.INTERP_NEAREST) colourspace.setTransform( transform_to, PyOpenColorIO.Constants.COLORSPACE_DIR_TO_REFERENCE) colourspace.setTransform( transform_from, PyOpenColorIO.Constants.COLORSPACE_DIR_FROM_REFERENCE) config.addColorSpace(colourspace) # Define the commodity sRGB transform colourspace = PyOpenColorIO.ColorSpace(family="Colourspace", name="BT.709 2.2 CCTF Colourspace") colourspace.setDescription("Commodity Display BT.709 2.2 CCTF Colourspace") colourspace.setBitDepth(PyOpenColorIO.Constants.BIT_DEPTH_F32) colourspace.setAllocationVars([0.0, 1.0]) colourspace.setAllocation(PyOpenColorIO.Constants.ALLOCATION_UNIFORM) transform_to = PyOpenColorIO.ExponentTransform([2.2, 2.2, 2.2, 1.0]) transform_from = PyOpenColorIO.ExponentTransform([2.2, 2.2, 2.2, 1.0]) transform_from.setDirection(PyOpenColorIO.Constants.TRANSFORM_DIR_INVERSE) colourspace.setTransform( transform_to, PyOpenColorIO.Constants.COLORSPACE_DIR_TO_REFERENCE) colourspace.setTransform( transform_from, PyOpenColorIO.Constants.COLORSPACE_DIR_FROM_REFERENCE) config.addColorSpace(colourspace)