2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-05-19 02:48:36 +08:00
|
|
|
* 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"
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2003-05-19 02:48:36 +08:00
|
|
|
|
|
|
|
#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-19 02:48:36 +08:00
|
|
|
#include "gimpimage.h"
|
|
|
|
#include "gimpimage-flip.h"
|
|
|
|
#include "gimpimage-guides.h"
|
2005-03-05 00:34:59 +08:00
|
|
|
#include "gimpimage-sample-points.h"
|
2003-05-19 02:48:36 +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"
|
2007-01-30 18:34:59 +08:00
|
|
|
#include "gimpsamplepoint.h"
|
2003-05-19 02:48:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_flip (GimpImage *image,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2003-05-19 02:48:36 +08:00
|
|
|
GimpOrientationType flip_type,
|
2004-08-11 02:47:21 +08:00
|
|
|
GimpProgress *progress)
|
2003-05-19 02:48:36 +08:00
|
|
|
{
|
2007-02-28 16:57:17 +08:00
|
|
|
GList *list;
|
|
|
|
gdouble axis;
|
|
|
|
gdouble progress_max;
|
|
|
|
gdouble progress_current = 1.0;
|
2003-05-19 02:48:36 +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-19 02:48:36 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_set_busy (image->gimp);
|
2003-05-19 02:48:36 +08:00
|
|
|
|
|
|
|
switch (flip_type)
|
|
|
|
{
|
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
2007-12-26 00:21:40 +08:00
|
|
|
axis = (gdouble) gimp_image_get_width (image) / 2.0;
|
2003-05-19 02:48:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
2007-12-26 00:21:40 +08:00
|
|
|
axis = (gdouble) gimp_image_get_height (image) / 2.0;
|
2003-05-19 02:48:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-05-12 16:13:33 +08:00
|
|
|
g_warning ("%s: unknown flip_type", G_STRFUNC);
|
2003-05-19 02:48:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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-19 02:48:36 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_FLIP, NULL);
|
2003-05-19 02:48:36 +08:00
|
|
|
|
|
|
|
/* Flip 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-19 02:48:36 +08:00
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
2007-02-28 16:57:17 +08:00
|
|
|
GimpItem *item = list->data;
|
2003-05-19 02:48:36 +08:00
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_item_flip (item, context, flip_type, axis, TRUE);
|
2003-05-19 02:48:36 +08:00
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
if (progress)
|
|
|
|
gimp_progress_set_value (progress, progress_current++ / progress_max);
|
2003-05-19 02:48:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Flip 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-19 02:48:36 +08:00
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
2007-02-28 16:57:17 +08:00
|
|
|
GimpItem *item = list->data;
|
2003-05-19 02:48:36 +08:00
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_item_flip (item, context, flip_type, axis, FALSE);
|
2003-05-19 02:48:36 +08:00
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
if (progress)
|
|
|
|
gimp_progress_set_value (progress, progress_current++ / progress_max);
|
2003-05-19 02:48:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't forget the selection mask! */
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_item_flip (GIMP_ITEM (gimp_image_get_mask (image)), context,
|
2003-09-03 18:19:47 +08:00
|
|
|
flip_type, axis, TRUE);
|
2003-05-19 02:48:36 +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-19 02:48:36 +08:00
|
|
|
/* Flip all layers */
|
2006-03-29 01:08:36 +08:00
|
|
|
for (list = GIMP_LIST (image->layers)->list;
|
2003-09-03 18:19:47 +08:00
|
|
|
list;
|
2003-05-19 02:48:36 +08:00
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
2007-02-28 16:57:17 +08:00
|
|
|
GimpItem *item = list->data;
|
2003-05-19 02:48:36 +08:00
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_item_flip (item, context, flip_type, axis, FALSE);
|
2003-05-19 02:48:36 +08:00
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
if (progress)
|
|
|
|
gimp_progress_set_value (progress, progress_current++ / progress_max);
|
2003-05-19 02:48:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Flip all Guides */
|
2007-12-26 01:09:04 +08:00
|
|
|
for (list = gimp_image_get_guides (image); list; list = g_list_next (list))
|
2003-05-19 02:48:36 +08:00
|
|
|
{
|
2006-06-07 23:49:59 +08:00
|
|
|
GimpGuide *guide = list->data;
|
|
|
|
gint position = gimp_guide_get_position (guide);
|
2003-05-19 02:48:36 +08:00
|
|
|
|
2006-06-07 23:49:59 +08:00
|
|
|
switch (gimp_guide_get_orientation (guide))
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
2003-05-19 02:48:36 +08:00
|
|
|
if (flip_type == GIMP_ORIENTATION_VERTICAL)
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_move_guide (image, guide,
|
2007-12-26 00:21:40 +08:00
|
|
|
gimp_image_get_height (image) - position,
|
|
|
|
TRUE);
|
2006-04-12 20:49:29 +08:00
|
|
|
break;
|
2003-05-19 02:48:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
2003-05-19 02:48:36 +08:00
|
|
|
if (flip_type == GIMP_ORIENTATION_HORIZONTAL)
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_move_guide (image, guide,
|
2007-12-26 00:21:40 +08:00
|
|
|
gimp_image_get_width (image) - position,
|
|
|
|
TRUE);
|
2006-04-12 20:49:29 +08:00
|
|
|
break;
|
2003-05-19 02:48:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
default:
|
2003-05-19 02:48:36 +08:00
|
|
|
break;
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2003-05-19 02:48:36 +08:00
|
|
|
}
|
|
|
|
|
2005-03-05 00:34:59 +08:00
|
|
|
/* Flip all sample points */
|
2007-12-26 01:09:04 +08:00
|
|
|
for (list = gimp_image_get_sample_points (image); list; list = g_list_next (list))
|
2005-03-05 00:34:59 +08:00
|
|
|
{
|
|
|
|
GimpSamplePoint *sample_point = list->data;
|
|
|
|
|
|
|
|
if (flip_type == GIMP_ORIENTATION_VERTICAL)
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_move_sample_point (image, sample_point,
|
2005-03-05 00:34:59 +08:00
|
|
|
sample_point->x,
|
2007-12-26 00:21:40 +08:00
|
|
|
gimp_image_get_height (image) -
|
|
|
|
sample_point->y,
|
2005-03-05 00:34:59 +08:00
|
|
|
TRUE);
|
|
|
|
|
|
|
|
if (flip_type == GIMP_ORIENTATION_HORIZONTAL)
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_move_sample_point (image, sample_point,
|
2007-12-26 00:21:40 +08:00
|
|
|
gimp_image_get_width (image) -
|
|
|
|
sample_point->x,
|
2005-03-05 00:34:59 +08:00
|
|
|
sample_point->y,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_group_end (image);
|
2003-05-19 02:48:36 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_unset_busy (image->gimp);
|
2003-05-19 02:48:36 +08:00
|
|
|
}
|