49#include "MagickWand/studio.h"
50#include "MagickWand/MagickWand.h"
51#include "MagickWand/magick-wand-private.h"
52#include "MagickWand/pixel-iterator.h"
53#include "MagickWand/pixel-wand.h"
54#include "MagickWand/wand.h"
59#define PixelIteratorId "PixelIterator"
70 name[MagickPathExtent];
122 assert(iterator->signature == MagickWandSignature);
123 if (iterator->debug != MagickFalse)
124 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
125 iterator->pixel_wands=DestroyPixelWands(iterator->pixel_wands,
126 iterator->region.width);
127 ClearMagickException(iterator->exception);
128 iterator->pixel_wands=NewPixelWands(iterator->region.width);
129 iterator->active=MagickFalse;
131 iterator->debug=IsEventLogging();
162 assert(iterator->signature == MagickWandSignature);
163 if (iterator->debug != MagickFalse)
164 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
166 sizeof(*clone_iterator));
167 (void) memset(clone_iterator,0,
sizeof(*clone_iterator));
168 clone_iterator->id=AcquireWandId();
169 (void) FormatLocaleString(clone_iterator->name,MagickPathExtent,
"%s-%.20g",
170 PixelIteratorId,(
double) clone_iterator->id);
171 clone_iterator->exception=AcquireExceptionInfo();
172 InheritException(clone_iterator->exception,iterator->exception);
173 clone_iterator->view=CloneCacheView(iterator->view);
174 clone_iterator->region=iterator->region;
175 clone_iterator->active=iterator->active;
176 clone_iterator->y=iterator->y;
177 clone_iterator->pixel_wands=ClonePixelWands((
const PixelWand **)
178 iterator->pixel_wands,iterator->region.width);
179 clone_iterator->debug=iterator->debug;
180 if (clone_iterator->debug != MagickFalse)
181 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",
182 clone_iterator->name);
183 clone_iterator->signature=MagickWandSignature;
184 return(clone_iterator);
212 assert(iterator->signature == MagickWandSignature);
213 if (iterator->debug != MagickFalse)
214 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
215 iterator->view=DestroyCacheView(iterator->view);
216 iterator->pixel_wands=DestroyPixelWands(iterator->pixel_wands,
217 iterator->region.width);
218 iterator->exception=DestroyExceptionInfo(iterator->exception);
219 iterator->signature=(~MagickWandSignature);
220 RelinquishWandId(iterator->id);
248WandExport MagickBooleanType IsPixelIterator(
const PixelIterator *iterator)
255 if (iterator->signature != MagickWandSignature)
257 length=strlen(PixelIteratorId);
258 if (LocaleNCompare(iterator->name,PixelIteratorId,length) != 0)
300 image=GetImageFromMagickWand(wand);
301 if (image == (Image *) NULL)
303 exception=AcquireExceptionInfo();
304 view=AcquireVirtualCacheView(image,exception);
305 if (view == (CacheView *) NULL)
307 iterator=(
PixelIterator *) AcquireCriticalMemory(
sizeof(*iterator));
308 (void) memset(iterator,0,
sizeof(*iterator));
309 iterator->id=AcquireWandId();
310 (void) FormatLocaleString(iterator->name,MagickPathExtent,
"%s-%.20g",
311 PixelIteratorId,(
double) iterator->id);
312 iterator->exception=exception;
314 SetGeometry(image,&iterator->region);
315 iterator->region.width=image->columns;
316 iterator->region.height=image->rows;
317 iterator->region.x=0;
318 iterator->region.y=0;
319 iterator->pixel_wands=NewPixelWands(iterator->region.width);
321 iterator->debug=IsEventLogging();
322 if (iterator->debug != MagickFalse)
323 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
324 iterator->signature=MagickWandSignature;
351WandExport MagickBooleanType PixelClearIteratorException(
355 assert(iterator->signature == MagickWandSignature);
356 if (iterator->debug != MagickFalse)
357 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
358 ClearMagickException(iterator->exception);
389 const ssize_t x,
const ssize_t y,
const size_t width,
const size_t height)
404 if ((width == 0) || (height == 0))
405 ThrowWandFatalException(WandError,
"ZeroRegionSize",wand->name);
406 image=GetImageFromMagickWand(wand);
407 if (image == (Image *) NULL)
409 exception=AcquireExceptionInfo();
410 view=AcquireVirtualCacheView(image,exception);
411 if (view == (CacheView *) NULL)
413 iterator=(
PixelIterator *) AcquireCriticalMemory(
sizeof(*iterator));
414 (void) memset(iterator,0,
sizeof(*iterator));
415 iterator->id=AcquireWandId();
416 (void) FormatLocaleString(iterator->name,MagickPathExtent,
"%s-%.20g",
417 PixelIteratorId,(
double) iterator->id);
418 iterator->exception=exception;
420 SetGeometry(image,&iterator->region);
421 iterator->region.width=width;
422 iterator->region.height=height;
423 iterator->region.x=x;
424 iterator->region.y=y;
425 iterator->pixel_wands=NewPixelWands(iterator->region.width);
427 iterator->debug=IsEventLogging();
428 if (iterator->debug != MagickFalse)
429 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
430 iterator->signature=MagickWandSignature;
461 size_t *number_wands)
470 assert(iterator->signature == MagickWandSignature);
471 if (iterator->debug != MagickFalse)
472 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
474 iterator->active=MagickTrue;
475 pixels=GetCacheViewVirtualPixels(iterator->view,iterator->region.x,
476 iterator->region.y+iterator->y,iterator->region.width,1,
477 iterator->exception);
478 if (pixels == (
const Quantum *) NULL)
480 for (x=0; x < (ssize_t) iterator->region.width; x++)
482 PixelSetQuantumPixel(GetCacheViewImage(iterator->view),pixels,
483 iterator->pixel_wands[x]);
484 pixels+=GetPixelChannels(GetCacheViewImage(iterator->view));
486 *number_wands=iterator->region.width;
487 return(iterator->pixel_wands);
516WandExport
char *PixelGetIteratorException(
const PixelIterator *iterator,
517 ExceptionType *severity)
523 assert(iterator->signature == MagickWandSignature);
524 if (iterator->debug != MagickFalse)
525 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
526 assert(severity != (ExceptionType *) NULL);
527 *severity=iterator->exception->severity;
528 description=(
char *) AcquireQuantumMemory(2UL*MagickPathExtent,
529 sizeof(*description));
530 if (description == (
char *) NULL)
531 ThrowWandFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed",
534 if (iterator->exception->reason != (
char *) NULL)
535 (void) CopyMagickString(description,GetLocaleExceptionMessage(
536 iterator->exception->severity,iterator->exception->reason),
538 if (iterator->exception->description != (
char *) NULL)
540 (void) ConcatenateMagickString(description,
" (",MagickPathExtent);
541 (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
542 iterator->exception->severity,iterator->exception->description),
544 (void) ConcatenateMagickString(description,
")",MagickPathExtent);
573WandExport ExceptionType PixelGetIteratorExceptionType(
577 assert(iterator->signature == MagickWandSignature);
578 if (iterator->debug != MagickFalse)
579 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
580 return(iterator->exception->severity);
605WandExport ssize_t PixelGetIteratorRow(
PixelIterator *iterator)
608 assert(iterator->signature == MagickWandSignature);
609 if (iterator->debug != MagickFalse)
610 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
641 size_t *number_wands)
650 assert(iterator->signature == MagickWandSignature);
651 if (iterator->debug != MagickFalse)
652 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
654 if (iterator->active != MagickFalse)
656 if (PixelSetIteratorRow(iterator,iterator->y) == MagickFalse)
658 pixels=GetCacheViewVirtualPixels(iterator->view,iterator->region.x,
659 iterator->region.y+iterator->y,iterator->region.width,1,
660 iterator->exception);
661 if (pixels == (
const Quantum *) NULL)
663 for (x=0; x < (ssize_t) iterator->region.width; x++)
665 PixelSetQuantumPixel(GetCacheViewImage(iterator->view),pixels,
666 iterator->pixel_wands[x]);
667 pixels+=GetPixelChannels(GetCacheViewImage(iterator->view));
669 *number_wands=iterator->region.width;
670 return(iterator->pixel_wands);
700 size_t *number_wands)
709 assert(iterator->signature == MagickWandSignature);
710 if (iterator->debug != MagickFalse)
711 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
713 if (iterator->active != MagickFalse)
715 if (PixelSetIteratorRow(iterator,iterator->y) == MagickFalse)
717 pixels=GetCacheViewVirtualPixels(iterator->view,iterator->region.x,
718 iterator->region.y+iterator->y,iterator->region.width,1,
719 iterator->exception);
720 if (pixels == (
const Quantum *) NULL)
722 for (x=0; x < (ssize_t) iterator->region.width; x++)
724 PixelSetQuantumPixel(GetCacheViewImage(iterator->view),pixels,
725 iterator->pixel_wands[x]);
726 pixels+=GetPixelChannels(GetCacheViewImage(iterator->view));
728 *number_wands=iterator->region.width;
729 return(iterator->pixel_wands);
759 assert(iterator->signature == MagickWandSignature);
760 if (iterator->debug != MagickFalse)
761 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
762 iterator->active=MagickFalse;
788WandExport
void PixelSetFirstIteratorRow(
PixelIterator *iterator)
791 assert(iterator->signature == MagickWandSignature);
792 if (iterator->debug != MagickFalse)
793 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
794 iterator->active=MagickFalse;
795 iterator->y=iterator->region.y;
821WandExport MagickBooleanType PixelSetIteratorRow(
PixelIterator *iterator,
825 assert(iterator->signature == MagickWandSignature);
826 if (iterator->debug != MagickFalse)
827 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
828 if ((row < 0) || (row >= (ssize_t) iterator->region.height))
830 iterator->active=MagickTrue;
857WandExport
void PixelSetLastIteratorRow(
PixelIterator *iterator)
860 assert(iterator->signature == MagickWandSignature);
861 if (iterator->debug != MagickFalse)
862 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
863 iterator->active=MagickFalse;
864 iterator->y=(ssize_t) iterator->region.height-1;
889WandExport MagickBooleanType PixelSyncIterator(
PixelIterator *iterator)
895 *magick_restrict pixels;
901 assert(iterator->signature == MagickWandSignature);
902 if (iterator->debug != MagickFalse)
903 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",iterator->name);
904 status=SetCacheViewStorageClass(iterator->view,DirectClass,
905 iterator->exception);
906 if (status == MagickFalse)
908 pixels=GetCacheViewAuthenticPixels(iterator->view,iterator->region.x,
909 iterator->region.y+iterator->y,iterator->region.width,1,
910 iterator->exception);
911 if (pixels == (Quantum *) NULL)
913 for (x=0; x < (ssize_t) iterator->region.width; x++)
915 PixelGetQuantumPixel(GetCacheViewImage(iterator->view),
916 iterator->pixel_wands[x],pixels);
917 pixels+=GetPixelChannels(GetCacheViewImage(iterator->view));
919 if (SyncCacheViewAuthenticPixels(iterator->view,iterator->exception) == MagickFalse)