[gimp] app: integer-ify position/offset members of GimpSourceCore



commit 7c7a1b6383c3a6e9d30f03b8b5bd91129c3db462
Author: Ell <ell_se yahoo com>
Date:   Mon Apr 3 11:37:58 2017 -0400

    app: integer-ify position/offset members of GimpSourceCore
    
    We don't support subpixel source sampling, so there's no use in
    pretending that we do.  Demoting everything to int as soon as
    possible helps guarantee that these values are at least rounded
    properly and in fewer places.
    
    Make sure we always round coordinates down, and not toward zero.
    
    Keep using floats only in the signatures of the relevant PDB
    functions.

 app/paint/gimpperspectiveclone.c     |   12 ++++----
 app/paint/gimpsourcecore.c           |   46 +++++++++++++++++----------------
 app/paint/gimpsourcecore.h           |   12 ++++----
 app/pdb/paint-tools-cmds.c           |    8 +++---
 app/tools/gimpperspectiveclonetool.c |   12 ++++----
 app/tools/gimpsourcetool.c           |   10 ++++---
 tools/pdbgen/pdb/paint_tools.pdb     |    8 +++---
 7 files changed, 56 insertions(+), 52 deletions(-)
---
diff --git a/app/paint/gimpperspectiveclone.c b/app/paint/gimpperspectiveclone.c
index fcd5452..1e58c0b 100644
--- a/app/paint/gimpperspectiveclone.c
+++ b/app/paint/gimpperspectiveclone.c
@@ -142,8 +142,8 @@ gimp_perspective_clone_paint (GimpPaintCore    *paint_core,
         {
           g_object_set (source_core, "src-drawable", drawable, NULL);
 
-          source_core->src_x = coords->x;
-          source_core->src_y = coords->y;
+          source_core->src_x = floor (coords->x);
+          source_core->src_y = floor (coords->y);
 
           /* get source coordinates in front view perspective */
           gimp_matrix3_transform_point (&clone->transform_inv,
@@ -271,8 +271,8 @@ gimp_perspective_clone_paint (GimpPaintCore    *paint_core,
         {
           /*  If the control key is down, move the src target and return */
 
-          source_core->src_x = coords->x;
-          source_core->src_y = coords->y;
+          source_core->src_x = floor (coords->x);
+          source_core->src_y = floor (coords->y);
 
           /* get source coordinates in front view perspective */
           gimp_matrix3_transform_point (&clone->transform_inv,
@@ -297,8 +297,8 @@ gimp_perspective_clone_paint (GimpPaintCore    *paint_core,
             {
               coords = gimp_symmetry_get_coords (sym, i);
 
-              dest_x = coords->x;
-              dest_y = coords->y;
+              dest_x = floor (coords->x);
+              dest_y = floor (coords->y);
 
               if (options->align_mode == GIMP_SOURCE_ALIGN_REGISTERED)
                 {
diff --git a/app/paint/gimpsourcecore.c b/app/paint/gimpsourcecore.c
index 265cffc..daf7ca6 100644
--- a/app/paint/gimpsourcecore.c
+++ b/app/paint/gimpsourcecore.c
@@ -21,6 +21,7 @@
 #include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
+#include "libgimpmath/gimpmath.h"
 
 #include "paint-types.h"
 
@@ -130,16 +131,16 @@ gimp_source_core_class_init (GimpSourceCoreClass *klass)
                                                         GIMP_PARAM_READWRITE));
 
   g_object_class_install_property (object_class, PROP_SRC_X,
-                                   g_param_spec_double ("src-x", NULL, NULL,
-                                                        0, GIMP_MAX_IMAGE_SIZE,
-                                                        0.0,
-                                                        GIMP_PARAM_READWRITE));
+                                   g_param_spec_int ("src-x", NULL, NULL,
+                                                     0, GIMP_MAX_IMAGE_SIZE,
+                                                     0,
+                                                     GIMP_PARAM_READWRITE));
 
   g_object_class_install_property (object_class, PROP_SRC_Y,
-                                   g_param_spec_double ("src-y", NULL, NULL,
-                                                        0, GIMP_MAX_IMAGE_SIZE,
-                                                        0.0,
-                                                        GIMP_PARAM_READWRITE));
+                                   g_param_spec_int ("src-y", NULL, NULL,
+                                                     0, GIMP_MAX_IMAGE_SIZE,
+                                                     0,
+                                                     GIMP_PARAM_READWRITE));
 }
 
 static void
@@ -148,14 +149,14 @@ gimp_source_core_init (GimpSourceCore *source_core)
   source_core->set_source   = FALSE;
 
   source_core->src_drawable = NULL;
-  source_core->src_x        = 0.0;
-  source_core->src_y        = 0.0;
+  source_core->src_x        = 0;
+  source_core->src_y        = 0;
 
-  source_core->orig_src_x   = 0.0;
-  source_core->orig_src_y   = 0.0;
+  source_core->orig_src_x   = 0;
+  source_core->orig_src_y   = 0;
 
-  source_core->offset_x     = 0.0;
-  source_core->offset_y     = 0.0;
+  source_core->offset_x     = 0;
+  source_core->offset_y     = 0;
   source_core->first_stroke = TRUE;
 }
 
@@ -174,10 +175,10 @@ gimp_source_core_set_property (GObject      *object,
                                          g_value_get_object (value));
       break;
     case PROP_SRC_X:
-      source_core->src_x = g_value_get_double (value);
+      source_core->src_x = g_value_get_int (value);
       break;
     case PROP_SRC_Y:
-      source_core->src_y = g_value_get_double (value);
+      source_core->src_y = g_value_get_int (value);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -272,8 +273,9 @@ gimp_source_core_paint (GimpPaintCore    *paint_core,
         {
           gimp_source_core_set_src_drawable (source_core, drawable);
 
-          source_core->src_x = coords->x;
-          source_core->src_y = coords->y;
+          /* FIXME(?): subpixel source sampling */
+          source_core->src_x = floor (coords->x);
+          source_core->src_y = floor (coords->y);
 
           source_core->first_stroke = TRUE;
         }
@@ -291,8 +293,8 @@ gimp_source_core_paint (GimpPaintCore    *paint_core,
         {
           /*  If the control key is down, move the src target and return */
 
-          source_core->src_x = coords->x;
-          source_core->src_y = coords->y;
+          source_core->src_x = floor (coords->x);
+          source_core->src_y = floor (coords->y);
 
           source_core->first_stroke = TRUE;
         }
@@ -303,8 +305,8 @@ gimp_source_core_paint (GimpPaintCore    *paint_core,
           gint dest_x;
           gint dest_y;
 
-          dest_x = coords->x;
-          dest_y = coords->y;
+          dest_x = floor (coords->x);
+          dest_y = floor (coords->y);
 
           if (options->align_mode == GIMP_SOURCE_ALIGN_REGISTERED)
             {
diff --git a/app/paint/gimpsourcecore.h b/app/paint/gimpsourcecore.h
index 583f3ab..a36900a 100644
--- a/app/paint/gimpsourcecore.h
+++ b/app/paint/gimpsourcecore.h
@@ -39,14 +39,14 @@ struct _GimpSourceCore
   gboolean       set_source;
 
   GimpDrawable  *src_drawable;
-  gdouble        src_x;
-  gdouble        src_y;
+  gint           src_x;
+  gint           src_y;
 
-  gdouble        orig_src_x;
-  gdouble        orig_src_y;
+  gint           orig_src_x;
+  gint           orig_src_y;
 
-  gdouble        offset_x;
-  gdouble        offset_y;
+  gint           offset_x;
+  gint           offset_y;
   gboolean       first_stroke;
 };
 
diff --git a/app/pdb/paint-tools-cmds.c b/app/pdb/paint-tools-cmds.c
index 7e677eb..c6a3584 100644
--- a/app/pdb/paint-tools-cmds.c
+++ b/app/pdb/paint-tools-cmds.c
@@ -238,8 +238,8 @@ clone_invoker (GimpProcedure         *procedure,
                                         num_strokes, strokes, error,
                                         "undo-desc",    options->paint_info->blurb,
                                         "src-drawable", src_drawable,
-                                        "src-x",        src_x,
-                                        "src-y",        src_y,
+                                        "src-x",        (gint) floor (src_x),
+                                        "src-y",        (gint) floor (src_y),
                                         NULL);
         }
       else
@@ -621,8 +621,8 @@ heal_invoker (GimpProcedure         *procedure,
                                         num_strokes, strokes, error,
                                         "undo-desc",    options->paint_info->blurb,
                                         "src-drawable", src_drawable,
-                                        "src-x",        src_x,
-                                        "src-y",        src_y,
+                                        "src-x",        (gint) floor (src_x),
+                                        "src-y",        (gint) floor (src_y),
                                         NULL);
         }
       else
diff --git a/app/tools/gimpperspectiveclonetool.c b/app/tools/gimpperspectiveclonetool.c
index bb975f6..eaffaf5 100644
--- a/app/tools/gimpperspectiveclonetool.c
+++ b/app/tools/gimpperspectiveclonetool.c
@@ -367,8 +367,8 @@ gimp_perspective_clone_tool_button_press (GimpTool            *tool,
                                                  coords->x, coords->y,
                                                  &nnx, &nny);
 
-        clone_tool->src_x = nnx;
-        clone_tool->src_y = nny;
+        clone_tool->src_x = floor (nnx);
+        clone_tool->src_y = floor (nny);
 
         gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
       }
@@ -510,8 +510,8 @@ gimp_perspective_clone_tool_motion (GimpTool         *tool,
                                                coords->x, coords->y,
                                                &nnx, &nny);
 
-      clone_tool->src_x = nnx;
-      clone_tool->src_y = nny;
+      clone_tool->src_x = floor (nnx);
+      clone_tool->src_y = floor (nny);
 
       gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
     }
@@ -694,8 +694,8 @@ gimp_perspective_clone_tool_oper_update (GimpTool         *tool,
                                                                coords->y,
                                                                &nnx, &nny);
 
-                      clone_tool->src_x = nnx;
-                      clone_tool->src_y = nny;
+                      clone_tool->src_x = floor (nnx);
+                      clone_tool->src_y = floor (nny);
                     }
                 }
 
diff --git a/app/tools/gimpsourcetool.c b/app/tools/gimpsourcetool.c
index 7fdc60f..eccd959 100644
--- a/app/tools/gimpsourcetool.c
+++ b/app/tools/gimpsourcetool.c
@@ -20,6 +20,8 @@
 #include <gegl.h>
 #include <gtk/gtk.h>
 
+#include "libgimpmath/gimpmath.h"
+
 #include "tools-types.h"
 
 #include "core/gimpchannel.h"
@@ -350,13 +352,13 @@ gimp_source_tool_oper_update (GimpTool         *tool,
               switch (options->align_mode)
                 {
                 case GIMP_SOURCE_ALIGN_YES:
-                  source_tool->src_x = coords->x + source->offset_x;
-                  source_tool->src_y = coords->y + source->offset_y;
+                  source_tool->src_x = floor (coords->x) + source->offset_x;
+                  source_tool->src_y = floor (coords->y) + source->offset_y;
                   break;
 
                 case GIMP_SOURCE_ALIGN_REGISTERED:
-                  source_tool->src_x = coords->x;
-                  source_tool->src_y = coords->y;
+                  source_tool->src_x = floor (coords->x);
+                  source_tool->src_y = floor (coords->y);
                   break;
 
                 default:
diff --git a/tools/pdbgen/pdb/paint_tools.pdb b/tools/pdbgen/pdb/paint_tools.pdb
index e21ad08..593bd4e 100644
--- a/tools/pdbgen/pdb/paint_tools.pdb
+++ b/tools/pdbgen/pdb/paint_tools.pdb
@@ -182,8 +182,8 @@ HELP
                                     num_strokes, strokes, error,
                                     "undo-desc",    options->paint_info->blurb,
                                     "src-drawable", src_drawable,
-                                    "src-x",        src_x,
-                                    "src-y",        src_y,
+                                    "src-x",        (gint) floor (src_x),
+                                    "src-y",        (gint) floor (src_y),
                                     NULL);
     }
   else
@@ -537,8 +537,8 @@ HELP
                                     num_strokes, strokes, error,
                                    "undo-desc",    options->paint_info->blurb,
                                     "src-drawable", src_drawable,
-                                    "src-x",        src_x,
-                                    "src-y",        src_y,
+                                    "src-x",        (gint) floor (src_x),
+                                    "src-y",        (gint) floor (src_y),
                                     NULL);
     }
   else


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