Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
plug in bump map: Works manually, but not using a Python procedure
#4
OK, I've tried my best given my current knowledge (actually lack of knowledge when it comes to pygtk, gtk C...) to replicate the procedure provided by Kevin:
- Updated the "load_library" function to include macOS
- Added a reference to the bump_layer in the main function.
- Reviewed the required parameters from the bump_map function based on the description at the GEGL project.

My understanding is that the bump_layer has to be passed as a GeglBuffer to be used in the GeglOperation: Could someone help me doing this part? The examples I was working on only had an "input" and an "output", while here, there is an "auxiliary" (bump_layer) as well.
The function where I'm stuck is:
Code:
def linettridge_gegl_graph(image, drawable, bump_layer, gegl_graph_string):
   class GeglBuffer(Structure):
       pass
   drawable_id = drawable.ID
   bump_layer_id = bump_layer.ID
   #
   gegl = load_library ('libgegl-0.4')
   sucess = gegl.gegl_init (None, None, None) # related to GeglBuffer: input, aux, output?
   #
   gimp.gimp_drawable_get_shadow_buffer.restype = POINTER (GeglBuffer)
   gimp.gimp_drawable_get_buffer.restype        = POINTER (GeglBuffer)
   #
   x = c_int (); y = c_int (); w = c_int (); h = c_int ()
   non_empty,x,y,w,h = pdb.gimp_drawable_mask_intersect (drawable)
   args = [b"string", c_char_p (gegl_graph_string), c_void_p ()]
   #
   if non_empty:
       source = gimp.gimp_drawable_get_buffer (drawable_id)
       auxiliary = gimp.gimp_drawable_get_buffer (bump_layer_id)
       target = gimp.gimp_drawable_get_shadow_buffer (drawable_id)
       sucess = gegl.gegl_render_op (source, auxiliary, target, "gegl:gegl", *args)
       gegl.gegl_buffer_flush (target)
       gimp.gimp_drawable_merge_shadow (drawable_id, PushUndo = True)
       gimp.gimp_drawable_update (drawable_id, x, y, w, h)
       gimp.gimp_displays_flush ()

Thanks in advance for any advice.
------------

The full code is here (NB: from the time being, I'm running it from the Python console directly)
Code:
########
g = gimp.pdb
# access to list of opened images
images = gimp.image_list()
# identify image opened last
img = images[0]
# get layers
layers = images[0].layers
#
target_layer = layers[0]
print target_layer
bump_layer = layers[1]
print bump_layer
#
########
from gimpfu import *
import pygtk
import gtk
from sys import argv, platform
from ctypes import *
#
def load_library(library_name):
   if platform == "linux" or platform == "linux2":
       library_name = library_name + '.so.0'
   elif platform == "win32":
       from ctypes.util import find_library
       library_name = find_library(library_name + "-0")
   elif platform == "darwin":
       from ctypes.util import find_library
       library_name = find_library(library_name + ".0.dylib")
   else:
       raise BaseException("TODO")
   return CDLL(library_name)

gimp = load_library('libgimp-2.0')

def linettridge_gegl_graph(image, drawable, bump_layer, gegl_graph_string):
   class GeglBuffer(Structure):
       pass
   drawable_id = drawable.ID
   bump_layer_id = bump_layer.ID
   #
   gegl = load_library ('libgegl-0.4')
   sucess = gegl.gegl_init (None, None, None) # related to GeglBuffer: input, aux, output?
   #
   gimp.gimp_drawable_get_shadow_buffer.restype = POINTER (GeglBuffer)
   gimp.gimp_drawable_get_buffer.restype        = POINTER (GeglBuffer)
   #
   x = c_int (); y = c_int (); w = c_int (); h = c_int ()
   non_empty,x,y,w,h = pdb.gimp_drawable_mask_intersect (drawable)
   args = [b"string", c_char_p (gegl_graph_string), c_void_p ()]
   #
   if non_empty:
       source = gimp.gimp_drawable_get_buffer (drawable_id)
       auxiliary = gimp.gimp_drawable_get_buffer (bump_layer_id)
       target = gimp.gimp_drawable_get_shadow_buffer (drawable_id)
       sucess = gegl.gegl_render_op (source, auxiliary, target, "gegl:gegl", *args)
       gegl.gegl_buffer_flush (target)
       gimp.gimp_drawable_merge_shadow (drawable_id, PushUndo = True)
       gimp.gimp_drawable_update (drawable_id, x, y, w, h)
       gimp.gimp_displays_flush ()

########@
#define the parameters of the GEGL function: cf. GEGL_PROPERTIES
type="linear"
compensate=TRUE
invert=FALSE
tiled=FALSE
azimuth=135.0
elevation=22.0
depth=23
offset_x=0
offset_y=0
waterlevel=0.0
ambient=0.0
gegl_graph_string="gegl:bump_map type=%s compensate=%d invert=%d tiled=%d azimuth=%f elevation=%f depth=%d offset_x=%d offset_y=%d waterlevel=%f ambient=%f" % (type, compensate, invert, tiled, azimuth, elevation, depth, offset_x, offset_y, waterlevel, ambient)
linettridge_gegl_graph(img, target_layer, bump_layer, gegl_graph_string)
Reply


Messages In This Thread
RE: plug in bump map: Works manually, but not using a Python procedure - by LinettRidge - 09-07-2020, 04:50 PM

Forum Jump: