Gimp/app/pdb/selection_cmds.c
Michael Natterer afd88f0bf4 replace the value union by a GValue.
2006-03-30  Michael Natterer  <mitch@gimp.org>

	* app/pdb/procedural_db.[ch] (struct Argument): replace the value
	union by a GValue.

	(procedural_db_argument_init)
	(procedural_db_compat_arg_init): new functions to initialize
	an Argument. They call g_value_init() on the Argument's value.

	(procedural_db_arguments)
	(procedural_db_return_values): initialize the returned Argument
	arrays so their GValues are ready to use. Allow to get the
	(unsuccessful) return values of a NULL ProcRecord.

	(procedural_db_destroy_args): g_value_unset() the values. Added a
	"gboolean full_destroy" parameter. Its only effect is to destroy
	PDB arrays, everything else is nicely memory managed by GValue.

	(procedural_db_execute)
	(procedural_db_run_proc): do GValue stuff. Added n_args and
	n_return_vals parameters to execute().

	(procedural_db_execute_proc): private function to execute a
	procedure. Validates the passed in arguments using the registered
	GParamSpecs before passing them to the resp. exec method.

	* app/plug-in/plug-in-params.[ch] (plug_in_params_to_args): needs
	an array of ProcArgs now in order to initialize the Arguments'
	GValues correctly. Passing NULL ProcArgs uses
	procedural_db_compat_arg_init(), so procedures (plug-ins)
	returning more values than expected work.

	(plug_in_args_to_params): do GValue stuff here too.

	(plug_in_args_destroy): removed this function,
	procedural_db_destroy_args() does the same now.

	* app/plug-in/plug-in-message.c (plug_in_handle_proc_run):
	simplified quite a bit because everything returns n_return_values
	now. Call plug_in_params_to_args() only of the procedure was found.

	(plug_in_handle_proc_return_priv): pass ProcRecs to
	plug_in_params_to_args().

	* app/batch.c
	* app/actions/plug-in-commands.c
	* app/actions/vectors-commands.c
	* app/core/gimppdbprogress.c
	* app/dialogs/about-dialog.c
	* app/file/file-open.c
	* app/file/file-save.c
	* app/plug-in/plug-ins.c
	* app/plug-in/plug-in-progress.c
	* app/plug-in/plug-in-run.[ch]
	* app/widgets/gimphelp.c
	* app/widgets/gimppdbdialog.c
	* app/xcf/xcf.c
	* tools/pdbgen/pdb/fileops.pdb: changed accordingly: don't
	g_new/g_free Argument arrays, always use procedural_db_foo()
	functions. Use GValue functions to get/set Arguments.

	* tools/pdbgen/pdb.pl: added get_value_func and set_value_func to
	all PDB types. Removed id_func, id_ret_func and check_func. Added
	flags which indicated that a type is an ID. Removed unused utility
	functions.

	* tools/pdbgen/lib.pl: use the flag instead of looking at
	functions and value types.

	* tools/pdbgen/app.pl: use the get_value_func and set_value_func
	to marshal inargs and outargs. Removed all checks performed on
	inargs because that's done by GParamSpec validation now. Added the
	missing bits to register excluded values with GimpParamSpecEnum.

	* app/pdb/*_cmds.c: regenerated.
2006-03-29 23:56:07 +00:00

1137 lines
42 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* NOTE: This file is autogenerated by pdbgen.pl. */
#include "config.h"
#include <glib-object.h>
#include "pdb-types.h"
#include "procedural_db.h"
#include "core/gimpparamspecs.h"
#include "core/gimpchannel-select.h"
#include "core/gimpchannel.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimplayer.h"
#include "core/gimppickable.h"
#include "core/gimpselection.h"
#include "gimp-intl.h"
static ProcRecord selection_bounds_proc;
static ProcRecord selection_value_proc;
static ProcRecord selection_is_empty_proc;
static ProcRecord selection_translate_proc;
static ProcRecord selection_float_proc;
static ProcRecord selection_invert_proc;
static ProcRecord selection_sharpen_proc;
static ProcRecord selection_all_proc;
static ProcRecord selection_none_proc;
static ProcRecord selection_feather_proc;
static ProcRecord selection_border_proc;
static ProcRecord selection_grow_proc;
static ProcRecord selection_shrink_proc;
static ProcRecord selection_layer_alpha_proc;
static ProcRecord selection_load_proc;
static ProcRecord selection_save_proc;
static ProcRecord selection_combine_proc;
void
register_selection_procs (Gimp *gimp)
{
ProcRecord *procedure;
/*
* selection_bounds
*/
procedure = procedural_db_init_proc (&selection_bounds_proc, 1, 5);
procedural_db_add_argument (procedure,
GIMP_PDB_IMAGE,
gimp_param_spec_image_id ("image",
"image",
"The image",
gimp,
GIMP_PARAM_READWRITE));
procedural_db_add_return_value (procedure,
GIMP_PDB_INT32,
g_param_spec_boolean ("non-empty",
"non empty",
"TRUE if there is a selection",
FALSE,
GIMP_PARAM_READWRITE));
procedural_db_add_return_value (procedure,
GIMP_PDB_INT32,
g_param_spec_int ("x1",
"x1",
"x coordinate of upper left corner of selection bounds",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
procedural_db_add_return_value (procedure,
GIMP_PDB_INT32,
g_param_spec_int ("y1",
"y1",
"y coordinate of upper left corner of selection bounds",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
procedural_db_add_return_value (procedure,
GIMP_PDB_INT32,
g_param_spec_int ("x2",
"x2",
"x coordinate of lower right corner of selection bounds",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
procedural_db_add_return_value (procedure,
GIMP_PDB_INT32,
g_param_spec_int ("y2",
"y2",
"y coordinate of lower right corner of selection bounds",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_value
*/
procedure = procedural_db_init_proc (&selection_value_proc, 3, 1);
procedural_db_add_argument (procedure,
GIMP_PDB_IMAGE,
gimp_param_spec_image_id ("image",
"image",
"The image",
gimp,
GIMP_PARAM_READWRITE));
procedural_db_add_argument (procedure,
GIMP_PDB_INT32,
g_param_spec_int ("x",
"x",
"x coordinate of value",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
procedural_db_add_argument (procedure,
GIMP_PDB_INT32,
g_param_spec_int ("y",
"y",
"y coordinate of value",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
procedural_db_add_return_value (procedure,
GIMP_PDB_INT32,
g_param_spec_int ("value",
"value",
"Value of the selection (0 <= value <= 255)",
0, 255, 0,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_is_empty
*/
procedure = procedural_db_init_proc (&selection_is_empty_proc, 1, 1);
procedural_db_add_argument (procedure,
GIMP_PDB_IMAGE,
gimp_param_spec_image_id ("image",
"image",
"The image",
gimp,
GIMP_PARAM_READWRITE));
procedural_db_add_return_value (procedure,
GIMP_PDB_INT32,
g_param_spec_boolean ("is-empty",
"is empty",
"Is the selection empty?",
FALSE,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_translate
*/
procedure = procedural_db_init_proc (&selection_translate_proc, 3, 0);
procedural_db_add_argument (procedure,
GIMP_PDB_IMAGE,
gimp_param_spec_image_id ("image",
"image",
"The image",
gimp,
GIMP_PARAM_READWRITE));
procedural_db_add_argument (procedure,
GIMP_PDB_INT32,
g_param_spec_int ("offx",
"offx",
"x offset for translation",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
procedural_db_add_argument (procedure,
GIMP_PDB_INT32,
g_param_spec_int ("offy",
"offy",
"y offset for translation",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_float
*/
procedure = procedural_db_init_proc (&selection_float_proc, 3, 1);
procedural_db_add_argument (procedure,
GIMP_PDB_DRAWABLE,
gimp_param_spec_item_id ("drawable",
"drawable",
"The drawable from which to float selection",
gimp,
GIMP_TYPE_DRAWABLE,
GIMP_PARAM_READWRITE));
procedural_db_add_argument (procedure,
GIMP_PDB_INT32,
g_param_spec_int ("offx",
"offx",
"x offset for translation",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
procedural_db_add_argument (procedure,
GIMP_PDB_INT32,
g_param_spec_int ("offy",
"offy",
"y offset for translation",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
procedural_db_add_return_value (procedure,
GIMP_PDB_LAYER,
gimp_param_spec_item_id ("layer",
"layer",
"The floated layer",
gimp,
GIMP_TYPE_LAYER,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_invert
*/
procedure = procedural_db_init_proc (&selection_invert_proc, 1, 0);
procedural_db_add_argument (procedure,
GIMP_PDB_IMAGE,
gimp_param_spec_image_id ("image",
"image",
"The image",
gimp,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_sharpen
*/
procedure = procedural_db_init_proc (&selection_sharpen_proc, 1, 0);
procedural_db_add_argument (procedure,
GIMP_PDB_IMAGE,
gimp_param_spec_image_id ("image",
"image",
"The image",
gimp,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_all
*/
procedure = procedural_db_init_proc (&selection_all_proc, 1, 0);
procedural_db_add_argument (procedure,
GIMP_PDB_IMAGE,
gimp_param_spec_image_id ("image",
"image",
"The image",
gimp,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_none
*/
procedure = procedural_db_init_proc (&selection_none_proc, 1, 0);
procedural_db_add_argument (procedure,
GIMP_PDB_IMAGE,
gimp_param_spec_image_id ("image",
"image",
"The image",
gimp,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_feather
*/
procedure = procedural_db_init_proc (&selection_feather_proc, 2, 0);
procedural_db_add_argument (procedure,
GIMP_PDB_IMAGE,
gimp_param_spec_image_id ("image",
"image",
"The image",
gimp,
GIMP_PARAM_READWRITE));
procedural_db_add_argument (procedure,
GIMP_PDB_FLOAT,
g_param_spec_double ("radius",
"radius",
"Radius of feather (in pixels)",
0, G_MAXDOUBLE, 0,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_border
*/
procedure = procedural_db_init_proc (&selection_border_proc, 2, 0);
procedural_db_add_argument (procedure,
GIMP_PDB_IMAGE,
gimp_param_spec_image_id ("image",
"image",
"The image",
gimp,
GIMP_PARAM_READWRITE));
procedural_db_add_argument (procedure,
GIMP_PDB_INT32,
g_param_spec_int ("radius",
"radius",
"Radius of border (in pixels)",
0, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_grow
*/
procedure = procedural_db_init_proc (&selection_grow_proc, 2, 0);
procedural_db_add_argument (procedure,
GIMP_PDB_IMAGE,
gimp_param_spec_image_id ("image",
"image",
"The image",
gimp,
GIMP_PARAM_READWRITE));
procedural_db_add_argument (procedure,
GIMP_PDB_INT32,
g_param_spec_int ("steps",
"steps",
"Steps of grow (in pixels)",
0, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_shrink
*/
procedure = procedural_db_init_proc (&selection_shrink_proc, 2, 0);
procedural_db_add_argument (procedure,
GIMP_PDB_IMAGE,
gimp_param_spec_image_id ("image",
"image",
"The image",
gimp,
GIMP_PARAM_READWRITE));
procedural_db_add_argument (procedure,
GIMP_PDB_INT32,
g_param_spec_int ("steps",
"steps",
"Steps of shrink (in pixels)",
0, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_layer_alpha
*/
procedure = procedural_db_init_proc (&selection_layer_alpha_proc, 1, 0);
procedural_db_add_argument (procedure,
GIMP_PDB_LAYER,
gimp_param_spec_item_id ("layer",
"layer",
"Layer with alpha",
gimp,
GIMP_TYPE_LAYER,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_load
*/
procedure = procedural_db_init_proc (&selection_load_proc, 1, 0);
procedural_db_add_argument (procedure,
GIMP_PDB_CHANNEL,
gimp_param_spec_item_id ("channel",
"channel",
"The channel",
gimp,
GIMP_TYPE_CHANNEL,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_save
*/
procedure = procedural_db_init_proc (&selection_save_proc, 1, 1);
procedural_db_add_argument (procedure,
GIMP_PDB_IMAGE,
gimp_param_spec_image_id ("image",
"image",
"The image",
gimp,
GIMP_PARAM_READWRITE));
procedural_db_add_return_value (procedure,
GIMP_PDB_CHANNEL,
gimp_param_spec_item_id ("channel",
"channel",
"The new channel",
gimp,
GIMP_TYPE_CHANNEL,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
/*
* selection_combine
*/
procedure = procedural_db_init_proc (&selection_combine_proc, 2, 0);
procedural_db_add_argument (procedure,
GIMP_PDB_CHANNEL,
gimp_param_spec_item_id ("channel",
"channel",
"The channel",
gimp,
GIMP_TYPE_CHANNEL,
GIMP_PARAM_READWRITE));
procedural_db_add_argument (procedure,
GIMP_PDB_INT32,
g_param_spec_enum ("operation",
"operation",
"The selection operation: { GIMP_CHANNEL_OP_ADD (0), GIMP_CHANNEL_OP_SUBTRACT (1), GIMP_CHANNEL_OP_REPLACE (2), GIMP_CHANNEL_OP_INTERSECT (3) }",
GIMP_TYPE_CHANNEL_OPS,
GIMP_CHANNEL_OP_ADD,
GIMP_PARAM_READWRITE));
procedural_db_register (gimp, procedure);
}
static Argument *
selection_bounds_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
Argument *return_vals;
GimpImage *image;
gboolean non_empty = FALSE;
gint32 x1 = 0;
gint32 y1 = 0;
gint32 x2 = 0;
gint32 y2 = 0;
image = gimp_value_get_image (&args[0].value, gimp);
if (success)
{
non_empty = gimp_channel_bounds (gimp_image_get_mask (image),
&x1, &y1, &x2, &y2);
}
return_vals = procedural_db_return_values (proc_record, success);
if (success)
{
g_value_set_boolean (&return_vals[1].value, non_empty);
g_value_set_int (&return_vals[2].value, x1);
g_value_set_int (&return_vals[3].value, y1);
g_value_set_int (&return_vals[4].value, x2);
g_value_set_int (&return_vals[5].value, y2);
}
return return_vals;
}
static ProcRecord selection_bounds_proc =
{
"gimp-selection-bounds",
"gimp-selection-bounds",
"Find the bounding box of the current selection.",
"This procedure returns whether there is a selection for the specified image. If there is one, the upper left and lower right corners of the bounding box are returned. These coordinates are relative to the image. Please note that the pixel specified by the lower righthand coordinate of the bounding box is not part of the selection. The selection ends at the upper left corner of this pixel. This means the width of the selection can be calculated as (x2 - x1), its height as (y2 - y1).",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_bounds_invoker } }
};
static Argument *
selection_value_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
Argument *return_vals;
GimpImage *image;
gint32 x;
gint32 y;
gint32 value = 0;
image = gimp_value_get_image (&args[0].value, gimp);
x = g_value_get_int (&args[1].value);
y = g_value_get_int (&args[2].value);
if (success)
{
value = gimp_pickable_get_opacity_at (GIMP_PICKABLE (gimp_image_get_mask (image)), x, y);
}
return_vals = procedural_db_return_values (proc_record, success);
if (success)
g_value_set_int (&return_vals[1].value, value);
return return_vals;
}
static ProcRecord selection_value_proc =
{
"gimp-selection-value",
"gimp-selection-value",
"Find the value of the selection at the specified coordinates.",
"This procedure returns the value of the selection at the specified coordinates. If the coordinates lie out of bounds, 0 is returned.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_value_invoker } }
};
static Argument *
selection_is_empty_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
Argument *return_vals;
GimpImage *image;
gboolean is_empty = FALSE;
image = gimp_value_get_image (&args[0].value, gimp);
if (success)
{
is_empty = gimp_channel_is_empty (gimp_image_get_mask (image));
}
return_vals = procedural_db_return_values (proc_record, success);
if (success)
g_value_set_boolean (&return_vals[1].value, is_empty);
return return_vals;
}
static ProcRecord selection_is_empty_proc =
{
"gimp-selection-is-empty",
"gimp-selection-is-empty",
"Determine whether the selection is empty.",
"This procedure returns TRUE if the selection for the specified image is not empty.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_is_empty_invoker } }
};
static Argument *
selection_translate_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
GimpImage *image;
gint32 offx;
gint32 offy;
image = gimp_value_get_image (&args[0].value, gimp);
offx = g_value_get_int (&args[1].value);
offy = g_value_get_int (&args[2].value);
if (success)
{
gimp_item_translate (GIMP_ITEM (gimp_image_get_mask (image)),
offx, offy, TRUE);
}
return procedural_db_return_values (proc_record, success);
}
static ProcRecord selection_translate_proc =
{
"gimp-selection-translate",
"gimp-selection-translate",
"Translate the selection by the specified offsets.",
"This procedure actually translates the selection for the specified image by the specified offsets. Regions that are translated from beyond the bounds of the image are set to empty. Valid regions of the selection which are translated beyond the bounds of the image because of this call are lost.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_translate_invoker } }
};
static Argument *
selection_float_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
Argument *return_vals;
GimpDrawable *drawable;
gint32 offx;
gint32 offy;
GimpLayer *layer = NULL;
drawable = (GimpDrawable *) gimp_value_get_item (&args[0].value, gimp, GIMP_TYPE_DRAWABLE);
offx = g_value_get_int (&args[1].value);
offy = g_value_get_int (&args[2].value);
if (success)
{
if (gimp_item_is_attached (GIMP_ITEM (drawable)))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
layer = gimp_selection_float (gimp_image_get_mask (image),
drawable, context, TRUE, offx, offy);
if (! layer)
success = FALSE;
}
else
success = FALSE;
}
return_vals = procedural_db_return_values (proc_record, success);
if (success)
gimp_value_set_item (&return_vals[1].value, GIMP_ITEM (layer));
return return_vals;
}
static ProcRecord selection_float_proc =
{
"gimp-selection-float",
"gimp-selection-float",
"Float the selection from the specified drawable with initial offsets as specified.",
"This procedure determines the region of the specified drawable that lies beneath the current selection. The region is then cut from the drawable and the resulting data is made into a new layer which is instantiated as a floating selection. The offsets allow initial positioning of the new floating selection.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_float_invoker } }
};
static Argument *
selection_invert_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
GimpImage *image;
image = gimp_value_get_image (&args[0].value, gimp);
if (success)
{
gimp_channel_invert (gimp_image_get_mask (image), TRUE);
}
return procedural_db_return_values (proc_record, success);
}
static ProcRecord selection_invert_proc =
{
"gimp-selection-invert",
"gimp-selection-invert",
"Invert the selection mask.",
"This procedure inverts the selection mask. For every pixel in the selection channel, its new value is calculated as (255 - old_value).",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_invert_invoker } }
};
static Argument *
selection_sharpen_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
GimpImage *image;
image = gimp_value_get_image (&args[0].value, gimp);
if (success)
{
gimp_channel_sharpen (gimp_image_get_mask (image), TRUE);
}
return procedural_db_return_values (proc_record, success);
}
static ProcRecord selection_sharpen_proc =
{
"gimp-selection-sharpen",
"gimp-selection-sharpen",
"Sharpen the selection mask.",
"This procedure sharpens the selection mask. For every pixel in the selection channel, if the value is > 0, the new pixel is assigned a value of 255. This removes any \"anti-aliasing\" that might exist in the selection mask's boundary.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_sharpen_invoker } }
};
static Argument *
selection_all_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
GimpImage *image;
image = gimp_value_get_image (&args[0].value, gimp);
if (success)
{
gimp_channel_all (gimp_image_get_mask (image), TRUE);
}
return procedural_db_return_values (proc_record, success);
}
static ProcRecord selection_all_proc =
{
"gimp-selection-all",
"gimp-selection-all",
"Select all of the image.",
"This procedure sets the selection mask to completely encompass the image. Every pixel in the selection channel is set to 255.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_all_invoker } }
};
static Argument *
selection_none_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
GimpImage *image;
image = gimp_value_get_image (&args[0].value, gimp);
if (success)
{
gimp_channel_clear (gimp_image_get_mask (image), NULL, TRUE);
}
return procedural_db_return_values (proc_record, success);
}
static ProcRecord selection_none_proc =
{
"gimp-selection-none",
"gimp-selection-none",
"Deselect the entire image.",
"This procedure deselects the entire image. Every pixel in the selection channel is set to 0.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_none_invoker } }
};
static Argument *
selection_feather_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
GimpImage *image;
gdouble radius;
image = gimp_value_get_image (&args[0].value, gimp);
radius = g_value_get_double (&args[1].value);
if (success)
{
gimp_channel_feather (gimp_image_get_mask (image),
radius, radius, TRUE);
}
return procedural_db_return_values (proc_record, success);
}
static ProcRecord selection_feather_proc =
{
"gimp-selection-feather",
"gimp-selection-feather",
"Feather the image's selection",
"This procedure feathers the selection. Feathering is implemented using a gaussian blur.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_feather_invoker } }
};
static Argument *
selection_border_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
GimpImage *image;
gint32 radius;
image = gimp_value_get_image (&args[0].value, gimp);
radius = g_value_get_int (&args[1].value);
if (success)
{
gimp_channel_border (gimp_image_get_mask (image),
radius, radius, TRUE);
}
return procedural_db_return_values (proc_record, success);
}
static ProcRecord selection_border_proc =
{
"gimp-selection-border",
"gimp-selection-border",
"Border the image's selection",
"This procedure borders the selection. Bordering creates a new selection which is defined along the boundary of the previous selection at every point within the specified radius.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_border_invoker } }
};
static Argument *
selection_grow_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
GimpImage *image;
gint32 steps;
image = gimp_value_get_image (&args[0].value, gimp);
steps = g_value_get_int (&args[1].value);
if (success)
{
gimp_channel_grow (gimp_image_get_mask (image),
steps, steps, TRUE);
}
return procedural_db_return_values (proc_record, success);
}
static ProcRecord selection_grow_proc =
{
"gimp-selection-grow",
"gimp-selection-grow",
"Grow the image's selection",
"This procedure grows the selection. Growing involves expanding the boundary in all directions by the specified pixel amount.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_grow_invoker } }
};
static Argument *
selection_shrink_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
GimpImage *image;
gint32 steps;
image = gimp_value_get_image (&args[0].value, gimp);
steps = g_value_get_int (&args[1].value);
if (success)
{
gimp_channel_shrink (gimp_image_get_mask (image),
steps, steps, FALSE, TRUE);
}
return procedural_db_return_values (proc_record, success);
}
static ProcRecord selection_shrink_proc =
{
"gimp-selection-shrink",
"gimp-selection-shrink",
"Shrink the image's selection",
"This procedure shrinks the selection. Shrinking invovles trimming the existing selection boundary on all sides by the specified number of pixels.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_shrink_invoker } }
};
static Argument *
selection_layer_alpha_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
GimpLayer *layer;
layer = (GimpLayer *) gimp_value_get_item (&args[0].value, gimp, GIMP_TYPE_LAYER);
if (success)
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
gimp_channel_select_alpha (gimp_image_get_mask (image),
GIMP_DRAWABLE (layer),
GIMP_CHANNEL_OP_REPLACE, FALSE, 0.0, 0.0);
}
return procedural_db_return_values (proc_record, success);
}
static ProcRecord selection_layer_alpha_proc =
{
"gimp-selection-layer-alpha",
"gimp-selection-layer-alpha",
"Transfer the specified layer's alpha channel to the selection mask.",
"This procedure requires a layer with an alpha channel. The alpha channel information is used to create a selection mask such that for any pixel in the image defined in the specified layer, that layer pixel's alpha value is transferred to the selection mask. If the layer is undefined at a particular image pixel, the associated selection mask value is set to 0.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_layer_alpha_invoker } }
};
static Argument *
selection_load_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
GimpChannel *channel;
channel = (GimpChannel *) gimp_value_get_item (&args[0].value, gimp, GIMP_TYPE_CHANNEL);
if (success)
{
GimpImage *image;
gint off_x, off_y;
image = gimp_item_get_image (GIMP_ITEM (channel));
gimp_item_offsets (GIMP_ITEM (channel), &off_x, &off_y);
gimp_channel_select_channel (gimp_image_get_mask (image),
_("Channel to Selection"),
channel,
off_x, off_y,
GIMP_CHANNEL_OP_REPLACE,
FALSE, 0.0, 0.0);
}
return procedural_db_return_values (proc_record, success);
}
static ProcRecord selection_load_proc =
{
"gimp-selection-load",
"gimp-selection-load",
"Transfer the specified channel to the selection mask.",
"This procedure loads the specified channel into the selection mask.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_load_invoker } }
};
static Argument *
selection_save_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
Argument *return_vals;
GimpImage *image;
GimpChannel *channel = NULL;
image = gimp_value_get_image (&args[0].value, gimp);
if (success)
{
channel = gimp_selection_save (gimp_image_get_mask (image));
if (! channel)
success = FALSE;
}
return_vals = procedural_db_return_values (proc_record, success);
if (success)
gimp_value_set_item (&return_vals[1].value, GIMP_ITEM (channel));
return return_vals;
}
static ProcRecord selection_save_proc =
{
"gimp-selection-save",
"gimp-selection-save",
"Copy the selection mask to a new channel.",
"This procedure copies the selection mask and stores the content in a new channel. The new channel is automatically inserted into the image's list of channels.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_save_invoker } }
};
static Argument *
selection_combine_invoker (ProcRecord *proc_record,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
GimpChannel *channel;
gint32 operation;
channel = (GimpChannel *) gimp_value_get_item (&args[0].value, gimp, GIMP_TYPE_CHANNEL);
operation = g_value_get_enum (&args[1].value);
if (success)
{
GimpImage *image;
gint off_x, off_y;
image = gimp_item_get_image (GIMP_ITEM (channel));
gimp_item_offsets (GIMP_ITEM (channel), &off_x, &off_y);
gimp_channel_select_channel (gimp_image_get_mask (image),
_("Channel to Selection"),
channel,
off_x, off_y,
operation,
FALSE, 0.0, 0.0);
}
return procedural_db_return_values (proc_record, success);
}
static ProcRecord selection_combine_proc =
{
"gimp-selection-combine",
"gimp-selection-combine",
"Combines the specified channel with the selection mask.",
"This procedure combines the specified channel into the selection mask.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL,
GIMP_INTERNAL,
0, NULL, 0, NULL,
{ { selection_combine_invoker } }
};