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
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-05-19 02:48:36 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-05-19 02:48:36 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2003-05-19 02:48:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2003-05-19 02:48:36 +08:00
|
|
|
|
2019-08-11 03:48:49 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2003-05-19 02:48:36 +08:00
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "gimp.h"
|
2019-08-11 03:48:49 +08:00
|
|
|
#include "gimpchannel.h"
|
2008-11-03 04:46:57 +08:00
|
|
|
#include "gimpcontainer.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"
|
app: use GimpObjectQueue in lots of places
Use GimpObjectQueue, added in the previous commit, in various
instances where we perform an action on a set of objects. This
improves progress reporting, by using a single progress for the
entire operation, rather than reporting the progress of each object
individually, and by taking the relative cost of each object into
account, instead of assuming a uniform cost for all objects.
In particular, this affects the various whole-image operations
(i.e., transformations and color conversions), operations on linked
items, and operations on layer groups. This also affects layers
with masks, whose progress is now reported together instead of
individually.
Additionally, this commit fixes erroneous group-layer mask cropping
during undo when resizing the image, by properly calling
{start,end}_move() on all the resized layers before starting the
operation, and when scaling the image, by only scaling top-level
layers, and letting group layers scale their children themselves.
2018-03-25 22:18:46 +08:00
|
|
|
#include "gimpobjectqueue.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
|
|
|
|
|
|
|
|
2019-08-11 03:48:49 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
|
|
|
static void gimp_image_flip_guides (GimpImage *image,
|
|
|
|
GimpOrientationType flip_type,
|
|
|
|
gdouble axis);
|
|
|
|
static void gimp_image_flip_sample_points (GimpImage *image,
|
|
|
|
GimpOrientationType flip_type,
|
|
|
|
gdouble axis);
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_image_flip_guides (GimpImage *image,
|
|
|
|
GimpOrientationType flip_type,
|
|
|
|
gdouble axis)
|
|
|
|
{
|
|
|
|
gint width = gimp_image_get_width (image);
|
|
|
|
gint height = gimp_image_get_height (image);
|
|
|
|
GList *iter;
|
|
|
|
|
|
|
|
for (iter = gimp_image_get_guides (image); iter;)
|
|
|
|
{
|
|
|
|
GimpGuide *guide = iter->data;
|
|
|
|
gint position = gimp_guide_get_position (guide);
|
|
|
|
|
|
|
|
iter = g_list_next (iter);
|
|
|
|
|
|
|
|
position = SIGNED_ROUND (2.0 * axis - position);
|
|
|
|
|
|
|
|
switch (gimp_guide_get_orientation (guide))
|
|
|
|
{
|
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
|
|
|
if (flip_type == GIMP_ORIENTATION_VERTICAL)
|
|
|
|
{
|
|
|
|
if (position >= 0 && position <= height)
|
|
|
|
gimp_image_move_guide (image, guide, position, TRUE);
|
|
|
|
else
|
|
|
|
gimp_image_remove_guide (image, guide, TRUE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
|
|
|
if (flip_type == GIMP_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
if (position >= 0 && position <= width)
|
|
|
|
gimp_image_move_guide (image, guide, position, TRUE);
|
|
|
|
else
|
|
|
|
gimp_image_remove_guide (image, guide, TRUE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ORIENTATION_UNKNOWN:
|
|
|
|
g_return_if_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_image_flip_sample_points (GimpImage *image,
|
|
|
|
GimpOrientationType flip_type,
|
|
|
|
gdouble axis)
|
|
|
|
{
|
|
|
|
gint width = gimp_image_get_width (image);
|
|
|
|
gint height = gimp_image_get_height (image);
|
|
|
|
GList *iter;
|
|
|
|
|
|
|
|
for (iter = gimp_image_get_sample_points (image); iter;)
|
|
|
|
{
|
|
|
|
GimpSamplePoint *sample_point = iter->data;
|
|
|
|
gint x;
|
|
|
|
gint y;
|
|
|
|
|
|
|
|
iter = g_list_next (iter);
|
|
|
|
|
|
|
|
gimp_sample_point_get_position (sample_point, &x, &y);
|
|
|
|
|
|
|
|
switch (flip_type)
|
|
|
|
{
|
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
|
|
|
x = SIGNED_ROUND (2.0 * axis - x);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
|
|
|
y = SIGNED_ROUND (2.0 * axis - y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ORIENTATION_UNKNOWN:
|
|
|
|
g_return_if_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x >= 0 && x < width &&
|
|
|
|
y >= 0 && y < height)
|
|
|
|
{
|
|
|
|
gimp_image_move_sample_point (image, sample_point, x, y, TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_image_remove_sample_point (image, sample_point, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
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
|
|
|
{
|
2019-08-11 03:48:49 +08:00
|
|
|
gdouble axis = 0.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
|
|
|
|
|
|
|
switch (flip_type)
|
|
|
|
{
|
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
2019-08-11 03:48:49 +08:00
|
|
|
axis = gimp_image_get_width (image) / 2.0;
|
2003-05-19 02:48:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
2019-08-11 03:48:49 +08:00
|
|
|
axis = gimp_image_get_height (image) / 2.0;
|
2003-05-19 02:48:36 +08:00
|
|
|
break;
|
|
|
|
|
2019-08-11 03:48:49 +08:00
|
|
|
case GIMP_ORIENTATION_UNKNOWN:
|
|
|
|
g_return_if_reached ();
|
2003-05-19 02:48:36 +08:00
|
|
|
}
|
|
|
|
|
2019-08-11 03:48:49 +08:00
|
|
|
gimp_image_flip_full (image, context, flip_type, axis,
|
|
|
|
GIMP_TRANSFORM_RESIZE_CLIP, progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_image_flip_full (GimpImage *image,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpOrientationType flip_type,
|
|
|
|
gdouble axis,
|
|
|
|
gboolean clip_result,
|
|
|
|
GimpProgress *progress)
|
|
|
|
{
|
|
|
|
GimpObjectQueue *queue;
|
|
|
|
GimpItem *item;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint offset_x = 0;
|
|
|
|
gint offset_y = 0;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
|
|
|
g_return_if_fail (GIMP_IS_CONTEXT (context));
|
|
|
|
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
|
|
|
|
|
|
|
|
width = gimp_image_get_width (image);
|
|
|
|
height = gimp_image_get_height (image);
|
|
|
|
|
|
|
|
if (! clip_result)
|
|
|
|
{
|
|
|
|
switch (flip_type)
|
|
|
|
{
|
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
|
|
|
offset_x = SIGNED_ROUND (2.0 * axis - width);
|
|
|
|
axis = width / 2.0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
|
|
|
offset_y = SIGNED_ROUND (2.0 * axis - height);
|
|
|
|
axis = height / 2.0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ORIENTATION_UNKNOWN:
|
|
|
|
g_return_if_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_set_busy (image->gimp);
|
|
|
|
|
app: use GimpObjectQueue in lots of places
Use GimpObjectQueue, added in the previous commit, in various
instances where we perform an action on a set of objects. This
improves progress reporting, by using a single progress for the
entire operation, rather than reporting the progress of each object
individually, and by taking the relative cost of each object into
account, instead of assuming a uniform cost for all objects.
In particular, this affects the various whole-image operations
(i.e., transformations and color conversions), operations on linked
items, and operations on layer groups. This also affects layers
with masks, whose progress is now reported together instead of
individually.
Additionally, this commit fixes erroneous group-layer mask cropping
during undo when resizing the image, by properly calling
{start,end}_move() on all the resized layers before starting the
operation, and when scaling the image, by only scaling top-level
layers, and letting group layers scale their children themselves.
2018-03-25 22:18:46 +08:00
|
|
|
queue = gimp_object_queue_new (progress);
|
|
|
|
progress = GIMP_PROGRESS (queue);
|
2003-05-19 02:48:36 +08:00
|
|
|
|
app: use GimpObjectQueue in lots of places
Use GimpObjectQueue, added in the previous commit, in various
instances where we perform an action on a set of objects. This
improves progress reporting, by using a single progress for the
entire operation, rather than reporting the progress of each object
individually, and by taking the relative cost of each object into
account, instead of assuming a uniform cost for all objects.
In particular, this affects the various whole-image operations
(i.e., transformations and color conversions), operations on linked
items, and operations on layer groups. This also affects layers
with masks, whose progress is now reported together instead of
individually.
Additionally, this commit fixes erroneous group-layer mask cropping
during undo when resizing the image, by properly calling
{start,end}_move() on all the resized layers before starting the
operation, and when scaling the image, by only scaling top-level
layers, and letting group layers scale their children themselves.
2018-03-25 22:18:46 +08:00
|
|
|
gimp_object_queue_push_container (queue, gimp_image_get_layers (image));
|
|
|
|
gimp_object_queue_push (queue, gimp_image_get_mask (image));
|
|
|
|
gimp_object_queue_push_container (queue, gimp_image_get_channels (image));
|
2024-07-11 08:07:44 +08:00
|
|
|
gimp_object_queue_push_container (queue, gimp_image_get_paths (image));
|
2003-05-19 02:48:36 +08:00
|
|
|
|
app: use GimpObjectQueue in lots of places
Use GimpObjectQueue, added in the previous commit, in various
instances where we perform an action on a set of objects. This
improves progress reporting, by using a single progress for the
entire operation, rather than reporting the progress of each object
individually, and by taking the relative cost of each object into
account, instead of assuming a uniform cost for all objects.
In particular, this affects the various whole-image operations
(i.e., transformations and color conversions), operations on linked
items, and operations on layer groups. This also affects layers
with masks, whose progress is now reported together instead of
individually.
Additionally, this commit fixes erroneous group-layer mask cropping
during undo when resizing the image, by properly calling
{start,end}_move() on all the resized layers before starting the
operation, and when scaling the image, by only scaling top-level
layers, and letting group layers scale their children themselves.
2018-03-25 22:18:46 +08:00
|
|
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_FLIP, NULL);
|
2003-06-04 00:42:46 +08:00
|
|
|
|
app: use GimpObjectQueue in lots of places
Use GimpObjectQueue, added in the previous commit, in various
instances where we perform an action on a set of objects. This
improves progress reporting, by using a single progress for the
entire operation, rather than reporting the progress of each object
individually, and by taking the relative cost of each object into
account, instead of assuming a uniform cost for all objects.
In particular, this affects the various whole-image operations
(i.e., transformations and color conversions), operations on linked
items, and operations on layer groups. This also affects layers
with masks, whose progress is now reported together instead of
individually.
Additionally, this commit fixes erroneous group-layer mask cropping
during undo when resizing the image, by properly calling
{start,end}_move() on all the resized layers before starting the
operation, and when scaling the image, by only scaling top-level
layers, and letting group layers scale their children themselves.
2018-03-25 22:18:46 +08:00
|
|
|
/* Flip all layers, channels (including selection mask), and vectors */
|
|
|
|
while ((item = gimp_object_queue_pop (queue)))
|
2003-05-19 02:48:36 +08:00
|
|
|
{
|
2019-08-11 03:48:49 +08:00
|
|
|
gboolean clip = FALSE;
|
|
|
|
|
|
|
|
if (GIMP_IS_CHANNEL (item))
|
|
|
|
clip = clip_result;
|
|
|
|
|
|
|
|
gimp_item_flip (item, context, flip_type, axis, clip);
|
2003-05-19 02:48:36 +08:00
|
|
|
|
app: use GimpObjectQueue in lots of places
Use GimpObjectQueue, added in the previous commit, in various
instances where we perform an action on a set of objects. This
improves progress reporting, by using a single progress for the
entire operation, rather than reporting the progress of each object
individually, and by taking the relative cost of each object into
account, instead of assuming a uniform cost for all objects.
In particular, this affects the various whole-image operations
(i.e., transformations and color conversions), operations on linked
items, and operations on layer groups. This also affects layers
with masks, whose progress is now reported together instead of
individually.
Additionally, this commit fixes erroneous group-layer mask cropping
during undo when resizing the image, by properly calling
{start,end}_move() on all the resized layers before starting the
operation, and when scaling the image, by only scaling top-level
layers, and letting group layers scale their children themselves.
2018-03-25 22:18:46 +08:00
|
|
|
gimp_progress_set_value (progress, 1.0);
|
2003-05-19 02:48:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Flip all Guides */
|
2019-08-11 03:48:49 +08:00
|
|
|
gimp_image_flip_guides (image, flip_type, axis);
|
2003-05-19 02:48:36 +08:00
|
|
|
|
2005-03-05 00:34:59 +08:00
|
|
|
/* Flip all sample points */
|
2019-08-11 03:48:49 +08:00
|
|
|
gimp_image_flip_sample_points (image, flip_type, axis);
|
2016-01-05 05:06:27 +08:00
|
|
|
|
2019-08-11 03:48:49 +08:00
|
|
|
if (offset_x || offset_y)
|
|
|
|
{
|
|
|
|
gimp_image_undo_push_image_size (image,
|
|
|
|
NULL,
|
|
|
|
offset_x,
|
|
|
|
offset_y,
|
|
|
|
width,
|
|
|
|
height);
|
2005-03-05 00:34:59 +08:00
|
|
|
}
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_group_end (image);
|
2003-05-19 02:48:36 +08:00
|
|
|
|
app: use GimpObjectQueue in lots of places
Use GimpObjectQueue, added in the previous commit, in various
instances where we perform an action on a set of objects. This
improves progress reporting, by using a single progress for the
entire operation, rather than reporting the progress of each object
individually, and by taking the relative cost of each object into
account, instead of assuming a uniform cost for all objects.
In particular, this affects the various whole-image operations
(i.e., transformations and color conversions), operations on linked
items, and operations on layer groups. This also affects layers
with masks, whose progress is now reported together instead of
individually.
Additionally, this commit fixes erroneous group-layer mask cropping
during undo when resizing the image, by properly calling
{start,end}_move() on all the resized layers before starting the
operation, and when scaling the image, by only scaling top-level
layers, and letting group layers scale their children themselves.
2018-03-25 22:18:46 +08:00
|
|
|
g_object_unref (queue);
|
|
|
|
|
2019-08-11 03:48:49 +08:00
|
|
|
if (offset_x || offset_y)
|
|
|
|
{
|
|
|
|
gimp_image_size_changed_detailed (image,
|
|
|
|
-offset_x,
|
|
|
|
-offset_y,
|
|
|
|
width,
|
|
|
|
height);
|
|
|
|
}
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_unset_busy (image->gimp);
|
2003-05-19 02:48:36 +08:00
|
|
|
}
|