Esempio n. 1
0
    def test_validate(self):
        """
        Test the validate().
        """
        ct = OCIO.ColorSpaceTransform()
        ct.setSrc("src")
        ct.setDst("dst")
        ct.validate()

        # Src has to be non-empty.
        ct.setSrc("")
        with self.assertRaises(OCIO.Exception):
            ct.validate()
        ct.setSrc("src")

        # Dst has to be non-empty.
        ct.setDst("")
        with self.assertRaises(OCIO.Exception):
            ct.validate()
        ct.setDst("dst")

        # Direction can't be unknown.
        for direction in OCIO.TransformDirection.__members__.values():
            ct.setDirection(direction)
            if direction != OCIO.TRANSFORM_DIR_UNKNOWN:
                self.assertIsNone(ct.validate())
            else:
                with self.assertRaises(OCIO.Exception):
                    ct.validate()
Esempio n. 2
0
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)
Esempio n. 3
0
 def test_dst(self):
     """
     Test setDst() and getDst().
     """
     ct = OCIO.ColorSpaceTransform()
     for dst in self.TEST_COLORSPACE:
         ct.setDst(dst)
         self.assertEqual(dst, ct.getDst())
Esempio n. 4
0
 def test_src(self):
     """
     Test setSrc() and getSrc().
     """
     ct = OCIO.ColorSpaceTransform()
     for src in self.TEST_COLORSPACE:
         ct.setSrc(src)
         self.assertEqual(src, ct.getSrc())
Esempio n. 5
0
    def test_constructor_wrong_parameter_type(self):
        """
        Test ColorSpaceTransform constructor with a wrong parameter type.
        """

        for invalid in (None, 1):
            with self.assertRaises(TypeError):
                cs_tr = OCIO.ColorSpaceTransform(invalid)
Esempio n. 6
0
 def test_data_bypass(self):
     """
     Test setDataBypass() and getDataBypass().
     """
     ct = OCIO.ColorSpaceTransform()
     ct.setDataBypass(False)
     self.assertEqual(False, ct.getDataBypass())
     ct.setDataBypass(True)
     self.assertEqual(True, ct.getDataBypass())
Esempio n. 7
0
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
Esempio n. 8
0
    def test_direction(self):
        """
        Test the setDirection() and getDirection() methods.
        """

        ct = OCIO.ColorSpaceTransform()
        for direction in OCIO.TransformDirection.__members__.values():
            # Setting the unknown direction preserves the current direction.
            if direction != OCIO.TRANSFORM_DIR_UNKNOWN:
                ct.setDirection(direction)
                self.assertEqual(direction, ct.getDirection())
Esempio n. 9
0
    def test_constructor_with_positional(self):
        """
        Test ColorSpaceTransform constructor without keywords and validate its values.
        """

        cs_tr = OCIO.ColorSpaceTransform(self.TEST_SRC, self.TEST_DST,
                                         self.TEST_DIRECTION)

        self.assertEqual(cs_tr.getDirection(), self.TEST_DIRECTION)
        self.assertEqual(cs_tr.getSrc(), self.TEST_SRC)
        self.assertEqual(cs_tr.getDst(), self.TEST_DST)
Esempio n. 10
0
    def test_constructor_with_keyword(self):
        """
        Test ColorSpaceTransform constructor with keywords and validate its values.
        """

        # With keywords in their proper order.
        cs_tr = OCIO.ColorSpaceTransform(src=self.TEST_SRC,
                                         dst=self.TEST_DST,
                                         direction=self.TEST_DIRECTION)

        self.assertEqual(cs_tr.getDirection(), self.TEST_DIRECTION)
        self.assertEqual(cs_tr.getSrc(), self.TEST_SRC)
        self.assertEqual(cs_tr.getDst(), self.TEST_DST)

        # With keywords not in their proper order.
        cs_tr2 = OCIO.ColorSpaceTransform(direction=self.TEST_DIRECTION,
                                          src=self.TEST_SRC,
                                          dst=self.TEST_DST)

        self.assertEqual(cs_tr2.getDirection(), self.TEST_DIRECTION)
        self.assertEqual(cs_tr2.getSrc(), self.TEST_SRC)
        self.assertEqual(cs_tr2.getDst(), self.TEST_DST)
Esempio n. 11
0
def convertImage(filename = '',fileOutName = '',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()
    #"""
    transform = OCIO.ColorSpaceTransform()
    transform.setSrc('srgb8')
    transform.setDst('acescg')
    #transform.setDirection(OCIO.Constants.TRANSFORM_DIR_INVERSE)
    processor = config.getProcessor(transform)
    #"""
    """
    # get the processor to transform from srgb8 to acescg space
    processor = config.getProcessor('srgb8','acescg')
    #processor = config.getProcessor('linear','srgb8')

    """
    # apply the transform
    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(fileOutName)
    # if tif format output as 16bit otherwise 8bit
    # if format != 'tif':
    #     spec.set_format(oiio.UINT8)
    # else:
    #     spec.set_format(oiio.UINT16)
    spec.set_format(oiio.HALF)
    # open and write the data transformed
    output.open(fileOutName,spec,oiio.Create)
    output.write_image(imgTrans)
    output.close()
    print 'done'
Esempio n. 12
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 ###
        """
Esempio n. 13
0
    def test_constructor(self):
        """
        Test ColorSpaceTransform constructor without and with keywords.
        """
        ct = OCIO.ColorSpaceTransform()
        self.assertEqual("", ct.getSrc())
        self.assertEqual("", ct.getDst())
        self.assertEqual(OCIO.TRANSFORM_DIR_FORWARD, ct.getDirection())
        self.assertEqual(True, ct.getDataBypass())

        ct = OCIO.ColorSpaceTransform("src", "dst")
        self.assertEqual("src", ct.getSrc())
        self.assertEqual("dst", ct.getDst())
        self.assertEqual(OCIO.TRANSFORM_DIR_FORWARD, ct.getDirection())
        self.assertEqual(True, ct.getDataBypass())

        ct = OCIO.ColorSpaceTransform("src", "dst", OCIO.TRANSFORM_DIR_INVERSE)
        self.assertEqual("src", ct.getSrc())
        self.assertEqual("dst", ct.getDst())
        self.assertEqual(OCIO.TRANSFORM_DIR_INVERSE, ct.getDirection())
        self.assertEqual(True, ct.getDataBypass())

        ct = OCIO.ColorSpaceTransform("src", "dst", OCIO.TRANSFORM_DIR_INVERSE,
                                      False)
        self.assertEqual("src", ct.getSrc())
        self.assertEqual("dst", ct.getDst())
        self.assertEqual(OCIO.TRANSFORM_DIR_INVERSE, ct.getDirection())
        self.assertEqual(False, ct.getDataBypass())

        ct = OCIO.ColorSpaceTransform(src="src", dst="dst", dataBypass=False)
        self.assertEqual("src", ct.getSrc())
        self.assertEqual("dst", ct.getDst())
        self.assertEqual(OCIO.TRANSFORM_DIR_FORWARD, ct.getDirection())
        self.assertEqual(False, ct.getDataBypass())

        ct = OCIO.ColorSpaceTransform(src="src",
                                      dst="dst",
                                      dir=OCIO.TRANSFORM_DIR_INVERSE,
                                      dataBypass=False)
        self.assertEqual("src", ct.getSrc())
        self.assertEqual("dst", ct.getDst())
        self.assertEqual(OCIO.TRANSFORM_DIR_INVERSE, ct.getDirection())
        self.assertEqual(False, ct.getDataBypass())

        # Src & dst can't be omitted and can't be empty.
        with self.assertRaises(OCIO.Exception):
            ct = OCIO.ColorSpaceTransform(dst="dst")
        with self.assertRaises(OCIO.Exception):
            ct = OCIO.ColorSpaceTransform(src="src")
        with self.assertRaises(OCIO.Exception):
            ct = OCIO.ColorSpaceTransform(src="", dst="dst")
        with self.assertRaises(OCIO.Exception):
            ct = OCIO.ColorSpaceTransform(src="src", dst="")
        with self.assertRaises(OCIO.Exception):
            ct = OCIO.ColorSpaceTransform("src", "")
    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()
Esempio n. 15
0
        config=config,
        family="Utilities/Curves",
        name="2.4 EOTF Encoding",
        description="2.4 Exponent EOTF Encoding",
        aliases=["2.4 EOTF Encoding", "BT.1886 EOTF Encoding"],
        transforms=transform_list
    )

    ####
    # Displays
    ####

    # Define the specification sRGB Display colourspace
    transform_list = [
        PyOpenColorIO.ColorSpaceTransform(
            src="Linear BT.709",
            dst="2.2 EOTF Encoding"
        )
    ]

    config, colourspace = AgX.add_colourspace(
        config=config,
        family="Displays/SDR",
        name="sRGB",
        description="sRGB IEC 61966-2-1 2.2 Exponent Reference EOTF Display",
        transforms=transform_list,
        referencespace=PyOpenColorIO.ReferenceSpaceType.REFERENCE_SPACE_SCENE
    )

    # TODO: Move this to a different section.
    AgX.add_view(
        displays, "sRGB", "Display Native", "sRGB"
Esempio n. 16
0
 def setUp(self):
     self.tr = OCIO.ColorSpaceTransform()
Esempio n. 17
0
        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(
        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)
Esempio n. 18
0
cs.setAllocationVars([-8.0, 5.0, 0.00390625])
cs.setAllocation(OCIO.Constants.ALLOCATION_LG2)
gt = OCIO.GroupTransform()
gt.push_back(
    OCIO.FileTransform("ProPhotoRGB_to_AP0.spimtx",
                       direction=OCIO.Constants.TRANSFORM_DIR_FORWARD))
cs.setTransform(gt, OCIO.Constants.COLORSPACE_DIR_TO_REFERENCE)
config.addColorSpace(cs)

# Output transforms
cs = OCIO.ColorSpace(name="Output - Rec.709", family="Output")
cs.setDescription("ACES Rec.709 output transform")
cs.setBitDepth(OCIO.Constants.BIT_DEPTH_F32)
gt = OCIO.GroupTransform()
gt.push_back(
    OCIO.ColorSpaceTransform(src="ACES - ACES2065-1",
                             dst="Utility - Log2 48 nits Shaper"))
gt.push_back(
    OCIO.FileTransform("Log2_48_nits_Shaper.RRT.a1.0.1.Rec.709.spi3d",
                       interpolation=OCIO.Constants.INTERP_TETRAHEDRAL,
                       direction=OCIO.Constants.TRANSFORM_DIR_FORWARD))
cs.setTransform(gt, OCIO.Constants.COLORSPACE_DIR_FROM_REFERENCE)
config.addColorSpace(cs)

# Utility transforms
cs = OCIO.ColorSpace(name="Utility - Raw", family="Utility")
cs.setDescription("Raw data")
cs.setBitDepth(OCIO.Constants.BIT_DEPTH_F32)
cs.setIsData(True)
config.addColorSpace(cs)

cs = OCIO.ColorSpace(name="Utility - Log2 48 nits Shaper", family="Utility")
Esempio n. 19
0
    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},
        colorspaces=[
            colorspace_1, colorspace_2, colorspace_3, colorspace_4,
            colorspace_5
        ],
        views=[
            {