2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2006-09-08 01:10:22 +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
|
2006-09-08 01:10:22 +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
|
2006-09-08 01:10:22 +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/>.
|
2006-09-08 01:10:22 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.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>
|
2006-09-08 01:10:22 +08:00
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
2007-04-09 19:54:44 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2006-09-08 01:10:22 +08:00
|
|
|
|
|
|
|
#include "paint-types.h"
|
|
|
|
|
2012-03-31 22:18:13 +08:00
|
|
|
#include "gegl/gimp-gegl-nodes.h"
|
2012-03-30 02:12:09 +08:00
|
|
|
#include "gegl/gimp-gegl-utils.h"
|
2006-09-08 01:10:22 +08:00
|
|
|
|
|
|
|
#include "core/gimp.h"
|
2012-04-09 06:59:20 +08:00
|
|
|
#include "core/gimp-utils.h"
|
2021-08-20 05:24:40 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
2006-09-08 01:10:22 +08:00
|
|
|
#include "core/gimpdrawable.h"
|
2008-11-12 18:56:06 +08:00
|
|
|
#include "core/gimperror.h"
|
2006-09-08 01:10:22 +08:00
|
|
|
#include "core/gimpimage.h"
|
2021-08-20 05:24:40 +08:00
|
|
|
#include "core/gimpimage-new.h"
|
2012-11-02 04:39:14 +08:00
|
|
|
#include "core/gimppattern.h"
|
2006-09-08 01:10:22 +08:00
|
|
|
#include "core/gimppickable.h"
|
2016-01-28 02:13:17 +08:00
|
|
|
#include "core/gimpsymmetry.h"
|
2006-09-08 01:10:22 +08:00
|
|
|
|
|
|
|
#include "gimpperspectiveclone.h"
|
|
|
|
#include "gimpperspectivecloneoptions.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2012-11-02 04:39:14 +08:00
|
|
|
static void gimp_perspective_clone_paint (GimpPaintCore *paint_core,
|
2021-08-17 05:46:32 +08:00
|
|
|
GList *drawables,
|
2012-11-02 04:39:14 +08:00
|
|
|
GimpPaintOptions *paint_options,
|
2016-01-28 02:13:17 +08:00
|
|
|
GimpSymmetry *sym,
|
2012-11-02 04:39:14 +08:00
|
|
|
GimpPaintState paint_state,
|
|
|
|
guint32 time);
|
|
|
|
|
|
|
|
static gboolean gimp_perspective_clone_use_source (GimpSourceCore *source_core,
|
|
|
|
GimpSourceOptions *options);
|
|
|
|
static GeglBuffer * gimp_perspective_clone_get_source (GimpSourceCore *source_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
2021-08-18 20:23:30 +08:00
|
|
|
gboolean self_drawable,
|
2012-11-02 04:39:14 +08:00
|
|
|
GimpPickable *src_pickable,
|
|
|
|
gint src_offset_x,
|
|
|
|
gint src_offset_y,
|
|
|
|
GeglBuffer *paint_buffer,
|
|
|
|
gint paint_buffer_x,
|
|
|
|
gint paint_buffer_y,
|
|
|
|
gint *paint_area_offset_x,
|
|
|
|
gint *paint_area_offset_y,
|
|
|
|
gint *paint_area_width,
|
|
|
|
gint *paint_area_height,
|
|
|
|
GeglRectangle *src_rect);
|
2012-03-31 04:11:46 +08:00
|
|
|
|
|
|
|
static void gimp_perspective_clone_get_matrix (GimpPerspectiveClone *clone,
|
|
|
|
GimpMatrix3 *matrix);
|
2008-08-20 17:49:40 +08:00
|
|
|
|
2006-09-08 01:10:22 +08:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (GimpPerspectiveClone, gimp_perspective_clone,
|
2006-09-12 20:57:55 +08:00
|
|
|
GIMP_TYPE_CLONE)
|
|
|
|
|
|
|
|
#define parent_class gimp_perspective_clone_parent_class
|
2006-09-08 01:10:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_perspective_clone_register (Gimp *gimp,
|
|
|
|
GimpPaintRegisterCallback callback)
|
|
|
|
{
|
|
|
|
(* callback) (gimp,
|
|
|
|
GIMP_TYPE_PERSPECTIVE_CLONE,
|
|
|
|
GIMP_TYPE_PERSPECTIVE_CLONE_OPTIONS,
|
|
|
|
"gimp-perspective-clone",
|
2006-09-12 20:57:55 +08:00
|
|
|
_("Perspective Clone"),
|
2006-09-08 01:10:22 +08:00
|
|
|
"gimp-tool-perspective-clone");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_perspective_clone_class_init (GimpPerspectiveCloneClass *klass)
|
|
|
|
{
|
2006-09-12 20:57:55 +08:00
|
|
|
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
|
|
|
|
GimpSourceCoreClass *source_core_class = GIMP_SOURCE_CORE_CLASS (klass);
|
|
|
|
|
|
|
|
paint_core_class->paint = gimp_perspective_clone_paint;
|
|
|
|
|
2012-11-02 04:39:14 +08:00
|
|
|
source_core_class->use_source = gimp_perspective_clone_use_source;
|
2006-09-12 20:57:55 +08:00
|
|
|
source_core_class->get_source = gimp_perspective_clone_get_source;
|
2006-09-08 01:10:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_perspective_clone_init (GimpPerspectiveClone *clone)
|
|
|
|
{
|
2006-09-12 20:57:55 +08:00
|
|
|
clone->src_x_fv = 0.0; /* source coords in front_view perspective */
|
|
|
|
clone->src_y_fv = 0.0;
|
2006-09-08 01:10:22 +08:00
|
|
|
|
2006-09-12 20:57:55 +08:00
|
|
|
clone->dest_x_fv = 0.0; /* destination coords in front_view perspective */
|
|
|
|
clone->dest_y_fv = 0.0;
|
2006-09-08 01:10:22 +08:00
|
|
|
|
|
|
|
gimp_matrix3_identity (&clone->transform);
|
|
|
|
gimp_matrix3_identity (&clone->transform_inv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_perspective_clone_paint (GimpPaintCore *paint_core,
|
2021-08-17 05:46:32 +08:00
|
|
|
GList *drawables,
|
2006-09-08 01:10:22 +08:00
|
|
|
GimpPaintOptions *paint_options,
|
2016-01-28 02:13:17 +08:00
|
|
|
GimpSymmetry *sym,
|
2006-09-08 01:10:22 +08:00
|
|
|
GimpPaintState paint_state,
|
|
|
|
guint32 time)
|
|
|
|
{
|
2012-11-02 04:39:14 +08:00
|
|
|
GimpSourceCore *source_core = GIMP_SOURCE_CORE (paint_core);
|
|
|
|
GimpPerspectiveClone *clone = GIMP_PERSPECTIVE_CLONE (paint_core);
|
|
|
|
GimpContext *context = GIMP_CONTEXT (paint_options);
|
|
|
|
GimpCloneOptions *clone_options = GIMP_CLONE_OPTIONS (paint_options);
|
|
|
|
GimpSourceOptions *options = GIMP_SOURCE_OPTIONS (paint_options);
|
2016-01-28 02:13:17 +08:00
|
|
|
const GimpCoords *coords;
|
2021-08-18 20:23:30 +08:00
|
|
|
gboolean sample_merged;
|
2016-01-28 02:13:17 +08:00
|
|
|
|
|
|
|
/* The source is based on the original stroke */
|
2021-08-18 20:23:30 +08:00
|
|
|
coords = gimp_symmetry_get_origin (sym);
|
|
|
|
|
|
|
|
sample_merged = options->sample_merged && (g_list_length (drawables) > 1);
|
2006-09-08 01:10:22 +08:00
|
|
|
|
|
|
|
switch (paint_state)
|
|
|
|
{
|
|
|
|
case GIMP_PAINT_STATE_INIT:
|
2006-09-12 20:57:55 +08:00
|
|
|
if (source_core->set_source)
|
2006-09-08 01:10:22 +08:00
|
|
|
{
|
2022-02-05 05:44:54 +08:00
|
|
|
gint src_x = floor (coords->x);
|
|
|
|
gint src_y = floor (coords->y);
|
2006-09-08 01:10:22 +08:00
|
|
|
|
2022-02-05 05:44:54 +08:00
|
|
|
g_object_set (options,
|
|
|
|
"src-drawables", drawables,
|
|
|
|
"src-x", src_x,
|
|
|
|
"src-y", src_y,
|
|
|
|
NULL);
|
2006-09-08 01:10:22 +08:00
|
|
|
|
|
|
|
/* get source coordinates in front view perspective */
|
|
|
|
gimp_matrix3_transform_point (&clone->transform_inv,
|
2022-02-05 05:44:54 +08:00
|
|
|
src_x,
|
|
|
|
src_y,
|
2006-09-12 20:57:55 +08:00
|
|
|
&clone->src_x_fv,
|
|
|
|
&clone->src_y_fv);
|
2006-09-08 01:10:22 +08:00
|
|
|
|
2006-09-12 20:57:55 +08:00
|
|
|
source_core->first_stroke = TRUE;
|
2006-09-08 01:10:22 +08:00
|
|
|
}
|
2012-03-31 08:16:59 +08:00
|
|
|
else
|
2006-09-08 01:10:22 +08:00
|
|
|
{
|
2021-08-20 05:24:40 +08:00
|
|
|
GimpImage *del_image = NULL;
|
2012-11-02 04:39:14 +08:00
|
|
|
GeglBuffer *orig_buffer = NULL;
|
|
|
|
GeglNode *tile = NULL;
|
2012-03-31 21:40:21 +08:00
|
|
|
|
2012-03-31 08:16:59 +08:00
|
|
|
if (options->align_mode == GIMP_SOURCE_ALIGN_NO)
|
|
|
|
{
|
2022-02-05 05:44:54 +08:00
|
|
|
g_object_get (options,
|
|
|
|
"src-x", &source_core->orig_src_x,
|
|
|
|
"src-y", &source_core->orig_src_y,
|
|
|
|
NULL);
|
2006-09-08 01:10:22 +08:00
|
|
|
|
2012-03-31 08:16:59 +08:00
|
|
|
source_core->first_stroke = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
clone->node = gegl_node_new ();
|
|
|
|
|
|
|
|
g_object_set (clone->node,
|
2019-02-22 02:07:34 +08:00
|
|
|
"cache-policy", GEGL_CACHE_POLICY_NEVER,
|
2012-03-31 08:16:59 +08:00
|
|
|
NULL);
|
|
|
|
|
2012-11-02 04:39:14 +08:00
|
|
|
switch (clone_options->clone_type)
|
|
|
|
{
|
2014-04-30 02:55:08 +08:00
|
|
|
case GIMP_CLONE_IMAGE:
|
2012-11-02 04:39:14 +08:00
|
|
|
{
|
2021-08-20 05:24:40 +08:00
|
|
|
GimpPickable *src_pickable = NULL;
|
2012-11-02 04:39:14 +08:00
|
|
|
GimpImage *src_image;
|
|
|
|
GimpImage *dest_image;
|
|
|
|
|
|
|
|
/* If the source image is different from the
|
|
|
|
* destination, then we should copy straight from the
|
|
|
|
* source image to the canvas.
|
|
|
|
* Otherwise, we need a call to get_orig_image to make sure
|
|
|
|
* we get a copy of the unblemished (offset) image
|
|
|
|
*/
|
2021-09-04 05:39:03 +08:00
|
|
|
src_image = gimp_pickable_get_image (options->src_drawables->data);
|
2012-11-02 04:39:14 +08:00
|
|
|
|
2021-08-18 20:23:30 +08:00
|
|
|
if (sample_merged)
|
2013-09-14 05:29:06 +08:00
|
|
|
src_pickable = GIMP_PICKABLE (src_image);
|
2012-11-02 04:39:14 +08:00
|
|
|
|
2021-08-17 05:46:32 +08:00
|
|
|
dest_image = gimp_item_get_image (GIMP_ITEM (drawables->data));
|
2012-11-02 04:39:14 +08:00
|
|
|
|
2021-08-18 20:23:30 +08:00
|
|
|
if ((sample_merged &&
|
2012-11-02 04:39:14 +08:00
|
|
|
(src_image != dest_image)) ||
|
2021-08-20 05:24:40 +08:00
|
|
|
(! sample_merged &&
|
2021-09-04 05:39:03 +08:00
|
|
|
g_list_length (options->src_drawables) == 1 &&
|
2021-08-20 05:24:40 +08:00
|
|
|
g_list_length (drawables) == 1 &&
|
2021-09-04 05:39:03 +08:00
|
|
|
(options->src_drawables != drawables->data)))
|
2012-11-02 04:39:14 +08:00
|
|
|
{
|
2021-08-20 05:24:40 +08:00
|
|
|
if (! sample_merged)
|
2021-09-04 05:39:03 +08:00
|
|
|
src_pickable = GIMP_PICKABLE (options->src_drawables->data);
|
2021-08-20 05:24:40 +08:00
|
|
|
|
2012-11-02 04:39:14 +08:00
|
|
|
orig_buffer = gimp_pickable_get_buffer (src_pickable);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-20 05:24:40 +08:00
|
|
|
if (sample_merged && paint_core->use_saved_proj)
|
2012-11-02 04:39:14 +08:00
|
|
|
orig_buffer = gimp_paint_core_get_orig_proj (paint_core);
|
|
|
|
else
|
2021-08-17 05:46:32 +08:00
|
|
|
orig_buffer = gimp_paint_core_get_orig_image (paint_core, drawables->data);
|
2012-11-02 04:39:14 +08:00
|
|
|
}
|
2021-08-20 05:24:40 +08:00
|
|
|
|
|
|
|
if (! orig_buffer)
|
|
|
|
{
|
|
|
|
/* A composited image of the drawables */
|
|
|
|
del_image = gimp_image_new_from_drawables (src_image->gimp, drawables,
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
FALSE, FALSE);
|
2021-08-20 05:24:40 +08:00
|
|
|
gimp_container_remove (src_image->gimp->images, GIMP_OBJECT (del_image));
|
|
|
|
|
|
|
|
src_pickable = GIMP_PICKABLE (del_image);
|
|
|
|
gimp_pickable_flush (src_pickable);
|
|
|
|
|
|
|
|
orig_buffer = gimp_pickable_get_buffer (src_pickable);
|
|
|
|
}
|
2012-11-02 04:39:14 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-04-30 02:55:08 +08:00
|
|
|
case GIMP_CLONE_PATTERN:
|
2012-11-02 04:39:14 +08:00
|
|
|
{
|
|
|
|
GimpPattern *pattern = gimp_context_get_pattern (context);
|
|
|
|
|
|
|
|
orig_buffer = gimp_pattern_create_buffer (pattern);
|
|
|
|
|
|
|
|
tile = gegl_node_new_child (clone->node,
|
|
|
|
"operation", "gegl:tile",
|
|
|
|
NULL);
|
2012-11-11 03:49:14 +08:00
|
|
|
clone->crop = gegl_node_new_child (clone->node,
|
|
|
|
"operation", "gegl:crop",
|
|
|
|
NULL);
|
2012-11-02 04:39:14 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-08-20 05:24:40 +08:00
|
|
|
clone->src_node = gegl_node_new_child (clone->node,
|
|
|
|
"operation", "gegl:buffer-source",
|
|
|
|
"buffer", orig_buffer,
|
|
|
|
NULL);
|
2012-03-31 08:16:59 +08:00
|
|
|
|
|
|
|
clone->transform_node =
|
|
|
|
gegl_node_new_child (clone->node,
|
2013-06-04 07:16:13 +08:00
|
|
|
"operation", "gegl:transform",
|
2013-06-07 01:56:06 +08:00
|
|
|
"sampler", GIMP_INTERPOLATION_LINEAR,
|
2012-03-31 08:16:59 +08:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
clone->dest_node =
|
|
|
|
gegl_node_new_child (clone->node,
|
|
|
|
"operation", "gegl:write-buffer",
|
|
|
|
NULL);
|
|
|
|
|
2012-11-02 04:39:14 +08:00
|
|
|
if (tile)
|
|
|
|
{
|
2021-08-20 05:24:40 +08:00
|
|
|
gegl_node_link_many (clone->src_node,
|
2012-11-11 03:49:14 +08:00
|
|
|
tile,
|
|
|
|
clone->crop,
|
2012-11-02 04:39:14 +08:00
|
|
|
clone->transform_node,
|
|
|
|
clone->dest_node,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_object_unref (orig_buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-20 05:24:40 +08:00
|
|
|
gegl_node_link_many (clone->src_node,
|
2012-11-02 04:39:14 +08:00
|
|
|
clone->transform_node,
|
|
|
|
clone->dest_node,
|
|
|
|
NULL);
|
|
|
|
}
|
2021-08-20 05:24:40 +08:00
|
|
|
|
|
|
|
g_clear_object (&del_image);
|
2006-09-08 01:10:22 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_PAINT_STATE_MOTION:
|
2006-09-12 20:57:55 +08:00
|
|
|
if (source_core->set_source)
|
2006-09-08 01:10:22 +08:00
|
|
|
{
|
2022-02-05 05:44:54 +08:00
|
|
|
gint src_x = floor (coords->x);
|
|
|
|
gint src_y = floor (coords->y);
|
|
|
|
|
2006-09-08 01:10:22 +08:00
|
|
|
/* If the control key is down, move the src target and return */
|
|
|
|
|
2022-02-05 05:44:54 +08:00
|
|
|
g_object_set (options,
|
|
|
|
"src-drawables", drawables,
|
|
|
|
"src-x", src_x,
|
|
|
|
"src-y", src_y,
|
|
|
|
NULL);
|
2006-09-08 01:10:22 +08:00
|
|
|
|
|
|
|
/* get source coordinates in front view perspective */
|
|
|
|
gimp_matrix3_transform_point (&clone->transform_inv,
|
2022-02-05 05:44:54 +08:00
|
|
|
src_x,
|
|
|
|
src_y,
|
2006-09-12 20:57:55 +08:00
|
|
|
&clone->src_x_fv,
|
|
|
|
&clone->src_y_fv);
|
2006-09-08 01:10:22 +08:00
|
|
|
|
2006-09-12 20:57:55 +08:00
|
|
|
source_core->first_stroke = TRUE;
|
2006-09-08 01:10:22 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* otherwise, update the target */
|
|
|
|
|
2022-02-05 05:44:54 +08:00
|
|
|
gint src_x;
|
|
|
|
gint src_y;
|
|
|
|
|
2006-09-08 01:10:22 +08:00
|
|
|
gint dest_x;
|
|
|
|
gint dest_y;
|
2016-01-28 02:13:17 +08:00
|
|
|
gint n_strokes;
|
|
|
|
gint i;
|
2006-09-08 01:10:22 +08:00
|
|
|
|
2022-02-05 05:44:54 +08:00
|
|
|
g_object_get (options,
|
|
|
|
"src-x", &src_x,
|
|
|
|
"src-y", &src_y,
|
|
|
|
NULL);
|
|
|
|
|
2016-01-28 02:13:17 +08:00
|
|
|
n_strokes = gimp_symmetry_get_size (sym);
|
|
|
|
for (i = 0; i < n_strokes; i++)
|
2006-09-08 01:10:22 +08:00
|
|
|
{
|
2016-01-28 02:13:17 +08:00
|
|
|
coords = gimp_symmetry_get_coords (sym, i);
|
|
|
|
|
2017-04-03 23:37:58 +08:00
|
|
|
dest_x = floor (coords->x);
|
|
|
|
dest_y = floor (coords->y);
|
2016-01-28 02:13:17 +08:00
|
|
|
|
|
|
|
if (options->align_mode == GIMP_SOURCE_ALIGN_REGISTERED)
|
|
|
|
{
|
|
|
|
source_core->offset_x = 0;
|
|
|
|
source_core->offset_y = 0;
|
|
|
|
}
|
|
|
|
else if (options->align_mode == GIMP_SOURCE_ALIGN_FIXED)
|
|
|
|
{
|
2022-02-05 05:44:54 +08:00
|
|
|
source_core->offset_x = src_x - dest_x;
|
|
|
|
source_core->offset_y = src_y - dest_y;
|
2016-01-28 02:13:17 +08:00
|
|
|
}
|
|
|
|
else if (source_core->first_stroke)
|
|
|
|
{
|
2022-02-05 05:44:54 +08:00
|
|
|
source_core->offset_x = src_x - dest_x;
|
|
|
|
source_core->offset_y = src_y - dest_y;
|
2016-01-28 02:13:17 +08:00
|
|
|
|
|
|
|
/* get destination coordinates in front view perspective */
|
|
|
|
gimp_matrix3_transform_point (&clone->transform_inv,
|
|
|
|
dest_x,
|
|
|
|
dest_y,
|
|
|
|
&clone->dest_x_fv,
|
|
|
|
&clone->dest_y_fv);
|
|
|
|
|
|
|
|
source_core->first_stroke = FALSE;
|
|
|
|
}
|
2006-09-08 01:10:22 +08:00
|
|
|
}
|
|
|
|
|
2021-08-17 05:46:32 +08:00
|
|
|
for (GList *iter = drawables; iter; iter = iter->next)
|
2021-08-18 20:23:30 +08:00
|
|
|
gimp_source_core_motion (source_core, iter->data, paint_options,
|
|
|
|
(g_list_length (drawables) > 1), sym);
|
2006-09-08 01:10:22 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_PAINT_STATE_FINISH:
|
2017-07-16 00:38:01 +08:00
|
|
|
g_clear_object (&clone->node);
|
|
|
|
clone->crop = NULL;
|
|
|
|
clone->transform_node = NULL;
|
|
|
|
clone->dest_node = NULL;
|
2006-09-08 01:10:22 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-02 04:39:14 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_perspective_clone_use_source (GimpSourceCore *source_core,
|
|
|
|
GimpSourceOptions *options)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-31 04:11:46 +08:00
|
|
|
static GeglBuffer *
|
2006-09-12 20:57:55 +08:00
|
|
|
gimp_perspective_clone_get_source (GimpSourceCore *source_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
2021-08-18 20:23:30 +08:00
|
|
|
gboolean self_drawable,
|
2006-09-12 20:57:55 +08:00
|
|
|
GimpPickable *src_pickable,
|
|
|
|
gint src_offset_x,
|
|
|
|
gint src_offset_y,
|
2012-04-02 03:02:49 +08:00
|
|
|
GeglBuffer *paint_buffer,
|
|
|
|
gint paint_buffer_x,
|
|
|
|
gint paint_buffer_y,
|
2006-09-12 20:57:55 +08:00
|
|
|
gint *paint_area_offset_x,
|
|
|
|
gint *paint_area_offset_y,
|
|
|
|
gint *paint_area_width,
|
2012-03-31 21:40:21 +08:00
|
|
|
gint *paint_area_height,
|
|
|
|
GeglRectangle *src_rect)
|
2006-09-08 01:10:22 +08:00
|
|
|
{
|
2012-11-11 03:49:14 +08:00
|
|
|
GimpPerspectiveClone *clone = GIMP_PERSPECTIVE_CLONE (source_core);
|
|
|
|
GimpCloneOptions *clone_options = GIMP_CLONE_OPTIONS (paint_options);
|
2012-03-31 21:40:21 +08:00
|
|
|
GeglBuffer *src_buffer;
|
|
|
|
GeglBuffer *dest_buffer;
|
2012-03-29 15:44:10 +08:00
|
|
|
const Babl *src_format_alpha;
|
2007-01-16 05:54:51 +08:00
|
|
|
gint x1d, y1d, x2d, y2d;
|
|
|
|
gdouble x1s, y1s, x2s, y2s, x3s, y3s, x4s, y4s;
|
2006-09-12 20:57:55 +08:00
|
|
|
gint xmin, ymin, xmax, ymax;
|
2007-01-16 05:54:51 +08:00
|
|
|
GimpMatrix3 matrix;
|
2012-03-30 02:12:09 +08:00
|
|
|
GimpMatrix3 gegl_matrix;
|
2006-09-12 20:57:55 +08:00
|
|
|
|
2021-08-20 05:24:40 +08:00
|
|
|
if (self_drawable)
|
|
|
|
src_pickable = GIMP_PICKABLE (drawable);
|
|
|
|
|
2012-03-30 02:12:09 +08:00
|
|
|
src_buffer = gimp_pickable_get_buffer (src_pickable);
|
2012-03-31 21:40:21 +08:00
|
|
|
src_format_alpha = gimp_pickable_get_format_with_alpha (src_pickable);
|
2006-09-12 20:57:55 +08:00
|
|
|
|
|
|
|
/* Destination coordinates that will be painted */
|
2012-04-02 03:02:49 +08:00
|
|
|
x1d = paint_buffer_x;
|
|
|
|
y1d = paint_buffer_y;
|
|
|
|
x2d = paint_buffer_x + gegl_buffer_get_width (paint_buffer);
|
|
|
|
y2d = paint_buffer_y + gegl_buffer_get_height (paint_buffer);
|
2006-09-12 20:57:55 +08:00
|
|
|
|
|
|
|
/* Boundary box for source pixels to copy: Convert all the vertex of
|
|
|
|
* the box to paint in destination area to its correspondent in
|
|
|
|
* source area bearing in mind perspective
|
|
|
|
*/
|
|
|
|
gimp_perspective_clone_get_source_point (clone, x1d, y1d, &x1s, &y1s);
|
|
|
|
gimp_perspective_clone_get_source_point (clone, x1d, y2d, &x2s, &y2s);
|
|
|
|
gimp_perspective_clone_get_source_point (clone, x2d, y1d, &x3s, &y3s);
|
|
|
|
gimp_perspective_clone_get_source_point (clone, x2d, y2d, &x4s, &y4s);
|
|
|
|
|
|
|
|
xmin = floor (MIN4 (x1s, x2s, x3s, x4s));
|
|
|
|
ymin = floor (MIN4 (y1s, y2s, y3s, y4s));
|
|
|
|
xmax = ceil (MAX4 (x1s, x2s, x3s, x4s));
|
|
|
|
ymax = ceil (MAX4 (y1s, y2s, y3s, y4s));
|
|
|
|
|
2012-11-11 03:49:14 +08:00
|
|
|
switch (clone_options->clone_type)
|
2007-01-16 05:54:51 +08:00
|
|
|
{
|
2014-04-30 02:55:08 +08:00
|
|
|
case GIMP_CLONE_IMAGE:
|
2012-11-11 03:49:14 +08:00
|
|
|
if (! gimp_rectangle_intersect (xmin, ymin,
|
|
|
|
xmax - xmin, ymax - ymin,
|
2019-09-07 01:05:29 +08:00
|
|
|
gegl_buffer_get_x (src_buffer),
|
|
|
|
gegl_buffer_get_y (src_buffer),
|
2012-11-11 03:49:14 +08:00
|
|
|
gegl_buffer_get_width (src_buffer),
|
|
|
|
gegl_buffer_get_height (src_buffer),
|
|
|
|
NULL, NULL, NULL, NULL))
|
|
|
|
{
|
|
|
|
/* if the source area is completely out of the image */
|
|
|
|
return NULL;
|
|
|
|
}
|
2021-08-20 05:24:40 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
gegl_node_set (clone->src_node,
|
|
|
|
"buffer", src_buffer,
|
|
|
|
NULL);
|
|
|
|
}
|
2012-11-11 03:49:14 +08:00
|
|
|
break;
|
|
|
|
|
2014-04-30 02:55:08 +08:00
|
|
|
case GIMP_CLONE_PATTERN:
|
2012-11-11 03:49:14 +08:00
|
|
|
gegl_node_set (clone->crop,
|
|
|
|
"x", (gdouble) xmin,
|
|
|
|
"y", (gdouble) ymin,
|
|
|
|
"width", (gdouble) xmax - xmin,
|
|
|
|
"height", (gdouble) ymax - ymin,
|
|
|
|
NULL);
|
|
|
|
break;
|
2007-01-16 05:54:51 +08:00
|
|
|
}
|
|
|
|
|
2012-04-02 21:19:47 +08:00
|
|
|
dest_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, x2d - x1d, y2d - y1d),
|
2012-03-31 04:11:46 +08:00
|
|
|
src_format_alpha);
|
2006-09-12 20:57:55 +08:00
|
|
|
|
2007-01-16 05:54:51 +08:00
|
|
|
gimp_perspective_clone_get_matrix (clone, &matrix);
|
|
|
|
|
2012-03-30 02:12:09 +08:00
|
|
|
gimp_matrix3_identity (&gegl_matrix);
|
|
|
|
gimp_matrix3_mult (&matrix, &gegl_matrix);
|
|
|
|
gimp_matrix3_translate (&gegl_matrix, -x1d, -y1d);
|
|
|
|
|
2012-03-31 22:18:13 +08:00
|
|
|
gimp_gegl_node_set_matrix (clone->transform_node, &gegl_matrix);
|
2012-03-30 02:12:09 +08:00
|
|
|
|
2012-03-31 08:16:59 +08:00
|
|
|
gegl_node_set (clone->dest_node,
|
|
|
|
"buffer", dest_buffer,
|
|
|
|
NULL);
|
2012-03-30 02:12:09 +08:00
|
|
|
|
2013-03-08 05:15:29 +08:00
|
|
|
gegl_node_blit (clone->dest_node, 1.0,
|
|
|
|
GEGL_RECTANGLE (0, 0, x2d - x1d, y2d - y1d),
|
|
|
|
NULL, NULL, 0, GEGL_BLIT_DEFAULT);
|
2007-01-16 05:54:51 +08:00
|
|
|
|
2012-04-02 21:19:47 +08:00
|
|
|
*src_rect = *GEGL_RECTANGLE (0, 0, x2d - x1d, y2d - y1d);
|
2006-09-08 01:10:22 +08:00
|
|
|
|
2012-03-31 04:11:46 +08:00
|
|
|
return dest_buffer;
|
2006-09-08 01:10:22 +08:00
|
|
|
}
|
|
|
|
|
2008-08-20 17:49:40 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_perspective_clone_set_transform (GimpPerspectiveClone *clone,
|
|
|
|
GimpMatrix3 *transform)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PERSPECTIVE_CLONE (clone));
|
|
|
|
g_return_if_fail (transform != NULL);
|
|
|
|
|
|
|
|
clone->transform = *transform;
|
|
|
|
|
|
|
|
clone->transform_inv = clone->transform;
|
|
|
|
gimp_matrix3_invert (&clone->transform_inv);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
g_printerr ("%f\t%f\t%f\n%f\t%f\t%f\n%f\t%f\t%f\n\n",
|
|
|
|
clone->transform.coeff[0][0],
|
|
|
|
clone->transform.coeff[0][1],
|
|
|
|
clone->transform.coeff[0][2],
|
|
|
|
clone->transform.coeff[1][0],
|
|
|
|
clone->transform.coeff[1][1],
|
|
|
|
clone->transform.coeff[1][2],
|
|
|
|
clone->transform.coeff[2][0],
|
|
|
|
clone->transform.coeff[2][1],
|
|
|
|
clone->transform.coeff[2][2]);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-09-08 01:10:22 +08:00
|
|
|
void
|
2007-01-16 05:54:51 +08:00
|
|
|
gimp_perspective_clone_get_source_point (GimpPerspectiveClone *clone,
|
2006-09-08 01:10:22 +08:00
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble *newx,
|
|
|
|
gdouble *newy)
|
|
|
|
{
|
|
|
|
gdouble temp_x, temp_y;
|
|
|
|
|
2008-08-20 17:49:40 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PERSPECTIVE_CLONE (clone));
|
|
|
|
g_return_if_fail (newx != NULL);
|
|
|
|
g_return_if_fail (newy != NULL);
|
|
|
|
|
2007-01-16 05:54:51 +08:00
|
|
|
gimp_matrix3_transform_point (&clone->transform_inv,
|
2006-09-08 01:10:22 +08:00
|
|
|
x, y, &temp_x, &temp_y);
|
|
|
|
|
2007-01-16 05:54:51 +08:00
|
|
|
#if 0
|
2006-09-08 01:10:22 +08:00
|
|
|
/* Get the offset of each pixel in destination area from the
|
|
|
|
* destination pixel in front view perspective
|
|
|
|
*/
|
2007-01-16 05:54:51 +08:00
|
|
|
offset_x_fv = temp_x - clone->dest_x_fv;
|
|
|
|
offset_y_fv = temp_y - clone->dest_y_fv;
|
2006-09-08 01:10:22 +08:00
|
|
|
|
|
|
|
/* Get the source pixel in front view perspective */
|
2007-01-16 05:54:51 +08:00
|
|
|
temp_x = offset_x_fv + clone->src_x_fv;
|
|
|
|
temp_y = offset_y_fv + clone->src_y_fv;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
temp_x += clone->src_x_fv - clone->dest_x_fv;
|
|
|
|
temp_y += clone->src_y_fv - clone->dest_y_fv;
|
2006-09-08 01:10:22 +08:00
|
|
|
|
|
|
|
/* Convert the source pixel to perspective view */
|
2007-01-16 05:54:51 +08:00
|
|
|
gimp_matrix3_transform_point (&clone->transform,
|
2006-09-08 01:10:22 +08:00
|
|
|
temp_x, temp_y, newx, newy);
|
|
|
|
}
|
2007-01-16 05:54:51 +08:00
|
|
|
|
2008-08-20 17:49:40 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
2007-01-16 05:54:51 +08:00
|
|
|
gimp_perspective_clone_get_matrix (GimpPerspectiveClone *clone,
|
|
|
|
GimpMatrix3 *matrix)
|
|
|
|
{
|
|
|
|
GimpMatrix3 temp;
|
|
|
|
|
|
|
|
gimp_matrix3_identity (&temp);
|
|
|
|
gimp_matrix3_translate (&temp,
|
|
|
|
clone->dest_x_fv - clone->src_x_fv,
|
|
|
|
clone->dest_y_fv - clone->src_y_fv);
|
|
|
|
|
|
|
|
*matrix = clone->transform_inv;
|
|
|
|
gimp_matrix3_mult (&temp, matrix);
|
|
|
|
gimp_matrix3_mult (&clone->transform, matrix);
|
|
|
|
}
|