applied patch from Philip Lafleur that makes Autocrop register a new

2004-05-29  Sven Neumann  <sven@gimp.org>

	* plug-ins/common/autocrop.c: applied patch from Philip Lafleur
	that makes Autocrop register a new procedure that autocrops a
	single layer as requested in bug #142618.

	* tools/pdbgen/pdb/layer.pdb
	* app/pdb/layer_cmds.c
	* libgimp/gimplayer_pdb.c: fixed documentation for gimp_resize_layer.
	Patch provided by Philip Lafleur (bug #142618).
This commit is contained in:
Sven Neumann
2004-05-29 11:29:37 +00:00
committed by Sven Neumann
parent e56c2fe71f
commit 2626b09043
5 changed files with 73 additions and 27 deletions

View File

@ -1,8 +1,19 @@
2004-05-29 Sven Neumann <sven@gimp.org>
* plug-ins/common/autocrop.c: applied patch from Philip Lafleur
that makes Autocrop register a new procedure that autocrops a
single layer as requested in bug #142618.
* tools/pdbgen/pdb/layer.pdb
* app/pdb/layer_cmds.c
* libgimp/gimplayer_pdb.c: fixed documentation for gimp_resize_layer.
Patch provided by Philip Lafleur (bug #142618).
2004-05-29 Sven Neumann <sven@gimp.org> 2004-05-29 Sven Neumann <sven@gimp.org>
* app/widgets/gimptemplateeditor.c * app/widgets/gimptemplateeditor.c
(gimp_template_editor_constructor): add the spinbuttons to the (gimp_template_editor_constructor): add the spinbuttons to the
size entry in the correct order. Fixes bug 143347. size entry in the correct order. Fixes bug #143347.
2004-05-28 Michael Natterer <mitch@gimp.org> 2004-05-28 Michael Natterer <mitch@gimp.org>

View File

@ -545,12 +545,12 @@ static ProcArg layer_resize_inargs[] =
{ {
GIMP_PDB_INT32, GIMP_PDB_INT32,
"offx", "offx",
"x offset between upper left corner of old and new layers: (new - old)" "x offset between upper left corner of old and new layers: (old - new)"
}, },
{ {
GIMP_PDB_INT32, GIMP_PDB_INT32,
"offy", "offy",
"y offset between upper left corner of old and new layers: (new - old)" "y offset between upper left corner of old and new layers: (old - new)"
} }
}; };

View File

@ -234,8 +234,8 @@ gimp_layer_scale (gint32 layer_ID,
* @layer_ID: The layer. * @layer_ID: The layer.
* @new_width: New layer width. * @new_width: New layer width.
* @new_height: New layer height. * @new_height: New layer height.
* @offx: x offset between upper left corner of old and new layers: (new - old). * @offx: x offset between upper left corner of old and new layers: (old - new).
* @offy: y offset between upper left corner of old and new layers: (new - old). * @offy: y offset between upper left corner of old and new layers: (old - new).
* *
* Resize the layer to the specified extents. * Resize the layer to the specified extents.
* *

View File

@ -31,25 +31,26 @@
/* Declare local functions. */ /* Declare local functions. */
static void query (void); static void query (void);
static void run (const gchar *name, static void run (const gchar *name,
gint nparams, gint nparams,
const GimpParam *param, const GimpParam *param,
gint *nreturn_vals, gint *nreturn_vals,
GimpParam **return_vals); GimpParam **return_vals);
static gboolean colors_equal (const guchar *col1, static gboolean colors_equal (const guchar *col1,
const guchar *col2, const guchar *col2,
gint bytes); gint bytes);
static gint guess_bgcolor (GimpPixelRgn *pr, static gint guess_bgcolor (GimpPixelRgn *pr,
gint width, gint width,
gint height, gint height,
gint bytes, gint bytes,
guchar *color); guchar *color);
static void doit (GimpDrawable *drawable, static void doit (GimpDrawable *drawable,
gint32 image_id, gint32 image_id,
gboolean show_progress); gboolean show_progress,
gboolean layer_only);
GimpPlugInInfo PLUG_IN_INFO = GimpPlugInInfo PLUG_IN_INFO =
@ -89,6 +90,22 @@ query (void)
gimp_plugin_menu_register ("plug_in_autocrop", gimp_plugin_menu_register ("plug_in_autocrop",
N_("<Image>/Image/Crop")); N_("<Image>/Image/Crop"));
gimp_install_procedure ("plug_in_autocrop_layer",
"Automagically crops a layer.",
"",
"Tim Newsome",
"Tim Newsome",
"1997",
N_("_Autocrop"),
"RGB*, GRAY*, INDEXED*",
GIMP_PLUGIN,
G_N_ELEMENTS (args), 0,
args, NULL);
gimp_plugin_menu_register ("plug_in_autocrop_layer",
N_("<Image>/Layer/Crop"));
} }
static void static void
@ -133,7 +150,8 @@ run (const gchar *name,
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width() + 1)); gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width() + 1));
doit (drawable, image_id, interactive); doit (drawable, image_id, interactive,
! strcmp (name, "plug_in_autocrop_layer"));
if (interactive) if (interactive)
gimp_displays_flush (); gimp_displays_flush ();
@ -151,7 +169,8 @@ run (const gchar *name,
static void static void
doit (GimpDrawable *drawable, doit (GimpDrawable *drawable,
gint32 image_id, gint32 image_id,
gboolean show_progress) gboolean show_progress,
gboolean layer_only)
{ {
GimpPixelRgn srcPR; GimpPixelRgn srcPR;
gint width, height; gint width, height;
@ -159,7 +178,8 @@ doit (GimpDrawable *drawable,
gint32 nx, ny, nw, nh; gint32 nx, ny, nw, nh;
guchar *buffer; guchar *buffer;
guchar color[4] = {0, 0, 0, 0}; guchar color[4] = {0, 0, 0, 0};
gint32 layer_id = 0;
width = drawable->width; width = drawable->width;
height = drawable->height; height = drawable->height;
bytes = drawable->bpp; bytes = drawable->bpp;
@ -169,6 +189,16 @@ doit (GimpDrawable *drawable,
nw = width; nw = width;
nh = height; nh = height;
if (layer_only)
{
layer_id = gimp_image_get_active_layer (image_id);
if (layer_id == -1)
{
gimp_drawable_detach (drawable);
return;
}
}
/* initialize the pixel regions */ /* initialize the pixel regions */
gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, width, height, FALSE, FALSE); gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, width, height, FALSE, FALSE);
@ -249,7 +279,12 @@ doit (GimpDrawable *drawable,
gimp_drawable_detach (drawable); gimp_drawable_detach (drawable);
if (nw != width || nh != height) if (nw != width || nh != height)
gimp_image_crop (image_id, nw, nh, nx, ny); {
if (layer_only)
gimp_layer_resize (layer_id, nw, nh, 0 - nx, 0 - ny);
else
gimp_image_crop (image_id, nw, nh, nx, ny);
}
if (show_progress) if (show_progress)
gimp_progress_update (1.00); gimp_progress_update (1.00);

View File

@ -323,7 +323,7 @@ sub layer_resize {
foreach (qw(x y)) { foreach (qw(x y)) {
push @args, { name => "off$_", type => 'int32', push @args, { name => "off$_", type => 'int32',
desc => "$_ offset between upper left corner of old and desc => "$_ offset between upper left corner of old and
new layers: (new - old)" } new layers: (old - new)" }
} }
&layer_dim_proc('resize', <<'HELP', @args); &layer_dim_proc('resize', <<'HELP', @args);