Commit e071bfa3 authored by Michael Natterer's avatar Michael Natterer 😴

Bug 656716 - Have a procedure to get a layer from its name

Add gimp_image_get_[layer|channel|vectors]_by_name().
parent 624e9904
......@@ -2574,6 +2574,99 @@ image_get_vectors_by_tattoo_invoker (GimpProcedure *procedure,
return return_vals;
}
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,
......@@ -5256,6 +5349,114 @@ register_image_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
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
*/
......
......@@ -28,7 +28,7 @@
#include "internal-procs.h"
/* 633 procedures registered total */
/* 636 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
......
......@@ -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
......
......@@ -2788,6 +2788,114 @@ gimp_image_get_vectors_by_tattoo (gint32 image_ID,
return vectors_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.
......
......@@ -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,
......
......@@ -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';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment