[gimp] app: fix more broken offset in other tools.



commit 03edaf5cea5e63f7c6fa57a5b014aee7a36a12ab
Author: Jehan <jehan girinstud io>
Date:   Wed Sep 1 23:49:13 2021 +0200

    app: fix more broken offset in other tools.
    
    Similar to the source core fix, but a bit simpler because we don't have
    to deal with a source and a target offset, let's fix offset handling in:
    - Blur / Sharpen tool.
    - Dodge / Burn tool.
    - Ink tool.
    - MyPaint brush tool.
    - Smudge tool.

 app/paint/gimpconvolve.c    | 23 +++++++++++++++--------
 app/paint/gimpdodgeburn.c   | 23 +++++++++++++++--------
 app/paint/gimpink.c         | 40 ++++++++++++++++++++++++----------------
 app/paint/gimpmybrushcore.c | 24 +++++++++++++-----------
 app/paint/gimpsmudge.c      | 33 ++++++++++++++++++++-------------
 5 files changed, 87 insertions(+), 56 deletions(-)
---
diff --git a/app/paint/gimpconvolve.c b/app/paint/gimpconvolve.c
index 347c8487e4..74c05e4c0a 100644
--- a/app/paint/gimpconvolve.c
+++ b/app/paint/gimpconvolve.c
@@ -141,7 +141,8 @@ gimp_convolve_motion (GimpPaintCore    *paint_core,
   gdouble              fade_point;
   gdouble              opacity;
   gdouble              rate;
-  const GimpCoords    *coords;
+  GimpCoords           coords;
+  gint                 off_x, off_y;
   gint                 paint_width, paint_height;
   gint                 n_strokes;
   gint                 i;
@@ -149,10 +150,14 @@ gimp_convolve_motion (GimpPaintCore    *paint_core,
   fade_point = gimp_paint_options_get_fade (paint_options, image,
                                             paint_core->pixel_dist);
 
-  coords = gimp_symmetry_get_origin (sym);
+  gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
+  coords = *(gimp_symmetry_get_origin (sym));
+  coords.x -= off_x;
+  coords.y -= off_y;
+
   opacity = gimp_dynamics_get_linear_value (dynamics,
                                             GIMP_DYNAMICS_OUTPUT_OPACITY,
-                                            coords,
+                                            &coords,
                                             paint_options,
                                             fade_point);
   if (opacity == 0.0)
@@ -161,18 +166,20 @@ gimp_convolve_motion (GimpPaintCore    *paint_core,
   gimp_brush_core_eval_transform_dynamics (GIMP_BRUSH_CORE (paint_core),
                                            image,
                                            paint_options,
-                                           coords);
+                                           &coords);
   n_strokes = gimp_symmetry_get_size (sym);
   for (i = 0; i < n_strokes; i++)
     {
-      coords = gimp_symmetry_get_coords (sym, i);
+      coords = *(gimp_symmetry_get_coords (sym, i));
+      coords.x -= off_x;
+      coords.y -= off_y;
 
       gimp_brush_core_eval_transform_symmetry (brush_core, sym, i);
 
       paint_buffer = gimp_paint_core_get_paint_buffer (paint_core, drawable,
                                                        paint_options,
                                                        GIMP_LAYER_MODE_NORMAL,
-                                                       coords,
+                                                       &coords,
                                                        &paint_buffer_x,
                                                        &paint_buffer_y,
                                                        &paint_width,
@@ -183,7 +190,7 @@ gimp_convolve_motion (GimpPaintCore    *paint_core,
       rate = (options->rate *
               gimp_dynamics_get_linear_value (dynamics,
                                               GIMP_DYNAMICS_OUTPUT_RATE,
-                                              coords,
+                                              &coords,
                                               paint_options,
                                               fade_point));
 
@@ -223,7 +230,7 @@ gimp_convolve_motion (GimpPaintCore    *paint_core,
       g_object_unref (convolve_buffer);
 
       gimp_brush_core_replace_canvas (brush_core, drawable,
-                                      coords,
+                                      &coords,
                                       MIN (opacity, GIMP_OPACITY_OPAQUE),
                                       gimp_context_get_opacity (context),
                                       gimp_paint_options_get_brush_mode (paint_options),
diff --git a/app/paint/gimpdodgeburn.c b/app/paint/gimpdodgeburn.c
index e803970018..1d9e3cdfe5 100644
--- a/app/paint/gimpdodgeburn.c
+++ b/app/paint/gimpdodgeburn.c
@@ -127,7 +127,8 @@ gimp_dodge_burn_motion (GimpPaintCore    *paint_core,
   gdouble               fade_point;
   gdouble               opacity;
   gdouble               force;
-  const GimpCoords     *coords;
+  GimpCoords            coords;
+  gint                  off_x, off_y;
   gint                  paint_width, paint_height;
   gint                  n_strokes;
   gint                  i;
@@ -135,10 +136,14 @@ gimp_dodge_burn_motion (GimpPaintCore    *paint_core,
   fade_point = gimp_paint_options_get_fade (paint_options, image,
                                             paint_core->pixel_dist);
 
-  coords = gimp_symmetry_get_origin (sym);
+  gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
+  coords = *(gimp_symmetry_get_origin (sym));
+  coords.x -= off_x;
+  coords.y -= off_y;
+
   opacity = gimp_dynamics_get_linear_value (dynamics,
                                             GIMP_DYNAMICS_OUTPUT_OPACITY,
-                                            coords,
+                                            &coords,
                                             paint_options,
                                             fade_point);
   if (opacity == 0.0)
@@ -152,18 +157,20 @@ gimp_dodge_burn_motion (GimpPaintCore    *paint_core,
   gimp_brush_core_eval_transform_dynamics (brush_core,
                                            image,
                                            paint_options,
-                                           coords);
+                                           &coords);
   n_strokes = gimp_symmetry_get_size (sym);
   for (i = 0; i < n_strokes; i++)
     {
-      coords = gimp_symmetry_get_coords (sym, i);
+      coords = *(gimp_symmetry_get_coords (sym, i));
+      coords.x -= off_x;
+      coords.y -= off_y;
 
       gimp_brush_core_eval_transform_symmetry (brush_core, sym, i);
 
       paint_buffer = gimp_paint_core_get_paint_buffer (paint_core, drawable,
                                                        paint_options,
                                                        GIMP_LAYER_MODE_NORMAL,
-                                                       coords,
+                                                       &coords,
                                                        &paint_buffer_x,
                                                        &paint_buffer_y,
                                                        &paint_width,
@@ -186,7 +193,7 @@ gimp_dodge_burn_motion (GimpPaintCore    *paint_core,
       if (gimp_dynamics_is_output_enabled (dynamics, GIMP_DYNAMICS_OUTPUT_FORCE))
         force = gimp_dynamics_get_linear_value (dynamics,
                                                 GIMP_DYNAMICS_OUTPUT_FORCE,
-                                                coords,
+                                                &coords,
                                                 paint_options,
                                                 fade_point);
       else
@@ -194,7 +201,7 @@ gimp_dodge_burn_motion (GimpPaintCore    *paint_core,
 
       /* Replace the newly dodgedburned area (paint_area) to the image */
       gimp_brush_core_replace_canvas (GIMP_BRUSH_CORE (paint_core), drawable,
-                                      coords,
+                                      &coords,
                                       MIN (opacity, GIMP_OPACITY_OPAQUE),
                                       gimp_context_get_opacity (context),
                                       gimp_paint_options_get_brush_mode (paint_options),
diff --git a/app/paint/gimpink.c b/app/paint/gimpink.c
index 9814309693..78a1a52be1 100644
--- a/app/paint/gimpink.c
+++ b/app/paint/gimpink.c
@@ -324,10 +324,12 @@ gimp_ink_motion (GimpPaintCore    *paint_core,
   GimpRGB         foreground;
   GeglColor      *color;
   GimpBlob       *last_blob;
-  GimpCoords     *coords;
+  GimpCoords      coords;
+  gint            off_x, off_y;
   gint            n_strokes;
   gint            i;
 
+  gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
   n_strokes = gimp_symmetry_get_size (sym);
 
   if (ink->last_blobs &&
@@ -349,16 +351,18 @@ gimp_ink_motion (GimpPaintCore    *paint_core,
         {
           GimpMatrix3 transform;
 
-          coords = gimp_symmetry_get_coords (sym, i);
+          coords    = *(gimp_symmetry_get_coords (sym, i));
+          coords.x -= off_x;
+          coords.y -= off_y;
 
           gimp_symmetry_get_matrix (sym, i, &transform);
 
           last_blob = ink_pen_ellipse (options,
-                                       coords->x,
-                                       coords->y,
-                                       coords->pressure,
-                                       coords->xtilt,
-                                       coords->ytilt,
+                                       coords.x,
+                                       coords.y,
+                                       coords.pressure,
+                                       coords.xtilt,
+                                       coords.ytilt,
                                        100,
                                        &transform);
 
@@ -380,17 +384,19 @@ gimp_ink_motion (GimpPaintCore    *paint_core,
           GimpBlob    *blob_union = NULL;
           GimpMatrix3  transform;
 
-          coords = gimp_symmetry_get_coords (sym, i);
+          coords    = *(gimp_symmetry_get_coords (sym, i));
+          coords.x -= off_x;
+          coords.y -= off_y;
 
           gimp_symmetry_get_matrix (sym, i, &transform);
 
           blob = ink_pen_ellipse (options,
-                                  coords->x,
-                                  coords->y,
-                                  coords->pressure,
-                                  coords->xtilt,
-                                  coords->ytilt,
-                                  coords->velocity * 100,
+                                  coords.x,
+                                  coords.y,
+                                  coords.pressure,
+                                  coords.xtilt,
+                                  coords.ytilt,
+                                  coords.velocity * 100,
                                   &transform);
 
           last_blob = g_list_nth_data (ink->last_blobs, i);
@@ -416,13 +422,15 @@ gimp_ink_motion (GimpPaintCore    *paint_core,
     {
       GimpBlob *blob_to_render = g_list_nth_data (blobs_to_render, i);
 
-      coords = gimp_symmetry_get_coords (sym, i);
+      coords    = *(gimp_symmetry_get_coords (sym, i));
+      coords.x -= off_x;
+      coords.y -= off_y;
 
       ink->cur_blob = blob_to_render;
       paint_buffer = gimp_paint_core_get_paint_buffer (paint_core, drawable,
                                                        paint_options,
                                                        paint_mode,
-                                                       coords,
+                                                       &coords,
                                                        &paint_buffer_x,
                                                        &paint_buffer_y,
                                                        NULL, NULL);
diff --git a/app/paint/gimpmybrushcore.c b/app/paint/gimpmybrushcore.c
index fe54a24f22..93374c33c9 100644
--- a/app/paint/gimpmybrushcore.c
+++ b/app/paint/gimpmybrushcore.c
@@ -255,9 +255,11 @@ gimp_mybrush_core_motion (GimpPaintCore    *paint_core,
   MyPaintRectangle  rect;
   GList            *iter;
   gdouble           dt = 0.0;
+  gint              off_x, off_y;
   gint              n_strokes;
   gint              i;
 
+  gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
   n_strokes = gimp_symmetry_get_size (sym);
 
   /* The number of strokes may change during a motion, depending on
@@ -278,15 +280,15 @@ gimp_mybrush_core_motion (GimpPaintCore    *paint_core,
            iter = g_list_next (iter), i++)
         {
           MyPaintBrush *brush  = iter->data;
-          GimpCoords   *coords = gimp_symmetry_get_coords (sym, i);
+          GimpCoords    coords = *(gimp_symmetry_get_coords (sym, i));
 
           mypaint_brush_stroke_to (brush,
                                    (MyPaintSurface *) mybrush->private->surface,
-                                   coords->x,
-                                   coords->y,
+                                   coords.x - off_x,
+                                   coords.y - off_y,
                                    0.0f,
-                                   coords->xtilt,
-                                   coords->ytilt,
+                                   coords.xtilt,
+                                   coords.ytilt,
                                    1.0f /* Pretend the cursor hasn't moved in a while */);
         }
 
@@ -309,16 +311,16 @@ gimp_mybrush_core_motion (GimpPaintCore    *paint_core,
        iter = g_list_next (iter), i++)
     {
       MyPaintBrush *brush    = iter->data;
-      GimpCoords   *coords   = gimp_symmetry_get_coords (sym, i);
-      gdouble       pressure = coords->pressure;
+      GimpCoords    coords   = *(gimp_symmetry_get_coords (sym, i));
+      gdouble       pressure = coords.pressure;
 
       mypaint_brush_stroke_to (brush,
                                (MyPaintSurface *) mybrush->private->surface,
-                               coords->x,
-                               coords->y,
+                               coords.x - off_x,
+                               coords.y - off_y,
                                pressure,
-                               coords->xtilt,
-                               coords->ytilt,
+                               coords.xtilt,
+                               coords.ytilt,
                                dt);
     }
 
diff --git a/app/paint/gimpsmudge.c b/app/paint/gimpsmudge.c
index a0ba1f2f4a..7741bcb496 100644
--- a/app/paint/gimpsmudge.c
+++ b/app/paint/gimpsmudge.c
@@ -363,7 +363,8 @@ gimp_smudge_motion (GimpPaintCore    *paint_core,
   GeglBuffer         *accum_buffer;
   /* other variables */
   gdouble             force;
-  GimpCoords         *coords;
+  GimpCoords          coords;
+  gint                off_x, off_y;
   gint                paint_width, paint_height;
   gint                n_strokes;
   gint                i;
@@ -387,10 +388,14 @@ gimp_smudge_motion (GimpPaintCore    *paint_core,
   fade_point = gimp_paint_options_get_fade (paint_options, image,
                                             paint_core->pixel_dist);
 
-  coords = gimp_symmetry_get_origin (sym);
+  gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
+
+  coords    = *(gimp_symmetry_get_origin (sym));
+  coords.x -= off_x;
+  coords.y -= off_y;
   opacity = gimp_dynamics_get_linear_value (dynamics,
                                             GIMP_DYNAMICS_OUTPUT_OPACITY,
-                                            coords,
+                                            &coords,
                                             paint_options,
                                             fade_point);
   if (opacity == 0.0)
@@ -399,26 +404,26 @@ gimp_smudge_motion (GimpPaintCore    *paint_core,
   gimp_brush_core_eval_transform_dynamics (brush_core,
                                            image,
                                            paint_options,
-                                           coords);
+                                           &coords);
 
   /* Get brush dynamic values other than opacity */
   rate = ((options->rate / 100.0) *
           gimp_dynamics_get_linear_value (dynamics,
                                           GIMP_DYNAMICS_OUTPUT_RATE,
-                                          coords,
+                                          &coords,
                                           paint_options,
                                           fade_point));
 
   flow = ((options->flow / 100.0) *
           gimp_dynamics_get_linear_value (dynamics,
                                           GIMP_DYNAMICS_OUTPUT_FLOW,
-                                          coords,
+                                          &coords,
                                           paint_options,
                                           fade_point));
 
   grad_point = gimp_dynamics_get_linear_value (dynamics,
                                                GIMP_DYNAMICS_OUTPUT_COLOR,
-                                               coords,
+                                               &coords,
                                                paint_options,
                                                fade_point);
 
@@ -450,14 +455,16 @@ gimp_smudge_motion (GimpPaintCore    *paint_core,
   n_strokes = gimp_symmetry_get_size (sym);
   for (i = 0; i < n_strokes; i++)
     {
-      coords = gimp_symmetry_get_coords (sym, i);
+      coords    = *(gimp_symmetry_get_coords (sym, i));
+      coords.x -= off_x;
+      coords.y -= off_y;
 
       gimp_brush_core_eval_transform_symmetry (brush_core, sym, i);
 
       paint_buffer = gimp_paint_core_get_paint_buffer (paint_core, drawable,
                                                        paint_options,
                                                        GIMP_LAYER_MODE_NORMAL,
-                                                       coords,
+                                                       &coords,
                                                        &paint_buffer_x,
                                                        &paint_buffer_y,
                                                        &paint_width,
@@ -469,7 +476,7 @@ gimp_smudge_motion (GimpPaintCore    *paint_core,
       paint_buffer_height = gegl_buffer_get_height (paint_buffer);
 
       /*  Get the unclipped accumulator coordinates  */
-      gimp_smudge_accumulator_coords (paint_core, coords, i, &x, &y);
+      gimp_smudge_accumulator_coords (paint_core, &coords, i, &x, &y);
 
       accum_buffer = g_list_nth_data (smudge->accum_buffers, i);
 
@@ -496,7 +503,7 @@ gimp_smudge_motion (GimpPaintCore    *paint_core,
       if (! brush_color_ptr && flow > 0.0)
         {
           gimp_brush_core_color_area_with_pixmap (brush_core, drawable,
-                                                  coords,
+                                                  &coords,
                                                   paint_buffer,
                                                   paint_buffer_x,
                                                   paint_buffer_y,
@@ -524,14 +531,14 @@ gimp_smudge_motion (GimpPaintCore    *paint_core,
       if (gimp_dynamics_is_output_enabled (dynamics, GIMP_DYNAMICS_OUTPUT_FORCE))
         force = gimp_dynamics_get_linear_value (dynamics,
                                                 GIMP_DYNAMICS_OUTPUT_FORCE,
-                                                coords,
+                                                &coords,
                                                 paint_options,
                                                 fade_point);
       else
         force = paint_options->brush_force;
 
       gimp_brush_core_replace_canvas (GIMP_BRUSH_CORE (paint_core), drawable,
-                                      coords,
+                                      &coords,
                                       MIN (opacity, GIMP_OPACITY_OPAQUE),
                                       gimp_context_get_opacity (context),
                                       gimp_paint_options_get_brush_mode (paint_options),


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