[gimp] app: fix broken source painting offset.



commit 977807985b633165914b7ccca4796cfc509de956
Author: Jehan <jehan girinstud io>
Date:   Wed Sep 1 17:21:52 2021 +0200

    app: fix broken source painting offset.
    
    As expected from early changes of code, painting was widely broken with
    offsetted layers, because previous code used to process the drawable
    offset earlier in the painting process, on paint tool level, whereas now
    the tool gives coordinates in image space to the paint core (because it
    gives a list of drawables which may have different offsets, hence image
    space is the only valid coordinates space). This means the various paint
    core algorithms must handle each drawable's offset at actual painting
    time.

 app/paint/gimppaintbrush.c | 28 ++++++++++++++++++----------
 app/paint/gimpsourcecore.c | 32 ++++++++++++++++++++++----------
 2 files changed, 40 insertions(+), 20 deletions(-)
---
diff --git a/app/paint/gimppaintbrush.c b/app/paint/gimppaintbrush.c
index 25940af5cf..075eb3d753 100644
--- a/app/paint/gimppaintbrush.c
+++ b/app/paint/gimppaintbrush.c
@@ -244,18 +244,24 @@ _gimp_paintbrush_motion (GimpPaintCore    *paint_core,
   gdouble           fade_point;
   gdouble           grad_point;
   gdouble           force;
-  const GimpCoords *coords;
+  GimpCoords        coords;
   gint              n_strokes;
+  gint              off_x, off_y;
   gint              i;
 
   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;
+
   /* Some settings are based on the original stroke. */
   opacity *= gimp_dynamics_get_linear_value (dynamics,
                                              GIMP_DYNAMICS_OUTPUT_OPACITY,
-                                             coords,
+                                             &coords,
                                              paint_options,
                                              fade_point);
   if (opacity == 0.0)
@@ -266,12 +272,12 @@ _gimp_paintbrush_motion (GimpPaintCore    *paint_core,
       gimp_brush_core_eval_transform_dynamics (brush_core,
                                                image,
                                                paint_options,
-                                               coords);
+                                               &coords);
     }
 
   grad_point = gimp_dynamics_get_linear_value (dynamics,
                                                GIMP_DYNAMICS_OUTPUT_COLOR,
-                                               coords,
+                                               &coords,
                                                paint_options,
                                                fade_point);
 
@@ -299,7 +305,9 @@ _gimp_paintbrush_motion (GimpPaintCore    *paint_core,
                                                                 &paint_pixmap,
                                                                 &paint_color);
 
-      coords = gimp_symmetry_get_coords (sym, i);
+      coords    = *(gimp_symmetry_get_coords (sym, i));
+      coords.x -= off_x;
+      coords.y -= off_y;
 
       if (GIMP_BRUSH_CORE_GET_CLASS (brush_core)->handles_transforming_brush)
         gimp_brush_core_eval_transform_symmetry (brush_core, sym, i);
@@ -307,7 +315,7 @@ _gimp_paintbrush_motion (GimpPaintCore    *paint_core,
       paint_buffer = gimp_paint_core_get_paint_buffer (paint_core, drawable,
                                                        paint_options,
                                                        paint_mode,
-                                                       coords,
+                                                       &coords,
                                                        &paint_buffer_x,
                                                        &paint_buffer_y,
                                                        &paint_width,
@@ -361,7 +369,7 @@ _gimp_paintbrush_motion (GimpPaintCore    *paint_core,
           if (paint_pixmap)
             {
               gimp_brush_core_color_area_with_pixmap (brush_core, drawable,
-                                                      coords,
+                                                      &coords,
                                                       paint_buffer,
                                                       paint_buffer_x,
                                                       paint_buffer_y,
@@ -383,7 +391,7 @@ _gimp_paintbrush_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
@@ -391,7 +399,7 @@ _gimp_paintbrush_motion (GimpPaintCore    *paint_core,
 
       /* finally, let the brush core paste the colored area on the canvas */
       gimp_brush_core_paste_canvas (brush_core, drawable,
-                                    coords,
+                                    &coords,
                                     MIN (opacity, GIMP_OPACITY_OPAQUE),
                                     gimp_context_get_opacity (context),
                                     paint_mode,
diff --git a/app/paint/gimpsourcecore.c b/app/paint/gimpsourcecore.c
index 67f043a60d..e9fb765184 100644
--- a/app/paint/gimpsourcecore.c
+++ b/app/paint/gimpsourcecore.c
@@ -406,24 +406,30 @@ gimp_source_core_motion (GimpSourceCore   *source_core,
   gdouble            opacity;
   GimpLayerMode      paint_mode;
   GeglNode          *op;
-  GimpCoords        *origin;
-  GimpCoords        *coords;
+  GimpCoords         origin;
+  GimpCoords         coords;
+  gint               src_off_x = 0;
+  gint               src_off_y = 0;
+  gint               off_x, off_y;
   gint               n_strokes;
   gint               i;
 
   fade_point = gimp_paint_options_get_fade (paint_options, image,
                                             paint_core->pixel_dist);
 
-  origin     = gimp_symmetry_get_origin (sym);
+  origin = *(gimp_symmetry_get_origin (sym));
+
   /* Some settings are based on the original stroke. */
   opacity = gimp_dynamics_get_linear_value (dynamics,
                                             GIMP_DYNAMICS_OUTPUT_OPACITY,
-                                            origin,
+                                            &origin,
                                             paint_options,
                                             fade_point);
   if (opacity == 0.0)
     return;
 
+  gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
+
   base_src_offset_x = source_core->offset_x;
   base_src_offset_y = source_core->offset_y;
 
@@ -452,26 +458,32 @@ gimp_source_core_motion (GimpSourceCore   *source_core,
         {
           src_pickable = source_core->src_pickable;
         }
+
+      if (GIMP_IS_ITEM (src_pickable))
+        gimp_item_get_offset (GIMP_ITEM (src_pickable),
+                              &src_off_x, &src_off_y);
     }
 
   gimp_brush_core_eval_transform_dynamics (brush_core,
                                            image,
                                            paint_options,
-                                           origin);
+                                           &origin);
 
   paint_mode = gimp_context_get_paint_mode (GIMP_CONTEXT (paint_options));
 
   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,
                                                        paint_mode,
-                                                       coords,
+                                                       &coords,
                                                        &paint_buffer_x,
                                                        &paint_buffer_y,
                                                        NULL, NULL);
@@ -488,8 +500,8 @@ gimp_source_core_motion (GimpSourceCore   *source_core,
       if (gimp_source_core_use_source (source_core, options))
         {
           /* When using a source, use the same for every stroke. */
-          src_offset_x += floor (origin->x) - floor (coords->x);
-          src_offset_y += floor (origin->y) - floor (coords->y);
+          src_offset_x += floor (origin.x) - floor (coords.x) - src_off_x;
+          src_offset_y += floor (origin.y) - floor (coords.y) - src_off_y;
           src_buffer =
             GIMP_SOURCE_CORE_GET_CLASS (source_core)->get_source (source_core,
                                                                   drawable,
@@ -563,7 +575,7 @@ gimp_source_core_motion (GimpSourceCore   *source_core,
       GIMP_SOURCE_CORE_GET_CLASS (source_core)->motion (source_core,
                                                         drawable,
                                                         paint_options,
-                                                        coords,
+                                                        &coords,
                                                         op,
                                                         opacity,
                                                         src_pickable,


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