]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/image-view.c
(no commit message)
[imagemagick] / MagickCore / image-view.c
index edfa608f3477254a205f8bc3c00844fefa0360e2..fa502d9d70dc4417c42cf12af3ecb909a5e6260c 100644 (file)
 %                       MagickCore Image View Methods                         %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                                March 2003                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 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  %
@@ -68,9 +68,6 @@ struct _ImageView
   CacheView
     *view;
 
-  size_t
-    number_threads;
-
   ExceptionInfo
     *exception;
 
@@ -117,7 +114,6 @@ MagickExport ImageView *CloneImageView(const ImageView *image_view)
   clone_view->description=ConstantString(image_view->description);
   clone_view->extent=image_view->extent;
   clone_view->view=CloneCacheView(image_view->view);
-  clone_view->number_threads=image_view->number_threads;
   clone_view->exception=AcquireExceptionInfo();
   InheritException(clone_view->exception,image_view->exception);
   clone_view->debug=image_view->debug;
@@ -215,9 +211,6 @@ MagickExport MagickBooleanType DuplexTransferImageViewIterator(
   ImageView *source,ImageView *duplex,ImageView *destination,
   DuplexTransferImageViewMethod transfer,void *context)
 {
-  ExceptionInfo
-    *exception;
-
   Image
     *destination_image,
     *source_image;
@@ -228,6 +221,11 @@ MagickExport MagickBooleanType DuplexTransferImageViewIterator(
   MagickOffsetType
     progress;
 
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+  size_t
+    height;
+#endif
+
   ssize_t
     y;
 
@@ -237,13 +235,16 @@ MagickExport MagickBooleanType DuplexTransferImageViewIterator(
     return(MagickFalse);
   source_image=source->image;
   destination_image=destination->image;
-  exception=destination->exception;
-  if (SetImageStorageClass(destination_image,DirectClass,exception) == MagickFalse)
+  status=SetImageStorageClass(destination_image,DirectClass,
+    destination->exception);
+  if (status == MagickFalse)
     return(MagickFalse);
   status=MagickTrue;
   progress=0;
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static,1) shared(progress,status) num_threads(source->number_threads)
+  height=source->extent.height-source->extent.y;
+  #pragma omp parallel for schedule(static,4) shared(progress,status) \
+    magick_threads(source_image,destination_image,height,1)
 #endif
   for (y=source->extent.y; y < (ssize_t) source->extent.height; y++)
   {
@@ -277,7 +278,8 @@ MagickExport MagickBooleanType DuplexTransferImageViewIterator(
         continue;
       }
     destination_pixels=GetCacheViewAuthenticPixels(destination->view,
-      destination->extent.x,y,destination->extent.width,1,exception);
+      destination->extent.x,y,destination->extent.width,1,
+      destination->exception);
     if (destination_pixels == (Quantum *) NULL)
       {
         status=MagickFalse;
@@ -285,20 +287,16 @@ MagickExport MagickBooleanType DuplexTransferImageViewIterator(
       }
     if (transfer(source,duplex,destination,y,id,context) == MagickFalse)
       status=MagickFalse;
-    sync=SyncCacheViewAuthenticPixels(destination->view,exception);
+    sync=SyncCacheViewAuthenticPixels(destination->view,destination->exception);
     if (sync == MagickFalse)
-      {
-        InheritException(destination->exception,GetCacheViewException(
-          source->view));
-        status=MagickFalse;
-      }
+      status=MagickFalse;
     if (source_image->progress_monitor != (MagickProgressMonitor) NULL)
       {
         MagickBooleanType
           proceed;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_DuplexTransferImageViewIterator)
+        #pragma omp critical (MagickCore_DuplexTransferImageViewIterator)
 #endif
         proceed=SetImageProgress(source_image,source->description,progress++,
           source->extent.height);
@@ -314,7 +312,7 @@ MagickExport MagickBooleanType DuplexTransferImageViewIterator(
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%   G e t I m a g e V i e w A u t h e n t i c M e t a c o n t e n t %
+%   G e t I m a g e V i e w A u t h e n t i c M e t a c o n t e n t           %
 %                                                                             %
 %                                                                             %
 %                                                                             %
@@ -540,6 +538,11 @@ MagickExport MagickBooleanType GetImageViewIterator(ImageView *source,
   MagickOffsetType
     progress;
 
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+  size_t
+    height;
+#endif
+
   ssize_t
     y;
 
@@ -551,7 +554,9 @@ MagickExport MagickBooleanType GetImageViewIterator(ImageView *source,
   status=MagickTrue;
   progress=0;
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static,1) shared(progress,status) num_threads(source->number_threads)
+  height=source->extent.height-source->extent.y;
+  #pragma omp parallel for schedule(static,4) shared(progress,status) \
+    magick_threads(source_image,source_image,height,1)
 #endif
   for (y=source->extent.y; y < (ssize_t) source->extent.height; y++)
   {
@@ -578,7 +583,7 @@ MagickExport MagickBooleanType GetImageViewIterator(ImageView *source,
           proceed;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_GetImageViewIterator)
+        #pragma omp critical (MagickCore_GetImageViewIterator)
 #endif
         proceed=SetImageProgress(source_image,source->description,progress++,
           source->extent.height);
@@ -699,14 +704,16 @@ MagickExport MagickBooleanType IsImageView(const ImageView *image_view)
 %
 %  The format of the NewImageView method is:
 %
-%      ImageView *NewImageView(MagickCore *wand)
+%      ImageView *NewImageView(MagickCore *wand,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
-%    o wand: the wand.
+%    o image: the image.
+%
+%    o exception: return any errors or warnings in this structure.
 %
 */
-MagickExport ImageView *NewImageView(Image *image)
+MagickExport ImageView *NewImageView(Image *image,ExceptionInfo *exception)
 {
   ImageView
     *image_view;
@@ -719,12 +726,11 @@ MagickExport ImageView *NewImageView(Image *image)
   (void) ResetMagickMemory(image_view,0,sizeof(*image_view));
   image_view->description=ConstantString("ImageView");
   image_view->image=image;
-  image_view->view=AcquireCacheView(image_view->image);
+  image_view->view=AcquireVirtualCacheView(image_view->image,exception);
   image_view->extent.width=image->columns;
   image_view->extent.height=image->rows;
   image_view->extent.x=0;
   image_view->extent.y=0;
-  image_view->number_threads=GetOpenMPMaximumThreads();
   image_view->exception=AcquireExceptionInfo();
   image_view->debug=IsEventLogging();
   image_view->signature=MagickSignature;
@@ -748,7 +754,8 @@ MagickExport ImageView *NewImageView(Image *image)
 %  The format of the NewImageViewRegion method is:
 %
 %      ImageView *NewImageViewRegion(MagickCore *wand,const ssize_t x,
-%        const ssize_t y,const size_t width,const size_t height)
+%        const ssize_t y,const size_t width,const size_t height,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -757,9 +764,12 @@ MagickExport ImageView *NewImageView(Image *image)
 %    o x,y,columns,rows:  These values define the perimeter of a extent of
 %      pixel_wands view.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 MagickExport ImageView *NewImageViewRegion(Image *image,const ssize_t x,
-  const ssize_t y,const size_t width,const size_t height)
+  const ssize_t y,const size_t width,const size_t height,
+  ExceptionInfo *exception)
 {
   ImageView
     *image_view;
@@ -771,13 +781,12 @@ MagickExport ImageView *NewImageViewRegion(Image *image,const ssize_t x,
     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
   (void) ResetMagickMemory(image_view,0,sizeof(*image_view));
   image_view->description=ConstantString("ImageView");
-  image_view->view=AcquireCacheView(image_view->image);
+  image_view->view=AcquireVirtualCacheView(image_view->image,exception);
   image_view->image=image;
   image_view->extent.width=width;
   image_view->extent.height=height;
   image_view->extent.x=x;
   image_view->extent.y=y;
-  image_view->number_threads=GetOpenMPMaximumThreads();
   image_view->exception=AcquireExceptionInfo();
   image_view->debug=IsEventLogging();
   image_view->signature=MagickSignature;
@@ -864,9 +873,6 @@ MagickExport void SetImageViewDescription(ImageView *image_view,
 MagickExport MagickBooleanType SetImageViewIterator(ImageView *destination,
   SetImageViewMethod set,void *context)
 {
-  ExceptionInfo
-    *exception;
-
   Image
     *destination_image;
 
@@ -876,6 +882,11 @@ MagickExport MagickBooleanType SetImageViewIterator(ImageView *destination,
   MagickOffsetType
     progress;
 
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+  size_t
+    height;
+#endif
+
   ssize_t
     y;
 
@@ -884,13 +895,16 @@ MagickExport MagickBooleanType SetImageViewIterator(ImageView *destination,
   if (set == (SetImageViewMethod) NULL)
     return(MagickFalse);
   destination_image=destination->image;
-  exception=destination->exception;
-  if (SetImageStorageClass(destination_image,DirectClass,exception) == MagickFalse)
+  status=SetImageStorageClass(destination_image,DirectClass,
+    destination->exception);
+  if (status == MagickFalse)
     return(MagickFalse);
   status=MagickTrue;
   progress=0;
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static,1) shared(progress,status) num_threads(destination->number_threads)
+  height=destination->extent.height-destination->extent.y;
+  #pragma omp parallel for schedule(static,4) shared(progress,status) \
+    magick_threads(destination_image,destination_image,height,1)
 #endif
   for (y=destination->extent.y; y < (ssize_t) destination->extent.height; y++)
   {
@@ -906,30 +920,24 @@ MagickExport MagickBooleanType SetImageViewIterator(ImageView *destination,
     if (status == MagickFalse)
       continue;
     pixels=GetCacheViewAuthenticPixels(destination->view,destination->extent.x,
-      y,destination->extent.width,1,exception);
+      y,destination->extent.width,1,destination->exception);
     if (pixels == (Quantum *) NULL)
       {
-        InheritException(destination->exception,GetCacheViewException(
-          destination->view));
         status=MagickFalse;
         continue;
       }
     if (set(destination,y,id,context) == MagickFalse)
       status=MagickFalse;
-    sync=SyncCacheViewAuthenticPixels(destination->view,exception);
+    sync=SyncCacheViewAuthenticPixels(destination->view,destination->exception);
     if (sync == MagickFalse)
-      {
-        InheritException(destination->exception,GetCacheViewException(
-          destination->view));
-        status=MagickFalse;
-      }
+      status=MagickFalse;
     if (destination_image->progress_monitor != (MagickProgressMonitor) NULL)
       {
         MagickBooleanType
           proceed;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_SetImageViewIterator)
+        #pragma omp critical (MagickCore_SetImageViewIterator)
 #endif
         proceed=SetImageProgress(destination_image,destination->description,
           progress++,destination->extent.height);
@@ -945,41 +953,6 @@ MagickExport MagickBooleanType SetImageViewIterator(ImageView *destination,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%   S e t I m a g e V i e w T h r e a d s                                     %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  SetImageViewThreads() sets the number of threads in a thread team.
-%
-%  The format of the SetImageViewDescription method is:
-%
-%      void SetImageViewThreads(ImageView *image_view,
-%        const size_t number_threads)
-%
-%  A description of each parameter follows:
-%
-%    o image_view: the image view.
-%
-%    o number_threads: the number of threads in a thread team.
-%
-*/
-MagickExport void SetImageViewThreads(ImageView *image_view,
-  const size_t number_threads)
-{
-  assert(image_view != (ImageView *) NULL);
-  assert(image_view->signature == MagickSignature);
-  image_view->number_threads=number_threads;
-  if (number_threads > GetOpenMPMaximumThreads())
-    image_view->number_threads=GetOpenMPMaximumThreads();
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
 %   T r a n s f e r I m a g e V i e w I t e r a t o r                         %
 %                                                                             %
 %                                                                             %
@@ -1026,9 +999,6 @@ MagickExport void SetImageViewThreads(ImageView *image_view,
 MagickExport MagickBooleanType TransferImageViewIterator(ImageView *source,
   ImageView *destination,TransferImageViewMethod transfer,void *context)
 {
-  ExceptionInfo
-    *exception;
-
   Image
     *destination_image,
     *source_image;
@@ -1039,6 +1009,11 @@ MagickExport MagickBooleanType TransferImageViewIterator(ImageView *source,
   MagickOffsetType
     progress;
 
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+  size_t
+    height;
+#endif
+
   ssize_t
     y;
 
@@ -1048,13 +1023,16 @@ MagickExport MagickBooleanType TransferImageViewIterator(ImageView *source,
     return(MagickFalse);
   source_image=source->image;
   destination_image=destination->image;
-  exception=destination->exception;
-  if (SetImageStorageClass(destination_image,DirectClass,exception) == MagickFalse)
+  status=SetImageStorageClass(destination_image,DirectClass,
+    destination->exception);
+  if (status == MagickFalse)
     return(MagickFalse);
   status=MagickTrue;
   progress=0;
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static,1) shared(progress,status) num_threads(source->number_threads)
+  height=source->extent.height-source->extent.y;
+  #pragma omp parallel for schedule(static,4) shared(progress,status) \
+    magick_threads(source_image,destination_image,height,1)
 #endif
   for (y=source->extent.y; y < (ssize_t) source->extent.height; y++)
   {
@@ -1080,7 +1058,8 @@ MagickExport MagickBooleanType TransferImageViewIterator(ImageView *source,
         continue;
       }
     destination_pixels=GetCacheViewAuthenticPixels(destination->view,
-      destination->extent.x,y,destination->extent.width,1,exception);
+      destination->extent.x,y,destination->extent.width,1,
+      destination->exception);
     if (destination_pixels == (Quantum *) NULL)
       {
         status=MagickFalse;
@@ -1088,20 +1067,16 @@ MagickExport MagickBooleanType TransferImageViewIterator(ImageView *source,
       }
     if (transfer(source,destination,y,id,context) == MagickFalse)
       status=MagickFalse;
-    sync=SyncCacheViewAuthenticPixels(destination->view,exception);
+    sync=SyncCacheViewAuthenticPixels(destination->view,destination->exception);
     if (sync == MagickFalse)
-      {
-        InheritException(destination->exception,GetCacheViewException(
-          source->view));
-        status=MagickFalse;
-      }
+      status=MagickFalse;
     if (source_image->progress_monitor != (MagickProgressMonitor) NULL)
       {
         MagickBooleanType
           proceed;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_TransferImageViewIterator)
+        #pragma omp critical (MagickCore_TransferImageViewIterator)
 #endif
         proceed=SetImageProgress(source_image,source->description,progress++,
           source->extent.height);
@@ -1158,9 +1133,6 @@ MagickExport MagickBooleanType TransferImageViewIterator(ImageView *source,
 MagickExport MagickBooleanType UpdateImageViewIterator(ImageView *source,
   UpdateImageViewMethod update,void *context)
 {
-  ExceptionInfo
-    *exception;
-
   Image
     *source_image;
 
@@ -1170,6 +1142,11 @@ MagickExport MagickBooleanType UpdateImageViewIterator(ImageView *source,
   MagickOffsetType
     progress;
 
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+  size_t
+    height;
+#endif
+
   ssize_t
     y;
 
@@ -1178,13 +1155,15 @@ MagickExport MagickBooleanType UpdateImageViewIterator(ImageView *source,
   if (update == (UpdateImageViewMethod) NULL)
     return(MagickFalse);
   source_image=source->image;
-  exception=source->exception;
-  if (SetImageStorageClass(source_image,DirectClass,exception) == MagickFalse)
+  status=SetImageStorageClass(source_image,DirectClass,source->exception);
+  if (status == MagickFalse)
     return(MagickFalse);
   status=MagickTrue;
   progress=0;
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static,1) shared(progress,status) num_threads(source->number_threads)
+  height=source->extent.height-source->extent.y;
+  #pragma omp parallel for schedule(static,4) shared(progress,status) \
+    magick_threads(source_image,source_image,height,1)
 #endif
   for (y=source->extent.y; y < (ssize_t) source->extent.height; y++)
   {
@@ -1197,27 +1176,24 @@ MagickExport MagickBooleanType UpdateImageViewIterator(ImageView *source,
     if (status == MagickFalse)
       continue;
     pixels=GetCacheViewAuthenticPixels(source->view,source->extent.x,y,
-      source->extent.width,1,exception);
+      source->extent.width,1,source->exception);
     if (pixels == (Quantum *) NULL)
       {
-        InheritException(source->exception,GetCacheViewException(source->view));
         status=MagickFalse;
         continue;
       }
     if (update(source,y,id,context) == MagickFalse)
       status=MagickFalse;
-    if (SyncCacheViewAuthenticPixels(source->view,exception) == MagickFalse)
-      {
-        InheritException(source->exception,GetCacheViewException(source->view));
-        status=MagickFalse;
-      }
+    status=SyncCacheViewAuthenticPixels(source->view,source->exception);
+    if (status == MagickFalse)
+      status=MagickFalse;
     if (source_image->progress_monitor != (MagickProgressMonitor) NULL)
       {
         MagickBooleanType
           proceed;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_UpdateImageViewIterator)
+        #pragma omp critical (MagickCore_UpdateImageViewIterator)
 #endif
         proceed=SetImageProgress(source_image,source->description,progress++,
           source->extent.height);