X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=MagickWand%2Fwand-view.c;h=1cbf6ee7d830f11e9bc519663b4b40a9974181f4;hb=de984cdc3631106b1cbbb8d3972b76a0fc27e8e8;hp=83b024e307643bffa4722b45a99058eba49ca4e9;hpb=874276bc8cb7bc180642c736749e094904eb7da6;p=imagemagick diff --git a/MagickWand/wand-view.c b/MagickWand/wand-view.c index 83b024e30..1cbf6ee7d 100644 --- a/MagickWand/wand-view.c +++ b/MagickWand/wand-view.c @@ -18,11 +18,11 @@ % MagickWand Wand 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 % @@ -80,9 +80,6 @@ struct _WandView CacheView *view; - size_t - number_threads; - PixelWand ***pixel_wands; @@ -143,10 +140,9 @@ WandExport WandView *CloneWandView(const WandView *wand_view) wand_view->exception); clone_view->view=CloneCacheView(wand_view->view); clone_view->extent=wand_view->extent; - clone_view->number_threads=wand_view->number_threads; clone_view->exception=AcquireExceptionInfo(); InheritException(clone_view->exception,wand_view->exception); - for (i=0; i < (ssize_t) wand_view->number_threads; i++) + for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++) clone_view->pixel_wands[i]=ClonePixelWands((const PixelWand **) wand_view->pixel_wands[i],wand_view->extent.width); clone_view->debug=wand_view->debug; @@ -180,13 +176,13 @@ WandExport WandView *CloneWandView(const WandView *wand_view) */ static PixelWand ***DestroyPixelsThreadSet(PixelWand ***pixel_wands, - const size_t number_wands,const size_t number_threads) + const size_t number_wands) { register ssize_t i; assert(pixel_wands != (PixelWand ***) NULL); - for (i=0; i < (ssize_t) number_threads; i++) + for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++) if (pixel_wands[i] != (PixelWand **) NULL) pixel_wands[i]=DestroyPixelWands(pixel_wands[i],number_wands); pixel_wands=(PixelWand ***) RelinquishMagickMemory(pixel_wands); @@ -198,7 +194,7 @@ WandExport WandView *DestroyWandView(WandView *wand_view) assert(wand_view != (WandView *) NULL); assert(wand_view->signature == WandSignature); wand_view->pixel_wands=DestroyPixelsThreadSet(wand_view->pixel_wands, - wand_view->extent.width,wand_view->number_threads); + wand_view->extent.width); wand_view->image=DestroyImage(wand_view->image); wand_view->view=DestroyCacheView(wand_view->view); wand_view->exception=DestroyExceptionInfo(wand_view->exception); @@ -263,9 +259,6 @@ WandExport MagickBooleanType DuplexTransferWandViewIterator(WandView *source, WandView *duplex,WandView *destination,DuplexTransferWandViewMethod transfer, void *context) { - ExceptionInfo - *exception; - Image *destination_image, *source_image; @@ -276,6 +269,11 @@ WandExport MagickBooleanType DuplexTransferWandViewIterator(WandView *source, MagickOffsetType progress; +#if defined(MAGICKCORE_OPENMP_SUPPORT) + size_t + height; +#endif + ssize_t y; @@ -285,13 +283,16 @@ WandExport MagickBooleanType DuplexTransferWandViewIterator(WandView *source, return(MagickFalse); source_image=source->wand->images; destination_image=destination->wand->images; - 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++) { @@ -339,7 +340,8 @@ WandExport MagickBooleanType DuplexTransferWandViewIterator(WandView *source, duplex_pixels+=GetPixelChannels(duplex->image); } 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; @@ -354,27 +356,24 @@ WandExport MagickBooleanType DuplexTransferWandViewIterator(WandView *source, if (transfer(source,duplex,destination,y,id,context) == MagickFalse) status=MagickFalse; destination_pixels=GetCacheViewAuthenticPixels(destination->view, - destination->extent.x,y,destination->extent.width,1,exception); + destination->extent.x,y,destination->extent.width,1, + destination->exception); for (x=0; x < (ssize_t) destination->extent.width; x++) { PixelGetQuantumPixel(destination->image,destination->pixel_wands[id][x], destination_pixels); destination_pixels+=GetPixelChannels(destination->image); } - 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 (MagickWand_DuplexTransferWandViewIterator) + #pragma omp critical (MagickWand_DuplexTransferWandViewIterator) #endif proceed=SetImageProgress(source_image,source->description,progress++, source->extent.height); @@ -401,7 +400,7 @@ WandExport MagickBooleanType DuplexTransferWandViewIterator(WandView *source, % % The format of the GetWandViewException method is: % -% char *GetWandViewException(const PixelWand *wand_view, +% char *GetWandViewException(const WandView *wand_view, % ExceptionType *severity) % % A description of each parameter follows: @@ -528,6 +527,11 @@ WandExport MagickBooleanType GetWandViewIterator(WandView *source, MagickOffsetType progress; +#if defined(MAGICKCORE_OPENMP_SUPPORT) + size_t + height; +#endif + ssize_t y; @@ -539,7 +543,9 @@ WandExport MagickBooleanType GetWandViewIterator(WandView *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++) { @@ -574,7 +580,7 @@ WandExport MagickBooleanType GetWandViewIterator(WandView *source, proceed; #if defined(MAGICKCORE_OPENMP_SUPPORT) - #pragma omp critical (MagickWand_GetWandViewIterator) + #pragma omp critical (MagickWand_GetWandViewIterator) #endif proceed=SetImageProgress(source_image,source->description,progress++, source->extent.height); @@ -708,8 +714,7 @@ WandExport MagickBooleanType IsWandView(const WandView *wand_view) % */ -static PixelWand ***AcquirePixelsThreadSet(const size_t number_wands, - const size_t number_threads) +static PixelWand ***AcquirePixelsThreadSet(const size_t number_wands) { PixelWand ***pixel_wands; @@ -717,6 +722,10 @@ static PixelWand ***AcquirePixelsThreadSet(const size_t number_wands, register ssize_t i; + size_t + number_threads; + + number_threads=GetOpenMPMaximumThreads(); pixel_wands=(PixelWand ***) AcquireQuantumMemory(number_threads, sizeof(*pixel_wands)); if (pixel_wands == (PixelWand ***) NULL) @@ -726,13 +735,16 @@ static PixelWand ***AcquirePixelsThreadSet(const size_t number_wands, { pixel_wands[i]=NewPixelWands(number_wands); if (pixel_wands[i] == (PixelWand **) NULL) - return(DestroyPixelsThreadSet(pixel_wands,number_wands,number_threads)); + return(DestroyPixelsThreadSet(pixel_wands,number_wands)); } return(pixel_wands); } WandExport WandView *NewWandView(MagickWand *wand) { + ExceptionInfo + *exception; + WandView *wand_view; @@ -748,13 +760,12 @@ WandExport WandView *NewWandView(MagickWand *wand) WandViewId,(double) wand_view->id); wand_view->description=ConstantString("WandView"); wand_view->wand=wand; - wand_view->view=AcquireCacheView(wand_view->wand->images); + exception=AcquireExceptionInfo(); + wand_view->view=AcquireVirtualCacheView(wand_view->wand->images,exception); wand_view->extent.width=wand->images->columns; wand_view->extent.height=wand->images->rows; - wand_view->number_threads=GetOpenMPMaximumThreads(); - wand_view->pixel_wands=AcquirePixelsThreadSet(wand_view->extent.width, - wand_view->number_threads); - wand_view->exception=AcquireExceptionInfo(); + wand_view->pixel_wands=AcquirePixelsThreadSet(wand_view->extent.width); + wand_view->exception=exception; if (wand_view->pixel_wands == (PixelWand ***) NULL) ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", GetExceptionMessage(errno)); @@ -793,6 +804,9 @@ WandExport WandView *NewWandView(MagickWand *wand) WandExport WandView *NewWandViewExtent(MagickWand *wand,const ssize_t x, const ssize_t y,const size_t width,const size_t height) { + ExceptionInfo + *exception; + WandView *wand_view; @@ -807,16 +821,15 @@ WandExport WandView *NewWandViewExtent(MagickWand *wand,const ssize_t x, (void) FormatLocaleString(wand_view->name,MaxTextExtent,"%s-%.20g", WandViewId,(double) wand_view->id); wand_view->description=ConstantString("WandView"); - wand_view->view=AcquireCacheView(wand_view->wand->images); + exception=AcquireExceptionInfo(); + wand_view->view=AcquireVirtualCacheView(wand_view->wand->images,exception); wand_view->wand=wand; wand_view->extent.width=width; wand_view->extent.height=height; wand_view->extent.x=x; wand_view->extent.y=y; - wand_view->number_threads=GetOpenMPMaximumThreads(); - wand_view->exception=AcquireExceptionInfo(); - wand_view->pixel_wands=AcquirePixelsThreadSet(wand_view->extent.width, - wand_view->number_threads); + wand_view->exception=exception; + wand_view->pixel_wands=AcquirePixelsThreadSet(wand_view->extent.width); if (wand_view->pixel_wands == (PixelWand ***) NULL) ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", GetExceptionMessage(errno)); @@ -904,9 +917,6 @@ MagickExport void SetWandViewDescription(WandView *wand_view, WandExport MagickBooleanType SetWandViewIterator(WandView *destination, SetWandViewMethod set,void *context) { - ExceptionInfo - *exception; - Image *destination_image; @@ -916,6 +926,11 @@ WandExport MagickBooleanType SetWandViewIterator(WandView *destination, MagickOffsetType progress; +#if defined(MAGICKCORE_OPENMP_SUPPORT) + size_t + height; +#endif + ssize_t y; @@ -924,13 +939,16 @@ WandExport MagickBooleanType SetWandViewIterator(WandView *destination, if (set == (SetWandViewMethod) NULL) return(MagickFalse); destination_image=destination->wand->images; - 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++) { @@ -949,11 +967,9 @@ WandExport MagickBooleanType SetWandViewIterator(WandView *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; } @@ -965,20 +981,16 @@ WandExport MagickBooleanType SetWandViewIterator(WandView *destination, pixels); pixels+=GetPixelChannels(destination->image); } - 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 (MagickWand_SetWandViewIterator) + #pragma omp critical (MagickWand_SetWandViewIterator) #endif proceed=SetImageProgress(destination_image,destination->description, progress++,destination->extent.height); @@ -994,41 +1006,6 @@ WandExport MagickBooleanType SetWandViewIterator(WandView *destination, % % % % % % -% S e t W a n d V i e w T h r e a d s % -% % -% % -% % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% SetWandViewThreads() sets the number of threads in a thread team. -% -% The format of the SetWandViewDescription method is: -% -% void SetWandViewThreads(WandView *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 SetWandViewThreads(WandView *image_view, - const size_t number_threads) -{ - assert(image_view != (WandView *) NULL); - assert(image_view->signature == MagickSignature); - image_view->number_threads=number_threads; - if (number_threads > GetOpenMPMaximumThreads()) - image_view->number_threads=GetOpenMPMaximumThreads(); -} - -/* -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % -% % -% % % T r a n s f e r W a n d V i e w I t e r a t o r % % % % % @@ -1075,9 +1052,6 @@ MagickExport void SetWandViewThreads(WandView *image_view, WandExport MagickBooleanType TransferWandViewIterator(WandView *source, WandView *destination,TransferWandViewMethod transfer,void *context) { - ExceptionInfo - *exception; - Image *destination_image, *source_image; @@ -1088,6 +1062,11 @@ WandExport MagickBooleanType TransferWandViewIterator(WandView *source, MagickOffsetType progress; +#if defined(MAGICKCORE_OPENMP_SUPPORT) + size_t + height; +#endif + ssize_t y; @@ -1097,13 +1076,16 @@ WandExport MagickBooleanType TransferWandViewIterator(WandView *source, return(MagickFalse); source_image=source->wand->images; destination_image=destination->wand->images; - 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++) { @@ -1137,7 +1119,8 @@ WandExport MagickBooleanType TransferWandViewIterator(WandView *source, pixels+=GetPixelChannels(source->image); } 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; @@ -1152,27 +1135,24 @@ WandExport MagickBooleanType TransferWandViewIterator(WandView *source, if (transfer(source,destination,y,id,context) == MagickFalse) status=MagickFalse; destination_pixels=GetCacheViewAuthenticPixels(destination->view, - destination->extent.x,y,destination->extent.width,1,exception); + destination->extent.x,y,destination->extent.width,1, + destination->exception); for (x=0; x < (ssize_t) destination->extent.width; x++) { PixelGetQuantumPixel(destination->image,destination->pixel_wands[id][x], destination_pixels); destination_pixels+=GetPixelChannels(destination->image); } - 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 (MagickWand_TransferWandViewIterator) + #pragma omp critical (MagickWand_TransferWandViewIterator) #endif proceed=SetImageProgress(source_image,source->description,progress++, source->extent.height); @@ -1229,9 +1209,6 @@ WandExport MagickBooleanType TransferWandViewIterator(WandView *source, WandExport MagickBooleanType UpdateWandViewIterator(WandView *source, UpdateWandViewMethod update,void *context) { - ExceptionInfo - *exception; - Image *source_image; @@ -1241,6 +1218,11 @@ WandExport MagickBooleanType UpdateWandViewIterator(WandView *source, MagickOffsetType progress; +#if defined(MAGICKCORE_OPENMP_SUPPORT) + size_t + height; +#endif + ssize_t y; @@ -1249,19 +1231,24 @@ WandExport MagickBooleanType UpdateWandViewIterator(WandView *source, if (update == (UpdateWandViewMethod) NULL) return(MagickFalse); source_image=source->wand->images; - 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++) { const int id = GetOpenMPThreadId(); + MagickBooleanType + sync; + register ssize_t x; @@ -1271,11 +1258,9 @@ WandExport MagickBooleanType UpdateWandViewIterator(WandView *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; } @@ -1291,18 +1276,16 @@ WandExport MagickBooleanType UpdateWandViewIterator(WandView *source, PixelGetQuantumPixel(source->image,source->pixel_wands[id][x],pixels); pixels+=GetPixelChannels(source->image); } - if (SyncCacheViewAuthenticPixels(source->view,exception) == MagickFalse) - { - InheritException(source->exception,GetCacheViewException(source->view)); - status=MagickFalse; - } + sync=SyncCacheViewAuthenticPixels(source->view,source->exception); + if (sync == MagickFalse) + status=MagickFalse; if (source_image->progress_monitor != (MagickProgressMonitor) NULL) { MagickBooleanType proceed; #if defined(MAGICKCORE_OPENMP_SUPPORT) - #pragma omp critical (MagickWand_UpdateWandViewIterator) + #pragma omp critical (MagickWand_UpdateWandViewIterator) #endif proceed=SetImageProgress(source_image,source->description,progress++, source->extent.height);