revert the precalculation of the sum of the coefficients - it
authorTony Cook <tony@develop=help.com>
Mon, 31 Jan 2005 09:07:58 +0000 (09:07 +0000)
committerTony Cook <tony@develop=help.com>
Mon, 31 Jan 2005 09:07:58 +0000 (09:07 +0000)
was incorrect

Changes
conv.c

diff --git a/Changes b/Changes
index c5160da91361ca813b422547ad47b6e26c8a79ba..6e2ae5da181fda40f52d000221da6777cef6b7aa 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1004,8 +1004,6 @@ Revision history for Perl extension Imager.
   directories and to enable/disable drivers.
 - added simple examples to most of the filters documented in 
   Imager::Filters
-- calculate the sum of the coefficients once rather than for every
-  pixel in i_conv() (convolution filter)
 - explicitly document there are no PNG specific tags.
 - more examples in Imager::Draw
 - minor cleanup of Imager::Fill
diff --git a/conv.c b/conv.c
index 6f7bd59061aeff46f2d09ebdcc56d4ea6485117b..7e8513d0b8d2555f02e2609429559cdf358b25e2 100644 (file)
--- a/conv.c
+++ b/conv.c
@@ -25,18 +25,17 @@ i_conv(i_img *im,float *coeff,int len) {
 
   center=(len-1)/2;
 
-  pc = 0.0;
-  for (c = 0; c < len; ++c) {
-    pc += coeff[c];
-  }
-
+  /* don't move the calculation of pc up here, it depends on which pixels
+     are readable */
   for(l=0;l<im->ysize;l++) {
     for(i=0;i<im->xsize;i++) {
+      pc=0.0;
       for(ch=0;ch<im->channels;ch++) res[ch]=0;
       for(c=0;c<len;c++)
        if (i_gpix(im,i+c-center,l,&rcolor)!=-1) {
          for(ch=0;ch<im->channels;ch++) 
             res[ch]+=(float)(rcolor.channel[ch])*coeff[c];
+         pc+=coeff[c];
        }
       for(ch=0;ch<im->channels;ch++) {
         double temp = res[ch]/pc;
@@ -51,12 +50,14 @@ i_conv(i_img *im,float *coeff,int len) {
     {
       for(i=0;i<im->ysize;i++)
        {
+         pc=0.0;
          for(ch=0;ch<im->channels;ch++) res[ch]=0;
          for(c=0;c<len;c++)
            if (i_gpix(&timg,l,i+c-center,&rcolor)!=-1)
              {
                for(ch=0;ch<im->channels;ch++) 
                   res[ch]+=(float)(rcolor.channel[ch])*coeff[c];
+               pc+=coeff[c];
              }
          for(ch=0;ch<im->channels;ch++) {
             double temp = res[ch]/pc;