]> granicus.if.org Git - imagemagick/commitdiff
Sync cache pixels before OpenMP loop (possible optimization)
authorCristy <urban-warrior@imagemagick.org>
Tue, 7 Jun 2016 13:15:26 +0000 (09:15 -0400)
committerCristy <urban-warrior@imagemagick.org>
Tue, 7 Jun 2016 13:15:26 +0000 (09:15 -0400)
MagickCore/annotate.c
MagickCore/draw.c
MagickCore/effect.c
MagickCore/shear.c

index 3f42b2791569778da7b70dae293820d8607ed3f0..da73df7f03f8b5e511c8decdc516c297666a56fc 100644 (file)
@@ -46,6 +46,7 @@
 #include "MagickCore/annotate.h"
 #include "MagickCore/annotate-private.h"
 #include "MagickCore/attribute.h"
+#include "MagickCore/cache-private.h"
 #include "MagickCore/cache-view.h"
 #include "MagickCore/channel.h"
 #include "MagickCore/client.h"
@@ -1482,8 +1483,10 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
   if (annotate_info->dash_pattern != (double *) NULL)
     annotate_info->dash_pattern[0]=0.0;
   (void) CloneString(&annotate_info->primitive,"path '");
+  status=MagickTrue;
   if (draw_info->render != MagickFalse)
     {
+      status=SyncImagePixelCache(image,exception);
       if (image->storage_class != DirectClass)
         (void) SetImageStorageClass(image,DirectClass,exception);
       if (image->alpha_trait == UndefinedPixelTrait)
@@ -1503,7 +1506,6 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
       if (utf8 != (unsigned char *) NULL)
         p=(char *) utf8;
     }
-  status=MagickTrue;
   grapheme=(GraphemeInfo *) NULL;
   length=ComplexTextLayout(image,draw_info,p,strlen(p),face,flags,&grapheme,
     exception);
index 4feece41ca9b331872e940732656762c8b6e01a0..da157f32b15835311fb5f6387de35c34ab39905f 100644 (file)
@@ -50,6 +50,7 @@
 #include "MagickCore/artifact.h"
 #include "MagickCore/blob.h"
 #include "MagickCore/cache.h"
+#include "MagickCore/cache-private.h"
 #include "MagickCore/cache-view.h"
 #include "MagickCore/channel.h"
 #include "MagickCore/color.h"
@@ -4315,6 +4316,8 @@ MagickExport MagickBooleanType DrawPrimitive(Image *image,
         draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy,
         draw_info->affine.tx,draw_info->affine.ty);
     }
+  if (SyncImagePixelCache(image,exception) == MagickFalse)
+    return(MagickFalse);
   if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
       ((IsPixelInfoGray(&draw_info->fill) == MagickFalse) ||
        (IsPixelInfoGray(&draw_info->stroke) == MagickFalse)))
index 4d467742f7150c7be5c7e4fb80bfbd34181cb1f8..924c47eed3d5c1120b5403825ddaa1ec1fc01f87 100644 (file)
@@ -1635,7 +1635,7 @@ MagickExport Image *KuwaharaImage(const Image *image,const double radius,
     kuwahara_image=DestroyImage(kuwahara_image);
   return(kuwahara_image);
 }
-
+\f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %                                                                             %
@@ -1655,7 +1655,7 @@ MagickExport Image *KuwaharaImage(const Image *image,const double radius,
 %  The format of the LocalContrastImage method is:
 %
 %      Image *LocalContrastImage(const Image *image, const double radius,
-%        const double strength, ExceptionInfo *exception)
+%        const double strength,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -1692,7 +1692,6 @@ MagickExport Image *LocalContrastImage(const Image *image,const double radius,
 
   ssize_t
     scanLineSize,
-    thread_count,
     width;
 
   /*
@@ -1717,20 +1716,10 @@ MagickExport Image *LocalContrastImage(const Image *image,const double radius,
     }
   image_view=AcquireVirtualCacheView(image,exception);
   contrast_view=AcquireAuthenticCacheView(contrast_image,exception);
-  thread_count=1;
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel magick_threads(image,image,image->rows,1)
-  {
-    #pragma omp single
-    {
-      thread_count=omp_get_num_threads();
-    }
-  }
-#endif
   scanLineSize=(ssize_t) MagickMax(image->columns,image->rows);
   width=(ssize_t) scanLineSize*0.002f*fabs(radius);
   scanLineSize+=(2*width);
-  scanLinePixels_info=AcquireVirtualMemory((size_t) thread_count*
+  scanLinePixels_info=AcquireVirtualMemory((size_t) GetOpenMPMaximumThreads()*
     scanLineSize,sizeof(*scanLinePixels));
   if (scanLinePixels_info == (MemoryInfo *) NULL)
     {
@@ -1740,7 +1729,9 @@ MagickExport Image *LocalContrastImage(const Image *image,const double radius,
       ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
     }
   scanLinePixels=(float *) GetVirtualMemoryBlob(scanLinePixels_info);
-  /* Create intermediate buffer */
+  /*
+    Create intermediate buffer.
+  */
   interImage_info=AcquireVirtualMemory(image->rows*(image->columns+(2*width)),
     sizeof(*interImage));
   if (interImage_info == (MemoryInfo *) NULL)
@@ -1753,8 +1744,9 @@ MagickExport Image *LocalContrastImage(const Image *image,const double radius,
     }
   interImage=(float *) GetVirtualMemoryBlob(interImage_info);
   totalWeight=(float) ((width+1)*(width+1));
-
-  /* Vertical Pass */
+  /*
+    Vertical pass.
+  */
   {
     ssize_t
       x;
@@ -1765,6 +1757,9 @@ MagickExport Image *LocalContrastImage(const Image *image,const double radius,
 #endif
     for (x=0; x < (ssize_t) image->columns; x++)
     {
+      const int
+        id = GetOpenMPThreadId();
+
       const Quantum
         *magick_restrict p;
 
@@ -1780,22 +1775,17 @@ MagickExport Image *LocalContrastImage(const Image *image,const double radius,
         i;
 
       pixels=scanLinePixels;
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-      pixels+=scanLineSize*omp_get_thread_num();
-#endif
+      pixels+=id*scanLineSize;
       pix=pixels;
       p=GetCacheViewVirtualPixels(image_view,x,-width,1,image->rows+(2*width),
         exception);
-
       for (y=0; y < (ssize_t) image->rows+(2*width); y++)
       {
         *pix++=(float)GetPixelLuma(image,p);
         p+=image->number_channels;
       }
-
       out=interImage+x+width;
-
-      for (y = 0; y < (ssize_t) image->rows; y++)
+      for (y=0; y < (ssize_t) image->rows; y++)
       {
         float
           sum,
@@ -1822,12 +1812,13 @@ MagickExport Image *LocalContrastImage(const Image *image,const double radius,
         if ((x > (ssize_t) image->columns-width-2) &&
             (x != (ssize_t) image->columns-1))
           *(out+((image->columns-x-1)*2))=*out;
-
         out+=image->columns+(width*2);
       }
     }
   }
-  /* Horizontal Pass */
+  /*
+    Horizontal pass.
+  */
   {
     ssize_t
       y;
@@ -1838,6 +1829,9 @@ MagickExport Image *LocalContrastImage(const Image *image,const double radius,
 #endif
     for (y=0; y < (ssize_t) image->rows; y++)
     {
+      const int
+        id = GetOpenMPThreadId();
+
       const Quantum
         *magick_restrict p;
 
@@ -1855,17 +1849,13 @@ MagickExport Image *LocalContrastImage(const Image *image,const double radius,
         i;
 
       pixels=scanLinePixels;
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-      pixels+=scanLineSize*omp_get_thread_num();
-#endif
+      pixels+=id*scanLineSize;
       p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,
         exception);
       q=GetCacheViewAuthenticPixels(contrast_view,0,y,image->columns,1,
         exception);
-
       memcpy(pixels,interImage+(y*(image->columns+(2*width))),(image->columns+
         (2*width))*sizeof(float));
-
       for (x=0; x < (ssize_t) image->columns; x++)
       {
         float
@@ -1887,7 +1877,6 @@ MagickExport Image *LocalContrastImage(const Image *image,const double radius,
           sum+=weight*(*pix++);
           weight-=1.0f;
         }
-
         /* Apply and write */
         srcVal=(float) GetPixelLuma(image,p);
         mult=(srcVal-(sum/totalWeight))*(strength/100.0f);
index 9b96881cff63cb347409f05152079d2100140f19..0d5c19e6f23f45d0b5f944c4a0981c4bac36f1a9 100644 (file)
@@ -745,6 +745,8 @@ MagickExport Image *IntegralRotateImage(const Image *image,size_t rotations,
       exception);
   if (rotate_image == (Image *) NULL)
     return((Image *) NULL);
+  if (SyncImagePixelCache(rotate_image,exception) == MagickFalse)
+    return(DestroyImage(rotate_image));
   /*
     Integral rotate the image.
   */