Index: gimp/app/paint-funcs/paint-funcs.c
===================================================================
RCS file: /cvs/gnome/gimp/app/paint-funcs/paint-funcs.c,v
retrieving revision 1.159
diff -u -p -r1.159 paint-funcs.c
--- a/gimp/app/paint-funcs/paint-funcs.c	15 Apr 2004 12:38:54 -0000	1.159
+++ b/gimp/app/paint-funcs/paint-funcs.c	31 May 2004 08:04:38 -0000
@@ -2358,27 +2358,31 @@ extract_from_region (PixelRegion *src,
 
 
 void
-convolve_region (PixelRegion             *srcR,
-                 PixelRegion             *destR,
-                 gint                     *matrix,
-                 gint                      size,
-                 gint                      divisor,
-                 GimpConvolutionType  mode)
+convolve_region (PixelRegion         *srcR,
+                 PixelRegion         *destR,
+                 gfloat              *matrix,
+                 gint                 size,
+                 gdouble              divisor,
+                 GimpConvolutionType  mode,
+                 gboolean             alpha_weighting)
 {
   /*  Convolve the src image using the convolution matrix, writing to dest  */
   /*  Convolve is not tile-enabled--use accordingly  */
-  guchar *src, *s_row, *s;
-  guchar *dest, *d;
-  gint   *m;
-  gint    total [4];
-  gint    b, bytes;
-  gint    length;
-  gint    wraparound;
-  gint    margin;      /*  margin imposed by size of conv. matrix  */
-  gint    i, j;
-  gint    x, y;
-  gint    offset;
-
+  guchar  *src, *s_row, *s;
+  guchar  *dest, *d;
+  gfloat  *m;
+  gdouble  total [4];
+  gint     b, bytes;
+  gint     alpha, a_byte;
+  gint     length;
+  gint     wraparound;
+  gint     margin;      /*  margin imposed by size of conv. matrix  */
+  gint     i, j;
+  gint     x, y;
+  gint     offset;
+  gdouble  matrixsum = 0.0;
+  gdouble  weighted_divisor, mult_alpha;
+  
   /*  If the mode is NEGATIVE_CONVOL, the offset should be 128  */
   if (mode == GIMP_NEGATIVE_CONVOL)
     {
@@ -2394,11 +2398,26 @@ convolve_region (PixelRegion            
 
   /*  Initialize some values  */
   bytes = srcR->bytes;
+  a_byte = bytes - 1;
   length = bytes * srcR->w;
   margin = size / 2;
   src = srcR->data;
   dest = destR->data;
 
+  if (alpha_weighting)
+    {
+      m = matrix;
+      i = size;
+      while (i --)
+        {
+          j = size;
+          while (j --)
+            matrixsum += *m++;
+        }
+      if (matrixsum == 0.0)
+        matrixsum = 1.0;
+    } 
+
   /*  calculate the source wraparound value  */
   wraparound = srcR->rowstride - size * bytes;
 
@@ -2411,7 +2430,7 @@ convolve_region (PixelRegion            
     }
 
   src = srcR->data;
-
+  
   for (y = margin; y < srcR->h - margin; y++)
     {
       s_row = src;
@@ -2425,42 +2444,103 @@ convolve_region (PixelRegion            
 
       /* now, handle the center pixels */
       x = srcR->w - margin*2;
-      while (x--)
-        {
-          s = s_row;
 
-          m = matrix;
-          total [0] = total [1] = total [2] = total [3] = 0;
-          i = size;
-          while (i --)
-            {
-              j = size;
-              while (j --)
-                {
-                  for (b = 0; b < bytes; b++)
-                    total [b] += *m * *s++;
-                  m ++;
-                }
+      if (alpha_weighting)
+        while (x--)
+          {
+            s = s_row;
 
-              s += wraparound;
-            }
+            m = matrix;
+            total [0] = total [1] = total [2] = total [3] = 0.0;
+            weighted_divisor = 0.0;
+              
+            i = size;
+            while (i --)
+              {
+                j = size;
+                while (j --)
+                  {
+                    alpha = s [a_byte];
 
-          for (b = 0; b < bytes; b++)
-            {
-              total [b] = total [b] / divisor + offset;
+                    if (alpha && *m)
+                      {
+                        mult_alpha = *m * alpha;
+                        weighted_divisor += mult_alpha;
 
-              if (total [b] < 0 && mode != GIMP_NORMAL_CONVOL)
-                total [b] = - total [b];
+                        for (b = 0; b < a_byte; b++)
+                          total [b] += mult_alpha * *s++;
+                        total [a_byte] += *m * *s++;
+                      }
+                    else
+                      s += bytes;
+                      
+                    m ++;
+                  }
 
-              if (total [b] < 0)
-                *d++ = 0;
-              else
-                *d++ = (total [b] > 255) ? 255 : (guchar) total [b];
-            }
+                s += wraparound;
+              }
 
-          s_row += bytes;
+            if (weighted_divisor == 0.0)
+              weighted_divisor = 1.0;
 
-        }
+            for (b = 0; b < bytes; b++)
+              {
+                total [b] /= divisor;
+                if (b != a_byte)
+                  total [b] = total [b] * matrixsum / weighted_divisor;
+                total [b] += offset;
+
+                if (total [b] < 0.0 && mode != GIMP_NORMAL_CONVOL)
+                  total [b] = - total [b];
+
+                if (total [b] < 0)
+                  *d++ = 0;
+                else
+                  *d++ = (total [b] > 255.0) ? 255 : (guchar) total [b];
+              }
+
+            s_row += bytes;
+          }
+      else
+        while (x--)
+          {
+            s = s_row;
+
+            m = matrix;
+            total [0] = total [1] = total [2] = total [3] = 0.0;
+
+            i = size;
+            while (i --)
+              {
+                j = size;
+                while (j --)
+                  {
+                    if (*m)
+                      for (b = 0; b < bytes; b++)
+                        total [b] += *m * *s++;
+                    else
+                      s += bytes;
+                    m ++;
+                  }
+
+                s += wraparound;
+              }
+
+            for (b = 0; b < bytes; b++)
+              {
+                total [b] = total [b] / divisor + offset;
+
+                if (total [b] < 0.0 && mode != GIMP_NORMAL_CONVOL)
+                  total [b] = - total [b];
+
+                if (total [b] < 0.0)
+                  *d++ = 0.0;
+                else
+                  *d++ = (total [b] > 255.0) ? 255 : (guchar) total [b];
+              }
+
+            s_row += bytes;
+          }
 
       /* handle the last pixel... */
       s = s_row + (srcR->rowstride + bytes) * margin;
Index: gimp/app/paint-funcs/paint-funcs.h
===================================================================
RCS file: /cvs/gnome/gimp/app/paint-funcs/paint-funcs.h,v
retrieving revision 1.43
diff -u -p -r1.43 paint-funcs.h
--- a/gimp/app/paint-funcs/paint-funcs.h	15 Apr 2004 12:38:54 -0000	1.43
+++ b/gimp/app/paint-funcs/paint-funcs.h	31 May 2004 08:04:38 -0000
@@ -349,10 +349,11 @@ void  extract_from_region               
 
 void  convolve_region                     (PixelRegion         *srcR,
                                            PixelRegion         *destR,
-                                           gint                *matrix,
+                                           gfloat              *matrix,
                                            gint                 size,
-                                           gint                 divisor,
-                                           GimpConvolutionType  mode);
+                                           gdouble              divisor,
+                                           GimpConvolutionType  mode,
+                                           gboolean             alpha_weighting);
 
 void  multiply_alpha_region               (PixelRegion *srcR);
 
Index: gimp/app/paint/gimpconvolve.c
===================================================================
RCS file: /cvs/gnome/gimp/app/paint/gimpconvolve.c,v
retrieving revision 1.93
diff -u -p -r1.93 gimpconvolve.c
--- a/gimp/app/paint/gimpconvolve.c	26 May 2004 16:13:53 -0000	1.93
+++ b/gimp/app/paint/gimpconvolve.c	31 May 2004 08:04:38 -0000
@@ -55,35 +55,31 @@ typedef enum
 } ConvolveClipType;
 
 
-static void   gimp_convolve_class_init       (GimpConvolveClass   *klass);
-static void   gimp_convolve_init             (GimpConvolve        *convolve);
+static void    gimp_convolve_class_init       (GimpConvolveClass   *klass);
+static void    gimp_convolve_init             (GimpConvolve        *convolve);
 
-static void   gimp_convolve_paint            (GimpPaintCore       *paint_core,
-                                              GimpDrawable        *drawable,
-                                              GimpPaintOptions    *paint_options,
-                                              GimpPaintCoreState   paint_state,
-                                              guint32              time);
-static void   gimp_convolve_motion           (GimpPaintCore       *paint_core,
-                                              GimpDrawable        *drawable,
-                                              GimpPaintOptions    *paint_options);
-
-static void   gimp_convolve_calculate_matrix (GimpConvolveType     type,
-                                              gdouble              rate);
-static void   gimp_convolve_integer_matrix   (const gfloat        *source,
-                                              gint                *dest,
-                                              gint                 size);
-static void   gimp_convolve_copy_matrix      (const gfloat        *src,
-                                              gfloat              *dest,
-                                              gint                 size);
-static gint   gimp_convolve_sum_matrix       (const gint          *matrix,
-                                              gint                 size);
-
-
-static gint matrix[25];
-static gint matrix_size;
-static gint matrix_divisor;
+static void    gimp_convolve_paint            (GimpPaintCore       *paint_core,
+                                               GimpDrawable        *drawable,
+                                               GimpPaintOptions    *paint_options,
+                                               GimpPaintCoreState   paint_state,
+                                               guint32              time);
+static void    gimp_convolve_motion           (GimpPaintCore       *paint_core,
+                                               GimpDrawable        *drawable,
+                                               GimpPaintOptions    *paint_options);
+
+static void    gimp_convolve_calculate_matrix (GimpConvolveType     type,
+                                               gdouble              rate);
+static void    gimp_convolve_copy_matrix      (const gfloat        *src,
+                                               gfloat              *dest,
+                                               gint                 size);
+static gdouble gimp_convolve_sum_matrix       (const gfloat        *matrix,
+                                               gint                 size);
 
-static gfloat custom_matrix[25] =
+
+static gint    matrix_size;
+static gdouble matrix_divisor;
+
+static gfloat matrix[25] =
 {
   0, 0, 0, 0, 0,
   0, 0, 0, 0, 0,
@@ -331,7 +327,7 @@ gimp_convolve_motion (GimpPaintCore    *
       tempPR.data = temp_data;
 
       convolve_region (&tempPR, &destPR, matrix, matrix_size,
-                       matrix_divisor, GIMP_NORMAL_CONVOL);
+                       matrix_divisor, GIMP_NORMAL_CONVOL, TRUE);
 
       /*  Free the allocated temp space  */
       g_free (temp_data);
@@ -409,7 +405,7 @@ gimp_convolve_motion (GimpPaintCore    *
       ovrsz1PR.data = ovrsz1_data;
 
       convolve_region (&ovrsz1PR, &ovrsz2PR, matrix, matrix_size,
-                       matrix_divisor, GIMP_NORMAL_CONVOL);
+                       matrix_divisor, GIMP_NORMAL_CONVOL, TRUE);
 
       /* Crop and copy to destination */
 
@@ -439,7 +435,7 @@ static void
 gimp_convolve_calculate_matrix (GimpConvolveType type,
                                 gdouble          rate)
 {
-  gfloat percent;
+  gdouble percent;
 
   /*  find percent of tool pressure  */
   percent = MIN (rate / 100.0, 1.0);
@@ -450,13 +446,13 @@ gimp_convolve_calculate_matrix (GimpConv
     case GIMP_BLUR_CONVOLVE:
       matrix_size = 5;
       blur_matrix[12] = MIN_BLUR + percent * (MAX_BLUR - MIN_BLUR);
-      gimp_convolve_copy_matrix (blur_matrix, custom_matrix, matrix_size);
+      gimp_convolve_copy_matrix (blur_matrix, matrix, matrix_size);
       break;
 
     case GIMP_SHARPEN_CONVOLVE:
       matrix_size = 5;
       sharpen_matrix[12] = MIN_SHARPEN + percent * (MAX_SHARPEN - MIN_SHARPEN);
-      gimp_convolve_copy_matrix (sharpen_matrix, custom_matrix, matrix_size);
+      gimp_convolve_copy_matrix (sharpen_matrix, matrix, matrix_size);
       break;
 
     case GIMP_CUSTOM_CONVOLVE:
@@ -464,24 +460,10 @@ gimp_convolve_calculate_matrix (GimpConv
       break;
     }
 
-  gimp_convolve_integer_matrix (custom_matrix, matrix, matrix_size);
   matrix_divisor = gimp_convolve_sum_matrix (matrix, matrix_size);
 
   if (!matrix_divisor)
-    matrix_divisor = 1;
-}
-
-static void
-gimp_convolve_integer_matrix (const gfloat *source,
-                              gint         *dest,
-                              gint          size)
-{
-  gint i;
-
-#define PRECISION  10000
-
-  for (i = 0; i < size*size; i++)
-    *dest++ = (gint) (*source ++ * PRECISION);
+    matrix_divisor = 1.0;
 }
 
 static void
@@ -489,20 +471,18 @@ gimp_convolve_copy_matrix (const gfloat 
                            gfloat       *dest,
                            gint          size)
 {
-  gint i;
-
-  for (i = 0; i < size*size; i++)
+  size *= size;
+  while (size --)
     *dest++ = *src++;
 }
 
-static gint
-gimp_convolve_sum_matrix (const gint *matrix,
-                          gint        size)
+static gdouble
+gimp_convolve_sum_matrix (const gfloat *matrix,
+                          gint          size)
 {
-  gint sum = 0;
+  gdouble sum = 0.0;
 
   size *= size;
-
   while (size --)
     sum += *matrix++;
 
Index: gimp/app/tools/gimpiscissorstool.c
===================================================================
RCS file: /cvs/gnome/gimp/app/tools/gimpiscissorstool.c,v
retrieving revision 1.139
diff -u -p -r1.139 gimpiscissorstool.c
--- a/gimp/app/tools/gimpiscissorstool.c	29 Apr 2004 13:19:27 -0000	1.139
+++ b/gimp/app/tools/gimpiscissorstool.c	31 May 2004 08:04:38 -0000
@@ -234,21 +234,21 @@ static guchar  maxgrad_conv1[TILE_WIDTH 
 static guchar  maxgrad_conv2[TILE_WIDTH * TILE_HEIGHT * 4] = "";
 
 
-static gint horz_deriv[9] =
+static gfloat horz_deriv[9] =
 {
   1, 0, -1,
   2, 0, -2,
   1, 0, -1,
 };
 
-static gint vert_deriv[9] =
+static gfloat vert_deriv[9] =
 {
   1, 2, 1,
   0, 0, 0,
   -1, -2, -1,
 };
 
-static gint blur_32[9] =
+static gfloat blur_32[9] =
 {
   1, 1, 1,
   1, 24, 1,
@@ -1767,7 +1767,7 @@ gradmap_tile_validate (TileManager *tm,
   /*  Blur the source to get rid of noise  */
   destPR.rowstride = TILE_WIDTH * 4;
   destPR.data      = maxgrad_conv0;
-  convolve_region (&srcPR, &destPR, blur_32, 3, 32, GIMP_NORMAL_CONVOL);
+  convolve_region (&srcPR, &destPR, blur_32, 3, 32, GIMP_NORMAL_CONVOL, FALSE);
 
   /*  Set the "src" temp buf up as the new source Pixel Region  */
   srcPR.rowstride = destPR.rowstride;
@@ -1775,11 +1775,13 @@ gradmap_tile_validate (TileManager *tm,
 
   /*  Get the horizontal derivative  */
   destPR.data = maxgrad_conv1;
-  convolve_region (&srcPR, &destPR, horz_deriv, 3, 1, GIMP_NEGATIVE_CONVOL);
+  convolve_region (&srcPR, &destPR, horz_deriv, 3, 1, GIMP_NEGATIVE_CONVOL,
+                   FALSE);
 
   /*  Get the vertical derivative  */
   destPR.data = maxgrad_conv2;
-  convolve_region (&srcPR, &destPR, vert_deriv, 3, 1, GIMP_NEGATIVE_CONVOL);
+  convolve_region (&srcPR, &destPR, vert_deriv, 3, 1, GIMP_NEGATIVE_CONVOL,
+                   FALSE);
 
   /* calculate overall gradient */
   tiledata = tile_data_pointer (tile, 0, 0);
