2003-05-20 18:36:29 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#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"
|
2003-05-20 18:36:29 +08:00
|
|
|
#include "gimpimage.h"
|
|
|
|
#include "gimpimage-rotate.h"
|
|
|
|
#include "gimpimage-guides.h"
|
2005-03-05 00:34:59 +08:00
|
|
|
#include "gimpimage-sample-points.h"
|
2003-05-20 18:36:29 +08:00
|
|
|
#include "gimpimage-undo.h"
|
|
|
|
#include "gimpimage-undo-push.h"
|
|
|
|
#include "gimpitem.h"
|
|
|
|
#include "gimplist.h"
|
2004-08-11 02:47:21 +08:00
|
|
|
#include "gimpprogress.h"
|
2003-05-20 18:36:29 +08:00
|
|
|
|
2003-05-20 19:55:12 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
static void gimp_image_rotate_item_offset (GimpImage *image,
|
2005-03-05 00:34:59 +08:00
|
|
|
GimpRotationType rotate_type,
|
|
|
|
GimpItem *item,
|
|
|
|
gint off_x,
|
|
|
|
gint off_y);
|
2006-03-29 01:08:36 +08:00
|
|
|
static void gimp_image_rotate_guides (GimpImage *image,
|
2005-03-05 00:34:59 +08:00
|
|
|
GimpRotationType rotate_type);
|
2006-03-29 01:08:36 +08:00
|
|
|
static void gimp_image_rotate_sample_points (GimpImage *image,
|
2005-03-05 00:34:59 +08:00
|
|
|
GimpRotationType rotate_type);
|
2003-05-20 18:36:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_rotate (GimpImage *image,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2003-05-20 18:36:29 +08:00
|
|
|
GimpRotationType rotate_type,
|
2004-08-11 02:47:21 +08:00
|
|
|
GimpProgress *progress)
|
2003-05-20 18:36:29 +08:00
|
|
|
{
|
2004-04-13 21:54:54 +08:00
|
|
|
GimpItem *item;
|
|
|
|
GList *list;
|
|
|
|
gdouble center_x;
|
|
|
|
gdouble center_y;
|
2004-08-11 02:47:21 +08:00
|
|
|
gdouble progress_max;
|
|
|
|
gdouble progress_current = 1.0;
|
2004-04-13 21:54:54 +08:00
|
|
|
gint new_image_width;
|
|
|
|
gint new_image_height;
|
|
|
|
gboolean size_changed;
|
2003-05-20 18:36:29 +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));
|
2004-08-11 02:47:21 +08:00
|
|
|
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
|
2003-05-20 18:36:29 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_set_busy (image->gimp);
|
2003-05-20 18:36:29 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
center_x = (gdouble) image->width / 2.0;
|
|
|
|
center_y = (gdouble) image->height / 2.0;
|
2003-05-20 18:36:29 +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 */);
|
2003-05-20 18:36:29 +08:00
|
|
|
|
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_ROTATE, NULL);
|
2003-05-20 18:36:29 +08:00
|
|
|
|
2003-05-20 19:55:12 +08:00
|
|
|
/* Resize the image (if needed) */
|
|
|
|
switch (rotate_type)
|
|
|
|
{
|
|
|
|
case GIMP_ROTATE_90:
|
|
|
|
case GIMP_ROTATE_270:
|
2006-03-29 01:08:36 +08:00
|
|
|
new_image_width = image->height;
|
|
|
|
new_image_height = image->width;
|
2003-05-20 23:26:38 +08:00
|
|
|
size_changed = TRUE;
|
2003-05-20 19:55:12 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ROTATE_180:
|
2006-03-29 01:08:36 +08:00
|
|
|
new_image_width = image->width;
|
|
|
|
new_image_height = image->height;
|
2003-05-20 23:26:38 +08:00
|
|
|
size_changed = FALSE;
|
|
|
|
break;
|
2003-05-20 23:41:39 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return;
|
2003-05-20 19:55:12 +08:00
|
|
|
}
|
|
|
|
|
2003-05-20 18:36:29 +08:00
|
|
|
/* Rotate all channels */
|
2006-03-29 01:08:36 +08:00
|
|
|
for (list = GIMP_LIST (image->channels)->list;
|
2003-09-03 18:19:47 +08:00
|
|
|
list;
|
2003-05-20 18:36:29 +08:00
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
item = (GimpItem *) list->data;
|
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_item_rotate (item, context, rotate_type, center_x, center_y, FALSE);
|
2003-05-20 23:26:38 +08:00
|
|
|
|
2003-05-24 06:50:03 +08:00
|
|
|
item->offset_x = 0;
|
|
|
|
item->offset_y = 0;
|
2003-05-20 18:36:29 +08:00
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
if (progress)
|
|
|
|
gimp_progress_set_value (progress, progress_current++ / progress_max);
|
2003-05-20 18:36:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Rotate all vectors */
|
2006-03-29 01:08:36 +08:00
|
|
|
for (list = GIMP_LIST (image->vectors)->list;
|
2003-09-03 18:19:47 +08:00
|
|
|
list;
|
2003-05-20 18:36:29 +08:00
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
item = (GimpItem *) list->data;
|
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_item_rotate (item, context, rotate_type, center_x, center_y, FALSE);
|
2003-05-20 18:36:29 +08:00
|
|
|
|
2003-05-24 06:50:03 +08:00
|
|
|
item->width = new_image_width;
|
|
|
|
item->height = new_image_height;
|
|
|
|
item->offset_x = 0;
|
|
|
|
item->offset_y = 0;
|
2003-09-03 18:19:47 +08:00
|
|
|
|
2003-05-24 06:50:03 +08:00
|
|
|
gimp_item_translate (item,
|
2006-04-12 20:49:29 +08:00
|
|
|
(new_image_width - image->width) / 2,
|
|
|
|
(new_image_height - image->height) / 2,
|
|
|
|
FALSE);
|
2003-05-20 23:26:38 +08:00
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
if (progress)
|
|
|
|
gimp_progress_set_value (progress, progress_current++ / progress_max);
|
2003-05-20 18:36:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't forget the selection mask! */
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_item_rotate (GIMP_ITEM (gimp_image_get_mask (image)), context,
|
2003-05-20 23:26:38 +08:00
|
|
|
rotate_type, center_x, center_y, FALSE);
|
2003-05-24 06:50:03 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
GIMP_ITEM (image->selection_mask)->offset_x = 0;
|
|
|
|
GIMP_ITEM (image->selection_mask)->offset_y = 0;
|
2003-05-24 06:50:03 +08:00
|
|
|
|
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-20 18:36:29 +08:00
|
|
|
/* Rotate all layers */
|
2006-03-29 01:08:36 +08:00
|
|
|
for (list = GIMP_LIST (image->layers)->list;
|
2003-05-20 23:26:38 +08:00
|
|
|
list;
|
2003-05-20 18:36:29 +08:00
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
2003-05-20 23:26:38 +08:00
|
|
|
gint off_x, off_y;
|
|
|
|
|
2003-05-20 18:36:29 +08:00
|
|
|
item = (GimpItem *) list->data;
|
|
|
|
|
2003-05-20 23:26:38 +08:00
|
|
|
gimp_item_offsets (item, &off_x, &off_y);
|
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_item_rotate (item, context, rotate_type, center_x, center_y, FALSE);
|
2003-05-20 18:36:29 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_rotate_item_offset (image, rotate_type, item, off_x, off_y);
|
2003-05-20 23:26:38 +08:00
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
if (progress)
|
|
|
|
gimp_progress_set_value (progress, progress_current++ / progress_max);
|
2003-05-20 18:36:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Rotate all Guides */
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_rotate_guides (image, rotate_type);
|
2003-05-20 18:36:29 +08:00
|
|
|
|
2005-03-05 00:34:59 +08:00
|
|
|
/* Rotate all sample points */
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_rotate_sample_points (image, rotate_type);
|
2005-03-05 00:34:59 +08:00
|
|
|
|
2003-05-20 23:26:38 +08:00
|
|
|
/* Resize the image (if needed) */
|
|
|
|
if (size_changed)
|
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_push_image_size (image, NULL);
|
2003-05-20 23:26:38 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_object_set (image,
|
2004-07-14 20:12:50 +08:00
|
|
|
"width", new_image_width,
|
|
|
|
"height", new_image_height,
|
|
|
|
NULL);
|
2003-05-20 23:26:38 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (image->xresolution != image->yresolution)
|
2003-05-20 23:26:38 +08:00
|
|
|
{
|
|
|
|
gdouble tmp;
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_push_image_resolution (image, NULL);
|
2003-05-20 23:26:38 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
tmp = image->xresolution;
|
|
|
|
image->yresolution = image->xresolution;
|
|
|
|
image->xresolution = tmp;
|
2003-05-20 23:26:38 +08:00
|
|
|
}
|
|
|
|
}
|
2003-05-20 18:36:29 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_group_end (image);
|
2003-05-20 18:36:29 +08:00
|
|
|
|
2003-05-20 19:55:12 +08:00
|
|
|
if (size_changed)
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_viewable_size_changed (GIMP_VIEWABLE (image));
|
2003-05-20 19:55:12 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_object_thaw_notify (G_OBJECT (image));
|
2004-07-14 20:12:50 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_unset_busy (image->gimp);
|
2003-05-20 18:36:29 +08:00
|
|
|
}
|
2003-05-20 19:55:12 +08:00
|
|
|
|
2003-05-24 06:50:03 +08:00
|
|
|
|
|
|
|
static void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_rotate_item_offset (GimpImage *image,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpRotationType rotate_type,
|
|
|
|
GimpItem *item,
|
|
|
|
gint off_x,
|
|
|
|
gint off_y)
|
2003-05-24 06:50:03 +08:00
|
|
|
{
|
2003-06-04 00:42:46 +08:00
|
|
|
gint x = 0;
|
|
|
|
gint y = 0;
|
2003-05-24 06:50:03 +08:00
|
|
|
|
|
|
|
switch (rotate_type)
|
|
|
|
{
|
|
|
|
case GIMP_ROTATE_90:
|
2006-03-29 01:08:36 +08:00
|
|
|
x = image->height - off_y - gimp_item_width (item);
|
2003-06-04 00:42:46 +08:00
|
|
|
y = off_x;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ROTATE_270:
|
|
|
|
x = off_y;
|
2006-03-29 01:08:36 +08:00
|
|
|
y = image->width - off_x - gimp_item_height (item);
|
2003-05-24 06:50:03 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ROTATE_180:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_item_offsets (item, &off_x, &off_y);
|
|
|
|
|
|
|
|
x -= off_x;
|
|
|
|
y -= off_y;
|
2003-09-03 18:19:47 +08:00
|
|
|
|
2003-05-24 06:50:03 +08:00
|
|
|
if (x || y)
|
|
|
|
gimp_item_translate (item, x, y, FALSE);
|
|
|
|
}
|
|
|
|
|
2003-05-20 19:55:12 +08:00
|
|
|
static void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_rotate_guides (GimpImage *image,
|
2003-05-20 19:55:12 +08:00
|
|
|
GimpRotationType rotate_type)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
/* Rotate all Guides */
|
2006-03-29 01:08:36 +08:00
|
|
|
for (list = image->guides; list; list = g_list_next (list))
|
2003-05-20 19:55:12 +08:00
|
|
|
{
|
|
|
|
GimpGuide *guide = list->data;
|
|
|
|
|
|
|
|
switch (rotate_type)
|
|
|
|
{
|
|
|
|
case GIMP_ROTATE_90:
|
|
|
|
switch (guide->orientation)
|
|
|
|
{
|
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_push_image_guide (image, NULL, guide);
|
2003-05-20 19:55:12 +08:00
|
|
|
guide->orientation = GIMP_ORIENTATION_VERTICAL;
|
2006-03-29 01:08:36 +08:00
|
|
|
guide->position = image->height - guide->position;
|
2003-05-20 19:55:12 +08:00
|
|
|
break;
|
2003-09-03 18:19:47 +08:00
|
|
|
|
2003-05-20 19:55:12 +08:00
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_push_image_guide (image, NULL, guide);
|
2003-05-20 19:55:12 +08:00
|
|
|
guide->orientation = GIMP_ORIENTATION_HORIZONTAL;
|
|
|
|
break;
|
2003-09-03 18:19:47 +08:00
|
|
|
|
2003-05-20 19:55:12 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ROTATE_180:
|
|
|
|
switch (guide->orientation)
|
|
|
|
{
|
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_move_guide (image, guide,
|
|
|
|
image->height - guide->position, TRUE);
|
2003-05-20 19:55:12 +08:00
|
|
|
break;
|
2003-09-03 18:19:47 +08:00
|
|
|
|
2003-05-20 19:55:12 +08:00
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_move_guide (image, guide,
|
|
|
|
image->width - guide->position, TRUE);
|
2003-05-20 19:55:12 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ROTATE_270:
|
|
|
|
switch (guide->orientation)
|
|
|
|
{
|
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_push_image_guide (image, NULL, guide);
|
2003-05-20 19:55:12 +08:00
|
|
|
guide->orientation = GIMP_ORIENTATION_VERTICAL;
|
|
|
|
break;
|
2003-09-03 18:19:47 +08:00
|
|
|
|
2003-05-20 19:55:12 +08:00
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_push_image_guide (image, NULL, guide);
|
2003-05-20 19:55:12 +08:00
|
|
|
guide->orientation = GIMP_ORIENTATION_HORIZONTAL;
|
2006-03-29 01:08:36 +08:00
|
|
|
guide->position = image->width - guide->position;
|
2003-05-20 19:55:12 +08:00
|
|
|
break;
|
2003-09-03 18:19:47 +08:00
|
|
|
|
2003-05-20 19:55:12 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2003-05-20 19:55:12 +08:00
|
|
|
}
|
|
|
|
}
|
2005-03-05 00:34:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_rotate_sample_points (GimpImage *image,
|
2005-03-05 00:34:59 +08:00
|
|
|
GimpRotationType rotate_type)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
/* Rotate all sample points */
|
2006-03-29 01:08:36 +08:00
|
|
|
for (list = image->sample_points; list; list = g_list_next (list))
|
2005-03-05 00:34:59 +08:00
|
|
|
{
|
|
|
|
GimpSamplePoint *sample_point = list->data;
|
|
|
|
gint old_x;
|
|
|
|
gint old_y;
|
|
|
|
|
|
|
|
old_x = sample_point->x;
|
|
|
|
old_y = sample_point->y;
|
|
|
|
|
|
|
|
switch (rotate_type)
|
|
|
|
{
|
|
|
|
case GIMP_ROTATE_90:
|
|
|
|
sample_point->x = old_y;
|
2006-03-29 01:08:36 +08:00
|
|
|
sample_point->y = image->height - old_x;
|
2005-03-05 00:34:59 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ROTATE_180:
|
2006-03-29 01:08:36 +08:00
|
|
|
sample_point->x = image->height - old_x;
|
|
|
|
sample_point->y = image->width - old_y;
|
2005-03-05 00:34:59 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ROTATE_270:
|
2006-03-29 01:08:36 +08:00
|
|
|
sample_point->x = image->width - old_y;
|
2005-03-05 00:34:59 +08:00
|
|
|
sample_point->y = old_x;
|
|
|
|
break;
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2005-03-05 00:34:59 +08:00
|
|
|
}
|
|
|
|
}
|