[gimp] Bug 155733 - need to check return values of gimp_drawable_mask_bounds()



commit 4f99c7294a8ea279549e5b5a2e267ce64b88005e
Author: Andrew Worsley <amworsley gmail com>
Date:   Sat Aug 29 21:04:09 2015 +1000

    Bug 155733 - need to check return values of gimp_drawable_mask_bounds()
    
    Remove gimp_drawable_mask_bounds() from several plug-ins
    
    Also avoid null pointer crash by returning if called with null
    drawable which appears to happen once on the initial update. Instead
    prints a message for some one who might want to fix it
    
    Change gimp_drawable_mask_intersect() to check return value
    
    We still get some GIMP Error and Warnings but no crashes now

 plug-ins/common/cml-explorer.c    |   31 +++++++++++++++++--------------
 plug-ins/common/curve-bend.c      |   15 ++++++++++++---
 plug-ins/common/edge-neon.c       |   24 +++++++++++-------------
 plug-ins/common/emboss.c          |   10 ++++++----
 plug-ins/common/fractal-trace.c   |   20 +++++++++++++++-----
 plug-ins/common/grid.c            |   12 +++++++++---
 plug-ins/common/hot.c             |    9 +++++----
 plug-ins/common/newsprint.c       |    9 ++++++++-
 plug-ins/common/nl-filter.c       |   11 ++++++-----
 plug-ins/common/oilify.c          |    9 ++++++---
 plug-ins/common/qbist.c           |   27 +++++++++++++++++----------
 plug-ins/common/sample-colorize.c |    9 +++++++--
 plug-ins/common/smooth-palette.c  |   11 ++++++-----
 plug-ins/common/softglow.c        |   15 +++++----------
 14 files changed, 130 insertions(+), 82 deletions(-)
---
diff --git a/plug-ins/common/cml-explorer.c b/plug-ins/common/cml-explorer.c
index 4dbeec6..f5d33b2 100644
--- a/plug-ins/common/cml-explorer.c
+++ b/plug-ins/common/cml-explorer.c
@@ -542,7 +542,7 @@ CML_main_function (gboolean preview_p)
   GimpPixelRgn  dest_rgn, src_rgn;
   guchar    *dest_buffer = NULL;
   guchar    *src_buffer  = NULL;
-  gint       x1, x2, y1, y2;
+  gint       x, y;
   gint       dx, dy;
   gboolean   dest_has_alpha = FALSE;
   gboolean   dest_is_gray   = FALSE;
@@ -560,7 +560,12 @@ CML_main_function (gboolean preview_p)
 
   /* open THE drawable */
   drawable = gimp_drawable_get (drawable_id);
-  gimp_drawable_mask_bounds (drawable_id, &x1, &y1, &x2, &y2);
+
+  if (! gimp_drawable_mask_intersect (drawable_id,
+                                      &x, &y,
+                                      &width_by_pixel, &height_by_pixel))
+    return GIMP_PDB_SUCCESS;
+
   src_has_alpha = dest_has_alpha = gimp_drawable_has_alpha (drawable_id);
   src_is_gray = dest_is_gray = gimp_drawable_is_gray (drawable_id);
   src_bpp = dest_bpp = (src_is_gray ? 1 : 3) + (src_has_alpha ? 1 : 0);
@@ -570,13 +575,11 @@ CML_main_function (gboolean preview_p)
       dest_has_alpha = FALSE;
       dest_bpp       = 3;
 
-      if (PREVIEW_WIDTH < x2 - x1)      /* preview < drawable (selection) */
-        x2 = x1 + PREVIEW_WIDTH;
-      if (PREVIEW_HEIGHT < y2 - y1)
-        y2 = y1 + PREVIEW_HEIGHT;
+      if (width_by_pixel > PREVIEW_WIDTH)      /* preview < drawable (selection) */
+        width_by_pixel = PREVIEW_WIDTH;
+      if (height_by_pixel > PREVIEW_HEIGHT)
+        height_by_pixel = PREVIEW_HEIGHT;
     }
-  width_by_pixel = x2 - x1;
-  height_by_pixel = y2 - y1;
   dest_bpl = width_by_pixel * dest_bpp;
   src_bpl = width_by_pixel * src_bpp;
   cell_num = (width_by_pixel - 1)/ VALS.scale + 1;
@@ -619,11 +622,11 @@ CML_main_function (gboolean preview_p)
   dest_buffer = mem_chank2;
 
   if (! preview_p)
-    gimp_pixel_rgn_init (&dest_rgn, drawable, x1, y1,
+    gimp_pixel_rgn_init (&dest_rgn, drawable, x, y,
                          width_by_pixel, height_by_pixel,
                          TRUE, TRUE);
 
-  gimp_pixel_rgn_init (&src_rgn, drawable, x1, y1,
+  gimp_pixel_rgn_init (&src_rgn, drawable, x, y,
                        width_by_pixel, height_by_pixel,
                        FALSE, FALSE);
 
@@ -748,7 +751,7 @@ CML_main_function (gboolean preview_p)
           int   i;
 
           gimp_pixel_rgn_get_pixel (&src_rgn, buffer,
-                                    x1 + (index * VALS.scale), y1);
+                                    x + (index * VALS.scale), y);
           for (i = 0; i < 3; i++) rgbi[i] = buffer[i];
           gimp_rgb_to_hsv_int (rgbi, rgbi + 1, rgbi + 2);
           hues[index] = (gdouble) rgbi[0] / (gdouble) 255;
@@ -778,7 +781,7 @@ CML_main_function (gboolean preview_p)
           (VALS.sat.function == CML_KEEP_VALUES) ||
           (VALS.val.function == CML_KEEP_VALUES))
         gimp_pixel_rgn_get_rect (&src_rgn, src_buffer,
-                                 x1, y1 + dy, width_by_pixel, keep_height);
+                                 x, y + dy, width_by_pixel, keep_height);
 
       CML_compute_next_step (cell_num,
                              &hues, &sats, &vals,
@@ -862,7 +865,7 @@ CML_main_function (gboolean preview_p)
                                 dest_buffer,
                                 dest_bpl);
       else
-        gimp_pixel_rgn_set_rect (&dest_rgn, dest_buffer, x1, y1 + dy,
+        gimp_pixel_rgn_set_rect (&dest_rgn, dest_buffer, x, y + dy,
                                  width_by_pixel, keep_height);
     }
   if (preview_p)
@@ -875,7 +878,7 @@ CML_main_function (gboolean preview_p)
       gimp_drawable_flush (drawable);
       gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
       gimp_drawable_update (drawable->drawable_id,
-                            x1, y1, (x2 - x1), (y2 - y1));
+                            x, y, width_by_pixel, height_by_pixel);
       gimp_drawable_detach (drawable);
     }
 
diff --git a/plug-ins/common/curve-bend.c b/plug-ins/common/curve-bend.c
index 2299113..e7a5f96 100644
--- a/plug-ins/common/curve-bend.c
+++ b/plug-ins/common/curve-bend.c
@@ -2534,17 +2534,26 @@ p_init_gdrw (t_GDRW       *gdrw,
              int           dirty,
              int           shadow)
 {
+  gint w, h;
+
   gdrw->drawable = drawable;
   gdrw->pft = gimp_pixel_fetcher_new (drawable, FALSE);
   gimp_pixel_fetcher_set_edge_mode (gdrw->pft, GIMP_PIXEL_FETCHER_EDGE_BLACK);
   gdrw->tile_width = gimp_tile_width ();
   gdrw->tile_height = gimp_tile_height ();
 
-  gimp_drawable_mask_bounds (drawable->drawable_id, &gdrw->x1,
-                             &gdrw->y1, &gdrw->x2, &gdrw->y2);
+  if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                      &gdrw->x1, &gdrw->y1, &w, &h))
+    {
+      w = 0;
+      h = 0;
+    }
+
+  gdrw->x2 = gdrw->x1 + w;
+  gdrw->y2 = gdrw->y1 + h;
 
   gdrw->bpp = drawable->bpp;
-  if (gimp_drawable_has_alpha(drawable->drawable_id))
+  if (gimp_drawable_has_alpha (drawable->drawable_id))
     {
       /* index of the alpha channelbyte {1|3} */
       gdrw->index_alpha = gdrw->bpp - 1;
diff --git a/plug-ins/common/edge-neon.c b/plug-ins/common/edge-neon.c
index f5aeab4..bc33f3c 100644
--- a/plug-ins/common/edge-neon.c
+++ b/plug-ins/common/edge-neon.c
@@ -254,7 +254,7 @@ neon (GimpDrawable *drawable,
   gdouble       d_p[5], d_m[5];
   gdouble       bd_p[5], bd_m[5];
   gdouble      *val_p, *val_m, *vp, *vm;
-  gint          x1, y1, x2, y2;
+  gint          x, y;
   gint          i, j;
   gint          row, col, b;
   gint          terms;
@@ -267,16 +267,14 @@ neon (GimpDrawable *drawable,
 
   if (preview)
     {
-      gimp_preview_get_position (preview, &x1, &y1);
+      gimp_preview_get_position (preview, &x, &y);
       gimp_preview_get_size (preview, &width, &height);
-      x2 = x1 + width;
-      y2 = y1 + height;
     }
   else
     {
-      gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
-      width  = (x2 - x1);
-      height = (y2 - y1);
+      if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                          &x, &y, &width, &height))
+        return;
     }
 
   if (radius < 1.0)
@@ -324,7 +322,7 @@ neon (GimpDrawable *drawable,
       memset (val_p, 0, height * bytes * sizeof (gdouble));
       memset (val_m, 0, height * bytes * sizeof (gdouble));
 
-      gimp_pixel_rgn_get_col (&src_rgn, src, col + x1, y1, (y2 - y1));
+      gimp_pixel_rgn_get_col (&src_rgn, src, col + x, y, height);
 
       sp_p = src;
       sp_m = src + (height - 1) * bytes;
@@ -385,7 +383,7 @@ neon (GimpDrawable *drawable,
         }
       else
         {
-          gimp_pixel_rgn_set_col (&dest_rgn, dest, col + x1, y1, (y2 - y1));
+          gimp_pixel_rgn_set_col (&dest_rgn, dest, col + x, y, height);
 
           progress += height * radius;
 
@@ -403,7 +401,7 @@ neon (GimpDrawable *drawable,
       memset (val_p, 0, width * bytes * sizeof (gdouble));
       memset (val_m, 0, width * bytes * sizeof (gdouble));
 
-      gimp_pixel_rgn_get_row (&src_rgn, src, x1, row + y1, (x2 - x1));
+      gimp_pixel_rgn_get_row (&src_rgn, src, x, row + y, width);
       if (preview)
         {
           memcpy (src2,
@@ -412,7 +410,7 @@ neon (GimpDrawable *drawable,
         }
       else
         {
-          gimp_pixel_rgn_get_row (&dest_rgn, src2, x1, row + y1, (x2 - x1));
+          gimp_pixel_rgn_get_row (&dest_rgn, src2, x, row + y, width);
         }
 
       sp_p = src;
@@ -475,7 +473,7 @@ neon (GimpDrawable *drawable,
         }
       else
         {
-          gimp_pixel_rgn_set_row (&dest_rgn, dest, x1, row + y1, (x2 - x1));
+          gimp_pixel_rgn_set_row (&dest_rgn, dest, x, row + y, width);
 
           progress += width * radius;
           if ((row % 20) == 0)
@@ -501,7 +499,7 @@ neon (GimpDrawable *drawable,
       gimp_drawable_flush (drawable);
       gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
       gimp_drawable_update (drawable->drawable_id,
-                            x1, y1, (x2 - x1), (y2 - y1));
+                            x, y, width, height);
     }
   /*  free up buffers  */
   g_free (val_p);
diff --git a/plug-ins/common/emboss.c b/plug-ins/common/emboss.c
index 430d498..6d5413a 100644
--- a/plug-ins/common/emboss.c
+++ b/plug-ins/common/emboss.c
@@ -353,15 +353,17 @@ emboss (GimpDrawable *drawable,
     }
   else
     {
-      gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
+      if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                          &x1, &y1, &width, &height))
+       return
 
       /* expand the bounds a little */
       x1 = MAX (0, x1 - evals.depth);
       y1 = MAX (0, y1 - evals.depth);
-      x2 = MIN (drawable->width, x2 + evals.depth);
-      y2 = MIN (drawable->height, y2 + evals.depth);
+      x2 = MIN (drawable->width, x1 + width + evals.depth);
+      y2 = MIN (drawable->height, y1 + height + evals.depth);
 
-      width = x2 - x1;
+      width  = x2 - x1;
       height = y2 - y1;
     }
 
diff --git a/plug-ins/common/fractal-trace.c b/plug-ins/common/fractal-trace.c
index a0d20f1..9e94850 100644
--- a/plug-ins/common/fractal-trace.c
+++ b/plug-ins/common/fractal-trace.c
@@ -176,11 +176,21 @@ run (const gchar      *name,
   image.height = gimp_drawable_height (drawable->drawable_id);
   image.bpp    = gimp_drawable_bpp (drawable->drawable_id);
   image.alpha  = gimp_drawable_has_alpha (drawable->drawable_id);
-  gimp_drawable_mask_bounds (drawable->drawable_id,
-                             &selection.x1, &selection.y1,
-                             &selection.x2, &selection.y2);
-  selection.width    = selection.x2 - selection.x1;
-  selection.height   = selection.y2 - selection.y1;
+
+  if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                      &selection.x1, &selection.y1,
+                                      &selection.width, &selection.height))
+    {
+      returns[0].type          = GIMP_PDB_STATUS;
+      returns[0].data.d_status = status;
+      *retc = 1;
+      *rets = returns;
+
+      return;
+    }
+
+  selection.x2       = selection.x1 + selection.width;
+  selection.y2       = selection.y1 + selection.height;
   selection.center_x = selection.x1 + (gdouble) selection.width / 2.0;
   selection.center_y = selection.y1 + (gdouble) selection.height / 2.0;
 
diff --git a/plug-ins/common/grid.c b/plug-ins/common/grid.c
index 7904a06..63a9085 100644
--- a/plug-ins/common/grid.c
+++ b/plug-ins/common/grid.c
@@ -393,10 +393,16 @@ grid (gint32        image_ID,
     }
   else
     {
-      gimp_drawable_mask_bounds (drawable->drawable_id, &sx1, &sy1, &sx2, &sy2);
+      gint w, h;
 
-      gimp_pixel_rgn_init (&destPR,
-                           drawable, 0, 0, sx2 - sx1, sy2 - sy1, TRUE, TRUE);
+      if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                          &sx1, &sy1, &w, &h))
+       return;
+
+      sx2 = sx1 + w;
+      sy2 = sy1 + h;
+
+      gimp_pixel_rgn_init (&destPR, drawable, 0, 0, w, h, TRUE, TRUE);
     }
 
   gimp_pixel_rgn_init (&srcPR,
diff --git a/plug-ins/common/hot.c b/plug-ins/common/hot.c
index e63df4c..7c3d62e 100644
--- a/plug-ins/common/hot.c
+++ b/plug-ins/common/hot.c
@@ -355,11 +355,12 @@ pluginCore (piArgs *argp)
       gimp_image_insert_layer (argp->image, nl, -1, 0);
     }
 
-  gimp_drawable_mask_bounds (drw->drawable_id,
-                             &sel_x1, &sel_y1, &sel_x2, &sel_y2);
+  if (! gimp_drawable_mask_intersect (drw->drawable_id,
+                                      &sel_x1, &sel_y1, &width, &height))
+    return success;
 
-  width  = sel_x2 - sel_x1;
-  height = sel_y2 - sel_y1;
+  sel_x2 = sel_x1 + width;
+  sel_y2 = sel_y1 + height;
 
   src = g_new (guchar, width * height * bpp);
   dst = g_new (guchar, width * height * 4);
diff --git a/plug-ins/common/newsprint.c b/plug-ins/common/newsprint.c
index 0f48d79..90d6849 100644
--- a/plug-ins/common/newsprint.c
+++ b/plug-ins/common/newsprint.c
@@ -1801,7 +1801,14 @@ newsprint (GimpDrawable *drawable,
     }
   else
     {
-      gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
+      gint w, h;
+
+      if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                          &x1, &y1, &w, &h))
+       return;
+
+      x2 = x1 + w;
+      y2 = y1 + h;
     }
 
   has_alpha  = gimp_drawable_has_alpha (drawable->drawable_id);
diff --git a/plug-ins/common/nl-filter.c b/plug-ins/common/nl-filter.c
index 051372d..4eff647 100644
--- a/plug-ins/common/nl-filter.c
+++ b/plug-ins/common/nl-filter.c
@@ -905,7 +905,7 @@ nlfilter (GimpDrawable *drawable,
   GimpPixelRgn  srcPr, dstPr;
   guchar       *srcbuf, *dstbuf;
   guchar       *lastrow, *thisrow, *nextrow, *temprow;
-  gint          x1, x2, y1, y2;
+  gint          x1, y1, y2;
   gint          width, height, bpp;
   gint          filtno, y, rowsize, exrowsize, p_update;
 
@@ -913,14 +913,15 @@ nlfilter (GimpDrawable *drawable,
     {
       gimp_preview_get_position (preview, &x1, &y1);
       gimp_preview_get_size (preview, &width, &height);
-      x2 = x1 + width;
       y2 = y1 + height;
     }
   else
     {
-      gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
-      width = x2 - x1;
-      height = y2 - y1;
+      if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                          &x1, &y1, &width, &height))
+       return;
+
+      y2 = y1 + height;
     }
 
   bpp = drawable->bpp;
diff --git a/plug-ins/common/oilify.c b/plug-ins/common/oilify.c
index 7a04506..d51cb2d 100644
--- a/plug-ins/common/oilify.c
+++ b/plug-ins/common/oilify.c
@@ -473,9 +473,12 @@ oilify (GimpDrawable *drawable,
     }
   else
     {
-      gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
-      width  = x2 - x1;
-      height = y2 - y1;
+      if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                          &x1, &y1, &width, &height))
+       return;
+
+      x2 = x1 + width;
+      y2 = y1 + height;
     }
 
   progress = 0;
diff --git a/plug-ins/common/qbist.c b/plug-ins/common/qbist.c
index bb7cdc0..9951a16 100644
--- a/plug-ins/common/qbist.c
+++ b/plug-ins/common/qbist.c
@@ -430,7 +430,7 @@ run (const gchar      *name,
      GimpParam       **return_vals)
 {
   static GimpParam values[1];
-  gint sel_x1, sel_y1, sel_x2, sel_y2;
+  gint sel_x1, sel_y1, sel_width, sel_height;
   gint img_height, img_width;
 
   GimpDrawable      *drawable;
@@ -455,12 +455,20 @@ run (const gchar      *name,
 
   img_width = gimp_drawable_width (drawable->drawable_id);
   img_height = gimp_drawable_height (drawable->drawable_id);
-  gimp_drawable_mask_bounds (drawable->drawable_id,
-                             &sel_x1, &sel_y1, &sel_x2, &sel_y2);
 
-  if (!gimp_drawable_is_rgb (drawable->drawable_id))
+  if (! gimp_drawable_is_rgb (drawable->drawable_id))
     status = GIMP_PDB_CALLING_ERROR;
 
+  if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                      &sel_x1, &sel_y1,
+                                      &sel_width, &sel_height))
+    {
+      values[0].type          = GIMP_PDB_STATUS;
+      values[0].data.d_status = status;
+
+      return;
+    }
+
   if (status == GIMP_PDB_SUCCESS)
     {
       gr = g_rand_new ();
@@ -527,22 +535,21 @@ run (const gchar      *name,
                          imagePR.x,
                          imagePR.y + row,
                          imagePR.w,
-                         sel_x2 - sel_x1,
-                         sel_y2 - sel_y1,
+                         sel_width,
+                         sel_height,
                          imagePR.bpp,
                          qbist_info.oversampling);
                 }
 
               gimp_progress_update ((gfloat) (imagePR.y - sel_y1) /
-                                    (gfloat) (sel_y2 - sel_y1));
+                                    (gfloat) sel_height);
             }
 
           gimp_progress_update (1.0);
           gimp_drawable_flush (drawable);
           gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
-          gimp_drawable_update (drawable->drawable_id,
-                                sel_x1, sel_y1,
-                                (sel_x2 - sel_x1), (sel_y2 - sel_y1));
+          gimp_drawable_update (drawable->drawable_id, sel_x1, sel_y1,
+                                                 sel_width, sel_height);
 
           gimp_displays_flush ();
         }
diff --git a/plug-ins/common/sample-colorize.c b/plug-ins/common/sample-colorize.c
index a3ed8e3..8f956f4 100644
--- a/plug-ins/common/sample-colorize.c
+++ b/plug-ins/common/sample-colorize.c
@@ -2544,6 +2544,7 @@ init_gdrw (t_GDRW         *gdrw,
   gint32  sel_channel_id;
   gint32  x1, x2, y1, y2;
   gint    offsetx, offsety;
+  gint    w, h;
   gint    sel_offsetx, sel_offsety;
   t_GDRW *sel_gdrw;
   gint32  non_empty;
@@ -2564,8 +2565,12 @@ init_gdrw (t_GDRW         *gdrw,
   /* get offsets within the image */
   gimp_drawable_offsets (drawable->drawable_id, &offsetx, &offsety);
 
-  gimp_drawable_mask_bounds (drawable->drawable_id,
-                             &gdrw->x1, &gdrw->y1, &gdrw->x2, &gdrw->y2);
+  if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                      &gdrw->x1, &gdrw->y1, &w, &h))
+    return;
+
+  gdrw->x2 = gdrw->x1 + w;
+  gdrw->y2 = gdrw->y1 + h;
 
   gdrw->bpp = drawable->bpp;
   if (gimp_drawable_has_alpha (drawable->drawable_id))
diff --git a/plug-ins/common/smooth-palette.c b/plug-ins/common/smooth-palette.c
index f3bf5fb..e3f6837 100644
--- a/plug-ins/common/smooth-palette.c
+++ b/plug-ins/common/smooth-palette.c
@@ -90,6 +90,8 @@ query (void)
                           GIMP_PLUGIN,
                           G_N_ELEMENTS (args), G_N_ELEMENTS (return_vals),
                           args, return_vals);
+
+  gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Colors/Info");
 }
 
 static struct
@@ -243,7 +245,7 @@ smooth_palette (GimpDrawable *drawable,
   gint          psize, i, j;
   guchar       *pal;
   guint         bpp = drawable->bpp;
-  gint          sel_x1, sel_x2, sel_y1, sel_y2;
+  gint          sel_x1, sel_y1;
   gint          width, height;
   GimpPixelRgn  pr;
   GRand        *gr;
@@ -263,10 +265,9 @@ smooth_palette (GimpDrawable *drawable,
 
   pal = g_new (guchar, psize * bpp);
 
-  gimp_drawable_mask_bounds (drawable->drawable_id,
-                             &sel_x1, &sel_y1, &sel_x2, &sel_y2);
-  width = sel_x2 - sel_x1;
-  height = sel_y2 - sel_y1;
+  if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                      &sel_x1, &sel_y1, &width, &height))
+    return new_image_id;
 
   gimp_pixel_rgn_init (&pr, drawable, sel_x1, sel_y1, width, height,
                        FALSE, FALSE);
diff --git a/plug-ins/common/softglow.c b/plug-ins/common/softglow.c
index 4414c45..37b8e98 100644
--- a/plug-ins/common/softglow.c
+++ b/plug-ins/common/softglow.c
@@ -245,7 +245,7 @@ softglow (GimpDrawable *drawable,
   gdouble       d_p[5], d_m[5];
   gdouble       bd_p[5], bd_m[5];
   gdouble      *val_p, *val_m, *vp, *vm;
-  gint          x1, y1, x2, y2;
+  gint          x1, y1;
   gint          i, j;
   gint          row, col, b;
   gint          terms;
@@ -261,15 +261,10 @@ softglow (GimpDrawable *drawable,
     {
       gimp_preview_get_position (preview, &x1, &y1);
       gimp_preview_get_size (preview, &width, &height);
-      x2 = x1 + width;
-      y2 = y1 + height;
-    }
-  else
-    {
-      gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
-      width     = (x2 - x1);
-      height    = (y2 - y1);
     }
+  else if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                           &x1, &y1, &width, &height))
+    return;
 
   bytes     = drawable->bpp;
   has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
@@ -481,7 +476,7 @@ softglow (GimpDrawable *drawable,
       gimp_drawable_flush (drawable);
       gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
       gimp_drawable_update (drawable->drawable_id,
-                            x1, y1, (x2 - x1), (y2 - y1));
+                            x1, y1, width, height);
     }
 
   /*  free up buffers  */


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