]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Wed, 17 Sep 2014 00:19:15 +0000 (00:19 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Wed, 17 Sep 2014 00:19:15 +0000 (00:19 +0000)
MagickCore/morphology.c

index 8f6c2707a7ca800476ee56055e452836dd657b42..b25623540c06a062043e68d9c9c2ffb056e6e84b 100644 (file)
@@ -2672,38 +2672,66 @@ static ssize_t MorphologyPrimitive(const Image *image,Image *morphology_image,
         center=(ssize_t) GetPixelChannels(image)*offset.y;
         for (y=0; y < (ssize_t) image->rows; y++)
         {
-          register ssize_t
-            i;
-
-          for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
-          {
-            double
-              alpha,
-              gamma,
-              pixel;
+          double
+            alpha,
+            gamma[MaxPixelChannels],
+            pixel[MaxPixelChannels];
 
-            PixelChannel
-              channel;
+          PixelChannel
+            channel;
 
-            PixelTrait
-              morphology_traits,
-              traits;
+          PixelTrait
+            morphology_traits,
+            traits;
 
-            register const MagickRealType
-              *restrict k;
+          register const MagickRealType
+            *restrict k;
 
-            register const Quantum
-              *restrict pixels;
+          register const Quantum
+            *restrict pixels;
 
-            register ssize_t
-              u;
+          register ssize_t
+            i,
+            u;
 
-            size_t
-              count;
+          size_t
+            count[MaxPixelChannels];
 
-            ssize_t
-              v;
+          ssize_t
+            v;
 
+          k=(&kernel->values[kernel->width*kernel->height-1]);
+          pixels=p;
+          alpha=1.0;
+          for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+          {
+            pixel[i]=bias;
+            gamma[i]=0.0;
+            count[i]=0;
+          }
+          for (v=0; v < (ssize_t) kernel->height; v++)
+          {
+            for (u=0; u < (ssize_t) kernel->width; u++)
+            {
+              for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+                if (IfNaN(*k) == MagickFalse)
+                  {
+                    channel=GetPixelChannelChannel(image,i);
+                    traits=GetPixelChannelTraits(image,channel);
+                    morphology_traits=GetPixelChannelTraits(morphology_image,
+                      channel);
+                    if ((morphology_traits & BlendPixelTrait) != 0)
+                      alpha=(double) (QuantumScale*GetPixelAlpha(image,pixels));
+                    pixel[i]+=(*k)*alpha*pixels[i];
+                    gamma[i]+=(*k)*alpha;
+                    count[i]++;
+                  }
+              k--;
+              pixels+=GetPixelChannels(image);
+            }
+          }
+          for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+          {
             channel=GetPixelChannelChannel(image,i);
             traits=GetPixelChannelTraits(image,channel);
             morphology_traits=GetPixelChannelTraits(morphology_image,channel);
@@ -2715,57 +2743,13 @@ static ssize_t MorphologyPrimitive(const Image *image,Image *morphology_image,
                 SetPixelChannel(morphology_image,channel,p[center+i],q);
                 continue;
               }
-            k=(&kernel->values[kernel->width*kernel->height-1]);
-            pixels=p;
-            pixel=bias;
-            if ((morphology_traits & BlendPixelTrait) == 0)
-              {
-                /*
-                  No alpha blending.
-                */
-                for (v=0; v < (ssize_t) kernel->height; v++)
-                {
-                  for (u=0; u < (ssize_t) kernel->width; u++)
-                  {
-                    if (IfNaN(*k) == MagickFalse)
-                      pixel+=(*k)*pixels[i];
-                    k--;
-                    pixels+=GetPixelChannels(image);
-                  }
-                }
-                if (fabs(pixel-p[center+i]) > MagickEpsilon)
-                  changes[id]++;
-                SetPixelChannel(morphology_image,channel,ClampToQuantum(pixel),
-                  q);
-                continue;
-              }
-            /*
-              Alpha blending.
-            */
-            gamma=0.0;
-            count=0;
-            for (v=0; v < (ssize_t) kernel->height; v++)
-            {
-              for (u=0; u < (ssize_t) kernel->width; u++)
-              {
-                if (IfNaN(*k) == MagickFalse)
-                  {
-                    alpha=(double) (QuantumScale*GetPixelAlpha(image,pixels));
-                    pixel+=(*k)*alpha*pixels[i];
-                    gamma+=(*k)*alpha;
-                    count++;
-                  }
-                k--;
-                pixels+=GetPixelChannels(image);
-              }
-            }
-            if (fabs(pixel-p[center+i]) > MagickEpsilon)
+            if (fabs(pixel[i]-p[center+i]) > MagickEpsilon)
               changes[id]++;
-            gamma=PerceptibleReciprocal(gamma);
-            if (count != 0)
-              gamma*=(double) kernel->height*kernel->width/count;
-            SetPixelChannel(morphology_image,channel,ClampToQuantum(gamma*
-              pixel),q);
+            gamma[i]=PerceptibleReciprocal(gamma[i]);
+            if (count[i] != 0)
+              gamma[i]*=(double) kernel->height*kernel->width/count[i];
+            SetPixelChannel(morphology_image,channel,ClampToQuantum(gamma[i]*
+              pixel[i]),q);
           }
           p+=GetPixelChannels(image);
           q+=GetPixelChannels(morphology_image);
@@ -2924,36 +2908,17 @@ static ssize_t MorphologyPrimitive(const Image *image,Image *morphology_image,
                  http://www.cs.umd.edu/~djacobs/CMSC426/Convolution.pdf
             */
             k=(&kernel->values[kernel->width*kernel->height-1]);
-            if ((morphology_traits & BlendPixelTrait) == 0)
-              {
-                /*
-                  No alpha blending.
-                */
-                for (v=0; v < (ssize_t) kernel->height; v++)
-                {
-                  for (u=0; u < (ssize_t) kernel->width; u++)
-                  {
-                    if (IfNaN(*k) == MagickFalse)
-                      pixel+=(*k)*pixels[i];
-                    k--;
-                    pixels+=GetPixelChannels(image);
-                  }
-                  pixels+=(image->columns-1)*GetPixelChannels(image);
-                }
-                break;
-              }
-            /*
-              Alpha blending.
-            */
             count=0;
             gamma=0.0;
+            alpha=1.0;
             for (v=0; v < (ssize_t) kernel->height; v++)
             {
               for (u=0; u < (ssize_t) kernel->width; u++)
               {
                 if (IfNaN(*k) == MagickFalse)
                   {
-                    alpha=(double) (QuantumScale*GetPixelAlpha(image,pixels));
+                    if ((morphology_traits & BlendPixelTrait) == 0)
+                      alpha=(double) (QuantumScale*GetPixelAlpha(image,pixels));
                     pixel+=alpha*(*k)*pixels[i];
                     gamma+=alpha*(*k);
                     count++;