From 88d320ae7a9e656e09a7771dd0c4035731c007b7 Mon Sep 17 00:00:00 2001 From: Cristy Date: Sun, 31 Mar 2019 12:04:45 -0400 Subject: [PATCH] Pixel cache optimization --- ChangeLog | 4 +- MagickCore/cache-private.h | 3 ++ MagickCore/cache.c | 103 ++++++++++++++++++------------------- coders/msl.c | 4 +- coders/svg.c | 4 +- configure | 4 +- configure.ac | 2 +- 7 files changed, 59 insertions(+), 65 deletions(-) diff --git a/ChangeLog b/ChangeLog index 61149b05f..dc0b79184 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,5 @@ -2019-03-30 7.0.8-36 Cristy - * Release ImageMagick version 7.0.8-36, GIT revision 15457:ee5b9c56b:20190330 +2019-03-31 7.0.8-36 Cristy + * Release ImageMagick version 7.0.8-36, GIT revision 15459:7e69ae7e4:20190331 2019-03-27 7.0.8-36 Cristy * Fixed a number of issues (reference diff --git a/MagickCore/cache-private.h b/MagickCore/cache-private.h index 9c8215160..d82dee7a0 100644 --- a/MagickCore/cache-private.h +++ b/MagickCore/cache-private.h @@ -124,6 +124,9 @@ typedef struct _NexusInfo size_t signature; + + struct _NexusInfo + *pixel_nexus; } NexusInfo; typedef struct _CacheInfo diff --git a/MagickCore/cache.c b/MagickCore/cache.c index 366ea0ccf..858f0227b 100644 --- a/MagickCore/cache.c +++ b/MagickCore/cache.c @@ -264,17 +264,18 @@ MagickPrivate NexusInfo **AcquirePixelCacheNexus(const size_t number_threads) i; nexus_info=(NexusInfo **) MagickAssumeAligned(AcquireAlignedMemory( - number_threads,sizeof(*nexus_info))); + number_threads+1,sizeof(*nexus_info))); if (nexus_info == (NexusInfo **) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); - nexus_info[0]=(NexusInfo *) AcquireQuantumMemory(number_threads, + nexus_info[0]=(NexusInfo *) AcquireQuantumMemory(number_threads+1, sizeof(**nexus_info)); if (nexus_info[0] == (NexusInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); - (void) memset(nexus_info[0],0,number_threads*sizeof(**nexus_info)); - for (i=0; i < (ssize_t) number_threads; i++) + (void) memset(nexus_info[0],0,(number_threads+1)*sizeof(**nexus_info)); + for (i=0; i <= (ssize_t) number_threads; i++) { nexus_info[i]=(&nexus_info[0][i]); + nexus_info[i]->pixel_nexus=(&nexus_info[0][number_threads]); nexus_info[i]->signature=MagickCoreSignature; } return(nexus_info); @@ -417,9 +418,6 @@ static MagickBooleanType ClipPixelCacheNexus(Image *image, MagickSizeType number_pixels; - NexusInfo - **magick_restrict image_nexus; - register Quantum *magick_restrict p, *magick_restrict q; @@ -437,10 +435,9 @@ static MagickBooleanType ClipPixelCacheNexus(Image *image, cache_info=(CacheInfo *) image->cache; if (cache_info == (Cache) NULL) return(MagickFalse); - image_nexus=AcquirePixelCacheNexus(1); p=GetAuthenticPixelCacheNexus(image,nexus_info->region.x,nexus_info->region.y, - nexus_info->region.width,nexus_info->region.height,image_nexus[0], - exception); + nexus_info->region.width,nexus_info->region.height, + nexus_info->pixel_nexus,exception); q=nexus_info->pixels; number_pixels=(MagickSizeType) nexus_info->region.width* nexus_info->region.height; @@ -472,7 +469,6 @@ static MagickBooleanType ClipPixelCacheNexus(Image *image, p+=GetPixelChannels(image); q+=GetPixelChannels(image); } - image_nexus=DestroyPixelCacheNexus(image_nexus,1); if (n < (ssize_t) number_pixels) return(MagickFalse); return(MagickTrue); @@ -1107,7 +1103,7 @@ MagickPrivate NexusInfo **DestroyPixelCacheNexus(NexusInfo **nexus_info, i; assert(nexus_info != (NexusInfo **) NULL); - for (i=0; i < (ssize_t) number_threads; i++) + for (i=0; i <= (ssize_t) number_threads; i++) { if (nexus_info[i]->cache != (Quantum *) NULL) RelinquishCacheNexusPixels(nexus_info[i]); @@ -2714,9 +2710,6 @@ MagickPrivate const Quantum *GetVirtualPixelCacheNexus(const Image *image, length, number_pixels; - NexusInfo - **magick_restrict virtual_nexus; - Quantum *magick_restrict pixels, virtual_pixel[MaxPixelChannels]; @@ -2795,7 +2788,6 @@ MagickPrivate const Quantum *GetVirtualPixelCacheNexus(const Image *image, Pixel request is outside cache extents. */ s=(unsigned char *) nexus_info->metacontent; - virtual_nexus=AcquirePixelCacheNexus(1); (void) memset(virtual_pixel,0,cache_info->number_channels* sizeof(*virtual_pixel)); virtual_metacontent=(void *) NULL; @@ -2821,7 +2813,6 @@ MagickPrivate const Quantum *GetVirtualPixelCacheNexus(const Image *image, cache_info->metacontent_extent); if (virtual_metacontent == (void *) NULL) { - virtual_nexus=DestroyPixelCacheNexus(virtual_nexus,1); (void) ThrowMagickException(exception,GetMagickModule(), CacheError,"UnableToGetCacheNexus","`%s'",image->filename); return((const Quantum *) NULL); @@ -2915,9 +2906,10 @@ MagickPrivate const Quantum *GetVirtualPixelCacheNexus(const Image *image, { p=GetVirtualPixelCacheNexus(image,virtual_pixel_method, EdgeX(x_offset,cache_info->columns), - EdgeY(y_offset,cache_info->rows),1UL,1UL,*virtual_nexus, - exception); - r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); + EdgeY(y_offset,cache_info->rows),1UL,1UL, + nexus_info->pixel_nexus,exception); + r=GetVirtualMetacontentFromNexus(cache_info, + nexus_info->pixel_nexus); break; } case RandomVirtualPixelMethod: @@ -2927,17 +2919,19 @@ MagickPrivate const Quantum *GetVirtualPixelCacheNexus(const Image *image, p=GetVirtualPixelCacheNexus(image,virtual_pixel_method, RandomX(cache_info->random_info,cache_info->columns), RandomY(cache_info->random_info,cache_info->rows),1UL,1UL, - *virtual_nexus,exception); - r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); + nexus_info->pixel_nexus,exception); + r=GetVirtualMetacontentFromNexus(cache_info, + nexus_info->pixel_nexus); break; } case DitherVirtualPixelMethod: { p=GetVirtualPixelCacheNexus(image,virtual_pixel_method, DitherX(x_offset,cache_info->columns), - DitherY(y_offset,cache_info->rows),1UL,1UL,*virtual_nexus, - exception); - r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); + DitherY(y_offset,cache_info->rows),1UL,1UL, + nexus_info->pixel_nexus,exception); + r=GetVirtualMetacontentFromNexus(cache_info, + nexus_info->pixel_nexus); break; } case TileVirtualPixelMethod: @@ -2945,9 +2939,10 @@ MagickPrivate const Quantum *GetVirtualPixelCacheNexus(const Image *image, x_modulo=VirtualPixelModulo(x_offset,cache_info->columns); y_modulo=VirtualPixelModulo(y_offset,cache_info->rows); p=GetVirtualPixelCacheNexus(image,virtual_pixel_method, - x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, - exception); - r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); + x_modulo.remainder,y_modulo.remainder,1UL,1UL, + nexus_info->pixel_nexus,exception); + r=GetVirtualMetacontentFromNexus(cache_info, + nexus_info->pixel_nexus); break; } case MirrorVirtualPixelMethod: @@ -2961,9 +2956,10 @@ MagickPrivate const Quantum *GetVirtualPixelCacheNexus(const Image *image, y_modulo.remainder=(ssize_t) cache_info->rows- y_modulo.remainder-1L; p=GetVirtualPixelCacheNexus(image,virtual_pixel_method, - x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, - exception); - r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); + x_modulo.remainder,y_modulo.remainder,1UL,1UL, + nexus_info->pixel_nexus,exception); + r=GetVirtualMetacontentFromNexus(cache_info, + nexus_info->pixel_nexus); break; } case HorizontalTileEdgeVirtualPixelMethod: @@ -2971,8 +2967,9 @@ MagickPrivate const Quantum *GetVirtualPixelCacheNexus(const Image *image, x_modulo=VirtualPixelModulo(x_offset,cache_info->columns); p=GetVirtualPixelCacheNexus(image,virtual_pixel_method, x_modulo.remainder,EdgeY(y_offset,cache_info->rows),1UL,1UL, - *virtual_nexus,exception); - r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); + nexus_info->pixel_nexus,exception); + r=GetVirtualMetacontentFromNexus(cache_info, + nexus_info->pixel_nexus); break; } case VerticalTileEdgeVirtualPixelMethod: @@ -2980,8 +2977,9 @@ MagickPrivate const Quantum *GetVirtualPixelCacheNexus(const Image *image, y_modulo=VirtualPixelModulo(y_offset,cache_info->rows); p=GetVirtualPixelCacheNexus(image,virtual_pixel_method, EdgeX(x_offset,cache_info->columns),y_modulo.remainder,1UL,1UL, - *virtual_nexus,exception); - r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); + nexus_info->pixel_nexus,exception); + r=GetVirtualMetacontentFromNexus(cache_info, + nexus_info->pixel_nexus); break; } case BackgroundVirtualPixelMethod: @@ -3006,9 +3004,10 @@ MagickPrivate const Quantum *GetVirtualPixelCacheNexus(const Image *image, break; } p=GetVirtualPixelCacheNexus(image,virtual_pixel_method, - x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, - exception); - r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); + x_modulo.remainder,y_modulo.remainder,1UL,1UL, + nexus_info->pixel_nexus,exception); + r=GetVirtualMetacontentFromNexus(cache_info, + nexus_info->pixel_nexus); break; } case HorizontalTileVirtualPixelMethod: @@ -3022,9 +3021,10 @@ MagickPrivate const Quantum *GetVirtualPixelCacheNexus(const Image *image, x_modulo=VirtualPixelModulo(x_offset,cache_info->columns); y_modulo=VirtualPixelModulo(y_offset,cache_info->rows); p=GetVirtualPixelCacheNexus(image,virtual_pixel_method, - x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, - exception); - r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); + x_modulo.remainder,y_modulo.remainder,1UL,1UL, + nexus_info->pixel_nexus,exception); + r=GetVirtualMetacontentFromNexus(cache_info, + nexus_info->pixel_nexus); break; } case VerticalTileVirtualPixelMethod: @@ -3038,9 +3038,10 @@ MagickPrivate const Quantum *GetVirtualPixelCacheNexus(const Image *image, x_modulo=VirtualPixelModulo(x_offset,cache_info->columns); y_modulo=VirtualPixelModulo(y_offset,cache_info->rows); p=GetVirtualPixelCacheNexus(image,virtual_pixel_method, - x_modulo.remainder,y_modulo.remainder,1UL,1UL,*virtual_nexus, - exception); - r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); + x_modulo.remainder,y_modulo.remainder,1UL,1UL, + nexus_info->pixel_nexus,exception); + r=GetVirtualMetacontentFromNexus(cache_info, + nexus_info->pixel_nexus); break; } } @@ -3060,10 +3061,10 @@ MagickPrivate const Quantum *GetVirtualPixelCacheNexus(const Image *image, Transfer a run of pixels. */ p=GetVirtualPixelCacheNexus(image,virtual_pixel_method,x_offset,y_offset, - (size_t) length,1UL,*virtual_nexus,exception); + (size_t) length,1UL,nexus_info->pixel_nexus,exception); if (p == (const Quantum *) NULL) break; - r=GetVirtualMetacontentFromNexus(cache_info,*virtual_nexus); + r=GetVirtualMetacontentFromNexus(cache_info,nexus_info->pixel_nexus); (void) memcpy(q,p,(size_t) (cache_info->number_channels*length* sizeof(*p))); q+=cache_info->number_channels*length; @@ -3081,7 +3082,6 @@ MagickPrivate const Quantum *GetVirtualPixelCacheNexus(const Image *image, */ if (virtual_metacontent != (void *) NULL) virtual_metacontent=(void *) RelinquishMagickMemory(virtual_metacontent); - virtual_nexus=DestroyPixelCacheNexus(virtual_nexus,1); if (v < (ssize_t) rows) return((const Quantum *) NULL); return(pixels); @@ -3396,9 +3396,6 @@ static MagickBooleanType MaskPixelCacheNexus(Image *image,NexusInfo *nexus_info, MagickSizeType number_pixels; - NexusInfo - **magick_restrict image_nexus; - register Quantum *magick_restrict p, *magick_restrict q; @@ -3416,10 +3413,9 @@ static MagickBooleanType MaskPixelCacheNexus(Image *image,NexusInfo *nexus_info, cache_info=(CacheInfo *) image->cache; if (cache_info == (Cache) NULL) return(MagickFalse); - image_nexus=AcquirePixelCacheNexus(1); p=GetAuthenticPixelCacheNexus(image,nexus_info->region.x,nexus_info->region.y, - nexus_info->region.width,nexus_info->region.height,image_nexus[0], - exception); + nexus_info->region.width,nexus_info->region.height, + nexus_info->pixel_nexus,exception); q=nexus_info->pixels; number_pixels=(MagickSizeType) nexus_info->region.width* nexus_info->region.height; @@ -3446,7 +3442,6 @@ static MagickBooleanType MaskPixelCacheNexus(Image *image,NexusInfo *nexus_info, p+=GetPixelChannels(image); q+=GetPixelChannels(image); } - image_nexus=DestroyPixelCacheNexus(image_nexus,1); if (n < (ssize_t) number_pixels) return(MagickFalse); return(MagickTrue); diff --git a/coders/msl.c b/coders/msl.c index 28ab8f313..f2e35d56e 100644 --- a/coders/msl.c +++ b/coders/msl.c @@ -7862,6 +7862,7 @@ static MagickBooleanType ProcessMSLScript(const ImageInfo *image_info, *msl_info.image=msl_image; if (*image != (Image *) NULL) MSLPushImage(&msl_info,*image); + xmlInitParser(); (void) xmlSubstituteEntitiesDefault(1); (void) memset(&sax_modules,0,sizeof(sax_modules)); sax_modules.internalSubset=MSLInternalSubset; @@ -7987,9 +7988,6 @@ ModuleExport size_t RegisterMSLImage(void) MagickInfo *entry; -#if defined(MAGICKCORE_XML_DELEGATE) - xmlInitParser(); -#endif entry=AcquireMagickInfo("MSL","MSL","Magick Scripting Language"); #if defined(MAGICKCORE_XML_DELEGATE) entry->decoder=(DecodeImageHandler *) ReadMSLImage; diff --git a/coders/svg.c b/coders/svg.c index 05f5d228b..aa8408874 100644 --- a/coders/svg.c +++ b/coders/svg.c @@ -3551,6 +3551,7 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception) (void) CloneString(&svg_info->size,image_info->size); if (image->debug != MagickFalse) (void) LogMagickEvent(CoderEvent,GetMagickModule(),"begin SAX"); + xmlInitParser(); (void) xmlSubstituteEntitiesDefault(1); (void) memset(&sax_modules,0,sizeof(sax_modules)); sax_modules.internalSubset=SVGInternalSubset; @@ -3737,9 +3738,6 @@ ModuleExport size_t RegisterSVGImage(void) #if defined(MAGICKCORE_RSVG_DELEGATE) #if !GLIB_CHECK_VERSION(2,35,0) g_type_init(); -#endif -#if defined(MAGICKCORE_XML_DELEGATE) - xmlInitParser(); #endif (void) FormatLocaleString(version,MagickPathExtent,"RSVG %d.%d.%d", LIBRSVG_MAJOR_VERSION,LIBRSVG_MINOR_VERSION,LIBRSVG_MICRO_VERSION); diff --git a/configure b/configure index a509086ae..38b86bfe0 100755 --- a/configure +++ b/configure @@ -4570,7 +4570,7 @@ MAGICK_PATCHLEVEL_VERSION=36 MAGICK_VERSION=7.0.8-36 -MAGICK_GIT_REVISION=15442:d94a5714f:20190325 +MAGICK_GIT_REVISION=15459:7e69ae7e4:20190331 # Substitute library versioning @@ -26860,7 +26860,7 @@ $as_echo "#define HAVE_SOCKET 1" >>confdefs.h fi -for ac_func in acosh _aligned_malloc asinh atanh atoll atexit cabs carg cimag creal clock clock_getres clock_gettime ctime_r directio erf _exit execvp fchmod floor fork ftime ftruncate getc_unlocked getcwd getpid getexecname getdtablesize getpagesize getrlimit getrusage gettimeofday gmtime_r isnan j0 j1 lltostr localtime_r lstat memmove memset mkstemp munmap nanosleep newlocale _NSGetExecutablePath pclose _pclose poll popen _popen posix_fadvise posix_fallocate posix_madvise posix_spawnp pow pread pwrite qsort_r raise rand_r readlink realpath select seekdir sendfile setlocale socket sqrt setvbuf stat strchr strrchr strcspn strdup strpbrk strspn strstr strtod strtod_l strtol strtoul symlink sysconf sigemptyset sigaction spawnvp strerror strlcat strlcpy strcasecmp strncasecmp telldir tempnam times ulltostr uselocale usleep utime vfprintf vfprintf_l vsprintf vsnprintf vsnprintf_l waitpid _wfopen _wstat +for ac_func in acosh _aligned_malloc asinh atanh atoll atexit cabs carg cimag creal clock clock_getres clock_gettime ctime_r directio erf _exit execvp fchmod floor fork ftime ftruncate getc_unlocked getcwd getpid getexecname getdtablesize getpagesize getrlimit getrusage gettimeofday gmtime_r isnan j0 j1 lltostr localtime_r lstat memmove memset mkstemp munmap nanosleep newlocale _NSGetExecutablePath pclose _pclose poll popen _popen posix_fadvise posix_fallocate posix_madvise posix_memalign posix_spawnp pow pread pwrite qsort_r raise rand_r readlink realpath select seekdir sendfile setlocale socket sqrt setvbuf stat strchr strrchr strcspn strdup strpbrk strspn strstr strtod strtod_l strtol strtoul symlink sysconf sigemptyset sigaction spawnvp strerror strlcat strlcpy strcasecmp strncasecmp telldir tempnam times ulltostr uselocale usleep utime vfprintf vfprintf_l vsprintf vsnprintf vsnprintf_l waitpid _wfopen _wstat do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.ac b/configure.ac index 854da8dd6..ef2ea207a 100644 --- a/configure.ac +++ b/configure.ac @@ -1220,7 +1220,7 @@ AC_SEARCH_LIBS(socket, socket, MAGICK_FEATURES="DPC $MAGICK_FEATURES" ]) -AC_CHECK_FUNCS([acosh _aligned_malloc asinh atanh atoll atexit cabs carg cimag creal clock clock_getres clock_gettime ctime_r directio erf _exit execvp fchmod floor fork ftime ftruncate getc_unlocked getcwd getpid getexecname getdtablesize getpagesize getrlimit getrusage gettimeofday gmtime_r isnan j0 j1 lltostr localtime_r lstat memmove memset mkstemp munmap nanosleep newlocale _NSGetExecutablePath pclose _pclose poll popen _popen posix_fadvise posix_fallocate posix_madvise posix_spawnp pow pread pwrite qsort_r raise rand_r readlink realpath select seekdir sendfile setlocale socket sqrt setvbuf stat strchr strrchr strcspn strdup strpbrk strspn strstr strtod strtod_l strtol strtoul symlink sysconf sigemptyset sigaction spawnvp strerror strlcat strlcpy strcasecmp strncasecmp telldir tempnam times ulltostr uselocale usleep utime vfprintf vfprintf_l vsprintf vsnprintf vsnprintf_l waitpid _wfopen _wstat]) +AC_CHECK_FUNCS([acosh _aligned_malloc asinh atanh atoll atexit cabs carg cimag creal clock clock_getres clock_gettime ctime_r directio erf _exit execvp fchmod floor fork ftime ftruncate getc_unlocked getcwd getpid getexecname getdtablesize getpagesize getrlimit getrusage gettimeofday gmtime_r isnan j0 j1 lltostr localtime_r lstat memmove memset mkstemp munmap nanosleep newlocale _NSGetExecutablePath pclose _pclose poll popen _popen posix_fadvise posix_fallocate posix_madvise posix_memalign posix_spawnp pow pread pwrite qsort_r raise rand_r readlink realpath select seekdir sendfile setlocale socket sqrt setvbuf stat strchr strrchr strcspn strdup strpbrk strspn strstr strtod strtod_l strtol strtoul symlink sysconf sigemptyset sigaction spawnvp strerror strlcat strlcpy strcasecmp strncasecmp telldir tempnam times ulltostr uselocale usleep utime vfprintf vfprintf_l vsprintf vsnprintf vsnprintf_l waitpid _wfopen _wstat]) # # Check for clock_gettime(). -- 2.40.0