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



commit 9b6c9e1fe4f46d2d47c6d97d4147cf060abd07f8
Author: Michael Natterer <mitch gimp org>
Date:   Sun Jun 7 23:52:37 2009 +0200

    Bug 155733 â?? need to check return values of gimp_drawable_mask_bounds()
    
    Finally commit the patch from Luidnel Maignan, but don't spit messages
    when the effected region is empty (core functions don't spit messages
    either). Also got rid of some x2 and y2 variables that are not needed
    any longer.
---
 plug-ins/common/blinds.c               |   10 ++++++----
 plug-ins/common/blur-gauss-selective.c |   28 ++++++++++++++--------------
 plug-ins/common/blur.c                 |    8 +++++++-
 plug-ins/common/deinterlace.c          |    9 +++------
 plug-ins/common/despeckle.c            |   28 ++++++++++++++--------------
 plug-ins/common/iwarp.c                |   22 +++++++++++++++-------
 plug-ins/common/mosaic.c               |   12 ++++++++----
 plug-ins/common/pixelize.c             |   19 +++++++++++++------
 plug-ins/common/polar-coords.c         |    9 +++++----
 plug-ins/common/sharpen.c              |   14 ++++++++------
 plug-ins/common/value-propagate.c      |   13 ++++++++-----
 plug-ins/common/warp.c                 |   14 +++++++++-----
 12 files changed, 110 insertions(+), 76 deletions(-)

diff --git a/plug-ins/common/blinds.c b/plug-ins/common/blinds.c
index fa2f1d1..a2aebdb 100644
--- a/plug-ins/common/blinds.c
+++ b/plug-ins/common/blinds.c
@@ -567,11 +567,13 @@ apply_blinds (GimpDrawable *drawable)
 
   gimp_drawable_get_color_uchar (drawable->drawable_id, &background, bg);
 
-  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_x1 + sel_width;
+  sel_y2 = sel_y1 + sel_height;
 
   gimp_pixel_rgn_init (&src_rgn, drawable,
                        sel_x1, sel_y1, sel_width, sel_height, FALSE, FALSE);
diff --git a/plug-ins/common/blur-gauss-selective.c b/plug-ins/common/blur-gauss-selective.c
index 0735f8c..74c87ef 100644
--- a/plug-ins/common/blur-gauss-selective.c
+++ b/plug-ins/common/blur-gauss-selective.c
@@ -730,19 +730,19 @@ sel_gauss (GimpDrawable *drawable,
            gint          maxdelta)
 {
   GimpPixelRgn src_rgn, dest_rgn;
-  gint         width, height;
   gint         bytes;
   gboolean     has_alpha;
   guchar      *dest;
   guchar      *src;
-  gint         x1, y1, x2, y2;
+  gint         x, y;
+  gint         width, height;
   gdouble     *mat;
   gint         numrad;
 
-  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     = x2 - x1;
-  height    = y2 - y1;
   bytes     = drawable->bpp;
   has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
 
@@ -754,20 +754,20 @@ sel_gauss (GimpDrawable *drawable,
   dest = g_new (guchar, width * height * bytes);
 
   gimp_pixel_rgn_init (&src_rgn,
-                       drawable, x1, y1, width, height, FALSE, FALSE);
-  gimp_pixel_rgn_get_rect (&src_rgn, src, x1, y1, width, height);
+                       drawable, x, y, width, height, FALSE, FALSE);
+  gimp_pixel_rgn_get_rect (&src_rgn, src, x, y, width, height);
 
   matrixmult (src, dest, width, height, mat, numrad,
               bytes, has_alpha, maxdelta, FALSE);
 
   gimp_pixel_rgn_init (&dest_rgn,
-                       drawable, x1, y1, width, height, TRUE, TRUE);
-  gimp_pixel_rgn_set_rect (&dest_rgn, dest, x1, y1, width, height);
+                       drawable, x, y, width, height, TRUE, TRUE);
+  gimp_pixel_rgn_set_rect (&dest_rgn, dest, x, y, width, height);
 
   /*  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);
 
   /* free up buffers */
   g_free (src);
@@ -780,7 +780,7 @@ preview_update (GimpPreview *preview)
 {
   GimpDrawable  *drawable;
   glong          bytes;
-  gint           x1, y1;
+  gint           x, y;
   guchar        *render_buffer;  /* Buffer to hold rendered image */
   gint           width;          /* Width of preview widget */
   gint           height;         /* Height of preview widget */
@@ -800,19 +800,19 @@ preview_update (GimpPreview *preview)
   /*
    * Setup for filter...
    */
-  gimp_preview_get_position (preview, &x1, &y1);
+  gimp_preview_get_position (preview, &x, &y);
   gimp_preview_get_size (preview, &width, &height);
 
   /* initialize pixel regions */
   gimp_pixel_rgn_init (&srcPR, drawable,
-                       x1, y1, width, height,
+                       x, y, width, height,
                        FALSE, FALSE);
   render_buffer = g_new (guchar, width * height * bytes);
 
   src = g_new (guchar, width * height * bytes);
 
   /* render image */
-  gimp_pixel_rgn_get_rect (&srcPR, src, x1, y1, width, height);
+  gimp_pixel_rgn_get_rect (&srcPR, src, x, y, width, height);
   has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
 
   radius = fabs (bvals.radius) + 1.0;
diff --git a/plug-ins/common/blur.c b/plug-ins/common/blur.c
index f0ff674..e520f84 100644
--- a/plug-ins/common/blur.c
+++ b/plug-ins/common/blur.c
@@ -250,7 +250,13 @@ blur (GimpDrawable *drawable)
   gint          ind;
   gboolean      has_alpha;
 
-  gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
+  if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                      &x1, &y1, &width, &height))
+    return;
+
+  x2 = x1 + width;
+  y2 = y1 + height;
+
   /*
    *  Get the size of the input image. (This will/must be the same
    *  as the size of the output image.  Also get alpha info.
diff --git a/plug-ins/common/deinterlace.c b/plug-ins/common/deinterlace.c
index b40654f..e57580a 100644
--- a/plug-ins/common/deinterlace.c
+++ b/plug-ins/common/deinterlace.c
@@ -204,12 +204,9 @@ deinterlace (GimpDrawable *drawable,
     }
   else
     {
-      gint x2, y2;
-
-      gimp_drawable_mask_bounds (drawable->drawable_id, &x, &y, &x2, &y2);
-
-      width  = x2 - x;
-      height = y2 - y;
+      if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                          &x, &y, &width, &height))
+        return;
 
       dest = g_new (guchar, width * bytes);
 
diff --git a/plug-ins/common/despeckle.c b/plug-ins/common/despeckle.c
index 6b0c2bf..08765f0 100644
--- a/plug-ins/common/despeckle.c
+++ b/plug-ins/common/despeckle.c
@@ -367,35 +367,35 @@ pixel_copy (guchar       *dest,
 static void
 despeckle (void)
 {
-  GimpPixelRgn  src_rgn,        /* Source image region */
-                dst_rgn;
-  guchar       *src, *dst;
+  GimpPixelRgn  src_rgn;        /* Source image region */
+  GimpPixelRgn  dst_rgn;
+  guchar       *src;
+  guchar       *dst;
   gint          img_bpp;
-  gint          width;
-  gint          height;
-  gint          x1, y1 ,x2 ,y2;
+  gint          x, y;
+  gint          width, height;
 
   img_bpp = gimp_drawable_bpp (drawable->drawable_id);
-  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;
 
-  gimp_pixel_rgn_init (&src_rgn, drawable, x1, y1, width, height, FALSE, FALSE);
-  gimp_pixel_rgn_init (&dst_rgn, drawable, x1, y1, width, height, TRUE, TRUE);
+  gimp_pixel_rgn_init (&src_rgn, drawable, x, y, width, height, FALSE, FALSE);
+  gimp_pixel_rgn_init (&dst_rgn, drawable, x, y, width, height, TRUE, TRUE);
 
   src = g_new (guchar, width * height * img_bpp);
   dst = g_new (guchar, width * height * img_bpp);
 
-  gimp_pixel_rgn_get_rect (&src_rgn, src, x1, y1, width, height);
+  gimp_pixel_rgn_get_rect (&src_rgn, src, x, y, width, height);
 
   despeckle_median (src, dst, width, height, img_bpp, despeckle_radius, FALSE);
 
-  gimp_pixel_rgn_set_rect (&dst_rgn, dst, x1, y1, width, height);
+  gimp_pixel_rgn_set_rect (&dst_rgn, dst, x, y, width, height);
 
   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);
 
   g_free (dst);
   g_free (src);
diff --git a/plug-ins/common/iwarp.c b/plug-ins/common/iwarp.c
index ac046ad..2f22edd 100644
--- a/plug-ins/common/iwarp.c
+++ b/plug-ins/common/iwarp.c
@@ -185,11 +185,10 @@ static void     iwarp_scale_preview       (gint       new_width,
 static void     iwarp_preview_build       (GtkWidget *dialog,
                                            GtkWidget *vbox);
 
-static void     iwarp_init                (void);
+static gboolean iwarp_init                (void);
 static void     iwarp_preview_init        (void);
 
 
-
 const GimpPlugInInfo PLUG_IN_INFO =
 {
   NULL,  /* init_proc  */
@@ -963,14 +962,20 @@ iwarp_preview_init (void)
   g_free (linebuffer);
 }
 
-static void
+static gboolean
 iwarp_init (void)
 {
   gint  i;
 
-  gimp_drawable_mask_bounds (drawable->drawable_id, &xl, &yl, &xh, &yh);
-  sel_width = xh - xl;
-  sel_height = yh - yl;
+  if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                      &xl, &yl, &sel_width, &sel_height))
+    {
+      g_message (_("Region affected by plug-in is empty"));
+      return FALSE;
+    }
+
+  xh = xl + sel_width;
+  yh = yl + sel_height;
 
   image_bpp = gimp_drawable_bpp (drawable->drawable_id);
 
@@ -1000,6 +1005,8 @@ iwarp_init (void)
         pow ((cos (sqrt((gdouble) i / MAX_DEFORM_AREA_RADIUS) * G_PI) + 1) *
              0.5, 0.7); /*0.7*/
     }
+
+  return TRUE;
 }
 
 static void
@@ -1269,7 +1276,8 @@ iwarp_dialog (void)
 
   gimp_ui_init (PLUG_IN_BINARY, TRUE);
 
-  iwarp_init ();
+  if (! iwarp_init ())
+    return FALSE;
 
   dialog = gimp_dialog_new (_("IWarp"), PLUG_IN_BINARY,
                             NULL, 0,
diff --git a/plug-ins/common/mosaic.c b/plug-ins/common/mosaic.c
index 81550b6..6e13ed6 100644
--- a/plug-ins/common/mosaic.c
+++ b/plug-ins/common/mosaic.c
@@ -488,14 +488,18 @@ mosaic (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;
+
+      x2 = x1 + width;
+      y2 = y1 + height;
 
       /*  progress bar for gradient finding  */
       gimp_progress_init (_("Finding edges"));
@@ -517,7 +521,7 @@ mosaic (GimpDrawable *drawable,
       grid_create_octagons (x1, y1, x2, y2);
       break;
     case TRIANGLES:
-      grid_create_triangles(x1, y1, x2, y2);
+      grid_create_triangles (x1, y1, x2, y2);
       break;
     default:
       break;
diff --git a/plug-ins/common/pixelize.c b/plug-ins/common/pixelize.c
index 32317dc..f107a46 100644
--- a/plug-ins/common/pixelize.c
+++ b/plug-ins/common/pixelize.c
@@ -460,10 +460,12 @@ pixelize_large (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;
 
       /* Initialize progress */
       progress = 0;
@@ -632,10 +634,15 @@ pixelize_small (GimpDrawable *drawable,
 {
   GimpPixelRgn src_rgn, dest_rgn;
   gint         bpp, has_alpha;
-  gint         x1, y1, x2, y2;
+  gint         x1, y1, x2, y2, w, h;
   gint         progress, max_progress;
 
-  gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
+  if (! gimp_drawable_mask_intersect (drawable->drawable_id, &x1, &y1, &w, &h))
+    return;
+
+  x2 = x1 + w;
+  y2 = y1 + h;
+
   gimp_pixel_rgn_init (&src_rgn, drawable, x1, y1, x2-x1, y2-y1, FALSE, FALSE);
   gimp_pixel_rgn_init (&dest_rgn, drawable, x1, y1, x2-x1, y2-y1, TRUE, TRUE);
 
diff --git a/plug-ins/common/polar-coords.c b/plug-ins/common/polar-coords.c
index 828178f..4a60efe 100644
--- a/plug-ins/common/polar-coords.c
+++ b/plug-ins/common/polar-coords.c
@@ -202,13 +202,14 @@ run (const gchar      *name,
   img_height    = gimp_drawable_height (drawable->drawable_id);
   img_has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
 
-  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;
 
   /* Calculate scaling parameters */
 
-  sel_width  = sel_x2 - sel_x1;
-  sel_height = sel_y2 - sel_y1;
+  sel_x2 = sel_x1 + sel_width;
+  sel_y2 = sel_y1 + sel_height;
 
   cen_x = (double) (sel_x1 + sel_x2 - 1) / 2.0;
   cen_y = (double) (sel_y1 + sel_y2 - 1) / 2.0;
diff --git a/plug-ins/common/sharpen.c b/plug-ins/common/sharpen.c
index 68ce638..bf3ef3a 100644
--- a/plug-ins/common/sharpen.c
+++ b/plug-ins/common/sharpen.c
@@ -291,17 +291,19 @@ sharpen (GimpDrawable *drawable)
 
   filter = NULL;
 
-  gimp_drawable_mask_bounds (drawable->drawable_id,
-                             &x1, &y1, &x2, &y2);
+  if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                      &x1, &y1, &sel_width, &sel_height))
+    return;
 
-  sel_width  = x2 - x1;
-  sel_height = y2 - y1;
-  img_bpp    = gimp_drawable_bpp (drawable->drawable_id);
+  x2 = x1 + sel_width;
+  y2 = y1 + sel_height;
+
+  img_bpp = gimp_drawable_bpp (drawable->drawable_id);
 
   /*
    * Let the user know what we're doing...
    */
-  gimp_progress_init( _("Sharpening"));
+  gimp_progress_init (_("Sharpening"));
 
   /*
    * Setup for filter...
diff --git a/plug-ins/common/value-propagate.c b/plug-ins/common/value-propagate.c
index 76fbc70..b926a66 100644
--- a/plug-ins/common/value-propagate.c
+++ b/plug-ins/common/value-propagate.c
@@ -429,20 +429,23 @@ value_propagate_body (GimpDrawable *drawable,
   dtype = gimp_drawable_type (drawable->drawable_id);
   bytes = drawable->bpp;
 
-  /* Here I use the algorithm of blur.c . */
+  /* Here I use the algorithm of blur.c */
   if (preview)
     {
        gimp_preview_get_position (preview, &begx, &begy);
        gimp_preview_get_size (preview, &width, &height);
+
        endx = begx + width;
        endy = begy + height;
     }
   else
     {
-      gimp_drawable_mask_bounds (drawable->drawable_id,
-                                 &begx, &begy, &endx, &endy);
-      width  = endx - begx;
-      height = endy - begy;
+      if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+                                          &begx, &begy, &width, &height))
+        return;
+
+      endx = begx + width;
+      endy = begy + height;
     }
 
   gimp_tile_cache_ntiles (2 * ((width) / gimp_tile_width () + 1));
diff --git a/plug-ins/common/warp.c b/plug-ins/common/warp.c
index a9d4243..173c24d 100644
--- a/plug-ins/common/warp.c
+++ b/plug-ins/common/warp.c
@@ -1350,14 +1350,18 @@ warp_one (GimpDrawable *draw,
 
   /* Get selection area */
 
-  if (! gimp_drawable_mask_intersect (draw->drawable_id, &x1, &y1, &x2, &y2))
+  if (! gimp_drawable_mask_intersect (draw->drawable_id,
+                                      &x1, &y1, &width, &height))
     return;
 
-   width  = draw->width;
-   height = draw->height;
-   dest_bytes  = draw->bpp;
+  x2 = x1 + width;
+  y2 = y1 + height;
+
+  width  = draw->width;
+  height = draw->height;
+  dest_bytes = draw->bpp;
 
-   dmap_bytes = map_x->bpp;
+  dmap_bytes = map_x->bpp;
 
    max_progress = (x2 - x1) * (y2 - y1);
 



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