Esempio n. 1
0
	def testChannelData( self ) :

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

		for chan in [ "R", "G", "B", "A", "Z", "ZBack" ] :
			self.assertEqual( e["out"].channelData( chan, imath.V2i( 0 ) ), IECore.FloatVectorData( [] ) )
Esempio n. 2
0
    def testMismatchThrows(self):

        deep = GafferImage.Empty()
        flat = GafferImage.Constant()

        mix = GafferImage.Mix()
        mix["mix"].setValue(0.5)
        mix["in"][0].setInput(flat["out"])
        mix["in"][1].setInput(flat["out"])

        self.assertNotEqual(GafferImage.ImageAlgo.imageHash(mix["out"]),
                            GafferImage.ImageAlgo.imageHash(flat["out"]))
        GafferImage.ImageAlgo.tiles(mix["out"])

        mix["in"][0].setInput(deep["out"])
        six.assertRaisesRegex(
            self, RuntimeError,
            'Mix.out.deep : Cannot mix between deep and flat image.',
            GafferImage.ImageAlgo.tiles, mix["out"])
        mix["in"][0].setInput(flat["out"])
        mix["in"][1].setInput(deep["out"])
        six.assertRaisesRegex(
            self, RuntimeError,
            'Mix.out.deep : Cannot mix between deep and flat image.',
            GafferImage.ImageAlgo.tiles, mix["out"])

        mix["in"][0].setInput(deep["out"])
        GafferImage.ImageAlgo.tiles(mix["out"])
Esempio n. 3
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 ) )
Esempio n. 4
0
	def assertRaisesDeepNotSupported( self, node ) :

		flat = GafferImage.Constant()
		node["in"].setInput( flat["out"] )

		self.assertNotEqual( GafferImage.ImageAlgo.imageHash( flat["out"] ), GafferImage.ImageAlgo.imageHash( node["out"] ) )

		deep = GafferImage.Empty()
		node["in"].setInput( deep["out"] )
		six.assertRaisesRegex( self, RuntimeError, 'Deep data not supported in input "in*', GafferImage.ImageAlgo.image, node["out"] )
Esempio n. 5
0
	def testFormatHash( self ) :

		# Check that the data and sampleOffsets hashes don't change when the format does.
		e = GafferImage.Empty()
		e["format"].setValue( GafferImage.Format( 2048, 1156, 1. ) )
		channelDataHash1 = e["out"].channelDataHash( "R", imath.V2i( 0 ) )
		sampleOffsetsHash1 = e["out"].sampleOffsetsHash( imath.V2i( 0 ) )
		e["format"].setValue( GafferImage.Format( 1920, 1080, 1. ) )
		channelDataHash2 = e["out"].channelDataHash( "R", imath.V2i( 0 ) )
		sampleOffsetsHash2 = e["out"].sampleOffsetsHash( imath.V2i( 0 ) )
		self.assertEqual( channelDataHash1, channelDataHash2 )
		self.assertEqual( sampleOffsetsHash1, sampleOffsetsHash2 )
Esempio n. 6
0
	def testFormatDependencies( self ) :

		e = GafferImage.Empty()

		self.assertEqual(
			e.affects( e["format"]["displayWindow"]["min"]["x"] ),
			[ e["out"]["format"], e["out"]["dataWindow"] ],
		)
		self.assertEqual(
			e.affects( e["format"]["pixelAspect"] ),
			[ e["out"]["format"] ],
		)
Esempio n. 7
0
	def testTileHashes( self ) :

		# Test that two tiles within the image have the same hash.
		e = GafferImage.Empty()
		e["format"].setValue( GafferImage.Format( 2048, 1156, 1. ) )

		self.assertEqual(
			e["out"].channelDataHash( "R", imath.V2i( 0 ) ),
			e["out"].channelDataHash( "R", imath.V2i( GafferImage.ImagePlug().tileSize() ) ),
		)

		self.assertEqual(
			e["out"].sampleOffsetsHash( imath.V2i( 0 ) ),
			e["out"].sampleOffsetsHash( imath.V2i( GafferImage.ImagePlug().tileSize() ) ),
		)
Esempio n. 8
0
	def testNonFlatThrows( self ) :

		deep = GafferImage.Empty()
		flat = GafferImage.Constant()

		merge = GafferImage.Merge()
		merge["in"][0].setInput( flat["out"] )
		merge["in"][1].setInput( flat["out"] )

		self.assertNotEqual( GafferImage.ImageAlgo.imageHash( merge["out"] ), GafferImage.ImageAlgo.imageHash( flat["out"] ) )

		merge["in"][0].setInput( deep["out"] )
		six.assertRaisesRegex( self, RuntimeError, 'Deep data not supported in input "in.in0"', GafferImage.ImageAlgo.image, merge["out"] )
		merge["in"][0].setInput( flat["out"] )
		merge["in"][1].setInput( deep["out"] )
		six.assertRaisesRegex( self, RuntimeError, 'Deep data not supported in input "in.in1"', GafferImage.ImageAlgo.image, merge["out"] )
Esempio n. 9
0
	def testTileIdentity( self ) :

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

		# The channelData() binding returns a copy by default, so we wouldn't
		# expect two tiles to be referencing the same object.
		self.assertFalse(
			e["out"].channelData( "R", imath.V2i( 0 ) ).isSame(
				e["out"].channelData( "R", imath.V2i( GafferImage.ImagePlug.tileSize() ) )
			)
		)

		# But behind the scenes we do want them to be the same, so
		# check that that is the case.
		self.assertTrue(
			e["out"].channelData( "R", imath.V2i( 0 ), _copy = False ).isSame(
				e["out"].channelData( "R", imath.V2i( GafferImage.ImagePlug.tileSize() ), _copy = False )
			)
		)
Esempio n. 10
0
	def testOccludeAll( self ) :
		representativeImage = GafferImage.ImageReader()
		representativeImage["fileName"].setValue( self.representativeImagePath )

		constantNodes = self.__getConstant( 0.1, 0.2, 0.3, 1, -10, -10, imath.V2i( 150, 100 ) )

		empty = GafferImage.Empty()
		empty["format"].setValue( GafferImage.Format( imath.Box2i( imath.V2i( 0 ), imath.V2i( 150, 100 ) ), 1 ) )

		deepConstant = GafferImage.DeepMerge()
		deepConstant["in"][0].setInput( constantNodes[1]["out"] )
		deepConstant["in"][1].setInput( empty["out"] )

		deepMerge = GafferImage.DeepMerge()
		deepMerge["in"][0].setInput( representativeImage["out"] )
		deepMerge["in"][1].setInput( deepConstant["out"] )

		deepState = GafferImage.DeepState()
		deepState["in"].setInput( deepMerge["out"] )
		deepState["pruneOccluded"].setValue( True )

		self.assertEqual( GafferImage.ImageAlgo.tiles( constantNodes[1]["out"] ), GafferImage.ImageAlgo.tiles( constantNodes[1]["out"] ) )
Esempio n. 11
0
	def testPracticalTransparencyPrune( self ) :
		representativeImage = GafferImage.ImageReader()
		representativeImage["fileName"].setValue( self.representativeImagePath )

		empty = GafferImage.Empty()
		empty["format"].setValue( GafferImage.Format( imath.Box2i( imath.V2i( 0 ), imath.V2i( 150, 100 ) ), 1 ) )

		properlyLabelledIn = GafferImage.DeepMerge()
		properlyLabelledIn["in"][0].setInput( representativeImage["out"] )
		properlyLabelledIn["in"][1].setInput( empty["out"] )

		# The representative image from Arnold actually contains overlaps one floating point epsilon in width.
		# Get rid of those, and then we can see the sampleCounts change in a predictable way
		actuallyTidyIn = GafferImage.DeepState()
		actuallyTidyIn["in"].setInput( properlyLabelledIn["out"] )

		prune = GafferImage.DeepState()
		prune["in"].setInput( actuallyTidyIn["out"] )
		prune["pruneTransparent"].setValue( True )

		flatRef = GafferImage.DeepState()
		flatRef["in"].setInput( actuallyTidyIn["out"] )
		flatRef["deepState"].setValue( GafferImage.DeepState.TargetState.Flat )

		flatPrune = GafferImage.DeepState()
		flatPrune["in"].setInput( prune["out"] )
		flatPrune["deepState"].setValue( GafferImage.DeepState.TargetState.Flat )

		diff = GafferImage.Merge()
		diff['operation'].setValue( GafferImage.Merge.Operation.Difference )
		diff['in'][0].setInput( flatPrune["out"] )
		diff['in'][1].setInput( flatRef["out"] )

		diffStats = GafferImage.ImageStats()
		diffStats["in"].setInput( diff["out"] )
		diffStats["area"].setValue( diff["out"].dataWindow() )


		origCounts = GafferImage.DeepSampleCounts()
		origCounts["in"].setInput( actuallyTidyIn["out"] )

		prunedCounts = GafferImage.DeepSampleCounts()
		prunedCounts["in"].setInput( prune["out"] )

		diffCounts = GafferImage.Merge()
		diffCounts["operation"].setValue( GafferImage.Merge.Operation.Subtract )
		diffCounts["in"][0].setInput( origCounts["out"] )
		diffCounts["in"][1].setInput( prunedCounts["out"] )

		diffCountsStats = GafferImage.ImageStats()
		diffCountsStats["in"].setInput( diffCounts["out"] )
		diffCountsStats["area"].setValue( diffCounts["out"].dataWindow() )

		self.assertEqual( diffCountsStats["max"].getValue()[0], 0 )
		# For some reason, our test data from Arnold has a bunch of transparent pixels to start with,
		# so we've got some stuff to throw out
		self.assertLess( diffCountsStats["min"].getValue()[0], -20 )
		self.assertLess( diffCountsStats["min"].getValue()[0], -0.26 )

		# We've got some moderate error introduced by discarding transparent.  Why is it so large?
		# Looks like those transparent pixels are slightly emissive
		for i in range( 4 ):
			self.assertLessEqual( diffStats["max"].getValue()[i], [0.00001,0.00001,0.00001,0][i] )
			self.assertGreaterEqual( diffStats["max"].getValue()[i], [0.000001,0.000001,0.000001,0][i] )

		# By premulting/unpremulting, we zero out samples with no alpha
		premultiply = GafferImage.Premultiply()
		premultiply["in"].setInput( actuallyTidyIn["out"] )
		unpremultiply = GafferImage.Unpremultiply()
		unpremultiply["in"].setInput( premultiply["out"] )
		flatRef["in"].setInput( unpremultiply["out"] )
		prune["in"].setInput( unpremultiply["out"] )

		# That gets us a couple extra digits of matching - this is more like what we would expect based
		# on floating point precision
		for i in range( 4 ):
			self.assertLessEqual( diffStats["max"].getValue()[i], [0.0000005,0.0000005,0.0000005,0][i] )

		# But now lets hack it to really make some transparent pixels
		grade = GafferImage.Grade()
		grade["in"].setInput( actuallyTidyIn["out"] )
		grade["channels"].setValue( '[A]' )
		grade["multiply"]["a"].setValue( 1.5 )
		grade["offset"]["a"].setValue( -0.5 )

		premultiply['in'].setInput( grade["out"] )

		# Now we can kill lots of samples
		self.assertEqual( diffCountsStats["max"].getValue()[0], 0 )
		self.assertLess( diffCountsStats["min"].getValue()[0], -200 )
		self.assertLess( diffCountsStats["min"].getValue()[0], -10 )

		# And the flattened results still match closely
		for i in range( 4 ):
			self.assertLessEqual( diffStats["max"].getValue()[i], [0.0000005,0.0000005,0.0000005,0.0000002][i] )
Esempio n. 12
0
	def testDeep( self ) :

		empty = GafferImage.Empty()
		empty["format"].setValue( GafferImage.Format( imath.Box2i( imath.V2i( 0 ), imath.V2i( 511 ) ), 1 ) )

		self.assertEqual( empty["out"]["deep"].getValue(), True )
Esempio n. 13
0
	def testChannelNames( self ) :

		e = GafferImage.Empty()
		self.assertEqual( e["out"]["channelNames"].getValue(), IECore.StringVectorData( [] ) )
Esempio n. 14
0
	def testEnableBehaviour( self ) :

		e = GafferImage.Empty()
		self.assertTrue( e.enabledPlug().isSame( e["enabled"] ) )
		self.assertEqual( e.correspondingInput( e["out"] ), None )
		self.assertEqual( e.correspondingInput( e["format"] ), None )