Gimp-Forum.net
Porting C plugin (xsane) to GIMP 3 - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions)
+---- Thread: Porting C plugin (xsane) to GIMP 3 (/Thread-Porting-C-plugin-xsane-to-GIMP-3)



Porting C plugin (xsane) to GIMP 3 - skelband - 05-28-2025

Hi,
I am engaged in porting the xsane GIMP plugin code to the new GIMP 3 API. So far it has been a bit of a struggle since the doc is still pretty sparse. So I am looking for some hints.

xsane doesn't have a very complex relationship with GIMP, so I don't believe that there is much left to do. However, I do have some specific questions that I hope I can get some help with.

What I have so far is the infrastructure and new boilerplate to register the menu items. All of that works fine. 

Now I am looking at image creation.

I have the following sequence to get a new image with an attached layer:

gimp_image_new()
gimp_layer_new()
gimp_image_insert_layer()

Now, in order to get a buffer onto which to draw the scanned image, the GIMP 2 code used:

buffer = gimp_drawable_get_buffer(layer_ID);

However, this function does not take a layer in GIMP 3. It takes a GimpDrawable. What do I need to do to draw to a layer or is there a different method not recommended? There doesn't seem to be a function to get a drawable from a layer.

Cheers, and thanks in advance.
skelband


RE: Porting C plugin (xsane) to GIMP 3 - Ofnuts - 05-28-2025

(05-28-2025, 05:27 AM)skelband Wrote: Hi,
I am engaged in porting the xsane GIMP plugin code to the new GIMP 3 API. So far it has been a bit of a struggle since the doc is still pretty sparse. So I am looking for some hints.

xsane doesn't have a very complex relationship with GIMP, so I don't believe that there is much left to do. However, I do have some specific questions that I hope I can get some help with.

What I have so far is the infrastructure and new boilerplate to register the menu items. All of that works fine. 

Now I am looking at image creation.

I have the following sequence to get a new image with an attached layer:

gimp_image_new()
gimp_layer_new()
gimp_image_insert_layer()

Now, in order to get a buffer onto which to draw the scanned image, the GIMP 2 code used:

buffer = gimp_drawable_get_buffer(layer_ID);

However, this function does not take a layer in GIMP 3. It takes a GimpDrawable. What do I need to do to draw to a layer or is there a different method not recommended? There doesn't seem to be a function to get a drawable from a layer.

Cheers, and thanks in advance.
skelband

A layer is a "drawable" (*) so you can always use the layer object directly where Gimp wants a drawable.

(*) A drawable is either a layer, a layer mask or a channel (including the selection). GroupLayers are also drawables even though you can't draw on them  Big Grin


RE: Porting C plugin (xsane) to GIMP 3 - skelband - 05-28-2025

Hi,
OK, I figured it out thanks. Yes you are right. Since layer is derived from a drawable, I can "cast" it to the right type with GIMP_DRAWABLE(layer). It all works now actually with some other little tweaks to the code. Wasn't as big a task as I anticipated.