app, libgimp, libgimpconfig, extensions: image procedures now with…

… drawable array instead of a single drawable.

Instead of expecting a single drawable, GimpImageProcedure's run()
function will now have an array of drawable as parameter.
As a consequence, all existing plug-ins are broken again. I am going to
fix them in the next commit so that this change can be easily reviewed
and examined if needed later.

I only fix the Vala demo plug-in now (or rather, I just use the first
layer in the array for now) because otherwise the build fails.
This commit is contained in:
Jehan 2021-04-02 01:04:07 +02:00
parent dc7853233b
commit 353c73457a
5 changed files with 76 additions and 28 deletions

View file

@ -26,6 +26,7 @@
#include "core/gimp.h" #include "core/gimp.h"
#include "core/gimpimage.h" #include "core/gimpimage.h"
#include "core/gimpdrawable.h"
#include "core/gimpparamspecs.h" #include "core/gimpparamspecs.h"
#include "core/gimpprogress.h" #include "core/gimpprogress.h"
@ -243,27 +244,61 @@ procedure_commands_get_display_args (GimpProcedure *procedure,
if (image) if (image)
{ {
GList *drawables_list = gimp_image_get_selected_drawables (image);
g_value_set_object (gimp_value_array_index (args, n_args), image); g_value_set_object (gimp_value_array_index (args, n_args), image);
n_args++; n_args++;
if (gimp_value_array_length (args) > n_args && if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_DRAWABLE (procedure->args[n_args])) GIMP_IS_PARAM_SPEC_DRAWABLE (procedure->args[n_args]))
{ {
GimpDrawable *drawable = gimp_image_get_active_drawable (image); if (drawables_list)
if (drawable)
{ {
g_warning ("%s: plug-in procedures expecting a single drawable are deprecated!",
G_STRFUNC);
g_value_set_object (gimp_value_array_index (args, n_args), g_value_set_object (gimp_value_array_index (args, n_args),
drawable); drawables_list->data);
n_args++; n_args++;
} }
else else
{ {
g_warning ("Uh-oh, no active drawable for the plug-in!"); g_warning ("Uh-oh, no active drawable for the plug-in!");
gimp_value_array_unref (args); gimp_value_array_unref (args);
g_list_free (drawables_list);
return NULL; return NULL;
} }
} }
else if (gimp_value_array_length (args) > n_args + 1 &&
G_IS_PARAM_SPEC_INT (procedure->args[n_args]) &&
GIMP_IS_PARAM_SPEC_OBJECT_ARRAY (procedure->args[n_args + 1]))
{
GimpDrawable **drawables = NULL;
gint n_drawables;
n_drawables = g_list_length (drawables_list);
g_value_set_int (gimp_value_array_index (args, n_args++),
n_drawables);
if (drawables_list)
{
GList *iter;
gint i;
drawables = g_new (GimpDrawable *, n_drawables);
for (iter = drawables_list, i = 0; iter; iter = iter->next, i++)
drawables[i] = iter->data;
}
gimp_value_set_object_array (gimp_value_array_index (args, n_args++),
GIMP_TYPE_DRAWABLE,
(GObject **) drawables, n_drawables);
g_free (drawables);
}
g_list_free (drawables_list);
} }
} }

View file

@ -55,8 +55,10 @@ public class Goat : Gimp.PlugIn {
public Gimp.ValueArray run(Gimp.Procedure procedure, public Gimp.ValueArray run(Gimp.Procedure procedure,
Gimp.RunMode run_mode, Gimp.RunMode run_mode,
Gimp.Image image, Gimp.Image image,
Gimp.Drawable drawable, Gimp.Drawable[] drawables,
Gimp.ValueArray args) { Gimp.ValueArray args) {
var drawable = drawables[0];
if (run_mode == Gimp.RunMode.INTERACTIVE) { if (run_mode == Gimp.RunMode.INTERACTIVE) {
GimpUi.init(PLUG_IN_BINARY); GimpUi.init(PLUG_IN_BINARY);

View file

@ -90,11 +90,17 @@ gimp_image_procedure_constructed (GObject *object)
FALSE, FALSE,
G_PARAM_READWRITE); G_PARAM_READWRITE);
GIMP_PROC_ARG_DRAWABLE (procedure, "drawable", GIMP_PROC_ARG_INT (procedure, "num-drawables",
"Drawable", "Number of drawables",
"The input drawable", "Number of input drawables",
TRUE, 0, G_MAXINT, 1,
G_PARAM_READWRITE); G_PARAM_READWRITE);
GIMP_PROC_ARG_OBJECT_ARRAY (procedure, "drawables",
"Drawables",
"The input drawables",
GIMP_TYPE_DRAWABLE,
G_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE);
} }
static void static void
@ -119,12 +125,14 @@ gimp_image_procedure_run (GimpProcedure *procedure,
GimpValueArray *return_values; GimpValueArray *return_values;
GimpRunMode run_mode; GimpRunMode run_mode;
GimpImage *image; GimpImage *image;
GimpDrawable *drawable; GimpDrawable **drawables;
gint n_drawables;
gint i; gint i;
run_mode = GIMP_VALUES_GET_ENUM (args, 0); run_mode = GIMP_VALUES_GET_ENUM (args, 0);
image = GIMP_VALUES_GET_IMAGE (args, 1); image = GIMP_VALUES_GET_IMAGE (args, 1);
drawable = GIMP_VALUES_GET_DRAWABLE (args, 2); n_drawables = GIMP_VALUES_GET_INT (args, 2);
drawables = GIMP_VALUES_GET_OBJECT_ARRAY (args, 3);
remaining = gimp_value_array_new (gimp_value_array_length (args) - ARG_OFFSET); remaining = gimp_value_array_new (gimp_value_array_length (args) - ARG_OFFSET);
@ -137,7 +145,7 @@ gimp_image_procedure_run (GimpProcedure *procedure,
return_values = image_proc->priv->run_func (procedure, return_values = image_proc->priv->run_func (procedure,
run_mode, run_mode,
image, drawable, image, n_drawables, drawables,
remaining, remaining,
image_proc->priv->run_data); image_proc->priv->run_data);

View file

@ -31,11 +31,12 @@ G_BEGIN_DECLS
/** /**
* GimpRunImageFunc: * GimpRunImageFunc:
* @procedure: the #GimpProcedure that runs. * @procedure: the #GimpProcedure that runs.
* @run_mode: the #GimpRunMode. * @run_mode: the #GimpRunMode.
* @image: the #GimpImage. * @image: the #GimpImage.
* @drawable: the #GimpDrawable. * @n_drawables: the number of #GimpDrawable-s.
* @args: the @procedure's remaining arguments. * @drawables: (array length=n_drawables): the input #GimpDrawable-s.
* @args: the @procedure's remaining arguments.
* @run_data: (closure): the run_data given in gimp_image_procedure_new(). * @run_data: (closure): the run_data given in gimp_image_procedure_new().
* *
* The image function is run during the lifetime of the GIMP session, * The image function is run during the lifetime of the GIMP session,
@ -45,12 +46,13 @@ G_BEGIN_DECLS
* *
* Since: 3.0 * Since: 3.0
**/ **/
typedef GimpValueArray * (* GimpRunImageFunc) (GimpProcedure *procedure, typedef GimpValueArray * (* GimpRunImageFunc) (GimpProcedure *procedure,
GimpRunMode run_mode, GimpRunMode run_mode,
GimpImage *image, GimpImage *image,
GimpDrawable *drawable, gint n_drawables,
const GimpValueArray *args, GimpDrawable **drawables,
gpointer run_data); const GimpValueArray *args,
gpointer run_data);
#define GIMP_TYPE_IMAGE_PROCEDURE (gimp_image_procedure_get_type ()) #define GIMP_TYPE_IMAGE_PROCEDURE (gimp_image_procedure_get_type ())

View file

@ -141,8 +141,9 @@ gimp_config_class_init (GObjectClass *klass,
{ {
g_object_class_install_property (klass, i + 1, copy); g_object_class_install_property (klass, i + 1, copy);
} }
else if (! G_IS_PARAM_SPEC_OBJECT (pspec) && else if (! G_IS_PARAM_SPEC_OBJECT (pspec) &&
! G_IS_PARAM_SPEC_POINTER (pspec)) ! G_IS_PARAM_SPEC_POINTER (pspec) &&
! GIMP_IS_PARAM_SPEC_OBJECT_ARRAY (pspec))
{ {
/* silently ignore object properties */ /* silently ignore object properties */