48#include "magick/studio.h"
49#include "magick/MagickCore.h"
50#include "magick/exception-private.h"
51#include "magick/monitor-private.h"
52#include "magick/thread-private.h"
111 assert(image_view != (
ImageView *) NULL);
112 assert(image_view->signature == MagickCoreSignature);
113 clone_view=(
ImageView *) AcquireMagickMemory(
sizeof(*clone_view));
115 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
116 (void) memset(clone_view,0,
sizeof(*clone_view));
117 clone_view->description=ConstantString(image_view->description);
118 clone_view->extent=image_view->extent;
119 clone_view->view=CloneCacheView(image_view->view);
120 clone_view->number_threads=image_view->number_threads;
121 clone_view->exception=AcquireExceptionInfo();
122 InheritException(clone_view->exception,image_view->exception);
123 clone_view->debug=image_view->debug;
124 clone_view->signature=MagickCoreSignature;
152 assert(image_view != (
ImageView *) NULL);
153 assert(image_view->signature == MagickCoreSignature);
154 if (image_view->description != (
char *) NULL)
155 image_view->description=DestroyString(image_view->description);
156 image_view->view=DestroyCacheView(image_view->view);
157 image_view->exception=DestroyExceptionInfo(image_view->exception);
158 image_view->signature=(~MagickCoreSignature);
159 image_view=(
ImageView *) RelinquishMagickMemory(image_view);
214MagickExport MagickBooleanType DuplexTransferImageViewIterator(
216 DuplexTransferImageViewMethod transfer,
void *context)
231#if defined(MAGICKCORE_OPENMP_SUPPORT)
240 assert(source->signature == MagickCoreSignature);
241 if (transfer == (DuplexTransferImageViewMethod) NULL)
243 source_image=source->image;
244 destination_image=destination->image;
245 if (SetImageStorageClass(destination_image,DirectClass) == MagickFalse)
249 exception=destination->exception;
250#if defined(MAGICKCORE_OPENMP_SUPPORT)
251 height=(size_t) (source->extent.height-source->extent.y);
252 #pragma omp parallel for schedule(static) shared(progress,status) \
253 magick_number_threads(source_image,destination_image,height,1)
255 for (y=source->extent.y; y < (ssize_t) source->extent.height; y++)
258 id = GetOpenMPThreadId();
264 *magick_restrict duplex_pixels,
265 *magick_restrict pixels;
268 *magick_restrict destination_pixels;
270 if (status == MagickFalse)
272 pixels=GetCacheViewVirtualPixels(source->view,source->extent.x,y,
273 source->extent.width,1,source->exception);
279 duplex_pixels=GetCacheViewVirtualPixels(duplex->view,duplex->extent.x,y,
280 duplex->extent.width,1,duplex->exception);
286 destination_pixels=GetCacheViewAuthenticPixels(destination->view,
287 destination->extent.x,y,destination->extent.width,1,exception);
293 if (transfer(source,duplex,destination,y,
id,context) == MagickFalse)
295 sync=SyncCacheViewAuthenticPixels(destination->view,exception);
296 if (sync == MagickFalse)
298 InheritException(destination->exception,GetCacheViewException(
302 if (source_image->progress_monitor != (MagickProgressMonitor) NULL)
307#if defined(MAGICKCORE_OPENMP_SUPPORT)
311 proceed=SetImageProgress(source_image,source->description,progress,
312 source->extent.height);
313 if (proceed == MagickFalse)
342MagickExport IndexPacket *GetImageViewAuthenticIndexes(
345 assert(image_view != (
ImageView *) NULL);
346 assert(image_view->signature == MagickCoreSignature);
347 return(GetCacheViewAuthenticIndexQueue(image_view->view));
372MagickExport
PixelPacket *GetImageViewAuthenticPixels(
375 assert(image_view != (
ImageView *) NULL);
376 assert(image_view->signature == MagickCoreSignature);
377 return(GetCacheViewAuthenticPixelQueue(image_view->view));
406MagickExport
char *GetImageViewException(
const ImageView *image_view,
407 ExceptionType *severity)
412 assert(image_view != (
const ImageView *) NULL);
413 assert(image_view->signature == MagickCoreSignature);
414 assert(severity != (ExceptionType *) NULL);
415 *severity=image_view->exception->severity;
416 description=(
char *) AcquireQuantumMemory(MaxTextExtent,
417 2*
sizeof(*description));
418 if (description == (
char *) NULL)
419 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
421 if (image_view->exception->reason != (
char *) NULL)
422 (void) CopyMagickString(description,GetLocaleExceptionMessage(
423 image_view->exception->severity,image_view->exception->reason),
425 if (image_view->exception->description != (
char *) NULL)
427 (void) ConcatenateMagickString(description,
" (",MaxTextExtent);
428 (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
429 image_view->exception->severity,image_view->exception->description),
431 (void) ConcatenateMagickString(description,
")",MaxTextExtent);
460 assert(image_view != (
ImageView *) NULL);
461 assert(image_view->signature == MagickCoreSignature);
462 return(image_view->extent);
489 assert(image_view != (
ImageView *) NULL);
490 assert(image_view->signature == MagickCoreSignature);
491 return(image_view->image);
537MagickExport MagickBooleanType GetImageViewIterator(
ImageView *source,
538 GetImageViewMethod get,
void *context)
549#if defined(MAGICKCORE_OPENMP_SUPPORT)
558 assert(source->signature == MagickCoreSignature);
559 if (get == (GetImageViewMethod) NULL)
561 source_image=source->image;
564#if defined(MAGICKCORE_OPENMP_SUPPORT)
565 height=(size_t) (source->extent.height-source->extent.y);
566 #pragma omp parallel for schedule(static) shared(progress,status) \
567 magick_number_threads(source_image,source_image,height,1)
569 for (y=source->extent.y; y < (ssize_t) source->extent.height; y++)
572 id = GetOpenMPThreadId();
577 if (status == MagickFalse)
579 pixels=GetCacheViewVirtualPixels(source->view,source->extent.x,y,
580 source->extent.width,1,source->exception);
586 if (get(source,y,
id,context) == MagickFalse)
588 if (source_image->progress_monitor != (MagickProgressMonitor) NULL)
593#if defined(MAGICKCORE_OPENMP_SUPPORT)
597 proceed=SetImageProgress(source_image,source->description,progress,
598 source->extent.height);
599 if (proceed == MagickFalse)
629MagickExport
const IndexPacket *GetImageViewVirtualIndexes(
632 assert(image_view != (
ImageView *) NULL);
633 assert(image_view->signature == MagickCoreSignature);
634 return(GetCacheViewVirtualIndexQueue(image_view->view));
659MagickExport
const PixelPacket *GetImageViewVirtualPixels(
662 assert(image_view != (
ImageView *) NULL);
663 assert(image_view->signature == MagickCoreSignature);
664 return(GetCacheViewVirtualPixelQueue(image_view->view));
690MagickExport MagickBooleanType IsImageView(
const ImageView *image_view)
692 if (image_view == (
const ImageView *) NULL)
694 if (image_view->signature != MagickCoreSignature)
727 assert(image != (
Image *) NULL);
728 assert(image->signature == MagickCoreSignature);
729 image_view=(
ImageView *) AcquireMagickMemory(
sizeof(*image_view));
731 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
732 (void) memset(image_view,0,
sizeof(*image_view));
733 image_view->description=ConstantString(
"ImageView");
734 image_view->image=image;
735 image_view->exception=AcquireExceptionInfo();
736 image_view->view=AcquireVirtualCacheView(image_view->image,
737 image_view->exception);
738 image_view->extent.width=image->columns;
739 image_view->extent.height=image->rows;
740 image_view->extent.x=0;
741 image_view->extent.y=0;
742 image_view->number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
743 image_view->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
745 image_view->signature=MagickCoreSignature;
776MagickExport
ImageView *NewImageViewRegion(
Image *image,
const ssize_t x,
777 const ssize_t y,
const size_t width,
const size_t height)
782 assert(image != (
Image *) NULL);
783 assert(image->signature == MagickCoreSignature);
784 image_view=(
ImageView *) AcquireMagickMemory(
sizeof(*image_view));
786 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
787 (void) memset(image_view,0,
sizeof(*image_view));
788 image_view->description=ConstantString(
"ImageView");
789 image_view->exception=AcquireExceptionInfo();
790 image_view->view=AcquireVirtualCacheView(image_view->image,
791 image_view->exception);
792 image_view->image=image;
793 image_view->extent.width=width;
794 image_view->extent.height=height;
795 image_view->extent.x=x;
796 image_view->extent.y=y;
797 image_view->number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
798 image_view->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
800 image_view->signature=MagickCoreSignature;
829MagickExport
void SetImageViewDescription(
ImageView *image_view,
830 const char *description)
832 assert(image_view != (
ImageView *) NULL);
833 assert(image_view->signature == MagickCoreSignature);
834 image_view->description=ConstantString(description);
881MagickExport MagickBooleanType SetImageViewIterator(
ImageView *destination,
882 SetImageViewMethod set,
void *context)
896#if defined(MAGICKCORE_OPENMP_SUPPORT)
904 assert(destination != (
ImageView *) NULL);
905 assert(destination->signature == MagickCoreSignature);
906 if (set == (SetImageViewMethod) NULL)
908 destination_image=destination->image;
909 if (SetImageStorageClass(destination_image,DirectClass) == MagickFalse)
913#if defined(MAGICKCORE_OPENMP_SUPPORT)
914 height=(size_t) (destination->extent.height-destination->extent.y);
916 exception=destination->exception;
917#if defined(MAGICKCORE_OPENMP_SUPPORT)
918 #pragma omp parallel for schedule(static) shared(progress,status) \
919 magick_number_threads(destination_image,destination_image,height,1)
921 for (y=destination->extent.y; y < (ssize_t) destination->extent.height; y++)
924 id = GetOpenMPThreadId();
930 *magick_restrict pixels;
932 if (status == MagickFalse)
934 pixels=GetCacheViewAuthenticPixels(destination->view,destination->extent.x,
935 y,destination->extent.width,1,exception);
938 InheritException(destination->exception,GetCacheViewException(
943 if (set(destination,y,
id,context) == MagickFalse)
945 sync=SyncCacheViewAuthenticPixels(destination->view,exception);
946 if (sync == MagickFalse)
948 InheritException(destination->exception,GetCacheViewException(
952 if (destination_image->progress_monitor != (MagickProgressMonitor) NULL)
957#if defined(MAGICKCORE_OPENMP_SUPPORT)
961 proceed=SetImageProgress(destination_image,destination->description,
962 progress,destination->extent.height);
963 if (proceed == MagickFalse)
995MagickExport
void SetImageViewThreads(
ImageView *image_view,
996 const size_t number_threads)
998 assert(image_view != (
ImageView *) NULL);
999 assert(image_view->signature == MagickCoreSignature);
1000 image_view->number_threads=number_threads;
1001 if (number_threads > (
size_t) GetMagickResourceLimit(ThreadResource))
1002 image_view->number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
1053MagickExport MagickBooleanType TransferImageViewIterator(
ImageView *source,
1054 ImageView *destination,TransferImageViewMethod transfer,
void *context)
1069#if defined(MAGICKCORE_OPENMP_SUPPORT)
1078 assert(source->signature == MagickCoreSignature);
1079 if (transfer == (TransferImageViewMethod) NULL)
1080 return(MagickFalse);
1081 source_image=source->image;
1082 destination_image=destination->image;
1083 if (SetImageStorageClass(destination_image,DirectClass) == MagickFalse)
1084 return(MagickFalse);
1087 exception=destination->exception;
1088#if defined(MAGICKCORE_OPENMP_SUPPORT)
1089 height=(size_t) (source->extent.height-source->extent.y);
1090 #pragma omp parallel for schedule(static) shared(progress,status) \
1091 magick_number_threads(source_image,destination_image,height,1)
1093 for (y=source->extent.y; y < (ssize_t) source->extent.height; y++)
1096 id = GetOpenMPThreadId();
1102 *magick_restrict pixels;
1105 *magick_restrict destination_pixels;
1107 if (status == MagickFalse)
1109 pixels=GetCacheViewVirtualPixels(source->view,source->extent.x,y,
1110 source->extent.width,1,source->exception);
1116 destination_pixels=GetCacheViewAuthenticPixels(destination->view,
1117 destination->extent.x,y,destination->extent.width,1,exception);
1123 if (transfer(source,destination,y,
id,context) == MagickFalse)
1125 sync=SyncCacheViewAuthenticPixels(destination->view,exception);
1126 if (sync == MagickFalse)
1128 InheritException(destination->exception,GetCacheViewException(
1132 if (source_image->progress_monitor != (MagickProgressMonitor) NULL)
1137#if defined(MAGICKCORE_OPENMP_SUPPORT)
1141 proceed=SetImageProgress(source_image,source->description,progress,
1142 source->extent.height);
1143 if (proceed == MagickFalse)
1193MagickExport MagickBooleanType UpdateImageViewIterator(
ImageView *source,
1194 UpdateImageViewMethod update,
void *context)
1208#if defined(MAGICKCORE_OPENMP_SUPPORT)
1217 assert(source->signature == MagickCoreSignature);
1218 if (update == (UpdateImageViewMethod) NULL)
1219 return(MagickFalse);
1220 source_image=source->image;
1221 if (SetImageStorageClass(source_image,DirectClass) == MagickFalse)
1222 return(MagickFalse);
1225 exception=source->exception;
1226#if defined(MAGICKCORE_OPENMP_SUPPORT)
1227 height=(size_t) (source->extent.height-source->extent.y);
1228 #pragma omp parallel for schedule(static) shared(progress,status) \
1229 magick_number_threads(source_image,source_image,height,1)
1231 for (y=source->extent.y; y < (ssize_t) source->extent.height; y++)
1234 id = GetOpenMPThreadId();
1237 *magick_restrict pixels;
1239 if (status == MagickFalse)
1241 pixels=GetCacheViewAuthenticPixels(source->view,source->extent.x,y,
1242 source->extent.width,1,exception);
1245 InheritException(source->exception,GetCacheViewException(source->view));
1249 if (update(source,y,
id,context) == MagickFalse)
1251 if (SyncCacheViewAuthenticPixels(source->view,exception) == MagickFalse)
1253 InheritException(source->exception,GetCacheViewException(source->view));
1256 if (source_image->progress_monitor != (MagickProgressMonitor) NULL)
1261#if defined(MAGICKCORE_OPENMP_SUPPORT)
1265 proceed=SetImageProgress(source_image,source->description,progress,
1266 source->extent.height);
1267 if (proceed == MagickFalse)