Пример #1
0
    def test_constructor_with_keyword(self):
        """
        Test Look constructor with keywords and validate its values.
        """

        # With keywords in their proper order.
        exp_tr = OCIO.ExponentTransform()
        inv_exp_tr = OCIO.ExponentTransform()
        look = OCIO.Look(name='coollook',
                         processSpace='somespace',
                         transform=exp_tr,
                         inverseTransform=inv_exp_tr,
                         description='this is a test')

        self.assertEqual(look.getName(), 'coollook')
        self.assertEqual(look.getProcessSpace(), 'somespace')
        self.assertIsInstance(look.getTransform(), type(exp_tr))
        self.assertIsInstance(look.getInverseTransform(), type(inv_exp_tr))
        self.assertEqual(look.getDescription(), 'this is a test')

        # With keyword not in their proper order.
        exp_tr2 = OCIO.ExponentTransform()
        inv_exp_tr2 = OCIO.ExponentTransform()
        look2 = OCIO.Look(inverseTransform=inv_exp_tr,
                          description='this is a test',
                          name='coollook',
                          processSpace='somespace',
                          transform=exp_tr)

        self.assertEqual(look2.getName(), 'coollook')
        self.assertEqual(look2.getProcessSpace(), 'somespace')
        self.assertIsInstance(look2.getTransform(), type(exp_tr2))
        self.assertIsInstance(look2.getInverseTransform(), type(inv_exp_tr2))
        self.assertEqual(look2.getDescription(), 'this is a test')
Пример #2
0
def CreateOCIODisplayTransform(config, inputColorSpace, display, view, swizzle,
                               fstopOffset, viewGamma):

    displayTransform = OCIO.DisplayTransform()
    displayTransform.setInputColorSpaceName(inputColorSpace)

    displayColorSpace = config.getDisplayColorSpaceName(display, view)
    displayTransform.setDisplayColorSpaceName(displayColorSpace)

    # Add the channel sizzle
    lumacoef = config.getDefaultLumaCoefs()
    mtx, offset = OCIO.MatrixTransform.View(swizzle, lumacoef)

    transform = OCIO.MatrixTransform()
    transform.setValue(mtx, offset)
    displayTransform.setChannelView(transform)

    # Add the linear fstop gain
    gain = 2**fstopOffset
    mtx, offset = OCIO.MatrixTransform.Scale((gain, gain, gain, gain))
    transform = OCIO.MatrixTransform()
    transform.setValue(mtx, offset)
    displayTransform.setLinearCC(transform)

    # Add the post-display CC
    transform = OCIO.ExponentTransform()
    transform.setValue([1.0 / max(1e-6, v) for v in \
                       (viewGamma, viewGamma, viewGamma, viewGamma)])
    displayTransform.setDisplayCC(transform)

    return displayTransform
Пример #3
0
    def test_constructor_wrong_parameter_type(self):
        """
        Test ExponentTransform constructor with a wrong parameter type.
        """

        for invalid in (None, 1):
            with self.assertRaises(TypeError):
                exp_tr = OCIO.ExponentTransform(invalid)
Пример #4
0
    def test_constructor_with_positional(self):
        """
        Test Look constructor without keywords and validate its values.
        """

        exp_tr = OCIO.ExponentTransform()
        inv_exp_tr = OCIO.ExponentTransform()
        look = OCIO.Look('coollook',
                         'somespace',
                         exp_tr,
                         inv_exp_tr,
                         'this is a test')

        self.assertEqual(look.getName(), 'coollook')
        self.assertEqual(look.getProcessSpace(), 'somespace')
        self.assertIsInstance(look.getTransform(), type(exp_tr))
        self.assertIsInstance(look.getInverseTransform(), type(inv_exp_tr))
        self.assertEqual(look.getDescription(), 'this is a test')
Пример #5
0
 def test_interface(self):
     lk = OCIO.Look()
     lk.setName("coollook")
     self.assertEqual("coollook", lk.getName())
     lk.setProcessSpace("somespace")
     self.assertEqual("somespace", lk.getProcessSpace())
     et = OCIO.ExponentTransform()
     et.setValue([0.1, 0.2, 0.3, 0.4])
     lk.setTransform(et)
     oet = lk.getTransform()
     vals = oet.getValue()
     self.assertAlmostEqual(0.2, vals[1], delta=1e-8)
     iet = OCIO.ExponentTransform()
     iet.setValue([-0.1, -0.2, -0.3, -0.4])
     lk.setInverseTransform(iet)
     ioet = lk.getInverseTransform()
     vals2 = ioet.getValue()
     self.assertAlmostEqual(-0.2, vals2[1], delta=1e-8)
Пример #6
0
    def test_constructor_with_positional(self):
        """
        Test ExponentTransform constructor without keywords and validate its values.
        """

        exp_tr = OCIO.ExponentTransform(self.TEST_VALUES,
                                        self.TEST_NEGATIVE_STYLE,
                                        self.TEST_DIRECTION)

        self.assertEqual(exp_tr.getValue(), self.TEST_VALUES)
        self.assertEqual(exp_tr.getNegativeStyle(), self.TEST_NEGATIVE_STYLE)
        self.assertEqual(exp_tr.getDirection(), self.TEST_DIRECTION)
Пример #7
0
    def test_constructor_with_keyword(self):
        """
        Test ExponentTransform constructor with keywords and validate its values.
        """

        # With keywords in their proper order.
        exp_tr = OCIO.ExponentTransform(value=self.TEST_VALUES,
                                        negativeStyle=self.TEST_NEGATIVE_STYLE,
                                        direction=self.TEST_DIRECTION)

        self.assertEqual(exp_tr.getValue(), self.TEST_VALUES)
        self.assertEqual(exp_tr.getNegativeStyle(), self.TEST_NEGATIVE_STYLE)
        self.assertEqual(exp_tr.getDirection(), self.TEST_DIRECTION)

        # With keywords not in their proper order.
        exp_tr2 = OCIO.ExponentTransform(
            negativeStyle=self.TEST_NEGATIVE_STYLE,
            direction=self.TEST_DIRECTION,
            value=self.TEST_VALUES)

        self.assertEqual(exp_tr2.getValue(), self.TEST_VALUES)
        self.assertEqual(exp_tr2.getNegativeStyle(), self.TEST_NEGATIVE_STYLE)
        self.assertEqual(exp_tr2.getDirection(), self.TEST_DIRECTION)
def display_cctf(gamma=1.0, offset=None, direction=None, negative_style=None):
    if offset:
        cctf = ocio.ExponentWithLinearTransform()
        cctf.setGamma(_rgba_tuple(gamma))
        cctf.setOffset(_rgba_tuple(offset, alpha=0.0))
    else:
        cctf = ocio.ExponentTransform(_rgba_tuple(gamma))

    if direction:
        cctf.setDirection(direction)
    if negative_style:
        cctf.setNegativeStyle(negative_style)

    return cctf
Пример #9
0
    def test_transform(self):
        """
        Test the setTransform() and getTransform() methods.
        """

        # Default initialized transform value is None
        self.assertIsNone(self.look.getTransform())

        exp_tr = OCIO.ExponentTransform()
        exp_tr.setValue(self.TEST_EXP_VALUES)
        self.look.setTransform(exp_tr)
        out_exp_tr = self.look.getTransform()
        self.assertListEqual(out_exp_tr.getValue(), self.TEST_EXP_VALUES)

        # Wrong type tests.
        for invalid in (OCIO.ALLOCATION_UNIFORM, 1):
            with self.assertRaises(TypeError):
                self.look.setTransform(invalid)
Пример #10
0
    def test_inverse_transform(self):
        """
        Test the setInverseTransform() and getInverseTransform() methods.
        """

        # Default initialized inverse transform value is None
        self.assertIsNone(self.look.getInverseTransform())

        exp_tr = OCIO.ExponentTransform()
        inv_exp_values = [1.0 / v for v in self.TEST_EXP_VALUES]
        exp_tr.setValue(inv_exp_values)
        self.look.setInverseTransform(exp_tr)
        inv_oet = self.look.getInverseTransform()
        self.assertListEqual(inv_oet.getValue(), inv_exp_values)

        # Wrong type tests.
        for invalid in (OCIO.ALLOCATION_UNIFORM, 1):
            with self.assertRaises(TypeError):
                self.look.setInverseTransform(invalid)
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)
Пример #12
0
    def test_interface(self):

        _cfg = OCIO.Config().CreateFromStream(self.SIMPLE_PROFILE)
        _cfge = _cfg.createEditableCopy()
        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())
        desc = OCIO.GpuShaderDesc()
        desc.setLanguage(OCIO.Constants.GPU_LANGUAGE_GLSL_1_3)
        desc.setFunctionName("pytestocio")
        desc.setLut3DEdgeLen(32)
        glsl = _proc.getGpuShaderText(desc)
        self.assertEqual(self.GLSLResult, glsl)
        # old DEPRECIATED GpuShaderDesc dict support
        desc2 = {
            "language": OCIO.Constants.GPU_LANGUAGE_GLSL_1_3,
            "functionName": "pytestocio",
            "lut3DEdgeLen": 32
        }
        glsl = _proc.getGpuShaderText(desc2)
        self.assertEqual(self.GLSLResult, glsl)
        #self.assertEqual("$1dead2bf42974cd1769164e45a0c9e40", _proc.getGpuShaderTextCacheID(desc))
        #self.assertEqual("$1dead2bf42974cd1769164e45a0c9e40", _proc.getGpuShaderTextCacheID(desc2))
        len = desc.getLut3DEdgeLen()
        size = 3 * len * len * len
        self.assertEqual(0.0,
                         _proc.getGpuLut3D(desc2)[size - 1])
        self.assertEqual("<NULL>", _proc.getGpuLut3DCacheID(desc))
        self.assertEqual("<NULL>", _proc.getGpuLut3DCacheID(desc2))

        del _cfge
        del _cfg
Пример #13
0
    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 baby_config():
    linear = ocio.ColorSpace(
        referenceSpace=ocio.REFERENCE_SPACE_SCENE,
        name="linear",
        description="scene-linear",
        encoding="scene-linear",
        bitDepth=ocio.BIT_DEPTH_F16,
        # allocation=ocio.ALLOCATION_LG2,
        # allocationVars=[-15, 6]
    )
    sRGB_inv_eotf = ocio.ColorSpace(
        referenceSpace=ocio.REFERENCE_SPACE_SCENE,
        name="sRGB (gamma ~2.2)",
        description="sRGB inverse EOTF",
        encoding="sdr-video",
        bitDepth=ocio.BIT_DEPTH_UINT10,
        fromReference=ocio.GroupTransform(
            [
                ocio.ExponentWithLinearTransform(
                    gamma=[2.4, 2.4, 2.4, 1.0],
                    offset=[0.055, 0.055, 0.055, 0.0],
                    direction=ocio.TRANSFORM_DIR_INVERSE,
                ),
                ocio.RangeTransform(
                    minInValue=0, minOutValue=0, maxInValue=1, maxOutValue=1
                ),
            ]
        ),
    )

    sRGB = ocio.ColorSpace(
        referenceSpace=ocio.REFERENCE_SPACE_SCENE,
        name="sRGB",
        description="sRGB inverse EOTF",
        encoding="sdr-video",
        bitDepth=ocio.BIT_DEPTH_UINT10,
        fromReference=ocio.GroupTransform(
            [
                ocio.ExponentTransform(
                    value=[2.2, 2.2, 2.2, 1.0], direction=ocio.TRANSFORM_DIR_INVERSE
                ),
                ocio.RangeTransform(
                    minInValue=0, minOutValue=0, maxInValue=1, maxOutValue=1
                ),
            ]
        ),
    )
    data = ocio.ColorSpace(
        referenceSpace=ocio.REFERENCE_SPACE_SCENE,
        name="non-color data",
        encoding="data",
        isData=True,
    )

    all_colorspaces = [data, linear, sRGB]

    cfg = ocio.Config()
    _ = [cfg.addColorSpace(cs) for cs in all_colorspaces]
    cfg.addColorSpace(linear)
    cfg.addColorSpace(sRGB)

    # Consistently throws problems here likely in relation to the above
    # 412-417 lines being called first and this tripping errors in this
    # block. Commenting seems to quiet the issues.
    # cfg.setRole('aces_interchange', aces.getName())
    # cfg.setRole('cie_xyz_d65_interchange', xyzd65.getName())

    cfg.setRole(ocio.ROLE_DATA, data.getName())
    cfg.setRole(ocio.ROLE_DEFAULT, linear.getName())
    cfg.setRole(ocio.ROLE_REFERENCE, linear.getName())
    cfg.setRole(ocio.ROLE_SCENE_LINEAR, linear.getName())
    cfg.setRole(ocio.ROLE_COLOR_PICKING, sRGB.getName())

    # add default colorimetry view transform to config
    # cfg.addViewTransform(
    #     ocio.ViewTransform(
    #         name='colorimetry',
    #         referenceSpace=ocio.REFERENCE_SPACE_SCENE,
    #         fromReference=ocio.BuiltinTransform('ACES-AP0_to_CIE-XYZ-D65_BFD'))
    #     )
    # )

    default_display_cs_name = "sRGB"
    cfg.addDisplayView(
        display="sRGB-like Commodity",
        view="Inverse EOTF",
        colorSpaceName=default_display_cs_name,
    )
    # cfg.addSharedView('Colorimetry', 'colorimetry', '<USE_DISPLAY_NAME>')
    # cfg.addDisplaySharedView(default_display, 'Colorimetry')
    return cfg
Пример #15
0
 def setUp(self):
     self.exp_tr = OCIO.ExponentTransform()
Пример #16
0
    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
Пример #17
0
        config=config,
        family="Log Encodings",
        name="AgX Log (Kraken)",
        description="AgX Log, (Kraken)",
        aliases=["Log", "AgX Log", "Kraken", "AgX Kraken Log"],
        transforms=transform_list
    )

    ####
    # Utilities
    ####

    # Define a generic 2.2 Electro Optical Transfer Function
    transform_list = [
        PyOpenColorIO.ExponentTransform(
            value=[2.2, 2.2, 2.2, 1.0],
            direction=PyOpenColorIO.TransformDirection.TRANSFORM_DIR_INVERSE
        )
    ]

    config, colourspace = AgX.add_colourspace(
        config=config,
        family="Utilities/Curves",
        name="2.2 EOTF Encoding",
        description="2.2 Exponent EOTF Encoding",
        aliases=["2.2 EOTF Encoding", "sRGB EOTF Encoding"],
        transforms=transform_list
    )

    # Define a generic 2.4 Electro Optical Transfer Function
    transform_list = [
        PyOpenColorIO.ExponentTransform(
Пример #18
0
    # colorspace.setAllocation(PyOpenColorIO.Constants.ALLOCATION_LG2)
    transform_bt709_to_xyz = PyOpenColorIO.MatrixTransform(ocio_bt709_to_xyz)
    transform_bt2020_to_xyz = PyOpenColorIO.MatrixTransform(ocio_bt2020_to_xyz)
    transform_bt2020_to_xyz.setDirection(
        PyOpenColorIO.Constants.TRANSFORM_DIR_INVERSE)
    transform = PyOpenColorIO.GroupTransform()
    transform.setTransforms([transform_bt709_to_xyz, transform_bt2020_to_xyz])
    colorspace.setTransform(
        transform, PyOpenColorIO.Constants.COLORSPACE_DIR_TO_REFERENCE)
    config.addColorSpace(colorspace)

    # Full colorimetric sRGB 2.2 transform
    colorspace = PyOpenColorIO.ColorSpace(family="Colorimetry",
                                          name="BT.709 E2.2 Nonlinear")
    colorspace.setDescription("Colorimetric BT.709 2.2 Transfer")
    transform_transfer = PyOpenColorIO.ExponentTransform()
    transform_transfer.setValue([2.2, 2.2, 2.2, 1.])
    # This should likely be a *nonlinear* transfer function
    # to scale the range down to 80 nits but hold middle grey
    # at 18-20 nit range.
    transform_scale = PyOpenColorIO.AllocationTransform()
    transform_scale.setAllocation(PyOpenColorIO.Constants.ALLOCATION_UNIFORM)
    transform_scale.setVars([0.0, 1.25])
    transform_colorimetry = PyOpenColorIO.ColorSpaceTransform()
    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(
Пример #19
0
    if not os.path.exists(build_directory):
        os.makedirs(build_directory)

    logging.basicConfig()
    logging.getLogger().setLevel(logging.INFO)

    # "OpenColorIO 1" configuration.
    colorspace_1 = colorspace_factory('Gamut - sRGB', 'Gamut')

    colorspace_2 = colorspace_factory(
        'CCTF - sRGB',
        'CCTF',
        description=('WARNING: The sRGB "EOTF" is purposely incorrect and '
                     'only a placeholder!'),
        to_reference_transform=ocio.ExponentTransform([2.2, 2.2, 2.2, 1]))

    colorspace_3 = colorspace_factory(
        'Colorspace - sRGB',
        'Colorspace',
        to_reference_transform=ocio.ColorSpaceTransform(
            'CCTF - sRGB', 'Gamut - sRGB'))

    colorspace_4 = colorspace_factory('View - sRGB Monitor - sRGB',
                                      'View',
                                      base_colorspace=colorspace_3)

    colorspace_5 = colorspace_factory('Utility - Raw', 'Utility', is_data=True)

    data = ConfigData(
        roles={'Gamut - sRGB': ocio.ROLE_SCENE_LINEAR},
Пример #20
0
t = OCIO.FileTransform('cineon.spi1d', interpolation=OCIO.Constants.INTERP_LINEAR)
cs.setTransform(t, OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE)
config.addColorSpace(cs)



###############################################################################

cs = OCIO.ColorSpace(name='Gamma1.8')
cs.setDescription("Emulates a idealized Gamma 1.8 display device.")
cs.setBitDepth(OCIO.Constants.BIT_DEPTH_F32)
cs.setAllocation(OCIO.Constants.ALLOCATION_UNIFORM)
cs.setAllocationVars([0.0, 1.0])

t = OCIO.ExponentTransform(value=(1.8,1.8,1.8,1.0))
cs.setTransform(t, OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE)
config.addColorSpace(cs)

cs = OCIO.ColorSpace(name='Gamma2.2')
cs.setDescription("Emulates a idealized Gamma 2.2 display device.")
cs.setBitDepth(OCIO.Constants.BIT_DEPTH_F32)
cs.setAllocation(OCIO.Constants.ALLOCATION_UNIFORM)
cs.setAllocationVars([0.0, 1.0])

t = OCIO.ExponentTransform(value=(2.2,2.2,2.2,1.0))
cs.setTransform(t, OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE)
config.addColorSpace(cs)


###############################################################################
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)
def make_transforms(transform_path, config):

    # The canonized sRGB transform
    # Due to the nature of the GPU issues in OpenColorIO v1.1.1, this
    # 1D LUT oversamples the sRGB transfer function range to have
    # correct results via the GPU.
    #
    # It also adds a faster inverse transform instead of a lookup for
    # output processing speed. It must be larger as a result, due to
    # quantisation issues in the linear domain.

    sRGB_domain = numpy.array([-0.125, 3.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_variant = 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_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 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)