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



commit 604d50fc36cc7b90feccf482b60f8d43255f670f
Author: Michael Natterer <mitch gimp org>
Date:   Sat May 7 01:11:56 2011 +0200

    Bug 155733 - need to check return values of gimp_drawable_mask_bounds()
    
    Apply modified patch from Brennan Shacklett that fixes some more
    plug-ins.

 plug-ins/color-rotate/color-rotate.c |   36 +++++++++-------
 plug-ins/common/blur-gauss.c         |   29 ++++---------
 plug-ins/common/blur-motion.c        |   11 +----
 plug-ins/common/bump-map.c           |   12 ++++--
 plug-ins/common/color-exchange.c     |   14 +++----
 plug-ins/common/cubism.c             |   10 +++--
 plug-ins/common/depth-merge.c        |   75 ++++++++++++++++++----------------
 plug-ins/common/destripe.c           |   15 ++++---
 plug-ins/common/diffraction.c        |   25 +++++++-----
 plug-ins/common/displace.c           |   24 +++++-----
 10 files changed, 128 insertions(+), 123 deletions(-)
---
diff --git a/plug-ins/color-rotate/color-rotate.c b/plug-ins/color-rotate/color-rotate.c
index 7101c42..4a168aa 100644
--- a/plug-ins/color-rotate/color-rotate.c
+++ b/plug-ins/color-rotate/color-rotate.c
@@ -241,30 +241,36 @@ color_rotate (GimpDrawable *drawable)
   gint         bytes;
   guchar      *src_row, *dest_row;
   gint         row;
-  gint         x1, y1, x2, y2;
+  gint         x, y;
 
-  gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
+  if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                      &x, &y, &width, &height))
+    {
+      return;
+    }
 
-  width  = drawable->width;
-  height = drawable->height;
-  bytes  = drawable->bpp;
+  bytes = drawable->bpp;
 
-  src_row  = g_new (guchar, (x2 - x1) * bytes);
-  dest_row = g_new (guchar, (x2 - x1) * bytes);
+  src_row  = g_new (guchar, width * bytes);
+  dest_row = g_new (guchar, width * bytes);
 
-  gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, width, height, FALSE, FALSE);
-  gimp_pixel_rgn_init (&destPR, drawable, 0, 0, width, height, TRUE, TRUE);
+  gimp_pixel_rgn_init (&srcPR, drawable, 0, 0,
+                       drawable->width,
+                       drawable->height, FALSE, FALSE);
+  gimp_pixel_rgn_init (&destPR, drawable, 0, 0,
+                       drawable->width,
+                       drawable->height, TRUE, TRUE);
 
-  for (row = y1; row < y2; row++)
+  for (row = y; row < (y + height); row++)
     {
-      gimp_pixel_rgn_get_row (&srcPR, src_row, x1, row, (x2 - x1));
+      gimp_pixel_rgn_get_row (&srcPR, src_row, x, row, width);
 
-      color_rotate_row (src_row, dest_row, row, (x2 - x1), bytes);
+      color_rotate_row (src_row, dest_row, row, width, bytes);
 
-      gimp_pixel_rgn_set_row (&destPR, dest_row, x1, row, (x2 - x1));
+      gimp_pixel_rgn_set_row (&destPR, dest_row, x, row, width);
 
       if ((row % 10) == 0)
-        gimp_progress_update ((double) row / (double) (y2 - y1));
+        gimp_progress_update ((double) row / (double) height);
     }
 
   /*  update the processed region  */
@@ -272,7 +278,7 @@ color_rotate (GimpDrawable *drawable)
   gimp_progress_update (1.0);
   gimp_drawable_flush (drawable);
   gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
-  gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
+  gimp_drawable_update (drawable->drawable_id, x, y, width, height);
 
   g_free (src_row);
   g_free (dest_row);
diff --git a/plug-ins/common/blur-gauss.c b/plug-ins/common/blur-gauss.c
index b74aef9..303a3c4 100644
--- a/plug-ins/common/blur-gauss.c
+++ b/plug-ins/common/blur-gauss.c
@@ -1416,9 +1416,9 @@ gauss (GimpDrawable *drawable,
        GtkWidget    *preview)
 {
 
-  gint    x1, y1, x2, y2;
+  gint    x, y;
   gint    width, height;
-  guchar *preview_buffer;
+  guchar *preview_buffer = NULL;
 
   /*
    * IIR goes wrong if the blur radius is less than 1, so we silently
@@ -1436,36 +1436,25 @@ gauss (GimpDrawable *drawable,
 
   if (preview)
     {
-      gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
+      gimp_preview_get_position (GIMP_PREVIEW (preview), &x, &y);
       gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
 
-      if (width < 1 || height < 1)
-        return;
-
       preview_buffer = g_new (guchar, width * height * drawable->bpp);
 
     }
-  else
+  else if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                           &x, &y, &width, &height))
     {
-      gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
-
-      width  = (x2 - x1);
-      height = (y2 - y1);
-
-      if (width < 1 || height < 1)
-        return;
-
-      preview_buffer = NULL;
-
+      return;
     }
 
 
   if (method == BLUR_IIR)
     gauss_iir (drawable,
-               horz, vert, method, preview_buffer, x1, y1, width, height);
+               horz, vert, method, preview_buffer, x, y, width, height);
   else
     gauss_rle (drawable,
-               horz, vert, method, preview_buffer, x1, y1, width, height);
+               horz, vert, method, preview_buffer, x, y, width, height);
 
   if (preview)
     {
@@ -1479,7 +1468,7 @@ gauss (GimpDrawable *drawable,
       /*  merge the shadow, update the drawable  */
       gimp_drawable_flush (drawable);
       gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
-      gimp_drawable_update (drawable->drawable_id, x1, y1, width, height);
+      gimp_drawable_update (drawable->drawable_id, x, y, width, height);
     }
 }
 
diff --git a/plug-ins/common/blur-motion.c b/plug-ins/common/blur-motion.c
index 5960357..b5abe04 100644
--- a/plug-ins/common/blur-motion.c
+++ b/plug-ins/common/blur-motion.c
@@ -895,17 +895,12 @@ mblur (GimpDrawable *drawable,
       gimp_preview_get_position (preview, &x, &y);
       gimp_preview_get_size (preview, &width, &height);
     }
-  else
+  else if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                           &x, &y, &width, &height))
     {
-      gimp_drawable_mask_bounds (drawable->drawable_id,
-                                 &x, &y, &width, &height);
-      width  -= x;
-      height -= y;
+      return;
     }
 
-  if (width < 1 || height < 1)
-    return;
-
   if (! preview)
     gimp_progress_init (_("Motion blurring"));
 
diff --git a/plug-ins/common/bump-map.c b/plug-ins/common/bump-map.c
index 3b3c540..fdf3d31 100644
--- a/plug-ins/common/bump-map.c
+++ b/plug-ins/common/bump-map.c
@@ -317,11 +317,15 @@ run (const gchar      *name,
   /* Get drawable information */
   drawable = gimp_drawable_get (param[2].data.d_drawable);
 
-  gimp_drawable_mask_bounds (drawable->drawable_id,
-                             &sel_x1, &sel_y1, &sel_x2, &sel_y2);
+  if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                      &sel_x1, &sel_y1,
+                                      &sel_width, &sel_height))
+    {
+      return;
+    }
 
-  sel_width     = sel_x2 - sel_x1;
-  sel_height    = sel_y2 - sel_y1;
+  sel_x2 = sel_width + sel_x1;
+  sel_y2 = sel_height + sel_y1;
   img_bpp       = gimp_drawable_bpp (drawable->drawable_id);
   img_has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
 
diff --git a/plug-ins/common/color-exchange.c b/plug-ins/common/color-exchange.c
index 0f8d746..9e0000c 100644
--- a/plug-ins/common/color-exchange.c
+++ b/plug-ins/common/color-exchange.c
@@ -668,18 +668,16 @@ exchange (GimpDrawable *drawable,
     {
       gimp_preview_get_position (preview, &x1, &y1);
       gimp_preview_get_size (preview, &width, &height);
-
-      x2 = x1 + width;
-      y2 = y1 + height;
     }
-  else
+  else if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                           &x1, &y1, &width, &height))
     {
-      gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
-
-      width  = x2 - x1;
-      height = y2 - y1;
+      return;
     }
 
+  x2 = x1 + width;
+  y2 = y1 + height;
+
   has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
   /* allocate memory */
   src_row = g_new (guchar, drawable->width * bpp);
diff --git a/plug-ins/common/cubism.c b/plug-ins/common/cubism.c
index 9d7cd8a..ad2e3f4 100644
--- a/plug-ins/common/cubism.c
+++ b/plug-ins/common/cubism.c
@@ -382,15 +382,17 @@ cubism (GimpDrawable *drawable,
     {
       gimp_preview_get_position (preview, &x1, &y1);
       gimp_preview_get_size (preview, &sel_width, &sel_height);
-      x2 = x1 + sel_width;
-      y2 = y1 + sel_height;
       dest = g_new (guchar, sel_height * sel_width * bytes);
     }
-  else
+  else if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                           &x1, &y1, &sel_width, &sel_height))
     {
-      gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
+      return;
     }
 
+  x2 = x1 + sel_width;
+  y2 = y1 + sel_height;
+
   /*  determine the background color  */
   if (cvals.bg_color == BLACK)
     {
diff --git a/plug-ins/common/depth-merge.c b/plug-ins/common/depth-merge.c
index c4c9cbd..7d8bc93 100644
--- a/plug-ins/common/depth-merge.c
+++ b/plug-ins/common/depth-merge.c
@@ -89,17 +89,15 @@ typedef struct _DepthMerge
   GimpDrawable        *source2Drawable;
   GimpDrawable        *depthMap1Drawable;
   GimpDrawable        *depthMap2Drawable;
-  gint                 selectionX0;
-  gint                 selectionY0;
-  gint                 selectionX1;
-  gint                 selectionY1;
+  gint                 selectionX;
+  gint                 selectionY;
   gint                 selectionWidth;
   gint                 selectionHeight;
   gint                 resultHasAlpha;
 } DepthMerge;
 
 static void      DepthMerge_initParams              (DepthMerge *dm);
-static void      DepthMerge_construct               (DepthMerge *dm);
+static gboolean  DepthMerge_construct               (DepthMerge *dm);
 static void      DepthMerge_destroy                 (DepthMerge *dm);
 static gint32    DepthMerge_execute                 (DepthMerge *dm);
 static void      DepthMerge_executeRegion           (DepthMerge *dm,
@@ -226,7 +224,9 @@ run (const gchar      *name,
       DepthMerge_initParams (&dm);
       gimp_get_data (PLUG_IN_PROC, &(dm.params));
       dm.params.result = param[2].data.d_drawable;
-      DepthMerge_construct (&dm);
+      if (!DepthMerge_construct (&dm))
+        return;
+
       if (!DepthMerge_dialog (&dm))
         {
           values[0].type = GIMP_PDB_STATUS;
@@ -251,13 +251,15 @@ run (const gchar      *name,
           dm.params.scale1    = param[ 9].data.d_float;
           dm.params.scale2    = param[10].data.d_float;
         }
-      DepthMerge_construct (&dm);
+      if (!DepthMerge_construct (&dm))
+        return;
       break;
 
     case GIMP_RUN_WITH_LAST_VALS:
       DepthMerge_initParams (&dm);
       gimp_get_data (PLUG_IN_PROC, &(dm.params));
-      DepthMerge_construct (&dm);
+      if (!DepthMerge_construct (&dm))
+        return;
       break;
 
     default:
@@ -302,17 +304,19 @@ DepthMerge_initParams (DepthMerge *dm)
   dm->params.scale2    =  1;
 }
 
-static void
+static gboolean
 DepthMerge_construct (DepthMerge *dm)
 {
   dm->interface = NULL;
 
   dm->resultDrawable = gimp_drawable_get (dm->params.result);
-  gimp_drawable_mask_bounds (dm->resultDrawable->drawable_id,
-                             &(dm->selectionX0), &(dm->selectionY0),
-                             &(dm->selectionX1), &(dm->selectionY1));
-  dm->selectionWidth  = dm->selectionX1 - dm->selectionX0;
-  dm->selectionHeight = dm->selectionY1 - dm->selectionY0;
+  if (! gimp_drawable_mask_intersect (dm->resultDrawable->drawable_id,
+                                      &(dm->selectionX), &(dm->selectionY),
+                                      &(dm->selectionWidth),
+                                      &(dm->selectionHeight)))
+    {
+      return FALSE;
+    }
   dm->resultHasAlpha = gimp_drawable_has_alpha (dm->resultDrawable->drawable_id);
 
   dm->source1Drawable =
@@ -333,6 +337,7 @@ DepthMerge_construct (DepthMerge *dm)
   dm->params.offset  = CLAMP (dm->params.offset, -1, 1);
   dm->params.scale1  = CLAMP (dm->params.scale1, -1, 1);
   dm->params.scale2  = CLAMP (dm->params.scale2, -1, 1);
+  return TRUE;
 }
 
 static void
@@ -398,7 +403,7 @@ DepthMerge_execute (DepthMerge *dm)
     {
       source1HasAlpha = gimp_drawable_has_alpha (dm->source1Drawable->drawable_id);
       gimp_pixel_rgn_init (&source1Rgn, dm->source1Drawable,
-                           dm->selectionX0, dm->selectionY0,
+                           dm->selectionX, dm->selectionY,
                            dm->selectionWidth, dm->selectionHeight,
                            FALSE, FALSE);
     }
@@ -414,7 +419,7 @@ DepthMerge_execute (DepthMerge *dm)
     {
       source2HasAlpha = gimp_drawable_has_alpha (dm->source2Drawable->drawable_id);
       gimp_pixel_rgn_init (&source2Rgn, dm->source2Drawable,
-                           dm->selectionX0, dm->selectionY0,
+                           dm->selectionX, dm->selectionY,
                            dm->selectionWidth, dm->selectionHeight,
                            FALSE, FALSE);
     }
@@ -430,7 +435,7 @@ DepthMerge_execute (DepthMerge *dm)
     {
       depthMap1HasAlpha = gimp_drawable_has_alpha (dm->depthMap1Drawable->drawable_id);
       gimp_pixel_rgn_init (&depthMap1Rgn, dm->depthMap1Drawable,
-                           dm->selectionX0, dm->selectionY0,
+                           dm->selectionX, dm->selectionY,
                            dm->selectionWidth, dm->selectionHeight,
                            FALSE, FALSE);
     }
@@ -443,7 +448,7 @@ DepthMerge_execute (DepthMerge *dm)
     {
       depthMap2HasAlpha = gimp_drawable_has_alpha (dm->depthMap2Drawable->drawable_id);
       gimp_pixel_rgn_init (&depthMap2Rgn, dm->depthMap2Drawable,
-                           dm->selectionX0, dm->selectionY0,
+                           dm->selectionX, dm->selectionY,
                            dm->selectionWidth, dm->selectionHeight,
                            FALSE, FALSE);
     }
@@ -453,16 +458,16 @@ DepthMerge_execute (DepthMerge *dm)
         depthMap2Row[x] = 0;
       }
   gimp_pixel_rgn_init (&resultRgn, dm->resultDrawable,
-                       dm->selectionX0, dm->selectionY0,
+                       dm->selectionX, dm->selectionY,
                        dm->selectionWidth, dm->selectionHeight,
                        TRUE, TRUE);
 
-  for (y = dm->selectionY0; y < dm->selectionY1; y++)
+  for (y = dm->selectionY; y < (dm->selectionY + dm->selectionHeight); y++)
     {
       if (dm->source1Drawable != NULL)
         {
           gimp_pixel_rgn_get_row (&source1Rgn, tempRow,
-                                  dm->selectionX0, y,
+                                  dm->selectionX, y,
                                   dm->selectionWidth);
           util_convertColorspace (source1Row, 4, TRUE,
                                   tempRow,
@@ -472,7 +477,7 @@ DepthMerge_execute (DepthMerge *dm)
       if (dm->source2Drawable != NULL)
         {
           gimp_pixel_rgn_get_row (&source2Rgn, tempRow,
-                                  dm->selectionX0, y,
+                                  dm->selectionX, y,
                                   dm->selectionWidth);
           util_convertColorspace (source2Row, 4, TRUE,
                                   tempRow,
@@ -482,7 +487,7 @@ DepthMerge_execute (DepthMerge *dm)
       if (dm->depthMap1Drawable != NULL)
         {
           gimp_pixel_rgn_get_row (&depthMap1Rgn, tempRow,
-                                  dm->selectionX0, y,
+                                  dm->selectionX, y,
                                   dm->selectionWidth);
           util_convertColorspace (depthMap1Row, 1, FALSE,
                                   tempRow,
@@ -492,7 +497,7 @@ DepthMerge_execute (DepthMerge *dm)
       if (dm->depthMap2Drawable != NULL)
         {
           gimp_pixel_rgn_get_row (&depthMap2Rgn, tempRow,
-                                  dm->selectionX0, y,
+                                  dm->selectionX, y,
                                   dm->selectionWidth);
           util_convertColorspace (depthMap2Row, 1, FALSE,
                                   tempRow,
@@ -509,10 +514,10 @@ DepthMerge_execute (DepthMerge *dm)
                               dm->selectionWidth);
 
       gimp_pixel_rgn_set_row (&resultRgn, tempRow,
-                              dm->selectionX0, y,
+                              dm->selectionX, y,
                               dm->selectionWidth);
 
-      gimp_progress_update ((double)(y-dm->selectionY0) /
+      gimp_progress_update ((double)(y-dm->selectionY) /
                             (double)(dm->selectionHeight - 1));
     }
 
@@ -527,7 +532,7 @@ DepthMerge_execute (DepthMerge *dm)
   gimp_drawable_flush (dm->resultDrawable);
   gimp_drawable_merge_shadow (dm->resultDrawable->drawable_id, TRUE);
   gimp_drawable_update (dm->resultDrawable->drawable_id,
-                        dm->selectionX0, dm->selectionY0,
+                        dm->selectionX, dm->selectionY,
                         dm->selectionWidth, dm->selectionHeight);
   return TRUE;
 }
@@ -820,7 +825,7 @@ DepthMerge_buildPreviewSourceImage (DepthMerge *dm)
                           dm->interface->previewHeight,
                           4, TRUE,
                           dm->source1Drawable,
-                          dm->selectionX0, dm->selectionY0,
+                          dm->selectionX, dm->selectionY,
                           dm->selectionWidth, dm->selectionHeight);
   dm->interface->previewSource2   =
     g_new (guchar, dm->interface->previewWidth *
@@ -830,7 +835,7 @@ DepthMerge_buildPreviewSourceImage (DepthMerge *dm)
                           dm->interface->previewHeight,
                           4, TRUE,
                           dm->source2Drawable,
-                          dm->selectionX0, dm->selectionY0,
+                          dm->selectionX, dm->selectionY,
                           dm->selectionWidth, dm->selectionHeight);
   dm->interface->previewDepthMap1 =
     g_new (guchar, dm->interface->previewWidth *
@@ -840,7 +845,7 @@ DepthMerge_buildPreviewSourceImage (DepthMerge *dm)
                           dm->interface->previewHeight,
                           1, FALSE,
                           dm->depthMap1Drawable,
-                          dm->selectionX0, dm->selectionY0,
+                          dm->selectionX, dm->selectionY,
                           dm->selectionWidth, dm->selectionHeight);
   dm->interface->previewDepthMap2 =
     g_new (guchar, dm->interface->previewWidth *
@@ -850,7 +855,7 @@ DepthMerge_buildPreviewSourceImage (DepthMerge *dm)
                           dm->interface->previewHeight,
                           1, FALSE,
                           dm->depthMap2Drawable,
-                          dm->selectionX0, dm->selectionY0,
+                          dm->selectionX, dm->selectionY,
                           dm->selectionWidth, dm->selectionHeight);
 }
 
@@ -933,7 +938,7 @@ dialogSource1ChangedCallback (GtkWidget  *widget,
                           dm->interface->previewHeight,
                           4, TRUE,
                           dm->source1Drawable,
-                          dm->selectionX0, dm->selectionY0,
+                          dm->selectionX, dm->selectionY,
                           dm->selectionWidth, dm->selectionHeight);
 
   DepthMerge_updatePreview (dm);
@@ -958,7 +963,7 @@ dialogSource2ChangedCallback (GtkWidget  *widget,
                           dm->interface->previewHeight,
                           4, TRUE,
                           dm->source2Drawable,
-                          dm->selectionX0, dm->selectionY0,
+                          dm->selectionX, dm->selectionY,
                           dm->selectionWidth, dm->selectionHeight);
 
   DepthMerge_updatePreview (dm);
@@ -983,7 +988,7 @@ dialogDepthMap1ChangedCallback (GtkWidget  *widget,
                           dm->interface->previewHeight,
                           1, FALSE,
                           dm->depthMap1Drawable,
-                          dm->selectionX0, dm->selectionY0,
+                          dm->selectionX, dm->selectionY,
                           dm->selectionWidth, dm->selectionHeight);
 
   DepthMerge_updatePreview (dm);
@@ -1008,7 +1013,7 @@ dialogDepthMap2ChangedCallback (GtkWidget  *widget,
                           dm->interface->previewHeight,
                           1, FALSE,
                           dm->depthMap2Drawable,
-                          dm->selectionX0, dm->selectionY0,
+                          dm->selectionX, dm->selectionY,
                           dm->selectionWidth, dm->selectionHeight);
 
   DepthMerge_updatePreview (dm);
diff --git a/plug-ins/common/destripe.c b/plug-ins/common/destripe.c
index def88e7..dcbdc50 100644
--- a/plug-ins/common/destripe.c
+++ b/plug-ins/common/destripe.c
@@ -244,7 +244,7 @@ destripe (GimpDrawable *drawable,
   GimpPixelRgn  dst_rgn;        /* destination image region */
   guchar       *src_rows;       /* image data */
   gdouble       progress, progress_inc;
-  gint          x1, x2, y1, y2;
+  gint          x1, x2, y1;
   gint          width, height;
   gint          bpp;
   glong        *hist, *corr;        /* "histogram" data */
@@ -264,20 +264,21 @@ destripe (GimpDrawable *drawable,
     {
       gimp_preview_get_position (preview, &x1, &y1);
       gimp_preview_get_size (preview, &width, &height);
-      x2 = x1 + width;
-      y2 = y1 + height;
     }
   else
     {
       gimp_progress_init (_("Destriping"));
-      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;
+        }
       progress = 0;
       progress_inc = 0.5 * tile_width / width;
     }
 
+  x2 = x1 + width;
+
   /*
    * Setup for filter...
    */
diff --git a/plug-ins/common/diffraction.c b/plug-ins/common/diffraction.c
index 4595538..de4b84c 100644
--- a/plug-ins/common/diffraction.c
+++ b/plug-ins/common/diffraction.c
@@ -286,8 +286,8 @@ run (const gchar      *name,
 typedef struct {
   gdouble       dhoriz;
   gdouble       dvert;
-  gint          x1;
-  gint          y1;
+  gint          x;
+  gint          y;
 } DiffractionParam_t;
 
 static void
@@ -301,8 +301,8 @@ diffraction_func (gint x,
   gdouble px, py;
   GimpRGB rgb;
 
-  px = -5.0 + param->dhoriz * (x - param->x1);
-  py = 5.0 + param->dvert * (y - param->y1);
+  px = -5.0 + param->dhoriz * (x - param->x);
+  py = 5.0 + param->dvert * (y - param->y);
 
   diff_diffract (px, py, &rgb);
 
@@ -319,13 +319,18 @@ diffraction (GimpDrawable *drawable)
 {
   GimpRgnIterator *iter;
   DiffractionParam_t param;
-  gint x1, y1, x2, y2;
+  gint x, y, width, height;
 
-  gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
-  param.x1 = x1;
-  param.y1 = y1;
-  param.dhoriz = 10.0 / (x2 - x1 - 1);
-  param.dvert  = -10.0 / (y2 - y1 - 1);
+  if (! gimp_drawable_mask_intersect (drawable->drawable_id, &x, &y,
+                                      &width, &height))
+    {
+      return;
+    }
+
+  param.x = x;
+  param.y = y;
+  param.dhoriz = 10.0 / (width - 1);
+  param.dvert  = -10.0 / (height - 1);
 
   gimp_progress_init (_("Creating diffraction pattern"));
   iter = gimp_rgn_iterator_new (drawable, 0);
diff --git a/plug-ins/common/displace.c b/plug-ins/common/displace.c
index f8dc5c7..f4ad051 100644
--- a/plug-ins/common/displace.c
+++ b/plug-ins/common/displace.c
@@ -523,7 +523,7 @@ displace (GimpDrawable *drawable,
   guchar           *mxrow, *mx;
   guchar           *myrow, *my;
   guchar            pixel[4][4];
-  gint              x1, y1, x2, y2;
+  gint              x1, y1;
   gint              x, y;
   gdouble           cx, cy;
   gint              progress, max_progress;
@@ -561,24 +561,24 @@ displace (GimpDrawable *drawable,
 
   bytes  = drawable->bpp;
 
-  gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
-  width  = x2 - x1;
-  height = y2 - y1;
-
-  if (dvals.mode == POLAR_MODE)
-    {
-      cx = x1 + width / 2.0;
-      cy = y1 + height / 2.0;
-    }
 
   if (preview)
     {
       gimp_preview_get_position (preview, &x1, &y1);
       gimp_preview_get_size (preview, &width, &height);
-      x2 = x1 + width;
-      y2 = y1 + height;
       buffer = g_new (guchar, width * height * bytes);
     }
+  else if (! gimp_drawable_mask_intersect (drawable->drawable_id, &x1, &y1,
+                                           &width, &height))
+    {
+      return;
+    }
+
+  if (dvals.mode == POLAR_MODE)
+    {
+      cx = x1 + width / 2.0;
+      cy = y1 + height / 2.0;
+    }
 
   progress     = 0;
   max_progress = width * height;



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