[gimp/soc-2010-cage-2] app: large scale formatting cleanup in the new cage code
- From: Michael Muré <mmure src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/soc-2010-cage-2] app: large scale formatting cleanup in the new cage code
- Date: Thu, 30 Dec 2010 18:05:37 +0000 (UTC)
commit a7779788b5b9512153fa282fa40d0c2dd7ccac1a
Author: Michael Natterer <mitch gimp org>
Date: Thu Nov 4 22:14:58 2010 +0100
app: large scale formatting cleanup in the new cage code
- move enum to the new gimp-gegl-enums.[ch]
- clean up includes
- spacing
- indentation
- coding style
app/gegl/Makefile.am | 28 +-
app/gegl/gimp-gegl-enums.c | 43 ++
app/gegl/gimp-gegl-enums.h | 35 ++
app/gegl/gimp-gegl-types.h | 2 +
app/gegl/gimpcageconfig.c | 358 +++++++-----
app/gegl/gimpcageconfig.h | 109 +---
app/gegl/gimpoperationcagecoefcalc.c | 165 +++---
app/gegl/gimpoperationcagecoefcalc.h | 6 +-
app/gegl/gimpoperationcagetransform.c | 431 ++++++++--------
app/gegl/gimpoperationcagetransform.h | 2 +
app/tools/gimpcageoptions.c | 41 +-
app/tools/gimpcageoptions.h | 17 +-
app/tools/gimpcagetool.c | 965 +++++++++++++++------------------
app/tools/gimpcagetool.h | 30 +-
app/tools/tools-enums.c | 29 -
app/tools/tools-enums.h | 10 -
16 files changed, 1136 insertions(+), 1135 deletions(-)
---
diff --git a/app/gegl/Makefile.am b/app/gegl/Makefile.am
index f48ce09..38b4c42 100644
--- a/app/gegl/Makefile.am
+++ b/app/gegl/Makefile.am
@@ -14,7 +14,8 @@ INCLUDES = \
noinst_LIBRARIES = libappgegl.a
-libappgegl_a_SOURCES = \
+libappgegl_a_sources = \
+ gimp-gegl-enums.h \
gimp-gegl-types.h \
gimp-gegl.c \
gimp-gegl.h \
@@ -122,3 +123,28 @@ libappgegl_a_SOURCES = \
gimpoperationreplacemode.h \
gimpoperationantierasemode.c \
gimpoperationantierasemode.h
+
+libappgegl_a_built_sources = gimp-gegl-enums.c
+
+libappgegl_a_SOURCES = $(libappgegl_a_built_sources) $(libappgegl_a_sources)
+
+#
+# rules to generate built sources
+#
+# setup autogeneration dependencies
+gen_sources = xgen-tec
+CLEANFILES = $(gen_sources)
+
+gimp-gegl-enums.c: $(srcdir)/gimp-gegl-enums.h $(GIMP_MKENUMS)
+ $(GIMP_MKENUMS) \
+ --fhead "#include \"config.h\"\n#include <glib-object.h>\n#include \"libgimpbase/gimpbase.h\"\n#include \"core/core-enums.h\"\n#include \"gimp-gegl-enums.h\"\n#include \"gimp-intl.h\"" \
+ --fprod "\n/* enumerations from \"@filename \" */" \
+ --vhead "GType\n enum_name@_get_type (void)\n{\n static const G Type@Value values[] =\n {" \
+ --vprod " { @VALUENAME@, \"@VALUENAME \", \"@valuenick \" }," \
+ --vtail " { 0, NULL, NULL }\n };\n" \
+ --dhead " static const Gimp Type@Desc descs[] =\n {" \
+ --dprod " { @VALUENAME@, @valuedesc@, @valuehelp@ }," \
+ --dtail " { 0, NULL, NULL }\n };\n\n static GType type = 0;\n\n if (G_UNLIKELY (! type))\n {\n type = g_ type@_register_static (\"@EnumName \", values);\n gimp_type_set_translation_context (type, \"@enumnick \");\n gimp_ type@_set_value_descriptions (type, descs);\n }\n\n return type;\n}\n" \
+ $(srcdir)/gimp-gegl-enums.h > xgen-tec \
+ && cp xgen-tec $(@F) \
+ && rm -f xgen-tec
diff --git a/app/gegl/gimp-gegl-enums.c b/app/gegl/gimp-gegl-enums.c
new file mode 100644
index 0000000..3751217
--- /dev/null
+++ b/app/gegl/gimp-gegl-enums.c
@@ -0,0 +1,43 @@
+
+/* Generated data (by gimp-mkenums) */
+
+#include "config.h"
+#include <glib-object.h>
+#include "libgimpbase/gimpbase.h"
+#include "core/core-enums.h"
+#include "gimp-gegl-enums.h"
+#include "gimp-intl.h"
+
+/* enumerations from "./gimp-gegl-enums.h" */
+GType
+gimp_cage_mode_get_type (void)
+{
+ static const GEnumValue values[] =
+ {
+ { GIMP_CAGE_MODE_CAGE_CHANGE, "GIMP_CAGE_MODE_CAGE_CHANGE", "cage-change" },
+ { GIMP_CAGE_MODE_DEFORM, "GIMP_CAGE_MODE_DEFORM", "deform" },
+ { 0, NULL, NULL }
+ };
+
+ static const GimpEnumDesc descs[] =
+ {
+ { GIMP_CAGE_MODE_CAGE_CHANGE, NC_("cage-mode", "Create or adjust the cage"), NULL },
+ { GIMP_CAGE_MODE_DEFORM, NC_("cage-mode", "Deform the cage to deform the image"), NULL },
+ { 0, NULL, NULL }
+ };
+
+ static GType type = 0;
+
+ if (G_UNLIKELY (! type))
+ {
+ type = g_enum_register_static ("GimpCageMode", values);
+ gimp_type_set_translation_context (type, "cage-mode");
+ gimp_enum_set_value_descriptions (type, descs);
+ }
+
+ return type;
+}
+
+
+/* Generated data ends here */
+
diff --git a/app/gegl/gimp-gegl-enums.h b/app/gegl/gimp-gegl-enums.h
new file mode 100644
index 0000000..3b7933c
--- /dev/null
+++ b/app/gegl/gimp-gegl-enums.h
@@ -0,0 +1,35 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimp-gegl-enums.h
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_GEGL_ENUMS_H__
+#define __GIMP_GEGL_ENUMS_H__
+
+
+#define GIMP_TYPE_CAGE_MODE (gimp_cage_mode_get_type ())
+
+GType gimp_cage_mode_get_type (void) G_GNUC_CONST;
+
+typedef enum
+{
+ GIMP_CAGE_MODE_CAGE_CHANGE, /*< desc="Create or adjust the cage" >*/
+ GIMP_CAGE_MODE_DEFORM /*< desc="Deform the cage to deform the image" >*/
+} GimpCageMode;
+
+
+#endif /* __GIMP_GEGL_ENUMS_H__ */
diff --git a/app/gegl/gimp-gegl-types.h b/app/gegl/gimp-gegl-types.h
index c5cf70f..6b6927a 100644
--- a/app/gegl/gimp-gegl-types.h
+++ b/app/gegl/gimp-gegl-types.h
@@ -22,6 +22,8 @@
#include "core/core-types.h"
+#include "gegl/gimp-gegl-enums.h"
+
/* operations */
diff --git a/app/gegl/gimpcageconfig.c b/app/gegl/gimpcageconfig.c
index e6335cf..069aeba 100644
--- a/app/gegl/gimpcageconfig.c
+++ b/app/gegl/gimpcageconfig.c
@@ -1,5 +1,5 @@
/* GIMP - The GNU Image Manipulation Program
- *
+ *
* gimpcageconfig.c
* Copyright (C) 2010 Michael Muré <batolettre gmail com>
*
@@ -20,23 +20,34 @@
#include "config.h"
#include <gegl.h>
+
#include "gimp-gegl-types.h"
#include "libgimpconfig/gimpconfig.h"
-#include "libgimpmodule/gimpmodule.h"
#include "libgimpmath/gimpmath.h"
#include "libgimpbase/gimpbase.h"
-#include "core/core-types.h"
-#include "libgimpmath/gimpmathtypes.h"
-#include "tools/tools-enums.h"
+#include "gimpcageconfig.h"
+
-#include "libgimpmath/gimpvector.h"
-#include <math.h>
+/*#define DEBUG_CAGE */
-#include <stdio.h>
+#define N_ITEMS_PER_ALLOC 10
+#define DELTA 0.010309278351
-#include "gimpcageconfig.h"
+
+static void gimp_cage_config_finalize (GObject *object);
+static void gimp_cage_config_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void gimp_cage_config_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+
+static void gimp_cage_config_compute_scaling_factor (GimpCageConfig *gcc);
+static void gimp_cage_config_compute_edge_normal (GimpCageConfig *gcc);
G_DEFINE_TYPE_WITH_CODE (GimpCageConfig, gimp_cage_config,
@@ -46,22 +57,6 @@ G_DEFINE_TYPE_WITH_CODE (GimpCageConfig, gimp_cage_config,
#define parent_class gimp_cage_config_parent_class
-#define N_ITEMS_PER_ALLOC 10
-#define DELTA 0.010309278351
-
-static void gimp_cage_config_finalize (GObject *object);
-static void gimp_cage_config_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec);
-static void gimp_cage_config_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gimp_cage_config_compute_scaling_factor (GimpCageConfig *gcc);
-static void gimp_cage_config_compute_edge_normal (GimpCageConfig *gcc);
-
-/*#define DEBUG_CAGE */
#ifdef DEBUG_CAGE
static void
@@ -86,24 +81,24 @@ print_cage (GimpCageConfig *gcc)
static void
gimp_cage_config_class_init (GimpCageConfigClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->set_property = gimp_cage_config_set_property;
- object_class->get_property = gimp_cage_config_get_property;
+ object_class->set_property = gimp_cage_config_set_property;
+ object_class->get_property = gimp_cage_config_get_property;
- object_class->finalize = gimp_cage_config_finalize;
+ object_class->finalize = gimp_cage_config_finalize;
}
static void
gimp_cage_config_init (GimpCageConfig *self)
{
self->cage_vertice_number = 0;
- self->cage_vertices_max = 50; /*pre-allocation for 50 vertices for the cage.*/
+ self->cage_vertices_max = 50; /*pre-allocation for 50 vertices for the cage.*/
- self->cage_vertices = g_new(GimpVector2, self->cage_vertices_max);
- self->cage_vertices_d = g_new(GimpVector2, self->cage_vertices_max);
- self->scaling_factor = g_malloc (self->cage_vertices_max * sizeof(gdouble));
- self->normal_d = g_new(GimpVector2, self->cage_vertices_max);
+ self->cage_vertices = g_new0 (GimpVector2, self->cage_vertices_max);
+ self->cage_vertices_d = g_new0 (GimpVector2, self->cage_vertices_max);
+ self->scaling_factor = g_malloc0 (self->cage_vertices_max * sizeof (gdouble));
+ self->normal_d = g_new0 (GimpVector2, self->cage_vertices_max);
}
static void
@@ -111,10 +106,10 @@ gimp_cage_config_finalize (GObject *object)
{
GimpCageConfig *gcc = GIMP_CAGE_CONFIG (object);
- g_free(gcc->cage_vertices);
- g_free(gcc->cage_vertices_d);
- g_free(gcc->scaling_factor);
- g_free(gcc->normal_d);
+ g_free (gcc->cage_vertices);
+ g_free (gcc->cage_vertices_d);
+ g_free (gcc->scaling_factor);
+ g_free (gcc->normal_d);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -125,10 +120,8 @@ gimp_cage_config_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
-
switch (property_id)
{
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -141,16 +134,23 @@ gimp_cage_config_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
-
switch (property_id)
{
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
+/**
+ * gimp_cage_config_add_cage_point:
+ * @gcc: the cage config
+ * @x: x value of the new point
+ * @y: y value of the new point
+ *
+ * Add a new point in the polygon of the cage, and make allocation if needed.
+ * Point is added in both source and destination cage
+ */
void
gimp_cage_config_add_cage_point (GimpCageConfig *gcc,
gdouble x,
@@ -160,24 +160,24 @@ gimp_cage_config_add_cage_point (GimpCageConfig *gcc,
/* reallocate memory if needed */
if (gcc->cage_vertice_number >= gcc->cage_vertices_max)
- {
- gcc->cage_vertices_max += N_ITEMS_PER_ALLOC;
+ {
+ gcc->cage_vertices_max += N_ITEMS_PER_ALLOC;
- gcc->cage_vertices = g_renew(GimpVector2,
- gcc->cage_vertices,
- gcc->cage_vertices_max);
+ gcc->cage_vertices = g_renew (GimpVector2,
+ gcc->cage_vertices,
+ gcc->cage_vertices_max);
- gcc->cage_vertices_d = g_renew(GimpVector2,
- gcc->cage_vertices_d,
- gcc->cage_vertices_max);
+ gcc->cage_vertices_d = g_renew (GimpVector2,
+ gcc->cage_vertices_d,
+ gcc->cage_vertices_max);
- gcc->scaling_factor = g_realloc (gcc->scaling_factor,
- gcc->cage_vertices_max * sizeof(gdouble));
+ gcc->scaling_factor = g_realloc (gcc->scaling_factor,
+ gcc->cage_vertices_max * sizeof (gdouble));
- gcc->normal_d = g_renew(GimpVector2,
- gcc->normal_d,
- gcc->cage_vertices_max);
- }
+ gcc->normal_d = g_renew (GimpVector2,
+ gcc->normal_d,
+ gcc->cage_vertices_max);
+ }
gcc->cage_vertices[gcc->cage_vertice_number].x = x + DELTA - gcc->offset_x;
gcc->cage_vertices[gcc->cage_vertice_number].y = y + DELTA - gcc->offset_y;
@@ -190,7 +190,13 @@ gimp_cage_config_add_cage_point (GimpCageConfig *gcc,
gimp_cage_config_compute_scaling_factor (gcc);
gimp_cage_config_compute_edge_normal (gcc);
}
-
+
+/**
+ * gimp_cage_config_remove_last_cage_point:
+ * @gcc: the cage config
+ *
+ * Remove the last point of the cage, in both source and destination cage
+ */
void
gimp_cage_config_remove_last_cage_point (GimpCageConfig *gcc)
{
@@ -203,39 +209,56 @@ gimp_cage_config_remove_last_cage_point (GimpCageConfig *gcc)
gimp_cage_config_compute_edge_normal (gcc);
}
-
-
+/**
+ * gimp_cage_config_move_cage_point:
+ * @gcc: the cage config
+ * @mode: the actual mode of the cage, GIMP_CAGE_MODE_CAGE_CHANGE or GIMP_CAGE_MODE_DEFORM
+ * @point_number: the point of the cage to move
+ * @x: new x value
+ * @y: new y value
+ *
+ * Move a point of the source or destination cage, according to the
+ * cage mode provided
+ */
void
-gimp_cage_config_move_cage_point (GimpCageConfig *gcc,
- GimpCageMode mode,
- gint point_number,
- gdouble x,
- gdouble y)
+gimp_cage_config_move_cage_point (GimpCageConfig *gcc,
+ GimpCageMode mode,
+ gint point_number,
+ gdouble x,
+ gdouble y)
{
g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc));
g_return_if_fail (point_number < gcc->cage_vertice_number);
g_return_if_fail (point_number >= 0);
if (mode == GIMP_CAGE_MODE_CAGE_CHANGE)
- {
- gcc->cage_vertices[point_number].x = x + DELTA - gcc->offset_x;
- gcc->cage_vertices[point_number].y = y + DELTA - gcc->offset_y;
- }
+ {
+ gcc->cage_vertices[point_number].x = x + DELTA - gcc->offset_x;
+ gcc->cage_vertices[point_number].y = y + DELTA - gcc->offset_y;
+ }
else
- {
- gcc->cage_vertices_d[point_number].x = x + DELTA - gcc->offset_x;
- gcc->cage_vertices_d[point_number].y = y + DELTA - gcc->offset_y;
- }
+ {
+ gcc->cage_vertices_d[point_number].x = x + DELTA - gcc->offset_x;
+ gcc->cage_vertices_d[point_number].y = y + DELTA - gcc->offset_y;
+ }
gimp_cage_config_compute_scaling_factor (gcc);
gimp_cage_config_compute_edge_normal (gcc);
}
+/**
+ * gimp_cage_config_get_bounding_box:
+ * @gcc: the cage config
+ *
+ * Compute the bounding box of the destination cage
+ *
+ * Returns: the bounding box of the destination cage, as a GeglRectangle
+ */
GeglRectangle
-gimp_cage_config_get_bounding_box (GimpCageConfig *gcc)
+gimp_cage_config_get_bounding_box (GimpCageConfig *gcc)
{
- gint i;
- GeglRectangle bounding_box = {0, };
+ GeglRectangle bounding_box = { 0, };
+ gint i;
g_return_val_if_fail (GIMP_IS_CAGE_CONFIG (gcc), bounding_box);
g_return_val_if_fail (gcc->cage_vertice_number >= 0, bounding_box);
@@ -246,65 +269,82 @@ gimp_cage_config_get_bounding_box (GimpCageConfig *gcc)
bounding_box.width = 0;
for (i = 1; i < gcc->cage_vertice_number; i++)
- {
- gdouble x,y;
-
- x = gcc->cage_vertices[i].x;
- y = gcc->cage_vertices[i].y;
-
- if (x < bounding_box.x)
{
- bounding_box.width += bounding_box.x - x;
- bounding_box.x = x;
+ gdouble x,y;
+
+ x = gcc->cage_vertices[i].x;
+ y = gcc->cage_vertices[i].y;
+
+ if (x < bounding_box.x)
+ {
+ bounding_box.width += bounding_box.x - x;
+ bounding_box.x = x;
+ }
+
+ if (y < bounding_box.y)
+ {
+ bounding_box.height += bounding_box.y - y;
+ bounding_box.y = y;
+ }
+
+ if (x > bounding_box.x + bounding_box.width)
+ {
+ bounding_box.width = x - bounding_box.x;
+ }
+
+ if (y > bounding_box.y + bounding_box.height)
+ {
+ bounding_box.height = y - bounding_box.y;
+ }
}
- if (y < bounding_box.y)
- {
- bounding_box.height += bounding_box.y - y;
- bounding_box.y = y;
- }
-
- if (x > bounding_box.x + bounding_box.width)
- {
- bounding_box.width = x - bounding_box.x;
- }
-
- if (y > bounding_box.y + bounding_box.height)
- {
- bounding_box.height = y - bounding_box.y;
- }
- }
-
return bounding_box;
}
+/**
+ * gimp_cage_config_reverse_cage:
+ * @gcc: the cage config
+ *
+ * When using non-simple cage (like a cage in 8), user may want to
+ * manually inverse inside and outside of the cage. This function
+ * reverse the cage
+ */
void
-gimp_cage_config_reverse_cage (GimpCageConfig *gcc)
+gimp_cage_config_reverse_cage (GimpCageConfig *gcc)
{
- gint i;
GimpVector2 temp;
+ gint i;
g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc));
for (i = 0; i < gcc->cage_vertice_number / 2; i++)
- {
- temp = gcc->cage_vertices[i];
- gcc->cage_vertices[i] = gcc->cage_vertices[gcc->cage_vertice_number - i -1];
- gcc->cage_vertices[gcc->cage_vertice_number - i -1] = temp;
+ {
+ temp = gcc->cage_vertices[i];
+ gcc->cage_vertices[i] = gcc->cage_vertices[gcc->cage_vertice_number - i -1];
+ gcc->cage_vertices[gcc->cage_vertice_number - i -1] = temp;
- temp = gcc->cage_vertices_d[i];
- gcc->cage_vertices_d[i] = gcc->cage_vertices_d[gcc->cage_vertice_number - i -1];
- gcc->cage_vertices_d[gcc->cage_vertice_number - i -1] = temp;
- }
+ temp = gcc->cage_vertices_d[i];
+ gcc->cage_vertices_d[i] = gcc->cage_vertices_d[gcc->cage_vertice_number - i -1];
+ gcc->cage_vertices_d[gcc->cage_vertice_number - i -1] = temp;
+ }
gimp_cage_config_compute_scaling_factor (gcc);
gimp_cage_config_compute_edge_normal (gcc);
}
+/**
+ * gimp_cage_config_reverse_cage_if_needed:
+ * @gcc: the cage config
+ *
+ * Since the cage need to be defined counter-clockwise to have the
+ * topological inside in the actual 'physical' inside of the cage,
+ * this function compute if the cage is clockwise or not, and reverse
+ * the cage if needed.
+ */
void
gimp_cage_config_reverse_cage_if_needed (GimpCageConfig *gcc)
{
- gint i;
+ gint i;
gdouble sum;
g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc));
@@ -312,47 +352,59 @@ gimp_cage_config_reverse_cage_if_needed (GimpCageConfig *gcc)
sum = 0.0;
/* this is a bit crappy, but should works most of the case */
- /* we do the sum of the projection of each point to the previous segment, and see the final sign */
+ /* we do the sum of the projection of each point to the previous
+ segment, and see the final sign */
for (i = 0; i < gcc->cage_vertice_number ; i++)
- {
- GimpVector2 P1, P2, P3;
- gdouble z;
+ {
+ GimpVector2 P1, P2, P3;
+ gdouble z;
- P1 = gcc->cage_vertices[i];
- P2 = gcc->cage_vertices[(i+1) % gcc->cage_vertice_number];
- P3 = gcc->cage_vertices[(i+2) % gcc->cage_vertice_number];
+ P1 = gcc->cage_vertices[i];
+ P2 = gcc->cage_vertices[(i+1) % gcc->cage_vertice_number];
+ P3 = gcc->cage_vertices[(i+2) % gcc->cage_vertice_number];
- z = P1.x * (P2.y - P3.y) + P2.x * (P3.y - P1.y) + P3.x * (P1.y - P2.y);
+ z = P1.x * (P2.y - P3.y) + P2.x * (P3.y - P1.y) + P3.x * (P1.y - P2.y);
- sum += z;
- }
+ sum += z;
+ }
/* sum > 0 mean a cage defined counter-clockwise, so we reverse it */
if (sum > 0)
- {
- gimp_cage_config_reverse_cage (gcc);
- }
+ {
+ gimp_cage_config_reverse_cage (gcc);
+ }
}
+/**
+ * gimp_cage_config_point_inside:
+ * @gcc: the cage config
+ * @x: x coordinate of the point to test
+ * @y: y coordinate of the point to test
+ *
+ * Check if the given point is inside the cage. This test is done in
+ * the regard of the topological inside of the cage.
+ *
+ * Returns: TRUE if the point is inside, FALSE if not.
+ */
static void
gimp_cage_config_compute_scaling_factor (GimpCageConfig *gcc)
{
- gint i;
GimpVector2 edge;
- gdouble length, length_d;
+ gdouble length, length_d;
+ gint i;
g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc));
for (i = 0; i < gcc->cage_vertice_number; i++)
- {
- gimp_vector2_sub ( &edge, &gcc->cage_vertices[i], &gcc->cage_vertices[(i+1) % gcc->cage_vertice_number]);
- length = gimp_vector2_length (&edge);
+ {
+ gimp_vector2_sub ( &edge, &gcc->cage_vertices[i], &gcc->cage_vertices[(i+1) % gcc->cage_vertice_number]);
+ length = gimp_vector2_length (&edge);
- gimp_vector2_sub ( &edge, &gcc->cage_vertices_d[i], &gcc->cage_vertices_d[(i+1) % gcc->cage_vertice_number]);
- length_d = gimp_vector2_length (&edge);
+ gimp_vector2_sub ( &edge, &gcc->cage_vertices_d[i], &gcc->cage_vertices_d[(i+1) % gcc->cage_vertice_number]);
+ length_d = gimp_vector2_length (&edge);
- gcc->scaling_factor[i] = length_d / length;
- }
+ gcc->scaling_factor[i] = length_d / length;
+ }
#ifdef DEBUG_CAGE
print_cage (gcc);
@@ -362,19 +414,19 @@ gimp_cage_config_compute_scaling_factor (GimpCageConfig *gcc)
static void
gimp_cage_config_compute_edge_normal (GimpCageConfig *gcc)
{
- gint i;
GimpVector2 normal;
+ gint i;
g_return_if_fail (GIMP_IS_CAGE_CONFIG (gcc));
for (i = 0; i < gcc->cage_vertice_number; i++)
- {
- gimp_vector2_sub (&normal,
- &gcc->cage_vertices_d[(i+1) % gcc->cage_vertice_number],
- &gcc->cage_vertices_d[i]);
+ {
+ gimp_vector2_sub (&normal,
+ &gcc->cage_vertices_d[(i+1) % gcc->cage_vertice_number],
+ &gcc->cage_vertices_d[i]);
- gcc->normal_d[i] = gimp_vector2_normal (&normal);
- }
+ gcc->normal_d[i] = gimp_vector2_normal (&normal);
+ }
}
gboolean
@@ -382,21 +434,25 @@ gimp_cage_config_point_inside (GimpCageConfig *gcc,
gfloat x,
gfloat y)
{
- gint i, j;
- gboolean inside = FALSE;
- GimpVector2 *cv = gcc->cage_vertices;
+ GimpVector2 *cv;
+ gboolean inside = FALSE;
+ gint i, j;
g_return_val_if_fail (GIMP_IS_CAGE_CONFIG (gcc), FALSE);
- for (i = 0, j = gcc->cage_vertice_number - 1; i < gcc->cage_vertice_number; j = i++)
- {
- if ((((cv[i].y <= y) && (y < cv[j].y))
- || ((cv[j].y <= y) && (y < cv[i].y)))
- && (x < (cv[j].x - cv[i].x) * (y - cv[i].y) / (cv[j].y - cv[i].y) + cv[i].x))
+ cv = gcc->cage_vertices;
+
+ for (i = 0, j = gcc->cage_vertice_number - 1;
+ i < gcc->cage_vertice_number;
+ j = i++)
{
- inside = !inside;
+ if ((((cv[i].y <= y) && (y < cv[j].y))
+ || ((cv[j].y <= y) && (y < cv[i].y)))
+ && (x < (cv[j].x - cv[i].x) * (y - cv[i].y) / (cv[j].y - cv[i].y) + cv[i].x))
+ {
+ inside = !inside;
+ }
}
- }
return inside;
}
diff --git a/app/gegl/gimpcageconfig.h b/app/gegl/gimpcageconfig.h
index 6fbc24f..e4fb7e8 100644
--- a/app/gegl/gimpcageconfig.h
+++ b/app/gegl/gimpcageconfig.h
@@ -1,5 +1,5 @@
/* GIMP - The GNU Image Manipulation Program
- *
+ *
* gimpcageconfig.h
* Copyright (C) 2010 Michael Muré <batolettre gmail com>
*
@@ -20,10 +20,9 @@
#ifndef __GIMP_CAGE_CONFIG_H__
#define __GIMP_CAGE_CONFIG_H__
+
#include "core/gimpimagemapconfig.h"
-#include <gegl.h>
-#include "gimp-gegl-types.h"
-#include "tools/tools-enums.h"
+
#define GIMP_TYPE_CAGE_CONFIG (gimp_cage_config_get_type ())
#define GIMP_CAGE_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CAGE_CONFIG, GimpCageConfig))
@@ -37,108 +36,42 @@ typedef struct _GimpCageConfigClass GimpCageConfigClass;
struct _GimpCageConfig
{
- GimpImageMapConfig parent_instance;
-
- gint cage_vertice_number; /* number of vertices used by the cage */
- gint cage_vertices_max; /* number of vertices allocated in memory */
-
- gint offset_x;
- gint offset_y;
-
- GimpVector2 *cage_vertices; /* cage before deformation */
- GimpVector2 *cage_vertices_d; /* cage after deformation */
- gdouble *scaling_factor;
- GimpVector2 *normal_d;
-};
+ GimpImageMapConfig parent_instance;
+
+ gint cage_vertice_number; /* number of vertices used by the cage */
+ gint cage_vertices_max; /* number of vertices allocated in memory */
+ gint offset_x;
+ gint offset_y;
+
+ GimpVector2 *cage_vertices; /* cage before deformation */
+ GimpVector2 *cage_vertices_d; /* cage after deformation */
+ gdouble *scaling_factor;
+ GimpVector2 *normal_d;
+};
struct _GimpCageConfigClass
{
- GimpImageMapConfigClass parent_class;
+ GimpImageMapConfigClass parent_class;
};
-GType gimp_cage_config_get_type (void) G_GNUC_CONST;
+GType gimp_cage_config_get_type (void) G_GNUC_CONST;
-/**
- * gimp_cage_config_add_cage_point:
- * @gcc: the cage config
- * @x: x value of the new point
- * @y: y value of the new point
- *
- * Add a new point in the polygon of the cage, and make allocation if needed.
- * Point is added in both source and destination cage
- */
void gimp_cage_config_add_cage_point (GimpCageConfig *gcc,
gdouble x,
gdouble y);
-
-/**
- * gimp_cage_config_remove_last_cage_point:
- * @gcc: the cage config
- *
- * Remove the last point of the cage, in both source and destination cage
- */
void gimp_cage_config_remove_last_cage_point (GimpCageConfig *gcc);
-
-
-
-/**
- * gimp_cage_config_move_cage_point:
- * @gcc: the cage config
- * @mode: the actual mode of the cage, GIMP_CAGE_MODE_CAGE_CHANGE or GIMP_CAGE_MODE_DEFORM
- * @point_number: the point of the cage to move
- * @x: new x value
- * @y: new y value
- *
- * Move a point of the source or destination cage, according to the cage mode provided
- */
void gimp_cage_config_move_cage_point (GimpCageConfig *gcc,
GimpCageMode mode,
gint point_number,
gdouble x,
gdouble y);
-
-/**
- * gimp_cage_config_get_bounding_box:
- * @gcc: the cage config
- *
- * Compute the bounding box of the destination cage
- *
- * Returns: the bounding box of the destination cage, as a GeglRectangle
- */
GeglRectangle gimp_cage_config_get_bounding_box (GimpCageConfig *gcc);
-
-/**
- * gimp_cage_config_reverse_cage_if_needed:
- * @gcc: the cage config
- *
- * Since the cage need to be defined counter-clockwise to have the topological inside in the actual 'physical' inside of the cage,
- * this function compute if the cage is clockwise or not, and reverse the cage if needed.
- */
void gimp_cage_config_reverse_cage_if_needed (GimpCageConfig *gcc);
+void gimp_cage_config_reverse_cage (GimpCageConfig *gcc);
+gboolean gimp_cage_config_point_inside (GimpCageConfig *gcc,
+ gfloat x,
+ gfloat y);
-/**
- * gimp_cage_config_reverse_cage:
- * @gcc: the cage config
- *
- * When using non-simple cage (like a cage in 8), user may want to manually inverse inside and outside of the cage.
- * This function reverse the cage
- */
-void gimp_cage_config_reverse_cage (GimpCageConfig *gcc);
-
-
-/**
- * gimp_cage_config_point_inside:
- * @gcc: the cage config
- * @x: x coordinate of the point to test
- * @y: y coordinate of the point to test
- *
- * Check if the given point is inside the cage. This test is done in the regard of the topological inside of the cage.
- *
- * Returns: TRUE if the point is inside, FALSE if not.
- */
-gboolean gimp_cage_config_point_inside (GimpCageConfig *gcc,
- gfloat x,
- gfloat y);
#endif /* __GIMP_CAGE_CONFIG_H__ */
diff --git a/app/gegl/gimpoperationcagecoefcalc.c b/app/gegl/gimpoperationcagecoefcalc.c
index d5b5836..76c6cec 100644
--- a/app/gegl/gimpoperationcagecoefcalc.c
+++ b/app/gegl/gimpoperationcagecoefcalc.c
@@ -20,11 +20,12 @@
#include "config.h"
#include <gegl.h>
-#include "gimp-gegl-types.h"
#include <gegl-buffer-iterator.h>
#include "libgimpmath/gimpmath.h"
+#include "gimp-gegl-types.h"
+
#include "gimpoperationcagecoefcalc.h"
#include "gimpcageconfig.h"
@@ -90,8 +91,8 @@ gimp_operation_cage_coef_calc_init (GimpOperationCageCoefCalc *self)
static void
gimp_operation_cage_coef_calc_prepare (GeglOperation *operation)
{
- GimpOperationCageCoefCalc *occc = GIMP_OPERATION_CAGE_COEF_CALC (operation);
- GimpCageConfig *config = GIMP_CAGE_CONFIG (occc->config);
+ GimpOperationCageCoefCalc *occc = GIMP_OPERATION_CAGE_COEF_CALC (operation);
+ GimpCageConfig *config = GIMP_CAGE_CONFIG (occc->config);
gegl_operation_set_format (operation,
"output",
@@ -114,12 +115,12 @@ gimp_operation_cage_coef_calc_finalize (GObject *object)
}
static void
-gimp_operation_cage_coef_calc_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+gimp_operation_cage_coef_calc_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- GimpOperationCageCoefCalc *self = GIMP_OPERATION_CAGE_COEF_CALC (object);
+ GimpOperationCageCoefCalc *self = GIMP_OPERATION_CAGE_COEF_CALC (object);
switch (property_id)
{
@@ -134,12 +135,12 @@ gimp_operation_cage_coef_calc_get_property (GObject *object,
}
static void
-gimp_operation_cage_coef_calc_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+gimp_operation_cage_coef_calc_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- GimpOperationCageCoefCalc *self = GIMP_OPERATION_CAGE_COEF_CALC (object);
+ GimpOperationCageCoefCalc *self = GIMP_OPERATION_CAGE_COEF_CALC (object);
switch (property_id)
{
@@ -161,7 +162,7 @@ gimp_operation_cage_coef_calc_is_on_straight (GimpVector2 *d1,
GimpVector2 *p)
{
GimpVector2 v1, v2;
- gfloat deter;
+ gfloat deter;
v1.x = p->x - d1->x;
v1.y = p->y - d1->y;
@@ -179,8 +180,8 @@ gimp_operation_cage_coef_calc_is_on_straight (GimpVector2 *d1,
static GeglRectangle
gimp_operation_cage_coef_calc_get_bounding_box (GeglOperation *operation)
{
- GimpOperationCageCoefCalc *occc = GIMP_OPERATION_CAGE_COEF_CALC (operation);
- GimpCageConfig *config = GIMP_CAGE_CONFIG (occc->config);
+ GimpOperationCageCoefCalc *occc = GIMP_OPERATION_CAGE_COEF_CALC (operation);
+ GimpCageConfig *config = GIMP_CAGE_CONFIG (occc->config);
return gimp_cage_config_get_bounding_box (config);
}
@@ -190,8 +191,8 @@ gimp_operation_cage_coef_calc_process (GeglOperation *operation,
GeglBuffer *output,
const GeglRectangle *roi)
{
- GimpOperationCageCoefCalc *occc = GIMP_OPERATION_CAGE_COEF_CALC (operation);
- GimpCageConfig *config = GIMP_CAGE_CONFIG (occc->config);
+ GimpOperationCageCoefCalc *occc = GIMP_OPERATION_CAGE_COEF_CALC (operation);
+ GimpCageConfig *config = GIMP_CAGE_CONFIG (occc->config);
Babl *format = babl_format_n (babl_type ("float"), 2 * config->cage_vertice_number);
@@ -203,75 +204,75 @@ gimp_operation_cage_coef_calc_process (GeglOperation *operation,
it = gegl_buffer_iterator_new (output, roi, format, GEGL_BUFFER_READWRITE);
while (gegl_buffer_iterator_next (it))
- {
- /* iterate inside the roi */
- gint n_pixels = it->length;
- gint x = it->roi->x; /* initial x */
- gint y = it->roi->y; /* and y coordinates */
- gint j;
+ {
+ /* iterate inside the roi */
+ gint n_pixels = it->length;
+ gint x = it->roi->x; /* initial x */
+ gint y = it->roi->y; /* and y coordinates */
+ gint j;
- gfloat *coef = it->data[0];
+ gfloat *coef = it->data[0];
- while(n_pixels--)
- {
- if (gimp_cage_config_point_inside(config, x, y))
- {
- for( j = 0; j < config->cage_vertice_number; j++)
+ while(n_pixels--)
{
- GimpVector2 v1,v2,a,b,p;
- gdouble BA,SRT,L0,L1,A0,A1,A10,L10, Q,S,R, absa;
-
- v1 = config->cage_vertices[j];
- v2 = config->cage_vertices[(j+1)%config->cage_vertice_number];
- p.x = x;
- p.y = y;
- a.x = v2.x - v1.x;
- a.y = v2.y - v1.y;
- absa = gimp_vector2_length (&a);
-
- b.x = v1.x - x;
- b.y = v1.y - y;
- Q = a.x * a.x + a.y * a.y;
- S = b.x * b.x + b.y * b.y;
- R = 2.0 * (a.x * b.x + a.y * b.y);
- BA = b.x * a.y - b.y * a.x;
- SRT = sqrt(4.0 * S * Q - R * R);
-
- L0 = log(S);
- L1 = log(S + Q + R);
- A0 = atan2(R, SRT) / SRT;
- A1 = atan2(2.0 * Q + R, SRT) / SRT;
- A10 = A1 - A0;
- L10 = L1 - L0;
-
- /* edge coef */
- coef[j + config->cage_vertice_number] = (-absa / (4.0 * M_PI)) * ((4.0*S-(R*R)/Q) * A10 + (R / (2.0 * Q)) * L10 + L1 - 2.0);
-
- if (isnan(coef[j + config->cage_vertice_number]))
- {
- coef[j + config->cage_vertice_number] = 0.0;
- }
-
- /* vertice coef */
- if (!gimp_operation_cage_coef_calc_is_on_straight (&v1, &v2, &p))
- {
- coef[j] += (BA / (2.0 * M_PI)) * (L10 /(2.0*Q) - A10 * (2.0 + R / Q));
- coef[(j+1)%config->cage_vertice_number] -= (BA / (2.0 * M_PI)) * (L10 / (2.0 * Q) - A10 * (R / Q));
- }
+ if (gimp_cage_config_point_inside(config, x, y))
+ {
+ for( j = 0; j < config->cage_vertice_number; j++)
+ {
+ GimpVector2 v1,v2,a,b,p;
+ gdouble BA,SRT,L0,L1,A0,A1,A10,L10, Q,S,R, absa;
+
+ v1 = config->cage_vertices[j];
+ v2 = config->cage_vertices[(j+1)%config->cage_vertice_number];
+ p.x = x;
+ p.y = y;
+ a.x = v2.x - v1.x;
+ a.y = v2.y - v1.y;
+ absa = gimp_vector2_length (&a);
+
+ b.x = v1.x - x;
+ b.y = v1.y - y;
+ Q = a.x * a.x + a.y * a.y;
+ S = b.x * b.x + b.y * b.y;
+ R = 2.0 * (a.x * b.x + a.y * b.y);
+ BA = b.x * a.y - b.y * a.x;
+ SRT = sqrt(4.0 * S * Q - R * R);
+
+ L0 = log(S);
+ L1 = log(S + Q + R);
+ A0 = atan2(R, SRT) / SRT;
+ A1 = atan2(2.0 * Q + R, SRT) / SRT;
+ A10 = A1 - A0;
+ L10 = L1 - L0;
+
+ /* edge coef */
+ coef[j + config->cage_vertice_number] = (-absa / (4.0 * M_PI)) * ((4.0*S-(R*R)/Q) * A10 + (R / (2.0 * Q)) * L10 + L1 - 2.0);
+
+ if (isnan(coef[j + config->cage_vertice_number]))
+ {
+ coef[j + config->cage_vertice_number] = 0.0;
+ }
+
+ /* vertice coef */
+ if (!gimp_operation_cage_coef_calc_is_on_straight (&v1, &v2, &p))
+ {
+ coef[j] += (BA / (2.0 * M_PI)) * (L10 /(2.0*Q) - A10 * (2.0 + R / Q));
+ coef[(j+1)%config->cage_vertice_number] -= (BA / (2.0 * M_PI)) * (L10 / (2.0 * Q) - A10 * (R / Q));
+ }
+ }
+ }
+
+ coef += 2 * config->cage_vertice_number;
+
+ /* update x and y coordinates */
+ x++;
+ if (x >= (it->roi->x + it->roi->width))
+ {
+ x = it->roi->x;
+ y++;
+ }
}
- }
-
- coef += 2 * config->cage_vertice_number;
-
- /* update x and y coordinates */
- x++;
- if (x >= (it->roi->x + it->roi->width))
- {
- x = it->roi->x;
- y++;
- }
}
- }
return TRUE;
}
diff --git a/app/gegl/gimpoperationcagecoefcalc.h b/app/gegl/gimpoperationcagecoefcalc.h
index 2795484..70f3a8c 100644
--- a/app/gegl/gimpoperationcagecoefcalc.h
+++ b/app/gegl/gimpoperationcagecoefcalc.h
@@ -20,9 +20,11 @@
#ifndef __GIMP_OPERATION_CAGE_COEF_CALC_H__
#define __GIMP_OPERATION_CAGE_COEF_CALC_H__
+
#include <gegl-plugin.h>
#include <operation/gegl-operation-source.h>
+
enum
{
GIMP_OPERATION_CAGE_COEF_CALC_PROP_0,
@@ -42,9 +44,9 @@ typedef struct _GimpOperationCageCoefCalcClass GimpOperationCageCoefCalcClass;
struct _GimpOperationCageCoefCalc
{
- GeglOperationSource parent_instance;
+ GeglOperationSource parent_instance;
- GimpCageConfig *config;
+ GimpCageConfig *config;
};
struct _GimpOperationCageCoefCalcClass
diff --git a/app/gegl/gimpoperationcagetransform.c b/app/gegl/gimpoperationcagetransform.c
index 7330372..5ed7bf3 100644
--- a/app/gegl/gimpoperationcagetransform.c
+++ b/app/gegl/gimpoperationcagetransform.c
@@ -20,15 +20,17 @@
#include "config.h"
#include <gegl.h>
-#include "gimp-gegl-types.h"
#include <gegl-buffer-iterator.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
+#include "gimp-gegl-types.h"
+
#include "gimpoperationcagetransform.h"
#include "gimpcageconfig.h"
+
static void gimp_operation_cage_transform_finalize (GObject *object);
static void gimp_operation_cage_transform_get_property (GObject *object,
guint property_id,
@@ -77,9 +79,9 @@ G_DEFINE_TYPE (GimpOperationCageTransform, gimp_operation_cage_transform,
static void
gimp_operation_cage_transform_class_init (GimpOperationCageTransformClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
- GeglOperationComposerClass *filter_class = GEGL_OPERATION_COMPOSER_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
+ GeglOperationComposerClass *filter_class = GEGL_OPERATION_COMPOSER_CLASS (klass);
object_class->get_property = gimp_operation_cage_transform_get_property;
object_class->set_property = gimp_operation_cage_transform_set_property;
@@ -135,10 +137,10 @@ gimp_operation_cage_transform_finalize (GObject *object)
}
static void
-gimp_operation_cage_transform_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+gimp_operation_cage_transform_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GimpOperationCageTransform *self = GIMP_OPERATION_CAGE_TRANSFORM (object);
@@ -147,7 +149,6 @@ gimp_operation_cage_transform_get_property (GObject *object,
case GIMP_OPERATION_CAGE_TRANSFORM_PROP_CONFIG:
g_value_set_object (value, self->config);
break;
-
case GIMP_OPERATION_CAGE_TRANSFORM_PROP_FILL:
g_value_set_boolean (value, self->fill_plain_color);
break;
@@ -159,10 +160,10 @@ gimp_operation_cage_transform_get_property (GObject *object,
}
static void
-gimp_operation_cage_transform_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+gimp_operation_cage_transform_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GimpOperationCageTransform *self = GIMP_OPERATION_CAGE_TRANSFORM (object);
@@ -173,7 +174,6 @@ gimp_operation_cage_transform_set_property (GObject *object,
g_object_unref (self->config);
self->config = g_value_dup_object (value);
break;
-
case GIMP_OPERATION_CAGE_TRANSFORM_PROP_FILL:
self->fill_plain_color = g_value_get_boolean (value);
break;
@@ -184,15 +184,17 @@ gimp_operation_cage_transform_set_property (GObject *object,
}
}
-
static void
gimp_operation_cage_transform_prepare (GeglOperation *operation)
{
- GimpOperationCageTransform *oct = GIMP_OPERATION_CAGE_TRANSFORM (operation);
- GimpCageConfig *config = GIMP_CAGE_CONFIG (oct->config);
-
- gegl_operation_set_format (operation, "input", babl_format_n (babl_type ("float"), 2 * config->cage_vertice_number));
- gegl_operation_set_format (operation, "output", babl_format_n (babl_type ("float"), 2));
+ GimpOperationCageTransform *oct = GIMP_OPERATION_CAGE_TRANSFORM (operation);
+ GimpCageConfig *config = GIMP_CAGE_CONFIG (oct->config);
+
+ gegl_operation_set_format (operation, "input",
+ babl_format_n (babl_type ("float"),
+ 2 * config->cage_vertice_number));
+ gegl_operation_set_format (operation, "output",
+ babl_format_n (babl_type ("float"), 2));
}
static gboolean
@@ -202,8 +204,8 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
GeglBuffer *out_buf,
const GeglRectangle *roi)
{
- GimpOperationCageTransform *oct = GIMP_OPERATION_CAGE_TRANSFORM (operation);
- GimpCageConfig *config = GIMP_CAGE_CONFIG (oct->config);
+ GimpOperationCageTransform *oct = GIMP_OPERATION_CAGE_TRANSFORM (operation);
+ GimpCageConfig *config = GIMP_CAGE_CONFIG (oct->config);
gint x, y;
GeglRectangle cage_bb = gimp_cage_config_get_bounding_box (config);
@@ -219,86 +221,86 @@ gimp_operation_cage_transform_process (GeglOperation *operation,
plain_color.y = (gint) config->cage_vertices[0].y;
while (gegl_buffer_iterator_next (it))
- {
- /* iterate inside the roi */
- gint n_pixels = it->length;
- gint x = it->roi->x; /* initial x */
- gint y = it->roi->y; /* and y coordinates */
-
- gfloat *output = it->data[0];
-
- while(n_pixels--)
{
- if (oct->fill_plain_color && gimp_cage_config_point_inside(config, x, y))
- {
- output[0] = plain_color.x;
- output[1] = plain_color.y;
- }
- else
- {
- output[0] = x;
- output[1] = y;
- }
-
- output += 2;
-
- /* update x and y coordinates */
- x++;
- if (x >= (it->roi->x + it->roi->width))
- {
- x = it->roi->x;
- y++;
- }
+ /* iterate inside the roi */
+ gint n_pixels = it->length;
+ gint x = it->roi->x; /* initial x */
+ gint y = it->roi->y; /* and y coordinates */
+
+ gfloat *output = it->data[0];
+
+ while(n_pixels--)
+ {
+ if (oct->fill_plain_color && gimp_cage_config_point_inside(config, x, y))
+ {
+ output[0] = plain_color.x;
+ output[1] = plain_color.y;
+ }
+ else
+ {
+ output[0] = x;
+ output[1] = y;
+ }
+
+ output += 2;
+
+ /* update x and y coordinates */
+ x++;
+ if (x >= (it->roi->x + it->roi->width))
+ {
+ x = it->roi->x;
+ y++;
+ }
+ }
}
- }
/* compute, reverse and interpolate the transformation */
for (x = cage_bb.x; x < cage_bb.x + cage_bb.width - 1; x++)
- {
- p1_s.x = x;
- p2_s.x = x+1;
- p3_s.x = x+1;
- p3_s.y = cage_bb.y;
- p4_s.x = x;
- p4_s.y = cage_bb.y;
-
- p3_d = gimp_cage_transform_compute_destination (config, aux_buf, p3_s);
- p4_d = gimp_cage_transform_compute_destination (config, aux_buf, p4_s);
-
- for (y = cage_bb.y; y < cage_bb.y + cage_bb.height - 1; y++)
{
- p1_s = p4_s;
- p2_s = p3_s;
- p3_s.y = y+1;
- p4_s.y = y+1;
+ p1_s.x = x;
+ p2_s.x = x+1;
+ p3_s.x = x+1;
+ p3_s.y = cage_bb.y;
+ p4_s.x = x;
+ p4_s.y = cage_bb.y;
- p1_d = p4_d;
- p2_d = p3_d;
p3_d = gimp_cage_transform_compute_destination (config, aux_buf, p3_s);
p4_d = gimp_cage_transform_compute_destination (config, aux_buf, p4_s);
- if (gimp_cage_config_point_inside(config, x, y))
- {
- gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
- out_buf,
- roi,
- p1_s, p1_d,
- p2_s, p2_d,
- p3_s, p3_d,
- 0,
- coords);
-
- gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
- out_buf,
- roi,
- p1_s, p1_d,
- p3_s, p3_d,
- p4_s, p4_d,
- 0,
- coords);
- }
+ for (y = cage_bb.y; y < cage_bb.y + cage_bb.height - 1; y++)
+ {
+ p1_s = p4_s;
+ p2_s = p3_s;
+ p3_s.y = y+1;
+ p4_s.y = y+1;
+
+ p1_d = p4_d;
+ p2_d = p3_d;
+ p3_d = gimp_cage_transform_compute_destination (config, aux_buf, p3_s);
+ p4_d = gimp_cage_transform_compute_destination (config, aux_buf, p4_s);
+
+ if (gimp_cage_config_point_inside(config, x, y))
+ {
+ gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
+ out_buf,
+ roi,
+ p1_s, p1_d,
+ p2_s, p2_d,
+ p3_s, p3_d,
+ 0,
+ coords);
+
+ gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
+ out_buf,
+ roi,
+ p1_s, p1_d,
+ p3_s, p3_d,
+ p4_s, p4_d,
+ 0,
+ coords);
+ }
+ }
}
- }
g_slice_free1 (2 * sizeof (gfloat), coords);
@@ -320,7 +322,7 @@ gimp_operation_cage_transform_interpolate_source_coords_recurs (GimpOperationCag
gfloat *coords)
{
gint xmin, xmax, ymin, ymax;
- GeglRectangle rect = {0, 0, 1, 1};
+ GeglRectangle rect = { 0, 0, 1, 1 };
if (p1_d.x > roi->x + roi->width) return;
if (p2_d.x > roi->x + roi->width) return;
@@ -363,126 +365,124 @@ gimp_operation_cage_transform_interpolate_source_coords_recurs (GimpOperationCag
* if yes, we compute the coefficient of the barycenter for the pixel (x,y) and see if a pixel is inside (ie the 3 coef have the same sign).
*/
if (xmax - xmin == 1 && ymax - ymin == 1)
- {
+ {
+ gdouble a, b, c, denom, x, y;
- gdouble a, b, c, denom, x, y;
+ rect.x = xmax;
+ rect.y = ymax;
- rect.x = xmax;
- rect.y = ymax;
+ x = (gdouble) xmax;
+ y = (gdouble) ymax;
- x = (gdouble) xmax;
- y = (gdouble) ymax;
+ denom = (p2_d.x - p1_d.x) * p3_d.y + (p1_d.x - p3_d.x) * p2_d.y + (p3_d.x - p2_d.x) * p1_d.y;
+ a = ((p2_d.x - x) * p3_d.y + (x - p3_d.x) * p2_d.y + (p3_d.x - p2_d.x) * y) / denom;
+ b = - ((p1_d.x - x) * p3_d.y + (x - p3_d.x) * p1_d.y + (p3_d.x - p1_d.x) * y) / denom;
+ c = 1.0 - a - b;
- denom = (p2_d.x - p1_d.x) * p3_d.y + (p1_d.x - p3_d.x) * p2_d.y + (p3_d.x - p2_d.x) * p1_d.y;
- a = ((p2_d.x - x) * p3_d.y + (x - p3_d.x) * p2_d.y + (p3_d.x - p2_d.x) * y) / denom;
- b = - ((p1_d.x - x) * p3_d.y + (x - p3_d.x) * p1_d.y + (p3_d.x - p1_d.x) * y) / denom;
- c = 1.0 - a - b;
+ /* if a pixel is inside, we compute his source coordinate and set it in the output buffer */
+ if ((a > 0 && b > 0 && c > 0) || (a < 0 && b < 0 && c < 0))
+ {
+ coords[0] = (a * p1_s.x + b * p2_s.x + c * p3_s.x);
+ coords[1] = (a * p1_s.y + b * p2_s.y + c * p3_s.y);
- /* if a pixel is inside, we compute his source coordinate and set it in the output buffer */
- if ((a > 0 && b > 0 && c > 0) || (a < 0 && b < 0 && c < 0))
- {
- coords[0] = (a * p1_s.x + b * p2_s.x + c * p3_s.x);
- coords[1] = (a * p1_s.y + b * p2_s.y + c * p3_s.y);
-
- gegl_buffer_set(out_buf,
- &rect,
- oct->format_coords,
- coords,
- GEGL_AUTO_ROWSTRIDE);
- }
+ gegl_buffer_set (out_buf,
+ &rect,
+ oct->format_coords,
+ coords,
+ GEGL_AUTO_ROWSTRIDE);
+ }
- return;
- }
+ return;
+ }
else
- {
- /* we cut the triangle in 4 sub-triangle and treat it recursively */
- /*
- * /\
- * /__\
- * /\ /\
- * /__\/__\
- *
- */
-
- GimpVector2 pm1_d, pm2_d, pm3_d;
- GimpVector2 pm1_s, pm2_s, pm3_s;
-
- gint next_depth = recursion_depth + 1;
-
- pm1_d.x = (p1_d.x + p2_d.x) / 2.0;
- pm1_d.y = (p1_d.y + p2_d.y) / 2.0;
-
- pm2_d.x = (p2_d.x + p3_d.x) / 2.0;
- pm2_d.y = (p2_d.y + p3_d.y) / 2.0;
-
- pm3_d.x = (p3_d.x + p1_d.x) / 2.0;
- pm3_d.y = (p3_d.y + p1_d.y) / 2.0;
-
- pm1_s.x = (p1_s.x + p2_s.x) / 2.0;
- pm1_s.y = (p1_s.y + p2_s.y) / 2.0;
-
- pm2_s.x = (p2_s.x + p3_s.x) / 2.0;
- pm2_s.y = (p2_s.y + p3_s.y) / 2.0;
-
- pm3_s.x = (p3_s.x + p1_s.x) / 2.0;
- pm3_s.y = (p3_s.y + p1_s.y) / 2.0;
-
- gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
- out_buf,
- roi,
- p1_s, p1_d,
- pm1_s, pm1_d,
- pm3_s, pm3_d,
- next_depth,
- coords);
-
- gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
- out_buf,
- roi,
- pm1_s, pm1_d,
- p2_s, p2_d,
- pm2_s, pm2_d,
- next_depth,
- coords);
-
- gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
- out_buf,
- roi,
- pm1_s, pm1_d,
- pm2_s, pm2_d,
- pm3_s, pm3_d,
- next_depth,
- coords);
-
- gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
- out_buf,
- roi,
- pm3_s, pm3_d,
- pm2_s, pm2_d,
- p3_s, p3_d,
- next_depth,
- coords);
- }
-
+ {
+ /* we cut the triangle in 4 sub-triangle and treat it recursively */
+ /*
+ * /\
+ * /__\
+ * /\ /\
+ * /__\/__\
+ *
+ */
+
+ GimpVector2 pm1_d, pm2_d, pm3_d;
+ GimpVector2 pm1_s, pm2_s, pm3_s;
+
+ gint next_depth = recursion_depth + 1;
+
+ pm1_d.x = (p1_d.x + p2_d.x) / 2.0;
+ pm1_d.y = (p1_d.y + p2_d.y) / 2.0;
+
+ pm2_d.x = (p2_d.x + p3_d.x) / 2.0;
+ pm2_d.y = (p2_d.y + p3_d.y) / 2.0;
+
+ pm3_d.x = (p3_d.x + p1_d.x) / 2.0;
+ pm3_d.y = (p3_d.y + p1_d.y) / 2.0;
+
+ pm1_s.x = (p1_s.x + p2_s.x) / 2.0;
+ pm1_s.y = (p1_s.y + p2_s.y) / 2.0;
+
+ pm2_s.x = (p2_s.x + p3_s.x) / 2.0;
+ pm2_s.y = (p2_s.y + p3_s.y) / 2.0;
+
+ pm3_s.x = (p3_s.x + p1_s.x) / 2.0;
+ pm3_s.y = (p3_s.y + p1_s.y) / 2.0;
+
+ gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
+ out_buf,
+ roi,
+ p1_s, p1_d,
+ pm1_s, pm1_d,
+ pm3_s, pm3_d,
+ next_depth,
+ coords);
+
+ gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
+ out_buf,
+ roi,
+ pm1_s, pm1_d,
+ p2_s, p2_d,
+ pm2_s, pm2_d,
+ next_depth,
+ coords);
+
+ gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
+ out_buf,
+ roi,
+ pm1_s, pm1_d,
+ pm2_s, pm2_d,
+ pm3_s, pm3_d,
+ next_depth,
+ coords);
+
+ gimp_operation_cage_transform_interpolate_source_coords_recurs (oct,
+ out_buf,
+ roi,
+ pm3_s, pm3_d,
+ pm2_s, pm2_d,
+ p3_s, p3_d,
+ next_depth,
+ coords);
+ }
}
static GimpVector2
gimp_cage_transform_compute_destination (GimpCageConfig *config,
GeglBuffer *coef_buf,
- GimpVector2 coords)
+ GimpVector2 coords)
{
- gfloat *coef;
- gdouble pos_x, pos_y;
- gint i;
- GeglRectangle rect;
- GimpVector2 result;
- gint cvn = config->cage_vertice_number;
- Babl *format_coef = babl_format_n (babl_type ("float"), 2 * cvn);
+ gfloat *coef;
+ gdouble pos_x, pos_y;
+ gint i;
+ GeglRectangle rect;
+ GimpVector2 result;
+ gint cvn = config->cage_vertice_number;
+ Babl *format_coef = babl_format_n (babl_type ("float"), 2 * cvn);
rect.height = 1;
- rect.width = 1;
- rect.x = coords.x;
- rect.y = coords.y;
+ rect.width = 1;
+ rect.x = coords.x;
+ rect.y = coords.y;
coef = g_malloc (config->cage_vertice_number * 2 * sizeof(gfloat));
@@ -491,17 +491,17 @@ gimp_cage_transform_compute_destination (GimpCageConfig *config,
pos_x = 0;
pos_y = 0;
- for(i = 0; i < cvn; i++)
- {
- pos_x += coef[i] * config->cage_vertices_d[i].x;
- pos_y += coef[i] * config->cage_vertices_d[i].y;
- }
+ for (i = 0; i < cvn; i++)
+ {
+ pos_x += coef[i] * config->cage_vertices_d[i].x;
+ pos_y += coef[i] * config->cage_vertices_d[i].y;
+ }
- for(i = 0; i < cvn; i++)
- {
+ for (i = 0; i < cvn; i++)
+ {
pos_x += coef[i + cvn] * config->scaling_factor[i] * config->normal_d[i].x;
pos_y += coef[i + cvn] * config->scaling_factor[i] * config->normal_d[i].y;
- }
+ }
result.x = pos_x;
result.y = pos_y;
@@ -512,28 +512,31 @@ gimp_cage_transform_compute_destination (GimpCageConfig *config,
}
GeglRectangle
-gimp_operation_cage_transform_get_cached_region (GeglOperation *operation,
- const GeglRectangle *roi)
+gimp_operation_cage_transform_get_cached_region (GeglOperation *operation,
+ const GeglRectangle *roi)
{
- GeglRectangle result = *gegl_operation_source_get_bounding_box (operation, "input");
+ GeglRectangle result = *gegl_operation_source_get_bounding_box (operation,
+ "input");
return result;
}
GeglRectangle
-gimp_operation_cage_transform_get_required_for_output (GeglOperation *operation,
- const gchar *input_pad,
- const GeglRectangle *roi)
+gimp_operation_cage_transform_get_required_for_output (GeglOperation *operation,
+ const gchar *input_pad,
+ const GeglRectangle *roi)
{
- GeglRectangle result = *gegl_operation_source_get_bounding_box (operation, "input");
+ GeglRectangle result = *gegl_operation_source_get_bounding_box (operation,
+ "input");
return result;
}
GeglRectangle
-gimp_operation_cage_transform_get_bounding_box (GeglOperation *operation)
+gimp_operation_cage_transform_get_bounding_box (GeglOperation *operation)
{
- GeglRectangle result = *gegl_operation_source_get_bounding_box (operation, "input");
+ GeglRectangle result = *gegl_operation_source_get_bounding_box (operation,
+ "input");
return result;
}
diff --git a/app/gegl/gimpoperationcagetransform.h b/app/gegl/gimpoperationcagetransform.h
index 092a9a5..cd02932 100644
--- a/app/gegl/gimpoperationcagetransform.h
+++ b/app/gegl/gimpoperationcagetransform.h
@@ -20,6 +20,7 @@
#ifndef __GIMP_OPERATION_CAGE_TRANSFORM_H__
#define __GIMP_OPERATION_CAGE_TRANSFORM_H__
+
#include <gegl-plugin.h>
#include <operation/gegl-operation-composer.h>
@@ -30,6 +31,7 @@ enum
GIMP_OPERATION_CAGE_TRANSFORM_PROP_FILL
};
+
#define GIMP_TYPE_OPERATION_CAGE_TRANSFORM (gimp_operation_cage_transform_get_type ())
#define GIMP_OPERATION_CAGE_TRANSFORM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_OPERATION_CAGE_TRANSFORM, GimpOperationCageTransform))
#define GIMP_OPERATION_CAGE_TRANSFORM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_OPERATION_CAGE_TRANSFORM, GimpOperationCageTransformClass))
diff --git a/app/tools/gimpcageoptions.c b/app/tools/gimpcageoptions.c
index 98fa919..888f785 100644
--- a/app/tools/gimpcageoptions.c
+++ b/app/tools/gimpcageoptions.c
@@ -19,9 +19,11 @@
#include "config.h"
+#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpconfig/gimpconfig.h"
+#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
@@ -47,15 +49,16 @@ enum
PROP_FILL_PLAIN_COLOR
};
-static void gimp_cage_options_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gimp_cage_options_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec);
+static void gimp_cage_options_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gimp_cage_options_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+
G_DEFINE_TYPE (GimpCageOptions, gimp_cage_options,
GIMP_TYPE_TRANSFORM_OPTIONS)
@@ -90,10 +93,10 @@ gimp_cage_options_init (GimpCageOptions *options)
}
static void
-gimp_cage_options_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+gimp_cage_options_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GimpCageOptions *options = GIMP_CAGE_OPTIONS (object);
@@ -102,7 +105,6 @@ gimp_cage_options_set_property (GObject *object,
case PROP_CAGE_MODE:
options->cage_mode = g_value_get_enum (value);
break;
-
case PROP_FILL_PLAIN_COLOR:
options->fill_plain_color = g_value_get_boolean (value);
break;
@@ -114,10 +116,10 @@ gimp_cage_options_set_property (GObject *object,
}
static void
-gimp_cage_options_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+gimp_cage_options_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GimpCageOptions *options = GIMP_CAGE_OPTIONS (object);
@@ -126,7 +128,6 @@ gimp_cage_options_get_property (GObject *object,
case PROP_CAGE_MODE:
g_value_set_enum (value, options->cage_mode);
break;
-
case PROP_FILL_PLAIN_COLOR:
g_value_set_boolean (value, options->fill_plain_color);
break;
@@ -150,16 +151,14 @@ gimp_cage_options_gui (GimpToolOptions *tool_options)
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
-
mode = gimp_prop_enum_radio_box_new (config, "cage-mode", 0, 0);
gtk_box_pack_start (GTK_BOX (vbox), mode, FALSE, FALSE, 0);
gtk_widget_show (mode);
-
button = gimp_prop_check_button_new (config, "fill-plain-color",
_("Fill from first point"));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
-
+
return vbox;
}
diff --git a/app/tools/gimpcageoptions.h b/app/tools/gimpcageoptions.h
index b449c7f..14815b9 100644
--- a/app/tools/gimpcageoptions.h
+++ b/app/tools/gimpcageoptions.h
@@ -20,8 +20,8 @@
#ifndef __GIMP_CAGE_OPTIONS_H__
#define __GIMP_CAGE_OPTIONS_H__
+
#include "tools/gimptransformoptions.h"
-#include "libgimpbase/gimpbase.h"
#define GIMP_TYPE_CAGE_OPTIONS (gimp_cage_options_get_type ())
@@ -32,22 +32,20 @@
#define GIMP_CAGE_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CAGE_OPTIONS, GimpCageOptionsClass))
+typedef struct _GimpCageOptions GimpCageOptions;
typedef struct _GimpCageOptionsClass GimpCageOptionsClass;
-typedef struct _GimpCageOptions GimpCageOptions;
-
struct _GimpCageOptions
{
- GimpTransformOptions parent_instance;
-
- GimpCageMode cage_mode;
- gboolean fill_plain_color;
-};
+ GimpTransformOptions parent_instance;
+ GimpCageMode cage_mode;
+ gboolean fill_plain_color;
+};
struct _GimpCageOptionsClass
{
- GimpToolOptionsClass parent_class;
+ GimpToolOptionsClass parent_class;
};
@@ -55,4 +53,5 @@ GType gimp_cage_options_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_cage_options_gui (GimpToolOptions *tool_options);
+
#endif /* __GIMP_CAGE_OPTIONS_H__ */
diff --git a/app/tools/gimpcagetool.c b/app/tools/gimpcagetool.c
index 4eb86c9..172ceee 100644
--- a/app/tools/gimpcagetool.c
+++ b/app/tools/gimpcagetool.c
@@ -17,7 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
#include "config.h"
#include <string.h>
@@ -26,121 +25,120 @@
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
+#include "libgimpbase/gimpbase.h"
#include "libgimpmath/gimpmath.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
-#include "tools/tools-enums.h"
-#include "gimptoolcontrol.h"
-#include "core/core-types.h"
+#include "base/tile-manager.h"
#include "core/gimp.h"
#include "core/gimp-transform-utils.h"
#include "core/gimpchannel.h"
-#include "core/gimpdrawable.h"
#include "core/gimpdrawable-operation.h"
#include "core/gimpdrawable-shadow.h"
#include "core/gimpimage.h"
#include "core/gimpimagemap.h"
#include "core/gimplayer.h"
-#include "core/gimpprojection.h"
#include "core/gimpprogress.h"
+#include "core/gimpprojection.h"
+
+#include "gegl/gimpcageconfig.h"
+
+#include "widgets/gimphelp-ids.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-transform.h"
-#include "base/tile-manager.h"
-
-#include "widgets/gimphelp-ids.h"
-
#include "gimpcagetool.h"
#include "gimpcageoptions.h"
+#include "gimptoolcontrol.h"
#include "gimp-intl.h"
-#include <stdio.h>
-
-/*static gboolean gimp_cage_tool_initialize (GimpTool *tool,
- GimpDisplay *display,
- GError **error);*/
-static void gimp_cage_tool_finalize (GObject *object);
-static void gimp_cage_tool_start (GimpCageTool *ct,
- GimpDisplay *display);
-static void gimp_cage_tool_halt (GimpCageTool *ct);
-static void gimp_cage_tool_button_press (GimpTool *tool,
- const GimpCoords *coords,
- guint32 time,
- GdkModifierType state,
- GimpButtonPressType press_type,
- GimpDisplay *display);
-static void gimp_cage_tool_button_release (GimpTool *tool,
- const GimpCoords *coords,
- guint32 time,
- GdkModifierType state,
- GimpButtonReleaseType release_type,
- GimpDisplay *display);
-static gboolean gimp_cage_tool_key_press (GimpTool *tool,
- GdkEventKey *kevent,
- GimpDisplay *display);
-static void gimp_cage_tool_motion (GimpTool *tool,
- const GimpCoords *coords,
- guint32 time,
- GdkModifierType state,
- GimpDisplay *display);
-static void gimp_cage_tool_control (GimpTool *tool,
- GimpToolAction action,
- GimpDisplay *display);
-static void gimp_cage_tool_cursor_update (GimpTool *tool,
- const GimpCoords *coords,
- GdkModifierType state,
- GimpDisplay *display);
-static void gimp_cage_tool_oper_update (GimpTool *tool,
- const GimpCoords *coords,
- GdkModifierType state,
- gboolean proximity,
- GimpDisplay *display);
-
-static gint gimp_cage_tool_is_on_handle (GimpCageConfig *gcc,
- GimpDrawTool *draw_tool,
- GimpDisplay *display,
- GimpCageMode mode,
- gdouble x,
- gdouble y,
- gint handle_size);
-static void gimp_cage_tool_draw (GimpDrawTool *draw_tool);
-static void gimp_cage_tool_switch_to_deform (GimpCageTool *ct);
-static void gimp_cage_tool_remove_last_handle (GimpCageTool *ct);
-static void gimp_cage_tool_compute_coef (GimpCageTool *ct,
- GimpDisplay *display);
-static void gimp_cage_tool_process (GimpCageTool *ct,
- GimpDisplay *display);
-static void gimp_cage_tool_process_drawable (GimpCageTool *ct,
- GimpDrawable *drawable,
- GimpProgress *progress);
-static void gimp_cage_tool_prepare_preview (GimpCageTool *ct,
- GimpDisplay *display);
-static gboolean gimp_cage_tool_update_preview (GimpTool *tool);
-
-static GeglNode* gimp_cage_tool_get_render_node (GimpCageTool *ct,
- GeglNode *parent);
+
+#define HANDLE_SIZE 25
+
+
+static void gimp_cage_tool_finalize (GObject *object);
+static void gimp_cage_tool_start (GimpCageTool *ct,
+ GimpDisplay *display);
+static void gimp_cage_tool_halt (GimpCageTool *ct);
+static void gimp_cage_tool_button_press (GimpTool *tool,
+ const GimpCoords *coords,
+ guint32 time,
+ GdkModifierType state,
+ GimpButtonPressType press_type,
+ GimpDisplay *display);
+static void gimp_cage_tool_button_release (GimpTool *tool,
+ const GimpCoords *coords,
+ guint32 time,
+ GdkModifierType state,
+ GimpButtonReleaseType release_type,
+ GimpDisplay *display);
+static gboolean gimp_cage_tool_key_press (GimpTool *tool,
+ GdkEventKey *kevent,
+ GimpDisplay *display);
+static void gimp_cage_tool_motion (GimpTool *tool,
+ const GimpCoords *coords,
+ guint32 time,
+ GdkModifierType state,
+ GimpDisplay *display);
+static void gimp_cage_tool_control (GimpTool *tool,
+ GimpToolAction action,
+ GimpDisplay *display);
+static void gimp_cage_tool_cursor_update (GimpTool *tool,
+ const GimpCoords *coords,
+ GdkModifierType state,
+ GimpDisplay *display);
+static void gimp_cage_tool_oper_update (GimpTool *tool,
+ const GimpCoords *coords,
+ GdkModifierType state,
+ gboolean proximity,
+ GimpDisplay *display);
+
+static void gimp_cage_tool_draw (GimpDrawTool *draw_tool);
+
+static gint gimp_cage_tool_is_on_handle (GimpCageConfig *gcc,
+ GimpDrawTool *draw_tool,
+ GimpDisplay *display,
+ GimpCageMode mode,
+ gdouble x,
+ gdouble y,
+ gint handle_size);
+
+static void gimp_cage_tool_switch_to_deform (GimpCageTool *ct);
+static void gimp_cage_tool_remove_last_handle (GimpCageTool *ct);
+static void gimp_cage_tool_compute_coef (GimpCageTool *ct,
+ GimpDisplay *display);
+static void gimp_cage_tool_process (GimpCageTool *ct,
+ GimpDisplay *display);
+static void gimp_cage_tool_process_drawable (GimpCageTool *ct,
+ GimpDrawable *drawable,
+ GimpProgress *progress);
+static void gimp_cage_tool_prepare_preview (GimpCageTool *ct,
+ GimpDisplay *display);
+static gboolean gimp_cage_tool_update_preview (GimpTool *tool);
+
+static GeglNode * gimp_cage_tool_get_render_node (GimpCageTool *ct,
+ GeglNode *parent);
G_DEFINE_TYPE (GimpCageTool, gimp_cage_tool, GIMP_TYPE_DRAW_TOOL)
#define parent_class gimp_cage_tool_parent_class
-#define HANDLE_SIZE 25
void
gimp_cage_tool_register (GimpToolRegisterCallback callback,
gpointer data)
{
- (* callback) (GIMP_TYPE_CAGE_TOOL, /* Tool type */
- GIMP_TYPE_CAGE_OPTIONS, /*Tool options type*/
- gimp_cage_options_gui, /*Tool opions gui*/
- 0, /*context_props*/
+ (* callback) (GIMP_TYPE_CAGE_TOOL,
+ GIMP_TYPE_CAGE_OPTIONS,
+ gimp_cage_options_gui,
+ 0,
"gimp-cage-tool",
_("Cage Transform"),
_("Cage Transform: Deform a selection with a cage"),
@@ -153,66 +151,53 @@ gimp_cage_tool_register (GimpToolRegisterCallback callback,
static void
gimp_cage_tool_class_init (GimpCageToolClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
- GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
-
- object_class->finalize = gimp_cage_tool_finalize;
-
- /*tool_class->initialize = gimp_cage_tool_initialize;*/
- tool_class->button_press = gimp_cage_tool_button_press;
- tool_class->button_release = gimp_cage_tool_button_release;
- tool_class->key_press = gimp_cage_tool_key_press;
- tool_class->motion = gimp_cage_tool_motion;
- tool_class->control = gimp_cage_tool_control;
- tool_class->cursor_update = gimp_cage_tool_cursor_update;
- tool_class->oper_update = gimp_cage_tool_oper_update;
-
- draw_tool_class->draw = gimp_cage_tool_draw;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
+ GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
+
+ object_class->finalize = gimp_cage_tool_finalize;
+
+ tool_class->button_press = gimp_cage_tool_button_press;
+ tool_class->button_release = gimp_cage_tool_button_release;
+ tool_class->key_press = gimp_cage_tool_key_press;
+ tool_class->motion = gimp_cage_tool_motion;
+ tool_class->control = gimp_cage_tool_control;
+ tool_class->cursor_update = gimp_cage_tool_cursor_update;
+ tool_class->oper_update = gimp_cage_tool_oper_update;
+
+ draw_tool_class->draw = gimp_cage_tool_draw;
}
static void
gimp_cage_tool_init (GimpCageTool *self)
{
- self->config = g_object_new (GIMP_TYPE_CAGE_CONFIG, NULL);
+ self->config = g_object_new (GIMP_TYPE_CAGE_CONFIG, NULL);
self->cursor_position.x = 0;
self->cursor_position.y = 0;
- self->handle_moved = -1;
- self->cage_complete = FALSE;
+ self->handle_moved = -1;
+ self->cage_complete = FALSE;
- self->coef = NULL;
- self->image_map = NULL;
- self->node_preview = NULL;
+ self->coef = NULL;
+ self->image_map = NULL;
+ self->node_preview = NULL;
- self->idle_id = 0;
+ self->idle_id = 0;
}
-/*static gboolean
-gimp_cage_tool_initialize (GimpTool *tool,
- GimpDisplay *display,
- GError **error)
-{
- GimpCageTool *cage_tool = GIMP_CAGE_TOOL (tool);
-
- return GIMP_TOOL_CLASS (parent_class)->initialize(tool, display, error);
-}*/
-
static void
gimp_cage_tool_finalize (GObject *object)
{
- GimpCageTool *ct = GIMP_CAGE_TOOL (object);
+ GimpCageTool *ct = GIMP_CAGE_TOOL (object);
gimp_cage_tool_halt (ct);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
-
-
static void
gimp_cage_tool_control (GimpTool *tool,
- GimpToolAction action,
- GimpDisplay *display)
+ GimpToolAction action,
+ GimpDisplay *display)
{
switch (action)
{
@@ -228,17 +213,16 @@ gimp_cage_tool_control (GimpTool *tool,
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
}
-
static void
-gimp_cage_tool_start (GimpCageTool *ct,
- GimpDisplay *display)
+gimp_cage_tool_start (GimpCageTool *ct,
+ GimpDisplay *display)
{
- GimpTool *tool = GIMP_TOOL (ct);
- GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
- GimpImage *image = gimp_display_get_image (display);
- GimpDrawable *drawable = gimp_image_get_active_drawable (image);
- gint off_x;
- gint off_y;
+ GimpTool *tool = GIMP_TOOL (ct);
+ GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
+ GimpImage *image = gimp_display_get_image (display);
+ GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+ gint off_x;
+ gint off_y;
gimp_tool_control_activate (tool->control);
@@ -255,17 +239,16 @@ gimp_cage_tool_start (GimpCageTool *ct,
g_object_unref (ct->image_map);
}
- ct->config = g_object_new (GIMP_TYPE_CAGE_CONFIG, NULL);
+ ct->config = g_object_new (GIMP_TYPE_CAGE_CONFIG, NULL);
ct->cursor_position.x = -1000;
ct->cursor_position.y = -1000;
- ct->handle_moved = -1;
- ct->cage_complete = FALSE;
-
- /*Setting up cage offset to convert the cage point coords to drawable coords*/
- gimp_item_get_offset (GIMP_ITEM (drawable),
- &off_x,
- &off_y);
+ ct->handle_moved = -1;
+ ct->cage_complete = FALSE;
+ /* Setting up cage offset to convert the cage point coords to
+ * drawable coords
+ */
+ gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
ct->config->offset_x = off_x;
ct->config->offset_y = off_y;
@@ -279,7 +262,7 @@ gimp_cage_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *display)
{
- GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
+ GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
switch (kevent->keyval)
{
@@ -291,17 +274,18 @@ gimp_cage_tool_key_press (GimpTool *tool,
case GDK_KP_Enter:
case GDK_ISO_Enter:
if (ct->cage_complete)
- {
- gimp_image_map_abort (ct->image_map);
- g_object_unref (ct->image_map);
- ct->image_map = NULL;
- if (ct->idle_id)
- {
- g_source_remove(ct->idle_id);
- ct->idle_id = 0; /*Stop preview update for now*/
- }
- gimp_cage_tool_process (ct, display); /*RUN IT BABY*/
- }
+ {
+ gimp_image_map_abort (ct->image_map);
+ g_object_unref (ct->image_map);
+ ct->image_map = NULL;
+ if (ct->idle_id)
+ {
+ g_source_remove (ct->idle_id);
+ ct->idle_id = 0;
+ }
+
+ gimp_cage_tool_process (ct, display);
+ }
return TRUE;
case GDK_Escape:
@@ -317,43 +301,41 @@ gimp_cage_tool_key_press (GimpTool *tool,
static void
gimp_cage_tool_motion (GimpTool *tool,
- const GimpCoords *coords,
- guint32 time,
- GdkModifierType state,
- GimpDisplay *display)
+ const GimpCoords *coords,
+ guint32 time,
+ GdkModifierType state,
+ GimpDisplay *display)
{
- GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
- GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
- GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
- GimpCageConfig *config = ct->config;
-
+ GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
+ GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
+ GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
+ GimpCageConfig *config = ct->config;
gimp_draw_tool_pause (draw_tool);
-
if (ct->handle_moved >= 0)
- {
- gimp_cage_config_move_cage_point (config,
- options->cage_mode,
- ct->handle_moved,
- coords->x,
- coords->y);
- }
+ {
+ gimp_cage_config_move_cage_point (config,
+ options->cage_mode,
+ ct->handle_moved,
+ coords->x,
+ coords->y);
+ }
gimp_draw_tool_resume (draw_tool);
}
static void
-gimp_cage_tool_oper_update (GimpTool *tool,
- const GimpCoords *coords,
- GdkModifierType state,
- gboolean proximity,
- GimpDisplay *display)
+gimp_cage_tool_oper_update (GimpTool *tool,
+ const GimpCoords *coords,
+ GdkModifierType state,
+ gboolean proximity,
+ GimpDisplay *display)
{
- GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
- GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
- GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
- GimpCageConfig *config = ct->config;
+ GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
+ GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
+ GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
+ GimpCageConfig *config = ct->config;
gint active_handle = -1;
if (config)
@@ -363,7 +345,8 @@ gimp_cage_tool_oper_update (GimpTool *tool,
options->cage_mode,
coords->x,
coords->y,
- HANDLE_SIZE );
+ HANDLE_SIZE);
+
if (!ct->cage_complete || (active_handle > -1))
{
gimp_draw_tool_pause (draw_tool);
@@ -375,69 +358,63 @@ gimp_cage_tool_oper_update (GimpTool *tool,
}
}
-
static void
-gimp_cage_tool_button_press (GimpTool *tool,
- const GimpCoords *coords,
- guint32 time,
- GdkModifierType state,
- GimpButtonPressType press_type,
- GimpDisplay *display)
+gimp_cage_tool_button_press (GimpTool *tool,
+ const GimpCoords *coords,
+ guint32 time,
+ GdkModifierType state,
+ GimpButtonPressType press_type,
+ GimpDisplay *display)
{
- GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
- GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
- GimpCageConfig *config = ct->config;
+ GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
+ GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
+ GimpCageConfig *config = ct->config;
g_return_if_fail (GIMP_IS_CAGE_TOOL (ct));
if (display != tool->display)
- {
- gimp_cage_tool_start (ct,
- display);
- config = ct->config;
- }
+ {
+ gimp_cage_tool_start (ct, display);
+ config = ct->config;
+ }
gimp_draw_tool_pause (GIMP_DRAW_TOOL (ct));
-
if (ct->handle_moved < 0)
- {
- ct->handle_moved = gimp_cage_tool_is_on_handle (config,
- GIMP_DRAW_TOOL(ct),
- display,
- options->cage_mode,
- coords->x,
- coords->y,
- HANDLE_SIZE);
- if (ct->handle_moved > 0 && ct->idle_id > 0)
- {
- g_source_remove(ct->idle_id);
- ct->idle_id = 0; /*Stop preview update for now*/
- }
- }
+ {
+ ct->handle_moved = gimp_cage_tool_is_on_handle (config,
+ GIMP_DRAW_TOOL (ct),
+ display,
+ options->cage_mode,
+ coords->x,
+ coords->y,
+ HANDLE_SIZE);
+ if (ct->handle_moved > 0 && ct->idle_id > 0)
+ {
+ g_source_remove(ct->idle_id);
+ ct->idle_id = 0; /*Stop preview update for now*/
+ }
+ }
if (ct->handle_moved < 0 && !ct->cage_complete)
- {
- gimp_cage_config_add_cage_point (config,
- coords->x,
- coords->y);
- }
+ {
+ gimp_cage_config_add_cage_point (config, coords->x, coords->y);
+ }
gimp_draw_tool_resume (GIMP_DRAW_TOOL (ct));
/* user is clicking on the first handle, we close the cage and
- * switch to deform mode*/
+ * switch to deform mode
+ */
if (ct->handle_moved == 0 && config->cage_vertice_number > 2 && !ct->coef)
- {
- ct->cage_complete = TRUE;
- gimp_cage_tool_switch_to_deform (ct);
-
- gimp_cage_config_reverse_cage_if_needed (config);
- gimp_cage_tool_compute_coef (ct, display);
- gimp_cage_tool_prepare_preview (ct, display);
-
- }
+ {
+ ct->cage_complete = TRUE;
+ gimp_cage_tool_switch_to_deform (ct);
+ gimp_cage_config_reverse_cage_if_needed (config);
+ gimp_cage_tool_compute_coef (ct, display);
+ gimp_cage_tool_prepare_preview (ct, display);
+ }
}
void
@@ -450,116 +427,96 @@ gimp_cage_tool_button_release (GimpTool *tool,
{
GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
-
if (ct->coef && ct->handle_moved > -1)
- {
-
- GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
- GimpItem *item = GIMP_ITEM (tool->drawable);
+ {
+ GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
+ GimpItem *item = GIMP_ITEM (tool->drawable);
+ gint x, y;
+ gint w, h;
+ gint off_x, off_y;
+ GeglRectangle visible;
- gint x, y;
- gint w, h;
- gint off_x, off_y;
- GeglRectangle visible;
+ gimp_display_shell_untransform_viewport (shell, &x, &y, &w, &h);
- gimp_display_shell_untransform_viewport (shell, &x, &y, &w, &h);
+ gimp_item_get_offset (item, &off_x, &off_y);
- gimp_item_get_offset (item, &off_x, &off_y);
+ gimp_rectangle_intersect (x, y, w, h,
+ off_x,
+ off_y,
+ gimp_item_get_width (item),
+ gimp_item_get_height (item),
+ &visible.x,
+ &visible.y,
+ &visible.width,
+ &visible.height);
- gimp_rectangle_intersect (x, y, w, h,
- off_x,
- off_y,
- gimp_item_get_width (item),
- gimp_item_get_height (item),
- &visible.x,
- &visible.y,
- &visible.width,
- &visible.height);
+ visible.x -= off_x;
+ visible.y -= off_y;
- visible.x -= off_x;
- visible.y -= off_y;
+ gimp_draw_tool_pause (GIMP_DRAW_TOOL (ct));
- gimp_draw_tool_pause (GIMP_DRAW_TOOL (ct));
+ gimp_image_map_apply (ct->image_map, &visible);
- gimp_image_map_apply (ct->image_map, &visible);
+ ct->idle_id = g_idle_add ((GSourceFunc) gimp_cage_tool_update_preview,
+ tool);
- ct->idle_id = g_idle_add ((GSourceFunc) gimp_cage_tool_update_preview, tool);
+ gimp_draw_tool_resume (GIMP_DRAW_TOOL (ct));
+ }
- gimp_draw_tool_resume (GIMP_DRAW_TOOL (ct));
- }
ct->handle_moved = -1;
-
}
static void
-gimp_cage_tool_cursor_update (GimpTool *tool,
- const GimpCoords *coords,
- GdkModifierType state,
- GimpDisplay *display)
+gimp_cage_tool_cursor_update (GimpTool *tool,
+ const GimpCoords *coords,
+ GdkModifierType state,
+ GimpDisplay *display)
{
- GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
- GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
+ GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
+ GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
if (tool->display == NULL)
- {
- GIMP_TOOL_CLASS (parent_class)->cursor_update (tool,
- coords,
- state,
- display);
- }
- else
- {
- GimpCursorModifier modifier;
-
- if (options->cage_mode == GIMP_CAGE_MODE_CAGE_CHANGE)
{
- modifier = GIMP_CURSOR_MODIFIER_ANCHOR;
+ GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state,
+ display);
}
- else
+ else
{
- modifier = GIMP_CURSOR_MODIFIER_MOVE;
+ GimpCursorModifier modifier;
+
+ if (options->cage_mode == GIMP_CAGE_MODE_CAGE_CHANGE)
+ {
+ modifier = GIMP_CURSOR_MODIFIER_ANCHOR;
+ }
+ else
+ {
+ modifier = GIMP_CURSOR_MODIFIER_MOVE;
+ }
+
+ gimp_tool_set_cursor (tool, display,
+ gimp_tool_control_get_cursor (tool->control),
+ gimp_tool_control_get_tool_cursor (tool->control),
+ modifier);
}
-
- gimp_tool_set_cursor (tool, display,
- gimp_tool_control_get_cursor (tool->control),
- gimp_tool_control_get_tool_cursor (tool->control),
- modifier);
- }
}
-
-/**
- * gimp_cage_tool_draw:
- * @draw_tool:
- *
- * Draw the tool on the canvas.
- */
static void
gimp_cage_tool_draw (GimpDrawTool *draw_tool)
{
- GimpCageTool *ct = GIMP_CAGE_TOOL (draw_tool);
- GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
- GimpCageConfig *config = ct->config;
-
- gint i = 0;
- gint on_handle = -1;
- GimpVector2 *vertices;
-
+ GimpCageTool *ct = GIMP_CAGE_TOOL (draw_tool);
+ GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
+ GimpCageConfig *config = ct->config;
+ gint i = 0;
+ gint on_handle = -1;
+ GimpVector2 *vertices;
if (config->cage_vertice_number <= 0)
- {
return;
- }
if (options->cage_mode == GIMP_CAGE_MODE_CAGE_CHANGE)
- {
vertices = config->cage_vertices;
- }
else
- {
vertices = config->cage_vertices_d;
- }
-
/*gimp_draw_tool_add_lines (draw_tool,
vertices,
@@ -567,21 +524,21 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool)
FALSE);*/
if (!ct->cage_complete && ct->cursor_position.x != -1000)
- {
- gimp_draw_tool_add_line (draw_tool,
- vertices[config->cage_vertice_number - 1].x + ct->config->offset_x,
- vertices[config->cage_vertice_number - 1].y + ct->config->offset_y,
- ct->cursor_position.x,
- ct->cursor_position.y);
- }
+ {
+ gimp_draw_tool_add_line (draw_tool,
+ vertices[config->cage_vertice_number - 1].x + ct->config->offset_x,
+ vertices[config->cage_vertice_number - 1].y + ct->config->offset_y,
+ ct->cursor_position.x,
+ ct->cursor_position.y);
+ }
else
- {
- gimp_draw_tool_add_line (draw_tool,
- vertices[config->cage_vertice_number - 1].x + ct->config->offset_x,
- vertices[config->cage_vertice_number - 1].y + ct->config->offset_y,
- vertices[0].x + ct->config->offset_x,
- vertices[0].y + ct->config->offset_y);
- }
+ {
+ gimp_draw_tool_add_line (draw_tool,
+ vertices[config->cage_vertice_number - 1].x + ct->config->offset_x,
+ vertices[config->cage_vertice_number - 1].y + ct->config->offset_y,
+ vertices[0].x + ct->config->offset_x,
+ vertices[0].y + ct->config->offset_y);
+ }
on_handle = gimp_cage_tool_is_on_handle (config,
draw_tool,
@@ -592,41 +549,38 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool)
HANDLE_SIZE);
for(i = 0; i < config->cage_vertice_number; i++)
- {
-
- GimpHandleType handle = GIMP_HANDLE_CIRCLE;
-
- if (i == on_handle)
{
- handle = GIMP_HANDLE_FILLED_CIRCLE;
+ GimpHandleType handle = GIMP_HANDLE_CIRCLE;
+
+ if (i == on_handle)
+ handle = GIMP_HANDLE_FILLED_CIRCLE;
+
+ if (i > 0)
+ gimp_draw_tool_add_line (draw_tool,
+ vertices[i - 1].x + ct->config->offset_x,
+ vertices[i - 1].y + ct->config->offset_y,
+ vertices[i].x + ct->config->offset_x,
+ vertices[i].y + ct->config->offset_y);
+
+ gimp_draw_tool_add_handle (draw_tool,
+ handle,
+ vertices[i].x + ct->config->offset_x,
+ vertices[i].y + ct->config->offset_y,
+ HANDLE_SIZE, HANDLE_SIZE,
+ GTK_ANCHOR_CENTER);
}
-
- if (i > 0)
- gimp_draw_tool_add_line (draw_tool,
- vertices[i - 1].x + ct->config->offset_x,
- vertices[i - 1].y + ct->config->offset_y,
- vertices[i].x + ct->config->offset_x,
- vertices[i].y + ct->config->offset_y);
-
- gimp_draw_tool_add_handle (draw_tool,
- handle,
- vertices[i].x + ct->config->offset_x,
- vertices[i].y + ct->config->offset_y,
- HANDLE_SIZE, HANDLE_SIZE,
- GTK_ANCHOR_CENTER);
- }
}
static gint
-gimp_cage_tool_is_on_handle (GimpCageConfig *gcc,
- GimpDrawTool *draw_tool,
- GimpDisplay *display,
- GimpCageMode mode,
- gdouble x,
- gdouble y,
- gint handle_size)
+gimp_cage_tool_is_on_handle (GimpCageConfig *gcc,
+ GimpDrawTool *draw_tool,
+ GimpDisplay *display,
+ GimpCageMode mode,
+ gdouble x,
+ gdouble y,
+ gint handle_size)
{
- gint i;
+ gint i;
gdouble vert_x;
gdouble vert_y;
gdouble dist = G_MAXDOUBLE;
@@ -637,30 +591,26 @@ gimp_cage_tool_is_on_handle (GimpCageConfig *gcc,
return -1;
for (i = 0; i < gcc->cage_vertice_number; i++)
- {
- if (mode == GIMP_CAGE_MODE_CAGE_CHANGE)
{
- vert_x = gcc->cage_vertices[i].x + gcc->offset_x;
- vert_y = gcc->cage_vertices[i].y + gcc->offset_y;
+ if (mode == GIMP_CAGE_MODE_CAGE_CHANGE)
+ {
+ vert_x = gcc->cage_vertices[i].x + gcc->offset_x;
+ vert_y = gcc->cage_vertices[i].y + gcc->offset_y;
+ }
+ else
+ {
+ vert_x = gcc->cage_vertices_d[i].x + gcc->offset_x;
+ vert_y = gcc->cage_vertices_d[i].y + gcc->offset_y;
+ }
+
+ dist = gimp_draw_tool_calc_distance_square (GIMP_DRAW_TOOL (draw_tool),
+ display,
+ x, y,
+ vert_x, vert_y);
+
+ if (dist <= (handle_size * handle_size))
+ return i;
}
- else
- {
- vert_x = gcc->cage_vertices_d[i].x + gcc->offset_x;
- vert_y = gcc->cage_vertices_d[i].y + gcc->offset_y;
- }
-
- dist = gimp_draw_tool_calc_distance_square (GIMP_DRAW_TOOL (draw_tool),
- display,
- x,
- y,
- vert_x,
- vert_y);
-
- if (dist <= (handle_size * handle_size))
- {
- return i;
- }
- }
return -1;
}
@@ -668,17 +618,19 @@ gimp_cage_tool_is_on_handle (GimpCageConfig *gcc,
static void
gimp_cage_tool_remove_last_handle (GimpCageTool *ct)
{
- GimpCageConfig *config = ct->config;
+ GimpCageConfig *config = ct->config;
gimp_draw_tool_pause (GIMP_DRAW_TOOL (ct));
+
gimp_cage_config_remove_last_cage_point (config);
+
gimp_draw_tool_resume (GIMP_DRAW_TOOL (ct));
}
static void
gimp_cage_tool_switch_to_deform (GimpCageTool *ct)
{
- GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
+ GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
g_object_set (options, "cage-mode", GIMP_CAGE_MODE_DEFORM, NULL);
}
@@ -687,39 +639,39 @@ static void
gimp_cage_tool_compute_coef (GimpCageTool *ct,
GimpDisplay *display)
{
- GimpCageConfig *config = ct->config;
-
- Babl *format;
- GeglNode *gegl, *input, *output;
- GeglProcessor *processor;
- GimpProgress *progress;
- GeglBuffer *buffer;
- gdouble value;
+ GimpCageConfig *config = ct->config;
+ Babl *format;
+ GeglNode *gegl, *input, *output;
+ GeglProcessor *processor;
+ GimpProgress *progress;
+ GeglBuffer *buffer;
+ gdouble value;
if (ct->coef)
- {
- gegl_buffer_destroy (ct->coef);
- ct->coef = NULL;
- }
+ {
+ gegl_buffer_destroy (ct->coef);
+ ct->coef = NULL;
+ }
- format = babl_format_n(babl_type("float"), config->cage_vertice_number * 2);
+ format = babl_format_n (babl_type ("float"),
+ config->cage_vertice_number * 2);
progress = gimp_progress_start (GIMP_PROGRESS (display),
- _("Coefficient computation"),
- FALSE);
+ _("Coefficient computation"),
+ FALSE);
gegl = gegl_node_new ();
input = gegl_node_new_child (gegl,
- "operation", "gimp:cage_coef_calc",
- "config", ct->config,
- NULL);
+ "operation", "gimp:cage_coef_calc",
+ "config", ct->config,
+ NULL);
output = gegl_node_new_child (gegl,
- "operation", "gegl:buffer-sink",
- "buffer", &buffer,
- "format", format,
- NULL);
+ "operation", "gegl:buffer-sink",
+ "buffer", &buffer,
+ "format", format,
+ NULL);
gegl_node_connect_to (input, "output",
output, "input");
@@ -727,33 +679,30 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
processor = gegl_node_new_processor (output, NULL);
while (gegl_processor_work (processor, &value))
- {
+ {
gimp_progress_set_value (progress, value);
- }
+ }
gimp_progress_end (progress);
+
gegl_processor_destroy (processor);
ct->coef = buffer;
g_object_unref (gegl);
}
-static GeglNode*
+static GeglNode *
gimp_cage_tool_get_render_node (GimpCageTool *ct,
GeglNode *parent)
{
- GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
+ GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
+ GeglNode *coef, *cage, *render; /* Render nodes */
+ GeglNode *input, *output; /* Proxy nodes*/
+ GeglNode *node; /* wraper to be returned */
- GeglNode *coef, *cage, *render; /* Render nodes */
- GeglNode *input, *output; /* Proxy nodes*/
- GeglNode *node; /* wraper to be returned */
-
- node = gegl_node_new_child (parent,
- NULL,
- NULL);
+ node = gegl_node_new_child (parent, NULL, NULL);
input = gegl_node_get_input_proxy (node, "input");
-
output = gegl_node_get_output_proxy (node, "output");
coef = gegl_node_new_child (ct->node_preview,
@@ -762,8 +711,8 @@ gimp_cage_tool_get_render_node (GimpCageTool *ct,
NULL);
cage = gegl_node_new_child (parent,
- "operation", "gimp:cage_transform",
- "config", ct->config,
+ "operation", "gimp:cage_transform",
+ "config", ct->config,
"fill_plain_color", options->fill_plain_color,
NULL);
@@ -792,22 +741,19 @@ static void
gimp_cage_tool_prepare_preview (GimpCageTool *ct,
GimpDisplay *display)
{
- GimpImage *image = gimp_display_get_image (display);
- GimpDrawable *drawable = gimp_image_get_active_drawable (image);
-
-
- GeglNode *node;
+ GimpImage *image = gimp_display_get_image (display);
+ GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+ GeglNode *node;
if (ct->node_preview)
- {
- g_object_unref (ct->node_preview);
- ct->node_preview = NULL;
- }
+ {
+ g_object_unref (ct->node_preview);
+ ct->node_preview = NULL;
+ }
ct->node_preview = gegl_node_new ();
- node = gimp_cage_tool_get_render_node (ct,
- ct->node_preview);
+ node = gimp_cage_tool_get_render_node (ct, ct->node_preview);
ct->image_map = gimp_image_map_new (drawable,
_("Cage transform"),
@@ -819,17 +765,17 @@ gimp_cage_tool_prepare_preview (GimpCageTool *ct,
static gboolean
gimp_cage_tool_update_preview (GimpTool *tool)
{
- GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
- GimpImage *image = gimp_display_get_image (tool->display);
+ GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
+ GimpImage *image = gimp_display_get_image (tool->display);
if (!ct->image_map)
- {
+ {
/*Destroyed, bailing out*/
ct->idle_id = 0;
return FALSE;
- }
+ }
- if (!gimp_image_map_is_busy(ct->image_map))
+ if (! gimp_image_map_is_busy (ct->image_map))
{
ct->idle_id = 0;
gimp_projection_flush_now (gimp_image_get_projection (image));
@@ -838,52 +784,45 @@ gimp_cage_tool_update_preview (GimpTool *tool)
}
return TRUE;
-
-
}
static void
gimp_cage_tool_process (GimpCageTool *ct,
GimpDisplay *display)
{
-
-
- GimpImage *image = gimp_display_get_image (display);
- GimpLayer *layer = gimp_image_get_active_layer (image);
- GimpDrawable *drawable = GIMP_DRAWABLE (layer);
- GimpDrawable *mask = GIMP_DRAWABLE (gimp_layer_get_mask(layer));
-
+ GimpImage *image = gimp_display_get_image (display);
+ GimpLayer *layer = gimp_image_get_active_layer (image);
+ GimpDrawable *drawable = GIMP_DRAWABLE (layer);
+ GimpDrawable *mask = GIMP_DRAWABLE (gimp_layer_get_mask(layer));
g_return_if_fail (ct->coef);
-
if (GIMP_IS_DRAWABLE (drawable))
- {
+ {
+ GimpProgress *progress;
- GimpProgress *progress;
+ progress = gimp_progress_start (GIMP_PROGRESS (display),
+ _("Rendering cage transform"),
+ FALSE);
- progress = gimp_progress_start (GIMP_PROGRESS (display),
- _("Rendering cage transform"),
- FALSE);
+ gimp_cage_tool_process_drawable (ct, drawable, progress);
- gimp_cage_tool_process_drawable (ct, drawable, progress);
+ gimp_progress_end (progress);
- gimp_progress_end (progress);
-
- if(mask)
- {
- progress = gimp_progress_start (GIMP_PROGRESS (display),
- _("Rendering mask cage transform"),
- FALSE);
- gimp_cage_tool_process_drawable (ct, mask, progress);
+ if (mask)
+ {
+ progress = gimp_progress_start (GIMP_PROGRESS (display),
+ _("Rendering mask cage transform"),
+ FALSE);
+ gimp_cage_tool_process_drawable (ct, mask, progress);
- gimp_progress_end (progress);
- }
+ gimp_progress_end (progress);
+ }
- gimp_image_flush (image);
+ gimp_image_flush (image);
- gimp_cage_tool_halt (ct);
- }
+ gimp_cage_tool_halt (ct);
+ }
}
static void
@@ -892,43 +831,41 @@ gimp_cage_tool_process_drawable (GimpCageTool *ct,
GimpProgress *progress)
{
- TileManager *new_tiles = NULL;
- TileManager *old_tiles = NULL;
- GeglRectangle rect;
- GeglProcessor *processor;
- gdouble value;
+ TileManager *new_tiles = NULL;
+ TileManager *old_tiles = NULL;
+ GeglRectangle rect;
+ GeglProcessor *processor;
+ gdouble value;
if (GIMP_IS_DRAWABLE (drawable))
- {
- GeglNode *gegl = gegl_node_new ();
+ {
+ GeglNode *gegl = gegl_node_new ();
- /* reverse transform */
- GeglNode *node, *input, *output;
+ /* reverse transform */
+ GeglNode *node, *input, *output;
- old_tiles = gimp_drawable_get_tiles (drawable);
+ old_tiles = gimp_drawable_get_tiles (drawable);
- input = gegl_node_new_child (gegl,
- "operation", "gimp:tilemanager-source",
- "tile-manager", old_tiles,
- "linear", TRUE,
- NULL);
+ input = gegl_node_new_child (gegl,
+ "operation", "gimp:tilemanager-source",
+ "tile-manager", old_tiles,
+ "linear", TRUE,
+ NULL);
+ node = gimp_cage_tool_get_render_node (ct, gegl);
- node = gimp_cage_tool_get_render_node (ct,
- gegl);
+ new_tiles = gimp_drawable_get_shadow_tiles (drawable);
+ output = gegl_node_new_child (gegl,
+ "operation", "gimp:tilemanager-sink",
+ "tile-manager", new_tiles,
+ "linear", TRUE,
+ NULL);
- new_tiles = gimp_drawable_get_shadow_tiles (drawable);
- output = gegl_node_new_child (gegl,
- "operation", "gimp:tilemanager-sink",
- "tile-manager", new_tiles,
- "linear", TRUE,
- NULL);
+ gegl_node_connect_to (input, "output",
+ node, "input");
- gegl_node_connect_to (input, "output",
- node, "input");
-
- gegl_node_connect_to (node, "output",
- output, "input");
+ gegl_node_connect_to (node, "output",
+ output, "input");
/* Debug code sample for debugging coef calculation.*/
@@ -944,34 +881,34 @@ gimp_cage_tool_process_drawable (GimpCageTool *ct,
output, "input");*/
- processor = gegl_node_new_processor (output, NULL);
+ processor = gegl_node_new_processor (output, NULL);
- while (gegl_processor_work (processor, &value))
- {
- gimp_progress_set_value (progress, value);
- }
+ while (gegl_processor_work (processor, &value))
+ {
+ gimp_progress_set_value (progress, value);
+ }
- rect.x = 0;
- rect.y = 0;
- rect.width = tile_manager_width (new_tiles);
- rect.height = tile_manager_height (new_tiles);
+ rect.x = 0;
+ rect.y = 0;
+ rect.width = tile_manager_width (new_tiles);
+ rect.height = tile_manager_height (new_tiles);
- gimp_drawable_merge_shadow_tiles (drawable, TRUE, _("Cage transform"));
- gimp_drawable_free_shadow_tiles (drawable);
+ gimp_drawable_merge_shadow_tiles (drawable, TRUE, _("Cage transform"));
+ gimp_drawable_free_shadow_tiles (drawable);
- gimp_drawable_update (drawable, rect.x, rect.y, rect.width, rect.height);
+ gimp_drawable_update (drawable, rect.x, rect.y, rect.width, rect.height);
- g_object_unref (gegl);
+ g_object_unref (gegl);
- gegl_processor_destroy (processor);
- }
+ gegl_processor_destroy (processor);
+ }
}
static void
gimp_cage_tool_halt (GimpCageTool *ct)
{
- GimpTool *tool = GIMP_TOOL (ct);
- GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (ct);
+ GimpTool *tool = GIMP_TOOL (ct);
+ GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (ct);
if (gimp_draw_tool_is_active (draw_tool))
gimp_draw_tool_stop (draw_tool);
@@ -980,41 +917,41 @@ gimp_cage_tool_halt (GimpCageTool *ct)
gimp_tool_control_halt (tool->control);
if (ct->config)
- {
- g_object_unref (ct->config);
- ct->config = NULL;
- }
+ {
+ g_object_unref (ct->config);
+ ct->config = NULL;
+ }
if (ct->coef)
- {
- gegl_buffer_destroy (ct->coef);
- ct->coef = NULL;
- }
+ {
+ gegl_buffer_destroy (ct->coef);
+ ct->coef = NULL;
+ }
if (ct->image_map)
- {
-
- if (ct->idle_id > 0)
{
- g_source_remove(ct->idle_id);
- ct->idle_id = 0;
- }
- gimp_tool_control_set_preserve (tool->control, TRUE);
+ if (ct->idle_id > 0)
+ {
+ g_source_remove (ct->idle_id);
+ ct->idle_id = 0;
+ }
+
+ gimp_tool_control_set_preserve (tool->control, TRUE);
- gimp_image_map_abort (ct->image_map);
- g_object_unref (ct->image_map);
- ct->image_map = NULL;
+ gimp_image_map_abort (ct->image_map);
+ g_object_unref (ct->image_map);
+ ct->image_map = NULL;
- gimp_tool_control_set_preserve (tool->control, FALSE);
+ gimp_tool_control_set_preserve (tool->control, FALSE);
- gimp_image_flush (gimp_display_get_image (tool->display));
- }
+ gimp_image_flush (gimp_display_get_image (tool->display));
+ }
if (ct->node_preview)
- {
- g_object_unref (ct->node_preview);
- ct->node_preview = NULL;
- }
+ {
+ g_object_unref (ct->node_preview);
+ ct->node_preview = NULL;
+ }
tool->display = NULL;
-}
\ No newline at end of file
+}
diff --git a/app/tools/gimpcagetool.h b/app/tools/gimpcagetool.h
index a51cf62..fd0255f 100644
--- a/app/tools/gimpcagetool.h
+++ b/app/tools/gimpcagetool.h
@@ -20,9 +20,9 @@
#ifndef __GIMP_CAGE_TOOL_H__
#define __GIMP_CAGE_TOOL_H__
+
#include "gimpdrawtool.h"
#include "libgimpmath/gimpvector.h"
-#include "gegl/gimpcageconfig.h"
#define GIMP_TYPE_CAGE_TOOL (gimp_cage_tool_get_type ())
@@ -34,37 +34,39 @@
#define GIMP_CAGE_TOOL_GET_OPTIONS(t) (GIMP_CAGE_OPTIONS (gimp_tool_get_options (GIMP_TOOL (t))))
+
+typedef struct _GimpCageTool GimpCageTool;
typedef struct _GimpCageToolClass GimpCageToolClass;
-typedef struct _GimpCageTool GimpCageTool;
struct _GimpCageTool
{
- GimpDrawTool parent_instance;
- GimpCageConfig *config;
+ GimpDrawTool parent_instance;
- GimpVector2 cursor_position;
- gint handle_moved;
- gboolean cage_complete;
+ GimpCageConfig *config;
- GeglBuffer *coef;
+ GimpVector2 cursor_position;
+ gint handle_moved;
+ gboolean cage_complete;
- GimpImageMap *image_map;
+ GeglBuffer *coef;
- GeglNode *node_preview;
+ GimpImageMap *image_map;
- guint idle_id;
+ GeglNode *node_preview;
+ guint idle_id;
};
-
struct _GimpCageToolClass
{
- GimpDrawToolClass parent_class;
+ GimpDrawToolClass parent_class;
};
+
void gimp_cage_tool_register (GimpToolRegisterCallback callback,
- gpointer data);
+ gpointer data);
GType gimp_cage_tool_get_type (void) G_GNUC_CONST;
+
#endif /* __GIMP_CAGE_TOOL_H__ */
diff --git a/app/tools/tools-enums.c b/app/tools/tools-enums.c
index 3278110..281de15 100644
--- a/app/tools/tools-enums.c
+++ b/app/tools/tools-enums.c
@@ -389,35 +389,6 @@ gimp_tool_action_get_type (void)
return type;
}
-GType
-gimp_cage_mode_get_type (void)
-{
- static const GEnumValue values[] =
- {
- { GIMP_CAGE_MODE_CAGE_CHANGE, "GIMP_CAGE_MODE_CAGE_CHANGE", "cage-change" },
- { GIMP_CAGE_MODE_DEFORM, "GIMP_CAGE_MODE_DEFORM", "deform" },
- { 0, NULL, NULL }
- };
-
- static const GimpEnumDesc descs[] =
- {
- { GIMP_CAGE_MODE_CAGE_CHANGE, NC_("cage-mode", "Create or adjust the cage"), NULL },
- { GIMP_CAGE_MODE_DEFORM, NC_("cage-mode", "Deform the cage to deform the image"), NULL },
- { 0, NULL, NULL }
- };
-
- static GType type = 0;
-
- if (G_UNLIKELY (! type))
- {
- type = g_enum_register_static ("GimpCageMode", values);
- gimp_type_set_translation_context (type, "cage-mode");
- gimp_enum_set_value_descriptions (type, descs);
- }
-
- return type;
-}
-
/* Generated data ends here */
diff --git a/app/tools/tools-enums.h b/app/tools/tools-enums.h
index 64a34b6..64712ea 100644
--- a/app/tools/tools-enums.h
+++ b/app/tools/tools-enums.h
@@ -220,15 +220,5 @@ typedef enum /*< skip >*/
TRANSFORM_HANDLE_CENTER
} TransformAction;
-#define GIMP_TYPE_CAGE_MODE (gimp_cage_mode_get_type ())
-
-GType gimp_cage_mode_get_type (void) G_GNUC_CONST;
-
-typedef enum
-{
- GIMP_CAGE_MODE_CAGE_CHANGE, /*< desc="Create or adjust the cage" >*/
- GIMP_CAGE_MODE_DEFORM /*< desc="Deform the cage to deform the image" >*/
-} GimpCageMode;
-
#endif /* __TOOLS_ENUMS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]