]> granicus.if.org Git - imagemagick/blobdiff - magick/fourier.c
(no commit message)
[imagemagick] / magick / fourier.c
index c633e7452e628db66d8d406883244f6ec2fb8d64..855d5c37c1627b91f14a1fef9608092ce4baf5f5 100644 (file)
@@ -19,7 +19,7 @@
 %                                 July 2009                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
 #if defined(MAGICKCORE_FFTW_DELEGATE)
 #if defined(MAGICKCORE_HAVE_COMPLEX_H)
 #include <complex.h>
-#else
+#endif
+#include <fftw3.h>
+#if !defined(MAGICKCORE_HAVE_CABS)
 #define cabs(z)  (sqrt(z[0]*z[0]+z[1]*z[1]))
-#define carg(z)  (atan2(z[1],z[0]))
-#define creal(z)  (z[0])
+#endif
+#if !defined(MAGICKCORE_HAVE_CARG)
+#define carg(z)  (atan2(cimag(z),creal(z)))
+#endif
+#if !defined(MAGICKCORE_HAVE_CIMAG)
 #define cimag(z)  (z[1])
 #endif
-#include <fftw3.h>
+#if !defined(MAGICKCORE_HAVE_CREAL)
+#define creal(z)  (z[0])
+#endif
 #endif
 \f
 /*
@@ -118,26 +125,25 @@ typedef struct _FourierInfo
 
 #if defined(MAGICKCORE_FFTW_DELEGATE)
 
-static MagickBooleanType RollFourier(const size_t width,
-  const size_t height,const ssize_t x_offset,const ssize_t y_offset,
-  double *fourier)
+static MagickBooleanType RollFourier(const size_t width,const size_t height,
+  const ssize_t x_offset,const ssize_t y_offset,double *fourier)
 {
   double
     *roll;
 
+  register ssize_t
+    i,
+    x;
+
   ssize_t
     u,
     v,
     y;
 
-  register ssize_t
-    i,
-    x;
-
   /*
-    Move the zero frequency (DC) from (0,0) to (width/2,height/2).
+    Move zero frequency (DC, average color) from (0,0) to (width/2,height/2).
   */
-  roll=(double *) AcquireQuantumMemory((size_t) width,height*sizeof(*roll));
+  roll=(double *) AcquireQuantumMemory((size_t) height,width*sizeof(*roll));
   if (roll == (double *) NULL)
     return(MagickFalse);
   i=0L;
@@ -156,9 +162,9 @@ static MagickBooleanType RollFourier(const size_t width,
         u=((x+x_offset) > ((ssize_t) width-1L)) ? x+x_offset-(ssize_t) width :
           x+x_offset;
       roll[v*width+u]=fourier[i++];
-   }
+    }
   }
-  (void) CopyMagickMemory(fourier,roll,width*height*sizeof(*roll));
+  (void) CopyMagickMemory(fourier,roll,height*width*sizeof(*roll));
   roll=(double *) RelinquishMagickMemory(roll);
   return(MagickTrue);
 }
@@ -166,16 +172,16 @@ static MagickBooleanType RollFourier(const size_t width,
 static MagickBooleanType ForwardQuadrantSwap(const size_t width,
   const size_t height,double *source,double *destination)
 {
-  ssize_t
-    center,
-    y;
-
   MagickBooleanType
     status;
 
   register ssize_t
     x;
 
+  ssize_t
+    center,
+    y;
+
   /*
     Swap quadrants.
   */
@@ -194,15 +200,15 @@ static MagickBooleanType ForwardQuadrantSwap(const size_t width,
   return(MagickTrue);
 }
 
-static void CorrectPhaseLHS(const size_t width,
-  const size_t height,double *fourier)
+static void CorrectPhaseLHS(const size_t width,const size_t height,
+  double *fourier)
 {
-  ssize_t
-    y;
-
   register ssize_t
     x;
 
+  ssize_t
+    y;
+
   for (y=0L; y < (ssize_t) height; y++)
     for (x=0L; x < (ssize_t) (width/2L); x++)
       fourier[y*width+x]*=(-1.0);
@@ -223,10 +229,6 @@ static MagickBooleanType ForwardFourier(const FourierInfo *fourier_info,
     *magnitude_image,
     *phase_image;
 
-  ssize_t
-    i,
-    y;
-
   MagickBooleanType
     status;
 
@@ -239,6 +241,10 @@ static MagickBooleanType ForwardFourier(const FourierInfo *fourier_info,
   register PixelPacket
     *q;
 
+  ssize_t
+    i,
+    y;
+
   magnitude_image=GetFirstImageInList(image);
   phase_image=GetNextImageInList(image);
   if (phase_image == (Image *) NULL)
@@ -254,11 +260,11 @@ static MagickBooleanType ForwardFourier(const FourierInfo *fourier_info,
     fourier_info->height,fourier_info->width*sizeof(*magnitude_source));
   if (magnitude_source == (double *) NULL)
     return(MagickFalse);
-  (void) ResetMagickMemory(magnitude_source,0,fourier_info->width*
-    fourier_info->height*sizeof(*magnitude_source));
+  (void) ResetMagickMemory(magnitude_source,0,fourier_info->height*
+    fourier_info->width*sizeof(*magnitude_source));
   phase_source=(double *) AcquireQuantumMemory((size_t) fourier_info->height,
     fourier_info->width*sizeof(*phase_source));
-  if (magnitude_source == (double *) NULL)
+  if (phase_source == (double *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
         ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
@@ -299,34 +305,38 @@ static MagickBooleanType ForwardFourier(const FourierInfo *fourier_info,
         case RedChannel:
         default:
         {
-          q->red=ClampToQuantum(QuantumRange*magnitude_source[i]);
+          SetRedPixelComponent(q,ClampToQuantum(QuantumRange*
+            magnitude_source[i]));
           break;
         }
         case GreenChannel:
         {
-          q->green=ClampToQuantum(QuantumRange*magnitude_source[i]);
+          SetGreenPixelComponent(q,ClampToQuantum(QuantumRange*
+            magnitude_source[i]));
           break;
         }
         case BlueChannel:
         {
-          q->blue=ClampToQuantum(QuantumRange*magnitude_source[i]);
+          SetBluePixelComponent(q,ClampToQuantum(QuantumRange*
+            magnitude_source[i]));
           break;
         }
         case OpacityChannel:
         {
-          q->opacity=ClampToQuantum(QuantumRange*magnitude_source[i]);
+          SetOpacityPixelComponent(q,ClampToQuantum(QuantumRange*
+            magnitude_source[i]));
           break;
         }
         case IndexChannel:
         {
-          indexes[x]=ClampToQuantum(QuantumRange*magnitude_source[i]);
+          SetIndexPixelComponent(indexes+x,ClampToQuantum(QuantumRange*
+            magnitude_source[i]));
           break;
         }
         case GrayChannels:
         {
-          q->red=ClampToQuantum(QuantumRange*magnitude_source[i]);
-          q->green=q->red;
-          q->blue=q->red;
+          SetGrayPixelComponent(q,ClampToQuantum(QuantumRange*
+            magnitude_source[i]));
           break;
         }
       }
@@ -352,34 +362,37 @@ static MagickBooleanType ForwardFourier(const FourierInfo *fourier_info,
         case RedChannel:
         default:
         {
-          q->red=ClampToQuantum(QuantumRange*phase_source[i]);
+          SetRedPixelComponent(q,ClampToQuantum(QuantumRange*
+            phase_source[i]));
           break;
         }
         case GreenChannel:
         {
-          q->green=ClampToQuantum(QuantumRange*phase_source[i]);
+          SetGreenPixelComponent(q,ClampToQuantum(QuantumRange*
+            phase_source[i]));
           break;
         }
         case BlueChannel:
         {
-          q->blue=ClampToQuantum(QuantumRange*phase_source[i]);
+          SetBluePixelComponent(q,ClampToQuantum(QuantumRange*
+            phase_source[i]));
           break;
         }
         case OpacityChannel:
         {
-          q->opacity=ClampToQuantum(QuantumRange*phase_source[i]);
+          SetOpacityPixelComponent(q,ClampToQuantum(QuantumRange*
+            phase_source[i]));
           break;
         }
         case IndexChannel:
         {
-          indexes[x]=ClampToQuantum(QuantumRange*phase_source[i]);
+          SetIndexPixelComponent(indexes+x,ClampToQuantum(QuantumRange*
+            phase_source[i]));
           break;
         }
         case GrayChannels:
         {
-          q->red=ClampToQuantum(QuantumRange*phase_source[i]);
-          q->green=q->red;
-          q->blue=q->red;
+          SetGrayPixelComponent(q,ClampToQuantum(QuantumRange*phase_source[i]));
           break;
         }
       }
@@ -413,9 +426,6 @@ static MagickBooleanType ForwardFourierTransform(FourierInfo *fourier_info,
   fftw_plan
     fftw_r2c_plan;
 
-  ssize_t
-    y;
-
   register const IndexPacket
     *indexes;
 
@@ -426,6 +436,9 @@ static MagickBooleanType ForwardFourierTransform(FourierInfo *fourier_info,
     i,
     x;
 
+  ssize_t
+    y;
+
   /*
     Generate the forward Fourier transform.
   */
@@ -437,7 +450,7 @@ static MagickBooleanType ForwardFourierTransform(FourierInfo *fourier_info,
         ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
       return(MagickFalse);
     }
-  ResetMagickMemory(source,0,fourier_info->width*fourier_info->height*
+  ResetMagickMemory(source,0,fourier_info->height*fourier_info->width*
     sizeof(*source));
   i=0L;
   image_view=AcquireCacheView(image);
@@ -480,7 +493,7 @@ static MagickBooleanType ForwardFourierTransform(FourierInfo *fourier_info,
         }
         case GrayChannels:
         {
-          source[i]=QuantumScale*GetRedPixelComponent(p);
+          source[i]=QuantumScale*GetGrayPixelComponent(p);
           break;
         }
       }
@@ -489,7 +502,7 @@ static MagickBooleanType ForwardFourierTransform(FourierInfo *fourier_info,
     }
   }
   image_view=DestroyCacheView(image_view);
-  fourier=(fftw_complex *) AcquireAlignedMemory((size_t) fourier_info->height,
+  fourier=(fftw_complex *) AcquireQuantumMemory((size_t) fourier_info->height,
     fourier_info->center*sizeof(*fourier));
   if (fourier == (fftw_complex *) NULL)
     {
@@ -542,7 +555,7 @@ static MagickBooleanType ForwardFourierTransform(FourierInfo *fourier_info,
         phase[i]=cimag(fourier[i]);
         i++;
       }
-  fourier=(fftw_complex *) RelinquishAlignedMemory(fourier);
+  fourier=(fftw_complex *) RelinquishMagickMemory(fourier);
   return(MagickTrue);
 }
 
@@ -557,12 +570,12 @@ static MagickBooleanType ForwardFourierTransformChannel(const Image *image,
   fftw_complex
     *fourier;
 
-  MagickBooleanType
-    status;
-
   FourierInfo
     fourier_info;
 
+  MagickBooleanType
+    status;
+
   size_t
     extent;
 
@@ -594,7 +607,7 @@ static MagickBooleanType ForwardFourierTransformChannel(const Image *image,
       magnitude=(double *) RelinquishMagickMemory(magnitude);
       return(MagickFalse);
     }
-  fourier=(fftw_complex *) AcquireAlignedMemory((size_t) fourier_info.height,
+  fourier=(fftw_complex *) AcquireQuantumMemory((size_t) fourier_info.height,
     fourier_info.center*sizeof(*fourier));
   if (fourier == (fftw_complex *) NULL)
     {
@@ -608,7 +621,7 @@ static MagickBooleanType ForwardFourierTransformChannel(const Image *image,
   if (status != MagickFalse)
     status=ForwardFourier(&fourier_info,fourier_image,magnitude,phase,
       exception);
-  fourier=(fftw_complex *) RelinquishAlignedMemory(fourier);
+  fourier=(fftw_complex *) RelinquishMagickMemory(fourier);
   phase=(double *) RelinquishMagickMemory(phase);
   magnitude=(double *) RelinquishMagickMemory(magnitude);
   return(status);
@@ -660,9 +673,6 @@ MagickExport Image *ForwardFourierTransformImage(const Image *image,
               is_gray,
               status;
 
-            register ssize_t
-              i;
-
             phase_image->storage_class=DirectClass;
             phase_image->depth=32UL;
             AppendImageToList(&fourier_image,magnitude_image);
@@ -670,59 +680,81 @@ MagickExport Image *ForwardFourierTransformImage(const Image *image,
             status=MagickTrue;
             is_gray=IsGrayImage(image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4) shared(status)
+  #pragma omp parallel sections
 #endif
-            for (i=0L; i < 5L; i++)
             {
-              MagickBooleanType
-                thread_status;
-
-              thread_status=MagickTrue;
-              switch (i)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+              #pragma omp section
+#endif
+              {
+                MagickBooleanType
+                  thread_status;
+
+                if (is_gray != MagickFalse)
+                  thread_status=ForwardFourierTransformChannel(image,
+                    GrayChannels,modulus,fourier_image,exception);
+                else
+                  thread_status=ForwardFourierTransformChannel(image,
+                    RedChannel,modulus,fourier_image,exception);
+                if (thread_status == MagickFalse)
+                  status=thread_status;
+              }
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+              #pragma omp section
+#endif
+              {
+                MagickBooleanType
+                  thread_status;
+
+                thread_status=MagickTrue;
+                if (is_gray == MagickFalse)
+                  thread_status=ForwardFourierTransformChannel(image,
+                    GreenChannel,modulus,fourier_image,exception);
+                if (thread_status == MagickFalse)
+                  status=thread_status;
+              }
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+              #pragma omp section
+#endif
+              {
+                MagickBooleanType
+                  thread_status;
+
+                thread_status=MagickTrue;
+                if (is_gray == MagickFalse)
+                  thread_status=ForwardFourierTransformChannel(image,
+                    BlueChannel,modulus,fourier_image,exception);
+                if (thread_status == MagickFalse)
+                  status=thread_status;
+              }
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+              #pragma omp section
+#endif
+              {
+                MagickBooleanType
+                  thread_status;
+
+                thread_status=MagickTrue;
+                if (image->matte != MagickFalse)
+                  thread_status=ForwardFourierTransformChannel(image,
+                    OpacityChannel,modulus,fourier_image,exception);
+                if (thread_status == MagickFalse)
+                  status=thread_status;
+              }
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+              #pragma omp section
+#endif
               {
-                case 0:
-                {
-                  if (is_gray != MagickFalse)
-                    {
-                      thread_status=ForwardFourierTransformChannel(image,
-                        GrayChannels,modulus,fourier_image,exception);
-                      break;
-                    }
-                  thread_status=ForwardFourierTransformChannel(image,RedChannel,
-                    modulus,fourier_image,exception);
-                  break;
-                }
-                case 1:
-                {
-                  if (is_gray == MagickFalse)
-                    thread_status=ForwardFourierTransformChannel(image,
-                      GreenChannel,modulus,fourier_image,exception);
-                  break;
-                }
-                case 2:
-                {
-                  if (is_gray == MagickFalse)
-                    thread_status=ForwardFourierTransformChannel(image,
-                      BlueChannel,modulus,fourier_image,exception);
-                  break;
-                }
-                case 4:
-                {
-                  if (image->matte != MagickFalse)
-                    thread_status=ForwardFourierTransformChannel(image,
-                      OpacityChannel,modulus,fourier_image,exception);
-                  break;
-                }
-                case 5:
-                {
-                  if (image->colorspace == CMYKColorspace)
-                    thread_status=ForwardFourierTransformChannel(image,
-                      IndexChannel,modulus,fourier_image,exception);
-                  break;
-                }
+                MagickBooleanType
+                  thread_status;
+
+                thread_status=MagickTrue;
+                if (image->colorspace == CMYKColorspace)
+                  thread_status=ForwardFourierTransformChannel(image,
+                    IndexChannel,modulus,fourier_image,exception);
+                if (thread_status == MagickFalse)
+                  status=thread_status;
               }
-              if (thread_status == MagickFalse)
-                status=thread_status;
             }
             if (status == MagickFalse)
               fourier_image=DestroyImageList(fourier_image);
@@ -772,13 +804,13 @@ MagickExport Image *ForwardFourierTransformImage(const Image *image,
 static MagickBooleanType InverseQuadrantSwap(const size_t width,
   const size_t height,const double *source,double *destination)
 {
+  register ssize_t
+    x;
+
   ssize_t
     center,
     y;
 
-  register ssize_t
-    x;
-
   /*
     Swap quadrants.
   */
@@ -807,9 +839,6 @@ static MagickBooleanType InverseFourier(FourierInfo *fourier_info,
     *magnitude_source,
     *phase_source;
 
-  ssize_t
-    y;
-
   MagickBooleanType
     status;
 
@@ -823,6 +852,9 @@ static MagickBooleanType InverseFourier(FourierInfo *fourier_info,
     i,
     x;
 
+  ssize_t
+    y;
+
   /*
     Inverse fourier - read image and break down into a double array.
   */
@@ -836,7 +868,7 @@ static MagickBooleanType InverseFourier(FourierInfo *fourier_info,
       return(MagickFalse);
     }
   phase_source=(double *) AcquireQuantumMemory((size_t) fourier_info->height,
-    fourier_info->height*sizeof(*phase_source));
+    fourier_info->width*sizeof(*phase_source));
   if (phase_source == (double *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
@@ -886,7 +918,7 @@ static MagickBooleanType InverseFourier(FourierInfo *fourier_info,
         }
         case GrayChannels:
         {
-          magnitude_source[i]=QuantumScale*GetRedPixelComponent(p);
+          magnitude_source[i]=QuantumScale*GetGrayPixelComponent(p);
           break;
         }
       }
@@ -935,7 +967,7 @@ static MagickBooleanType InverseFourier(FourierInfo *fourier_info,
         }
         case GrayChannels:
         {
-          phase_source[i]=QuantumScale*GetRedPixelComponent(p);
+          phase_source[i]=QuantumScale*GetGrayPixelComponent(p);
           break;
         }
       }
@@ -970,8 +1002,8 @@ static MagickBooleanType InverseFourier(FourierInfo *fourier_info,
   status=InverseQuadrantSwap(fourier_info->width,fourier_info->height,
     magnitude_source,magnitude);
   magnitude_source=(double *) RelinquishMagickMemory(magnitude_source);
-  phase=(double *) AcquireQuantumMemory((size_t) fourier_info->width,
-    fourier_info->height*sizeof(*phase));
+  phase=(double *) AcquireQuantumMemory((size_t) fourier_info->height,
+    fourier_info->width*sizeof(*phase));
   if (phase == (double *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
@@ -1030,21 +1062,21 @@ static MagickBooleanType InverseFourierTransform(FourierInfo *fourier_info,
   fftw_plan
     fftw_c2r_plan;
 
-  ssize_t
-    y;
-
   register IndexPacket
     *indexes;
 
+  register PixelPacket
+    *q;
+
   register ssize_t
     i,
     x;
 
-  register PixelPacket
-    *q;
+  ssize_t
+    y;
 
-  source=(double *) AcquireQuantumMemory((size_t) fourier_info->width,
-    fourier_info->height*sizeof(double));
+  source=(double *) AcquireQuantumMemory((size_t) fourier_info->height,
+    fourier_info->width*sizeof(*source));
   if (source == (double *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
@@ -1064,8 +1096,10 @@ static MagickBooleanType InverseFourierTransform(FourierInfo *fourier_info,
   image_view=AcquireCacheView(image);
   for (y=0L; y < (ssize_t) fourier_info->height; y++)
   {
-    q=GetCacheViewAuthenticPixels(image_view,0L,y,fourier_info->width,1UL,
-      exception);
+    if (y >= (ssize_t) image->rows)
+      break;
+    q=GetCacheViewAuthenticPixels(image_view,0L,y,fourier_info->width >
+      image->columns ? image->columns : fourier_info->width,1UL,exception);
     if (q == (PixelPacket *) NULL)
       break;
     indexes=GetCacheViewAuthenticIndexQueue(image_view);
@@ -1076,34 +1110,33 @@ static MagickBooleanType InverseFourierTransform(FourierInfo *fourier_info,
         case RedChannel:
         default:
         {
-          q->red=ClampToQuantum(QuantumRange*source[i]);
+          SetRedPixelComponent(q,ClampToQuantum(QuantumRange*source[i]));
           break;
         }
         case GreenChannel:
         {
-          q->green=ClampToQuantum(QuantumRange*source[i]);
+          SetGreenPixelComponent(q,ClampToQuantum(QuantumRange*source[i]));
           break;
         }
         case BlueChannel:
         {
-          q->blue=ClampToQuantum(QuantumRange*source[i]);
+          SetBluePixelComponent(q,ClampToQuantum(QuantumRange*source[i]));
           break;
         }
         case OpacityChannel:
         {
-          q->opacity=ClampToQuantum(QuantumRange*source[i]);
+          SetOpacityPixelComponent(q,ClampToQuantum(QuantumRange*source[i]));
           break;
         }
         case IndexChannel:
         {
-          indexes[x]=ClampToQuantum(QuantumRange*source[i]);
+          SetIndexPixelComponent(indexes+x,ClampToQuantum(QuantumRange*
+            source[i]));
           break;
         }
         case GrayChannels:
         {
-          q->red=ClampToQuantum(QuantumRange*source[i]);
-          q->green=q->red;
-          q->blue=q->red;
+          SetGrayPixelComponent(q,ClampToQuantum(QuantumRange*source[i]));
           break;
         }
       }
@@ -1153,7 +1186,7 @@ static MagickBooleanType InverseFourierTransformChannel(
   fourier_info.channel=channel;
   fourier_info.modulus=modulus;
   magnitude=(double *) AcquireQuantumMemory((size_t) fourier_info.height,
-    fourier_info.center*sizeof(double));
+    fourier_info.center*sizeof(*magnitude));
   if (magnitude == (double *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
@@ -1162,7 +1195,7 @@ static MagickBooleanType InverseFourierTransformChannel(
       return(MagickFalse);
     }
   phase=(double *) AcquireQuantumMemory((size_t) fourier_info.height,
-    fourier_info.center*sizeof(double));
+    fourier_info.center*sizeof(*phase));
   if (phase == (double *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
@@ -1171,7 +1204,7 @@ static MagickBooleanType InverseFourierTransformChannel(
       magnitude=(double *) RelinquishMagickMemory(magnitude);
       return(MagickFalse);
     }
-  fourier=(fftw_complex *) AcquireAlignedMemory((size_t) fourier_info.height,
+  fourier=(fftw_complex *) AcquireQuantumMemory((size_t) fourier_info.height,
     fourier_info.center*sizeof(*fourier));
   if (fourier == (fftw_complex *) NULL)
     {
@@ -1187,7 +1220,7 @@ static MagickBooleanType InverseFourierTransformChannel(
   if (status != MagickFalse)
     status=InverseFourierTransform(&fourier_info,fourier,fourier_image,
       exception);
-  fourier=(fftw_complex *) RelinquishAlignedMemory(fourier);
+  fourier=(fftw_complex *) RelinquishMagickMemory(fourier);
   phase=(double *) RelinquishMagickMemory(phase);
   magnitude=(double *) RelinquishMagickMemory(magnitude);
   return(status);
@@ -1228,72 +1261,91 @@ MagickExport Image *InverseFourierTransformImage(const Image *magnitude_image,
           is_gray,
           status;
 
-        register ssize_t
-          i;
-
         status=MagickTrue;
         is_gray=IsGrayImage(magnitude_image,exception);
         if (is_gray != MagickFalse)
           is_gray=IsGrayImage(phase_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-        #pragma omp parallel for schedule(dynamic,4) shared(status)
+        #pragma omp parallel sections
 #endif
-        for (i=0L; i < 5L; i++)
         {
-          MagickBooleanType
-            thread_status;
-
-          thread_status=MagickTrue;
-          switch (i)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+          #pragma omp section
+#endif
           {
-            case 0:
-            {
-              if (is_gray != MagickFalse)
-                {
-                  thread_status=InverseFourierTransformChannel(magnitude_image,
-                    phase_image,GrayChannels,modulus,fourier_image,exception);
-                  break;
-                }
+            MagickBooleanType
+              thread_status;
+
+            if (is_gray != MagickFalse)
+              thread_status=InverseFourierTransformChannel(magnitude_image,
+                phase_image,GrayChannels,modulus,fourier_image,exception);
+            else
               thread_status=InverseFourierTransformChannel(magnitude_image,
                 phase_image,RedChannel,modulus,fourier_image,exception);
-              break;
-            }
-            case 1:
-            {
-              if (is_gray == MagickFalse)
-                thread_status=InverseFourierTransformChannel(magnitude_image,
-                  phase_image,GreenChannel,modulus,fourier_image,exception);
-              break;
-            }
-            case 2:
-            {
-              if (is_gray == MagickFalse)
-                thread_status=InverseFourierTransformChannel(magnitude_image,
-                  phase_image,BlueChannel,modulus,fourier_image,exception);
-              break;
-            }
-            case 3:
-            {
-              if (magnitude_image->matte != MagickFalse)
-                thread_status=InverseFourierTransformChannel(magnitude_image,
-                  phase_image,OpacityChannel,modulus,fourier_image,exception);
-              break;
-            }
-            case 4:
-            {
-              if (magnitude_image->colorspace == CMYKColorspace)
-                thread_status=InverseFourierTransformChannel(magnitude_image,
-                  phase_image,IndexChannel,modulus,fourier_image,exception);
-              break;
-            }
+            if (thread_status == MagickFalse)
+              status=thread_status;
+          }
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+          #pragma omp section
+#endif
+          {
+            MagickBooleanType
+              thread_status;
+
+            thread_status=MagickTrue;
+            if (is_gray == MagickFalse)
+              thread_status=InverseFourierTransformChannel(magnitude_image,
+                phase_image,GreenChannel,modulus,fourier_image,exception);
+            if (thread_status == MagickFalse)
+              status=thread_status;
+          }
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+          #pragma omp section
+#endif
+          {
+            MagickBooleanType
+              thread_status;
+
+            thread_status=MagickTrue;
+            if (is_gray == MagickFalse)
+              thread_status=InverseFourierTransformChannel(magnitude_image,
+                phase_image,BlueChannel,modulus,fourier_image,exception);
+            if (thread_status == MagickFalse)
+              status=thread_status;
+          }
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+          #pragma omp section
+#endif
+          {
+            MagickBooleanType
+              thread_status;
+
+            thread_status=MagickTrue;
+            if (magnitude_image->matte != MagickFalse)
+              thread_status=InverseFourierTransformChannel(magnitude_image,
+                phase_image,OpacityChannel,modulus,fourier_image,exception);
+            if (thread_status == MagickFalse)
+              status=thread_status;
+          }
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+          #pragma omp section
+#endif
+          {
+            MagickBooleanType
+              thread_status;
+
+            thread_status=MagickTrue;
+            if (magnitude_image->colorspace == CMYKColorspace)
+              thread_status=InverseFourierTransformChannel(magnitude_image,
+                phase_image,IndexChannel,modulus,fourier_image,exception);
+            if (thread_status == MagickFalse)
+              status=thread_status;
           }
-          if (thread_status == MagickFalse)
-            status=thread_status;
         }
         if (status == MagickFalse)
           fourier_image=DestroyImage(fourier_image);
       }
-      fftw_cleanup();
+    fftw_cleanup();
   }
 #endif
   return(fourier_image);