]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/cache.c
...
[imagemagick] / MagickCore / cache.c
index fd284fab985d9740062c340e0d99d93997b6136c..d45001ac46a6e6139446de2dcb11dccfdce5d73d 100644 (file)
 %                                 July 1999                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2017 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  %
 %  obtain a copy of the License at                                            %
 %                                                                             %
-%    http://www.imagemagick.org/script/license.php                            %
+%    https://www.imagemagick.org/script/license.php                           %
 %                                                                             %
 %  Unless required by applicable law or agreed to in writing, software        %
 %  distributed under the License is distributed on an "AS IS" BASIS,          %
@@ -119,11 +119,16 @@ static MagickBooleanType
   GetOneVirtualPixelFromCache(const Image *,const VirtualPixelMethod,
     const ssize_t,const ssize_t,Quantum *,ExceptionInfo *),
   OpenPixelCache(Image *,const MapMode,ExceptionInfo *),
-  ReadPixelCachePixels(CacheInfo *,NexusInfo *,ExceptionInfo *),
-  ReadPixelCacheMetacontent(CacheInfo *,NexusInfo *,ExceptionInfo *),
+  OpenPixelCacheOnDisk(CacheInfo *,const MapMode),
+  ReadPixelCachePixels(CacheInfo *magick_restrict,NexusInfo *magick_restrict,
+    ExceptionInfo *),
+  ReadPixelCacheMetacontent(CacheInfo *magick_restrict,
+    NexusInfo *magick_restrict,ExceptionInfo *),
   SyncAuthenticPixelsCache(Image *,ExceptionInfo *),
-  WritePixelCachePixels(CacheInfo *,NexusInfo *,ExceptionInfo *),
-  WritePixelCacheMetacontent(CacheInfo *,NexusInfo *,ExceptionInfo *);
+  WritePixelCachePixels(CacheInfo *magick_restrict,NexusInfo *magick_restrict,
+    ExceptionInfo *),
+  WritePixelCacheMetacontent(CacheInfo *,NexusInfo *magick_restrict,
+    ExceptionInfo *);
 
 static Quantum
   *GetAuthenticPixelsCache(Image *,const ssize_t,const ssize_t,const size_t,
@@ -133,6 +138,11 @@ static Quantum
   *SetPixelCacheNexusPixels(const CacheInfo *,const MapMode,
     const RectangleInfo *,NexusInfo *,ExceptionInfo *) magick_hot_spot;
 
+#if defined(MAGICKCORE_OPENCL_SUPPORT)
+static void
+  CopyOpenCLBuffer(CacheInfo *magick_restrict);
+#endif
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif
@@ -145,6 +155,12 @@ static volatile MagickBooleanType
 
 static SemaphoreInfo
   *cache_semaphore = (SemaphoreInfo *) NULL;
+
+static ssize_t
+  cache_anonymous_memory = (-1);
+
+static time_t
+  cache_epoch = 0;
 \f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -171,10 +187,10 @@ static SemaphoreInfo
 MagickPrivate Cache AcquirePixelCache(const size_t number_threads)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   char
-    *synchronize;
+    *value;
 
   cache_info=(CacheInfo *) AcquireQuantumMemory(1,sizeof(*cache_info));
   if (cache_info == (CacheInfo *) NULL)
@@ -195,17 +211,23 @@ MagickPrivate Cache AcquirePixelCache(const size_t number_threads)
   cache_info->nexus_info=AcquirePixelCacheNexus(cache_info->number_threads);
   if (cache_info->nexus_info == (NexusInfo **) NULL)
     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
-  synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
-  if (synchronize != (const char *) NULL)
+  value=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
+  if (value != (const char *) NULL)
+    {
+      cache_info->synchronize=IsStringTrue(value);
+      value=DestroyString(value);
+    }
+  value=GetPolicyValue("cache:synchronize");
+  if (value != (const char *) NULL)
     {
-      cache_info->synchronize=IsStringTrue(synchronize);
-      synchronize=DestroyString(synchronize);
+      cache_info->synchronize=IsStringTrue(value);
+      value=DestroyString(value);
     }
   cache_info->semaphore=AcquireSemaphoreInfo();
   cache_info->reference_count=1;
   cache_info->file_semaphore=AcquireSemaphoreInfo();
   cache_info->debug=IsEventLogging();
-  cache_info->signature=MagickSignature;
+  cache_info->signature=MagickCoreSignature;
   return((Cache ) cache_info);
 }
 \f
@@ -234,7 +256,7 @@ MagickPrivate Cache AcquirePixelCache(const size_t number_threads)
 MagickPrivate NexusInfo **AcquirePixelCacheNexus(const size_t number_threads)
 {
   NexusInfo
-    **restrict nexus_info;
+    **magick_restrict nexus_info;
 
   register ssize_t
     i;
@@ -251,7 +273,7 @@ MagickPrivate NexusInfo **AcquirePixelCacheNexus(const size_t number_threads)
   for (i=0; i < (ssize_t) number_threads; i++)
   {
     nexus_info[i]=(&nexus_info[0][i]);
-    nexus_info[i]->signature=MagickSignature;
+    nexus_info[i]->signature=MagickCoreSignature;
   }
   return(nexus_info);
 }
@@ -288,15 +310,15 @@ MagickPrivate const void *AcquirePixelCachePixels(const Image *image,
   MagickSizeType *length,ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   *length=0;
   if ((cache_info->type != MemoryCache) && (cache_info->type != MapCache))
     return((const void *) NULL);
@@ -382,14 +404,14 @@ MagickPrivate void CacheComponentTerminus(void)
 MagickPrivate Cache ClonePixelCache(const Cache cache)
 {
   CacheInfo
-    *restrict clone_info;
+    *magick_restrict clone_info;
 
   const CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   assert(cache != NULL);
   cache_info=(const CacheInfo *) cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       cache_info->filename);
@@ -428,18 +450,18 @@ MagickPrivate Cache ClonePixelCache(const Cache cache)
 MagickPrivate void ClonePixelCacheMethods(Cache clone,const Cache cache)
 {
   CacheInfo
-    *restrict cache_info,
-    *restrict source_info;
+    *magick_restrict cache_info,
+    *magick_restrict source_info;
 
   assert(clone != (Cache) NULL);
   source_info=(CacheInfo *) clone;
-  assert(source_info->signature == MagickSignature);
+  assert(source_info->signature == MagickCoreSignature);
   if (source_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       source_info->filename);
   assert(cache != (Cache) NULL);
   cache_info=(CacheInfo *) cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   source_info->methods=cache_info->methods;
 }
 \f
@@ -452,7 +474,7 @@ MagickPrivate void ClonePixelCacheMethods(Cache clone,const Cache cache)
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %  ClonePixelCacheRepository() clones the source pixel cache to the destination
 %  cache.
 %
@@ -471,13 +493,62 @@ MagickPrivate void ClonePixelCacheMethods(Cache clone,const Cache cache)
 %
 */
 
+static MagickBooleanType ClonePixelCacheOnDisk(
+  CacheInfo *magick_restrict cache_info,CacheInfo *magick_restrict clone_info)
+{
+  MagickSizeType
+    extent;
+
+  size_t
+    quantum;
+
+  ssize_t
+    count;
+
+  struct stat
+    file_stats;
+
+  unsigned char
+    *buffer;
+
+  /*
+    Clone pixel cache on disk with identical morphology.
+  */
+  if ((OpenPixelCacheOnDisk(cache_info,ReadMode) == MagickFalse) ||
+      (OpenPixelCacheOnDisk(clone_info,IOMode) == MagickFalse))
+    return(MagickFalse);
+  quantum=(size_t) MagickMaxBufferExtent;
+  if ((fstat(cache_info->file,&file_stats) == 0) && (file_stats.st_size > 0))
+    quantum=(size_t) MagickMin(file_stats.st_size,MagickMaxBufferExtent);
+  buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
+  if (buffer == (unsigned char *) NULL)
+    ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+  extent=0;
+  while ((count=read(cache_info->file,buffer,quantum)) > 0)
+  {
+    ssize_t
+      number_bytes;
+
+    number_bytes=write(clone_info->file,buffer,(size_t) count);
+    if (number_bytes != count)
+      break;
+    extent+=number_bytes;
+  }
+  buffer=(unsigned char *) RelinquishMagickMemory(buffer);
+  if (extent != cache_info->length)
+    return(MagickFalse);
+  return(MagickTrue);
+}
+
 static MagickBooleanType ClonePixelCacheRepository(
-  CacheInfo *restrict clone_info,CacheInfo *restrict cache_info,
+  CacheInfo *magick_restrict clone_info,CacheInfo *magick_restrict cache_info,
   ExceptionInfo *exception)
 {
 #define MaxCacheThreads  2
-#define cache_threads(source,destination,chunk) \
-  num_threads((chunk) < (16*GetMagickResourceLimit(ThreadResource)) ? 1 : \
+#define cache_threads(source,destination) \
+  num_threads(((source)->type == DiskCache) || \
+    ((destination)->type == DiskCache) || (((source)->rows) < \
+    (16*GetMagickResourceLimit(ThreadResource))) ? 1 : \
     GetMagickResourceLimit(ThreadResource) < MaxCacheThreads ? \
     GetMagickResourceLimit(ThreadResource) : MaxCacheThreads)
 
@@ -486,8 +557,8 @@ static MagickBooleanType ClonePixelCacheRepository(
     status;
 
   NexusInfo
-    **restrict cache_nexus,
-    **restrict clone_nexus;
+    **magick_restrict cache_nexus,
+    **magick_restrict clone_nexus;
 
   size_t
     length;
@@ -501,23 +572,32 @@ static MagickBooleanType ClonePixelCacheRepository(
   if (cache_info->type == PingCache)
     return(MagickTrue);
   length=cache_info->number_channels*sizeof(*cache_info->channel_map);
-  if (((cache_info->type == MemoryCache) || (cache_info->type == MapCache)) &&
-      ((clone_info->type == MemoryCache) || (clone_info->type == MapCache)) &&
-      (cache_info->columns == clone_info->columns) &&
+  if ((cache_info->columns == clone_info->columns) &&
       (cache_info->rows == clone_info->rows) &&
       (cache_info->number_channels == clone_info->number_channels) &&
       (memcmp(cache_info->channel_map,clone_info->channel_map,length) == 0) &&
       (cache_info->metacontent_extent == clone_info->metacontent_extent))
     {
-      (void) memcpy(clone_info->pixels,cache_info->pixels,cache_info->columns*
-        cache_info->number_channels*cache_info->rows*
-        sizeof(*cache_info->pixels));
-      if ((cache_info->metacontent_extent != 0) &&
-          (clone_info->metacontent_extent != 0))
-        (void) memcpy(clone_info->metacontent,cache_info->metacontent,
-          cache_info->columns*cache_info->rows*clone_info->metacontent_extent*
-          sizeof(unsigned char));
-      return(MagickTrue);
+      /*
+        Identical pixel cache morphology.
+      */
+      if (((cache_info->type == MemoryCache) ||
+           (cache_info->type == MapCache)) &&
+          ((clone_info->type == MemoryCache) ||
+           (clone_info->type == MapCache)))
+        {
+          (void) memcpy(clone_info->pixels,cache_info->pixels,
+            cache_info->columns*cache_info->number_channels*cache_info->rows*
+            sizeof(*cache_info->pixels));
+          if ((cache_info->metacontent_extent != 0) &&
+              (clone_info->metacontent_extent != 0))
+            (void) memcpy(clone_info->metacontent,cache_info->metacontent,
+              cache_info->columns*cache_info->rows*
+              clone_info->metacontent_extent*sizeof(unsigned char));
+          return(MagickTrue);
+        }
+      if ((cache_info->type == DiskCache) && (clone_info->type == DiskCache))
+        return(ClonePixelCacheOnDisk(cache_info,clone_info));
     }
   /*
     Mismatched pixel cache morphology.
@@ -536,7 +616,7 @@ static MagickBooleanType ClonePixelCacheRepository(
   status=MagickTrue;
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(status) \
-    cache_threads(cache_info,clone_info,cache_info->rows)
+    cache_threads(cache_info,clone_info)
 #endif
   for (y=0; y < (ssize_t) cache_info->rows; y++)
   {
@@ -560,8 +640,8 @@ static MagickBooleanType ClonePixelCacheRepository(
     region.height=1;
     region.x=0;
     region.y=y;
-    pixels=SetPixelCacheNexusPixels(cache_info,ReadMode,&region,cache_nexus[id],
-      exception);
+    pixels=SetPixelCacheNexusPixels(cache_info,ReadMode,&region,
+      cache_nexus[id],exception);
     if (pixels == (Quantum *) NULL)
       continue;
     status=ReadPixelCachePixels(cache_info,cache_nexus[id],exception);
@@ -580,10 +660,10 @@ static MagickBooleanType ClonePixelCacheRepository(
     else
       {
         register const Quantum
-          *restrict p;
+          *magick_restrict p;
 
         register Quantum
-          *restrict q;
+          *magick_restrict q;
 
         /*
           Mismatched pixel channel map.
@@ -608,8 +688,7 @@ static MagickBooleanType ClonePixelCacheRepository(
             channel=clone_info->channel_map[i].channel;
             traits=cache_info->channel_map[channel].traits;
             if (traits != UndefinedPixelTrait)
-              (void) memcpy(q,p+cache_info->channel_map[channel].offset,
-                sizeof(Quantum));
+              *q=*(p+cache_info->channel_map[channel].offset);
             q++;
           }
           p+=cache_info->number_channels;
@@ -627,7 +706,7 @@ static MagickBooleanType ClonePixelCacheRepository(
         clone_info->metacontent_extent);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
       #pragma omp parallel for schedule(static,4) shared(status) \
-        cache_threads(cache_info,clone_info,cache_info->rows)
+        cache_threads(cache_info,clone_info)
 #endif
       for (y=0; y < (ssize_t) cache_info->rows; y++)
       {
@@ -672,9 +751,9 @@ static MagickBooleanType ClonePixelCacheRepository(
   if (cache_info->debug != MagickFalse)
     {
       char
-        message[MaxTextExtent];
+        message[MagickPathExtent];
 
-      (void) FormatLocaleString(message,MaxTextExtent,"%s => %s",
+      (void) FormatLocaleString(message,MagickPathExtent,"%s => %s",
         CommandOptionToMnemonic(MagickCacheOptions,(ssize_t) cache_info->type),
         CommandOptionToMnemonic(MagickCacheOptions,(ssize_t) clone_info->type));
       (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",message);
@@ -707,7 +786,7 @@ static MagickBooleanType ClonePixelCacheRepository(
 static void DestroyImagePixelCache(Image *image)
 {
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   if (image->cache == (void *) NULL)
@@ -740,15 +819,15 @@ static void DestroyImagePixelCache(Image *image)
 MagickExport void DestroyImagePixels(Image *image)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->methods.destroy_pixel_handler != (DestroyPixelHandler) NULL)
     {
       cache_info->methods.destroy_pixel_handler(image);
@@ -801,14 +880,20 @@ static inline void RelinquishPixelCachePixels(CacheInfo *cache_info)
   {
     case MemoryCache:
     {
+#if defined(MAGICKCORE_OPENCL_SUPPORT)
+      if (cache_info->opencl != (MagickCLCacheInfo) NULL)
+        {
+          cache_info->opencl=RelinquishMagickCLCacheInfo(cache_info->opencl,
+            MagickTrue);
+          cache_info->pixels=(Quantum *) NULL;
+          break;
+        }
+#endif
       if (cache_info->mapped == MagickFalse)
         cache_info->pixels=(Quantum *) RelinquishAlignedMemory(
           cache_info->pixels);
       else
-        {
-          (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
-          cache_info->pixels=(Quantum *) NULL;
-        }
+        (void) UnmapBlob(cache_info->pixels,(size_t) cache_info->length);
       RelinquishMagickResource(MemoryResource,cache_info->length);
       break;
     }
@@ -849,11 +934,11 @@ static inline void RelinquishPixelCachePixels(CacheInfo *cache_info)
 MagickPrivate Cache DestroyPixelCache(Cache cache)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   assert(cache != (Cache) NULL);
   cache_info=(CacheInfo *) cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       cache_info->filename);
@@ -868,9 +953,9 @@ MagickPrivate Cache DestroyPixelCache(Cache cache)
   if (cache_info->debug != MagickFalse)
     {
       char
-        message[MaxTextExtent];
+        message[MagickPathExtent];
 
-      (void) FormatLocaleString(message,MaxTextExtent,"destroy %s",
+      (void) FormatLocaleString(message,MagickPathExtent,"destroy %s",
         cache_info->filename);
       (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",message);
     }
@@ -887,7 +972,7 @@ MagickPrivate Cache DestroyPixelCache(Cache cache)
     RelinquishSemaphoreInfo(&cache_info->file_semaphore);
   if (cache_info->semaphore != (SemaphoreInfo *) NULL)
     RelinquishSemaphoreInfo(&cache_info->semaphore);
-  cache_info->signature=(~MagickSignature);
+  cache_info->signature=(~MagickCoreSignature);
   cache_info=(CacheInfo *) RelinquishMagickMemory(cache_info);
   cache=(Cache) NULL;
   return(cache);
@@ -943,7 +1028,7 @@ MagickPrivate NexusInfo **DestroyPixelCacheNexus(NexusInfo **nexus_info,
   {
     if (nexus_info[i]->cache != (Quantum *) NULL)
       RelinquishCacheNexusPixels(nexus_info[i]);
-    nexus_info[i]->signature=(~MagickSignature);
+    nexus_info[i]->signature=(~MagickCoreSignature);
   }
   nexus_info[0]=(NexusInfo *) RelinquishMagickMemory(nexus_info[0]);
   nexus_info=(NexusInfo **) RelinquishAlignedMemory(nexus_info);
@@ -977,16 +1062,16 @@ MagickPrivate NexusInfo **DestroyPixelCacheNexus(NexusInfo **nexus_info,
 MagickExport void *GetAuthenticMetacontent(const Image *image)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->methods.get_authentic_metacontent_from_handler !=
       (GetAuthenticMetacontentFromHandler) NULL)
     {
@@ -1028,19 +1113,80 @@ MagickExport void *GetAuthenticMetacontent(const Image *image)
 static void *GetAuthenticMetacontentFromCache(const Image *image)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   assert(id < (int) cache_info->number_threads);
   return(cache_info->nexus_info[id]->metacontent);
 }
+
+#if defined(MAGICKCORE_OPENCL_SUPPORT)
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
++   G e t A u t h e n t i c O p e n C L B u f f e r                           %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  GetAuthenticOpenCLBuffer() returns an OpenCL buffer used to execute OpenCL
+%  operations.
+%
+%  The format of the GetAuthenticOpenCLBuffer() method is:
+%
+%      cl_mem GetAuthenticOpenCLBuffer(const Image *image,
+%        MagickCLDevice device,ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image: the image.
+%
+%    o device: the device to use.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+MagickPrivate cl_mem GetAuthenticOpenCLBuffer(const Image *image,
+  MagickCLDevice device,ExceptionInfo *exception)
+{
+  CacheInfo
+    *magick_restrict cache_info;
+
+  cl_int
+    status;
+
+  assert(image != (const Image *) NULL);
+  assert(device != (const MagickCLDevice) NULL);
+  cache_info=(CacheInfo *) image->cache;
+  if (cache_info->type == UndefinedCache)
+    SyncImagePixelCache((Image *) image,exception);
+  if ((cache_info->type != MemoryCache) || (cache_info->mapped != MagickFalse))
+    return((cl_mem) NULL);
+  if ((cache_info->opencl != (MagickCLCacheInfo) NULL) &&
+      (cache_info->opencl->device->context != device->context))
+    cache_info->opencl=CopyMagickCLCacheInfo(cache_info->opencl);
+  if (cache_info->opencl == (MagickCLCacheInfo) NULL)
+    {
+      assert(cache_info->pixels != (Quantum *) NULL);
+      cache_info->opencl=AcquireMagickCLCacheInfo(device,cache_info->pixels,
+        cache_info->length);
+      if (cache_info->opencl == (MagickCLCacheInfo) NULL)
+        return((cl_mem) NULL);
+    }
+  assert(cache_info->opencl->pixels == cache_info->pixels);
+  return(cache_info->opencl->buffer);
+}
+#endif
 \f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -1082,22 +1228,22 @@ MagickPrivate Quantum *GetAuthenticPixelCacheNexus(Image *image,const ssize_t x,
   ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   Quantum
-    *restrict pixels;
+    *magick_restrict pixels;
 
   /*
     Transfer pixels from the cache.
   */
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   pixels=QueueAuthenticPixelCacheNexus(image,x,y,columns,rows,MagickTrue,
     nexus_info,exception);
   if (pixels == (Quantum *) NULL)
     return((Quantum *) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (nexus_info->authentic_pixel_cache != MagickFalse)
     return(pixels);
   if (ReadPixelCachePixels(cache_info,nexus_info,exception) == MagickFalse)
@@ -1134,16 +1280,16 @@ MagickPrivate Quantum *GetAuthenticPixelCacheNexus(Image *image,const ssize_t x,
 static Quantum *GetAuthenticPixelsFromCache(const Image *image)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   assert(id < (int) cache_info->number_threads);
   return(cache_info->nexus_info[id]->pixels);
 }
@@ -1175,16 +1321,16 @@ static Quantum *GetAuthenticPixelsFromCache(const Image *image)
 MagickExport Quantum *GetAuthenticPixelQueue(const Image *image)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->methods.get_authentic_pixels_from_handler !=
        (GetAuthenticPixelsFromHandler) NULL)
     return(cache_info->methods.get_authentic_pixels_from_handler(image));
@@ -1200,7 +1346,8 @@ MagickExport Quantum *GetAuthenticPixelQueue(const Image *image)
 %   G e t A u t h e n t i c P i x e l s                                       %
 %                                                                             %
 %                                                                             %
-%                                                                             % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  GetAuthenticPixels() obtains a pixel region for read/write access. If the
 %  region is successfully accessed, a pointer to a Quantum array
@@ -1241,7 +1388,7 @@ MagickExport Quantum *GetAuthenticPixels(Image *image,const ssize_t x,
   ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
@@ -1250,10 +1397,10 @@ MagickExport Quantum *GetAuthenticPixels(Image *image,const ssize_t x,
     *pixels;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->methods.get_authentic_pixels_handler !=
       (GetAuthenticPixelsHandler) NULL)
     {
@@ -1303,21 +1450,21 @@ static Quantum *GetAuthenticPixelsCache(Image *image,const ssize_t x,
   ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   Quantum
-    *restrict pixels;
+    *magick_restrict pixels;
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
   if (cache_info == (Cache) NULL)
     return((Quantum *) NULL);
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   assert(id < (int) cache_info->number_threads);
   pixels=GetAuthenticPixelCacheNexus(image,x,y,columns,rows,
     cache_info->nexus_info[id],exception);
@@ -1350,18 +1497,18 @@ static Quantum *GetAuthenticPixelsCache(Image *image,const ssize_t x,
 MagickExport MagickSizeType GetImageExtent(const Image *image)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   assert(id < (int) cache_info->number_threads);
   return(GetPixelCacheNexusExtent(cache_info,cache_info->nexus_info[id]));
 }
@@ -1397,14 +1544,14 @@ MagickExport MagickSizeType GetImageExtent(const Image *image)
 */
 
 static inline MagickBooleanType ValidatePixelCacheMorphology(
-  const Image *restrict image)
+  const Image *magick_restrict image)
 {
   const CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const PixelChannelMap
-    *restrict p,
-    *restrict q;
+    *magick_restrict p,
+    *magick_restrict q;
 
   /*
     Does the image match the pixel cache morphology?
@@ -1431,44 +1578,44 @@ static Cache GetImagePixelCache(Image *image,const MagickBooleanType clone,
   ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   MagickBooleanType
     destroy,
     status;
 
   static MagickSizeType
+    cache_timelimit = MagickResourceInfinity,
     cpu_throttle = MagickResourceInfinity,
-    cycles = 0,
-    time_limit = 0;
-
-  static time_t
-    cache_timestamp = 0;
+    cycles = 0;
 
   status=MagickTrue;
-  LockSemaphoreInfo(image->semaphore);
   if (cpu_throttle == MagickResourceInfinity)
     cpu_throttle=GetMagickResourceLimit(ThrottleResource);
   if ((cpu_throttle != 0) && ((cycles++ % 32) == 0))
     MagickDelay(cpu_throttle);
-  if (time_limit == 0)
+  if (cache_epoch == 0)
     {
       /*
         Set the expire time in seconds.
       */
-      time_limit=GetMagickResourceLimit(TimeResource);
-      cache_timestamp=time((time_t *) NULL);
+      cache_timelimit=GetMagickResourceLimit(TimeResource);
+      cache_epoch=time((time_t *) NULL);
     }
-  if ((time_limit != MagickResourceInfinity) &&
-      ((MagickSizeType) (time((time_t *) NULL)-cache_timestamp) >= time_limit))
-     {
+  if ((cache_timelimit != MagickResourceInfinity) &&
+      ((MagickSizeType) (time((time_t *) NULL)-cache_epoch) >= cache_timelimit))
+    {
 #if defined(ECANCELED)
-       errno=ECANCELED;
+      errno=ECANCELED;
 #endif
-       ThrowFatalException(ResourceLimitFatalError,"TimeLimitExceeded");
-     }
+      ThrowFatalException(ResourceLimitFatalError,"TimeLimitExceeded");
+    }
+  LockSemaphoreInfo(image->semaphore);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
+#if defined(MAGICKCORE_OPENCL_SUPPORT)
+  CopyOpenCLBuffer(cache_info);
+#endif
   destroy=MagickFalse;
   if ((cache_info->reference_count > 1) || (cache_info->mode == ReadMode))
     {
@@ -1555,13 +1702,13 @@ static Cache GetImagePixelCache(Image *image,const MagickBooleanType clone,
 MagickExport CacheType GetImagePixelCacheType(const Image *image)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   return(cache_info->type);
 }
 \f
@@ -1596,8 +1743,8 @@ MagickExport CacheType GetImagePixelCacheType(const Image *image)
 %
 */
 
-static inline MagickBooleanType CopyPixel(const Image *image,const Quantum *source,
-  Quantum *destination)
+static inline MagickBooleanType CopyPixel(const Image *image,
+  const Quantum *source,Quantum *destination)
 {
   register ssize_t
     i;
@@ -1605,10 +1752,14 @@ static inline MagickBooleanType CopyPixel(const Image *image,const Quantum *sour
   if (source == (const Quantum *) NULL)
     {
       destination[RedPixelChannel]=ClampToQuantum(image->background_color.red);
-      destination[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
-      destination[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
-      destination[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
-      destination[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
+      destination[GreenPixelChannel]=ClampToQuantum(
+        image->background_color.green);
+      destination[BluePixelChannel]=ClampToQuantum(
+        image->background_color.blue);
+      destination[BlackPixelChannel]=ClampToQuantum(
+        image->background_color.black);
+      destination[AlphaPixelChannel]=ClampToQuantum(
+        image->background_color.alpha);
       return(MagickFalse);
     }
   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
@@ -1623,16 +1774,16 @@ MagickExport MagickBooleanType GetOneAuthenticPixel(Image *image,
   const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   register Quantum
-    *restrict q;
+    *magick_restrict q;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
   if (cache_info->methods.get_one_authentic_pixel_from_handler !=
        (GetOneAuthenticPixelFromHandler) NULL)
@@ -1677,19 +1828,19 @@ static MagickBooleanType GetOneAuthenticPixelFromCache(Image *image,
   const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   register Quantum
-    *restrict q;
+    *magick_restrict q;
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   assert(id < (int) cache_info->number_threads);
   (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
   q=GetAuthenticPixelCacheNexus(image,x,y,1UL,1UL,cache_info->nexus_info[id],
@@ -1732,7 +1883,7 @@ MagickExport MagickBooleanType GetOneVirtualPixel(const Image *image,
   const ssize_t x,const ssize_t y,Quantum *pixel,ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
@@ -1741,10 +1892,10 @@ MagickExport MagickBooleanType GetOneVirtualPixel(const Image *image,
     *p;
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
   if (cache_info->methods.get_one_virtual_pixel_from_handler !=
        (GetOneVirtualPixelFromHandler) NULL)
@@ -1795,7 +1946,7 @@ static MagickBooleanType GetOneVirtualPixelFromCache(const Image *image,
   Quantum *pixel,ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
@@ -1804,10 +1955,10 @@ static MagickBooleanType GetOneVirtualPixelFromCache(const Image *image,
     *p;
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   assert(id < (int) cache_info->number_threads);
   (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
   p=GetVirtualPixelsFromNexus(image,virtual_pixel_method,x,y,1UL,1UL,
@@ -1854,19 +2005,19 @@ MagickExport MagickBooleanType GetOneVirtualPixelInfo(const Image *image,
   PixelInfo *pixel,ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   register const Quantum
-    *restrict p;
+    *magick_restrict p;
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   assert(id < (int) cache_info->number_threads);
   GetPixelInfo(image,pixel);
   p=GetVirtualPixelsFromNexus(image,virtual_pixel_method,x,y,1UL,1UL,
@@ -1902,11 +2053,11 @@ MagickExport MagickBooleanType GetOneVirtualPixelInfo(const Image *image,
 MagickPrivate ColorspaceType GetPixelCacheColorspace(const Cache cache)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   assert(cache != (Cache) NULL);
   cache_info=(CacheInfo *) cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       cache_info->filename);
@@ -1981,17 +2132,17 @@ MagickPrivate void GetPixelCacheMethods(CacheMethods *cache_methods)
 %
 */
 MagickPrivate MagickSizeType GetPixelCacheNexusExtent(const Cache cache,
-  NexusInfo *restrict nexus_info)
+  NexusInfo *magick_restrict nexus_info)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   MagickSizeType
     extent;
 
   assert(cache != NULL);
   cache_info=(CacheInfo *) cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   extent=(MagickSizeType) nexus_info->region.width*nexus_info->region.height;
   if (extent == 0)
     return((MagickSizeType) cache_info->columns*cache_info->rows);
@@ -2029,16 +2180,16 @@ MagickPrivate void *GetPixelCachePixels(Image *image,MagickSizeType *length,
   ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   assert(length != (MagickSizeType *) NULL);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   *length=0;
   if ((cache_info->type != MemoryCache) && (cache_info->type != MapCache))
     return((void *) NULL);
@@ -2073,11 +2224,11 @@ MagickPrivate void *GetPixelCachePixels(Image *image,MagickSizeType *length,
 MagickPrivate ClassType GetPixelCacheStorageClass(const Cache cache)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   assert(cache != (Cache) NULL);
   cache_info=(CacheInfo *) cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       cache_info->filename);
@@ -2115,14 +2266,14 @@ MagickPrivate void GetPixelCacheTileSize(const Image *image,size_t *width,
   size_t *height)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   *width=2048UL/(cache_info->number_channels*sizeof(Quantum));
   if (GetImagePixelCacheType(image) == DiskCache)
     *width=8192UL/(cache_info->number_channels*sizeof(Quantum));
@@ -2156,13 +2307,13 @@ MagickPrivate void GetPixelCacheTileSize(const Image *image,size_t *width,
 MagickPrivate VirtualPixelMethod GetPixelCacheVirtualMethod(const Image *image)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   return(cache_info->virtual_pixel_method);
 }
 \f
@@ -2192,19 +2343,19 @@ MagickPrivate VirtualPixelMethod GetPixelCacheVirtualMethod(const Image *image)
 static const void *GetVirtualMetacontentFromCache(const Image *image)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   const void
-    *restrict metacontent;
+    *magick_restrict metacontent;
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   assert(id < (int) cache_info->number_threads);
   metacontent=GetVirtualMetacontentFromNexus(cache_info,
     cache_info->nexus_info[id]);
@@ -2238,14 +2389,14 @@ static const void *GetVirtualMetacontentFromCache(const Image *image)
 %
 */
 MagickPrivate const void *GetVirtualMetacontentFromNexus(const Cache cache,
-  NexusInfo *restrict nexus_info)
+  NexusInfo *magick_restrict nexus_info)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   assert(cache != (Cache) NULL);
   cache_info=(CacheInfo *) cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->storage_class == UndefinedClass)
     return((void *) NULL);
   return(nexus_info->metacontent);
@@ -2278,19 +2429,19 @@ MagickPrivate const void *GetVirtualMetacontentFromNexus(const Cache cache,
 MagickExport const void *GetVirtualMetacontent(const Image *image)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   const void
-    *restrict metacontent;
+    *magick_restrict metacontent;
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   metacontent=cache_info->methods.get_virtual_metacontent_from_handler(image);
   if (metacontent != (void *) NULL)
     return(metacontent);
@@ -2430,7 +2581,7 @@ MagickPrivate const Quantum *GetVirtualPixelsFromNexus(const Image *image,
   ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   MagickOffsetType
     offset;
@@ -2440,47 +2591,50 @@ MagickPrivate const Quantum *GetVirtualPixelsFromNexus(const Image *image,
     number_pixels;
 
   NexusInfo
-    **restrict virtual_nexus;
+    **magick_restrict virtual_nexus;
 
   Quantum
-    *restrict pixels,
+    *magick_restrict pixels,
     virtual_pixel[MaxPixelChannels];
 
   RectangleInfo
     region;
 
   register const Quantum
-    *restrict p;
+    *magick_restrict p;
 
   register const void
-    *restrict r;
+    *magick_restrict r;
 
   register Quantum
-    *restrict q;
+    *magick_restrict q;
 
   register ssize_t
     i,
     u;
 
   register unsigned char
-    *restrict s;
+    *magick_restrict s;
 
   ssize_t
     v;
 
   void
-    *restrict virtual_metacontent;
+    *magick_restrict virtual_metacontent;
 
   /*
     Acquire pixels.
   */
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->type == UndefinedCache)
     return((const Quantum *) NULL);
+#if defined(MAGICKCORE_OPENCL_SUPPORT)
+  CopyOpenCLBuffer(cache_info);
+#endif
   region.x=x;
   region.y=y;
   region.width=columns;
@@ -2525,8 +2679,6 @@ MagickPrivate const Quantum *GetVirtualPixelsFromNexus(const Image *image,
   virtual_nexus=AcquirePixelCacheNexus(1);
   if (virtual_nexus == (NexusInfo **) NULL)
     {
-      if (virtual_nexus != (NexusInfo **) NULL)
-        virtual_nexus=DestroyPixelCacheNexus(virtual_nexus,1);
       (void) ThrowMagickException(exception,GetMagickModule(),CacheError,
         "UnableToGetCacheNexus","`%s'",image->filename);
       return((const Quantum *) NULL);
@@ -2569,7 +2721,7 @@ MagickPrivate const Quantum *GetVirtualPixelsFromNexus(const Image *image,
         case BlackVirtualPixelMethod:
         {
           for (i=0; i < (ssize_t) cache_info->number_channels; i++)
-            SetPixelChannel(image,(PixelChannel) i,0,virtual_pixel);
+            SetPixelChannel(image,(PixelChannel) i,(Quantum) 0,virtual_pixel);
           SetPixelAlpha(image,OpaqueAlpha,virtual_pixel);
           break;
         }
@@ -2584,7 +2736,7 @@ MagickPrivate const Quantum *GetVirtualPixelsFromNexus(const Image *image,
         case TransparentVirtualPixelMethod:
         {
           for (i=0; i < (ssize_t) cache_info->number_channels; i++)
-            SetPixelChannel(image,(PixelChannel) i,0,virtual_pixel);
+            SetPixelChannel(image,(PixelChannel) i,(Quantum) 0,virtual_pixel);
           SetPixelAlpha(image,TransparentAlpha,virtual_pixel);
           break;
         }
@@ -2808,6 +2960,8 @@ MagickPrivate const Quantum *GetVirtualPixelsFromNexus(const Image *image,
           s+=length*cache_info->metacontent_extent;
         }
     }
+    if (u < (ssize_t) columns)
+      break;
   }
   /*
     Free resources.
@@ -2815,6 +2969,8 @@ MagickPrivate const Quantum *GetVirtualPixelsFromNexus(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);
 }
 \f
@@ -2857,19 +3013,19 @@ static const Quantum *GetVirtualPixelCache(const Image *image,
   const size_t columns,const size_t rows,ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   const Quantum
-    *restrict p;
+    *magick_restrict p;
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   assert(id < (int) cache_info->number_threads);
   p=GetVirtualPixelsFromNexus(image,virtual_pixel_method,x,y,columns,rows,
     cache_info->nexus_info[id],exception);
@@ -2902,16 +3058,16 @@ static const Quantum *GetVirtualPixelCache(const Image *image,
 MagickExport const Quantum *GetVirtualPixelQueue(const Image *image)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->methods.get_virtual_pixels_handler !=
        (GetVirtualPixelsHandler) NULL)
     return(cache_info->methods.get_virtual_pixels_handler(image));
@@ -2972,19 +3128,19 @@ MagickExport const Quantum *GetVirtualPixels(const Image *image,
   ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   const Quantum
-    *restrict p;
+    *magick_restrict p;
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->methods.get_virtual_pixel_handler !=
        (GetVirtualPixelHandler) NULL)
     return(cache_info->methods.get_virtual_pixel_handler(image,
@@ -3021,16 +3177,16 @@ MagickExport const Quantum *GetVirtualPixels(const Image *image,
 static const Quantum *GetVirtualPixelsCache(const Image *image)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   assert(id < (int) cache_info->number_threads);
   return(GetVirtualPixelsNexus(image->cache,cache_info->nexus_info[id]));
 }
@@ -3062,14 +3218,14 @@ static const Quantum *GetVirtualPixelsCache(const Image *image)
 %
 */
 MagickPrivate const Quantum *GetVirtualPixelsNexus(const Cache cache,
-  NexusInfo *restrict nexus_info)
+  NexusInfo *magick_restrict nexus_info)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   assert(cache != (Cache) NULL);
   cache_info=(CacheInfo *) cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->storage_class == UndefinedClass)
     return((Quantum *) NULL);
   return((const Quantum *) nexus_info->pixels);
@@ -3106,19 +3262,6 @@ MagickPrivate const Quantum *GetVirtualPixelsNexus(const Cache cache,
 %
 */
 
-static inline void AllocatePixelCachePixels(CacheInfo *cache_info)
-{
-  cache_info->mapped=MagickFalse;
-  cache_info->pixels=(Quantum *) MagickAssumeAligned(AcquireAlignedMemory(1,
-    (size_t) cache_info->length));
-  if (cache_info->pixels == (Quantum *) NULL)
-    {
-      cache_info->mapped=MagickTrue;
-      cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
-        cache_info->length);
-    }
-}
-
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {
 #endif
@@ -3143,8 +3286,8 @@ static MagickBooleanType OpenPixelCacheOnDisk(CacheInfo *cache_info,
   /*
     Open pixel cache on disk.
   */
-  if (cache_info->file != -1)
-    return(MagickTrue);  /* cache already open */
+  if ((cache_info->file != -1) && (cache_info->mode == mode))
+    return(MagickTrue);  /* cache already open and in the proper mode */
   if (*cache_info->cache_filename == '\0')
     file=AcquireUniqueFileResource(cache_info->cache_filename);
   else
@@ -3176,14 +3319,15 @@ static MagickBooleanType OpenPixelCacheOnDisk(CacheInfo *cache_info,
   if (file == -1)
     return(MagickFalse);
   (void) AcquireMagickResource(FileResource,1);
+  if (cache_info->file != -1)
+    (void) ClosePixelCacheOnDisk(cache_info);
   cache_info->file=file;
-  cache_info->mode=mode;
   return(MagickTrue);
 }
 
 static inline MagickOffsetType WritePixelCacheRegion(
-  const CacheInfo *restrict cache_info,const MagickOffsetType offset,
-  const MagickSizeType length,const unsigned char *restrict buffer)
+  const CacheInfo *magick_restrict cache_info,const MagickOffsetType offset,
+  const MagickSizeType length,const unsigned char *magick_restrict buffer)
 {
   register MagickOffsetType
     i;
@@ -3199,11 +3343,11 @@ static inline MagickOffsetType WritePixelCacheRegion(
   for (i=0; i < (MagickOffsetType) length; i+=count)
   {
 #if !defined(MAGICKCORE_HAVE_PWRITE)
-    count=write(cache_info->file,buffer+i,(size_t) MagickMin(length-i,
-      (MagickSizeType) SSIZE_MAX));
+    count=write(cache_info->file,buffer+i,(size_t) MagickMin(length-i,(size_t)
+      SSIZE_MAX));
 #else
-    count=pwrite(cache_info->file,buffer+i,(size_t) MagickMin(length-i,
-      (MagickSizeType) SSIZE_MAX),(off_t) (offset+i));
+    count=pwrite(cache_info->file,buffer+i,(size_t) MagickMin(length-i,(size_t)
+      SSIZE_MAX),(off_t) (offset+i));
 #endif
     if (count <= 0)
       {
@@ -3218,7 +3362,7 @@ static inline MagickOffsetType WritePixelCacheRegion(
 static MagickBooleanType SetPixelCacheExtent(Image *image,MagickSizeType length)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   MagickOffsetType
     count,
@@ -3229,11 +3373,11 @@ static MagickBooleanType SetPixelCacheExtent(Image *image,MagickSizeType length)
   if (image->debug != MagickFalse)
     {
       char
-        format[MaxTextExtent],
-        message[MaxTextExtent];
+        format[MagickPathExtent],
+        message[MagickPathExtent];
 
-      (void) FormatMagickSize(length,MagickFalse,"B",format);
-      (void) FormatLocaleString(message,MaxTextExtent,
+      (void) FormatMagickSize(length,MagickFalse,"B",MagickPathExtent,format);
+      (void) FormatLocaleString(message,MagickPathExtent,
         "extend %s (%s[%d], disk, %s)",cache_info->filename,
         cache_info->cache_filename,cache_info->file,format);
       (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",message);
@@ -3244,29 +3388,38 @@ static MagickBooleanType SetPixelCacheExtent(Image *image,MagickSizeType length)
   if (offset < 0)
     return(MagickFalse);
   if ((MagickSizeType) offset >= length)
-    return(MagickTrue);
-  extent=(MagickOffsetType) length-1;
-  count=WritePixelCacheRegion(cache_info,extent,1,(const unsigned char *) "");
+    count=(MagickOffsetType) 1;
+  else
+    {
+      extent=(MagickOffsetType) length-1;
+      count=WritePixelCacheRegion(cache_info,extent,1,(const unsigned char *)
+        "");
+      if (count != 1)
+        return(MagickFalse);
 #if defined(MAGICKCORE_HAVE_POSIX_FALLOCATE)
-  if (cache_info->synchronize != MagickFalse)
-    (void) posix_fallocate(cache_info->file,offset+1,extent-offset);
+      if (cache_info->synchronize != MagickFalse)
+        (void) posix_fallocate(cache_info->file,offset+1,extent-offset);
 #endif
 #if defined(SIGBUS)
-  (void) signal(SIGBUS,CacheSignalHandler);
+      (void) signal(SIGBUS,CacheSignalHandler);
 #endif
-  return(count != (MagickOffsetType) 1 ? MagickFalse : MagickTrue);
+    }
+  offset=(MagickOffsetType) lseek(cache_info->file,0,SEEK_SET);
+  if (offset < 0)
+    return(MagickFalse);
+  return(MagickTrue);
 }
 
 static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
   ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info,
+    *magick_restrict cache_info,
     source_info;
 
   char
-    format[MaxTextExtent],
-    message[MaxTextExtent];
+    format[MagickPathExtent],
+    message[MagickPathExtent];
 
   const char
     *type;
@@ -3283,21 +3436,45 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
     packet_size;
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+  if (cache_anonymous_memory < 0)
+    {
+      char
+        *value;
+
+      /*
+        Does the security policy require anonymous mapping for pixel cache?
+      */
+      cache_anonymous_memory=0;
+      value=GetPolicyValue("pixel-cache-memory");
+      if (value == (char *) NULL)
+        value=GetPolicyValue("cache:memory-map");
+      if (LocaleCompare(value,"anonymous") == 0)
+        {
+#if defined(MAGICKCORE_HAVE_MMAP) && defined(MAP_ANONYMOUS)
+          cache_anonymous_memory=1;
+#else
+          (void) ThrowMagickException(exception,GetMagickModule(),
+            MissingDelegateError,"DelegateLibrarySupportNotBuiltIn",
+            "'%s' (policy requires anonymous memory mapping)",image->filename);
+#endif
+        }
+      value=DestroyString(value);
+    }
   if ((image->columns == 0) || (image->rows == 0))
     ThrowBinaryException(CacheError,"NoPixelsDefinedInCache",image->filename);
+  cache_info=(CacheInfo *) image->cache;
+  assert(cache_info->signature == MagickCoreSignature);
   if ((AcquireMagickResource(WidthResource,image->columns) == MagickFalse) ||
       (AcquireMagickResource(HeightResource,image->rows) == MagickFalse))
-    ThrowBinaryException(ResourceLimitError,"PixelCacheAllocationFailed",
+    ThrowBinaryException(ImageError,"WidthOrHeightExceedsLimit",
       image->filename);
-  cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
   source_info=(*cache_info);
   source_info.file=(-1);
-  (void) FormatLocaleString(cache_info->filename,MaxTextExtent,"%s[%.20g]",
+  (void) FormatLocaleString(cache_info->filename,MagickPathExtent,"%s[%.20g]",
     image->filename,(double) GetImageIndexInList(image));
   cache_info->storage_class=image->storage_class;
   cache_info->colorspace=image->colorspace;
@@ -3312,14 +3489,6 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
     sizeof(*image->channel_map));
   cache_info->metacontent_extent=image->metacontent_extent;
   cache_info->mode=mode;
-  if (image->ping != MagickFalse)
-    {
-      cache_info->type=PingCache;
-      cache_info->pixels=(Quantum *) NULL;
-      cache_info->metacontent=(void *) NULL;
-      cache_info->length=0;
-      return(MagickTrue);
-    }
   number_pixels=(MagickSizeType) cache_info->columns*cache_info->rows;
   packet_size=cache_info->number_channels*sizeof(Quantum);
   if (image->metacontent_extent != 0)
@@ -3331,6 +3500,13 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
     ThrowBinaryException(ResourceLimitError,"PixelCacheAllocationFailed",
       image->filename);
   cache_info->length=length;
+  if (image->ping != MagickFalse)
+    {
+      cache_info->storage_class=image->storage_class;
+      cache_info->colorspace=image->colorspace;
+      cache_info->type=PingCache;
+      return(MagickTrue);
+    }
   status=AcquireMagickResource(AreaResource,cache_info->length);
   length=number_pixels*(cache_info->number_channels*sizeof(Quantum)+
     cache_info->metacontent_extent);
@@ -3340,7 +3516,19 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
       if (((cache_info->type == UndefinedCache) && (status != MagickFalse)) ||
           (cache_info->type == MemoryCache))
         {
-          AllocatePixelCachePixels(cache_info);
+          status=MagickTrue;
+          if (cache_anonymous_memory <= 0)
+            {
+              cache_info->mapped=MagickFalse;
+              cache_info->pixels=(Quantum *) MagickAssumeAligned(
+                AcquireAlignedMemory(1,(size_t) cache_info->length));
+            }
+          else
+            {
+              cache_info->mapped=MagickTrue;
+              cache_info->pixels=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
+                cache_info->length);
+            }
           if (cache_info->pixels == (Quantum *) NULL)
             cache_info->pixels=source_info.pixels;
           else
@@ -3348,7 +3536,6 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
               /*
                 Create memory pixel cache.
               */
-              status=MagickTrue;
               cache_info->type=MemoryCache;
               cache_info->metacontent=(void *) NULL;
               if (cache_info->metacontent_extent != 0)
@@ -3364,10 +3551,10 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
               if (image->debug != MagickFalse)
                 {
                   (void) FormatMagickSize(cache_info->length,MagickTrue,"B",
-                    format);
+                    MagickPathExtent,format);
                   type=CommandOptionToMnemonic(MagickCacheOptions,(ssize_t)
                     cache_info->type);
-                  (void) FormatLocaleString(message,MaxTextExtent,
+                  (void) FormatLocaleString(message,MagickPathExtent,
                     "open %s (%s %s, %.20gx%.20gx%.20g %s)",
                     cache_info->filename,cache_info->mapped != MagickFalse ?
                     "Anonymous" : "Heap",type,(double) cache_info->columns,
@@ -3376,7 +3563,7 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
                   (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",
                     message);
                 }
-              return(status);
+              return(status == 0 ? MagickFalse : MagickTrue);
             }
         }
       RelinquishMagickResource(MemoryResource,cache_info->length);
@@ -3407,10 +3594,11 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
               /*
                 Create a distributed pixel cache.
               */
+              status=MagickTrue;
               cache_info->type=DistributedCache;
               cache_info->server_info=server_info;
               (void) FormatLocaleString(cache_info->cache_filename,
-                MaxTextExtent,"%s:%d",GetDistributeCacheHostname(
+                MagickPathExtent,"%s:%d",GetDistributeCacheHostname(
                 (DistributeCacheInfo *) cache_info->server_info),
                 GetDistributeCachePort((DistributeCacheInfo *)
                 cache_info->server_info));
@@ -3424,10 +3612,10 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
               if (image->debug != MagickFalse)
                 {
                   (void) FormatMagickSize(cache_info->length,MagickFalse,"B",
-                    format);
+                    MagickPathExtent,format);
                   type=CommandOptionToMnemonic(MagickCacheOptions,(ssize_t)
                     cache_info->type);
-                  (void) FormatLocaleString(message,MaxTextExtent,
+                  (void) FormatLocaleString(message,MagickPathExtent,
                     "open %s (%s[%d], %s, %.20gx%.20gx%.20g %s)",
                     cache_info->filename,cache_info->cache_filename,
                     GetDistributeCacheFile((DistributeCacheInfo *)
@@ -3437,7 +3625,7 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
                   (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",
                     message);
                 }
-              return(MagickTrue);
+              return(status == 0 ? MagickFalse : MagickTrue);
             }
         }
       RelinquishMagickResource(DiskResource,cache_info->length);
@@ -3474,9 +3662,13 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
       status=AcquireMagickResource(MapResource,cache_info->length);
       if ((status == MagickFalse) && (cache_info->type != MapCache) &&
           (cache_info->type != MemoryCache))
-        cache_info->type=DiskCache;
+        {
+          status=MagickTrue;
+          cache_info->type=DiskCache;
+        }
       else
         {
+          status=MagickTrue;
           cache_info->pixels=(Quantum *) MapBlob(cache_info->file,mode,
             cache_info->offset,(size_t) cache_info->length);
           if (cache_info->pixels == (Quantum *) NULL)
@@ -3489,7 +3681,6 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
               /*
                 Create file-backed memory-mapped pixel cache.
               */
-              status=MagickTrue;
               (void) ClosePixelCacheOnDisk(cache_info);
               cache_info->type=MapCache;
               cache_info->mapped=MagickTrue;
@@ -3507,10 +3698,10 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
               if (image->debug != MagickFalse)
                 {
                   (void) FormatMagickSize(cache_info->length,MagickTrue,"B",
-                    format);
+                    MagickPathExtent,format);
                   type=CommandOptionToMnemonic(MagickCacheOptions,(ssize_t)
                     cache_info->type);
-                  (void) FormatLocaleString(message,MaxTextExtent,
+                  (void) FormatLocaleString(message,MagickPathExtent,
                     "open %s (%s[%d], %s, %.20gx%.20gx%.20g %s)",
                     cache_info->filename,cache_info->cache_filename,
                     cache_info->file,type,(double) cache_info->columns,(double)
@@ -3519,7 +3710,7 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
                   (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",
                     message);
                 }
-              return(status);
+              return(status == 0 ? MagickFalse : MagickTrue);
             }
         }
       RelinquishMagickResource(MapResource,cache_info->length);
@@ -3532,17 +3723,18 @@ static MagickBooleanType OpenPixelCache(Image *image,const MapMode mode,
     }
   if (image->debug != MagickFalse)
     {
-      (void) FormatMagickSize(cache_info->length,MagickFalse,"B",format);
+      (void) FormatMagickSize(cache_info->length,MagickFalse,"B",
+        MagickPathExtent,format);
       type=CommandOptionToMnemonic(MagickCacheOptions,(ssize_t)
         cache_info->type);
-      (void) FormatLocaleString(message,MaxTextExtent,
+      (void) FormatLocaleString(message,MagickPathExtent,
         "open %s (%s[%d], %s, %.20gx%.20gx%.20g %s)",cache_info->filename,
         cache_info->cache_filename,cache_info->file,type,(double)
         cache_info->columns,(double) cache_info->rows,(double)
         cache_info->number_channels,format);
       (void) LogMagickEvent(CacheEvent,GetMagickModule(),"%s",message);
     }
-  return(status);
+  return(status == 0 ? MagickFalse : MagickTrue);
 }
 \f
 /*
@@ -3587,8 +3779,8 @@ MagickExport MagickBooleanType PersistPixelCache(Image *image,
   ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info,
-    *restrict clone_info;
+    *magick_restrict cache_info,
+    *magick_restrict clone_info;
 
   Image
     clone_image;
@@ -3600,7 +3792,7 @@ MagickExport MagickBooleanType PersistPixelCache(Image *image,
     page_size;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(image->cache != (void *) NULL);
@@ -3608,7 +3800,10 @@ MagickExport MagickBooleanType PersistPixelCache(Image *image,
   assert(offset != (MagickOffsetType *) NULL);
   page_size=GetMagickPageSize();
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
+#if defined(MAGICKCORE_OPENCL_SUPPORT)
+  CopyOpenCLBuffer(cache_info);
+#endif
   if (attach != MagickFalse)
     {
       /*
@@ -3618,7 +3813,7 @@ MagickExport MagickBooleanType PersistPixelCache(Image *image,
         (void) LogMagickEvent(CacheEvent,GetMagickModule(),
           "attach persistent cache");
       (void) CopyMagickString(cache_info->cache_filename,filename,
-        MaxTextExtent);
+        MagickPathExtent);
       cache_info->type=DiskCache;
       cache_info->offset=(*offset);
       if (OpenPixelCache(image,ReadMode,exception) == MagickFalse)
@@ -3626,38 +3821,6 @@ MagickExport MagickBooleanType PersistPixelCache(Image *image,
       *offset+=cache_info->length+page_size-(cache_info->length % page_size);
       return(MagickTrue);
     }
-  if ((cache_info->mode != ReadMode) &&
-      ((cache_info->type == DiskCache) || (cache_info->type == MapCache)) &&
-      (cache_info->reference_count == 1))
-    {
-      LockSemaphoreInfo(cache_info->semaphore);
-      if ((cache_info->mode != ReadMode) &&
-          ((cache_info->type == DiskCache) || (cache_info->type == MapCache)) &&
-          (cache_info->reference_count == 1))
-        {
-          int
-            status;
-
-          /*
-            Usurp existing persistent pixel cache.
-          */
-          status=rename_utf8(cache_info->cache_filename,filename);
-          if (status == 0)
-            {
-              (void) CopyMagickString(cache_info->cache_filename,filename,
-                MaxTextExtent);
-              *offset+=cache_info->length+page_size-(cache_info->length %
-                page_size);
-              UnlockSemaphoreInfo(cache_info->semaphore);
-              cache_info=(CacheInfo *) ReferencePixelCache(cache_info);
-              if (image->debug != MagickFalse)
-                (void) LogMagickEvent(CacheEvent,GetMagickModule(),
-                  "Usurp resident persistent cache");
-              return(MagickTrue);
-            }
-        }
-      UnlockSemaphoreInfo(cache_info->semaphore);
-    }
   /*
     Clone persistent pixel cache.
   */
@@ -3665,7 +3828,7 @@ MagickExport MagickBooleanType PersistPixelCache(Image *image,
   clone_info=(CacheInfo *) clone_image.cache;
   image->cache=ClonePixelCache(cache_info);
   cache_info=(CacheInfo *) ReferencePixelCache(image->cache);
-  (void) CopyMagickString(cache_info->cache_filename,filename,MaxTextExtent);
+  (void) CopyMagickString(cache_info->cache_filename,filename,MagickPathExtent);
   cache_info->type=DiskCache;
   cache_info->offset=(*offset);
   cache_info=(CacheInfo *) image->cache;
@@ -3720,7 +3883,7 @@ MagickPrivate Quantum *QueueAuthenticPixelCacheNexus(Image *image,
   const MagickBooleanType clone,NexusInfo *nexus_info,ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   MagickOffsetType
     offset;
@@ -3729,7 +3892,7 @@ MagickPrivate Quantum *QueueAuthenticPixelCacheNexus(Image *image,
     number_pixels;
 
   Quantum
-    *restrict pixels;
+    *magick_restrict pixels;
 
   RectangleInfo
     region;
@@ -3738,12 +3901,12 @@ MagickPrivate Quantum *QueueAuthenticPixelCacheNexus(Image *image,
     Validate pixel cache geometry.
   */
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) GetImagePixelCache(image,clone,exception);
   if (cache_info == (Cache) NULL)
     return((Quantum *) NULL);
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if ((cache_info->columns == 0) || (cache_info->rows == 0) || (x < 0) ||
       (y < 0) || (x >= (ssize_t) cache_info->columns) ||
       (y >= (ssize_t) cache_info->rows))
@@ -3809,19 +3972,19 @@ static Quantum *QueueAuthenticPixelsCache(Image *image,const ssize_t x,
   ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   Quantum
-    *restrict pixels;
+    *magick_restrict pixels;
 
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   assert(id < (int) cache_info->number_threads);
   pixels=QueueAuthenticPixelCacheNexus(image,x,y,columns,rows,MagickFalse,
     cache_info->nexus_info[id],exception);
@@ -3889,19 +4052,19 @@ MagickExport Quantum *QueueAuthenticPixels(Image *image,const ssize_t x,
   ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
 
   Quantum
-    *restrict pixels;
+    *magick_restrict pixels;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->methods.queue_authentic_pixels_handler !=
       (QueueAuthenticPixelsHandler) NULL)
     {
@@ -3945,8 +4108,8 @@ MagickExport Quantum *QueueAuthenticPixels(Image *image,const ssize_t x,
 */
 
 static inline MagickOffsetType ReadPixelCacheRegion(
-  const CacheInfo *restrict cache_info,const MagickOffsetType offset,
-  const MagickSizeType length,unsigned char *restrict buffer)
+  const CacheInfo *magick_restrict cache_info,const MagickOffsetType offset,
+  const MagickSizeType length,unsigned char *magick_restrict buffer)
 {
   register MagickOffsetType
     i;
@@ -3962,11 +4125,11 @@ static inline MagickOffsetType ReadPixelCacheRegion(
   for (i=0; i < (MagickOffsetType) length; i+=count)
   {
 #if !defined(MAGICKCORE_HAVE_PREAD)
-    count=read(cache_info->file,buffer+i,(size_t) MagickMin(length-i,
-      (MagickSizeType) SSIZE_MAX));
+    count=read(cache_info->file,buffer+i,(size_t) MagickMin(length-i,(size_t)
+      SSIZE_MAX));
 #else
-    count=pread(cache_info->file,buffer+i,(size_t) MagickMin(length-i,
-      (MagickSizeType) SSIZE_MAX),(off_t) (offset+i));
+    count=pread(cache_info->file,buffer+i,(size_t) MagickMin(length-i,(size_t)
+      SSIZE_MAX),(off_t) (offset+i));
 #endif
     if (count <= 0)
       {
@@ -3979,7 +4142,7 @@ static inline MagickOffsetType ReadPixelCacheRegion(
 }
 
 static MagickBooleanType ReadPixelCacheMetacontent(
-  CacheInfo *restrict cache_info,NexusInfo *restrict nexus_info,
+  CacheInfo *magick_restrict cache_info,NexusInfo *magick_restrict nexus_info,
   ExceptionInfo *exception)
 {
   MagickOffsetType
@@ -3994,7 +4157,7 @@ static MagickBooleanType ReadPixelCacheMetacontent(
     y;
 
   register unsigned char
-    *restrict q;
+    *magick_restrict q;
 
   size_t
     rows;
@@ -4017,7 +4180,7 @@ static MagickBooleanType ReadPixelCacheMetacontent(
     case MapCache:
     {
       register unsigned char
-        *restrict p;
+        *magick_restrict p;
 
       /*
         Read meta-content from memory.
@@ -4149,8 +4312,9 @@ static MagickBooleanType ReadPixelCacheMetacontent(
 %    o exception: return any errors or warnings in this structure.
 %
 */
-static MagickBooleanType ReadPixelCachePixels(CacheInfo *restrict cache_info,
-  NexusInfo *restrict nexus_info,ExceptionInfo *exception)
+static MagickBooleanType ReadPixelCachePixels(
+  CacheInfo *magick_restrict cache_info,NexusInfo *magick_restrict nexus_info,
+  ExceptionInfo *exception)
 {
   MagickOffsetType
     count,
@@ -4161,22 +4325,30 @@ static MagickBooleanType ReadPixelCachePixels(CacheInfo *restrict cache_info,
     length;
 
   register Quantum
-    *restrict q;
+    *magick_restrict q;
 
   register ssize_t
     y;
 
   size_t
+    number_channels,
     rows;
 
   if (nexus_info->authentic_pixel_cache != MagickFalse)
     return(MagickTrue);
-  offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns+
-    nexus_info->region.x;
-  length=(MagickSizeType) cache_info->number_channels*nexus_info->region.width*
+  offset=(MagickOffsetType) nexus_info->region.y*cache_info->columns;
+  if ((ssize_t) (offset/cache_info->columns) != nexus_info->region.y)
+    return(MagickFalse);
+  offset+=nexus_info->region.x;
+  number_channels=cache_info->number_channels;
+  length=(MagickSizeType) number_channels*nexus_info->region.width*
     sizeof(Quantum);
-  extent=length*nexus_info->region.height;
+  if ((length/number_channels/sizeof(Quantum)) != nexus_info->region.width)
+    return(MagickFalse);
   rows=nexus_info->region.height;
+  extent=length*rows;
+  if ((extent == 0) || ((extent/length) != rows))
+    return(MagickFalse);
   y=0;
   q=nexus_info->pixels;
   switch (cache_info->type)
@@ -4185,7 +4357,7 @@ static MagickBooleanType ReadPixelCachePixels(CacheInfo *restrict cache_info,
     case MapCache:
     {
       register Quantum
-        *restrict p;
+        *magick_restrict p;
 
       /*
         Read pixels from memory.
@@ -4312,11 +4484,11 @@ static MagickBooleanType ReadPixelCachePixels(CacheInfo *restrict cache_info,
 MagickPrivate Cache ReferencePixelCache(Cache cache)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   assert(cache != (Cache *) NULL);
   cache_info=(CacheInfo *) cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   LockSemaphoreInfo(cache_info->semaphore);
   cache_info->reference_count++;
   UnlockSemaphoreInfo(cache_info->semaphore);
@@ -4328,6 +4500,64 @@ MagickPrivate Cache ReferencePixelCache(Cache cache)
 %                                                                             %
 %                                                                             %
 %                                                                             %
++   R e s e t P i x e l C a c h e C h a n n e l s                             %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  ResetPixelCacheChannels() resets the pixel cache channels.
+%
+%  The format of the ResetPixelCacheChannels method is:
+%
+%      void ResetPixelCacheChannels(Image *)
+%
+%  A description of each parameter follows:
+%
+%    o image: the image.
+%
+*/
+MagickPrivate void ResetPixelCacheChannels(Image *image)
+{
+  CacheInfo
+    *magick_restrict cache_info;
+
+  assert(image != (const Image *) NULL);
+  assert(image->signature == MagickCoreSignature);
+  assert(image->cache != (Cache) NULL);
+  cache_info=(CacheInfo *) image->cache;
+  assert(cache_info->signature == MagickCoreSignature);
+  cache_info->number_channels=GetPixelChannels(image);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
++   R e s e t P i x e l C a c h e E p o c h                                   %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  ResetPixelCacheEpoch() resets the pixel cache epoch.
+%
+%  The format of the ResetPixelCacheEpoch method is:
+%
+%      void ResetPixelCacheEpoch(void)
+%
+*/
+MagickPrivate void ResetPixelCacheEpoch(void)
+{
+  cache_epoch=0;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 +   S e t P i x e l C a c h e M e t h o d s                                   %
 %                                                                             %
 %                                                                             %
@@ -4350,7 +4580,7 @@ MagickPrivate Cache ReferencePixelCache(Cache cache)
 MagickPrivate void SetPixelCacheMethods(Cache cache,CacheMethods *cache_methods)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   GetOneAuthenticPixelFromHandler
     get_one_authentic_pixel_from_handler;
@@ -4364,7 +4594,7 @@ MagickPrivate void SetPixelCacheMethods(Cache cache,CacheMethods *cache_methods)
   assert(cache != (Cache) NULL);
   assert(cache_methods != (CacheMethods *) NULL);
   cache_info=(CacheInfo *) cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       cache_info->filename);
@@ -4448,15 +4678,21 @@ MagickPrivate void SetPixelCacheMethods(Cache cache,CacheMethods *cache_methods)
 */
 
 static inline MagickBooleanType AcquireCacheNexusPixels(
-  const CacheInfo *restrict cache_info,NexusInfo *nexus_info,
+  const CacheInfo *magick_restrict cache_info,NexusInfo *nexus_info,
   ExceptionInfo *exception)
 {
   if (nexus_info->length != (MagickSizeType) ((size_t) nexus_info->length))
     return(MagickFalse);
-  nexus_info->mapped=MagickFalse;
-  nexus_info->cache=(Quantum *) MagickAssumeAligned(AcquireAlignedMemory(1,
-    (size_t) nexus_info->length));
-  if (nexus_info->cache == (Quantum *) NULL)
+  if (cache_anonymous_memory <= 0)
+    {
+      nexus_info->mapped=MagickFalse;
+      nexus_info->cache=(Quantum *) MagickAssumeAligned(AcquireAlignedMemory(1,
+        (size_t) nexus_info->length));
+      if (nexus_info->cache != (Quantum *) NULL)
+        (void) ResetMagickMemory(nexus_info->cache,0,(size_t)
+          nexus_info->length);
+    }
+  else
     {
       nexus_info->mapped=MagickTrue;
       nexus_info->cache=(Quantum *) MapBlob(-1,IOMode,0,(size_t)
@@ -4473,7 +4709,8 @@ static inline MagickBooleanType AcquireCacheNexusPixels(
 }
 
 static inline MagickBooleanType IsPixelCacheAuthentic(
-  const CacheInfo *restrict cache_info,const NexusInfo *restrict nexus_info)
+  const CacheInfo *magick_restrict cache_info,
+  const NexusInfo *magick_restrict nexus_info)
 {
   MagickBooleanType
     status;
@@ -4516,7 +4753,7 @@ static Quantum *SetPixelCacheNexusPixels(const CacheInfo *cache_info,
     number_pixels;
 
   assert(cache_info != (const CacheInfo *) NULL);
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->type == UndefinedCache)
     return((Quantum *) NULL);
   nexus_info->region=(*region);
@@ -4629,10 +4866,10 @@ static MagickBooleanType SetCacheAlphaChannel(Image *image,const Quantum alpha,
   ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   CacheView
-    *restrict image_view;
+    *magick_restrict image_view;
 
   MagickBooleanType
     status;
@@ -4641,12 +4878,12 @@ static MagickBooleanType SetCacheAlphaChannel(Image *image,const Quantum alpha,
     y;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   image->alpha_trait=BlendPixelTrait;
   status=MagickTrue;
   image_view=AcquireVirtualCacheView(image,exception);  /* must be virtual */
@@ -4657,7 +4894,7 @@ static MagickBooleanType SetCacheAlphaChannel(Image *image,const Quantum alpha,
   for (y=0; y < (ssize_t) image->rows; y++)
   {
     register Quantum
-      *restrict q;
+      *magick_restrict q;
 
     register ssize_t
       x;
@@ -4685,18 +4922,18 @@ MagickPrivate VirtualPixelMethod SetPixelCacheVirtualMethod(Image *image,
   const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   VirtualPixelMethod
     method;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   method=cache_info->virtual_pixel_method;
   cache_info->virtual_pixel_method=virtual_pixel_method;
   if ((image->columns != 0) && (image->rows != 0))
@@ -4723,6 +4960,58 @@ MagickPrivate VirtualPixelMethod SetPixelCacheVirtualMethod(Image *image,
     }
   return(method);
 }
+
+#if defined(MAGICKCORE_OPENCL_SUPPORT)
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
++   S y n c A u t h e n t i c O p e n C L B u f f e r                         %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  SyncAuthenticOpenCLBuffer() makes sure that all the OpenCL operations have
+%  been completed and updates the host memory.
+%
+%  The format of the SyncAuthenticOpenCLBuffer() method is:
+%
+%      void SyncAuthenticOpenCLBuffer(const Image *image)
+%
+%  A description of each parameter follows:
+%
+%    o image: the image.
+%
+*/
+
+static void CopyOpenCLBuffer(CacheInfo *magick_restrict cache_info)
+{
+  assert(cache_info != (CacheInfo *) NULL);
+  assert(cache_info->signature == MagickCoreSignature);
+  if ((cache_info->type != MemoryCache) ||
+      (cache_info->opencl == (MagickCLCacheInfo) NULL))
+    return;
+  /*
+    Ensure single threaded access to OpenCL environment.
+  */
+  LockSemaphoreInfo(cache_info->semaphore);
+  cache_info->opencl=(MagickCLCacheInfo) CopyMagickCLCacheInfo(
+    cache_info->opencl);
+  UnlockSemaphoreInfo(cache_info->semaphore);
+}
+
+MagickPrivate void SyncAuthenticOpenCLBuffer(const Image *image)
+{
+  CacheInfo
+    *magick_restrict cache_info;
+
+  assert(image != (const Image *) NULL);
+  cache_info=(CacheInfo *) image->cache;
+  CopyOpenCLBuffer(cache_info);
+}
+#endif
 \f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -4754,10 +5043,10 @@ MagickPrivate VirtualPixelMethod SetPixelCacheVirtualMethod(Image *image,
 %
 */
 MagickPrivate MagickBooleanType SyncAuthenticPixelCacheNexus(Image *image,
-  NexusInfo *restrict nexus_info,ExceptionInfo *exception)
+  NexusInfo *magick_restrict nexus_info,ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   MagickBooleanType
     status;
@@ -4766,11 +5055,11 @@ MagickPrivate MagickBooleanType SyncAuthenticPixelCacheNexus(Image *image,
     Transfer pixels to the cache.
   */
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->cache == (Cache) NULL)
     ThrowBinaryException(CacheError,"PixelCacheIsNotOpen",image->filename);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->type == UndefinedCache)
     return(MagickFalse);
   if (nexus_info->authentic_pixel_cache != MagickFalse)
@@ -4778,7 +5067,7 @@ MagickPrivate MagickBooleanType SyncAuthenticPixelCacheNexus(Image *image,
       image->taint=MagickTrue;
       return(MagickTrue);
     }
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   status=WritePixelCachePixels(cache_info,nexus_info,exception);
   if ((cache_info->metacontent_extent != 0) &&
       (WritePixelCacheMetacontent(cache_info,nexus_info,exception) == MagickFalse))
@@ -4819,7 +5108,7 @@ static MagickBooleanType SyncAuthenticPixelsCache(Image *image,
   ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
@@ -4828,10 +5117,10 @@ static MagickBooleanType SyncAuthenticPixelsCache(Image *image,
     status;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   assert(id < (int) cache_info->number_threads);
   status=SyncAuthenticPixelCacheNexus(image,cache_info->nexus_info[id],
     exception);
@@ -4869,7 +5158,7 @@ MagickExport MagickBooleanType SyncAuthenticPixels(Image *image,
   ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   const int
     id = GetOpenMPThreadId();
@@ -4878,10 +5167,10 @@ MagickExport MagickBooleanType SyncAuthenticPixels(Image *image,
     status;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(image->cache != (Cache) NULL);
   cache_info=(CacheInfo *) image->cache;
-  assert(cache_info->signature == MagickSignature);
+  assert(cache_info->signature == MagickCoreSignature);
   if (cache_info->methods.sync_authentic_pixels_handler !=
        (SyncAuthenticPixelsHandler) NULL)
     {
@@ -4926,7 +5215,7 @@ MagickPrivate MagickBooleanType SyncImagePixelCache(Image *image,
   ExceptionInfo *exception)
 {
   CacheInfo
-    *restrict cache_info;
+    *magick_restrict cache_info;
 
   assert(image != (Image *) NULL);
   assert(exception != (ExceptionInfo *) NULL);
@@ -4963,7 +5252,7 @@ MagickPrivate MagickBooleanType SyncImagePixelCache(Image *image,
 %
 */
 static MagickBooleanType WritePixelCacheMetacontent(CacheInfo *cache_info,
-  NexusInfo *restrict nexus_info,ExceptionInfo *exception)
+  NexusInfo *magick_restrict nexus_info,ExceptionInfo *exception)
 {
   MagickOffsetType
     count,
@@ -4974,7 +5263,7 @@ static MagickBooleanType WritePixelCacheMetacontent(CacheInfo *cache_info,
     length;
 
   register const unsigned char
-    *restrict p;
+    *magick_restrict p;
 
   register ssize_t
     y;
@@ -5000,7 +5289,7 @@ static MagickBooleanType WritePixelCacheMetacontent(CacheInfo *cache_info,
     case MapCache:
     {
       register unsigned char
-        *restrict q;
+        *magick_restrict q;
 
       /*
         Write associated pixels to memory.
@@ -5132,8 +5421,9 @@ static MagickBooleanType WritePixelCacheMetacontent(CacheInfo *cache_info,
 %    o exception: return any errors or warnings in this structure.
 %
 */
-static MagickBooleanType WritePixelCachePixels(CacheInfo *restrict cache_info,
-  NexusInfo *restrict nexus_info,ExceptionInfo *exception)
+static MagickBooleanType WritePixelCachePixels(
+  CacheInfo *magick_restrict cache_info,NexusInfo *magick_restrict nexus_info,
+  ExceptionInfo *exception)
 {
   MagickOffsetType
     count,
@@ -5144,7 +5434,7 @@ static MagickBooleanType WritePixelCachePixels(CacheInfo *restrict cache_info,
     length;
 
   register const Quantum
-    *restrict p;
+    *magick_restrict p;
 
   register ssize_t
     y;
@@ -5168,7 +5458,7 @@ static MagickBooleanType WritePixelCachePixels(CacheInfo *restrict cache_info,
     case MapCache:
     {
       register Quantum
-        *restrict q;
+        *magick_restrict q;
 
       /*
         Write pixels to memory.