]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/cache-view.c
Update web pages
[imagemagick] / MagickCore / cache-view.c
index 5127bdb89e479e17d582b3cc435ce7687b4eddf3..7453aee9bb9a6c439373f21bdf02be88fe61e0ae 100644 (file)
 %                        MagickCore Cache View Methods                        %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                               February 2000                                 %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2015 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  %
@@ -51,6 +51,7 @@
 #include "MagickCore/cache-private.h"
 #include "MagickCore/cache-view.h"
 #include "MagickCore/memory_.h"
+#include "MagickCore/memory-private.h"
 #include "MagickCore/exception.h"
 #include "MagickCore/exception-private.h"
 #include "MagickCore/pixel-accessor.h"
@@ -94,6 +95,7 @@ struct _CacheView
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  AcquireAuthenticCacheView() acquires an authentic view into the pixel cache.
+%  It always succeeds but may return a warning or informational exception.
 %
 %  The format of the AcquireAuthenticCacheView method is:
 %
@@ -111,15 +113,10 @@ MagickExport CacheView *AcquireAuthenticCacheView(const Image *image,
   ExceptionInfo *exception)
 {
   CacheView
-    *cache_view;
-
-  MagickBooleanType
-    status;
+    *restrict cache_view;
 
   cache_view=AcquireVirtualCacheView(image,exception);
-  status=SyncImagePixelCache(cache_view->image,exception);
-  if (status == MagickFalse)
-    ThrowFatalException(CacheFatalError,"UnableToAcquireCacheView");
+  (void) SyncImagePixelCache(cache_view->image,exception);
   return(cache_view);
 }
 \f
@@ -136,6 +133,7 @@ MagickExport CacheView *AcquireAuthenticCacheView(const Image *image,
 %
 %  AcquireVirtualCacheView() acquires a virtual view into the pixel cache,
 %  using the VirtualPixelMethod that is defined within the given image itself.
+%  It always succeeds but may return a warning or informational exception.
 %
 %  The format of the AcquireVirtualCacheView method is:
 %
@@ -153,23 +151,28 @@ MagickExport CacheView *AcquireVirtualCacheView(const Image *image,
   ExceptionInfo *exception)
 {
   CacheView
-    *cache_view;
+    *restrict cache_view;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   (void) exception;
-  cache_view=(CacheView *) AcquireQuantumMemory(1,sizeof(*cache_view));
+  cache_view=(CacheView *) MagickAssumeAligned(AcquireAlignedMemory(1,
+    sizeof(*cache_view)));
   if (cache_view == (CacheView *) NULL)
     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
   (void) ResetMagickMemory(cache_view,0,sizeof(*cache_view));
   cache_view->image=ReferenceImage((Image *) image);
   cache_view->number_threads=GetOpenMPMaximumThreads();
+  if (GetMagickResourceLimit(ThreadResource) > cache_view->number_threads)
+    cache_view->number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
+  if (cache_view->number_threads == 0)
+    cache_view->number_threads=1;
   cache_view->nexus_info=AcquirePixelCacheNexus(cache_view->number_threads);
   cache_view->virtual_pixel_method=GetImageVirtualPixelMethod(image);
   cache_view->debug=IsEventLogging();
-  cache_view->signature=MagickSignature;
+  cache_view->signature=MagickCoreSignature;
   if (cache_view->nexus_info == (NexusInfo **) NULL)
     ThrowFatalException(CacheFatalError,"UnableToAcquireCacheView");
   return(cache_view);
@@ -200,14 +203,15 @@ MagickExport CacheView *AcquireVirtualCacheView(const Image *image,
 MagickExport CacheView *CloneCacheView(const CacheView *cache_view)
 {
   CacheView
-    *clone_view;
+    *restrict clone_view;
 
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   if (cache_view->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       cache_view->image->filename);
-  clone_view=(CacheView *) AcquireQuantumMemory(1,sizeof(*clone_view));
+  clone_view=(CacheView *) MagickAssumeAligned(AcquireAlignedMemory(1,
+    sizeof(*clone_view)));
   if (clone_view == (CacheView *) NULL)
     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
   (void) ResetMagickMemory(clone_view,0,sizeof(*clone_view));
@@ -216,7 +220,7 @@ MagickExport CacheView *CloneCacheView(const CacheView *cache_view)
   clone_view->nexus_info=AcquirePixelCacheNexus(cache_view->number_threads);
   clone_view->virtual_pixel_method=cache_view->virtual_pixel_method;
   clone_view->debug=cache_view->debug;
-  clone_view->signature=MagickSignature;
+  clone_view->signature=MagickCoreSignature;
   return(clone_view);
 }
 \f
@@ -246,7 +250,7 @@ MagickExport CacheView *CloneCacheView(const CacheView *cache_view)
 MagickExport CacheView *DestroyCacheView(CacheView *cache_view)
 {
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   if (cache_view->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       cache_view->image->filename);
@@ -254,8 +258,8 @@ MagickExport CacheView *DestroyCacheView(CacheView *cache_view)
     cache_view->nexus_info=DestroyPixelCacheNexus(cache_view->nexus_info,
       cache_view->number_threads);
   cache_view->image=DestroyImage(cache_view->image);
-  cache_view->signature=(~MagickSignature);
-  cache_view=(CacheView *) RelinquishMagickMemory(cache_view);
+  cache_view->signature=(~MagickCoreSignature);
+  cache_view=(CacheView *) RelinquishAlignedMemory(cache_view);
   return(cache_view);
 }
 \f
@@ -298,10 +302,10 @@ MagickExport Quantum *GetCacheViewAuthenticPixels(CacheView *cache_view,
     id = GetOpenMPThreadId();
 
   Quantum
-    *pixels;
+    *restrict pixels;
 
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   assert(id < (int) cache_view->number_threads);
   pixels=GetAuthenticPixelCacheNexus(cache_view->image,x,y,columns,rows,
     cache_view->nexus_info[id],exception);
@@ -338,16 +342,11 @@ MagickExport void *GetCacheViewAuthenticMetacontent(CacheView *cache_view)
   const int
     id = GetOpenMPThreadId();
 
-  void
-    *metacontent;
-
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   assert(cache_view->image->cache != (Cache) NULL);
   assert(id < (int) cache_view->number_threads);
-  metacontent=GetPixelCacheNexusMetacontent(cache_view->image->cache,
-    cache_view->nexus_info[id]);
-  return(metacontent);
+  return(cache_view->nexus_info[id]->metacontent);
 }
 \f
 /*
@@ -380,16 +379,11 @@ MagickExport Quantum *GetCacheViewAuthenticPixelQueue(CacheView *cache_view)
   const int
     id = GetOpenMPThreadId();
 
-  Quantum
-    *pixels;
-
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   assert(cache_view->image->cache != (Cache) NULL);
   assert(id < (int) cache_view->number_threads);
-  pixels=GetPixelCacheNexusPixels(cache_view->image->cache,
-    cache_view->nexus_info[id]);
-  return(pixels);
+  return(cache_view->nexus_info[id]->pixels);
 }
 \f
 /*
@@ -418,7 +412,7 @@ MagickExport Quantum *GetCacheViewAuthenticPixelQueue(CacheView *cache_view)
 MagickExport ColorspaceType GetCacheViewColorspace(const CacheView *cache_view)
 {
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   if (cache_view->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       cache_view->image->filename);
@@ -458,7 +452,7 @@ MagickExport MagickSizeType GetCacheViewExtent(const CacheView *cache_view)
     extent;
 
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   if (cache_view->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       cache_view->image->filename);
@@ -494,7 +488,7 @@ MagickExport MagickSizeType GetCacheViewExtent(const CacheView *cache_view)
 MagickExport const Image *GetCacheViewImage(const CacheView *cache_view)
 {
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   if (cache_view->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       cache_view->image->filename);
@@ -527,7 +521,7 @@ MagickExport const Image *GetCacheViewImage(const CacheView *cache_view)
 MagickExport ClassType GetCacheViewStorageClass(const CacheView *cache_view)
 {
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   if (cache_view->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       cache_view->image->filename);
@@ -566,10 +560,10 @@ MagickExport const void *GetCacheViewVirtualMetacontent(
     id = GetOpenMPThreadId();
 
   const void
-    *metacontent;
+    *restrict metacontent;
 
   assert(cache_view != (const CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   assert(cache_view->image->cache != (Cache) NULL);
   assert(id < (int) cache_view->number_threads);
   metacontent=GetVirtualMetacontentFromNexus(cache_view->image->cache,
@@ -609,10 +603,10 @@ MagickExport const Quantum *GetCacheViewVirtualPixelQueue(
     id = GetOpenMPThreadId();
 
   const Quantum
-    *pixels;
+    *restrict pixels;
 
   assert(cache_view != (const CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   assert(cache_view->image->cache != (Cache) NULL);
   assert(id < (int) cache_view->number_threads);
   pixels=GetVirtualPixelsNexus(cache_view->image->cache,
@@ -660,10 +654,10 @@ MagickExport const Quantum *GetCacheViewVirtualPixels(
     id = GetOpenMPThreadId();
 
   const Quantum
-    *pixels;
+    *restrict pixels;
 
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   assert(id < (int) cache_view->number_threads);
   pixels=GetVirtualPixelsFromNexus(cache_view->image,
     cache_view->virtual_pixel_method,x,y,columns,rows,
@@ -710,18 +704,18 @@ MagickExport MagickBooleanType GetOneCacheViewAuthenticPixel(
     id = GetOpenMPThreadId();
 
   Quantum
-    *p;
+    *restrict q;
 
   register ssize_t
     i;
 
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   assert(id < (int) cache_view->number_threads);
   (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
-  p=GetAuthenticPixelCacheNexus(cache_view->image,x,y,1,1,
+  q=GetAuthenticPixelCacheNexus(cache_view->image,x,y,1,1,
     cache_view->nexus_info[id],exception);
-  if (p == (const Quantum *) NULL)
+  if (q == (const Quantum *) NULL)
     {
       PixelInfo
         background_color;
@@ -736,11 +730,8 @@ MagickExport MagickBooleanType GetOneCacheViewAuthenticPixel(
     }
   for (i=0; i < (ssize_t) GetPixelChannels(cache_view->image); i++)
   {
-    PixelChannel
-      channel;
-
-    channel=GetPixelChannelMapChannel(cache_view->image,i);
-    pixel[channel]=p[i];
+    PixelChannel channel=GetPixelChannelChannel(cache_view->image,i);
+    pixel[channel]=q[i];
   }
   return(MagickTrue);
 }
@@ -785,13 +776,13 @@ MagickExport MagickBooleanType GetOneCacheViewVirtualPixel(
     id = GetOpenMPThreadId();
 
   register const Quantum
-    *p;
+    *restrict p;
 
   register ssize_t
     i;
 
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   assert(id < (int) cache_view->number_threads);
   (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
   p=GetVirtualPixelsFromNexus(cache_view->image,
@@ -812,10 +803,7 @@ MagickExport MagickBooleanType GetOneCacheViewVirtualPixel(
     }
   for (i=0; i < (ssize_t) GetPixelChannels(cache_view->image); i++)
   {
-    PixelChannel
-      channel;
-
-    channel=GetPixelChannelMapChannel(cache_view->image,i);
+    PixelChannel channel=GetPixelChannelChannel(cache_view->image,i);
     pixel[channel]=p[i];
   }
   return(MagickTrue);
@@ -861,10 +849,10 @@ MagickExport MagickBooleanType GetOneCacheViewVirtualPixelInfo(
     id = GetOpenMPThreadId();
 
   register const Quantum
-    *p;
+    *restrict p;
 
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   assert(id < (int) cache_view->number_threads);
   GetPixelInfo(cache_view->image,pixel);
   p=GetVirtualPixelsFromNexus(cache_view->image,
@@ -920,13 +908,13 @@ MagickExport MagickBooleanType GetOneCacheViewVirtualMethodPixel(
     id = GetOpenMPThreadId();
 
   const Quantum
-    *p;
+    *restrict p;
 
   register ssize_t
     i;
 
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   assert(id < (int) cache_view->number_threads);
   (void) memset(pixel,0,MaxPixelChannels*sizeof(*pixel));
   p=GetVirtualPixelsFromNexus(cache_view->image,virtual_pixel_method,x,y,1,1,
@@ -946,10 +934,7 @@ MagickExport MagickBooleanType GetOneCacheViewVirtualMethodPixel(
     }
   for (i=0; i < (ssize_t) GetPixelChannels(cache_view->image); i++)
   {
-    PixelChannel
-      channel;
-
-    channel=GetPixelChannelMapChannel(cache_view->image,i);
+    PixelChannel channel=GetPixelChannelChannel(cache_view->image,i);
     pixel[channel]=p[i];
   }
   return(MagickTrue);
@@ -995,10 +980,10 @@ MagickExport Quantum *QueueCacheViewAuthenticPixels(CacheView *cache_view,
     id = GetOpenMPThreadId();
 
   Quantum
-    *pixels;
+    *restrict pixels;
 
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   assert(id < (int) cache_view->number_threads);
   pixels=QueueAuthenticPixelCacheNexus(cache_view->image,x,y,columns,rows,
     MagickFalse,cache_view->nexus_info[id],exception);
@@ -1037,7 +1022,7 @@ MagickExport MagickBooleanType SetCacheViewStorageClass(CacheView *cache_view,
   const ClassType storage_class,ExceptionInfo *exception)
 {
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   if (cache_view->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       cache_view->image->filename);
@@ -1071,10 +1056,10 @@ MagickExport MagickBooleanType SetCacheViewStorageClass(CacheView *cache_view,
 %
 */
 MagickExport MagickBooleanType SetCacheViewVirtualPixelMethod(
-  CacheView *cache_view,const VirtualPixelMethod virtual_pixel_method)
+  CacheView *restrict cache_view,const VirtualPixelMethod virtual_pixel_method)
 {
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   if (cache_view->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       cache_view->image->filename);
@@ -1110,7 +1095,7 @@ MagickExport MagickBooleanType SetCacheViewVirtualPixelMethod(
 %
 */
 MagickExport MagickBooleanType SyncCacheViewAuthenticPixels(
-  CacheView *cache_view,ExceptionInfo *exception)
+  CacheView *restrict cache_view,ExceptionInfo *exception)
 {
   const int
     id = GetOpenMPThreadId();
@@ -1119,7 +1104,7 @@ MagickExport MagickBooleanType SyncCacheViewAuthenticPixels(
     status;
 
   assert(cache_view != (CacheView *) NULL);
-  assert(cache_view->signature == MagickSignature);
+  assert(cache_view->signature == MagickCoreSignature);
   assert(id < (int) cache_view->number_threads);
   status=SyncAuthenticPixelCacheNexus(cache_view->image,
     cache_view->nexus_info[id],exception);