1998-06-28 18:39:58 +08:00
|
|
|
/* 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.
|
|
|
|
*/
|
2000-12-11 11:33:25 +08:00
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
#include <glib-object.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core-types.h"
|
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
#include "gimp.h"
|
2004-04-15 07:37:34 +08:00
|
|
|
#include "gimpcontext.h"
|
2006-06-07 06:48:57 +08:00
|
|
|
#include "gimpguide.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "gimpimage.h"
|
include the new "paint-funcs/paint-funcs-types.h".
2001-11-28 Michael Natterer <mitch@gimp.org>
* app/base/base-types.h: include the new
"paint-funcs/paint-funcs-types.h".
* app/paint-funcs/Makefile.am
* app/paint-funcs/paint-funcs-types.h: new file. Includes
"base/base-types.h".
* app/paint-funcs/paint-funcs.[ch]: removed the enums here,
include "paint-funcs-types.h".
* app/widgets/widgets-types.h: include "display/display-types.h"
* app/display/display-types.h: include "widgets/widgets-types.h".
* app/tools/tools-types.h: include "display/display-types.h"
* app/gui/gui-types.h: include "tools/tools-types.h".
The order of namespaces/dependencies should be (but is not):
(base, paint-funcs) -> (core, file, xcf, pdb) ->
(widgets, display) -> tools -> gui
* app/path.c: include "tools/tools-types.h".
* app/core/Makefile.am
* app/core/gimpimage-guides.[ch]
* app/core/gimpimage-merge.[ch]
* app/core/gimpimage-resize.[ch]
* app/core/gimpimage-scale.[ch]: new files.
* app/core/gimpimage.[ch]: removed the stuff which is in the new
files. Reordered all functions in both the .h and .c files,
commented the groups of functions.
* app/core/gimpcontainer.c: create the handler_id using a counter,
not the address of a pointer, because the address *may* be the
same twice, added debugging output.
* app/core/gimpviewable.[ch]: added primitive support for getting
a preview GdkPixbuf.
* app/nav_window.c
* app/undo.c
* app/undo_history.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage-mask.[ch]
* app/display/gimpdisplay.c
* app/display/gimpdisplayshell-callbacks.c
* app/display/gimpdisplayshell-dnd.c
* app/display/gimpdisplayshell-render.c
* app/display/gimpdisplayshell-scale.c
* app/display/gimpdisplayshell-scroll.c
* app/gui/image-commands.c
* app/gui/info-window.c
* app/gui/layers-commands.c
* app/gui/palette-import-dialog.c
* app/tools/gimpbycolorselecttool.c
* app/tools/gimpeditselectiontool.c
* app/tools/gimpmeasuretool.c
* app/tools/gimpmovetool.c
* app/widgets/gimpcontainerview-utils.c
* app/xcf/xcf-load.c: changed accordingly, some cleanup.
* tools/pdbgen/pdb/guides.pdb
* tools/pdbgen/pdb/image.pdb: changed accordingly, reordered functions.
* app/plug_in.c: set the labels of the "Repeat" and "Re-Show" menu
items to the name of the last plug-in (Fixes #50986).
* app/display/gimpdisplayshell.[ch]: set the labels of "Undo" and
"Redo" to the resp. undo names. Much simplified the WM icon stuff
by removing most code and using gimp_viewable_get_new_preview_pixbuf().
* app/widgets/gimpbrushfactoryview.c: forgot to assign the GQuark
returned by gimp_container_add_handler().
* app/pdb/guides_cmds.c
* app/pdb/image_cmds.c
* libgimp/gimpimage_pdb.[ch]: regenerated.
2001-11-29 01:51:06 +08:00
|
|
|
#include "gimpimage-guides.h"
|
2006-05-21 19:32:41 +08:00
|
|
|
#include "gimpimage-item-list.h"
|
include the new "paint-funcs/paint-funcs-types.h".
2001-11-28 Michael Natterer <mitch@gimp.org>
* app/base/base-types.h: include the new
"paint-funcs/paint-funcs-types.h".
* app/paint-funcs/Makefile.am
* app/paint-funcs/paint-funcs-types.h: new file. Includes
"base/base-types.h".
* app/paint-funcs/paint-funcs.[ch]: removed the enums here,
include "paint-funcs-types.h".
* app/widgets/widgets-types.h: include "display/display-types.h"
* app/display/display-types.h: include "widgets/widgets-types.h".
* app/tools/tools-types.h: include "display/display-types.h"
* app/gui/gui-types.h: include "tools/tools-types.h".
The order of namespaces/dependencies should be (but is not):
(base, paint-funcs) -> (core, file, xcf, pdb) ->
(widgets, display) -> tools -> gui
* app/path.c: include "tools/tools-types.h".
* app/core/Makefile.am
* app/core/gimpimage-guides.[ch]
* app/core/gimpimage-merge.[ch]
* app/core/gimpimage-resize.[ch]
* app/core/gimpimage-scale.[ch]: new files.
* app/core/gimpimage.[ch]: removed the stuff which is in the new
files. Reordered all functions in both the .h and .c files,
commented the groups of functions.
* app/core/gimpcontainer.c: create the handler_id using a counter,
not the address of a pointer, because the address *may* be the
same twice, added debugging output.
* app/core/gimpviewable.[ch]: added primitive support for getting
a preview GdkPixbuf.
* app/nav_window.c
* app/undo.c
* app/undo_history.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage-mask.[ch]
* app/display/gimpdisplay.c
* app/display/gimpdisplayshell-callbacks.c
* app/display/gimpdisplayshell-dnd.c
* app/display/gimpdisplayshell-render.c
* app/display/gimpdisplayshell-scale.c
* app/display/gimpdisplayshell-scroll.c
* app/gui/image-commands.c
* app/gui/info-window.c
* app/gui/layers-commands.c
* app/gui/palette-import-dialog.c
* app/tools/gimpbycolorselecttool.c
* app/tools/gimpeditselectiontool.c
* app/tools/gimpmeasuretool.c
* app/tools/gimpmovetool.c
* app/widgets/gimpcontainerview-utils.c
* app/xcf/xcf-load.c: changed accordingly, some cleanup.
* tools/pdbgen/pdb/guides.pdb
* tools/pdbgen/pdb/image.pdb: changed accordingly, reordered functions.
* app/plug_in.c: set the labels of the "Repeat" and "Re-Show" menu
items to the name of the last plug-in (Fixes #50986).
* app/display/gimpdisplayshell.[ch]: set the labels of "Undo" and
"Redo" to the resp. undo names. Much simplified the WM icon stuff
by removing most code and using gimp_viewable_get_new_preview_pixbuf().
* app/widgets/gimpbrushfactoryview.c: forgot to assign the GQuark
returned by gimp_container_add_handler().
* app/pdb/guides_cmds.c
* app/pdb/image_cmds.c
* libgimp/gimpimage_pdb.[ch]: regenerated.
2001-11-29 01:51:06 +08:00
|
|
|
#include "gimpimage-resize.h"
|
2005-08-08 05:05:09 +08:00
|
|
|
#include "gimpimage-sample-points.h"
|
2003-02-13 19:23:50 +08:00
|
|
|
#include "gimpimage-undo.h"
|
2003-02-14 22:14:29 +08:00
|
|
|
#include "gimpimage-undo-push.h"
|
2001-02-02 02:44:22 +08:00
|
|
|
#include "gimplayer.h"
|
2001-02-19 21:06:09 +08:00
|
|
|
#include "gimplist.h"
|
2004-08-11 02:47:21 +08:00
|
|
|
#include "gimpprogress.h"
|
2001-07-05 03:31:35 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2003-02-13 19:23:50 +08:00
|
|
|
|
2000-12-29 00:19:55 +08:00
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_resize (GimpImage *image,
|
2004-08-11 02:47:21 +08:00
|
|
|
GimpContext *context,
|
2004-09-05 06:08:43 +08:00
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y,
|
2004-08-11 02:47:21 +08:00
|
|
|
GimpProgress *progress)
|
2005-02-25 00:39:12 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_resize_with_layers (image, context,
|
2005-02-25 00:39:12 +08:00
|
|
|
new_width, new_height, offset_x, offset_y,
|
2006-05-19 22:50:46 +08:00
|
|
|
GIMP_ITEM_SET_NONE,
|
2005-02-25 00:39:12 +08:00
|
|
|
progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-05-19 22:50:46 +08:00
|
|
|
gimp_image_resize_with_layers (GimpImage *image,
|
|
|
|
GimpContext *context,
|
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y,
|
|
|
|
GimpItemSet layer_set,
|
|
|
|
GimpProgress *progress)
|
1998-06-28 18:39:58 +08:00
|
|
|
{
|
2004-08-11 02:47:21 +08:00
|
|
|
GList *list;
|
2006-05-21 19:32:41 +08:00
|
|
|
GList *resize_layers;
|
2004-08-11 02:47:21 +08:00
|
|
|
gdouble progress_max;
|
|
|
|
gdouble progress_current = 1.0;
|
2005-02-25 00:39:12 +08:00
|
|
|
gint old_width, old_height;
|
1998-06-28 18:39:58 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
2004-04-15 07:37:34 +08:00
|
|
|
g_return_if_fail (GIMP_IS_CONTEXT (context));
|
2001-08-11 22:39:19 +08:00
|
|
|
g_return_if_fail (new_width > 0 && new_height > 0);
|
2004-08-11 02:47:21 +08:00
|
|
|
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
|
1999-01-11 07:36:29 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_set_busy (image->gimp);
|
1998-06-28 18:39:58 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
progress_max = (image->channels->num_children +
|
|
|
|
image->layers->num_children +
|
|
|
|
image->vectors->num_children +
|
2003-06-04 00:42:46 +08:00
|
|
|
1 /* selection */);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_object_freeze_notify (G_OBJECT (image));
|
2004-07-14 20:12:50 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_RESIZE,
|
2003-02-13 19:23:50 +08:00
|
|
|
_("Resize Image"));
|
1998-06-28 18:39:58 +08:00
|
|
|
|
2006-05-21 19:32:41 +08:00
|
|
|
resize_layers = gimp_image_item_list_get_list (image, NULL,
|
|
|
|
GIMP_ITEM_TYPE_LAYERS,
|
|
|
|
layer_set);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
old_width = image->width;
|
|
|
|
old_height = image->height;
|
2005-02-25 00:39:12 +08:00
|
|
|
|
1998-06-28 18:39:58 +08:00
|
|
|
/* Push the image size to the stack */
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_push_image_size (image, NULL);
|
1998-06-28 18:39:58 +08:00
|
|
|
|
|
|
|
/* Set the new width and height */
|
2006-03-29 01:08:36 +08:00
|
|
|
g_object_set (image,
|
2004-07-14 20:12:50 +08:00
|
|
|
"width", new_width,
|
|
|
|
"height", new_height,
|
|
|
|
NULL);
|
1998-06-28 18:39:58 +08:00
|
|
|
|
|
|
|
/* Resize all channels */
|
2006-03-29 01:08:36 +08:00
|
|
|
for (list = GIMP_LIST (image->channels)->list;
|
2003-05-09 19:27:21 +08:00
|
|
|
list;
|
2001-02-19 21:06:09 +08:00
|
|
|
list = g_list_next (list))
|
1998-06-28 18:39:58 +08:00
|
|
|
{
|
2003-05-07 21:01:17 +08:00
|
|
|
GimpItem *item = list->data;
|
1999-07-10 02:15:39 +08:00
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_item_resize (item, context,
|
|
|
|
new_width, new_height, offset_x, offset_y);
|
2003-06-04 00:42:46 +08:00
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
if (progress)
|
|
|
|
gimp_progress_set_value (progress, progress_current++ / progress_max);
|
1999-07-10 02:15:39 +08:00
|
|
|
}
|
|
|
|
|
2003-05-09 08:38:51 +08:00
|
|
|
/* Resize all vectors */
|
2006-03-29 01:08:36 +08:00
|
|
|
for (list = GIMP_LIST (image->vectors)->list;
|
2003-05-09 19:27:21 +08:00
|
|
|
list;
|
2003-05-09 08:38:51 +08:00
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpItem *item = list->data;
|
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_item_resize (item, context,
|
|
|
|
new_width, new_height, offset_x, offset_y);
|
2003-06-04 00:42:46 +08:00
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
if (progress)
|
|
|
|
gimp_progress_set_value (progress, progress_current++ / progress_max);
|
2003-05-09 08:38:51 +08:00
|
|
|
}
|
|
|
|
|
2003-05-09 19:27:21 +08:00
|
|
|
/* Don't forget the selection mask! */
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_item_resize (GIMP_ITEM (gimp_image_get_mask (image)), context,
|
2003-05-09 19:27:21 +08:00
|
|
|
new_width, new_height, offset_x, offset_y);
|
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
if (progress)
|
|
|
|
gimp_progress_set_value (progress, progress_current++ / progress_max);
|
2003-06-04 00:42:46 +08:00
|
|
|
|
2003-05-09 19:27:21 +08:00
|
|
|
/* Reposition all layers */
|
2006-03-29 01:08:36 +08:00
|
|
|
for (list = GIMP_LIST (image->layers)->list;
|
2003-05-09 19:27:21 +08:00
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpItem *item = list->data;
|
2005-02-25 00:39:12 +08:00
|
|
|
gint old_offset_x;
|
|
|
|
gint old_offset_y;
|
|
|
|
|
|
|
|
gimp_item_offsets (item, &old_offset_x, &old_offset_y);
|
2003-05-09 19:27:21 +08:00
|
|
|
|
|
|
|
gimp_item_translate (item, offset_x, offset_y, TRUE);
|
2003-06-04 00:42:46 +08:00
|
|
|
|
2006-05-21 19:32:41 +08:00
|
|
|
if (g_list_find (resize_layers, item))
|
2005-03-02 04:19:53 +08:00
|
|
|
gimp_item_resize (item, context,
|
|
|
|
new_width, new_height,
|
|
|
|
offset_x + old_offset_x, offset_y + old_offset_y);
|
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
if (progress)
|
|
|
|
gimp_progress_set_value (progress, progress_current++ / progress_max);
|
2003-05-09 19:27:21 +08:00
|
|
|
}
|
|
|
|
|
2006-05-21 19:32:41 +08:00
|
|
|
g_list_free (resize_layers);
|
|
|
|
|
2003-05-09 19:27:21 +08:00
|
|
|
/* Reposition or remove all guides */
|
2006-06-07 15:57:24 +08:00
|
|
|
for (list = image->guides; list; list = g_list_next (list))
|
1999-07-10 02:15:39 +08:00
|
|
|
{
|
2003-03-31 00:11:51 +08:00
|
|
|
GimpGuide *guide = list->data;
|
|
|
|
gboolean remove_guide = FALSE;
|
2006-06-07 23:49:59 +08:00
|
|
|
gint new_position = gimp_guide_get_position (guide);
|
1999-07-10 02:15:39 +08:00
|
|
|
|
2006-06-07 23:49:59 +08:00
|
|
|
switch (gimp_guide_get_orientation (guide))
|
2004-09-05 06:08:43 +08:00
|
|
|
{
|
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
2003-05-09 19:27:21 +08:00
|
|
|
new_position += offset_y;
|
2004-09-05 06:08:43 +08:00
|
|
|
if (new_position < 0 || new_position > new_height)
|
2003-03-31 00:11:51 +08:00
|
|
|
remove_guide = TRUE;
|
2004-09-05 06:08:43 +08:00
|
|
|
break;
|
2000-12-28 02:15:37 +08:00
|
|
|
|
2004-09-05 06:08:43 +08:00
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
2003-05-09 19:27:21 +08:00
|
|
|
new_position += offset_x;
|
2004-09-05 06:08:43 +08:00
|
|
|
if (new_position < 0 || new_position > new_width)
|
2003-03-31 00:11:51 +08:00
|
|
|
remove_guide = TRUE;
|
2004-09-05 06:08:43 +08:00
|
|
|
break;
|
2000-12-28 02:15:37 +08:00
|
|
|
|
2004-09-05 06:08:43 +08:00
|
|
|
default:
|
2003-05-09 19:27:21 +08:00
|
|
|
break;
|
2004-09-05 06:08:43 +08:00
|
|
|
}
|
2003-03-31 00:11:51 +08:00
|
|
|
|
|
|
|
if (remove_guide)
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_remove_guide (image, guide, TRUE);
|
2006-06-07 23:49:59 +08:00
|
|
|
else if (new_position != gimp_guide_get_position (guide))
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_move_guide (image, guide, new_position, TRUE);
|
1998-06-28 18:39:58 +08:00
|
|
|
}
|
|
|
|
|
2005-08-08 05:05:09 +08:00
|
|
|
/* Reposition or remove sample points */
|
2006-06-07 15:57:24 +08:00
|
|
|
for (list = image->sample_points; list; list = g_list_next (list))
|
2005-08-08 05:05:09 +08:00
|
|
|
{
|
|
|
|
GimpSamplePoint *sample_point = list->data;
|
|
|
|
gboolean remove_sample_point = FALSE;
|
|
|
|
gint new_x = sample_point->x;
|
|
|
|
gint new_y = sample_point->y;
|
|
|
|
|
|
|
|
new_y += offset_y;
|
|
|
|
if ((sample_point->y < 0) || (sample_point->y > new_height))
|
|
|
|
remove_sample_point = TRUE;
|
|
|
|
|
|
|
|
new_x += offset_x;
|
|
|
|
if ((sample_point->x < 0) || (sample_point->x > new_width))
|
|
|
|
remove_sample_point = TRUE;
|
|
|
|
|
|
|
|
if (remove_sample_point)
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_remove_sample_point (image, sample_point, TRUE);
|
2005-08-08 05:05:09 +08:00
|
|
|
else if (new_x != sample_point->x || new_y != sample_point->y)
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_move_sample_point (image, sample_point,
|
2005-08-08 05:05:09 +08:00
|
|
|
new_x, new_y, TRUE);
|
|
|
|
}
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_group_end (image);
|
2001-05-07 01:56:10 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_viewable_size_changed (GIMP_VIEWABLE (image));
|
|
|
|
g_object_thaw_notify (G_OBJECT (image));
|
1999-01-11 07:36:29 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_unset_busy (image->gimp);
|
1998-06-28 18:39:58 +08:00
|
|
|
}
|
2004-09-05 06:08:43 +08:00
|
|
|
|
|
|
|
void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_resize_to_layers (GimpImage *image,
|
2004-09-05 06:08:43 +08:00
|
|
|
GimpContext *context,
|
|
|
|
GimpProgress *progress)
|
|
|
|
{
|
|
|
|
gint min_x, max_x, min_y, max_y;
|
2006-03-29 01:08:36 +08:00
|
|
|
GList *list = GIMP_LIST (image->layers)->list;
|
2004-09-05 06:08:43 +08:00
|
|
|
GimpItem *item;
|
2005-02-25 00:39:12 +08:00
|
|
|
|
2004-09-05 06:08:43 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_resize (image, context,
|
2004-09-05 06:08:43 +08:00
|
|
|
max_x - min_x, max_y - min_y,
|
|
|
|
- min_x, - min_y,
|
|
|
|
progress);
|
|
|
|
}
|
|
|
|
|