]> granicus.if.org Git - imagemagick/commitdiff
Optimize wavelet denoise algorithm
authorCristy <urban-warrior@imagemagick.org>
Tue, 1 Mar 2016 21:40:57 +0000 (16:40 -0500)
committerCristy <urban-warrior@imagemagick.org>
Tue, 1 Mar 2016 21:40:57 +0000 (16:40 -0500)
MagickCore/fx.c

index 3f7a1b182a7b930df83888d5d066aaf00af1b91e..ae47d3c0fb23e5b4cd676556482e61d729b2e525 100644 (file)
@@ -5765,7 +5765,7 @@ MagickExport Image *WaveImage(const Image *image,const double amplitude,
 */
 
 static inline void HatTransform(const float *magick_restrict pixels,
-  const size_t stride,const size_t size,const size_t scale,double *kernel)
+  const size_t stride,const size_t size,const size_t scale,float *kernel)
 {
   const float
     *restrict p = pixels,
@@ -5805,10 +5805,8 @@ MagickExport Image *WaveletDenoiseImage(const Image *image,
     *image_view,
     *noise_view;
 
-  double
-    *kernel;
-
   float
+    *kernel,
     *pixels;
 
   Image
@@ -5826,9 +5824,9 @@ MagickExport Image *WaveletDenoiseImage(const Image *image,
   ssize_t
     channel;
 
-  static const double
+  static const float
     noise_levels[]= {
-      0.8002, 0.2735, 0.1202, 0.0585, 0.0291, 0.0152, 0.0080, 0.0044 };
+      0.8002f, 0.2735f, 0.1202f, 0.0585f, 0.0291f, 0.0152f, 0.0080f, 0.0044f };
 
   /*
     Initialize noise image attributes.
@@ -5923,11 +5921,15 @@ MagickExport Image *WaveletDenoiseImage(const Image *image,
       double
         magnitude;
 
+      register float
+        *p,
+        *q;
+
       ssize_t
         x,
         y;
 
-      low_pass=(size_t) (((level & 1)+1)*number_pixels);
+      low_pass=(size_t) (number_pixels*((level & 0x01)+1));
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
       #pragma omp parallel for schedule(static,1) \
         magick_threads(image,image,image->rows,1)
@@ -5940,10 +5942,12 @@ MagickExport Image *WaveletDenoiseImage(const Image *image,
         register ssize_t
           x;
 
-        HatTransform(pixels+y*image->columns+high_pass,1,image->columns,
-          1UL << level,kernel+id*image->columns);
+        p=kernel+id*image->columns;
+        q=pixels+y*image->columns;
+        HatTransform(q+high_pass,1,image->columns,1UL << level,p);
+        q+=low_pass;
         for (x=0; x < (ssize_t) image->columns; x++)
-          pixels[y*image->columns+x+low_pass]=kernel[id*image->columns+x];
+          *q++=(*p++);
       }
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
       #pragma omp parallel for schedule(static,1) \
@@ -5957,10 +5961,14 @@ MagickExport Image *WaveletDenoiseImage(const Image *image,
         register ssize_t
           y;
 
-        HatTransform(pixels+x+low_pass,image->columns,image->rows,1UL << level,
-          kernel+id*image->rows);
+        p=kernel+id*image->rows;
+        q=pixels+x+low_pass;
+        HatTransform(q,image->columns,image->rows,1UL << level,p);
         for (y=0; y < (ssize_t) image->rows; y++)
-          pixels[y*image->columns+x+low_pass]=kernel[id*image->rows+y];
+        {
+          *q=(*p++);
+          q+=image->columns;
+        }
       }
       /*
         To threshold, each coefficient is compared to a threshold value and