2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % PPPP IIIII X X EEEEE L %
10 % P IIIII X X EEEEE LLLLL %
12 % IIIII TTTTT EEEEE RRRR AAA TTTTT OOO RRRR %
13 % I T E R R A A T O O R R %
14 % I T EEE RRRR AAAAA T O O RRRR %
15 % I T E R R A A T O O R R %
16 % IIIII T EEEEE R R A A T OOO R R %
19 % ImageMagick Image Pixel Iterator Methods %
26 % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
27 % dedicated to making software imaging solutions freely available. %
29 % You may not use this file except in compliance with the License. You may %
30 % obtain a copy of the License at %
32 % http://www.imagemagick.org/script/license.php %
34 % Unless required by applicable law or agreed to in writing, software %
35 % distributed under the License is distributed on an "AS IS" BASIS, %
36 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
37 % See the License for the specific language governing permissions and %
38 % limitations under the License. %
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 #include "wand/studio.h"
50 #include "wand/MagickWand.h"
51 #include "wand/magick-wand-private.h"
52 #include "wand/pixel-iterator.h"
53 #include "wand/pixel-wand.h"
54 #include "wand/wand.h"
59 #define PixelIteratorId "PixelIterator"
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 % C l e a r P i x e l I t e r a t o r %
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 % ClearPixelIterator() clear resources associated with a PixelIterator.
110 % The format of the ClearPixelIterator method is:
112 % PixelIterator *ClearPixelIterator(PixelIterator *iterator)
114 % A description of each parameter follows:
116 % o iterator: the pixel iterator.
119 WandExport void ClearPixelIterator(PixelIterator *iterator)
121 assert(iterator != (const PixelIterator *) NULL);
122 assert(iterator->signature == WandSignature);
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();
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 % C l o n e P i x e l I t e r a t o r %
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 % ClonePixelIterator() makes an exact copy of the specified iterator.
147 % The format of the ClonePixelIterator method is:
149 % PixelIterator *ClonePixelIterator(const PixelIterator *iterator)
151 % A description of each parameter follows:
153 % o iterator: the magick iterator.
156 WandExport PixelIterator *ClonePixelIterator(const PixelIterator *iterator)
161 assert(iterator != (PixelIterator *) NULL);
162 assert(iterator->signature == WandSignature);
163 if (iterator->debug != MagickFalse)
164 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
165 clone_iterator=(PixelIterator *) AcquireMagickMemory(
166 sizeof(*clone_iterator));
167 if (clone_iterator == (PixelIterator *) NULL)
168 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
170 (void) ResetMagickMemory(clone_iterator,0,sizeof(*clone_iterator));
171 clone_iterator->id=AcquireWandId();
172 (void) FormatMagickString(clone_iterator->name,MaxTextExtent,"%s-%.20g",
173 PixelIteratorId,(double) clone_iterator->id);
174 clone_iterator->exception=AcquireExceptionInfo();
175 InheritException(clone_iterator->exception,iterator->exception);
176 clone_iterator->view=CloneCacheView(iterator->view);
177 clone_iterator->region=iterator->region;
178 clone_iterator->active=iterator->active;
179 clone_iterator->y=iterator->y;
180 clone_iterator->pixel_wands=ClonePixelWands((const PixelWand **)
181 iterator->pixel_wands,iterator->region.width);
182 clone_iterator->debug=iterator->debug;
183 if (clone_iterator->debug != MagickFalse)
184 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",
185 clone_iterator->name);
186 clone_iterator->signature=WandSignature;
187 return(clone_iterator);
191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 % D e s t r o y P i x e l I t e r a t o r %
199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 % DestroyPixelIterator() deallocates resources associated with a PixelIterator.
203 % The format of the DestroyPixelIterator method is:
205 % PixelIterator *DestroyPixelIterator(PixelIterator *iterator)
207 % A description of each parameter follows:
209 % o iterator: the pixel iterator.
212 WandExport PixelIterator *DestroyPixelIterator(PixelIterator *iterator)
214 assert(iterator != (const PixelIterator *) NULL);
215 assert(iterator->signature == WandSignature);
216 if (iterator->debug != MagickFalse)
217 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
218 iterator->view=DestroyCacheView(iterator->view);
219 iterator->pixel_wands=DestroyPixelWands(iterator->pixel_wands,
220 iterator->region.width);
221 iterator->exception=DestroyExceptionInfo(iterator->exception);
222 iterator->signature=(~WandSignature);
223 RelinquishWandId(iterator->id);
224 iterator=(PixelIterator *) RelinquishMagickMemory(iterator);
229 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 % I s P i x e l I t e r a t o r %
237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239 % IsPixelIterator() returns MagickTrue if the iterator is verified as a pixel
242 % The format of the IsPixelIterator method is:
244 % MagickBooleanType IsPixelIterator(const PixelIterator *iterator)
246 % A description of each parameter follows:
248 % o iterator: the magick iterator.
251 WandExport MagickBooleanType IsPixelIterator(const PixelIterator *iterator)
256 if (iterator == (const PixelIterator *) NULL)
258 if (iterator->signature != WandSignature)
260 length=strlen(PixelIteratorId);
261 if (LocaleNCompare(iterator->name,PixelIteratorId,length) != 0)
267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271 % N e w P i x e l I t e r a t o r %
275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277 % NewPixelIterator() returns a new pixel iterator.
279 % The format of the NewPixelIterator method is:
281 % PixelIterator *NewPixelIterator(MagickWand *wand)
283 % A description of each parameter follows:
285 % o wand: the magick wand.
288 WandExport PixelIterator *NewPixelIterator(MagickWand *wand)
305 depth=MAGICKCORE_QUANTUM_DEPTH;
306 quantum=GetMagickQuantumDepth(&depth);
307 if (depth != MAGICKCORE_QUANTUM_DEPTH)
308 ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
309 assert(wand != (MagickWand *) NULL);
310 image=GetImageFromMagickWand(wand);
311 if (image == (Image *) NULL)
312 return((PixelIterator *) NULL);
313 view=AcquireCacheView(image);
314 if (view == (CacheView *) NULL)
315 return((PixelIterator *) NULL);
316 iterator=(PixelIterator *) AcquireMagickMemory(sizeof(*iterator));
317 if (iterator == (PixelIterator *) NULL)
318 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
319 GetExceptionMessage(errno));
320 (void) ResetMagickMemory(iterator,0,sizeof(*iterator));
321 iterator->id=AcquireWandId();
322 (void) FormatMagickString(iterator->name,MaxTextExtent,"%s-%.20g",
323 PixelIteratorId,(double) iterator->id);
324 iterator->exception=AcquireExceptionInfo();
326 SetGeometry(image,&iterator->region);
327 iterator->region.width=image->columns;
328 iterator->region.height=image->rows;
329 iterator->region.x=0;
330 iterator->region.y=0;
331 iterator->pixel_wands=NewPixelWands(iterator->region.width);
333 iterator->debug=IsEventLogging();
334 if (iterator->debug != MagickFalse)
335 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
336 iterator->signature=WandSignature;
341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345 % P i x e l C l e a r I t e r a t o r E x c e p t i o n %
349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
351 % PixelClearIteratorException() clear any exceptions associated with the
354 % The format of the PixelClearIteratorException method is:
356 % MagickBooleanType PixelClearIteratorException(PixelIterator *wand)
358 % A description of each parameter follows:
360 % o wand: the pixel wand.
363 WandExport MagickBooleanType PixelClearIteratorException(
364 PixelIterator *iterator)
366 assert(iterator != (PixelIterator *) NULL);
367 assert(iterator->signature == WandSignature);
368 if (iterator->debug != MagickFalse)
369 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
370 ClearMagickException(iterator->exception);
375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 % N e w P i x e l R e g i o n I t e r a t o r %
383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
385 % NewPixelRegionIterator() returns a new pixel iterator.
387 % The format of the NewPixelRegionIterator method is:
389 % PixelIterator NewPixelRegionIterator(MagickWand *wand,const ssize_t x,
390 % const ssize_t y,const size_t width,const size_t height)
392 % A description of each parameter follows:
394 % o wand: the magick wand.
396 % o x,y,columns,rows: These values define the perimeter of a region of
400 WandExport PixelIterator *NewPixelRegionIterator(MagickWand *wand,
401 const ssize_t x,const ssize_t y,const size_t width,const size_t height)
418 assert(wand != (MagickWand *) NULL);
419 depth=MAGICKCORE_QUANTUM_DEPTH;
420 quantum=GetMagickQuantumDepth(&depth);
421 if (depth != MAGICKCORE_QUANTUM_DEPTH)
422 ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
423 if ((width == 0) || (width == 0))
424 ThrowWandFatalException(WandError,"ZeroRegionSize",quantum);
425 image=GetImageFromMagickWand(wand);
426 if (image == (Image *) NULL)
427 return((PixelIterator *) NULL);
428 view=AcquireCacheView(image);
429 if (view == (CacheView *) NULL)
430 return((PixelIterator *) NULL);
431 iterator=(PixelIterator *) AcquireMagickMemory(sizeof(*iterator));
432 if (iterator == (PixelIterator *) NULL)
433 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
435 (void) ResetMagickMemory(iterator,0,sizeof(*iterator));
436 iterator->id=AcquireWandId();
437 (void) FormatMagickString(iterator->name,MaxTextExtent,"%s-%.20g",
438 PixelIteratorId,(double) iterator->id);
439 iterator->exception=AcquireExceptionInfo();
441 SetGeometry(image,&iterator->region);
442 iterator->region.width=width;
443 iterator->region.height=height;
444 iterator->region.x=x;
445 iterator->region.y=y;
446 iterator->pixel_wands=NewPixelWands(iterator->region.width);
448 iterator->debug=IsEventLogging();
449 if (iterator->debug != MagickFalse)
450 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
451 iterator->signature=WandSignature;
456 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
460 % P i x e l G e t C u r r e n t I t e r a t o r R o w %
464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
466 % PixelGetCurrentIteratorRow() returns the current row as an array of pixel
467 % wands from the pixel iterator.
469 % The format of the PixelGetCurrentIteratorRow method is:
471 % PixelWand **PixelGetCurrentIteratorRow(PixelIterator *iterator,
472 % size_t *number_wands)
474 % A description of each parameter follows:
476 % o iterator: the pixel iterator.
478 % o number_wands: the number of pixel wands.
481 WandExport PixelWand **PixelGetCurrentIteratorRow(PixelIterator *iterator,
482 size_t *number_wands)
484 register const IndexPacket
487 register const PixelPacket
493 assert(iterator != (PixelIterator *) NULL);
494 assert(iterator->signature == WandSignature);
495 if (iterator->debug != MagickFalse)
496 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
498 iterator->active=MagickTrue;
499 pixels=GetCacheViewVirtualPixels(iterator->view,iterator->region.x,
500 iterator->region.y+iterator->y,iterator->region.width,1,
501 iterator->exception);
502 if (pixels == (const PixelPacket *) NULL)
504 InheritException(iterator->exception,GetCacheViewException(
506 return((PixelWand **) NULL);
508 indexes=GetCacheViewVirtualIndexQueue(iterator->view);
509 for (x=0; x < (ssize_t) iterator->region.width; x++)
510 PixelSetQuantumColor(iterator->pixel_wands[x],pixels+x);
511 if (GetCacheViewColorspace(iterator->view) == CMYKColorspace)
512 for (x=0; x < (ssize_t) iterator->region.width; x++)
513 PixelSetBlackQuantum(iterator->pixel_wands[x],indexes[x]);
514 if (GetCacheViewStorageClass(iterator->view) == PseudoClass)
515 for (x=0; x < (ssize_t) iterator->region.width; x++)
516 PixelSetIndex(iterator->pixel_wands[x],indexes[x]);
517 *number_wands=iterator->region.width;
518 return(iterator->pixel_wands);
522 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
526 % P i x e l G e t I t e r a t o r E x c e p t i o n %
530 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
532 % PixelGetIteratorException() returns the severity, reason, and description of
533 % any error that occurs when using other methods in this API.
535 % The format of the PixelGetIteratorException method is:
537 % char *PixelGetIteratorException(const Pixeliterator *iterator,
538 % ExceptionType *severity)
540 % A description of each parameter follows:
542 % o iterator: the pixel iterator.
544 % o severity: the severity of the error is returned here.
547 WandExport char *PixelGetIteratorException(const PixelIterator *iterator,
548 ExceptionType *severity)
553 assert(iterator != (const PixelIterator *) NULL);
554 assert(iterator->signature == WandSignature);
555 if (iterator->debug != MagickFalse)
556 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
557 assert(severity != (ExceptionType *) NULL);
558 *severity=iterator->exception->severity;
559 description=(char *) AcquireQuantumMemory(2UL*MaxTextExtent,
560 sizeof(*description));
561 if (description == (char *) NULL)
562 ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
565 if (iterator->exception->reason != (char *) NULL)
566 (void) CopyMagickString(description,GetLocaleExceptionMessage(
567 iterator->exception->severity,iterator->exception->reason),MaxTextExtent);
568 if (iterator->exception->description != (char *) NULL)
570 (void) ConcatenateMagickString(description," (",MaxTextExtent);
571 (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
572 iterator->exception->severity,iterator->exception->description),
574 (void) ConcatenateMagickString(description,")",MaxTextExtent);
580 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
584 % P i x e l G e t E x c e p t i o n T y p e %
588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
590 % PixelGetIteratorExceptionType() the exception type associated with the wand.
591 % If no exception has occurred, UndefinedExceptionType is returned.
593 % The format of the PixelGetIteratorExceptionType method is:
595 % ExceptionType PixelGetIteratorExceptionType(const PixelWand *wand)
597 % A description of each parameter follows:
599 % o wand: the magick wand.
602 WandExport ExceptionType PixelGetIteratorExceptionType(
603 const PixelIterator *wand)
605 assert(wand != (const PixelIterator *) NULL);
606 assert(wand->signature == WandSignature);
607 if (wand->debug != MagickFalse)
608 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
609 return(wand->exception->severity);
613 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
617 % P i x e l G e t I t e r a t o r R o w %
621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
623 % PixelGetIteratorRow() returns the current pixel iterator row.
625 % The format of the PixelGetIteratorRow method is:
627 % MagickBooleanType PixelGetIteratorRow(PixelIterator *iterator)
629 % A description of each parameter follows:
631 % o iterator: the pixel iterator.
634 WandExport ssize_t PixelGetIteratorRow(PixelIterator *iterator)
636 assert(iterator != (const PixelIterator *) NULL);
637 assert(iterator->signature == WandSignature);
638 if (iterator->debug != MagickFalse)
639 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
648 % P i x e l G e t N e x t I t e r a t o r R o w %
652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
654 % PixelGetNextIteratorRow() returns the next row as an array of pixel wands
655 % from the pixel iterator.
657 % The format of the PixelGetNextIteratorRow method is:
659 % PixelWand **PixelGetNextIteratorRow(PixelIterator *iterator,
660 % size_t *number_wands)
662 % A description of each parameter follows:
664 % o iterator: the pixel iterator.
666 % o number_wands: the number of pixel wands.
669 WandExport PixelWand **PixelGetNextIteratorRow(PixelIterator *iterator,
670 size_t *number_wands)
672 register const IndexPacket
675 register const PixelPacket
681 assert(iterator != (PixelIterator *) NULL);
682 assert(iterator->signature == WandSignature);
683 if (iterator->debug != MagickFalse)
684 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
686 if (iterator->active != MagickFalse)
688 if (PixelSetIteratorRow(iterator,iterator->y) == MagickFalse)
689 return((PixelWand **) NULL);
690 pixels=GetCacheViewVirtualPixels(iterator->view,iterator->region.x,
691 iterator->region.y+iterator->y,iterator->region.width,1,
692 iterator->exception);
693 if (pixels == (const PixelPacket *) NULL)
695 InheritException(iterator->exception,GetCacheViewException(
697 return((PixelWand **) NULL);
699 indexes=GetCacheViewVirtualIndexQueue(iterator->view);
700 for (x=0; x < (ssize_t) iterator->region.width; x++)
701 PixelSetQuantumColor(iterator->pixel_wands[x],pixels+x);
702 if (GetCacheViewColorspace(iterator->view) == CMYKColorspace)
703 for (x=0; x < (ssize_t) iterator->region.width; x++)
704 PixelSetBlackQuantum(iterator->pixel_wands[x],indexes[x]);
705 if (GetCacheViewStorageClass(iterator->view) == PseudoClass)
706 for (x=0; x < (ssize_t) iterator->region.width; x++)
707 PixelSetIndex(iterator->pixel_wands[x],indexes[x]);
708 *number_wands=iterator->region.width;
709 return(iterator->pixel_wands);
713 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
717 % P i x e l G e t P r e v i o u s I t e r a t o r R o w %
721 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
723 % PixelGetPreviousIteratorRow() returns the previous row as an array of pixel
724 % wands from the pixel iterator.
726 % The format of the PixelGetPreviousIteratorRow method is:
728 % PixelWand **PixelGetPreviousIteratorRow(PixelIterator *iterator,
729 % size_t *number_wands)
731 % A description of each parameter follows:
733 % o iterator: the pixel iterator.
735 % o number_wands: the number of pixel wands.
739 WandExport PixelWand **PixelGetPreviousRow(PixelIterator *iterator)
744 return(PixelGetPreviousIteratorRow(iterator,&number_wands));
747 WandExport PixelWand **PixelGetPreviousIteratorRow(PixelIterator *iterator,
748 size_t *number_wands)
750 register const IndexPacket
753 register const PixelPacket
759 assert(iterator != (PixelIterator *) NULL);
760 assert(iterator->signature == WandSignature);
761 if (iterator->debug != MagickFalse)
762 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
764 if (iterator->active != MagickFalse)
766 if (PixelSetIteratorRow(iterator,iterator->y) == MagickFalse)
767 return((PixelWand **) NULL);
768 pixels=GetCacheViewVirtualPixels(iterator->view,iterator->region.x,
769 iterator->region.y+iterator->y,iterator->region.width,1,
770 iterator->exception);
771 if (pixels == (const PixelPacket *) NULL)
773 InheritException(iterator->exception,GetCacheViewException(
775 return((PixelWand **) NULL);
777 indexes=GetCacheViewVirtualIndexQueue(iterator->view);
778 for (x=0; x < (ssize_t) iterator->region.width; x++)
779 PixelSetQuantumColor(iterator->pixel_wands[x],pixels+x);
780 if (GetCacheViewColorspace(iterator->view) == CMYKColorspace)
781 for (x=0; x < (ssize_t) iterator->region.width; x++)
782 PixelSetBlackQuantum(iterator->pixel_wands[x],indexes[x]);
783 if (GetCacheViewStorageClass(iterator->view) == PseudoClass)
784 for (x=0; x < (ssize_t) iterator->region.width; x++)
785 PixelSetIndex(iterator->pixel_wands[x],indexes[x]);
786 *number_wands=iterator->region.width;
787 return(iterator->pixel_wands);
791 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
795 % P i x e l R e s e t I t e r a t o r %
799 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
801 % PixelResetIterator() resets the pixel iterator. Use it in conjunction
802 % with PixelGetNextIteratorRow() to iterate over all the pixels in a pixel
805 % The format of the PixelResetIterator method is:
807 % void PixelResetIterator(PixelIterator *iterator)
809 % A description of each parameter follows:
811 % o iterator: the pixel iterator.
814 WandExport void PixelResetIterator(PixelIterator *iterator)
816 assert(iterator != (PixelIterator *) NULL);
817 assert(iterator->signature == WandSignature);
818 if (iterator->debug != MagickFalse)
819 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
820 iterator->active=MagickFalse;
825 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
829 % P i x e l S e t F i r s t I t e r a t o r R o w %
833 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
835 % PixelSetFirstIteratorRow() sets the pixel iterator to the first pixel row.
837 % The format of the PixelSetFirstIteratorRow method is:
839 % void PixelSetFirstIteratorRow(PixelIterator *iterator)
841 % A description of each parameter follows:
843 % o iterator: the magick iterator.
846 WandExport void PixelSetFirstIteratorRow(PixelIterator *iterator)
848 assert(iterator != (PixelIterator *) NULL);
849 assert(iterator->signature == WandSignature);
850 if (iterator->debug != MagickFalse)
851 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
852 iterator->active=MagickFalse;
853 iterator->y=iterator->region.y;
857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
861 % P i x e l S e t I t e r a t o r R o w %
865 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
867 % PixelSetIteratorRow() set the pixel iterator row.
869 % The format of the PixelSetIteratorRow method is:
871 % MagickBooleanType PixelSetIteratorRow(PixelIterator *iterator,
874 % A description of each parameter follows:
876 % o iterator: the pixel iterator.
879 WandExport MagickBooleanType PixelSetIteratorRow(PixelIterator *iterator,
882 assert(iterator != (const PixelIterator *) NULL);
883 assert(iterator->signature == WandSignature);
884 if (iterator->debug != MagickFalse)
885 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
886 if ((row < 0) || (row >= (ssize_t) iterator->region.height))
888 iterator->active=MagickTrue;
894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
898 % P i x e l S e t L a s t I t e r a t o r R o w %
902 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
904 % PixelSetLastIteratorRow() sets the pixel iterator to the last pixel row.
906 % The format of the PixelSetLastIteratorRow method is:
908 % void PixelSetLastIteratorRow(PixelIterator *iterator)
910 % A description of each parameter follows:
912 % o iterator: the magick iterator.
915 WandExport void PixelSetLastIteratorRow(PixelIterator *iterator)
917 assert(iterator != (PixelIterator *) NULL);
918 assert(iterator->signature == WandSignature);
919 if (iterator->debug != MagickFalse)
920 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
921 iterator->active=MagickFalse;
922 iterator->y=(ssize_t) iterator->region.height-1;
926 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
930 % P i x e l S y n c I t e r a t o r %
934 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
936 % PixelSyncIterator() syncs the pixel iterator.
938 % The format of the PixelSyncIterator method is:
940 % MagickBooleanType PixelSyncIterator(PixelIterator *iterator)
942 % A description of each parameter follows:
944 % o iterator: the pixel iterator.
947 WandExport MagickBooleanType PixelSyncIterator(PixelIterator *iterator)
961 assert(iterator != (const PixelIterator *) NULL);
962 assert(iterator->signature == WandSignature);
963 if (iterator->debug != MagickFalse)
964 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
965 if (SetCacheViewStorageClass(iterator->view,DirectClass) == MagickFalse)
967 exception=iterator->exception;
968 pixels=GetCacheViewAuthenticPixels(iterator->view,iterator->region.x,
969 iterator->region.y+iterator->y,iterator->region.width,1,exception);
970 if (pixels == (PixelPacket *) NULL)
972 InheritException(iterator->exception,GetCacheViewException(
976 indexes=GetCacheViewAuthenticIndexQueue(iterator->view);
977 for (x=0; x < (ssize_t) iterator->region.width; x++)
978 PixelGetQuantumColor(iterator->pixel_wands[x],pixels+x);
979 if (GetCacheViewColorspace(iterator->view) == CMYKColorspace)
980 for (x=0; x < (ssize_t) iterator->region.width; x++)
981 indexes[x]=PixelGetBlackQuantum(iterator->pixel_wands[x]);
982 if (SyncCacheViewAuthenticPixels(iterator->view,exception) == MagickFalse)
984 InheritException(iterator->exception,GetCacheViewException(