def testEmpty(self): self.assertTrue(GafferImage.BufferAlgo.empty(imath.Box2i())) self.assertTrue( GafferImage.BufferAlgo.empty( imath.Box2i(imath.V2i(0), imath.V2i(0)))) self.assertFalse( GafferImage.BufferAlgo.empty( imath.Box2i(imath.V2i(0), imath.V2i(1)))) self.assertTrue( GafferImage.BufferAlgo.empty( imath.Box2i(imath.V2i(2147483646), imath.V2i(-2147483646)))) self.assertTrue( GafferImage.BufferAlgo.empty( imath.Box2i(imath.V2i(0), imath.V2i(-2147483647)))) self.assertTrue( GafferImage.BufferAlgo.empty( imath.Box2i(imath.V2i(2147483647), imath.V2i(0)))) self.assertTrue( GafferImage.BufferAlgo.empty( imath.Box2i(imath.V2i(-1), imath.V2i(-2147483647)))) self.assertTrue( GafferImage.BufferAlgo.empty( imath.Box2i(imath.V2i(2147483647), imath.V2i(1)))) self.assertTrue( GafferImage.BufferAlgo.empty( imath.Box2i(imath.V2i(1), imath.V2i(-2147483647)))) self.assertTrue( GafferImage.BufferAlgo.empty( imath.Box2i(imath.V2i(2147483647), imath.V2i(-1))))
def testIntersection(self): self.assertEqual( GafferImage.BufferAlgo.intersection( imath.Box2i(imath.V2i(1, 2), imath.V2i(9, 10)), imath.Box2i(imath.V2i(2, 0), imath.V2i(8, 29)), ), imath.Box2i(imath.V2i(2, 2), imath.V2i(8, 10)))
def testDeep( self ) : representativeDeep = GafferImage.ImageReader() representativeDeep["fileName"].setValue( self.representativeDeepImagePath ) deepCrop = GafferImage.Crop() deepCrop["in"].setInput( representativeDeep["out"] ) postFlatten = GafferImage.DeepToFlat() postFlatten["in"].setInput( deepCrop["out"] ) preFlatten = GafferImage.DeepToFlat() preFlatten["in"].setInput( representativeDeep["out"] ) flatCrop = GafferImage.Crop() flatCrop["in"].setInput( preFlatten["out"] ) dataWindow = representativeDeep["out"].dataWindow() for affectDisplay in [ True, False ]: for area in [ imath.Box2i( imath.V2i( 0, 0 ), imath.V2i( 150, 100 ) ), imath.Box2i( imath.V2i( -10, -13 ), imath.V2i( 157, 103 ) ), imath.Box2i( imath.V2i( 10, 13 ), imath.V2i( 143, 77 ) ), imath.Box2i( imath.V2i( 37, 65 ), imath.V2i( 101, 67 ) ), imath.Box2i( imath.V2i( 0, 0 ), imath.V2i( 149, 99 ) ) ] : deepCrop["area"].setValue( area ) flatCrop["area"].setValue( area ) self.assertImagesEqual( postFlatten["out"], flatCrop["out"] )
def testOnePixelBlur(self): constant = GafferImage.Constant() constant["color"].setValue(imath.Color4f(1)) crop = GafferImage.Crop() crop["in"].setInput(constant["out"]) crop["area"].setValue(imath.Box2i(imath.V2i(10), imath.V2i(11))) crop["affectDisplayWindow"].setValue(False) blur = GafferImage.Blur() blur["in"].setInput(crop["out"]) blur["radius"].setValue(imath.V2f(1)) blur["expandDataWindow"].setValue(True) sampler = GafferImage.Sampler(blur["out"], "R", imath.Box2i(imath.V2i(0), imath.V2i(20))) # Centre is brightest self.assertGreater(sampler.sample(10, 10), sampler.sample(11, 10)) # Corners are least bright self.assertGreater(sampler.sample(11, 10), sampler.sample(11, 11)) self.assertGreater(sampler.sample(11, 11), 0) # Shape is symmetrical self.assertEqual(sampler.sample(11, 10), sampler.sample(9, 10)) self.assertEqual(sampler.sample(10, 11), sampler.sample(10, 9)) self.assertEqual(sampler.sample(10, 11), sampler.sample(10, 9)) self.assertEqual(sampler.sample(9, 9), sampler.sample(11, 9)) self.assertEqual(sampler.sample(9, 9), sampler.sample(11, 11)) self.assertEqual(sampler.sample(9, 9), sampler.sample(9, 11))
def testWriteDataWindowFormatToNonDataWindowFormat(self): # source data window inside display window displayWindow = imath.Box2i(imath.V2i(0, 0), imath.V2i(99, 99)) dataWindow = imath.Box2i(imath.V2i(10, 10), imath.V2i(50, 50)) imgOrig = self.__makeFloatImage(dataWindow, displayWindow) w = IECore.Writer.create(imgOrig, "test/IECoreImage/data/jpg/output.jpg") self.assertEqual(type(w), IECoreImage.ImageWriter) w.write() self.assertTrue(os.path.exists("test/IECoreImage/data/jpg/output.jpg")) r = IECore.Reader.create("test/IECoreImage/data/jpg/output.jpg") imgNew = r.read() self.__verifyImageRGB(imgNew, imgOrig, maxError=0.05) # source data window outside display window displayWindow = imath.Box2i(imath.V2i(0, 0), imath.V2i(99, 99)) dataWindow = imath.Box2i(imath.V2i(-10, -10), imath.V2i(99, 99)) imgOrig = self.__makeFloatImage(dataWindow, displayWindow) w = IECore.Writer.create(imgOrig, "test/IECoreImage/data/jpg/output.jpg") self.assertEqual(type(w), IECoreImage.ImageWriter) w.write() self.assertTrue(os.path.exists("test/IECoreImage/data/jpg/output.jpg"))
def test( self ) : n = GafferImage.OpenImageIOReader() n["fileName"].setValue( self.fileName ) self.assertEqual( n["out"]["dataWindow"].getValue(), imath.Box2i( imath.V2i( 0 ), imath.V2i( 200, 150 ) ) ) self.assertEqual( n["out"]["format"].getValue().getDisplayWindow(), imath.Box2i( imath.V2i( 0 ), imath.V2i( 200, 150 ) ) ) expectedMetadata = IECore.CompoundData( { "oiio:ColorSpace" : IECore.StringData( 'Linear' ), "compression" : IECore.StringData( 'zips' ), "PixelAspectRatio" : IECore.FloatData( 1 ), "screenWindowCenter" : IECore.V2fData( imath.V2f( 0, 0 ) ), "screenWindowWidth" : IECore.FloatData( 1 ), "fileFormat" : IECore.StringData( "openexr" ), "dataType" : IECore.StringData( "float" ), } ) self.assertEqual( n["out"]["metadata"].getValue(), expectedMetadata ) channelNames = n["out"]["channelNames"].getValue() self.failUnless( isinstance( channelNames, IECore.StringVectorData ) ) self.failUnless( "R" in channelNames ) self.failUnless( "G" in channelNames ) self.failUnless( "B" in channelNames ) self.failUnless( "A" in channelNames ) image = GafferImage.ImageAlgo.image( n["out"] ) self.assertEqual( image.blindData(), IECore.CompoundData( dict(expectedMetadata) ) ) image2 = IECore.Reader.create( self.fileName ).read() image.blindData().clear() image2.blindData().clear() self.assertEqual( image, image2 )
def testWindowWrite(self): dataWindow = imath.Box2i(imath.V2i(0, 0), imath.V2i(99, 99)) imgOrig = self.__makeFloatImage(dataWindow, dataWindow) imgOrig.displayWindow = imath.Box2i(imath.V2i(-20, -20), imath.V2i(199, 199)) w = IECore.Writer.create( imgOrig, os.path.join("test", "IECoreImage", "data", "exr", "output.exr")) self.assertIsInstance(w, IECoreImage.ImageWriter) w.write() self.assertTrue( os.path.exists( os.path.join("test", "IECoreImage", "data", "exr", "output.exr"))) r = IECore.Reader.create( os.path.join("test", "IECoreImage", "data", "exr", "output.exr")) imgNew = r.read() self.__verifyImageRGB(imgNew, imgOrig)
def testHash(self): w = imath.Box2i(imath.V2i(0), imath.V2i(10)) i = IECoreImage.ImagePrimitive(w, w) h = i.hash() i.displayWindow = imath.Box2i(imath.V2i(10), imath.V2i(20)) self.assertNotEqual(i.hash(), h) h = i.hash() i.dataWindow = imath.Box2i(imath.V2i(10), imath.V2i(20)) self.assertNotEqual(i.hash(), h) h = i.hash() i["R"] = IECore.IntData(10) self.assertNotEqual(i.hash(), h) h = i.hash() i["R"] = IECore.FloatData(10) self.assertNotEqual(i.hash(), h) h = i.hash() i["G"] = IECore.IntData(10) self.assertNotEqual(i.hash(), h) h = i.hash()
def testPromoteDynamicBoxPlugAndSerialise(self): s = Gaffer.ScriptNode() s["b"] = Gaffer.Box() s["b"]["n"] = Gaffer.Node() s["b"]["n"]["p"] = Gaffer.Box2iPlug(flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic) p = Gaffer.PlugAlgo.promote(s["b"]["n"]["p"]) p.setValue(imath.Box2i(imath.V2i(1, 2), imath.V2i(3, 4))) p.setName("c") self.assertTrue(isinstance(s["b"]["c"], Gaffer.Box2iPlug)) self.assertTrue(s["b"]["n"]["p"].getInput().isSame(s["b"]["c"])) self.assertTrue(s["b"]["n"]["p"]["min"].getInput().isSame( s["b"]["c"]["min"])) self.assertTrue(s["b"]["n"]["p"]["max"].getInput().isSame( s["b"]["c"]["max"])) self.assertEqual(s["b"]["c"].getValue(), imath.Box2i(imath.V2i(1, 2), imath.V2i(3, 4))) s2 = Gaffer.ScriptNode() s2.execute(s.serialise()) self.assertTrue(isinstance(s2["b"]["c"], Gaffer.Box2iPlug)) self.assertTrue(s2["b"]["n"]["p"].getInput().isSame(s2["b"]["c"])) self.assertTrue(s2["b"]["n"]["p"]["min"].getInput().isSame( s2["b"]["c"]["min"])) self.assertTrue(s2["b"]["n"]["p"]["max"].getInput().isSame( s2["b"]["c"]["max"])) self.assertEqual(s2["b"]["c"].getValue(), imath.Box2i(imath.V2i(1, 2), imath.V2i(3, 4)))
def testDefaultValueSerialisation( self ) : s = Gaffer.ScriptNode() s["s"] = Gaffer.Spreadsheet() s["s"]["rows"].addColumn( Gaffer.V3iPlug( "c1", defaultValue = imath.V3i( 1, 2, 3 ) ) ) s["s"]["rows"].addColumn( Gaffer.Box2iPlug( "c2", defaultValue = imath.Box2i( imath.V2i( 0 ), imath.V2i( 1 ) ) ) ) s["s"]["rows"].addRows( 3 ) # Change defaults for some plugs s["s"]["rows"][1]["name"].setValue( "testName" ) s["s"]["rows"][1]["cells"]["c1"]["value"].setValue( imath.V3i( 4, 5, 6 ) ) s["s"]["rows"][2]["enabled"].setValue( False ) s["s"]["rows"][2]["cells"]["c1"]["value"]["x"].setValue( 10 ) s["s"]["rows"][3]["cells"]["c1"]["enabled"].setValue( False ) s["s"]["rows"][3]["cells"]["c2"]["value"].setValue( imath.Box2i( imath.V2i( 10 ), imath.V2i( 11 ) ) ) s["s"]["rows"][1]["name"].resetDefault() # Change values for some plugs, some of which also had their # defaults changed. s["s"]["rows"][1]["name"].setValue( "testName2" ) s["s"]["rows"][1]["cells"]["c1"]["value"]["x"].setValue( 7 ) s["s"]["rows"][3]["enabled"].setValue( False ) # Check that everything round-trips correctly through a serialisation and load. s2 = Gaffer.ScriptNode() s2.execute( s.serialise() ) self.assertEqual( s["s"]["rows"].defaultHash(), s2["s"]["rows"].defaultHash() ) self.assertEqual( s["s"]["rows"].hash(), s2["s"]["rows"].hash() )
def testChannelDataPassThrough(self): # Resize to the same size as the input image. c = GafferImage.Constant() c["format"].setValue( GafferImage.Format(imath.Box2i(imath.V2i(0), imath.V2i(512)), 1)) c["color"].setValue(imath.Color4f(0.25, 0.5, 0.75, 1)) r = GafferImage.Resize() r["in"].setInput(c["out"]) r["format"].setValue( GafferImage.Format(imath.Box2i(imath.V2i(0), imath.V2i(512)), 1)) # Assert that the pixel data is passed clean through, even # if we request a new pixel aspect ratio. for pixelAspect in (0.5, 1, 2): r["format"]["pixelAspect"].setValue(pixelAspect) for channel in ["R", "G", "B", "A"]: self.assertEqual( c["out"].channelDataHash(channel, imath.V2i(0)), r["out"].channelDataHash(channel, imath.V2i(0)), ) self.assertTrue(c["out"].channelData( channel, imath.V2i(0), _copy=False).isSame(r["out"].channelData(channel, imath.V2i(0), _copy=False)))
def editPlugs( self, plugs, scrollTo = True, allowDirectEditing = True, position = None ) : tableView = self._qtWidget() selectionModel = tableView.selectionModel() indexes = [ tableView.model().indexForPlug( plug ) for plug in plugs ] assert( all( [ index.isValid() for index in indexes ] ) ) if not all( [ index.flags() & ( QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsEditable ) for index in indexes ] ) : return if scrollTo : tableView.scrollTo( indexes[ -1 ] ) self.__selectIndexes( indexes ) if position is None : visibleRect = tableView.visualRect( selectionModel.currentIndex() ) rect = QtCore.QRect( tableView.viewport().mapToGlobal( visibleRect.topLeft() ), tableView.viewport().mapToGlobal( visibleRect.bottomRight() ) ) bound = imath.Box2i( imath.V2i( rect.left(), rect.bottom() ), imath.V2i( rect.right(), rect.top() ) ) else : bound = imath.Box2i( position, position ) self.__showEditor( plugs, bound, allowDirectEditing )
def testHeaderToBlindData(self): dictHeader = { 'channelNames': IECore.StringVectorData(["R", "G", "B"]), 'oiio:ColorSpace': IECore.StringData("Linear"), 'compression': IECore.StringData("piz"), 'screenWindowCenter': IECore.V2fData(imath.V2f(0, 0)), 'displayWindow': IECore.Box2iData(imath.Box2i(imath.V2i(0, 0), imath.V2i(511, 255))), 'dataWindow': IECore.Box2iData(imath.Box2i(imath.V2i(0, 0), imath.V2i(511, 255))), 'PixelAspectRatio': IECore.FloatData(1), 'screenWindowWidth': IECore.FloatData(1), 'deep': IECore.BoolData(False), } if IECoreImage.OpenImageIOAlgo.version() >= 20206: dictHeader['oiio:subimages'] = IECore.IntData(1) r = IECore.Reader.create("test/IECoreImage/data/exr/uvMap.512x256.exr") header = r.readHeader() self.assertEqual(header, IECore.CompoundObject(dictHeader)) img = r.read() del dictHeader['channelNames'] del dictHeader['deep'] self.assertEqual(img.blindData(), IECore.CompoundData(dictHeader))
def testTiff(self): for (fileName, rawType) in ( ("test/IECoreImage/data/tiff/uvMap.200x100.rgba.8bit.tif", IECore.UCharVectorData), ("test/IECoreImage/data/tiff/uvMap.200x100.rgba.16bit.tif", IECore.UShortVectorData), ("test/IECoreImage/data/tiff/uvMap.200x100.rgba.32bit.tif", IECore.FloatVectorData), ): r = IECore.Reader.create(fileName) self.assertIsInstance(r, IECoreImage.ImageReader) img = r.read() r["rawChannels"] = IECore.BoolData(True) imgRaw = r.read() self.assertEqual(img.displayWindow, imath.Box2i(imath.V2i(0, 0), imath.V2i(199, 99))) self.assertEqual(img.dataWindow, imath.Box2i(imath.V2i(0, 0), imath.V2i(199, 99))) self.assertTrue(img.channelsValid()) self.assertTrue(imgRaw.channelsValid()) self.assertEqual(img.keys(), imgRaw.keys()) for c in img.keys(): self.assertEqual(type(img[c]), IECore.FloatVectorData) self.assertEqual(type(imgRaw[c]), rawType)
def testReadHeader(self): r = IECoreImage.ImageReader( "test/IECoreImage/data/exr/manyChannels.exr") h = r.readHeader() c = h['channelNames'] self.assertEqual(c.staticTypeId(), IECore.StringVectorData.staticTypeId()) self.assertEqual(len(c), 7) self.assertTrue("R" in c) self.assertTrue("G" in c) self.assertTrue("B" in c) self.assertTrue("A" in c) self.assertTrue("diffuse.red" in c) self.assertTrue("diffuse.green" in c) self.assertTrue("diffuse.blue" in c) self.assertEqual( h['displayWindow'], IECore.Box2iData(imath.Box2i(imath.V2i(0, 0), imath.V2i(255, 255)))) self.assertEqual( h['dataWindow'], IECore.Box2iData(imath.Box2i(imath.V2i(0, 0), imath.V2i(255, 255))))
def testReadImage(self): r = IECoreImage.ImageReader( "test/IECoreImage/data/exr/uvMap.256x256.exr") i = r.read() self.assertEqual(i.typeId(), IECoreImage.ImagePrimitive.staticTypeId()) self.assertEqual(i.dataWindow, imath.Box2i(imath.V2i(0), imath.V2i(255))) self.assertEqual(i.displayWindow, imath.Box2i(imath.V2i(0), imath.V2i(255))) self.assertTrue(i.channelsValid()) self.assertEqual(len(i), 3) for c in ["R", "G", "B"]: self.assertEqual(i[c].typeId(), IECore.FloatVectorData.staticTypeId()) r = i["R"] self.assertEqual(r[0], 0) self.assertEqual(r[-1], 1) g = i["G"] self.assertEqual(g[0], 0) self.assertEqual(g[-1], 1) for b in i["B"]: self.assertEqual(b, 0)
def testCrop(self): inputFile = os.path.join("test", "IECoreImage", "data", "exr", "colorBarsWithDataWindow.exr") tests = [ { "cropBox": imath.Box2i(imath.V2i(855, 170), imath.V2i(1460, 1465)), "checkFile": os.path.join("test", "IECoreImage", "data", "exr", "imageCropDataWindow.exr"), "matchDataWindow": False, "resetOrigin": True }, { "cropBox": imath.Box2i(imath.V2i(855, 170), imath.V2i(1460, 1465)), "checkFile": os.path.join("test", "IECoreImage", "data", "exr", "imageCropDataWindowMatched.exr"), "matchDataWindow": True, "resetOrigin": True }, { "cropBox": self.__fromNukeCrop(1125, 195, 1551, 681), "checkFile": os.path.join("test", "IECoreImage", "data", "exr", "imageCropDataWindow2Matched.exr"), "matchDataWindow": True, "resetOrigin": False }, { "cropBox": self.__fromNukeCrop(1125, 195, 1551, 681), "checkFile": os.path.join("test", "IECoreImage", "data", "exr", "imageCropDataWindow2.exr"), "matchDataWindow": False, "resetOrigin": False }, { "cropBox": imath.Box2i(imath.V2i(-10, -10), imath.V2i(3000, 3000)), "checkFile": inputFile, "matchDataWindow": False, "resetOrigin": False }, ] self.__testCrop(inputFile, tests)
def testOffsetDisplayWindows(self): r = IECore.Reader.create("test/IECoreImage/data/exr/carPark.exr") imageA = r.read() imageB = r.read() op = IECoreImage.ImageDiffOp() res = op(imageA=imageA, imageB=imageB, alignDisplayWindows=False) self.assertFalse(res.value) # Offset the display and data windows. offsetDisplayWindow = imath.Box2i( imageA.displayWindow.min() + imath.V2i(-261, 172), imageA.displayWindow.max() + imath.V2i(-261, 172)) offsetDataWindow = imath.Box2i( imageA.dataWindow.min() + imath.V2i(-261, 172), imageA.dataWindow.max() + imath.V2i(-261, 172)) imageA.displayWindow = offsetDisplayWindow imageA.dataWindow = offsetDataWindow # Compare the images again and they should fail as the display windows are different. op = IECoreImage.ImageDiffOp() res = op(imageA=imageA, imageB=imageB, alignDisplayWindows=False) self.assertTrue(res.value) # Compare the images again and they should not fail if "alignDisplayWindows" is turned on. op = IECoreImage.ImageDiffOp() res = op(imageA=imageA, imageB=imageB, alignDisplayWindows=True) self.assertFalse(res.value)
def testClamp(self): self.assertEqual( GafferImage.BufferAlgo.clamp( imath.V2i(5, 6), imath.Box2i(imath.V2i(0), imath.V2i(10))), imath.V2i(5, 6)) self.assertEqual( GafferImage.BufferAlgo.clamp( imath.V2i(10, 6), imath.Box2i(imath.V2i(0), imath.V2i(10))), imath.V2i(9, 6)) self.assertEqual( GafferImage.BufferAlgo.clamp( imath.V2i(0, 6), imath.Box2i(imath.V2i(0), imath.V2i(10))), imath.V2i(0, 6)) self.assertEqual( GafferImage.BufferAlgo.clamp( imath.V2i(5, -1), imath.Box2i(imath.V2i(0), imath.V2i(10))), imath.V2i(5, 0)) self.assertEqual( GafferImage.BufferAlgo.clamp( imath.V2i(5, 10), imath.Box2i(imath.V2i(0), imath.V2i(10))), imath.V2i(5, 9))
def testSampleOutsideDataWindow(self): constant = GafferImage.Constant() constant["format"].setValue(GafferImage.Format(1000, 1000)) constant["color"].setValue(imath.Color4f(1)) crop = GafferImage.Crop() crop["in"].setInput(constant["out"]) crop["areaSource"].setValue(crop.AreaSource.Area) crop["area"].setValue(imath.Box2i(imath.V2i(135), imath.V2i(214))) crop["affectDisplayWindow"].setValue(False) sampler = GafferImage.Sampler( crop["out"], "R", imath.Box2i(imath.V2i(0), imath.V2i(50)), boundingMode=GafferImage.Sampler.BoundingMode.Clamp) self.assertEqual(sampler.sample(0, 0), 1) sampler = GafferImage.Sampler( crop["out"], "R", imath.Box2i(imath.V2i(0), imath.V2i(50)), boundingMode=GafferImage.Sampler.BoundingMode.Black) self.assertEqual(sampler.sample(0, 0), 0)
def testExpressions(self): s = Gaffer.ScriptNode() s["n1"] = Gaffer.Node() s["n2"] = Gaffer.Node() s["n1"]["user"]["f"] = GafferImage.FormatPlug( flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic) s["n2"]["user"]["f"] = GafferImage.FormatPlug( flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic) s["e"] = Gaffer.Expression() s["e"].setExpression( inspect.cleandoc(""" f = parent["n1"]["user"]["f"] b = f.getDisplayWindow() b.setMin( b.min() - imath.V2i( 10 ) ) b.setMax( b.max() + imath.V2i( 20 ) ) f.setPixelAspect( 0.5 ) f.setDisplayWindow( b ) parent["n2"]["user"]["f"] = f """)) s["n1"]["user"]["f"].setValue( GafferImage.Format( imath.Box2i(imath.V2i(20, 30), imath.V2i(100, 110)), 1)) self.assertEqual( s["n2"]["user"]["f"].getValue(), GafferImage.Format( imath.Box2i(imath.V2i(10, 20), imath.V2i(120, 130)), 0.5))
def testConvenienceConstructors(self): """ Test IECoreImage.ImagePrimitive convenience constructors """ window1Min = imath.V2i(0, 0) window1Max = imath.V2i(15, 15) w1 = imath.Box2i(window1Min, window1Max) window2Min = imath.V2i(4, 4) window2Max = imath.V2i(11, 11) w2 = imath.Box2i(window2Min, window2Max) fill = imath.Color3f(0.49, 0.50, 0.51) i = IECoreImage.ImagePrimitive.createRGBFloat(fill, w1, w2) self.assert_(i.isInstanceOf(IECoreImage.ImagePrimitive.staticTypeId())) self.assert_("R" in i) self.assert_("G" in i) self.assert_("B" in i) self.assert_("Y" not in i) self.assertEqual(i.dataWindow, w1) self.assertEqual(i.displayWindow, w2) self.assert_(i["R"].isInstanceOf( IECore.FloatVectorData.staticTypeId())) self.assert_(i["G"].isInstanceOf( IECore.FloatVectorData.staticTypeId())) self.assert_(i["B"].isInstanceOf( IECore.FloatVectorData.staticTypeId())) self.assertEqual(i["R"].size(), 256) self.assertEqual(i["G"].size(), 256) self.assertEqual(i["B"].size(), 256) for p in (0, 63, 127, 255): self.assertEqual(i["R"][p], fill[0]) self.assertEqual(i["G"][p], fill[1]) self.assertEqual(i["B"][p], fill[2]) fill = 0.5 i = IECoreImage.ImagePrimitive.createGreyscaleFloat(fill, w1, w2) self.assert_(i.isInstanceOf(IECoreImage.ImagePrimitive.staticTypeId())) self.assert_("R" not in i) self.assert_("G" not in i) self.assert_("B" not in i) self.assert_("Y" in i) self.assertEqual(i.dataWindow, w1) self.assertEqual(i.displayWindow, w2) self.assert_(i["Y"].isInstanceOf( IECore.FloatVectorData.staticTypeId())) self.assertEqual(i["Y"].size(), 256) for p in (0, 63, 127, 255): self.assertEqual(i["Y"][p], fill)
def testWriteDataWindowFormatToNonDataWindowFormat(self): # source data window inside display window displayWindow = imath.Box2i(imath.V2i(0, 0), imath.V2i(99, 99)) dataWindow = imath.Box2i(imath.V2i(10, 10), imath.V2i(50, 50)) imgOrig = self.__makeFloatImage(dataWindow, displayWindow) w = IECore.Writer.create( imgOrig, os.path.join("test", "IECoreImage", "data", "jpg", "output.jpg")) self.assertIsInstance(w, IECoreImage.ImageWriter) w.write() self.assertTrue( os.path.exists( os.path.join("test", "IECoreImage", "data", "jpg", "output.jpg"))) r = IECore.Reader.create( os.path.join("test", "IECoreImage", "data", "jpg", "output.jpg")) imgNew = r.read() self.__verifyImageRGB(imgNew, imgOrig, maxError=0.05) # source data window outside display window displayWindow = imath.Box2i(imath.V2i(0, 0), imath.V2i(99, 99)) dataWindow = imath.Box2i(imath.V2i(-10, -10), imath.V2i(99, 99)) imgOrig = self.__makeFloatImage(dataWindow, displayWindow) w = IECore.Writer.create( imgOrig, os.path.join("test", "IECoreImage", "data", "jpg", "output.jpg")) self.assertIsInstance(w, IECoreImage.ImageWriter) w.write() self.assertTrue( os.path.exists( os.path.join("test", "IECoreImage", "data", "jpg", "output.jpg"))) # test if the scan line doesn't overlap the # display window at all. dataWindow = imath.Box2i(imath.V2i(200, 50), imath.V2i(505, 55)) imgOrig2 = self.__makeFloatImage(dataWindow, displayWindow) w = IECore.Writer.create( imgOrig2, os.path.join("test", "IECoreImage", "data", "png", "output.png")) self.assertEqual(type(w), IECoreImage.ImageWriter) w.write() self.assertTrue( os.path.exists( os.path.join("test", "IECoreImage", "data", "png", "output.png")))
def setUp(self): paths = self.__paths() for p in paths.keys(): if os.path.exists(p): os.remove(p) # Set the default format to be something fun. nuke.root()["format"].fromScript( "1144 862 0 0 1144 862 2 CortexTestAlexaProxyAnamorphic(2.66)") # Create a colourful test image that we will distort. n1 = nuke.createNode("ColorWheel") n2 = nuke.createNode("ColorBars") n3 = nuke.createNode("CheckerBoard2") m1 = nuke.createNode("Merge2") m2 = nuke.createNode("Merge2") m1.setInput(0, n1) m1.setInput(1, n2) m2.setInput(0, m1) m2.setInput(1, n3) m2["operation"].setValue(1) # Create a write node so that we can save the image to disk. w = nuke.createNode("Write") w.setInput(0, m2) w["file"].setText(paths['path']) # Crop the image and generate another test image. c = nuke.createNode("Crop") c["box"].setValue((29, -74, 374, 448)) c.setInput(0, m2) w2 = nuke.createNode("Write") w2.setInput(0, c) w2["file"].setText(paths['croppedPath']) # Create the test files. nuke.execute(w, 1, 1) nuke.execute(w2, 1, 1) # Finally, read back the images and offset their display windows to make the # tests even more interesting... offsetImg = IECore.Reader.create(paths['path']).read() offsetDisplayWindow = imath.Box2i( offsetImg.displayWindow.min() + imath.V2i(-261, 172), offsetImg.displayWindow.max() + imath.V2i(-261, 172)) offsetImg.displayWindow = offsetDisplayWindow IECore.Writer.create(offsetImg, paths['offsetPath']).write() croppedOffsetImg = IECore.Reader.create(paths['croppedPath']).read() offsetDisplayWindow = imath.Box2i( croppedOffsetImg.displayWindow.min() + imath.V2i(120, -100), croppedOffsetImg.displayWindow.max() + imath.V2i(120, -100)) croppedOffsetImg.displayWindow = offsetDisplayWindow IECore.Writer.create(croppedOffsetImg, paths['croppedOffsetPath']).write()
def testNonZeroDataWindowOrigin( self ) : r = IECoreImage.ImageReader( "test/IECoreImage/data/exr/uvMapWithDataWindow.100x100.exr" ) i = r.read() self.assertEqual( i.dataWindow, imath.Box2i( imath.V2i( 25 ), imath.V2i( 49 ) ) ) self.assertEqual( i.displayWindow, imath.Box2i( imath.V2i( 0 ), imath.V2i( 99 ) ) ) self.assertTrue( i.channelsValid() )
def testRotateEmptyDataWindow( self ) : r = GafferImage.ImageReader() self.assertEqual( r["out"]["dataWindow"].getValue(), imath.Box2i() ) t = GafferImage.ImageTransform() t["in"].setInput( r["out"] ) t["transform"]["rotate"].setValue( 1 ) self.assertEqual( t["out"]["dataWindow"].getValue(), imath.Box2i() )
def testROIHash(self): r = GafferImage.ImageReader() r["fileName"].setValue(self.__file300PxPath) s = GafferImage.ImageStats() s["in"].setInput(r["out"]) s["channels"].setValue(IECore.StringVectorData(["R", "G", "B", "A"])) allHashes = [] stats = [] for a in [ imath.Box2i(imath.V2i(0, 0), imath.V2i(300, 300)), imath.Box2i(imath.V2i(3, 5), imath.V2i(300, 300)) ]: s["area"].setValue(a) hashes = {} for x in range(0, 300, 64): for y in range(0, 300, 64): c = Gaffer.Context() c["image:channelName"] = "R" c["image:tileOrigin"] = imath.V2i(x, y) with c: hashes[(x, y)] = s["__tileStats"].hash() allHashes.append(hashes) stats.append([ s["min"].getValue(), s["max"].getValue(), s["average"].getValue() ]) self.__assertColour(stats[0][0], imath.Color4f(0, 0, 0, 0)) self.__assertColour(stats[0][1], imath.Color4f(0.8027, 1, 1, 0)) self.__assertColour(stats[0][2], imath.Color4f(0.0031, 0.0499, 0.1956, 0)) self.__assertColour(stats[1][0], imath.Color4f(0, 0, 0, 0)) self.__assertColour(stats[1][1], imath.Color4f(0.8027, 1, 1, 0)) self.__assertColour(stats[1][2], imath.Color4f(0.0031, 0.0503, 0.1973, 0)) numDiff = 0 numSame = 0 for k, v in allHashes[0].items(): if v == allHashes[1][k]: numSame += 1 else: numDiff += 1 # Check that interior hashes stay the same self.assertEqual(numSame, 16) # Check that border hashes change self.assertEqual(numDiff, 9)
def testDefaultFormatForImage( self ) : constant = GafferImage.Constant() with Gaffer.Context() as c : GafferImage.FormatPlug.setDefaultFormat( c, GafferImage.Format( 100, 200 ) ) self.assertEqual( constant["out"].image().displayWindow, imath.Box2i( imath.V2i( 0 ), imath.V2i( 99, 199 ) ) ) GafferImage.FormatPlug.setDefaultFormat( c, GafferImage.Format( 200, 300 ) ) self.assertEqual( constant["out"].image().displayWindow, imath.Box2i( imath.V2i( 0 ), imath.V2i( 199, 299 ) ) )
def testConstruction(self): idd = IECoreImage.ImageDisplayDriver( imath.Box2i(imath.V2i(0, 0), imath.V2i(100, 100)), imath.Box2i(imath.V2i(10, 10), imath.V2i(40, 40)), ['r', 'g', 'b'], IECore.CompoundData()) self.assertEqual(idd.scanLineOrderOnly(), False) self.assertEqual(idd.displayWindow(), imath.Box2i(imath.V2i(0, 0), imath.V2i(100, 100))) self.assertEqual(idd.dataWindow(), imath.Box2i(imath.V2i(10, 10), imath.V2i(40, 40))) self.assertEqual(idd.channelNames(), ['r', 'g', 'b'])
def emptyImage( self ) : emptyCrop = GafferImage.Crop( "Crop" ) emptyCrop["Constant"] = GafferImage.Constant() emptyCrop["Constant"]["format"].setValue( GafferImage.Format( 100, 100, 1.000 ) ) emptyCrop["in"].setInput( emptyCrop["Constant"]["out"] ) emptyCrop["area"].setValue( imath.Box2i() ) emptyCrop["affectDisplayWindow"].setValue( False ) self.assertEqual( emptyCrop["out"]["dataWindow"].getValue(), imath.Box2i() ) return emptyCrop