Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GEGL kaleidoscope
#8
(Yesterday, 01:28 PM)trandoductin Wrote: Thanks to Kevin and teapot I was able to fulfill a request for client now just waiting to hear back from them.
Maybe Windows 10 VM understood the ctypes.util, on mine it was complaining that there is not util attribute in ctypes and I asked chatGPT and chatGPT gave me that from ctypes.util import find_library code which works
Not sure why it would blow up on me i mean it's the same thing (to me).
Ah I noticed you attached a file rich and looked at it and for windows it's also doing the from ctypes.util import find_library so that would work (strange how that is to me).

There is a problem with the version I put in post #4, I only have Linux so didn't realise.  I think changing just the import statement should fix it. If any Windows users could try the one below and say if it works that would be helpful. Thanks.

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# print 'gegl_command.py: __name__', __name__

import sys
import ctypes.util
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()
Reply


Messages In This Thread
GEGL kaleidoscope - by trandoductin - Yesterday, 01:24 AM
RE: GEGL kaleidoscope - by teapot - Yesterday, 04:19 AM
RE: GEGL kaleidoscope - by trandoductin - Yesterday, 07:36 AM
RE: GEGL kaleidoscope - by teapot - Yesterday, 09:29 AM
RE: GEGL kaleidoscope - by trandoductin - Yesterday, 12:19 PM
RE: GEGL kaleidoscope - by rich2005 - Yesterday, 12:49 PM
RE: GEGL kaleidoscope - by trandoductin - Yesterday, 01:28 PM
RE: GEGL kaleidoscope - by teapot - 6 hours ago

Forum Jump: