Implement function to resize the image to contain all layers completely.

2004-09-05  Simon Budig  <simon@gimp.org>

	* app/core/gimpimage-resize.[ch]: Implement function to resize
	the image to contain all layers completely. Untabified.

	* app/actions/image-actions.c
	* app/actions/image-commands.[ch]
	* app/widgets/gimphelp-ids.h
	* menus/image-menu.xml.in: Make it available in the GUI.

	* tools/pdbgen/pdb/image.pdb: Make it available in the PDB.

	* app/pdb/image_cmds.c
	* app/pdb/internal_procs.c
	* libgimp/gimpimage_pdb.[ch]: regenerated.
This commit is contained in:
Simon Budig 2004-09-04 22:08:43 +00:00 committed by Simon Budig
parent 967bac104d
commit fe7eb34e6e
13 changed files with 291 additions and 93 deletions

View file

@ -1,3 +1,19 @@
2004-09-05 Simon Budig <simon@gimp.org>
* app/core/gimpimage-resize.[ch]: Implement function to resize
the image to contain all layers completely. Untabified.
* app/actions/image-actions.c
* app/actions/image-commands.[ch]
* app/widgets/gimphelp-ids.h
* menus/image-menu.xml.in: Make it available in the GUI.
* tools/pdbgen/pdb/image.pdb: Make it available in the PDB.
* app/pdb/image_cmds.c
* app/pdb/internal_procs.c
* libgimp/gimpimage_pdb.[ch]: regenerated.
2004-09-04 DindinX <david@dindinx.org>
* plug-ins/common/noisify.c: ported to GimpDrawablePreview.

View file

@ -72,6 +72,11 @@ static GimpActionEntry image_actions[] =
G_CALLBACK (image_resize_cmd_callback),
GIMP_HELP_IMAGE_RESIZE },
{ "image-resize-to-layers", NULL,
N_("F_it Canvas to Layers"), NULL, NULL,
G_CALLBACK (image_resize_to_layers_cmd_callback),
GIMP_HELP_IMAGE_RESIZE_TO_LAYERS },
{ "image-scale", GIMP_STOCK_SCALE,
N_("_Scale Image..."), NULL, NULL,
G_CALLBACK (image_scale_cmd_callback),
@ -233,13 +238,14 @@ image_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("image-rotate-180", gimage);
SET_SENSITIVE ("image-rotate-270", gimage);
SET_SENSITIVE ("image-resize", gimage);
SET_SENSITIVE ("image-scale", gimage);
SET_SENSITIVE ("image-crop", gimage && sel);
SET_SENSITIVE ("image-duplicate", gimage);
SET_SENSITIVE ("image-merge-layers", gimage && !fs && !aux && lp);
SET_SENSITIVE ("image-flatten", gimage && !fs && !aux && lp);
SET_SENSITIVE ("image-configure-grid", gimage);
SET_SENSITIVE ("image-resize", gimage);
SET_SENSITIVE ("image-resize-to-layers", gimage);
SET_SENSITIVE ("image-scale", gimage);
SET_SENSITIVE ("image-crop", gimage && sel);
SET_SENSITIVE ("image-duplicate", gimage);
SET_SENSITIVE ("image-merge-layers", gimage && !fs && !aux && lp);
SET_SENSITIVE ("image-flatten", gimage && !fs && !aux && lp);
SET_SENSITIVE ("image-configure-grid", gimage);
#undef SET_SENSITIVE
}

View file

@ -217,6 +217,28 @@ image_resize_cmd_callback (GtkAction *action,
gtk_widget_show (options->dialog->shell);
}
void
image_resize_to_layers_cmd_callback (GtkAction *action,
gpointer data)
{
GimpDisplay *gdisp;
GimpProgress *progress;
return_if_no_display (gdisp, data);
progress = gimp_progress_start (GIMP_PROGRESS (gdisp),
_("Resizing..."), FALSE);
gimp_image_resize_to_layers (gdisp->gimage,
action_data_get_context (data),
progress);
if (progress)
gimp_progress_end (progress);
gimp_image_flush (gdisp->gimage);
}
void
image_scale_cmd_callback (GtkAction *action,
gpointer data)

View file

@ -20,38 +20,40 @@
#define __IMAGE_COMMANDS_H__
void image_new_cmd_callback (GtkAction *action,
gpointer data);
void image_new_from_image_cmd_callback (GtkAction *action,
gpointer data);
void image_convert_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void image_resize_cmd_callback (GtkAction *action,
gpointer data);
void image_scale_cmd_callback (GtkAction *action,
gpointer data);
void image_flip_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void image_rotate_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void image_crop_cmd_callback (GtkAction *action,
gpointer data);
void image_duplicate_cmd_callback (GtkAction *action,
gpointer data);
void image_merge_layers_cmd_callback (GtkAction *action,
gpointer data);
void image_flatten_image_cmd_callback (GtkAction *action,
gpointer data);
void image_configure_grid_cmd_callback (GtkAction *action,
gpointer data);
void image_new_cmd_callback (GtkAction *action,
gpointer data);
void image_new_from_image_cmd_callback (GtkAction *action,
gpointer data);
void image_convert_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void image_resize_cmd_callback (GtkAction *action,
gpointer data);
void image_resize_to_layers_cmd_callback (GtkAction *action,
gpointer data);
void image_scale_cmd_callback (GtkAction *action,
gpointer data);
void image_flip_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void image_rotate_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void image_crop_cmd_callback (GtkAction *action,
gpointer data);
void image_duplicate_cmd_callback (GtkAction *action,
gpointer data);
void image_merge_layers_cmd_callback (GtkAction *action,
gpointer data);
void image_flatten_image_cmd_callback (GtkAction *action,
gpointer data);
void image_configure_grid_cmd_callback (GtkAction *action,
gpointer data);
#endif /* __IMAGE_COMMANDS_H__ */

View file

@ -39,10 +39,10 @@
void
gimp_image_resize (GimpImage *gimage,
GimpContext *context,
gint new_width,
gint new_height,
gint offset_x,
gint offset_y,
gint new_width,
gint new_height,
gint offset_x,
gint offset_y,
GimpProgress *progress)
{
GList *list;
@ -134,22 +134,22 @@ gimp_image_resize (GimpImage *gimage,
list = g_list_next (list);
switch (guide->orientation)
{
case GIMP_ORIENTATION_HORIZONTAL:
{
case GIMP_ORIENTATION_HORIZONTAL:
new_position += offset_y;
if (new_position < 0 || new_position > new_height)
if (new_position < 0 || new_position > new_height)
remove_guide = TRUE;
break;
case GIMP_ORIENTATION_VERTICAL:
new_position += offset_x;
if (new_position < 0 || new_position > new_width)
remove_guide = TRUE;
break;
default:
break;
}
case GIMP_ORIENTATION_VERTICAL:
new_position += offset_x;
if (new_position < 0 || new_position > new_width)
remove_guide = TRUE;
break;
default:
break;
}
if (remove_guide)
gimp_image_remove_guide (gimage, guide, TRUE);
@ -164,3 +164,42 @@ gimp_image_resize (GimpImage *gimage,
gimp_unset_busy (gimage->gimp);
}
void
gimp_image_resize_to_layers (GimpImage *gimage,
GimpContext *context,
GimpProgress *progress)
{
gint min_x, max_x, min_y, max_y;
GList *list = GIMP_LIST (gimage->layers)->list;
GimpItem *item;
if (!list)
return;
/* figure out starting values */
item = list->data;
min_x = item->offset_x;
min_y = item->offset_y;
max_x = item->offset_x + item->width;
max_y = item->offset_y + item->height;
/* Respect all layers */
for (list = g_list_next (list);
list;
list = g_list_next (list))
{
item = list->data;
min_x = MIN (min_x, item->offset_x);
min_y = MIN (min_y, item->offset_y);
max_x = MAX (max_x, item->offset_x + item->width);
max_y = MAX (max_y, item->offset_y + item->height);
}
gimp_image_resize (gimage, context,
max_x - min_x, max_y - min_y,
- min_x, - min_y,
progress);
}

View file

@ -20,13 +20,17 @@
#define __GIMP_IMAGE_RESIZE_H__
void gimp_image_resize (GimpImage *gimage,
GimpContext *context,
gint new_width,
gint new_height,
gint offset_x,
gint offset_y,
GimpProgress *progress);
void gimp_image_resize (GimpImage *gimage,
GimpContext *context,
gint new_width,
gint new_height,
gint offset_x,
gint offset_y,
GimpProgress *progress);
void gimp_image_resize_to_layers (GimpImage *gimage,
GimpContext *context,
GimpProgress *progress);
#endif /* __GIMP_IMAGE_RESIZE_H__ */

View file

@ -60,6 +60,7 @@ static ProcRecord image_width_proc;
static ProcRecord image_height_proc;
static ProcRecord image_free_shadow_proc;
static ProcRecord image_resize_proc;
static ProcRecord image_resize_to_layers_proc;
static ProcRecord image_scale_proc;
static ProcRecord image_crop_proc;
static ProcRecord image_flip_proc;
@ -125,6 +126,7 @@ register_image_procs (Gimp *gimp)
procedural_db_register (gimp, &image_height_proc);
procedural_db_register (gimp, &image_free_shadow_proc);
procedural_db_register (gimp, &image_resize_proc);
procedural_db_register (gimp, &image_resize_to_layers_proc);
procedural_db_register (gimp, &image_scale_proc);
procedural_db_register (gimp, &image_crop_proc);
procedural_db_register (gimp, &image_flip_proc);
@ -740,6 +742,52 @@ static ProcRecord image_resize_proc =
{ { image_resize_invoker } }
};
static Argument *
image_resize_to_layers_invoker (Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
GimpImage *gimage;
gimage = gimp_image_get_by_ID (gimp, args[0].value.pdb_int);
if (! GIMP_IS_IMAGE (gimage))
success = FALSE;
if (success)
{
gimp_image_resize_to_layers (gimage, context, NULL);
}
return procedural_db_return_args (&image_resize_to_layers_proc, success);
}
static ProcArg image_resize_to_layers_inargs[] =
{
{
GIMP_PDB_IMAGE,
"image",
"The image"
}
};
static ProcRecord image_resize_to_layers_proc =
{
"gimp_image_resize_to_layers",
"Resize the image to fit all layers.",
"This procedure resizes the image so that it exactly fits all layers of the image. All channels within the image are resized to the new size; this includes the image selection mask. All layers within the image are repositioned to the new image area.",
"Simon Budig",
"Simon Budig",
"2004",
GIMP_INTERNAL,
1,
image_resize_to_layers_inargs,
0,
NULL,
{ { image_resize_to_layers_invoker } }
};
static Argument *
image_scale_invoker (Gimp *gimp,
GimpContext *context,

View file

@ -70,7 +70,7 @@ void register_transform_tools_procs (Gimp *gimp);
void register_undo_procs (Gimp *gimp);
void register_unit_procs (Gimp *gimp);
/* 380 procedures registered total */
/* 381 procedures registered total */
void
internal_procs_init (Gimp *gimp,
@ -88,13 +88,13 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Channel"), 0.037);
register_channel_procs (gimp);
(* status_callback) (NULL, _("Color"), 0.061);
(* status_callback) (NULL, _("Color"), 0.06);
register_color_procs (gimp);
(* status_callback) (NULL, _("Convert"), 0.095);
(* status_callback) (NULL, _("Convert"), 0.094);
register_convert_procs (gimp);
(* status_callback) (NULL, _("Display procedures"), 0.103);
(* status_callback) (NULL, _("Display procedures"), 0.102);
register_display_procs (gimp);
(* status_callback) (NULL, _("Drawable procedures"), 0.113);
@ -106,79 +106,79 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("File Operations"), 0.218);
register_fileops_procs (gimp);
(* status_callback) (NULL, _("Floating selections"), 0.242);
(* status_callback) (NULL, _("Floating selections"), 0.241);
register_floating_sel_procs (gimp);
(* status_callback) (NULL, _("Font UI"), 0.258);
(* status_callback) (NULL, _("Font UI"), 0.257);
register_font_select_procs (gimp);
(* status_callback) (NULL, _("Fonts"), 0.266);
(* status_callback) (NULL, _("Fonts"), 0.265);
register_fonts_procs (gimp);
(* status_callback) (NULL, _("Gimprc procedures"), 0.271);
(* status_callback) (NULL, _("Gimprc procedures"), 0.27);
register_gimprc_procs (gimp);
(* status_callback) (NULL, _("Gradient"), 0.287);
(* status_callback) (NULL, _("Gradient"), 0.286);
register_gradient_edit_procs (gimp);
(* status_callback) (NULL, _("Gradient UI"), 0.347);
(* status_callback) (NULL, _("Gradient UI"), 0.346);
register_gradient_select_procs (gimp);
(* status_callback) (NULL, _("Gradients"), 0.355);
(* status_callback) (NULL, _("Gradients"), 0.354);
register_gradients_procs (gimp);
(* status_callback) (NULL, _("Guide procedures"), 0.384);
(* status_callback) (NULL, _("Guide procedures"), 0.383);
register_guides_procs (gimp);
(* status_callback) (NULL, _("Help procedures"), 0.4);
(* status_callback) (NULL, _("Help procedures"), 0.399);
register_help_procs (gimp);
(* status_callback) (NULL, _("Image"), 0.403);
(* status_callback) (NULL, _("Image"), 0.402);
register_image_procs (gimp);
(* status_callback) (NULL, _("Layer"), 0.563);
(* status_callback) (NULL, _("Layer"), 0.564);
register_layer_procs (gimp);
(* status_callback) (NULL, _("Message procedures"), 0.632);
(* status_callback) (NULL, _("Message procedures"), 0.633);
register_message_procs (gimp);
(* status_callback) (NULL, _("Miscellaneous"), 0.639);
(* status_callback) (NULL, _("Miscellaneous"), 0.64);
register_misc_procs (gimp);
(* status_callback) (NULL, _("Paint Tool procedures"), 0.645);
(* status_callback) (NULL, _("Paint Tool procedures"), 0.646);
register_paint_tools_procs (gimp);
(* status_callback) (NULL, _("Palette"), 0.684);
(* status_callback) (NULL, _("Palette"), 0.685);
register_palette_procs (gimp);
(* status_callback) (NULL, _("Palette UI"), 0.7);
(* status_callback) (NULL, _("Palette UI"), 0.701);
register_palette_select_procs (gimp);
(* status_callback) (NULL, _("Palettes"), 0.708);
(* status_callback) (NULL, _("Palettes"), 0.709);
register_palettes_procs (gimp);
(* status_callback) (NULL, _("Parasite procedures"), 0.721);
(* status_callback) (NULL, _("Parasite procedures"), 0.722);
register_parasite_procs (gimp);
(* status_callback) (NULL, _("Paths"), 0.753);
register_paths_procs (gimp);
(* status_callback) (NULL, _("Pattern UI"), 0.792);
(* status_callback) (NULL, _("Pattern UI"), 0.793);
register_pattern_select_procs (gimp);
(* status_callback) (NULL, _("Patterns"), 0.8);
(* status_callback) (NULL, _("Patterns"), 0.801);
register_patterns_procs (gimp);
(* status_callback) (NULL, _("Plug-in"), 0.813);
(* status_callback) (NULL, _("Plug-in"), 0.814);
register_plug_in_procs (gimp);
(* status_callback) (NULL, _("Procedural database"), 0.826);
(* status_callback) (NULL, _("Procedural database"), 0.827);
register_procedural_db_procs (gimp);
(* status_callback) (NULL, _("Progress"), 0.85);
register_progress_procs (gimp);
(* status_callback) (NULL, _("Image mask"), 0.863);
(* status_callback) (NULL, _("Image mask"), 0.864);
register_selection_procs (gimp);
(* status_callback) (NULL, _("Selection Tool procedures"), 0.911);
@ -193,7 +193,7 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Undo"), 0.95);
register_undo_procs (gimp);
(* status_callback) (NULL, _("Units"), 0.968);
(* status_callback) (NULL, _("Units"), 0.969);
register_unit_procs (gimp);
}

View file

@ -113,6 +113,7 @@
#define GIMP_HELP_IMAGE_ROTATE_180 "gimp-image-rotate-180"
#define GIMP_HELP_IMAGE_ROTATE_270 "gimp-image-rotate-270"
#define GIMP_HELP_IMAGE_RESIZE "gimp-image-resize"
#define GIMP_HELP_IMAGE_RESIZE_TO_LAYERS "gimp-image-resize-to-layers"
#define GIMP_HELP_IMAGE_SCALE "gimp-image-scale"
#define GIMP_HELP_IMAGE_SCALE_WARNING "gimp-image-scale-warning"
#define GIMP_HELP_IMAGE_CROP "gimp-image-crop"

View file

@ -342,6 +342,38 @@ gimp_image_resize (gint32 image_ID,
return success;
}
/**
* gimp_image_resize_to_layers:
* @image_ID: The image.
*
* Resize the image to fit all layers.
*
* This procedure resizes the image so that it exactly fits all layers
* of the image. All channels within the image are resized to the new
* size; this includes the image selection mask. All layers within the
* image are repositioned to the new image area.
*
* Returns: TRUE on success.
*/
gboolean
gimp_image_resize_to_layers (gint32 image_ID)
{
GimpParam *return_vals;
gint nreturn_vals;
gboolean success = TRUE;
return_vals = gimp_run_procedure ("gimp_image_resize_to_layers",
&nreturn_vals,
GIMP_PDB_IMAGE, image_ID,
GIMP_PDB_END);
success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
gimp_destroy_params (return_vals, nreturn_vals);
return success;
}
/**
* gimp_image_scale:
* @image_ID: The image.

View file

@ -44,6 +44,7 @@ gboolean gimp_image_resize (gint32 ima
gint new_height,
gint offx,
gint offy);
gboolean gimp_image_resize_to_layers (gint32 image_ID);
gboolean gimp_image_scale (gint32 image_ID,
gint new_width,
gint new_height);

View file

@ -267,6 +267,7 @@
<separator />
<placeholder name="Resize">
<menuitem action="image-resize" />
<menuitem action="image-resize-to-layers" />
</placeholder>
<placeholder name="Scale">
<menuitem action="image-scale" />

View file

@ -336,6 +336,31 @@ CODE
);
}
sub image_resize_to_layers {
$blurb = 'Resize the image to fit all layers.';
$help = <<'HELP';
This procedure resizes the image so that it exactly fits all layers of the
image. All channels within the image are resized to the new size; this includes
the image selection mask. All layers within the image are repositioned to the
new image area.
HELP
$author = $copyright = 'Simon Budig';
$date = '2004';
@inargs = ( &std_image_arg );
%invoke = (
headers => [ qw("core/gimpimage-resize.h") ],
code => <<'CODE'
{
gimp_image_resize_to_layers (gimage, context, NULL);
}
CODE
);
}
sub image_scale {
$blurb = 'Scale the image to the specified extents.';
@ -1509,7 +1534,8 @@ unshift @procs, qw(image_list image_new image_duplicate image_delete
image_base_type
image_width image_height
image_free_shadow
image_resize image_scale image_crop image_flip image_rotate
image_resize image_resize_to_layers image_scale
image_crop image_flip image_rotate
image_get_layers image_get_channels
image_get_active_drawable
image_unset_active_channel
@ -1525,7 +1551,7 @@ unshift @procs, qw(image_list image_new image_duplicate image_delete
image_get_cmap image_set_cmap
image_clean_all image_is_dirty
image_thumbnail);
%exports = (app => [@procs], lib => [@procs[0..33,36..60]]);
%exports = (app => [@procs], lib => [@procs[0..34,37..61]]);
$desc = 'Image';