[gimp] app: transform the transform grid lines on the fly



commit f632c4a8aa6b451d2231333cd07554fb0c138f22
Author: Michael Natterer <mitch gimp org>
Date:   Sat Mar 26 22:14:07 2011 +0100

    app: transform the transform grid lines on the fly
    
    which is much less code than keeping the transformed lines around.

 app/tools/gimptransformtool.c |   62 ++++++++++------------------------------
 app/tools/gimptransformtool.h |    1 -
 2 files changed, 16 insertions(+), 47 deletions(-)
---
diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c
index 28b7d61..6ddb99a 100644
--- a/app/tools/gimptransformtool.c
+++ b/app/tools/gimptransformtool.c
@@ -228,7 +228,6 @@ gimp_transform_tool_init (GimpTransformTool *tr_tool)
   tr_tool->ngx              = 0;
   tr_tool->ngy              = 0;
   tr_tool->grid_coords      = NULL;
-  tr_tool->tgrid_coords     = NULL;
 
   tr_tool->type             = GIMP_TRANSFORM_TYPE_LAYER;
   tr_tool->direction        = GIMP_TRANSFORM_FORWARD;
@@ -273,12 +272,6 @@ gimp_transform_tool_finalize (GObject *object)
       tr_tool->grid_coords = NULL;
     }
 
-  if (tr_tool->tgrid_coords)
-    {
-      g_free (tr_tool->tgrid_coords);
-      tr_tool->tgrid_coords = NULL;
-    }
-
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -874,22 +867,27 @@ gimp_transform_tool_draw (GimpDrawTool *draw_tool)
             (tr_tool->tx1 - tr_tool->tx2) * (tr_tool->ty3 - tr_tool->ty2));
 
       /*  draw the grid  */
-      if (tr_tool->grid_coords  &&
-          tr_tool->tgrid_coords &&
-          z1 * z2 > 0           &&
+      if (tr_tool->grid_coords &&
+          z1 * z2 > 0          &&
           z3 * z4 > 0)
         {
-          gint gci, i, k;
-
-          k = tr_tool->ngx + tr_tool->ngy;
+          gint k = tr_tool->ngx + tr_tool->ngy;
+          gint i, gci;
 
           for (i = 0, gci = 0; i < k; i++, gci += 4)
             {
-              gimp_draw_tool_add_line (draw_tool,
-                                       tr_tool->tgrid_coords[gci],
-                                       tr_tool->tgrid_coords[gci + 1],
-                                       tr_tool->tgrid_coords[gci + 2],
-                                       tr_tool->tgrid_coords[gci + 3]);
+              gdouble x1, y1, x2, y2;
+
+              gimp_matrix3_transform_point (&tr_tool->transform,
+                                            tr_tool->grid_coords[gci],
+                                            tr_tool->grid_coords[gci + 1],
+                                            &x1, &y1);
+              gimp_matrix3_transform_point (&tr_tool->transform,
+                                            tr_tool->grid_coords[gci + 2],
+                                            tr_tool->grid_coords[gci + 3],
+                                            &x2, &y2);
+
+              gimp_draw_tool_add_line (draw_tool, x1, y1, x2, y2);
             }
         }
 
@@ -1381,25 +1379,6 @@ gimp_transform_tool_transform_bounding_box (GimpTransformTool *tr_tool)
   gimp_matrix3_transform_point (&tr_tool->transform,
                                 tr_tool->cx, tr_tool->cy,
                                 &tr_tool->tcx, &tr_tool->tcy);
-
-  if (tr_tool->grid_coords && tr_tool->tgrid_coords)
-    {
-      gint i, k;
-      gint gci;
-
-      gci = 0;
-      k   = (tr_tool->ngx + tr_tool->ngy) * 2;
-
-      for (i = 0; i < k; i++)
-        {
-          gimp_matrix3_transform_point (&tr_tool->transform,
-                                        tr_tool->grid_coords[gci],
-                                        tr_tool->grid_coords[gci + 1],
-                                        &tr_tool->tgrid_coords[gci],
-                                        &tr_tool->tgrid_coords[gci + 1]);
-          gci += 2;
-        }
-    }
 }
 
 void
@@ -1577,12 +1556,6 @@ gimp_transform_tool_grid_recalc (GimpTransformTool *tr_tool)
       tr_tool->grid_coords = NULL;
     }
 
-  if (tr_tool->tgrid_coords != NULL)
-    {
-      g_free (tr_tool->tgrid_coords);
-      tr_tool->tgrid_coords = NULL;
-    }
-
   if (options->preview_type != GIMP_TRANSFORM_PREVIEW_TYPE_GRID &&
       options->preview_type != GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE_GRID)
     return;
@@ -1626,9 +1599,6 @@ gimp_transform_tool_grid_recalc (GimpTransformTool *tr_tool)
         tr_tool->grid_coords = coords =
           g_new (gdouble, (tr_tool->ngx + tr_tool->ngy) * 4);
 
-        tr_tool->tgrid_coords =
-          g_new (gdouble, (tr_tool->ngx + tr_tool->ngy) * 4);
-
         gci = 0;
 
         for (i = 1; i <= tr_tool->ngx; i++)
diff --git a/app/tools/gimptransformtool.h b/app/tools/gimptransformtool.h
index 45d3bda..f6030f5 100644
--- a/app/tools/gimptransformtool.h
+++ b/app/tools/gimptransformtool.h
@@ -84,7 +84,6 @@ struct _GimpTransformTool
                                     *  endpoints (a total of (ngx+ngy)*2
                                     *  coordinate pairs)
                                     */
-  gdouble        *tgrid_coords;    /*  transformed grid_coords           */
 
   GimpTransformType       type;
   GimpTransformDirection  direction;



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