(Yesterday, 07:36 AM)trandoductin Wrote: Thanks teapot.
Do you have an example of how you call gegl command?
Tricky, there are several versions floating around. I believe the original was by paynekj, Kevin Payne. I use the one below but I cannot remember where I got it.
In my plugin I import it:
import gegl_command
and call it:
gegl_command.gegl_command(image, layer, gegl_string)
You can call it via the pdb but that's much slower:
pdb.python_gegl(image, new_layer, gegl_string)
EDIT: Do not use this version, see post #8.
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
print 'gegl_command.py: __name__', __name__
import sys
import ctypes
import gimpfu
def load_library(lib):
pl = sys.platform
if pl == 'linux' or pl == 'linux2':
return ctypes.CDLL(lib + '.so.0')
if pl == 'win32':
return ctypes.CDLL(ctypes.util.find_library(lib + '-0'))
raise BaseException('TODO:' + pl)
gimp = load_library('libgimp-2.0')
gegl = load_library('libgegl-0.4')
gegl.gegl_init(None, None)
print 'gegl_command.py: gegl done'
def gegl_command(image, drawable, gegl_graph_string):
overlap, x, y, w, h = gimpfu.pdb.gimp_drawable_mask_intersect(drawable)
if not overlap:
return
class GeglBuffer(ctypes.Structure):
pass
GeglBufferPtr = ctypes.POINTER(GeglBuffer)
gimp.gimp_drawable_get_shadow_buffer.restype = GeglBufferPtr
gimp.gimp_drawable_get_buffer.restype = GeglBufferPtr
gegl.gegl_render_op.restype = None
drawable_id = drawable.ID
source = gimp.gimp_drawable_get_buffer(drawable_id)
target = gimp.gimp_drawable_get_shadow_buffer(drawable_id)
gegl.gegl_render_op(source, target, 'gegl:gegl',
'string', ctypes.c_char_p(gegl_graph_string),
ctypes.c_void_p()
)
print 'source=', source, 'target=', target
gegl.gegl_buffer_flush.restype = None
gimp.gimp_drawable_merge_shadow.restype = ctypes.c_bool
gimp.gimp_drawable_update.restype = ctypes.c_bool
gegl.gegl_buffer_flush(target)
okay = gimp.gimp_drawable_merge_shadow(drawable_id, PushUndo=True)
print 'merge okay=', okay
okay = gimp.gimp_drawable_update(drawable_id, x, y, w, h)
print 'update okay=', okay
# gimp_displays_flush takes approximately 1/6th second.
# gimp.gimp_displays_flush()
def init():
print 'gegl_command.py: registering python_gegl'
gimpfu.register(
'python_gegl', # name
'Gegl Command', # blurb
'Gegl Command . . .', # help
'paynekj', # author
'paynekj', # copyright
'2021', # date
'Gegl Command', # menu name
'RGB,RGBA', # image types
[
(gimpfu.PF_IMAGE, 'image', 'Input image', None),
(gimpfu.PF_DRAWABLE, 'drawable', 'Input drawable', None),
(gimpfu.PF_TEXT, 'gegl_graph_string', 'Graph', ''),
],
[],
gegl_command,
menu='<Image>/Python-Fu' # menu path
)
if __name__ == '__main__':
init()
gimpfu.main()