Calling GEGL ops is a bit verbose but you can hide a lot of the complexity in a single function. And in Python, keyword arguments can be retrieved as a dictionary in the callee, so can be iterated. So, a first shot:
# Sample function to apply a GEGL operation on one drawable
def applyGeglOnBuffers(bufferIn,bufferOut,opName,**kwargs):
graph=Gegl.Node()
source=graph.create_child("gegl:buffer-source")
source.set_property('buffer',bufferIn)
sink=graph.create_child("gegl:write-buffer")
sink.set_property('buffer',bufferOut)
operation=graph.create_child(opName)
# Iterate named arguments, converting names_with_underscores to names-with-dashes
for name,value in kwargs.items():
operation.set_property(name.replace('_','-'),value)
source.link(operation)
operation.link(sink)
sink.process()
bufferOut.flush()
Used like this in the code:
sizeX=config.get_property('sizeX')
sizeY=config.get_property('sizeY')
Gegl.init()
layer=drawables[0]
selected,x,y,w,h=layer.mask_intersect()
if selected:
# kwarg names should match the GEGL properties (_/- conversion done in the function)
applyGeglOnBuffers(layer.get_buffer(),layer.get_shadow_buffer(),'gegl:gaussian-blur',std_dev_x=sizeX,std_dev_y=sizeY)
layer.merge_shadow(True)
layer.update(x,y,w,h)
Yes, thanks for that. Just used your suggestion to resurrect edge detection using gegl:edge and it worked beautifully. I realised that since we are are using kwargs it was possible to set default arguments for the parameters which for some operations would reduce the verbosity even more eg here it was just “border_behaviour” which defaults to “Clamp”.