Index: gauss_iir.c
===================================================================
RCS file: /cvs/gnome/gimp/plug-ins/common/gauss_iir.c,v
retrieving revision 1.45
diff -u -p -r1.45 gauss_iir.c
--- gauss_iir.c	18 Feb 2003 17:54:02 -0000	1.45
+++ gauss_iir.c	25 Feb 2003 23:18:12 -0000
@@ -30,6 +30,9 @@
 #include "libgimp/stdplugins-intl.h"
 
 
+/* Extra security area to use in case of having a selection */
+#define EXTRA_INPUT_AREA 10
+
 typedef struct
 {
   gdouble  radius;
@@ -574,7 +577,10 @@ gauss_iir (GimpDrawable *drawable,
   gdouble progress, max_progress;
   gint initial_p[4];
   gint initial_m[4];
+  guchar *guc_tmp1, *guc_tmp2;
+  gint *gi_tmp1, *gi_tmp2;
   gdouble std_dev;
+  gint padx, pady, paddedx1, paddedy1;
 
   if (horz <= 0.0 && vert <= 0.0)
     return;
@@ -587,6 +593,19 @@ gauss_iir (GimpDrawable *drawable,
   if (width < 1 || height < 1)
     return;
 
+  /* Readjust, cos we are interested not only in destination pixels */
+  /* but in all source pixels that will affect the computation      */
+  padx = horz + EXTRA_INPUT_AREA;
+  pady = vert + EXTRA_INPUT_AREA;
+  width  += (2 * padx);
+  height += (2 * pady);
+
+  /* But avoiding "underflow" or "overflow" */
+  paddedx1 = MAX(0, (x1 - padx));
+  paddedy1 = MAX(0, (y1 - pady));
+  width  = MIN((drawable->width - paddedx1), width);
+  height = MIN((drawable->height - paddedy1), height);
+
   bytes = drawable->bpp;
   has_alpha = gimp_drawable_has_alpha(drawable->drawable_id);
 
@@ -622,7 +641,8 @@ gauss_iir (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 + paddedx1), paddedy1, height);
           if (has_alpha)
               multiply_alpha (src, height, bytes);
 
@@ -670,7 +690,8 @@ gauss_iir (GimpDrawable *drawable,
           if (has_alpha)
               separate_alpha (src, height, bytes);
 
-	  gimp_pixel_rgn_set_col (&dest_rgn, dest, col + x1, y1, (y2 - y1));
+          gimp_pixel_rgn_set_col (&dest_rgn, dest,
+                                  (col + paddedx1), paddedy1, height);
 
 	  progress += height * vert;
 	  if ((col % 5) == 0)
@@ -701,7 +722,8 @@ if (horz > 0.0)
 	  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,
+                                  paddedx1, (row + paddedy1), width);
           if (has_alpha)
               multiply_alpha (dest, width, bytes);
 
@@ -749,7 +771,8 @@ if (horz > 0.0)
           if (has_alpha)
               separate_alpha (dest, width, bytes);
 
-	  gimp_pixel_rgn_set_row (&dest_rgn, dest, x1, row + y1, (x2 - x1));
+          gimp_pixel_rgn_set_row (&dest_rgn, dest,
+                                  paddedx1, (row + paddedy1), width);
 
 	  progress += width * horz;
 	  if ((row % 5) == 0)
@@ -760,7 +783,8 @@ if (horz > 0.0)
   /*  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, (x2 - x1), (y2 - y1));
+  gimp_drawable_update (drawable->drawable_id,
+                        paddedx1, paddedy1, width, height);
 
   /*  free up buffers  */
   g_free (val_p);
