[gimp] app: add boundary_offset() which offsets BoundSegs in place



commit a0cb4fe80510669e1edf2a938bf56aa3e9a4efbd
Author: Michael Natterer <mitch gimp org>
Date:   Thu Sep 23 10:47:59 2010 +0200

    app: add boundary_offset() which offsets BoundSegs in place
    
    and use it in gimp_region_select_tool_calculate().
    Also fix boundary_transform() indentation.

 app/base/boundary.c              |   84 ++++++++++++++++++++++++-------------
 app/base/boundary.h              |    6 +++
 app/tools/gimpregionselecttool.c |   14 +++++-
 3 files changed, 72 insertions(+), 32 deletions(-)
---
diff --git a/app/base/boundary.c b/app/base/boundary.c
index c8ca075..d6d7ff9 100644
--- a/app/base/boundary.c
+++ b/app/base/boundary.c
@@ -363,45 +363,69 @@ boundary_simplify (BoundSeg *sorted_segs,
 
 /*Transform boundary based on a matrix*/
 
-BoundSeg * boundary_transform (const BoundSeg *segs,
-                               gint           *num_segs,
-                               GimpMatrix3    *matrix)
+BoundSeg *
+boundary_transform (const BoundSeg *segs,
+                    gint           *num_segs,
+                    GimpMatrix3    *matrix)
 {
+  Boundary *boundary = boundary_new (NULL);
+  gint      i;
 
-  Boundary *boundary = boundary_new(NULL);
-  gint i;
+  for (i = 0; i < *num_segs; i++)
+    {
+      /* dont transform sorting sentinels */
+      if (!(segs[i].x1 == -1 &&
+            segs[i].y1 == -1 &&
+            segs[i].x2 == -1 &&
+            segs[i].y2 == -1))
+        {
+          gdouble x1, y1, x2, y2;
+
+          gimp_matrix3_transform_point (matrix, segs[i].x1, segs[i].y1, &x1, &y1);
+          gimp_matrix3_transform_point (matrix, segs[i].x2, segs[i].y2, &x2, &y2);
 
-      for (i = 0; i < *num_segs; i++)
+          boundary_add_seg (boundary,
+                            (gint) ceil(x1), (gint) ceil(y1),
+                            (gint) ceil(x2), (gint) ceil(y2),
+                            segs[i].open);
+        }
+      else
         {
+          /* Keep the sorting sentinel */
+          boundary_add_seg (boundary,
+                            -1, -1,
+                            -1, -1,
+                            segs[i].open);
+        }
+    }
 
+  *num_segs = boundary->num_segs;
 
-          /*dont transform sorting sentinels*/
-          if (!(segs[i].x1 == -1 &&
-                segs[i].y1 == -1 &&
-                segs[i].x2 == -1 &&
-                segs[i].y2 == -1))
-            {
-              gdouble x1, y1, x2, y2;
+  return boundary_free (boundary, FALSE);
+}
 
-              gimp_matrix3_transform_point (matrix, segs[i].x1, segs[i].y1, &x1, &y1);
-              gimp_matrix3_transform_point (matrix, segs[i].x2, segs[i].y2, &x2, &y2);
+void
+boundary_offset (BoundSeg *segs,
+                 gint      num_segs,
+                 gint      off_x,
+                 gint      off_y)
+{
+  gint i;
 
-              boundary_add_seg (boundary,
-                                (gint) ceil(x1), (gint) ceil(y1),
-                                (gint) ceil(x2), (gint) ceil(y2),
-                                segs[i].open);
-            }
-          else
-            {
-              /*Keep the sorting sentinel*/
-              boundary_add_seg (boundary,
-                                -1, -1,
-                                -1, -1,
-                                segs[i].open);
-            }
+  for (i = 0; i < num_segs; i++)
+    {
+      /* dont offset sorting sentinels */
+      if (!(segs[i].x1 == -1 &&
+            segs[i].y1 == -1 &&
+            segs[i].x2 == -1 &&
+            segs[i].y2 == -1))
+        {
+          segs[i].x1 += off_x;
+          segs[i].y1 += off_y;
+          segs[i].x2 += off_x;
+          segs[i].y2 += off_y;
         }
-      *num_segs = boundary->num_segs;
-      return boundary_free(boundary, FALSE);
+    }
 }
 
 
diff --git a/app/base/boundary.h b/app/base/boundary.h
index 7192b78..f4ee8b3 100644
--- a/app/base/boundary.h
+++ b/app/base/boundary.h
@@ -60,5 +60,11 @@ BoundSeg * boundary_transform (const BoundSeg *segs,
                                gint           *num_segs,
                                GimpMatrix3    *matrix);
 
+/* offsets in-place */
+void       boundary_offset    (BoundSeg       *segs,
+                               gint            num_segs,
+                               gint            off_x,
+                               gint            off_y);
+
 
 #endif  /*  __BOUNDARY_H__  */
diff --git a/app/tools/gimpregionselecttool.c b/app/tools/gimpregionselecttool.c
index 44b141b..64cf8e9 100644
--- a/app/tools/gimpregionselecttool.c
+++ b/app/tools/gimpregionselecttool.c
@@ -381,10 +381,20 @@ gimp_region_select_tool_calculate (GimpRegionSelectTool *region_sel,
                          BOUNDARY_HALF_WAY,
                          num_segs);
 
+  if (! options->sample_merged)
+    {
+      GimpImage    *image    = gimp_display_get_image (display);
+      GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+      gint          off_x, off_y;
+
+      gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
+
+      boundary_offset (bsegs, *num_segs, off_x, off_y);
+    }
+
   segs = g_new (GdkSegment, *num_segs);
 
-  gimp_display_shell_transform_segments (shell, bsegs, segs, *num_segs,
-                                         ! options->sample_merged);
+  gimp_display_shell_transform_segments (shell, bsegs, segs, *num_segs, FALSE);
   g_free (bsegs);
 
   gimp_display_shell_unset_override_cursor (shell);



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