From: Cristy Date: Tue, 7 Jun 2016 13:15:26 +0000 (-0400) Subject: Sync cache pixels before OpenMP loop (possible optimization) X-Git-Tag: 7.0.1-10~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ba4ad2dfd3d5b883e8aa7d6e8b4e6f9613dc3c45;p=imagemagick Sync cache pixels before OpenMP loop (possible optimization) --- diff --git a/MagickCore/annotate.c b/MagickCore/annotate.c index 3f42b2791..da73df7f0 100644 --- a/MagickCore/annotate.c +++ b/MagickCore/annotate.c @@ -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); diff --git a/MagickCore/draw.c b/MagickCore/draw.c index 4feece41c..da157f32b 100644 --- a/MagickCore/draw.c +++ b/MagickCore/draw.c @@ -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))) diff --git a/MagickCore/effect.c b/MagickCore/effect.c index 4d467742f..924c47eed 100644 --- a/MagickCore/effect.c +++ b/MagickCore/effect.c @@ -1635,7 +1635,7 @@ MagickExport Image *KuwaharaImage(const Image *image,const double radius, kuwahara_image=DestroyImage(kuwahara_image); return(kuwahara_image); } - + /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % @@ -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); diff --git a/MagickCore/shear.c b/MagickCore/shear.c index 9b96881cf..0d5c19e6f 100644 --- a/MagickCore/shear.c +++ b/MagickCore/shear.c @@ -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. */