app/core/Makefile.am new files for gimp_image_crop() and

2001-07-07  Michael Natterer  <mitch@gimp.org>

	* app/core/Makefile.am
	* app/core/gimpimage-crop.[ch]: new files for gimp_image_crop()
	and gimp_image_crop_auto_shrink() (should share large portions of
	code with gimp_image_resize()).

	* app/tools/gimpcroptool.[ch]: removed here.

	* tools/pdbgen/pdb/image.pdb
	* tools/pdbgen/pdb/tools.pdb: gimp_crop --> gimp_image_crop

	* app/pdb/image_cmds.c
	* app/pdb/internal_procs.c
	* app/pdb/tools_cmds.c
	* libgimp/gimpimage_pdb.[ch]
	* libgimp/gimptools_pdb.[ch]: regenerated.

	* plug-ins/common/autocrop.c
	* plug-ins/common/gif.c
	* plug-ins/common/guillotine.c
	* plug-ins/common/zealouscrop.c
	* plug-ins/perl/examples/image_tile
	* plug-ins/script-fu/scripts/add-bevel.scm
	* plug-ins/script-fu/scripts/ripply-anim.scm
	* plug-ins/script-fu/scripts/slide.scm: changed accordingly. Some
	cleanups in the plug-ins.
This commit is contained in:
Michael Natterer 2001-07-07 14:53:42 +00:00 committed by Michael Natterer
parent 3afc602f13
commit 5693956664
26 changed files with 1357 additions and 1252 deletions

View File

@ -1,3 +1,31 @@
2001-07-07 Michael Natterer <mitch@gimp.org>
* app/core/Makefile.am
* app/core/gimpimage-crop.[ch]: new files for gimp_image_crop()
and gimp_image_crop_auto_shrink() (should share large portions of
code with gimp_image_resize()).
* app/tools/gimpcroptool.[ch]: removed here.
* tools/pdbgen/pdb/image.pdb
* tools/pdbgen/pdb/tools.pdb: gimp_crop --> gimp_image_crop
* app/pdb/image_cmds.c
* app/pdb/internal_procs.c
* app/pdb/tools_cmds.c
* libgimp/gimpimage_pdb.[ch]
* libgimp/gimptools_pdb.[ch]: regenerated.
* plug-ins/common/autocrop.c
* plug-ins/common/gif.c
* plug-ins/common/guillotine.c
* plug-ins/common/zealouscrop.c
* plug-ins/perl/examples/image_tile
* plug-ins/script-fu/scripts/add-bevel.scm
* plug-ins/script-fu/scripts/ripply-anim.scm
* plug-ins/script-fu/scripts/slide.scm: changed accordingly. Some
cleanups in the plug-ins.
2001-07-07 Michael Natterer <mitch@gimp.org>
* app/Makefile.am

View File

@ -54,6 +54,8 @@ libappcore_a_SOURCES = @STRIP_BEGIN@ \
gimpimage-convert.c \
gimpimage-convert.h \
gimpimage-convert-fsdither.h \
gimpimage-crop.c \
gimpimage-crop.h \
gimpimage-duplicate.c \
gimpimage-duplicate.h \
gimpimage-mask.c \

543
app/core/gimpimage-crop.c Normal file
View File

@ -0,0 +1,543 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 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.
*/
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "core-types.h"
#include "base/pixel-region.h"
#include "gimpchannel.h"
#include "gimpdrawable.h"
#include "gimpimage.h"
#include "gimpimage-crop.h"
#include "gimpimage-mask.h"
#include "gimplayer.h"
#include "gimplist.h"
#include "app_procs.h"
#include "floating_sel.h"
#include "undo.h"
typedef enum
{
AUTO_CROP_NOTHING = 0,
AUTO_CROP_ALPHA = 1,
AUTO_CROP_COLOR = 2
} AutoCropType;
typedef guchar * (* GetColorFunc) (GtkObject *crop_object,
gint ,
gint );
typedef AutoCropType (* ColorsEqualFunc) (guchar *,
guchar *,
gint );
/* local function prototypes */
static void gimp_image_crop_adjust_guides (GimpImage *gimage,
gint x1,
gint y1,
gint x2,
gint y2);
static AutoCropType gimp_image_crop_guess_bgcolor (GtkObject *get_color_obj,
GetColorFunc get_color_func,
gint bytes,
gboolean has_alpha,
guchar *color,
gint x1,
gint x2,
gint y1,
gint y2);
static gint gimp_image_crop_colors_equal (guchar *col1,
guchar *col2,
gint bytes);
static gint gimp_image_crop_colors_alpha (guchar *col1,
guchar *col2,
gint bytes);
/* public functions */
void
gimp_image_crop (GimpImage *gimage,
gint x1,
gint y1,
gint x2,
gint y2,
gboolean active_layer_only,
gboolean crop_layers)
{
GimpLayer *layer;
GimpLayer *floating_layer;
GimpChannel *channel;
GList *guide_list_ptr;
GList *list;
gint width, height;
gint lx1, ly1, lx2, ly2;
gint off_x, off_y;
gint doff_x, doff_y;
g_return_if_fail (gimage != NULL);
g_return_if_fail (GIMP_IS_IMAGE (gimage));
width = x2 - x1;
height = y2 - y1;
/* Make sure new width and height are non-zero */
if (width && height)
{
gimp_set_busy ();
if (active_layer_only)
{
undo_push_group_start (gimage, LAYER_RESIZE_UNDO);
layer = gimp_image_get_active_layer (gimage);
if (gimp_layer_is_floating_sel (layer))
floating_sel_relax (layer, TRUE);
gimp_drawable_offsets (GIMP_DRAWABLE (layer), &doff_x, &doff_y);
off_x = (doff_x - x1);
off_y = (doff_y - y1);
gimp_layer_resize (layer, width, height, off_x, off_y);
if (gimp_layer_is_floating_sel (layer))
floating_sel_rigor (layer, TRUE);
undo_push_group_end (gimage);
}
else
{
floating_layer = gimp_image_floating_sel (gimage);
undo_push_group_start (gimage, CROP_UNDO);
/* relax the floating layer */
if (floating_layer)
floating_sel_relax (floating_layer, TRUE);
/* Push the image size to the stack */
undo_push_gimage_mod (gimage);
/* Set the new width and height */
gimage->width = width;
gimage->height = height;
/* Resize all channels */
for (list = GIMP_LIST (gimage->channels)->list;
list;
list = g_list_next (list))
{
channel = (GimpChannel *) list->data;
gimp_channel_resize (channel, width, height, -x1, -y1);
}
/* Don't forget the selection mask! */
gimp_channel_resize (gimage->selection_mask, width, height, -x1, -y1);
gimage_mask_invalidate (gimage);
/* crop all layers */
list = GIMP_LIST (gimage->layers)->list;
while (list)
{
GList *next;
layer = (GimpLayer *) list->data;
next = g_list_next (list);
gimp_layer_translate (layer, -x1, -y1);
gimp_drawable_offsets (GIMP_DRAWABLE (layer), &off_x, &off_y);
if (crop_layers)
{
gimp_drawable_offsets (GIMP_DRAWABLE (layer), &off_x, &off_y);
lx1 = CLAMP (off_x, 0, gimage->width);
ly1 = CLAMP (off_y, 0, gimage->height);
lx2 = CLAMP ((gimp_drawable_width (GIMP_DRAWABLE (layer)) + off_x),
0, gimage->width);
ly2 = CLAMP ((gimp_drawable_height (GIMP_DRAWABLE (layer)) + off_y),
0, gimage->height);
width = lx2 - lx1;
height = ly2 - ly1;
if (width && height)
gimp_layer_resize (layer, width, height,
-(lx1 - off_x),
-(ly1 - off_y));
else
gimp_image_remove_layer (gimage, layer);
}
list = next;
}
/* Make sure the projection matches the gimage size */
gimp_image_projection_realloc (gimage);
/* rigor the floating layer */
if (floating_layer)
floating_sel_rigor (floating_layer, TRUE);
guide_list_ptr = gimage->guides;
while ( guide_list_ptr != NULL)
{
undo_push_guide (gimage, (GimpGuide *) guide_list_ptr->data);
guide_list_ptr = guide_list_ptr->next;
}
undo_push_group_end (gimage);
/* Adjust any guides we might have laying about */
gimp_image_crop_adjust_guides (gimage, x1, y1, x2, y2);
}
gimp_viewable_size_changed (GIMP_VIEWABLE (gimage));
gimp_unset_busy ();
}
}
gboolean
gimp_image_crop_auto_shrink (GimpImage *gimage,
gint x1,
gint y1,
gint x2,
gint y2,
gboolean active_drawable_only,
gint *shrunk_x1,
gint *shrunk_y1,
gint *shrunk_x2,
gint *shrunk_y2)
{
GimpDrawable *active_drawable = NULL;
GetColorFunc get_color_func;
ColorsEqualFunc colors_equal_func;
GtkObject *get_color_obj;
guchar bgcolor[MAX_CHANNELS] = { 0, 0, 0, 0 };
gboolean has_alpha;
PixelRegion PR;
guchar *buffer = NULL;
gint width, height;
gint bytes;
gint x, y, abort;
gboolean retval = FALSE;
g_return_val_if_fail (gimage != NULL, FALSE);
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
g_return_val_if_fail (shrunk_x1 != NULL, FALSE);
g_return_val_if_fail (shrunk_y1 != NULL, FALSE);
g_return_val_if_fail (shrunk_x2 != NULL, FALSE);
g_return_val_if_fail (shrunk_y2 != NULL, FALSE);
gimp_set_busy ();
/* You should always keep in mind that crop->tx2 and crop->ty2 are the NOT the
coordinates of the bottomright corner of the area to be cropped. They point
at the pixel located one to the right and one to the bottom.
*/
if (active_drawable_only)
{
active_drawable = gimp_image_active_drawable (gimage);
if (! active_drawable)
goto FINISH;
bytes = gimp_drawable_bytes (GIMP_DRAWABLE (active_drawable));
has_alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (active_drawable));
get_color_obj = GTK_OBJECT (active_drawable);
get_color_func = (GetColorFunc) gimp_drawable_get_color_at;
}
else
{
has_alpha = TRUE;
bytes = gimp_image_composite_bytes (gimage);
get_color_obj = GTK_OBJECT (gimage);
get_color_func = (GetColorFunc) gimp_image_get_color_at;
}
switch (gimp_image_crop_guess_bgcolor (get_color_obj, get_color_func,
bytes, has_alpha, bgcolor,
x1, x2-1, y1, y2-1))
{
case AUTO_CROP_ALPHA:
colors_equal_func = (ColorsEqualFunc) gimp_image_crop_colors_alpha;
break;
case AUTO_CROP_COLOR:
colors_equal_func = (ColorsEqualFunc) gimp_image_crop_colors_equal;
break;
default:
goto FINISH;
break;
}
width = x2 - x1;
height = y2 - y1;
if (active_drawable_only)
pixel_region_init (&PR, gimp_drawable_data (active_drawable),
x1, y1, width, height, FALSE);
else
pixel_region_init (&PR, gimp_image_composite (gimage),
x1, y1, width, height, FALSE);
/* The following could be optimized further by processing
* the smaller side first instead of defaulting to width --Sven
*/
buffer = g_malloc ((width > height ? width : height) * bytes);
/* Check how many of the top lines are uniform/transparent. */
abort = FALSE;
for (y = y1; y < y2 && !abort; y++)
{
pixel_region_get_row (&PR, x1, y, width, buffer, 1);
for (x = 0; x < width && !abort; x++)
abort = !(colors_equal_func) (bgcolor, buffer + x * bytes, bytes);
}
if (y == y2 && !abort)
goto FINISH;
y1 = y - 1;
/* Check how many of the bottom lines are uniform/transparent. */
abort = FALSE;
for (y = y2; y > y1 && !abort; y--)
{
pixel_region_get_row (&PR, x1, y-1 , width, buffer, 1);
for (x = 0; x < width && !abort; x++)
abort = !(colors_equal_func) (bgcolor, buffer + x * bytes, bytes);
}
y2 = y + 1;
/* compute a new height for the next operations */
height = y2 - y1;
/* Check how many of the left lines are uniform/transparent. */
abort = FALSE;
for (x = x1; x < x2 && !abort; x++)
{
pixel_region_get_col (&PR, x, y1, height, buffer, 1);
for (y = 0; y < height && !abort; y++)
abort = !(colors_equal_func) (bgcolor, buffer + y * bytes, bytes);
}
x1 = x - 1;
/* Check how many of the right lines are uniform/transparent. */
abort = FALSE;
for (x = x2; x > x1 && !abort; x--)
{
pixel_region_get_col (&PR, x-1, y1, height, buffer, 1);
for (y = 0; y < height && !abort; y++)
abort = !(colors_equal_func) (bgcolor, buffer + y * bytes, bytes);
}
x2 = x + 1;
*shrunk_x1 = x1;
*shrunk_y1 = y1;
*shrunk_x2 = x2;
*shrunk_y2 = y2;
retval = TRUE;
FINISH:
g_free (buffer);
gimp_unset_busy ();
return retval;
}
/* private functions */
static void
gimp_image_crop_adjust_guides (GimpImage *gimage,
gint x1,
gint y1,
gint x2,
gint y2)
{
GList *glist;
GimpGuide *guide;
gboolean remove_guide;
for (glist = gimage->guides; glist; glist = g_list_next (glist))
{
guide = (GimpGuide *) glist->data;
remove_guide = FALSE;
switch (guide->orientation)
{
case ORIENTATION_HORIZONTAL:
if ((guide->position < y1) || (guide->position > y2))
remove_guide = TRUE;
break;
case ORIENTATION_VERTICAL:
if ((guide->position < x1) || (guide->position > x2))
remove_guide = TRUE;
break;
default:
break;
}
if (remove_guide)
{
guide->position = -1;
guide = NULL;
}
else
{
if (guide->orientation == ORIENTATION_HORIZONTAL)
{
guide->position -= y1 ;
}
else
{
guide->position -= x1;
}
}
}
}
static AutoCropType
gimp_image_crop_guess_bgcolor (GtkObject *get_color_obj,
GetColorFunc get_color_func,
gint bytes,
gboolean has_alpha,
guchar *color,
gint x1,
gint x2,
gint y1,
gint y2)
{
guchar *tl = NULL;
guchar *tr = NULL;
guchar *bl = NULL;
guchar *br = NULL;
gint i, alpha;
for (i = 0; i < bytes; i++)
color[i] = 0;
/* First check if there's transparency to crop. If not, guess the
* background-color to see if at least 2 corners are equal.
*/
if (!(tl = (*get_color_func) (get_color_obj, x1, y1)))
goto ERROR;
if (!(tr = (*get_color_func) (get_color_obj, x1, y2)))
goto ERROR;
if (!(bl = (*get_color_func) (get_color_obj, x2, y1)))
goto ERROR;
if (!(br = (*get_color_func) (get_color_obj, x2, y2)))
goto ERROR;
if (has_alpha)
{
alpha = bytes - 1;
if ((tl[alpha] == 0 && tr[alpha] == 0) ||
(tl[alpha] == 0 && bl[alpha] == 0) ||
(tr[alpha] == 0 && br[alpha] == 0) ||
(bl[alpha] == 0 && br[alpha] == 0))
{
g_free (tl);
g_free (tr);
g_free (bl);
g_free (br);
return AUTO_CROP_ALPHA;
}
}
if (gimp_image_crop_colors_equal (tl, tr, bytes) ||
gimp_image_crop_colors_equal (tl, bl, bytes))
{
memcpy (color, tl, bytes);
}
else if (gimp_image_crop_colors_equal (br, bl, bytes) ||
gimp_image_crop_colors_equal (br, tr, bytes))
{
memcpy (color, br, bytes);
}
else
{
goto ERROR;
}
g_free (tl);
g_free (tr);
g_free (bl);
g_free (br);
return AUTO_CROP_COLOR;
ERROR:
g_free (tl);
g_free (tr);
g_free (bl);
g_free (br);
return AUTO_CROP_NOTHING;
}
static int
gimp_image_crop_colors_equal (guchar *col1,
guchar *col2,
gint bytes)
{
gboolean equal = TRUE;
gint b;
for (b = 0; b < bytes; b++)
{
if (col1[b] != col2[b])
{
equal = FALSE;
break;
}
}
return equal;
}
static gboolean
gimp_image_crop_colors_alpha (guchar *dummy,
guchar *col,
gint bytes)
{
if (col[bytes-1] == 0)
return TRUE;
else
return FALSE;
}

43
app/core/gimpimage-crop.h Normal file
View File

@ -0,0 +1,43 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 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.
*/
#ifndef __GIMP_IMAGE_CROP_H__
#define __GIMP_IMAGE_CROP_H__
void gimp_image_crop (GimpImage *gimage,
gint x1,
gint y1,
gint x2,
gint y2,
gboolean active_layer_only,
gboolean crop_layers);
gboolean gimp_image_crop_auto_shrink (GimpImage *gimage,
gint x1,
gint y1,
gint x2,
gint y2,
gboolean active_drawable_only,
gint *shrunk_x1,
gint *shrunk_y1,
gint *shrunk_x2,
gint *shrunk_y2);
#endif /* __GIMP_IMAGE_CROP_H__ */

View File

@ -35,6 +35,7 @@
#include "core/gimp.h"
#include "core/gimpchannel.h"
#include "core/gimpcontainer.h"
#include "core/gimpimage-crop.h"
#include "core/gimpimage-duplicate.h"
#include "core/gimpimage.h"
#include "core/gimplayer.h"
@ -51,6 +52,7 @@ static ProcRecord image_list_proc;
static ProcRecord image_new_proc;
static ProcRecord image_resize_proc;
static ProcRecord image_scale_proc;
static ProcRecord image_crop_proc;
static ProcRecord image_delete_proc;
static ProcRecord image_free_shadow_proc;
static ProcRecord image_get_layers_proc;
@ -115,6 +117,7 @@ register_image_procs (Gimp *gimp)
procedural_db_register (gimp, &image_new_proc);
procedural_db_register (gimp, &image_resize_proc);
procedural_db_register (gimp, &image_scale_proc);
procedural_db_register (gimp, &image_crop_proc);
procedural_db_register (gimp, &image_delete_proc);
procedural_db_register (gimp, &image_free_shadow_proc);
procedural_db_register (gimp, &image_get_layers_proc);
@ -465,6 +468,96 @@ static ProcRecord image_scale_proc =
{ { image_scale_invoker } }
};
static Argument *
image_crop_invoker (Gimp *gimp,
Argument *args)
{
gboolean success = TRUE;
GimpImage *gimage;
gint32 new_width;
gint32 new_height;
gint32 offx;
gint32 offy;
gimage = gimp_image_get_by_ID (args[0].value.pdb_int);
if (gimage == NULL)
success = FALSE;
new_width = args[1].value.pdb_int;
if (new_width <= 0)
success = FALSE;
new_height = args[2].value.pdb_int;
if (new_height <= 0)
success = FALSE;
offx = args[3].value.pdb_int;
if (offx < 0)
success = FALSE;
offy = args[4].value.pdb_int;
if (offy < 0)
success = FALSE;
if (success)
{
if (new_width > gimage->width || new_height > gimage->height ||
offx > (gimage->width - new_width) ||
offy > (gimage->height - new_height))
success = FALSE;
else
gimp_image_crop (gimage, offx, offy, offx + new_width, offy + new_height,
FALSE, TRUE);
}
return procedural_db_return_args (&image_crop_proc, success);
}
static ProcArg image_crop_inargs[] =
{
{
GIMP_PDB_IMAGE,
"image",
"The image"
},
{
GIMP_PDB_INT32,
"new_width",
"New image width: (0 < new_width <= width)"
},
{
GIMP_PDB_INT32,
"new_height",
"New image height: (0 < new_height <= height)"
},
{
GIMP_PDB_INT32,
"offx",
"x offset: (0 <= offx <= (width - new_width))"
},
{
GIMP_PDB_INT32,
"offy",
"y offset: (0 <= offy <= (height - new_height))"
}
};
static ProcRecord image_crop_proc =
{
"gimp_image_crop",
"Crop the image to the specified extents.",
"This procedure crops the image so that it's new width and height are equal to the supplied parameters. Offsets are also provided which describe the position of the previous image's content. All channels and layers within the image are cropped to the new image extents; this includes the image selection mask. If any parameters are out of range, an error is returned.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
GIMP_INTERNAL,
5,
image_crop_inargs,
0,
NULL,
{ { image_crop_invoker } }
};
static Argument *
image_delete_invoker (Gimp *gimp,
Argument *args)

View File

@ -115,43 +115,43 @@ internal_procs_init (Gimp *gimp)
app_init_update_status (NULL, _("Image"), 0.338);
register_image_procs (gimp);
app_init_update_status (NULL, _("Layer"), 0.523);
app_init_update_status (NULL, _("Layer"), 0.526);
register_layer_procs (gimp);
app_init_update_status (NULL, _("Interface"), 0.618);
app_init_update_status (NULL, _("Interface"), 0.622);
register_message_procs (gimp);
app_init_update_status (NULL, _("Miscellaneous"), 0.628);
app_init_update_status (NULL, _("Miscellaneous"), 0.631);
register_misc_procs (gimp);
app_init_update_status (NULL, _("Palette"), 0.634);
app_init_update_status (NULL, _("Palette"), 0.637);
register_palette_procs (gimp);
app_init_update_status (NULL, _("Parasite procedures"), 0.655);
app_init_update_status (NULL, _("Parasite procedures"), 0.658);
register_parasite_procs (gimp);
app_init_update_status (NULL, _("Paths"), 0.692);
app_init_update_status (NULL, _("Paths"), 0.695);
register_paths_procs (gimp);
app_init_update_status (NULL, _("Pattern UI"), 0.732);
app_init_update_status (NULL, _("Pattern UI"), 0.735);
register_pattern_select_procs (gimp);
app_init_update_status (NULL, _("Patterns"), 0.742);
app_init_update_status (NULL, _("Patterns"), 0.745);
register_patterns_procs (gimp);
app_init_update_status (NULL, _("Plug-in"), 0.754);
app_init_update_status (NULL, _("Plug-in"), 0.757);
register_plug_in_procs (gimp);
app_init_update_status (NULL, _("Procedural database"), 0.772);
app_init_update_status (NULL, _("Procedural database"), 0.775);
register_procedural_db_procs (gimp);
app_init_update_status (NULL, _("Image mask"), 0.797);
app_init_update_status (NULL, _("Image mask"), 0.8);
register_selection_procs (gimp);
app_init_update_status (NULL, _("Text procedures"), 0.852);
app_init_update_status (NULL, _("Text procedures"), 0.855);
register_text_tool_procs (gimp);
app_init_update_status (NULL, _("Tool procedures"), 0.865);
app_init_update_status (NULL, _("Tool procedures"), 0.868);
register_tools_procs (gimp);
app_init_update_status (NULL, _("Undo"), 0.957);

View File

@ -42,7 +42,6 @@
#include "tools/gimpclonetool.h"
#include "tools/gimpcolorpickertool.h"
#include "tools/gimpconvolvetool.h"
#include "tools/gimpcroptool.h"
#include "tools/gimpdodgeburntool.h"
#include "tools/gimpellipseselecttool.h"
#include "tools/gimperasertool.h"
@ -73,7 +72,6 @@ static ProcRecord clone_default_proc;
static ProcRecord color_picker_proc;
static ProcRecord convolve_proc;
static ProcRecord convolve_default_proc;
static ProcRecord crop_proc;
static ProcRecord dodgeburn_proc;
static ProcRecord dodgeburn_default_proc;
static ProcRecord ellipse_select_proc;
@ -107,7 +105,6 @@ register_tools_procs (Gimp *gimp)
procedural_db_register (gimp, &color_picker_proc);
procedural_db_register (gimp, &convolve_proc);
procedural_db_register (gimp, &convolve_default_proc);
procedural_db_register (gimp, &crop_proc);
procedural_db_register (gimp, &dodgeburn_proc);
procedural_db_register (gimp, &dodgeburn_default_proc);
procedural_db_register (gimp, &ellipse_select_proc);
@ -1091,96 +1088,6 @@ static ProcRecord convolve_default_proc =
{ { convolve_default_invoker } }
};
static Argument *
crop_invoker (Gimp *gimp,
Argument *args)
{
gboolean success = TRUE;
GimpImage *gimage;
gint32 new_width;
gint32 new_height;
gint32 offx;
gint32 offy;
gimage = gimp_image_get_by_ID (args[0].value.pdb_int);
if (gimage == NULL)
success = FALSE;
new_width = args[1].value.pdb_int;
if (new_width <= 0)
success = FALSE;
new_height = args[2].value.pdb_int;
if (new_height <= 0)
success = FALSE;
offx = args[3].value.pdb_int;
if (offx < 0)
success = FALSE;
offy = args[4].value.pdb_int;
if (offy < 0)
success = FALSE;
if (success)
{
if (new_width > gimage->width || new_height > gimage->height ||
offx > (gimage->width - new_width) ||
offy > (gimage->height - new_height))
success = FALSE;
else
crop_image (gimage, offx, offy, offx + new_width, offy + new_height,
FALSE, TRUE);
}
return procedural_db_return_args (&crop_proc, success);
}
static ProcArg crop_inargs[] =
{
{
GIMP_PDB_IMAGE,
"image",
"The image"
},
{
GIMP_PDB_INT32,
"new_width",
"New image width: (0 < new_width <= width)"
},
{
GIMP_PDB_INT32,
"new_height",
"New image height: (0 < new_height <= height)"
},
{
GIMP_PDB_INT32,
"offx",
"x offset: (0 <= offx <= (width - new_width))"
},
{
GIMP_PDB_INT32,
"offy",
"y offset: (0 <= offy <= (height - new_height))"
}
};
static ProcRecord crop_proc =
{
"gimp_crop",
"Crop the image to the specified extents.",
"This procedure crops the image so that it's new width and height are equal to the supplied parameters. Offsets are also provided which describe the position of the previous image's content. All channels and layers within the image are cropped to the new image extents; this includes the image selection mask. If any parameters are out of range, an error is returned.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
GIMP_INTERNAL,
5,
crop_inargs,
0,
NULL,
{ { crop_invoker } }
};
static Argument *
dodgeburn_invoker (Gimp *gimp,
Argument *args)

File diff suppressed because it is too large Load Diff

View File

@ -73,14 +73,4 @@ void gimp_crop_tool_register (Gimp *gimp);
GtkType gimp_crop_tool_get_type (void);
/* Keep around for the PDB, temporarily */
void crop_image (GimpImage *gimage,
gint x1,
gint y1,
gint x2,
gint y2,
gboolean layer_only,
gboolean crop_layers);
#endif /* __GIMP_CROP_TOOL_H__ */

View File

@ -193,6 +193,52 @@ gimp_image_scale (gint32 image_ID,
return success;
}
/**
* gimp_image_crop:
* @image_ID: The image.
* @new_width: New image width: (0 < new_width <= width).
* @new_height: New image height: (0 < new_height <= height).
* @offx: x offset: (0 <= offx <= (width - new_width)).
* @offy: y offset: (0 <= offy <= (height - new_height)).
*
* Crop the image to the specified extents.
*
* This procedure crops the image so that it's new width and height are
* equal to the supplied parameters. Offsets are also provided which
* describe the position of the previous image's content. All channels
* and layers within the image are cropped to the new image extents;
* this includes the image selection mask. If any parameters are out of
* range, an error is returned.
*
* Returns: TRUE on success.
*/
gboolean
gimp_image_crop (gint32 image_ID,
gint new_width,
gint new_height,
gint offx,
gint offy)
{
GimpParam *return_vals;
gint nreturn_vals;
gboolean success = TRUE;
return_vals = gimp_run_procedure ("gimp_image_crop",
&nreturn_vals,
GIMP_PDB_IMAGE, image_ID,
GIMP_PDB_INT32, new_width,
GIMP_PDB_INT32, new_height,
GIMP_PDB_INT32, offx,
GIMP_PDB_INT32, offy,
GIMP_PDB_END);
success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
gimp_destroy_params (return_vals, nreturn_vals);
return success;
}
/**
* gimp_image_delete:
* @image_ID: The image.

View File

@ -43,6 +43,11 @@ gboolean gimp_image_resize (gint32 image
gboolean gimp_image_scale (gint32 image_ID,
gint new_width,
gint new_height);
gboolean gimp_image_crop (gint32 image_ID,
gint new_width,
gint new_height,
gint offx,
gint offy);
gboolean gimp_image_delete (gint32 image_ID);
gboolean gimp_image_free_shadow (gint32 image_ID);
gint* gimp_image_get_layers (gint32 image_ID,

View File

@ -547,52 +547,6 @@ gimp_convolve_default (gint32 drawable_ID,
return success;
}
/**
* gimp_crop:
* @image_ID: The image.
* @new_width: New image width: (0 < new_width <= width).
* @new_height: New image height: (0 < new_height <= height).
* @offx: x offset: (0 <= offx <= (width - new_width)).
* @offy: y offset: (0 <= offy <= (height - new_height)).
*
* Crop the image to the specified extents.
*
* This procedure crops the image so that it's new width and height are
* equal to the supplied parameters. Offsets are also provided which
* describe the position of the previous image's content. All channels
* and layers within the image are cropped to the new image extents;
* this includes the image selection mask. If any parameters are out of
* range, an error is returned.
*
* Returns: TRUE on success.
*/
gboolean
gimp_crop (gint32 image_ID,
gint new_width,
gint new_height,
gint offx,
gint offy)
{
GimpParam *return_vals;
gint nreturn_vals;
gboolean success = TRUE;
return_vals = gimp_run_procedure ("gimp_crop",
&nreturn_vals,
GIMP_PDB_IMAGE, image_ID,
GIMP_PDB_INT32, new_width,
GIMP_PDB_INT32, new_height,
GIMP_PDB_INT32, offx,
GIMP_PDB_INT32, offy,
GIMP_PDB_END);
success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
gimp_destroy_params (return_vals, nreturn_vals);
return success;
}
/**
* gimp_dodgeburn:
* @drawable_ID: The affected drawable.

View File

@ -95,11 +95,6 @@ gboolean gimp_convolve (gint32 drawable_ID,
gboolean gimp_convolve_default (gint32 drawable_ID,
gint num_strokes,
gdouble *strokes);
gboolean gimp_crop (gint32 image_ID,
gint new_width,
gint new_height,
gint offx,
gint offy);
gboolean gimp_dodgeburn (gint32 drawable_ID,
gdouble exposure,
GimpDodgeBurnType dodgeburn_type,

View File

@ -22,25 +22,26 @@
/* Declare local functions. */
static void query (void);
static void run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
static void query (void);
static void run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
static gint colors_equal (guchar *col1,
guchar *col2,
gint bytes);
static gint colors_equal (guchar *col1,
guchar *col2,
gint bytes);
static gint guess_bgcolor (GimpPixelRgn *pr,
gint width,
gint height,
gint bytes,
guchar *color);
gint width,
gint height,
gint bytes,
guchar *color);
static void doit (GimpDrawable *drawable,
gint32 image_id,
gboolean show_progress);
gint32 image_id,
gboolean show_progress);
GimpPlugInInfo PLUG_IN_INFO =
{
@ -52,6 +53,7 @@ GimpPlugInInfo PLUG_IN_INFO =
static gint bytes;
MAIN ()
static void
@ -79,18 +81,18 @@ query (void)
}
static void
run (gchar *name,
gint n_params,
run (gchar *name,
gint n_params,
GimpParam *param,
gint *nreturn_vals,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[1];
GimpDrawable *drawable;
GimpRunModeType run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_id;
gboolean interactive;
static GimpParam values[1];
GimpDrawable *drawable;
GimpRunModeType run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_id;
gboolean interactive;
*nreturn_vals = 1;
*return_vals = values;
@ -140,16 +142,16 @@ doit (GimpDrawable *drawable,
gint32 image_id,
gboolean show_progress)
{
GimpPixelRgn srcPR;
gint width, height;
gint x, y, abort;
gint32 nx, ny, nw, nh;
guchar *buffer;
guchar color[4] = {0, 0, 0, 0};
GimpPixelRgn srcPR;
gint width, height;
gint x, y, abort;
gint32 nx, ny, nw, nh;
guchar *buffer;
guchar color[4] = {0, 0, 0, 0};
width = drawable->width;
width = drawable->width;
height = drawable->height;
bytes = drawable->bpp;
bytes = drawable->bpp;
nx = 0;
ny = 0;
@ -236,7 +238,7 @@ doit (GimpDrawable *drawable,
gimp_drawable_detach (drawable);
if (nw != width || nh != height)
gimp_crop (image_id, nw, nh, nx, ny);
gimp_image_crop (image_id, nw, nh, nx, ny);
if (show_progress)
gimp_progress_update (1.00);
@ -244,10 +246,10 @@ doit (GimpDrawable *drawable,
static gint
guess_bgcolor (GimpPixelRgn *pr,
gint width,
gint height,
gint bytes,
guchar *color)
gint width,
gint height,
gint bytes,
guchar *color)
{
guchar tl[4], tr[4], bl[4], br[4];

View File

@ -311,25 +311,28 @@ typedef struct
/* Declare some local functions.
*/
static void query (void);
static void run (gchar *name,
gint nparams,
static void run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
gint *nreturn_vals,
GimpParam **return_vals);
static gint save_image (gchar *filename,
gint32 image_ID,
gint32 drawable_ID,
gint32 orig_image_ID);
static gint save_image (gchar *filename,
gint32 image_ID,
gint32 drawable_ID,
gint32 orig_image_ID);
static gboolean boundscheck (gint32 image_ID);
static gboolean boundscheck (gint32 image_ID);
static gboolean badbounds_dialog (void);
static void cropok_callback (GtkWidget *widget, gpointer data);
static void cropok_callback (GtkWidget *widget,
gpointer data);
static gint save_dialog (gint32 image_ID);
static gint save_dialog (gint32 image_ID);
static void save_ok_callback (GtkWidget *widget, gpointer data);
static void comment_entry_callback (GtkWidget *widget, gpointer data);
static void save_ok_callback (GtkWidget *widget,
gpointer data);
static void comment_entry_callback (GtkWidget *widget,
gpointer data);
static gboolean comment_was_edited = FALSE;
@ -410,17 +413,17 @@ query (void)
}
static void
run (gchar *name,
gint nparams,
run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[2];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_ID;
gint32 drawable_ID;
gint32 orig_image_ID;
static GimpParam values[2];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_ID;
gint32 drawable_ID;
gint32 orig_image_ID;
GimpExportReturnType export = GIMP_EXPORT_CANCEL;
run_mode = param[0].data.d_int32;
@ -781,10 +784,10 @@ static gboolean
boundscheck (gint32 image_ID)
{
GimpDrawable *drawable;
gint32 *layers;
gint nlayers;
gint i;
gint offset_x, offset_y;
gint32 *layers;
gint nlayers;
gint i;
gint offset_x, offset_y;
/* get a list of layers for this image_ID */
layers = gimp_image_get_layers (image_ID, &nlayers);
@ -793,7 +796,7 @@ boundscheck (gint32 image_ID)
/*** Iterate through the layers to make sure they're all ***/
/*** within the bounds of the image ***/
for (i=0;i<nlayers;i++)
for (i = 0; i < nlayers; i++)
{
drawable = gimp_drawable_get (layers[i]);
gimp_drawable_offsets (layers[i], &offset_x, &offset_y);
@ -812,9 +815,10 @@ boundscheck (gint32 image_ID)
* the user and they said yes. */
if ((run_mode == GIMP_RUN_NONINTERACTIVE) || badbounds_dialog ())
{
gimp_crop (image_ID,
gimp_image_width (image_ID), gimp_image_height (image_ID),
0, 0);
gimp_image_crop (image_ID,
gimp_image_width (image_ID),
gimp_image_height (image_ID),
0, 0);
return TRUE;
}
else
@ -823,7 +827,9 @@ boundscheck (gint32 image_ID)
}
}
else
gimp_drawable_detach(drawable);
{
gimp_drawable_detach (drawable);
}
}
g_free (layers);

View File

@ -37,14 +37,14 @@
/* Declare local functions.
*/
static void query (void);
static void run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
static void query (void);
static void run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
static void guillotine (gint32 image_ID);
static void guillotine (gint32 image_ID);
GimpPlugInInfo PLUG_IN_INFO =
@ -63,14 +63,16 @@ query (void)
{
static GimpParamDef args[] =
{
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
{ GIMP_PDB_IMAGE, "image", "Input image" },
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable (unused)" }
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
{ GIMP_PDB_IMAGE, "image", "Input image" },
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable (unused)" }
};
static gint nargs = sizeof (args) / sizeof (args[0]);
gimp_install_procedure ("plug_in_guillotine",
"Slice up the image into subimages, cutting along the image's Guides. Fooey to you and your broccoli, Pokey.",
"Slice up the image into subimages, cutting along "
"the image's Guides. Fooey to you and your "
"broccoli, Pokey.",
"This function takes an image and blah blah. Hooray!",
"Adam D. Moss (adam@foxbox.org)",
"Adam D. Moss (adam@foxbox.org)",
@ -83,14 +85,14 @@ query (void)
}
static void
run (gchar *name,
gint nparams,
run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[1];
gint32 image_ID;
static GimpParam values[1];
gint32 image_ID;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
*nreturn_vals = 1;
@ -129,32 +131,36 @@ unexciting (const void *a,
static void
guillotine (gint32 image_ID)
{
gint num_vguides;
gint num_hguides;
gint guide_num;
gint* hguides;
gint* vguides;
gint num_vguides;
gint num_hguides;
gint guide_num;
gint *hguides;
gint *vguides;
gchar filename[1024];
gint i,x,y;
gint i, x, y;
num_vguides = 0;
num_hguides = 0;
guide_num = gimp_image_find_next_guide(image_ID, 0);
guide_num = gimp_image_find_next_guide (image_ID, 0);
/* Count the guides so we can allocate appropriate memory */
if (guide_num > 0)
{
do
{
switch (gimp_image_get_guide_orientation(image_ID, guide_num))
switch (gimp_image_get_guide_orientation (image_ID, guide_num))
{
case GIMP_VERTICAL:
num_vguides++; break;
num_vguides++;
break;
case GIMP_HORIZONTAL:
num_hguides++; break;
num_hguides++;
break;
default:
g_print ("Aie! Aie! Aie!\n");
gimp_quit ();
break;
}
guide_num = gimp_image_find_next_guide (image_ID, guide_num);
}
@ -174,38 +180,43 @@ guillotine (gint32 image_ID)
/* Allocate memory for the arrays of guide offsets, build arrays */
vguides = g_malloc ((num_vguides+2) * sizeof(gint));
hguides = g_malloc ((num_hguides+2) * sizeof(gint));
vguides = g_malloc ((num_vguides+2) * sizeof (gint));
hguides = g_malloc ((num_hguides+2) * sizeof (gint));
num_vguides = 0;
num_hguides = 0;
vguides[num_vguides++] = 0;
hguides[num_hguides++] = 0;
guide_num = gimp_image_find_next_guide(image_ID, 0);
if (guide_num>0)
{
do
{
switch (gimp_image_get_guide_orientation(image_ID, guide_num))
switch (gimp_image_get_guide_orientation (image_ID, guide_num))
{
case GIMP_VERTICAL:
vguides[num_vguides++] =
gimp_image_get_guide_position(image_ID, guide_num); break;
gimp_image_get_guide_position( image_ID, guide_num);
break;
case GIMP_HORIZONTAL:
hguides[num_hguides++] =
gimp_image_get_guide_position(image_ID, guide_num); break;
gimp_image_get_guide_position (image_ID, guide_num);
break;
default:
g_print ("Aie! Aie! Aie! Too!\n");
gimp_quit();
break;
}
guide_num = gimp_image_find_next_guide(image_ID, guide_num);
}
while (guide_num>0);
while (guide_num > 0);
}
vguides[num_vguides++] = gimp_image_width(image_ID);
hguides[num_hguides++] = gimp_image_height(image_ID);
qsort(hguides, num_hguides, sizeof(gint), &unexciting);
qsort(vguides, num_vguides, sizeof(gint), &unexciting);
vguides[num_vguides++] = gimp_image_width (image_ID);
hguides[num_hguides++] = gimp_image_height (image_ID);
qsort (hguides, num_hguides, sizeof (gint), &unexciting);
qsort (vguides, num_vguides, sizeof (gint), &unexciting);
for (i=0;i<num_vguides;i++)
g_print ("%d,",vguides[i]);
@ -217,9 +228,9 @@ guillotine (gint32 image_ID)
/* Do the actual dup'ing and cropping... this isn't a too naive a
way to do this since we got copy-on-write tiles, either. */
for (y=0; y<num_hguides-1; y++)
for (y = 0; y < num_hguides-1; y++)
{
for (x=0; x<num_vguides-1; x++)
for (x=0; x < num_vguides-1; x++)
{
gint32 new_image;
@ -241,18 +252,21 @@ guillotine (gint32 image_ID)
/* vguides[x], hguides[y],x, y); */
gimp_crop (new_image,
vguides[x+1] - vguides[x], hguides[y+1] - hguides[y],
vguides[x], hguides[y]);
gimp_image_crop (new_image,
vguides[x+1] - vguides[x],
hguides[y+1] - hguides[y],
vguides[x],
hguides[y]);
/* gimp_undo_push_group_end (new_image); */
gimp_image_undo_enable (new_image);
/* show the rough coordinates of the image in the title */
g_snprintf (filename, sizeof (filename), "%s-(%i,%i)", gimp_image_get_filename (image_ID),
g_snprintf (filename, sizeof (filename), "%s-(%i,%i)",
gimp_image_get_filename (image_ID),
x, y);
gimp_image_set_filename(new_image, filename);
gimp_image_set_filename (new_image, filename);
gimp_display_new (new_image);
}

View File

@ -21,23 +21,20 @@
#include "libgimp/stdplugins-intl.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/* Declare local functions. */
static void query (void);
static void run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
static inline gint colours_equal (guchar *col1,
guchar *col2,
gint bytes);
static void query (void);
static void run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
static inline gint colours_equal (guchar *col1,
guchar *col2,
gint bytes);
static void do_zcrop (GimpDrawable *drawable,
gint32 image_id);
static void do_zcrop (GimpDrawable *drawable,
gint32 image_id);
GimpPlugInInfo PLUG_IN_INFO =
{
@ -57,37 +54,38 @@ query (void)
{
static GimpParamDef args[] =
{
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
{ GIMP_PDB_IMAGE, "image", "Input image" },
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" }
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
{ GIMP_PDB_IMAGE, "image", "Input image" },
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" }
};
static gint nargs = sizeof (args) / sizeof (args[0]);
gimp_install_procedure("plug_in_zealouscrop",
"Automagically crops unused space from the edges and middle of a picture.",
"",
"Adam D. Moss",
"Adam D. Moss",
"1997",
N_("<Image>/Image/Transforms/Zealous Crop"),
"RGB*, GRAY*, INDEXED*",
GIMP_PLUGIN,
nargs, 0,
args, NULL);
gimp_install_procedure ("plug_in_zealouscrop",
"Automagically crops unused space from the edges "
"and middle of a picture.",
"",
"Adam D. Moss",
"Adam D. Moss",
"1997",
N_("<Image>/Image/Transforms/Zealous Crop"),
"RGB*, GRAY*, INDEXED*",
GIMP_PLUGIN,
nargs, 0,
args, NULL);
}
static void
run (gchar *name,
gint n_params,
run (gchar *name,
gint n_params,
GimpParam *param,
gint *nreturn_vals,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[1];
GimpDrawable *drawable;
GimpRunModeType run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_id;
static GimpParam values[1];
GimpDrawable *drawable;
GimpRunModeType run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_id;
INIT_I18N();
@ -125,9 +123,9 @@ run (gchar *name,
do_zcrop(drawable, image_id);
if (run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_displays_flush();
gimp_displays_flush ();
gimp_drawable_detach(drawable);
gimp_drawable_detach (drawable);
}
else
{
@ -135,31 +133,31 @@ run (gchar *name,
}
}
values[0].type = GIMP_PDB_STATUS;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
}
static void
do_zcrop (GimpDrawable *drawable,
gint32 image_id)
gint32 image_id)
{
GimpPixelRgn srcPR, destPR;
gint width, height, x, y;
guchar *buffer;
gint8 *killrows;
gint8 *killcols;
gint32 livingrows, livingcols, destrow, destcol;
gint total_area, area;
GimpPixelRgn srcPR, destPR;
gint width, height, x, y;
guchar *buffer;
gint8 *killrows;
gint8 *killcols;
gint32 livingrows, livingcols, destrow, destcol;
gint total_area, area;
width = drawable->width;
width = drawable->width;
height = drawable->height;
bytes = drawable->bpp;
bytes = drawable->bpp;
total_area = width * height * 4;
area = 0;
killrows = g_malloc (sizeof(gint8)*height);
killcols = g_malloc (sizeof(gint8)*width);
killrows = g_new (gint8, height);
killcols = g_new (gint8, width);
buffer = g_malloc ((width > height ? width : height) * bytes);
@ -226,8 +224,8 @@ do_zcrop (GimpDrawable *drawable,
{
if (!killrows[y])
{
gimp_pixel_rgn_get_row(&srcPR, buffer, 0, y, width);
gimp_pixel_rgn_set_row(&destPR, buffer, 0, destrow, width);
gimp_pixel_rgn_get_row (&srcPR, buffer, 0, y, width);
gimp_pixel_rgn_set_row (&destPR, buffer, 0, destrow, width);
destrow++;
}
@ -244,8 +242,8 @@ do_zcrop (GimpDrawable *drawable,
{
if (!killcols[x])
{
gimp_pixel_rgn_get_col(&srcPR, buffer, x, 0, height);
gimp_pixel_rgn_set_col(&destPR, buffer, destcol, 0, height);
gimp_pixel_rgn_get_col (&srcPR, buffer, x, 0, height);
gimp_pixel_rgn_set_col (&destPR, buffer, destcol, 0, height);
destcol++;
}
@ -256,30 +254,32 @@ do_zcrop (GimpDrawable *drawable,
/* printf("dc: %d, lc: %d - - - dr: %d, lr: %d\n",destcol, livingcols, destrow, livingrows);*/
g_free(buffer);
g_free (buffer);
g_free(killrows);
g_free(killcols);
g_free (killrows);
g_free (killcols);
gimp_progress_update(1.00);
gimp_progress_update (1.00);
gimp_undo_push_group_start (image_id);
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_crop (image_id, livingcols, livingrows, 0, 0);
gimp_image_crop (image_id, livingcols, livingrows, 0, 0);
gimp_undo_push_group_end (image_id);
}
static inline int colours_equal(guchar *col1, guchar *col2, int bytes)
static inline gint
colours_equal (guchar *col1,
guchar *col2,
gint bytes)
{
int b;
gint b;
for (b = 0; b < bytes; b++)
{
if (col1[b] != col2[b])
{
return (FALSE);
break;
return FALSE;
}
}

View File

@ -352,12 +352,12 @@ sub match_aspect {
my $oldheight=$height;
$height = int($width/$target_aspect);
# print "Image was $width X $oldheight, cropping to $width X $height\n";
gimp_crop($img,$width,$height,0,int(($oldheight-$height)/2));
gimp_image_crop($img,$width,$height,0,int(($oldheight-$height)/2));
} elsif ($aspect > $target_aspect) {
my $oldwidth=$width;
$width = int($target_aspect*$height);
# print "Image was $oldwidth X $height, cropping to $width X $height\n";
gimp_crop($img,$width,$height,int(($oldwidth-$width)/2),0);
gimp_image_crop($img,$width,$height,int(($oldwidth-$width)/2),0);
}
}

View File

@ -165,7 +165,7 @@
; Shave one pixel off each edge
;
(if (= bevelling-whole-image TRUE)
(gimp-crop image width height 1 1)
(gimp-image-crop image width height 1 1)
)
(if (= work-on-copy FALSE) (gimp-image-undo-disable image))

View File

@ -62,7 +62,7 @@
(while (> remaining-frames 0)
(set! dup-image (car (gimp-image-duplicate rippletiled-image)))
(gimp-image-undo-disable dup-image)
(gimp-crop dup-image width height xpos ypos)
(gimp-image-crop dup-image width height xpos ypos)
(set! layer-name (string-append "Frame "
(number->string (- num-frames remaining-frames) 10)

View File

@ -98,11 +98,11 @@
(gimp-layer-add-alpha pic-layer)
; crop, resize and eventually rotate the image
(gimp-crop image
crop-width
crop-height
(/ (- owidth crop-width) 2)
(/ (- oheight crop-height) 2))
(gimp-image-crop image
crop-width
crop-height
(/ (- owidth crop-width) 2)
(/ (- oheight crop-height) 2))
(gimp-image-resize image
width
height

View File

@ -332,6 +332,47 @@ CODE
);
}
sub image_crop {
$blurb = 'Crop the image to the specified extents.';
$help = <<'HELP';
This procedure crops the image so that it's new width and height are equal to
the supplied parameters. Offsets are also provided which describe the position
of the previous image's content. All channels and layers within the image are
cropped to the new image extents; this includes the image selection mask. If
any parameters are out of range, an error is returned.
HELP
&std_pdb_misc;
@inargs = (
&std_image_arg,
{ name => 'new_width', type => '0 < int32',
desc => 'New image width: (0 < new_width <= width)' },
{ name => 'new_height', type => '0 < int32',
desc => 'New image height: (0 < new_height <= height)' },
{ name => 'offx', type => '0 <= int32',
desc => 'x offset: (0 <= offx <= (width - new_width))' },
{ name => 'offy', type => '0 <= int32',
desc => 'y offset: (0 <= offy <= (height - new_height))' }
);
%invoke = (
headers => [ qw("core/gimpimage-crop.h") ],
code => <<'CODE'
{
if (new_width > gimage->width || new_height > gimage->height ||
offx > (gimage->width - new_width) ||
offy > (gimage->height - new_height))
success = FALSE;
else
gimp_image_crop (gimage, offx, offy, offx + new_width, offy + new_height,
FALSE, TRUE);
}
CODE
);
}
sub image_delete {
$blurb = 'Delete the specified image.';
@ -1473,7 +1514,8 @@ gimlist_cb (gpointer im,
}
CODE
unshift @procs, qw(image_list image_new image_resize image_scale image_delete
unshift @procs, qw(image_list image_new image_resize image_scale image_crop
image_delete
image_free_shadow image_get_layers image_get_channels
image_unset_active_channel image_pick_correlate_layer
image_raise_layer image_lower_layer image_raise_layer_to_top

View File

@ -495,47 +495,6 @@ CODE
);
}
sub crop {
$blurb = 'Crop the image to the specified extents.';
$help = <<'HELP';
This procedure crops the image so that it's new width and height are equal to
the supplied parameters. Offsets are also provided which describe the position
of the previous image's content. All channels and layers within the image are
cropped to the new image extents; this includes the image selection mask. If
any parameters are out of range, an error is returned.
HELP
&std_pdb_misc;
@inargs = (
&std_image_arg,
{ name => 'new_width', type => '0 < int32',
desc => 'New image width: (0 < new_width <= width)' },
{ name => 'new_height', type => '0 < int32',
desc => 'New image height: (0 < new_height <= height)' },
{ name => 'offx', type => '0 <= int32',
desc => 'x offset: (0 <= offx <= (width - new_width))' },
{ name => 'offy', type => '0 <= int32',
desc => 'y offset: (0 <= offy <= (height - new_height))' }
);
%invoke = (
headers => [ qw("tools/gimpcroptool.h") ],
code => <<'CODE'
{
if (new_width > gimage->width || new_height > gimage->height ||
offx > (gimage->width - new_width) ||
offy > (gimage->height - new_height))
success = FALSE;
else
crop_image (gimage, offx, offy, offx + new_width, offy + new_height,
FALSE, TRUE);
}
CODE
);
}
sub ellipse_select {
$blurb = 'Create an elliptical selection over the specified image.';
@ -1542,7 +1501,7 @@ sub ink {
@procs = qw(airbrush airbrush_default blend bucket_fill by_color_select
clone clone_default color_picker
convolve convolve_default crop dodgeburn dodgeburn_default
convolve convolve_default dodgeburn dodgeburn_default
ellipse_select eraser eraser_default
flip free_select fuzzy_select
paintbrush paintbrush_default

View File

@ -495,47 +495,6 @@ CODE
);
}
sub crop {
$blurb = 'Crop the image to the specified extents.';
$help = <<'HELP';
This procedure crops the image so that it's new width and height are equal to
the supplied parameters. Offsets are also provided which describe the position
of the previous image's content. All channels and layers within the image are
cropped to the new image extents; this includes the image selection mask. If
any parameters are out of range, an error is returned.
HELP
&std_pdb_misc;
@inargs = (
&std_image_arg,
{ name => 'new_width', type => '0 < int32',
desc => 'New image width: (0 < new_width <= width)' },
{ name => 'new_height', type => '0 < int32',
desc => 'New image height: (0 < new_height <= height)' },
{ name => 'offx', type => '0 <= int32',
desc => 'x offset: (0 <= offx <= (width - new_width))' },
{ name => 'offy', type => '0 <= int32',
desc => 'y offset: (0 <= offy <= (height - new_height))' }
);
%invoke = (
headers => [ qw("tools/gimpcroptool.h") ],
code => <<'CODE'
{
if (new_width > gimage->width || new_height > gimage->height ||
offx > (gimage->width - new_width) ||
offy > (gimage->height - new_height))
success = FALSE;
else
crop_image (gimage, offx, offy, offx + new_width, offy + new_height,
FALSE, TRUE);
}
CODE
);
}
sub ellipse_select {
$blurb = 'Create an elliptical selection over the specified image.';
@ -1542,7 +1501,7 @@ sub ink {
@procs = qw(airbrush airbrush_default blend bucket_fill by_color_select
clone clone_default color_picker
convolve convolve_default crop dodgeburn dodgeburn_default
convolve convolve_default dodgeburn dodgeburn_default
ellipse_select eraser eraser_default
flip free_select fuzzy_select
paintbrush paintbrush_default

View File

@ -495,47 +495,6 @@ CODE
);
}
sub crop {
$blurb = 'Crop the image to the specified extents.';
$help = <<'HELP';
This procedure crops the image so that it's new width and height are equal to
the supplied parameters. Offsets are also provided which describe the position
of the previous image's content. All channels and layers within the image are
cropped to the new image extents; this includes the image selection mask. If
any parameters are out of range, an error is returned.
HELP
&std_pdb_misc;
@inargs = (
&std_image_arg,
{ name => 'new_width', type => '0 < int32',
desc => 'New image width: (0 < new_width <= width)' },
{ name => 'new_height', type => '0 < int32',
desc => 'New image height: (0 < new_height <= height)' },
{ name => 'offx', type => '0 <= int32',
desc => 'x offset: (0 <= offx <= (width - new_width))' },
{ name => 'offy', type => '0 <= int32',
desc => 'y offset: (0 <= offy <= (height - new_height))' }
);
%invoke = (
headers => [ qw("tools/gimpcroptool.h") ],
code => <<'CODE'
{
if (new_width > gimage->width || new_height > gimage->height ||
offx > (gimage->width - new_width) ||
offy > (gimage->height - new_height))
success = FALSE;
else
crop_image (gimage, offx, offy, offx + new_width, offy + new_height,
FALSE, TRUE);
}
CODE
);
}
sub ellipse_select {
$blurb = 'Create an elliptical selection over the specified image.';
@ -1542,7 +1501,7 @@ sub ink {
@procs = qw(airbrush airbrush_default blend bucket_fill by_color_select
clone clone_default color_picker
convolve convolve_default crop dodgeburn dodgeburn_default
convolve convolve_default dodgeburn dodgeburn_default
ellipse_select eraser eraser_default
flip free_select fuzzy_select
paintbrush paintbrush_default

View File

@ -495,47 +495,6 @@ CODE
);
}
sub crop {
$blurb = 'Crop the image to the specified extents.';
$help = <<'HELP';
This procedure crops the image so that it's new width and height are equal to
the supplied parameters. Offsets are also provided which describe the position
of the previous image's content. All channels and layers within the image are
cropped to the new image extents; this includes the image selection mask. If
any parameters are out of range, an error is returned.
HELP
&std_pdb_misc;
@inargs = (
&std_image_arg,
{ name => 'new_width', type => '0 < int32',
desc => 'New image width: (0 < new_width <= width)' },
{ name => 'new_height', type => '0 < int32',
desc => 'New image height: (0 < new_height <= height)' },
{ name => 'offx', type => '0 <= int32',
desc => 'x offset: (0 <= offx <= (width - new_width))' },
{ name => 'offy', type => '0 <= int32',
desc => 'y offset: (0 <= offy <= (height - new_height))' }
);
%invoke = (
headers => [ qw("tools/gimpcroptool.h") ],
code => <<'CODE'
{
if (new_width > gimage->width || new_height > gimage->height ||
offx > (gimage->width - new_width) ||
offy > (gimage->height - new_height))
success = FALSE;
else
crop_image (gimage, offx, offy, offx + new_width, offy + new_height,
FALSE, TRUE);
}
CODE
);
}
sub ellipse_select {
$blurb = 'Create an elliptical selection over the specified image.';
@ -1542,7 +1501,7 @@ sub ink {
@procs = qw(airbrush airbrush_default blend bucket_fill by_color_select
clone clone_default color_picker
convolve convolve_default crop dodgeburn dodgeburn_default
convolve convolve_default dodgeburn dodgeburn_default
ellipse_select eraser eraser_default
flip free_select fuzzy_select
paintbrush paintbrush_default