Index: plug-ins/common/gauss_iir.c
===================================================================
RCS file: /cvs/gnome/gimp/plug-ins/common/gauss_iir.c,v
retrieving revision 1.56
diff -u -p -r1.56 gauss_iir.c
--- plug-ins/common/gauss_iir.c	20 Jan 2004 17:07:42 -0000	1.56
+++ plug-ins/common/gauss_iir.c	5 Apr 2004 00:43:06 -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;
@@ -541,6 +544,7 @@ gauss_iir (GimpDrawable *drawable,
   gint initial_p[4];
   gint initial_m[4];
   gdouble std_dev;
+  gint padx, pady, paddedx1, paddedy1;
 
   if (horz <= 0.0 && vert <= 0.0)
     return;
@@ -553,6 +557,19 @@ gauss_iir (GimpDrawable *drawable,
   if (width < 1 || height < 1)
     return;
 
+  /* Readjust because 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);
 
@@ -588,7 +605,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);
 
@@ -636,7 +654,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)
@@ -667,7 +686,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);
 
@@ -715,7 +735,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)
