Example #1
0
	def testPixelAspectRatio( self ) :

		r = GafferImage.ImageReader()
		r["fileName"].setValue( self.__rgbFilePath+".exr" )
		self.assertEqual( r["out"]["format"].getValue().getPixelAspect(), 1 )
		self.assertEqual( r["out"]["metadata"].getValue()["PixelAspectRatio"], IECore.FloatData( 1 ) )

		# change the Format pixel aspect
		f = GafferImage.Resize()
		f["in"].setInput( r["out"] )
		f["format"].setValue( GafferImage.Format( r["out"]["format"].getValue().getDisplayWindow(), 2. ) )
		self.assertEqual( f["out"]["format"].getValue().getPixelAspect(), 2 )
		# processing does not change metadata
		self.assertEqual( r["out"]["metadata"].getValue()["PixelAspectRatio"], IECore.FloatData( 1 ) )

		testFile = self.__testFile( "pixelAspectFromFormat", "RGBA", "exr" )
		self.failIf( os.path.exists( testFile ) )

		w = GafferImage.ImageWriter()
		w["in"].setInput( f["out"] )
		w["fileName"].setValue( testFile )
		w["channels"].setValue( IECore.StringVectorData( f["out"]["channelNames"].getValue() ) )

		with Gaffer.Context() :
			w.execute()
		self.failUnless( os.path.exists( testFile ) )

		after = GafferImage.ImageReader()
		after["fileName"].setValue( testFile )
		# the image is loaded with the correct pixel aspect
		self.assertEqual( after["out"]["format"].getValue().getPixelAspect(), 2 )
		# the metadata reflects this as well
		self.assertEqual( after["out"]["metadata"].getValue()["PixelAspectRatio"], IECore.FloatData( 2 ) )
Example #2
0
    def testDefaultFormatWrite(self):

        s = Gaffer.ScriptNode()
        w = GafferImage.ImageWriter()
        g = GafferImage.Grade()

        s.addChild(g)
        s.addChild(w)

        testFile = self.__testFilePath + "testBlack.exr"
        self.failIf(os.path.exists(testFile))

        GafferImage.Format.setDefaultFormat(
            s,
            GafferImage.Format(
                IECore.Box2i(IECore.V2i(-7, -2), IECore.V2i(22, 24)), 1.))
        w["in"].setInput(g["out"])
        w["fileName"].setValue(testFile)
        w["channels"].setValue(
            IECore.StringVectorData(g["out"]["channelNames"].getValue()))

        # Try to execute. In older versions of the ImageWriter this would throw an exception.
        with s.context():
            w.execute()
        self.failUnless(os.path.exists(testFile))

        # Check the output.
        expectedFile = self.__defaultFormatFile
        expectedOutput = IECore.Reader.create(expectedFile).read()
        expectedOutput.blindData().clear()

        writerOutput = IECore.Reader.create(testFile).read()
        writerOutput.blindData().clear()

        self.assertEqual(writerOutput, expectedOutput)
Example #3
0
	def testWriteEmptyImage( self ) :

		i = GafferImage.Constant()
		i["format"].setValue( GafferImage.Format( IECore.Box2i( IECore.V2i( 0 ), IECore.V2i( 100 ) ), 1 ) )

		c = GafferImage.Crop()
		c["areaSource"].setValue( GafferImage.Crop.AreaSource.Area )
		c["area"].setValue( IECore.Box2i( IECore.V2i( 40 ), IECore.V2i( 40 ) ) )
		c["affectDisplayWindow"].setValue( False )
		c["affectDataWindow"].setValue( True )
		c["in"].setInput( i["out"] )

		testFile = self.__testFile( "emptyImage", "RGBA", "exr" )
		self.failIf( os.path.exists( testFile ) )

		w = GafferImage.ImageWriter()
		w["in"].setInput( c["out"] )
		w["fileName"].setValue( testFile )

		with Gaffer.Context():
			w.execute()
		self.failUnless( os.path.exists( testFile ) )

		after = GafferImage.ImageReader()
		after["fileName"].setValue( testFile )
		# Check that the data window and the display window are the same
		self.assertEqual( after["out"]["format"].getValue().getDisplayWindow(), after["out"]["dataWindow"].getValue() )
Example #4
0
    def testLargeDataWindowAddedToSmall(self):

        b = GafferImage.Constant()
        b["format"].setValue(GafferImage.Format(500, 500, 1.0))
        b["color"].setValue(imath.Color4f(1, 0, 0, 1))

        a = GafferImage.Constant()
        a["format"].setValue(GafferImage.Format(500, 500, 1.0))
        a["color"].setValue(imath.Color4f(0, 1, 0, 1))

        mask = GafferImage.Constant()
        mask["format"].setValue(GafferImage.Format(500, 500, 1.0))
        mask["color"].setValue(imath.Color4f(0.5))

        bCrop = GafferImage.Crop()
        bCrop["in"].setInput(b["out"])
        bCrop["areaSource"].setValue(bCrop.AreaSource.Area)
        bCrop["area"].setValue(imath.Box2i(imath.V2i(50), imath.V2i(162)))
        bCrop["affectDisplayWindow"].setValue(False)

        m = GafferImage.Mix()
        m["in"][0].setInput(bCrop["out"])
        m["in"][1].setInput(a["out"])
        m["mask"].setInput(mask["out"])

        redSampler = GafferImage.Sampler(
            m["out"], "R", m["out"]["format"].getValue().getDisplayWindow())
        greenSampler = GafferImage.Sampler(
            m["out"], "G", m["out"]["format"].getValue().getDisplayWindow())
        blueSampler = GafferImage.Sampler(
            m["out"], "B", m["out"]["format"].getValue().getDisplayWindow())

        def sample(x, y):

            return imath.Color3f(
                redSampler.sample(x, y),
                greenSampler.sample(x, y),
                blueSampler.sample(x, y),
            )

        # We should only have yellow in areas where the background exists,
        # and should have just green everywhere else.

        self.assertEqual(sample(49, 49), imath.Color3f(0, 0.5, 0))
        self.assertEqual(sample(50, 50), imath.Color3f(0.5, 0.5, 0))
        self.assertEqual(sample(161, 161), imath.Color3f(0.5, 0.5, 0))
        self.assertEqual(sample(162, 162), imath.Color3f(0, 0.5, 0))
Example #5
0
	def testSampleOffsets( self ) :

		ts = GafferImage.ImagePlug.tileSize()

		e = GafferImage.Empty()
		e["format"].setValue( GafferImage.Format( 2048, 1156, 1. ) )

		self.assertEqual( e["out"].sampleOffsets( imath.V2i( 0 ) ), IECore.IntVectorData( [ 0 ] * ts * ts ) )
Example #6
0
	def testOffsetDisplayWindow( self ) :

		box = IECore.Box2i( IECore.V2i( 6, -4 ), IECore.V2i( 49, 149 ) )
		f = GafferImage.Format( box, 1.1 )
		self.assertEqual( f.getDisplayWindow(), box )
		self.assertEqual( f.width(), 44 )
		self.assertEqual( f.height(), 154 )
		self.assertEqual( f.getPixelAspect(), 1.1 )
Example #7
0
    def testAutoConstructFromFormat(self):

        f = GafferImage.Format(
            IECore.Box2i(IECore.V2i(0), IECore.V2i(200, 100)), 0.5)

        d = IECore.CompoundData()
        d["f"] = f
        self.assertEqual(d["f"], GafferImage.FormatData(f))
Example #8
0
	def testDefaultFormat( self ) :

		d = GafferImage.Display()

		with Gaffer.Context() as c :
			self.assertEqual( d["out"]["format"].getValue(), GafferImage.FormatPlug.getDefaultFormat( c ) )
			GafferImage.FormatPlug.setDefaultFormat( c, GafferImage.Format( 200, 150, 1. ) )
			self.assertEqual( d["out"]["format"].getValue(), GafferImage.FormatPlug.getDefaultFormat( c ) )
Example #9
0
	def __constantLayer( self, layer, color, size = IECore.V2i( 512 ) ) :

		result = GafferImage.Constant()
		result["format"].setValue( GafferImage.Format( IECore.Box2i( IECore.V2i( 0 ), size ), 1 ) )
		result["color"].setValue( color )
		result["layer"].setValue( layer )

		return result
Example #10
0
    def testDefaultFormatForImage(self):

        constant = GafferImage.Constant()

        with Gaffer.Context() as c:

            GafferImage.FormatPlug.setDefaultFormat(
                c, GafferImage.Format(100, 200))
            self.assertEqual(
                GafferImage.ImageAlgo.image(constant["out"]).displayWindow,
                imath.Box2i(imath.V2i(0), imath.V2i(99, 199)))

            GafferImage.FormatPlug.setDefaultFormat(
                c, GafferImage.Format(200, 300))
            self.assertEqual(
                GafferImage.ImageAlgo.image(constant["out"]).displayWindow,
                imath.Box2i(imath.V2i(0), imath.V2i(199, 299)))
Example #11
0
    def testEmptyBoxCoordinateSystemTransforms(self):

        f = GafferImage.Format(100, 200)
        self.assertEqual(f.toEXRSpace(IECore.Box2i()), IECore.Box2i())
        self.assertEqual(
            f.toEXRSpace(IECore.Box2i(IECore.V2i(0), IECore.V2i(0))),
            IECore.Box2i())
        self.assertEqual(f.fromEXRSpace(IECore.Box2i()), IECore.Box2i())
Example #12
0
    def testOffsetDisplayWindow(self):

        box = imath.Box2i(imath.V2i(6, -4), imath.V2i(50, 150))
        f = GafferImage.Format(box, 1.1)
        self.assertEqual(f.getDisplayWindow(), box)
        self.assertEqual(f.width(), 44)
        self.assertEqual(f.height(), 154)
        self.assertEqual(f.getPixelAspect(), 1.1)
Example #13
0
	def testSmallDataWindowOverLarge( self ) :

		b = GafferImage.Constant()
		b["format"].setValue( GafferImage.Format( 500, 500, 1.0 ) )
		b["color"].setValue( IECore.Color4f( 1, 0, 0, 1 ) )

		a = GafferImage.Constant()
		a["format"].setValue( GafferImage.Format( 500, 500, 1.0 ) )
		a["color"].setValue( IECore.Color4f( 0, 1, 0, 1 ) )

		mask = GafferImage.Constant()
		mask["format"].setValue( GafferImage.Format( 500, 500, 1.0 ) )
		mask["color"].setValue( IECore.Color4f( 0.75 ) )

		aCrop = GafferImage.Crop()
		aCrop["in"].setInput( a["out"] )
		aCrop["areaSource"].setValue( aCrop.AreaSource.Area )
		aCrop["area"].setValue( IECore.Box2i( IECore.V2i( 50 ), IECore.V2i( 162 ) ) )
		aCrop["affectDisplayWindow"].setValue( False )

		m = GafferImage.Mix()
		m["in"][0].setInput( b["out"] )
		m["in"][1].setInput( aCrop["out"] )
		m["mask"].setInput( mask["out"] )

		redSampler = GafferImage.Sampler( m["out"], "R", m["out"]["format"].getValue().getDisplayWindow() )
		greenSampler = GafferImage.Sampler( m["out"], "G", m["out"]["format"].getValue().getDisplayWindow() )
		blueSampler = GafferImage.Sampler( m["out"], "B", m["out"]["format"].getValue().getDisplayWindow() )

		def sample( x, y ) :

			return IECore.Color3f(
				redSampler.sample( x, y ),
				greenSampler.sample( x, y ),
				blueSampler.sample( x, y ),
			)

		# We should only have green in areas which are inside
		# the data window of aCrop. But we still only take 25%
		# of the red everywhere

		self.assertEqual( sample( 49, 49 ), IECore.Color3f( 0.25, 0, 0 ) )
		self.assertEqual( sample( 50, 50 ), IECore.Color3f( 0.25, 0.75, 0 ) )
		self.assertEqual( sample( 161, 161 ), IECore.Color3f( 0.25, 0.75, 0 ) )
		self.assertEqual( sample( 162, 162 ), IECore.Color3f( 0.25, 0, 0 ) )
Example #14
0
    def testConstructor(self):

        p = GafferImage.FormatPlug()
        self.assertEqual(p.getName(), "FormatPlug")
        self.assertEqual(p.direction(), Gaffer.Plug.Direction.In)
        self.assertEqual(p.defaultValue(), GafferImage.Format())
        self.assertEqual(p.getValue(), GafferImage.Format())
        self.assertEqual(p.getFlags(), Gaffer.Plug.Flags.Default)

        p = GafferImage.FormatPlug(
            "p", Gaffer.Plug.Direction.Out, GafferImage.Format(100, 200, 2),
            Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)
        self.assertEqual(p.getName(), "p")
        self.assertEqual(p.direction(), Gaffer.Plug.Direction.Out)
        self.assertEqual(p.defaultValue(), GafferImage.Format(100, 200, 2))
        self.assertEqual(p.getValue(), GafferImage.Format(100, 200, 2))
        self.assertEqual(p.getFlags(),
                         Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)
Example #15
0
	def testChannelNamesPassThrough( self ) :

		c = GafferImage.Constant()
		r = GafferImage.Reformat()
		r["in"].setInput( c["out"] )
		r["format"].setValue( GafferImage.Format( 200, 150, 1.0 ) )

		self.assertEqual( r["out"]["channelNames"].hash(), c["out"]["channelNames"].hash() )
		self.assertEqual( r["out"]["channelNames"].getValue(), c["out"]["channelNames"].getValue() )
Example #16
0
	def testValue( self ) :

		p = GafferImage.FormatPlug()
		v = GafferImage.Format( imath.Box2i( imath.V2i( 11, 12 ), imath.V2i( 100, 200 ) ), 2 )

		p.setValue( v )
		self.assertEqual( p.getValue(), v )
		self.assertEqual( p["displayWindow"].getValue(), v.getDisplayWindow() )
		self.assertEqual( p["pixelAspect"].getValue(), v.getPixelAspect() )
Example #17
0
	def testDefaultFormatHashRepeatability( self ) :

		allHashes = set()
		for i in range( 0, 1000 ) :
			c = Gaffer.Context()
			GafferImage.FormatPlug.setDefaultFormat( c, GafferImage.Format( 1920, 1080 ) )
			allHashes.add( str( c.hash() ) )

		self.assertEqual( len( allHashes ), 1 )
Example #18
0
 def testTileHashes(self):
     # Test that two tiles within the image have the same hash.
     c = GafferImage.Constant()
     c["format"].setValue(GafferImage.Format(2048, 1156, 1.))
     c["color"][0].setValue(.5)
     h1 = c["out"].channelData("R", IECore.V2i(0)).hash()
     h2 = c["out"].channelData(
         "R", IECore.V2i(GafferImage.ImagePlug().tileSize())).hash()
     self.assertEqual(h1, h2)
Example #19
0
    def testDefaultColorSpaceFunctionArguments(self):

        # Make a network to write and read an image
        # in various formats.

        c = GafferImage.Constant()
        c["format"].setValue(GafferImage.Format(64, 64))

        w = GafferImage.ImageWriter()
        w["in"].setInput(c["out"])

        r = GafferImage.ImageReader()
        r["fileName"].setInput(w["fileName"])

        # Register a custom colorspace function that
        # just captures its arguments.

        capturedArguments = {}

        def f(fileName, fileFormat, dataType, metadata):

            capturedArguments.update({
                "fileName": fileName,
                "fileFormat": fileFormat,
                "dataType": dataType,
                "metadata": metadata,
            })
            return "linear"

        GafferImage.ImageReader.setDefaultColorSpaceFunction(f)

        # Verify that the correct arguments are passed for
        # a variety of fileNames and dataTypes.

        for ext, fileFormat, dataType in [
            ("exr", "openexr", "half"),
            ("dpx", "dpx", "uint12"),
            ("TIFF", "tiff", "float"),
            ("tif", "tiff", "uint32"),
        ]:

            w["fileName"].setValue("{0}/{1}.{2}".format(
                self.temporaryDirectory(), dataType, ext))
            w[fileFormat]["dataType"].setValue(dataType)
            w.execute()

            capturedArguments.clear()
            r["out"].channelData(
                "R", imath.V2i(0))  # Triggers call to color space function

            self.assertEqual(len(capturedArguments), 4)
            self.assertEqual(capturedArguments["fileName"],
                             w["fileName"].getValue())
            self.assertEqual(capturedArguments["fileFormat"], fileFormat)
            self.assertEqual(capturedArguments["dataType"], dataType)
            self.assertEqual(capturedArguments["metadata"],
                             r["out"]["metadata"].getValue())
Example #20
0
    def testEmptyDataWindow(self):

        e = self.emptyImage()

        r = GafferImage.Resize()
        r["in"].setInput(e["out"])
        r["format"].setValue(GafferImage.Format(2121, 1012))

        self.assertEqual(r["out"]["dataWindow"].getValue(), imath.Box2i())
Example #21
0
	def testDataWindowWhenBNotConnected( self ) :
	
		a = GafferImage.Constant()
		a["format"].setValue( GafferImage.Format( 100, 200 ) )
		
		m = GafferImage.Merge()
		m["in"][1].setInput( a["out"] )
		
		self.assertEqual( m["out"]["dataWindow"].getValue(), a["out"]["dataWindow"].getValue() )
Example #22
0
    def testSmallDataWindowOverLarge(self):

        b = GafferImage.Constant()
        b["format"].setValue(GafferImage.Format(500, 500, 1.0))
        b["color"].setValue(imath.Color4f(1, 0, 0, 1))

        a = GafferImage.Constant()
        a["format"].setValue(GafferImage.Format(500, 500, 1.0))
        a["color"].setValue(imath.Color4f(0, 1, 0, 1))

        aCrop = GafferImage.Crop()
        aCrop["in"].setInput(a["out"])
        aCrop["areaSource"].setValue(aCrop.AreaSource.Area)
        aCrop["area"].setValue(imath.Box2i(imath.V2i(50), imath.V2i(162)))
        aCrop["affectDisplayWindow"].setValue(False)

        m = GafferImage.Merge()
        m["operation"].setValue(m.Operation.Over)
        m["in"][0].setInput(b["out"])
        m["in"][1].setInput(aCrop["out"])

        redSampler = GafferImage.Sampler(
            m["out"], "R", m["out"]["format"].getValue().getDisplayWindow())
        greenSampler = GafferImage.Sampler(
            m["out"], "G", m["out"]["format"].getValue().getDisplayWindow())
        blueSampler = GafferImage.Sampler(
            m["out"], "B", m["out"]["format"].getValue().getDisplayWindow())

        def sample(x, y):

            return imath.Color3f(
                redSampler.sample(x, y),
                greenSampler.sample(x, y),
                blueSampler.sample(x, y),
            )

        # We should only have overed green in areas which are inside
        # the data window of aCrop. Everywhere else we should have
        # red still.

        self.assertEqual(sample(49, 49), imath.Color3f(1, 0, 0))
        self.assertEqual(sample(50, 50), imath.Color3f(0, 1, 0))
        self.assertEqual(sample(161, 161), imath.Color3f(0, 1, 0))
        self.assertEqual(sample(162, 162), imath.Color3f(1, 0, 0))
Example #23
0
    def testSetDriver(self):

        driversCreated = GafferTest.CapturingSlot(
            GafferImage.Display.driverCreatedSignal())

        server = IECoreImage.DisplayDriverServer()
        dataWindow = IECore.Box2i(IECore.V2i(0), IECore.V2i(100))

        driver = self.Driver(GafferImage.Format(dataWindow),
                             dataWindow, ["Y"],
                             port=server.portNumber())

        self.assertTrue(len(driversCreated), 1)

        display = GafferImage.Display()
        self.assertTrue(display.getDriver() is None)

        display.setDriver(driversCreated[0][0])
        self.assertTrue(display.getDriver().isSame(driversCreated[0][0]))

        driver.sendBucket(dataWindow, [
            IECore.FloatVectorData(
                [0.5] * dataWindow.size().x * dataWindow.size().y)
        ])

        self.assertEqual(
            display["out"]["format"].getValue().getDisplayWindow(), dataWindow)
        self.assertEqual(display["out"]["dataWindow"].getValue(), dataWindow)
        self.assertEqual(display["out"]["channelNames"].getValue(),
                         IECore.StringVectorData(["Y"]))
        self.assertEqual(
            display["out"].channelData("Y", IECore.V2i(0)),
            IECore.FloatVectorData([0.5] * GafferImage.ImagePlug.tileSize() *
                                   GafferImage.ImagePlug.tileSize()))

        display2 = GafferImage.Display()
        display2.setDriver(display.getDriver(), copy=True)

        self.assertImagesEqual(display["out"], display2["out"])

        driver.sendBucket(dataWindow, [
            IECore.FloatVectorData(
                [1] * dataWindow.size().x * dataWindow.size().y)
        ])

        self.assertEqual(
            display["out"].channelData("Y", IECore.V2i(0)),
            IECore.FloatVectorData([1] * GafferImage.ImagePlug.tileSize() *
                                   GafferImage.ImagePlug.tileSize()))

        self.assertEqual(
            display2["out"].channelData("Y", IECore.V2i(0)),
            IECore.FloatVectorData([0.5] * GafferImage.ImagePlug.tileSize() *
                                   GafferImage.ImagePlug.tileSize()))

        driver.close()
Example #24
0
	def testTileHashes( self ) :

		semaphore = threading.Semaphore( 0 )
		imageReceivedConnection = GafferImage.Display.imageReceivedSignal().connect( lambda plug : semaphore.release() )

		node = GafferImage.Display()
		node["port"].setValue( 2500 )

		gafferDisplayWindow = IECore.Box2i( IECore.V2i( -100, -200 ), IECore.V2i( 303, 557 ) )
		gafferFormat = GafferImage.Format( gafferDisplayWindow, 1.0 )

		externalDisplayWindow = gafferFormat.toEXRSpace( gafferDisplayWindow )

		externalDataWindow = externalDisplayWindow
		gafferDataWindow = gafferDisplayWindow
		driver = IECore.ClientDisplayDriver(
			externalDisplayWindow,
			externalDataWindow,
			[ "Y" ],
			{
				"displayHost" : "localHost",
				"displayPort" : "2500",
				"remoteDisplayType" : "GafferImage::GafferDisplayDriver",
			}
		)

		for i in range( 0, 1000 ) :

			h1 = self.__tileHashes( node, "Y" )
			t1 = self.__tiles( node, "Y" )

			externalBucketWindow = IECore.Box2i()
			for j in range( 0, 2 ) :
				externalBucketWindow.extendBy(
					IECore.V2i(
						int( random.uniform( externalDisplayWindow.min.x, externalDisplayWindow.max.x ) ),
						int( random.uniform( externalDisplayWindow.min.y, externalDisplayWindow.max.y ) ),
					)
				)

			numPixels = ( externalBucketWindow.size().x + 1 ) * ( externalBucketWindow.size().y + 1 )
			bucketData = IECore.FloatVectorData()
			bucketData.resize( numPixels, i + 1 )

			self.__sendBucket( driver, externalBucketWindow, bucketData )

			h2 = self.__tileHashes( node, "Y" )
			t2 = self.__tiles( node, "Y" )

			gafferBucketWindow = gafferFormat.fromEXRSpace( externalBucketWindow )

			self.__assertTilesChangedInRegion( t1, t2, gafferBucketWindow )
			self.__assertTilesChangedInRegion( h1, h2, gafferBucketWindow )

		driver.imageClose()
		semaphore.acquire()
Example #25
0
    def testDisable(self):

        c = GafferImage.Constant()
        c["format"].setValue(GafferImage.Format(100, 100))

        r = GafferImage.Resize()
        r["in"].setInput(c["out"])
        r["format"].setValue(GafferImage.Format(200, 200))

        self.assertEqual(r["out"]["format"].getValue(),
                         GafferImage.Format(200, 200))
        self.assertEqual(r["out"]["dataWindow"].getValue(),
                         IECore.Box2i(IECore.V2i(0), IECore.V2i(200)))

        r["enabled"].setValue(False)
        self.assertEqual(r["out"]["format"].getValue(),
                         GafferImage.Format(100, 100))
        self.assertEqual(r["out"]["dataWindow"].getValue(),
                         IECore.Box2i(IECore.V2i(0), IECore.V2i(100)))
Example #26
0
    def testFormatDependencies(self):

        r = GafferImage.Resize()
        cs = GafferTest.CapturingSlot(r.plugDirtiedSignal())

        r["format"].setValue(GafferImage.Format(100, 200, 2))
        dirtiedPlugs = set(c[0] for c in cs)

        self.assertTrue(r["out"]["format"] in dirtiedPlugs)
        self.assertTrue(r["out"]["dataWindow"] in dirtiedPlugs)
Example #27
0
	def testMixParm( self ) :

		b = GafferImage.Constant()
		b["format"].setValue( GafferImage.Format( 50, 50, 1.0 ) )
		b["color"].setValue( IECore.Color4f( 1, 0, 0, 1 ) )

		a = GafferImage.Constant()
		a["format"].setValue( GafferImage.Format( 50, 50, 1.0 ) )
		a["color"].setValue( IECore.Color4f( 0, 1, 0, 1 ) )

		mask = GafferImage.Constant()
		mask["format"].setValue( GafferImage.Format( 50, 50, 1.0 ) )
		mask["color"].setValue( IECore.Color4f( 0.5 ) )

		m = GafferImage.Mix()
		m["in"][0].setInput( b["out"] )
		m["in"][1].setInput( a["out"] )


		def sample( x, y ) :
			redSampler = GafferImage.Sampler( m["out"], "R", m["out"]["format"].getValue().getDisplayWindow() )
			greenSampler = GafferImage.Sampler( m["out"], "G", m["out"]["format"].getValue().getDisplayWindow() )
			blueSampler = GafferImage.Sampler( m["out"], "B", m["out"]["format"].getValue().getDisplayWindow() )

			return IECore.Color3f(
				redSampler.sample( x, y ),
				greenSampler.sample( x, y ),
				blueSampler.sample( x, y ),
			)

		# Using just mix
		m["mix"].setValue( 0.75 )
		self.assertEqual( sample( 49, 49 ), IECore.Color3f( 0.25, 0.75, 0 ) )
		m["mix"].setValue( 0.25 )
		self.assertEqual( sample( 49, 49 ), IECore.Color3f( 0.75, 0.25, 0 ) )

		# Using mask multiplied with mix
		m["mask"].setInput( mask["out"] )
		self.assertEqual( sample( 49, 49 ), IECore.Color3f( 0.875, 0.125, 0 ) )

		# Using invalid channel of mask defaults to just mix
		m["maskChannel"].setValue( "DOES_NOT_EXIST" )
		self.assertEqual( sample( 49, 49 ), IECore.Color3f( 0.75, 0.25, 0 ) )
Example #28
0
    def testDefaultFormat(self):
        constant = GafferImage.Constant()

        oslImage = GafferOSL.OSLImage()
        oslImage["channels"].addChild(
            Gaffer.NameValuePlug("", imath.Color3f(0.5, 0.6, 0.7)))

        self.assertEqual(oslImage["out"]["dataWindow"].getValue(),
                         imath.Box2i(imath.V2i(0), imath.V2i(1920, 1080)))
        self.assertEqual(
            oslImage["out"]["format"].getValue().getDisplayWindow(),
            imath.Box2i(imath.V2i(0), imath.V2i(1920, 1080)))

        oslImage["defaultFormat"].setValue(
            GafferImage.Format(imath.Box2i(imath.V2i(0), imath.V2i(5))))

        self.assertEqual(oslImage["out"]["dataWindow"].getValue(),
                         imath.Box2i(imath.V2i(0), imath.V2i(5, 5)))
        self.assertEqual(
            oslImage["out"]["format"].getValue().getDisplayWindow(),
            imath.Box2i(imath.V2i(0), imath.V2i(5, 5)))
        self.assertEqual(
            GafferImage.ImageAlgo.image(oslImage["out"])["G"],
            IECore.FloatVectorData([0.6] * 25))

        oslImage["in"].setInput(constant["out"])

        self.assertEqual(oslImage["out"]["dataWindow"].getValue(),
                         imath.Box2i(imath.V2i(0), imath.V2i(1920, 1080)))
        self.assertEqual(
            oslImage["out"]["format"].getValue().getDisplayWindow(),
            imath.Box2i(imath.V2i(0), imath.V2i(1920, 1080)))

        constant["format"].setValue(
            GafferImage.Format(imath.Box2i(imath.V2i(0), imath.V2i(4))))
        self.assertEqual(oslImage["out"]["dataWindow"].getValue(),
                         imath.Box2i(imath.V2i(0), imath.V2i(4, 4)))
        self.assertEqual(
            oslImage["out"]["format"].getValue().getDisplayWindow(),
            imath.Box2i(imath.V2i(0), imath.V2i(4, 4)))
        self.assertEqual(
            GafferImage.ImageAlgo.image(oslImage["out"])["G"],
            IECore.FloatVectorData([0.6] * 16))
Example #29
0
    def testCrashWithResizedInput(self):

        b = GafferImage.Constant()
        b["format"].setValue(GafferImage.Format(2048, 1556))

        bResized = GafferImage.Resize()
        bResized["in"].setInput(b["out"])
        bResized["format"].setValue(GafferImage.Format(1920, 1080))
        bResized["fitMode"].setValue(bResized.FitMode.Fit)

        a = GafferImage.Constant()
        a["format"].setValue(GafferImage.Format(1920, 1080))

        merge = GafferImage.Merge()
        merge["operation"].setValue(merge.Operation.Over)
        merge["in"][0].setInput(bResized["out"])
        merge["in"][1].setInput(a["out"])

        GafferImageTest.processTiles(merge["out"])
	def __formatLabel( self, fmt ) :

		if fmt == GafferImage.Format() :
			return "Default ( %s )" % GafferImage.FormatPlug.getDefaultFormat( self.getContext() )
		else :
			name = GafferImage.Format.name( fmt )
			if name :
				return "%s ( %s )" % ( name, str( fmt ) )
			else :
				return "Custom"