[gimp] Bug 656716 - Have a procedure to get a layer from its name
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Bug 656716 - Have a procedure to get a layer from its name
- Date: Sat, 24 Sep 2011 14:36:41 +0000 (UTC)
commit e071bfa3b6eae78b9e81d22d9dc584701173d6bc
Author: Michael Natterer <mitch gimp org>
Date: Sat Sep 24 16:35:59 2011 +0200
Bug 656716 - Have a procedure to get a layer from its name
Add gimp_image_get_[layer|channel|vectors]_by_name().
app/pdb/image-cmds.c | 201 ++++++++++++++++++++++++++++++++++++++++++++
app/pdb/internal-procs.c | 2 +-
libgimp/gimp.def | 3 +
libgimp/gimpimage_pdb.c | 108 ++++++++++++++++++++++++
libgimp/gimpimage_pdb.h | 6 ++
tools/pdbgen/pdb/image.pdb | 96 +++++++++++++++++++++-
6 files changed, 414 insertions(+), 2 deletions(-)
---
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index 378e234..78ba3b2 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -2575,6 +2575,99 @@ image_get_vectors_by_tattoo_invoker (GimpProcedure *procedure,
}
static GValueArray *
+image_get_layer_by_name_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GValueArray *return_vals;
+ GimpImage *image;
+ const gchar *name;
+ GimpLayer *layer = NULL;
+
+ image = gimp_value_get_image (&args->values[0], gimp);
+ name = g_value_get_string (&args->values[1]);
+
+ if (success)
+ {
+ layer = gimp_image_get_layer_by_name (image, name);
+ }
+
+ return_vals = gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+
+ if (success)
+ gimp_value_set_layer (&return_vals->values[1], layer);
+
+ return return_vals;
+}
+
+static GValueArray *
+image_get_channel_by_name_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GValueArray *return_vals;
+ GimpImage *image;
+ const gchar *name;
+ GimpChannel *channel = NULL;
+
+ image = gimp_value_get_image (&args->values[0], gimp);
+ name = g_value_get_string (&args->values[1]);
+
+ if (success)
+ {
+ channel = gimp_image_get_channel_by_name (image, name);
+ }
+
+ return_vals = gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+
+ if (success)
+ gimp_value_set_channel (&return_vals->values[1], channel);
+
+ return return_vals;
+}
+
+static GValueArray *
+image_get_vectors_by_name_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GValueArray *return_vals;
+ GimpImage *image;
+ const gchar *name;
+ GimpVectors *vectors = NULL;
+
+ image = gimp_value_get_image (&args->values[0], gimp);
+ name = g_value_get_string (&args->values[1]);
+
+ if (success)
+ {
+ vectors = gimp_image_get_vectors_by_name (image, name);
+ }
+
+ return_vals = gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+
+ if (success)
+ gimp_value_set_vectors (&return_vals->values[1], vectors);
+
+ return return_vals;
+}
+
+static GValueArray *
image_attach_parasite_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
@@ -5257,6 +5350,114 @@ register_image_procs (GimpPDB *pdb)
g_object_unref (procedure);
/*
+ * gimp-image-get-layer-by-name
+ */
+ procedure = gimp_procedure_new (image_get_layer_by_name_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-image-get-layer-by-name");
+ gimp_procedure_set_static_strings (procedure,
+ "gimp-image-get-layer-by-name",
+ "Find a layer with a given name in an image.",
+ "This procedure returns the layer with the given name in the specified image.",
+ "Michael Natterer <mitch gimp org>",
+ "Michael Natterer",
+ "2011",
+ NULL);
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_image_id ("image",
+ "image",
+ "The image",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_string ("name",
+ "name",
+ "The name of the layer to find",
+ FALSE, FALSE, TRUE,
+ NULL,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ gimp_param_spec_layer_id ("layer",
+ "layer",
+ "The layer with the specified name",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
+ * gimp-image-get-channel-by-name
+ */
+ procedure = gimp_procedure_new (image_get_channel_by_name_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-image-get-channel-by-name");
+ gimp_procedure_set_static_strings (procedure,
+ "gimp-image-get-channel-by-name",
+ "Find a channel with a given name in an image.",
+ "This procedure returns the channel with the given name in the specified image.",
+ "Michael Natterer <mitch gimp org>",
+ "Michael Natterer",
+ "2011",
+ NULL);
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_image_id ("image",
+ "image",
+ "The image",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_string ("name",
+ "name",
+ "The name of the channel to find",
+ FALSE, FALSE, TRUE,
+ NULL,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ gimp_param_spec_channel_id ("channel",
+ "channel",
+ "The channel with the specified name",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
+ * gimp-image-get-vectors-by-name
+ */
+ procedure = gimp_procedure_new (image_get_vectors_by_name_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-image-get-vectors-by-name");
+ gimp_procedure_set_static_strings (procedure,
+ "gimp-image-get-vectors-by-name",
+ "Find a vectors with a given name in an image.",
+ "This procedure returns the vectors with the given name in the specified image.",
+ "Michael Natterer <mitch gimp org>",
+ "Michael Natterer",
+ "2011",
+ NULL);
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_image_id ("image",
+ "image",
+ "The image",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_string ("name",
+ "name",
+ "The name of the vectors to find",
+ FALSE, FALSE, TRUE,
+ NULL,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ gimp_param_spec_vectors_id ("vectors",
+ "vectors",
+ "The vectors with the specified name",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
* gimp-image-attach-parasite
*/
procedure = gimp_procedure_new (image_attach_parasite_invoker);
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 269f64b..97edc7b 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
#include "internal-procs.h"
-/* 633 procedures registered total */
+/* 636 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 347f606..260c3c3 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -352,6 +352,7 @@ EXPORTS
gimp_image_get_active_drawable
gimp_image_get_active_layer
gimp_image_get_active_vectors
+ gimp_image_get_channel_by_name
gimp_image_get_channel_by_tattoo
gimp_image_get_channel_position
gimp_image_get_channels
@@ -366,6 +367,7 @@ EXPORTS
gimp_image_get_guide_position
gimp_image_get_imported_uri
gimp_image_get_item_position
+ gimp_image_get_layer_by_name
gimp_image_get_layer_by_tattoo
gimp_image_get_layer_position
gimp_image_get_layers
@@ -380,6 +382,7 @@ EXPORTS
gimp_image_get_unit
gimp_image_get_uri
gimp_image_get_vectors
+ gimp_image_get_vectors_by_name
gimp_image_get_vectors_by_tattoo
gimp_image_get_vectors_position
gimp_image_get_xcf_uri
diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c
index ce7b82d..6ee0c0f 100644
--- a/libgimp/gimpimage_pdb.c
+++ b/libgimp/gimpimage_pdb.c
@@ -2789,6 +2789,114 @@ gimp_image_get_vectors_by_tattoo (gint32 image_ID,
}
/**
+ * gimp_image_get_layer_by_name:
+ * @image_ID: The image.
+ * @name: The name of the layer to find.
+ *
+ * Find a layer with a given name in an image.
+ *
+ * This procedure returns the layer with the given name in the
+ * specified image.
+ *
+ * Returns: The layer with the specified name.
+ *
+ * Since: GIMP 2.8
+ **/
+gint32
+gimp_image_get_layer_by_name (gint32 image_ID,
+ const gchar *name)
+{
+ GimpParam *return_vals;
+ gint nreturn_vals;
+ gint32 layer_ID = -1;
+
+ return_vals = gimp_run_procedure ("gimp-image-get-layer-by-name",
+ &nreturn_vals,
+ GIMP_PDB_IMAGE, image_ID,
+ GIMP_PDB_STRING, name,
+ GIMP_PDB_END);
+
+ if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
+ layer_ID = return_vals[1].data.d_layer;
+
+ gimp_destroy_params (return_vals, nreturn_vals);
+
+ return layer_ID;
+}
+
+/**
+ * gimp_image_get_channel_by_name:
+ * @image_ID: The image.
+ * @name: The name of the channel to find.
+ *
+ * Find a channel with a given name in an image.
+ *
+ * This procedure returns the channel with the given name in the
+ * specified image.
+ *
+ * Returns: The channel with the specified name.
+ *
+ * Since: GIMP 2.8
+ **/
+gint32
+gimp_image_get_channel_by_name (gint32 image_ID,
+ const gchar *name)
+{
+ GimpParam *return_vals;
+ gint nreturn_vals;
+ gint32 channel_ID = -1;
+
+ return_vals = gimp_run_procedure ("gimp-image-get-channel-by-name",
+ &nreturn_vals,
+ GIMP_PDB_IMAGE, image_ID,
+ GIMP_PDB_STRING, name,
+ GIMP_PDB_END);
+
+ if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
+ channel_ID = return_vals[1].data.d_channel;
+
+ gimp_destroy_params (return_vals, nreturn_vals);
+
+ return channel_ID;
+}
+
+/**
+ * gimp_image_get_vectors_by_name:
+ * @image_ID: The image.
+ * @name: The name of the vectors to find.
+ *
+ * Find a vectors with a given name in an image.
+ *
+ * This procedure returns the vectors with the given name in the
+ * specified image.
+ *
+ * Returns: The vectors with the specified name.
+ *
+ * Since: GIMP 2.8
+ **/
+gint32
+gimp_image_get_vectors_by_name (gint32 image_ID,
+ const gchar *name)
+{
+ GimpParam *return_vals;
+ gint nreturn_vals;
+ gint32 vectors_ID = -1;
+
+ return_vals = gimp_run_procedure ("gimp-image-get-vectors-by-name",
+ &nreturn_vals,
+ GIMP_PDB_IMAGE, image_ID,
+ GIMP_PDB_STRING, name,
+ GIMP_PDB_END);
+
+ if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
+ vectors_ID = return_vals[1].data.d_vectors;
+
+ gimp_destroy_params (return_vals, nreturn_vals);
+
+ return vectors_ID;
+}
+
+/**
* gimp_image_attach_parasite:
* @image_ID: The image.
* @parasite: The parasite to attach to an image.
diff --git a/libgimp/gimpimage_pdb.h b/libgimp/gimpimage_pdb.h
index 28003a6..3f48a62 100644
--- a/libgimp/gimpimage_pdb.h
+++ b/libgimp/gimpimage_pdb.h
@@ -204,6 +204,12 @@ gint32 gimp_image_get_channel_by_tattoo (gint32
gint tattoo);
gint32 gimp_image_get_vectors_by_tattoo (gint32 image_ID,
gint tattoo);
+gint32 gimp_image_get_layer_by_name (gint32 image_ID,
+ const gchar *name);
+gint32 gimp_image_get_channel_by_name (gint32 image_ID,
+ const gchar *name);
+gint32 gimp_image_get_vectors_by_name (gint32 image_ID,
+ const gchar *name);
gboolean gimp_image_attach_parasite (gint32 image_ID,
const GimpParasite *parasite);
gboolean gimp_image_detach_parasite (gint32 image_ID,
diff --git a/tools/pdbgen/pdb/image.pdb b/tools/pdbgen/pdb/image.pdb
index 6bc1d91..df8426b 100644
--- a/tools/pdbgen/pdb/image.pdb
+++ b/tools/pdbgen/pdb/image.pdb
@@ -2601,6 +2601,97 @@ CODE
);
}
+sub image_get_layer_by_name {
+ $blurb = 'Find a layer with a given name in an image.';
+
+ $help = <<'HELP';
+This procedure returns the layer with the given name in the specified image.
+HELP
+
+ &mitch_pdb_misc('2011', '2.8');
+
+ @inargs = (
+ { name => 'image', type => 'image',
+ desc => 'The image' },
+ { name => 'name', type => 'string', non_empty => 1,
+ desc => 'The name of the layer to find' }
+ );
+
+ @outargs = (
+ { name => 'layer', type => 'layer',
+ desc => 'The layer with the specified name' }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ layer = gimp_image_get_layer_by_name (image, name);
+}
+CODE
+ );
+}
+
+sub image_get_channel_by_name {
+ $blurb = 'Find a channel with a given name in an image.';
+
+ $help = <<'HELP';
+This procedure returns the channel with the given name in the specified image.
+HELP
+
+ &mitch_pdb_misc('2011', '2.8');
+
+ @inargs = (
+ { name => 'image', type => 'image',
+ desc => 'The image' },
+ { name => 'name', type => 'string', non_empty => 1,
+ desc => 'The name of the channel to find' }
+ );
+
+ @outargs = (
+ { name => 'channel', type => 'channel',
+ desc => 'The channel with the specified name' }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ channel = gimp_image_get_channel_by_name (image, name);
+}
+CODE
+ );
+}
+
+sub image_get_vectors_by_name {
+ $blurb = 'Find a vectors with a given name in an image.';
+
+ $help = <<'HELP';
+This procedure returns the vectors with the given name in the
+specified image.
+HELP
+
+ &mitch_pdb_misc('2011', '2.8');
+
+ @inargs = (
+ { name => 'image', type => 'image',
+ desc => 'The image' },
+ { name => 'name', type => 'string', non_empty => 1,
+ desc => 'The name of the vectors to find' }
+ );
+
+ @outargs = (
+ { name => 'vectors', type => 'vectors',
+ desc => 'The vectors with the specified name' }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ vectors = gimp_image_get_vectors_by_name (image, name);
+}
+CODE
+ );
+}
+
sub image_attach_parasite {
$blurb = 'Add a parasite to an image.';
@@ -2857,6 +2948,9 @@ CODE
image_get_layer_by_tattoo
image_get_channel_by_tattoo
image_get_vectors_by_tattoo
+ image_get_layer_by_name
+ image_get_channel_by_name
+ image_get_vectors_by_name
image_attach_parasite image_detach_parasite
image_get_parasite
image_get_parasite_list);
@@ -2865,7 +2959,7 @@ CODE
# image_add_layer_mask and image_remove_layer_mask.
# If adding or removing functions, make sure the range below is
# updated correctly!
-%exports = (app => [ procs], lib => [ procs[0 42,45..80]]);
+%exports = (app => [ procs], lib => [ procs[0 42,45..83]]);
$desc = 'Image';
$doc_title = 'gimpimage';
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]