[gimp] app, libgimp, pdb: add missing functions for selected items.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app, libgimp, pdb: add missing functions for selected items.
- Date: Thu, 20 Oct 2022 16:31:37 +0000 (UTC)
commit b73278f1a8181d1ce31b666834f3d229f30e2ed9
Author: Jehan <jehan girinstud io>
Date: Thu Oct 20 02:36:50 2022 +0200
app, libgimp, pdb: add missing functions for selected items.
Missing functions were:
* gimp_image_get_selected_channels()
* gimp_image_get_selected_vectors()
* gimp_image_list_selected_channels()
* gimp_image_list_selected_vectors()
* gimp_image_set_selected_channels()
* gimp_image_set_selected_vectors()
* gimp_image_take_selected_channels()
* gimp_image_take_selected_vectors()
There are discussions of renaming GimpVectors to GimpPath, which would
also be consistent with the GUI and make the always-plural less akward
in API. We'll see. For now keeping named like this.
app/pdb/image-cmds.c | 298 +++++++++++++++++++++++++++++++++++++++++++++++
app/pdb/internal-procs.c | 2 +-
libgimp/gimp.def | 8 ++
libgimp/gimpimage.c | 136 ++++++++++++++++++++-
libgimp/gimpimage.h | 10 +-
libgimp/gimpimage_pdb.c | 179 ++++++++++++++++++++++++++++
libgimp/gimpimage_pdb.h | 10 ++
pdb/groups/image.pdb | 167 ++++++++++++++++++++++++++
8 files changed, 806 insertions(+), 4 deletions(-)
---
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index aba92be6a7..0b7dc28eea 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -1836,6 +1836,164 @@ image_set_selected_layers_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
+static GimpValueArray *
+image_get_selected_channels_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GimpValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GimpValueArray *return_vals;
+ GimpImage *image;
+ gint num_channels = 0;
+ GimpChannel **channels = NULL;
+
+ image = g_value_get_object (gimp_value_array_index (args, 0));
+
+ if (success)
+ {
+ GList *list = gimp_image_get_selected_channels (image);
+
+ num_channels = g_list_length (list);
+
+ if (num_channels)
+ {
+ gint i;
+
+ channels = g_new (GimpLayer *, num_channels);
+
+ for (i = 0; i < num_channels; i++, list = g_list_next (list))
+ channels[i] = g_object_ref (list->data);
+ }
+ }
+
+ return_vals = gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+
+ if (success)
+ {
+ g_value_set_int (gimp_value_array_index (return_vals, 1), num_channels);
+ gimp_value_take_object_array (gimp_value_array_index (return_vals, 2), GIMP_TYPE_CHANNEL, (GObject **)
channels, num_channels);
+ }
+
+ return return_vals;
+}
+
+static GimpValueArray *
+image_set_selected_channels_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GimpValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GimpImage *image;
+ gint num_channels;
+ const GimpChannel **channels;
+
+ image = g_value_get_object (gimp_value_array_index (args, 0));
+ num_channels = g_value_get_int (gimp_value_array_index (args, 1));
+ channels = gimp_value_get_object_array (gimp_value_array_index (args, 2));
+
+ if (success)
+ {
+ GList *selected_channels = NULL;
+ gint i;
+
+ for (i = 0; i < num_channels; i++)
+ selected_channels = g_list_prepend (selected_channels,
+ GIMP_LAYER (channels[i]));
+
+ gimp_image_set_selected_channels (image, selected_channels);
+ g_list_free (selected_channels);
+ }
+
+ return gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+}
+
+static GimpValueArray *
+image_get_selected_vectors_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GimpValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GimpValueArray *return_vals;
+ GimpImage *image;
+ gint num_vectors = 0;
+ GimpVectors **vectors = NULL;
+
+ image = g_value_get_object (gimp_value_array_index (args, 0));
+
+ if (success)
+ {
+ GList *list = gimp_image_get_selected_vectors (image);
+
+ num_vectors = g_list_length (list);
+
+ if (num_vectors)
+ {
+ gint i;
+
+ vectors = g_new (GimpVectors *, num_vectors);
+
+ for (i = 0; i < num_vectors; i++, list = g_list_next (list))
+ vectors[i] = g_object_ref (list->data);
+ }
+ }
+
+ return_vals = gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+
+ if (success)
+ {
+ g_value_set_int (gimp_value_array_index (return_vals, 1), num_vectors);
+ gimp_value_take_object_array (gimp_value_array_index (return_vals, 2), GIMP_TYPE_VECTORS, (GObject **)
vectors, num_vectors);
+ }
+
+ return return_vals;
+}
+
+static GimpValueArray *
+image_set_selected_vectors_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GimpValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GimpImage *image;
+ gint num_vectors;
+ const GimpVectors **vectors;
+
+ image = g_value_get_object (gimp_value_array_index (args, 0));
+ num_vectors = g_value_get_int (gimp_value_array_index (args, 1));
+ vectors = (const GimpVectors **) gimp_value_get_object_array (gimp_value_array_index (args, 2));
+
+ if (success)
+ {
+ GList *selected_vectors = NULL;
+ gint i;
+
+ for (i = 0; i < num_vectors; i++)
+ selected_vectors = g_list_prepend (selected_vectors,
+ GIMP_LAYER (vectors[i]));
+
+ gimp_image_set_selected_vectors (image, selected_vectors);
+ g_list_free (selected_vectors);
+ }
+
+ return gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+}
+
static GimpValueArray *
image_get_selected_drawables_invoker (GimpProcedure *procedure,
Gimp *gimp,
@@ -4425,6 +4583,146 @@ register_image_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
+ /*
+ * gimp-image-get-selected-channels
+ */
+ procedure = gimp_procedure_new (image_get_selected_channels_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-image-get-selected-channels");
+ gimp_procedure_set_static_help (procedure,
+ "Returns the specified image's selected channels.",
+ "This procedure returns the list of selected channels in the specified
image.",
+ NULL);
+ gimp_procedure_set_static_attribution (procedure,
+ "Jehan",
+ "Jehan",
+ "2022");
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_image ("image",
+ "image",
+ "The image",
+ FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ g_param_spec_int ("num-channels",
+ "num channels",
+ "The number of selected channels in the image",
+ 0, G_MAXINT32, 0,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ gimp_param_spec_object_array ("channels",
+ "channels",
+ "The list of selected channels in the
image.",
+ GIMP_TYPE_CHANNEL,
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
+ * gimp-image-set-selected-channels
+ */
+ procedure = gimp_procedure_new (image_set_selected_channels_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-image-set-selected-channels");
+ gimp_procedure_set_static_help (procedure,
+ "Sets the specified image's selected channels.",
+ "The channels are set as the selected channels in the image. Any previous
selected layers or channels are unselected. An exception is a previously existing floating selection, in
which case this procedure will return an execution error.",
+ NULL);
+ gimp_procedure_set_static_attribution (procedure,
+ "Jehan",
+ "Jehan",
+ "2022");
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_image ("image",
+ "image",
+ "The image",
+ FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ g_param_spec_int ("num-channels",
+ "num channels",
+ "The number of channels to select",
+ 0, G_MAXINT32, 0,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_object_array ("channels",
+ "channels",
+ "The list of channels to select",
+ GIMP_TYPE_CHANNEL,
+ GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
+ * gimp-image-get-selected-vectors
+ */
+ procedure = gimp_procedure_new (image_get_selected_vectors_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-image-get-selected-vectors");
+ gimp_procedure_set_static_help (procedure,
+ "Returns the specified image's selected vectors.",
+ "This procedure returns the list of selected vectors in the specified
image.",
+ NULL);
+ gimp_procedure_set_static_attribution (procedure,
+ "Jehan",
+ "Jehan",
+ "2022");
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_image ("image",
+ "image",
+ "The image",
+ FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ g_param_spec_int ("num-vectors",
+ "num vectors",
+ "The number of selected vectors in the image",
+ 0, G_MAXINT32, 0,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ gimp_param_spec_object_array ("vectors",
+ "vectors",
+ "The list of selected vectors in the
image.",
+ GIMP_TYPE_VECTORS,
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
+ * gimp-image-set-selected-vectors
+ */
+ procedure = gimp_procedure_new (image_set_selected_vectors_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-image-set-selected-vectors");
+ gimp_procedure_set_static_help (procedure,
+ "Sets the specified image's selected vectors.",
+ "The vectors are set as the selected vectors in the image.",
+ NULL);
+ gimp_procedure_set_static_attribution (procedure,
+ "Jehan",
+ "Jehan",
+ "2022");
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_image ("image",
+ "image",
+ "The image",
+ FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ g_param_spec_int ("num-vectors",
+ "num vectors",
+ "The number of vectors to select",
+ 0, G_MAXINT32, 0,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_object_array ("vectors",
+ "vectors",
+ "The list of vectors to select",
+ GIMP_TYPE_VECTORS,
+ GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
/*
* gimp-image-get-selected-drawables
*/
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 2ad07ddfc3..d604090843 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -30,7 +30,7 @@
#include "internal-procs.h"
-/* 763 procedures registered total */
+/* 767 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index cd54a8213a..0e2aec5062 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -414,8 +414,10 @@ EXPORTS
gimp_image_get_precision
gimp_image_get_resolution
gimp_image_get_sample_point_position
+ gimp_image_get_selected_channels
gimp_image_get_selected_drawables
gimp_image_get_selected_layers
+ gimp_image_get_selected_vectors
gimp_image_get_selection
gimp_image_get_simulation_bpc
gimp_image_get_simulation_intent
@@ -448,7 +450,9 @@ EXPORTS
gimp_image_is_valid
gimp_image_list_channels
gimp_image_list_layers
+ gimp_image_list_selected_channels
gimp_image_list_selected_layers
+ gimp_image_list_selected_vectors
gimp_image_list_vectors
gimp_image_lower_item
gimp_image_lower_item_to_bottom
@@ -494,14 +498,18 @@ EXPORTS
gimp_image_set_file
gimp_image_set_metadata
gimp_image_set_resolution
+ gimp_image_set_selected_channels
gimp_image_set_selected_layers
+ gimp_image_set_selected_vectors
gimp_image_set_simulation_bpc
gimp_image_set_simulation_intent
gimp_image_set_simulation_profile
gimp_image_set_simulation_profile_from_file
gimp_image_set_tattoo_state
gimp_image_set_unit
+ gimp_image_take_selected_channels
gimp_image_take_selected_layers
+ gimp_image_take_selected_vectors
gimp_image_thaw_channels
gimp_image_thaw_layers
gimp_image_thaw_vectors
diff --git a/libgimp/gimpimage.c b/libgimp/gimpimage.c
index 40ac24bdb4..43db416634 100644
--- a/libgimp/gimpimage.c
+++ b/libgimp/gimpimage.c
@@ -261,7 +261,7 @@ gimp_image_list_layers (GimpImage *image)
* image.
*
* Returns: (element-type GimpLayer) (transfer container):
- * The list of layers contained in the image.
+ * The list of selected layers in the image.
* The returned list must be freed with g_list_free(). Layer
* elements belong to libgimp and must not be freed.
*
@@ -319,6 +319,140 @@ gimp_image_take_selected_layers (GimpImage *image,
return success;
}
+/**
+ * gimp_image_list_selected_channels:
+ * @image: The image.
+ *
+ * Returns the list of channels selected in the specified image.
+ *
+ * This procedure returns the list of channels selected in the specified
+ * image.
+ *
+ * Returns: (element-type GimpChannel) (transfer container):
+ * The list of selected channels in the image.
+ * The returned list must be freed with g_list_free(). Layer
+ * elements belong to libgimp and must not be freed.
+ *
+ * Since: 3.0
+ **/
+GList *
+gimp_image_list_selected_channels (GimpImage *image)
+{
+ GimpChannel **channels;
+ gint num_channels;
+ GList *list = NULL;
+ gint i;
+
+ channels = gimp_image_get_selected_channels (image, &num_channels);
+
+ for (i = 0; i < num_channels; i++)
+ list = g_list_prepend (list, channels[i]);
+
+ g_free (channels);
+
+ return g_list_reverse (list);
+}
+
+/**
+ * gimp_image_take_selected_channels:
+ * @image: The image.
+ * @channels: (transfer container) (element-type GimpChannel): The list of channels to select.
+ *
+ * The channels are set as the selected channels in the image. Any previous
+ * selected layers or channels are unselected. An exception is a previously
+ * existing floating selection, in which case this procedure will return an
+ * execution error.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 3.0
+ **/
+gboolean
+gimp_image_take_selected_channels (GimpImage *image,
+ GList *channels)
+{
+ GimpChannel **sel_channels;
+ GList *list;
+ gboolean success;
+ gint i;
+
+ sel_channels = g_new0 (GimpChannel *, g_list_length (channels));
+ for (list = channels, i = 0; list; list = list->next, i++)
+ sel_channels[i] = list->data;
+
+ success = gimp_image_set_selected_channels (image, g_list_length (channels),
+ (const GimpChannel **) sel_channels);
+ g_list_free (channels);
+
+ return success;
+}
+
+/**
+ * gimp_image_list_selected_vectors:
+ * @image: The image.
+ *
+ * Returns the list of paths selected in the specified image.
+ *
+ * This procedure returns the list of paths selected in the specified
+ * image.
+ *
+ * Returns: (element-type GimpVectors) (transfer container):
+ * The list of selected paths in the image.
+ * The returned list must be freed with g_list_free().
+ * Path elements belong to libgimp and must not be freed.
+ *
+ * Since: 3.0
+ **/
+GList *
+gimp_image_list_selected_vectors (GimpImage *image)
+{
+ GimpVectors **vectors;
+ gint num_vectors;
+ GList *list = NULL;
+ gint i;
+
+ vectors = gimp_image_get_selected_vectors (image, &num_vectors);
+
+ for (i = 0; i < num_vectors; i++)
+ list = g_list_prepend (list, vectors[i]);
+
+ g_free (vectors);
+
+ return g_list_reverse (list);
+}
+
+/**
+ * gimp_image_take_selected_vectors:
+ * @image: The image.
+ * @vectors: (transfer container) (element-type GimpVectors): The list of paths to select.
+ *
+ * The paths are set as the selected paths in the image. Any previous
+ * selected paths are unselected.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 3.0
+ **/
+gboolean
+gimp_image_take_selected_vectors (GimpImage *image,
+ GList *vectors)
+{
+ GimpVectors **sel_vectors;
+ GList *list;
+ gboolean success;
+ gint i;
+
+ sel_vectors = g_new0 (GimpVectors *, g_list_length (vectors));
+ for (list = vectors, i = 0; list; list = list->next, i++)
+ sel_vectors[i] = list->data;
+
+ success = gimp_image_set_selected_vectors (image, g_list_length (vectors),
+ (const GimpVectors **) sel_vectors);
+ g_list_free (vectors);
+
+ return success;
+}
+
/**
* gimp_image_list_channels:
* @image: The image.
diff --git a/libgimp/gimpimage.h b/libgimp/gimpimage.h
index 82352eb865..b2de76785d 100644
--- a/libgimp/gimpimage.h
+++ b/libgimp/gimpimage.h
@@ -46,9 +46,15 @@ GList * gimp_image_list_layers (GimpImage *image);
GList * gimp_image_list_channels (GimpImage *image);
GList * gimp_image_list_vectors (GimpImage *image);
-GList * gimp_image_list_selected_layers (GimpImage *image);
-gboolean gimp_image_take_selected_layers (GimpImage *image,
+GList * gimp_image_list_selected_layers (GimpImage *image);
+gboolean gimp_image_take_selected_layers (GimpImage *image,
GList *layers);
+GList * gimp_image_list_selected_channels (GimpImage *image);
+gboolean gimp_image_take_selected_channels (GimpImage *image,
+ GList *channels);
+GList * gimp_image_list_selected_vectors (GimpImage *image);
+gboolean gimp_image_take_selected_vectors (GimpImage *image,
+ GList *vectors);
guchar * gimp_image_get_colormap (GimpImage *image,
gint *num_colors);
diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c
index e691fe6939..4a3d9d19ec 100644
--- a/libgimp/gimpimage_pdb.c
+++ b/libgimp/gimpimage_pdb.c
@@ -2138,6 +2138,185 @@ gimp_image_set_selected_layers (GimpImage *image,
return success;
}
+/**
+ * gimp_image_get_selected_channels: (skip)
+ * @image: The image.
+ * @num_channels: (out): The number of selected channels in the image.
+ *
+ * Returns the specified image's selected channels.
+ *
+ * This procedure returns the list of selected channels in the
+ * specified image.
+ *
+ * Returns: (array length=num_channels) (element-type GimpChannel) (transfer container):
+ * The list of selected channels in the image.
+ * The returned value must be freed with g_free().
+ *
+ * Since: 3.0.0
+ **/
+GimpChannel **
+gimp_image_get_selected_channels (GimpImage *image,
+ gint *num_channels)
+{
+ GimpValueArray *args;
+ GimpValueArray *return_vals;
+ GimpChannel **channels = NULL;
+
+ args = gimp_value_array_new_from_types (NULL,
+ GIMP_TYPE_IMAGE, image,
+ G_TYPE_NONE);
+
+ return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+ "gimp-image-get-selected-channels",
+ args);
+ gimp_value_array_unref (args);
+
+ *num_channels = 0;
+
+ if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
+ {
+ *num_channels = GIMP_VALUES_GET_INT (return_vals, 1);
+ { GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) channels =
g_memdup2 (a->data, a->length * sizeof (gpointer)); };
+ }
+
+ gimp_value_array_unref (return_vals);
+
+ return channels;
+}
+
+/**
+ * gimp_image_set_selected_channels:
+ * @image: The image.
+ * @num_channels: The number of channels to select.
+ * @channels: (array length=num_channels) (element-type GimpChannel): The list of channels to select.
+ *
+ * Sets the specified image's selected channels.
+ *
+ * The channels are set as the selected channels in the image. Any
+ * previous selected layers or channels are unselected. An exception is
+ * a previously existing floating selection, in which case this
+ * procedure will return an execution error.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 3.0.0
+ **/
+gboolean
+gimp_image_set_selected_channels (GimpImage *image,
+ gint num_channels,
+ const GimpChannel **channels)
+{
+ GimpValueArray *args;
+ GimpValueArray *return_vals;
+ gboolean success = TRUE;
+
+ args = gimp_value_array_new_from_types (NULL,
+ GIMP_TYPE_IMAGE, image,
+ G_TYPE_INT, num_channels,
+ GIMP_TYPE_OBJECT_ARRAY, NULL,
+ G_TYPE_NONE);
+ gimp_value_set_object_array (gimp_value_array_index (args, 2), GIMP_TYPE_CHANNEL, (GObject **) channels,
num_channels);
+
+ return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+ "gimp-image-set-selected-channels",
+ args);
+ gimp_value_array_unref (args);
+
+ success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
+
+ gimp_value_array_unref (return_vals);
+
+ return success;
+}
+
+/**
+ * gimp_image_get_selected_vectors: (skip)
+ * @image: The image.
+ * @num_vectors: (out): The number of selected vectors in the image.
+ *
+ * Returns the specified image's selected vectors.
+ *
+ * This procedure returns the list of selected vectors in the specified
+ * image.
+ *
+ * Returns: (array length=num_vectors) (element-type GimpVectors) (transfer container):
+ * The list of selected vectors in the image.
+ * The returned value must be freed with g_free().
+ *
+ * Since: 3.0.0
+ **/
+GimpVectors **
+gimp_image_get_selected_vectors (GimpImage *image,
+ gint *num_vectors)
+{
+ GimpValueArray *args;
+ GimpValueArray *return_vals;
+ GimpVectors **vectors = NULL;
+
+ args = gimp_value_array_new_from_types (NULL,
+ GIMP_TYPE_IMAGE, image,
+ G_TYPE_NONE);
+
+ return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+ "gimp-image-get-selected-vectors",
+ args);
+ gimp_value_array_unref (args);
+
+ *num_vectors = 0;
+
+ if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
+ {
+ *num_vectors = GIMP_VALUES_GET_INT (return_vals, 1);
+ { GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) vectors =
g_memdup2 (a->data, a->length * sizeof (gpointer)); };
+ }
+
+ gimp_value_array_unref (return_vals);
+
+ return vectors;
+}
+
+/**
+ * gimp_image_set_selected_vectors:
+ * @image: The image.
+ * @num_vectors: The number of vectors to select.
+ * @vectors: (array length=num_vectors) (element-type GimpVectors): The list of vectors to select.
+ *
+ * Sets the specified image's selected vectors.
+ *
+ * The vectors are set as the selected vectors in the image.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 3.0.0
+ **/
+gboolean
+gimp_image_set_selected_vectors (GimpImage *image,
+ gint num_vectors,
+ const GimpVectors **vectors)
+{
+ GimpValueArray *args;
+ GimpValueArray *return_vals;
+ gboolean success = TRUE;
+
+ args = gimp_value_array_new_from_types (NULL,
+ GIMP_TYPE_IMAGE, image,
+ G_TYPE_INT, num_vectors,
+ GIMP_TYPE_OBJECT_ARRAY, NULL,
+ G_TYPE_NONE);
+ gimp_value_set_object_array (gimp_value_array_index (args, 2), GIMP_TYPE_VECTORS, (GObject **) vectors,
num_vectors);
+
+ return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+ "gimp-image-set-selected-vectors",
+ args);
+ gimp_value_array_unref (args);
+
+ success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
+
+ gimp_value_array_unref (return_vals);
+
+ return success;
+}
+
/**
* gimp_image_get_selected_drawables:
* @image: The image.
diff --git a/libgimp/gimpimage_pdb.h b/libgimp/gimpimage_pdb.h
index 50d34554c1..f2d4d31ae0 100644
--- a/libgimp/gimpimage_pdb.h
+++ b/libgimp/gimpimage_pdb.h
@@ -138,6 +138,16 @@ GimpLayer** gimp_image_get_selected_layers (GimpImage
gboolean gimp_image_set_selected_layers (GimpImage *image,
gint num_layers,
const GimpLayer **layers);
+GimpChannel** gimp_image_get_selected_channels (GimpImage *image,
+ gint *num_channels);
+gboolean gimp_image_set_selected_channels (GimpImage *image,
+ gint num_channels,
+ const GimpChannel **channels);
+GimpVectors** gimp_image_get_selected_vectors (GimpImage *image,
+ gint *num_vectors);
+gboolean gimp_image_set_selected_vectors (GimpImage *image,
+ gint num_vectors,
+ const GimpVectors **vectors);
GimpItem** gimp_image_get_selected_drawables (GimpImage *image,
gint *num_drawables);
GimpSelection* gimp_image_get_selection (GimpImage *image);
diff --git a/pdb/groups/image.pdb b/pdb/groups/image.pdb
index cb443fb3e0..f0817d6152 100644
--- a/pdb/groups/image.pdb
+++ b/pdb/groups/image.pdb
@@ -1884,6 +1884,171 @@ CODE
);
}
+sub image_get_selected_channels {
+ $blurb = "Returns the specified image's selected channels.";
+
+ $help = <<'HELP';
+This procedure returns the list of selected channels in the specified image.
+HELP
+
+ &jehan_pdb_misc('2022', '3.0.0');
+
+ $skip_gi = 1;
+
+ @inargs = (
+ { name => 'image', type => 'image',
+ desc => 'The image' }
+ );
+
+ @outargs = (
+ { name => 'channels', type => 'channelarray',
+ desc => 'The list of selected channels in the image.',
+ array => { name => 'num_channels',
+ desc => 'The number of selected channels in the image' } }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ GList *list = gimp_image_get_selected_channels (image);
+
+ num_channels = g_list_length (list);
+
+ if (num_channels)
+ {
+ gint i;
+
+ channels = g_new (GimpLayer *, num_channels);
+
+ for (i = 0; i < num_channels; i++, list = g_list_next (list))
+ channels[i] = g_object_ref (list->data);
+ }
+}
+CODE
+ );
+}
+
+sub image_set_selected_channels {
+ $blurb = "Sets the specified image's selected channels.";
+
+ $help = <<'HELP';
+The channels are set as the selected channels in the image. Any previous
+selected layers or channels are unselected. An exception is a previously
+existing floating selection, in which case this procedure will return an
+execution error.
+HELP
+
+ &jehan_pdb_misc('2022', '3.0.0');
+
+ @inargs = (
+ { name => 'image', type => 'image',
+ desc => 'The image' },
+ { name => 'channels', type => 'channelarray',
+ desc => 'The list of channels to select',
+ no_validate => 1,
+ array => { name => 'num_channels',
+ type => '0 <= int32',
+ desc => 'The number of channels to select' } }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ GList *selected_channels = NULL;
+ gint i;
+
+ for (i = 0; i < num_channels; i++)
+ selected_channels = g_list_prepend (selected_channels,
+ GIMP_LAYER (channels[i]));
+
+ gimp_image_set_selected_channels (image, selected_channels);
+ g_list_free (selected_channels);
+}
+CODE
+ );
+}
+
+sub image_get_selected_vectors {
+ $blurb = "Returns the specified image's selected vectors.";
+
+ $help = <<'HELP';
+This procedure returns the list of selected vectors in the specified image.
+HELP
+
+ &jehan_pdb_misc('2022', '3.0.0');
+
+ $skip_gi = 1;
+
+ @inargs = (
+ { name => 'image', type => 'image',
+ desc => 'The image' }
+ );
+
+ @outargs = (
+ { name => 'vectors', type => 'vectorarray',
+ desc => 'The list of selected vectors in the image.',
+ array => { name => 'num_vectors',
+ desc => 'The number of selected vectors in the image' } }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ GList *list = gimp_image_get_selected_vectors (image);
+
+ num_vectors = g_list_length (list);
+
+ if (num_vectors)
+ {
+ gint i;
+
+ vectors = g_new (GimpVectors *, num_vectors);
+
+ for (i = 0; i < num_vectors; i++, list = g_list_next (list))
+ vectors[i] = g_object_ref (list->data);
+ }
+}
+CODE
+ );
+}
+
+sub image_set_selected_vectors {
+ $blurb = "Sets the specified image's selected vectors.";
+
+ $help = <<'HELP';
+The vectors are set as the selected vectors in the image.
+HELP
+
+ &jehan_pdb_misc('2022', '3.0.0');
+
+ @inargs = (
+ { name => 'image', type => 'image',
+ desc => 'The image' },
+ { name => 'vectors', type => 'vectorarray',
+ desc => 'The list of vectors to select',
+ no_validate => 1,
+ array => { name => 'num_vectors',
+ type => '0 <= int32',
+ desc => 'The number of vectors to select' } }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ GList *selected_vectors = NULL;
+ gint i;
+
+ for (i = 0; i < num_vectors; i++)
+ selected_vectors = g_list_prepend (selected_vectors,
+ GIMP_LAYER (vectors[i]));
+
+ gimp_image_set_selected_vectors (image, selected_vectors);
+ g_list_free (selected_vectors);
+}
+CODE
+ );
+}
+
sub image_get_selected_drawables {
$blurb = "Get the image's selected drawables";
@@ -3015,6 +3180,8 @@ CODE
image_clean_all image_is_dirty
image_thumbnail
image_get_selected_layers image_set_selected_layers
+ image_get_selected_channels image_set_selected_channels
+ image_get_selected_vectors image_set_selected_vectors
image_get_selected_drawables
image_get_selection
image_get_component_active image_set_component_active
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]