def testHashPassThrough(self): n = GafferImage.ImageReader() n["fileName"].setValue(self.imageFile) o = GafferImage.CDL() o["in"].setInput(n["out"]) self.assertEqual(n["out"].image(), o["out"].image()) o['slope'].setValue(imath.Color3f(1, 2, 3)) self.assertNotEqual(n["out"].image(), o["out"].image()) o["enabled"].setValue(False) self.assertEqual(n["out"].image(), o["out"].image()) self.assertEqual(n["out"]['format'].hash(), o["out"]['format'].hash()) self.assertEqual(n["out"]['dataWindow'].hash(), o["out"]['dataWindow'].hash()) self.assertEqual(n["out"]["metadata"].getValue(), o["out"]["metadata"].getValue()) self.assertEqual(n["out"]['channelNames'].hash(), o["out"]['channelNames'].hash()) o["enabled"].setValue(True) o['slope'].setValue(o['slope'].defaultValue()) self.assertEqual(n["out"].image(), o["out"].image()) self.assertEqual(n["out"]['format'].hash(), o["out"]['format'].hash()) self.assertEqual(n["out"]['dataWindow'].hash(), o["out"]['dataWindow'].hash()) self.assertEqual(n["out"]["metadata"].getValue(), o["out"]["metadata"].getValue()) self.assertEqual(n["out"]['channelNames'].hash(), o["out"]['channelNames'].hash())
def testMultipleLayers(self): main = GafferImage.Constant() main["color"].setValue(imath.Color4f(1, 0.5, 0.25, 1)) diffuse = GafferImage.Constant() diffuse["color"].setValue(imath.Color4f(0.25, 0.5, 0.75, 1)) diffuse["layer"].setValue("diffuse") m = GafferImage.CopyChannels() m["in"][0].setInput(main["out"]) m["in"][1].setInput(diffuse["out"]) m["channels"].setValue("*") cdl = GafferImage.CDL() cdl["in"].setInput(m["out"]) self.assertImagesEqual(cdl["out"], m["out"]) mainCDLSampler = GafferImage.ImageSampler() mainCDLSampler["image"].setInput(cdl["out"]) mainCDLSampler["pixel"].setValue(imath.V2f(0.5)) mainCDLSampler["channels"].setValue( IECore.StringVectorData(["R", "G", "B", "A"])) diffuseCDLSampler = GafferImage.ImageSampler() diffuseCDLSampler["image"].setInput(cdl["out"]) diffuseCDLSampler["pixel"].setValue(imath.V2f(0.5)) diffuseCDLSampler["channels"].setValue( IECore.StringVectorData(["diffuse." + x for x in "RGBA"])) self.assertEqual(mainCDLSampler["color"].getValue(), main["color"].getValue()) self.assertEqual(diffuseCDLSampler["color"].getValue(), diffuse["color"].getValue()) cdl["saturation"].setValue(0.5) self.assertNotEqual(mainCDLSampler["color"].getValue(), main["color"].getValue()) self.assertEqual(diffuseCDLSampler["color"].getValue(), diffuse["color"].getValue()) cdl["channels"].setValue("*[RGB]") self.assertNotEqual(mainCDLSampler["color"].getValue(), main["color"].getValue()) self.assertNotEqual(diffuseCDLSampler["color"].getValue(), diffuse["color"].getValue()) self.assertNotEqual(mainCDLSampler["color"].hash(), diffuseCDLSampler["color"].hash()) self.assertNotEqual(mainCDLSampler["color"].getValue(), diffuseCDLSampler["color"].getValue()) cdl["channels"].setValue("diffuse.[RGB]") self.assertEqual(mainCDLSampler["color"].getValue(), main["color"].getValue()) self.assertNotEqual(diffuseCDLSampler["color"].getValue(), diffuse["color"].getValue())
def testPassThrough(self): i = GafferImage.ImageReader() i["fileName"].setValue(self.imageFile) o = GafferImage.CDL() o["in"].setInput(i["out"]) o['slope'].setValue(imath.Color3f(1, 2, 3)) self.assertEqual(i["out"]["format"].hash(), o["out"]["format"].hash()) self.assertEqual(i["out"]["dataWindow"].hash(), o["out"]["dataWindow"].hash()) self.assertEqual(i["out"]["metadata"].getValue(), o["out"]["metadata"].getValue()) self.assertEqual(i["out"]["channelNames"].hash(), o["out"]["channelNames"].hash()) self.assertEqual(i["out"]["format"].getValue(), o["out"]["format"].getValue()) self.assertEqual(i["out"]["dataWindow"].getValue(), o["out"]["dataWindow"].getValue()) self.assertEqual(i["out"]["metadata"].getValue(), o["out"]["metadata"].getValue()) self.assertEqual(i["out"]["channelNames"].getValue(), o["out"]["channelNames"].getValue())
def testImageHashPassThrough(self): i = GafferImage.ImageReader() i["fileName"].setValue(self.imageFile) o = GafferImage.CDL() o["in"].setInput(i["out"]) self.assertEqual(i["out"].imageHash(), o["out"].imageHash()) o['slope'].setValue(imath.Color3f(1, 2, 3)) self.assertNotEqual(i["out"].imageHash(), o["out"].imageHash())
def testChannelsAreSeparate(self): i = GafferImage.ImageReader() i["fileName"].setValue( os.path.expandvars( "$GAFFER_ROOT/python/GafferImageTest/images/circles.exr")) o = GafferImage.CDL() o["in"].setInput(i["out"]) o['slope'].setValue(imath.Color3f(1, 2, 3)) self.assertNotEqual(o["out"].channelDataHash("R", imath.V2i(0)), o["out"].channelDataHash("G", imath.V2i(0))) self.assertNotEqual(o["out"].channelData("R", imath.V2i(0)), o["out"].channelData("G", imath.V2i(0)))
def test(self): n = GafferImage.ImageReader() n["fileName"].setValue(self.imageFile) orig = n["out"].image() o = GafferImage.CDL() o["in"].setInput(n["out"]) self.assertEqual(n["out"].image(), o["out"].image()) o['slope'].setValue(imath.Color3f(1, 2, 3)) slope = o["out"].image() self.assertNotEqual(orig, slope) o["offset"].setValue(imath.Color3f(1, 2, 3)) offset = o["out"].image() self.assertNotEqual(orig, offset) self.assertNotEqual(slope, offset) o["power"].setValue(imath.Color3f(1, 2, 3)) power = o["out"].image() self.assertNotEqual(orig, power) self.assertNotEqual(slope, power) self.assertNotEqual(offset, power) o["saturation"].setValue(0.5) saturation = o["out"].image() self.assertNotEqual(orig, saturation) self.assertNotEqual(slope, saturation) self.assertNotEqual(offset, saturation) self.assertNotEqual(power, saturation) o["direction"].setValue(2) # inverse inverse = o["out"].image() self.assertNotEqual(orig, inverse) self.assertNotEqual(slope, inverse) self.assertNotEqual(offset, inverse) self.assertNotEqual(power, inverse) self.assertNotEqual(saturation, inverse)
def __init__(self, name="ColoriseSHO"): GafferImage.ImageProcessor.__init__(self, name) self["show"] = Gaffer.IntPlug(defaultValue=0, minValue=0, maxValue=3) # Channel colorising merge = GafferImage.Merge() self["__Merge"] = merge merge["operation"].setValue(0) outputSwitch = Gaffer.Switch() self["__Switch_output"] = outputSwitch outputSwitch.setup(self["out"]) outputSwitch["index"].setInput(self["show"]) outputSwitch["in"][0].setInput(merge["out"]) for channel in GafferAstro.NarrowbandChannels: self["source%s" % channel] = Gaffer.StringPlug( defaultValue='%s.input' % channel) self["range%s" % channel] = Gaffer.V2fPlug(defaultValue=imath.V2f(0, 1)) self["map%s" % channel] = Gaffer.SplinefColor4fPlug( defaultValue=self.__mapDefaults[channel]) self["saturation%s" % channel] = Gaffer.FloatPlug(defaultValue=1.0, minValue=0.0) self["multiply%s" % channel] = Gaffer.FloatPlug(defaultValue=1.0) self["gamma%s" % channel] = Gaffer.FloatPlug(defaultValue=1.0) colorise = GafferAstro.Colorise() self["__Colorise_%s" % channel] = colorise colorise["in"].setInput(self["in"]) colorise["channel"].setInput(self["source%s" % channel]) colorise["mapEnabled"].setValue(True) colorise["range"].setInput(self["range%s" % channel]) colorise["enabled"].setInput(colorise["channel"]) # Work around issue where setInput doesn't sync the number of knots colorise["map"].setValue(self["map%s" % channel].getValue()) colorise["map"].setInput(self["map%s" % channel]) cdl = GafferImage.CDL() self["__CDL_%s" % channel] = cdl cdl["in"].setInput(colorise["out"]) cdl["saturation"].setInput(self["saturation%s" % channel]) grade = GafferImage.Grade() self["__Grade_%s" % channel] = grade grade["in"].setInput(cdl["out"]) grade["multiply"].gang() grade["multiply"]["r"].setInput(self["multiply%s" % channel]) grade["gamma"].gang() grade["gamma"]["r"].setInput(self["gamma%s" % channel]) merge["in"][len(merge["in"]) - 1].setInput(grade["out"]) outputSwitch["in"][len(outputSwitch["in"]) - 1].setInput( grade["out"]) self["saturation"] = Gaffer.FloatPlug(defaultValue=1.0, minValue=0.0) self["blackPoint"] = Gaffer.FloatPlug(defaultValue=0.0) self["whitePoint"] = Gaffer.FloatPlug(defaultValue=1.0) self["multiply"] = Gaffer.Color4fPlug( defaultValue=imath.Color4f(1, 1, 1, 1)) self["gamma"] = Gaffer.FloatPlug(defaultValue=1.0, minValue=0.0) outputCdl = GafferImage.CDL() self["__CDL_output"] = outputCdl outputCdl["in"].setInput(outputSwitch["out"]) outputCdl["saturation"].setInput(self["saturation"]) outputGrade = GafferImage.Grade() self["__Grade_output"] = outputGrade outputGrade["in"].setInput(outputCdl["out"]) outputGrade["blackPoint"].gang() outputGrade["blackPoint"]["r"].setInput(self["blackPoint"]) outputGrade["whitePoint"].gang() outputGrade["whitePoint"]["r"].setInput(self["whitePoint"]) outputGrade["multiply"].setInput(self["multiply"]) outputGrade["gamma"].gang() outputGrade["gamma"]["r"].setInput(self["gamma"]) copyChannels = GafferImage.CopyChannels() self["__CopyChannels"] = copyChannels copyChannels["in"][0].setInput(self["in"]) copyChannels["in"][1].setInput(outputGrade["out"]) copyChannels["channels"].setValue("*") self["out"].setInput(copyChannels["out"])