[gimp/goat-invasion: 348/526] app: add gimp_gegl_node_set_matrix() and use it instead of manual fiddling



commit c21275df5ce6d728940717ac211f09f05100b6e0
Author: Michael Natterer <mitch gimp org>
Date:   Sat Mar 31 16:18:13 2012 +0200

    app: add gimp_gegl_node_set_matrix() and use it instead of manual fiddling

 app/core/gimpdrawable-transform.c |    7 +++----
 app/gegl/gimp-gegl-nodes.c        |   18 ++++++++++++++++++
 app/gegl/gimp-gegl-nodes.h        |    2 ++
 app/paint/gimpperspectiveclone.c  |    8 ++------
 4 files changed, 25 insertions(+), 10 deletions(-)
---
diff --git a/app/core/gimpdrawable-transform.c b/app/core/gimpdrawable-transform.c
index 048e3b2..9867aad 100644
--- a/app/core/gimpdrawable-transform.c
+++ b/app/core/gimpdrawable-transform.c
@@ -29,6 +29,7 @@
 
 #include "core-types.h"
 
+#include "gegl/gimp-gegl-nodes.h"
 #include "gegl/gimp-gegl-utils.h"
 
 #include "gimp.h"
@@ -83,7 +84,6 @@ gimp_drawable_transform_buffer_affine (GimpDrawable           *drawable,
   gint         u1, v1, u2, v2;  /* source bounding box */
   gint         x1, y1, x2, y2;  /* target bounding box */
   GeglNode    *affine;
-  gchar       *matrix_string;
   GimpMatrix3  gegl_matrix;
 
   g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
@@ -135,14 +135,13 @@ gimp_drawable_transform_buffer_affine (GimpDrawable           *drawable,
   gimp_matrix3_mult (&inv, &gegl_matrix);
   gimp_matrix3_translate (&gegl_matrix, -x1, -y1);
 
-  matrix_string = gegl_matrix3_to_string ((GeglMatrix3 *) &gegl_matrix);
   affine = gegl_node_new_child (NULL,
                                 "operation",  "gegl:transform",
-                                "transform",  matrix_string,
                                 "filter",     gimp_interpolation_to_gegl_filter (interpolation_type),
                                 "hard-edges", TRUE,
                                 NULL);
-  g_free (matrix_string);
+
+  gimp_gegl_node_set_matrix (affine, &gegl_matrix);
 
   gimp_apply_operation (orig_buffer, progress, NULL,
                         affine,
diff --git a/app/gegl/gimp-gegl-nodes.c b/app/gegl/gimp-gegl-nodes.c
index 707cb43..0d7174d 100644
--- a/app/gegl/gimp-gegl-nodes.c
+++ b/app/gegl/gimp-gegl-nodes.c
@@ -319,3 +319,21 @@ gimp_gegl_node_set_layer_mode (GeglNode             *node,
                  "premultiplied", premultiplied,
                  NULL);
 }
+
+void
+gimp_gegl_node_set_matrix (GeglNode          *node,
+                           const GimpMatrix3 *matrix)
+{
+  gchar *matrix_string;
+
+  g_return_if_fail (GEGL_IS_NODE (node));
+  g_return_if_fail (matrix != NULL);
+
+  matrix_string = gegl_matrix3_to_string ((GeglMatrix3 *) matrix);
+
+  gegl_node_set (node,
+                 "transform", matrix_string,
+                 NULL);
+
+  g_free (matrix_string);
+}
diff --git a/app/gegl/gimp-gegl-nodes.h b/app/gegl/gimp-gegl-nodes.h
index dfca8da..ecff41f 100644
--- a/app/gegl/gimp-gegl-nodes.h
+++ b/app/gegl/gimp-gegl-nodes.h
@@ -48,6 +48,8 @@ GeglNode * gimp_gegl_add_buffer_source         (GeglNode             *parent,
 void       gimp_gegl_node_set_layer_mode       (GeglNode             *node,
                                                 GimpLayerModeEffects  mode,
                                                 gboolean              premultiplied);
+void       gimp_gegl_node_set_matrix           (GeglNode             *node,
+                                                const GimpMatrix3    *matrix);
 
 
 #endif /* __GIMP_GEGL_NODES_H__ */
diff --git a/app/paint/gimpperspectiveclone.c b/app/paint/gimpperspectiveclone.c
index 1b07a31..f8f6f63 100644
--- a/app/paint/gimpperspectiveclone.c
+++ b/app/paint/gimpperspectiveclone.c
@@ -29,6 +29,7 @@
 
 #include "base/temp-buf.h"
 
+#include "gegl/gimp-gegl-nodes.h"
 #include "gegl/gimp-gegl-utils.h"
 
 #include "core/gimp.h"
@@ -351,7 +352,6 @@ gimp_perspective_clone_get_source (GimpSourceCore   *source_core,
   gdouble               x1s, y1s, x2s, y2s, x3s, y3s, x4s, y4s;
   gint                  xmin, ymin, xmax, ymax;
   GimpMatrix3           matrix;
-  gchar                *matrix_string;
   GimpMatrix3           gegl_matrix;
 
   src_buffer       = gimp_pickable_get_buffer (src_pickable);
@@ -398,11 +398,7 @@ gimp_perspective_clone_get_source (GimpSourceCore   *source_core,
   gimp_matrix3_mult (&matrix, &gegl_matrix);
   gimp_matrix3_translate (&gegl_matrix, -x1d, -y1d);
 
-  matrix_string = gegl_matrix3_to_string ((GeglMatrix3 *) &gegl_matrix);
-  gegl_node_set (clone->transform_node,
-                 "transform", matrix_string,
-                 NULL);
-  g_free (matrix_string);
+  gimp_gegl_node_set_matrix (clone->transform_node, &gegl_matrix);
 
   gegl_node_set (clone->dest_node,
                  "buffer", dest_buffer,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]