MagickWand 7.1.1
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
pixel-iterator.c
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% PPPP IIIII X X EEEEE L %
7% P P I X X E L %
8% PPPP I X EEE L %
9% P I X X E L %
10% P IIIII X X EEEEE LLLLL %
11% %
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 %
17% %
18% %
19% ImageMagick Image Pixel Iterator Methods %
20% %
21% Software Design %
22% Cristy %
23% March 2003 %
24% %
25% %
26% Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization %
27% dedicated to making software imaging solutions freely available. %
28% %
29% You may not use this file except in compliance with the License. You may %
30% obtain a copy of the License at %
31% %
32% https://imagemagick.org/script/license.php %
33% %
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. %
39% %
40%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41%
42%
43%
44*/
45
46/*
47 Include declarations.
48*/
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"
55
56/*
57 Define declarations.
58*/
59#define PixelIteratorId "PixelIterator"
60
61/*
62 Typedef declarations.
63*/
65{
66 size_t
67 id;
68
69 char
70 name[MagickPathExtent];
71
72 ExceptionInfo
73 *exception;
74
75 CacheView
76 *view;
77
78 RectangleInfo
79 region;
80
81 MagickBooleanType
82 active; /* user has been given pixel data */
83
84 ssize_t
85 y;
86
88 **pixel_wands;
89
90 MagickBooleanType
91 debug;
92
93 size_t
94 signature;
95};
96
97/*
98%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99% %
100% %
101% %
102% C l e a r P i x e l I t e r a t o r %
103% %
104% %
105% %
106%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107%
108% ClearPixelIterator() clear resources associated with a PixelIterator.
109%
110% The format of the ClearPixelIterator method is:
111%
112% void ClearPixelIterator(PixelIterator *iterator)
113%
114% A description of each parameter follows:
115%
116% o iterator: the pixel iterator.
117%
118*/
119WandExport void ClearPixelIterator(PixelIterator *iterator)
120{
121 assert(iterator != (const PixelIterator *) NULL);
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;
130 iterator->y=0;
131 iterator->debug=IsEventLogging();
132}
133
134/*
135%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136% %
137% %
138% %
139% C l o n e P i x e l I t e r a t o r %
140% %
141% %
142% %
143%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144%
145% ClonePixelIterator() makes an exact copy of the specified iterator.
146%
147% The format of the ClonePixelIterator method is:
148%
149% PixelIterator *ClonePixelIterator(const PixelIterator *iterator)
150%
151% A description of each parameter follows:
152%
153% o iterator: the magick iterator.
154%
155*/
156WandExport PixelIterator *ClonePixelIterator(const PixelIterator *iterator)
157{
159 *clone_iterator;
160
161 assert(iterator != (PixelIterator *) NULL);
162 assert(iterator->signature == MagickWandSignature);
163 if (iterator->debug != MagickFalse)
164 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
165 clone_iterator=(PixelIterator *) AcquireCriticalMemory(
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);
185}
186
187/*
188%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189% %
190% %
191% %
192% D e s t r o y P i x e l I t e r a t o r %
193% %
194% %
195% %
196%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197%
198% DestroyPixelIterator() deallocates resources associated with a PixelIterator.
199%
200% The format of the DestroyPixelIterator method is:
201%
202% PixelIterator *DestroyPixelIterator(PixelIterator *iterator)
203%
204% A description of each parameter follows:
205%
206% o iterator: the pixel iterator.
207%
208*/
209WandExport PixelIterator *DestroyPixelIterator(PixelIterator *iterator)
210{
211 assert(iterator != (const PixelIterator *) NULL);
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);
221 iterator=(PixelIterator *) RelinquishMagickMemory(iterator);
222 return(iterator);
223}
224
225/*
226%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227% %
228% %
229% %
230% I s P i x e l I t e r a t o r %
231% %
232% %
233% %
234%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235%
236% IsPixelIterator() returns MagickTrue if the iterator is verified as a pixel
237% iterator.
238%
239% The format of the IsPixelIterator method is:
240%
241% MagickBooleanType IsPixelIterator(const PixelIterator *iterator)
242%
243% A description of each parameter follows:
244%
245% o iterator: the magick iterator.
246%
247*/
248WandExport MagickBooleanType IsPixelIterator(const PixelIterator *iterator)
249{
250 size_t
251 length;
252
253 if (iterator == (const PixelIterator *) NULL)
254 return(MagickFalse);
255 if (iterator->signature != MagickWandSignature)
256 return(MagickFalse);
257 length=strlen(PixelIteratorId);
258 if (LocaleNCompare(iterator->name,PixelIteratorId,length) != 0)
259 return(MagickFalse);
260 return(MagickTrue);
261}
262
263/*
264%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265% %
266% %
267% %
268% N e w P i x e l I t e r a t o r %
269% %
270% %
271% %
272%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
273%
274% NewPixelIterator() returns a new pixel iterator.
275%
276% The format of the NewPixelIterator method is:
277%
278% PixelIterator *NewPixelIterator(MagickWand *wand)
279%
280% A description of each parameter follows:
281%
282% o wand: the magick wand.
283%
284*/
285WandExport PixelIterator *NewPixelIterator(MagickWand *wand)
286{
287 ExceptionInfo
288 *exception;
289
290 Image
291 *image;
292
294 *iterator;
295
296 CacheView
297 *view;
298
299 assert(wand != (MagickWand *) NULL);
300 image=GetImageFromMagickWand(wand);
301 if (image == (Image *) NULL)
302 return((PixelIterator *) NULL);
303 exception=AcquireExceptionInfo();
304 view=AcquireVirtualCacheView(image,exception);
305 if (view == (CacheView *) NULL)
306 return((PixelIterator *) 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;
313 iterator->view=view;
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);
320 iterator->y=0;
321 iterator->debug=IsEventLogging();
322 if (iterator->debug != MagickFalse)
323 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
324 iterator->signature=MagickWandSignature;
325 return(iterator);
326}
327
328/*
329%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
330% %
331% %
332% %
333% 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 %
334% %
335% %
336% %
337%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338%
339% PixelClearIteratorException() clear any exceptions associated with the
340% iterator.
341%
342% The format of the PixelClearIteratorException method is:
343%
344% MagickBooleanType PixelClearIteratorException(PixelIterator *iterator)
345%
346% A description of each parameter follows:
347%
348% o iterator: the pixel iterator.
349%
350*/
351WandExport MagickBooleanType PixelClearIteratorException(
352 PixelIterator *iterator)
353{
354 assert(iterator != (PixelIterator *) NULL);
355 assert(iterator->signature == MagickWandSignature);
356 if (iterator->debug != MagickFalse)
357 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
358 ClearMagickException(iterator->exception);
359 return(MagickTrue);
360}
361
362/*
363%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
364% %
365% %
366% %
367% N e w P i x e l R e g i o n I t e r a t o r %
368% %
369% %
370% %
371%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
372%
373% NewPixelRegionIterator() returns a new pixel iterator.
374%
375% The format of the NewPixelRegionIterator method is:
376%
377% PixelIterator *NewPixelRegionIterator(MagickWand *wand,const ssize_t x,
378% const ssize_t y,const size_t width,const size_t height)
379%
380% A description of each parameter follows:
381%
382% o wand: the magick wand.
383%
384% o x,y,columns,rows: These values define the perimeter of a region of
385% pixels.
386%
387*/
388WandExport PixelIterator *NewPixelRegionIterator(MagickWand *wand,
389 const ssize_t x,const ssize_t y,const size_t width,const size_t height)
390{
391 CacheView
392 *view;
393
394 ExceptionInfo
395 *exception;
396
397 Image
398 *image;
399
401 *iterator;
402
403 assert(wand != (MagickWand *) NULL);
404 if ((width == 0) || (height == 0))
405 ThrowWandFatalException(WandError,"ZeroRegionSize",wand->name);
406 image=GetImageFromMagickWand(wand);
407 if (image == (Image *) NULL)
408 return((PixelIterator *) NULL);
409 exception=AcquireExceptionInfo();
410 view=AcquireVirtualCacheView(image,exception);
411 if (view == (CacheView *) NULL)
412 return((PixelIterator *) 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;
419 iterator->view=view;
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);
426 iterator->y=0;
427 iterator->debug=IsEventLogging();
428 if (iterator->debug != MagickFalse)
429 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
430 iterator->signature=MagickWandSignature;
431 return(iterator);
432}
433
434/*
435%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
436% %
437% %
438% %
439% 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 %
440% %
441% %
442% %
443%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
444%
445% PixelGetCurrentIteratorRow() returns the current row as an array of pixel
446% wands from the pixel iterator.
447%
448% The format of the PixelGetCurrentIteratorRow method is:
449%
450% PixelWand **PixelGetCurrentIteratorRow(PixelIterator *iterator,
451% size_t *number_wands)
452%
453% A description of each parameter follows:
454%
455% o iterator: the pixel iterator.
456%
457% o number_wands: the number of pixel wands.
458%
459*/
460WandExport PixelWand **PixelGetCurrentIteratorRow(PixelIterator *iterator,
461 size_t *number_wands)
462{
463 const Quantum
464 *pixels;
465
466 ssize_t
467 x;
468
469 assert(iterator != (PixelIterator *) NULL);
470 assert(iterator->signature == MagickWandSignature);
471 if (iterator->debug != MagickFalse)
472 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
473 *number_wands=0;
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)
479 return((PixelWand **) NULL);
480 for (x=0; x < (ssize_t) iterator->region.width; x++)
481 {
482 PixelSetQuantumPixel(GetCacheViewImage(iterator->view),pixels,
483 iterator->pixel_wands[x]);
484 pixels+=GetPixelChannels(GetCacheViewImage(iterator->view));
485 }
486 *number_wands=iterator->region.width;
487 return(iterator->pixel_wands);
488}
489
490/*
491%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
492% %
493% %
494% %
495% 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 %
496% %
497% %
498% %
499%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
500%
501% PixelGetIteratorException() returns the severity, reason, and description of
502% any error that occurs when using other methods in this API.
503%
504% The format of the PixelGetIteratorException method is:
505%
506% char *PixelGetIteratorException(const PixelIterator *iterator,
507% ExceptionType *severity)
508%
509% A description of each parameter follows:
510%
511% o iterator: the pixel iterator.
512%
513% o severity: the severity of the error is returned here.
514%
515*/
516WandExport char *PixelGetIteratorException(const PixelIterator *iterator,
517 ExceptionType *severity)
518{
519 char
520 *description;
521
522 assert(iterator != (const PixelIterator *) NULL);
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",
532 iterator->name);
533 *description='\0';
534 if (iterator->exception->reason != (char *) NULL)
535 (void) CopyMagickString(description,GetLocaleExceptionMessage(
536 iterator->exception->severity,iterator->exception->reason),
537 MagickPathExtent);
538 if (iterator->exception->description != (char *) NULL)
539 {
540 (void) ConcatenateMagickString(description," (",MagickPathExtent);
541 (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
542 iterator->exception->severity,iterator->exception->description),
543 MagickPathExtent);
544 (void) ConcatenateMagickString(description,")",MagickPathExtent);
545 }
546 return(description);
547}
548
549/*
550%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
551% %
552% %
553% %
554% P i x e l G e t E x c e p t i o n T y p e %
555% %
556% %
557% %
558%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
559%
560% PixelGetIteratorExceptionType() the exception type associated with the
561% iterator. If no exception has occurred, UndefinedExceptionType is returned.
562%
563% The format of the PixelGetIteratorExceptionType method is:
564%
565% ExceptionType PixelGetIteratorExceptionType(
566% const PixelIterator *iterator)
567%
568% A description of each parameter follows:
569%
570% o iterator: the pixel iterator.
571%
572*/
573WandExport ExceptionType PixelGetIteratorExceptionType(
574 const PixelIterator *iterator)
575{
576 assert(iterator != (const PixelIterator *) NULL);
577 assert(iterator->signature == MagickWandSignature);
578 if (iterator->debug != MagickFalse)
579 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
580 return(iterator->exception->severity);
581}
582
583/*
584%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
585% %
586% %
587% %
588% P i x e l G e t I t e r a t o r R o w %
589% %
590% %
591% %
592%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
593%
594% PixelGetIteratorRow() returns the current pixel iterator row.
595%
596% The format of the PixelGetIteratorRow method is:
597%
598% MagickBooleanType PixelGetIteratorRow(PixelIterator *iterator)
599%
600% A description of each parameter follows:
601%
602% o iterator: the pixel iterator.
603%
604*/
605WandExport ssize_t PixelGetIteratorRow(PixelIterator *iterator)
606{
607 assert(iterator != (const PixelIterator *) NULL);
608 assert(iterator->signature == MagickWandSignature);
609 if (iterator->debug != MagickFalse)
610 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
611 return(iterator->y);
612}
613
614/*
615%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
616% %
617% %
618% %
619% P i x e l G e t N e x t I t e r a t o r R o w %
620% %
621% %
622% %
623%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
624%
625% PixelGetNextIteratorRow() returns the next row as an array of pixel wands
626% from the pixel iterator.
627%
628% The format of the PixelGetNextIteratorRow method is:
629%
630% PixelWand **PixelGetNextIteratorRow(PixelIterator *iterator,
631% size_t *number_wands)
632%
633% A description of each parameter follows:
634%
635% o iterator: the pixel iterator.
636%
637% o number_wands: the number of pixel wands.
638%
639*/
640WandExport PixelWand **PixelGetNextIteratorRow(PixelIterator *iterator,
641 size_t *number_wands)
642{
643 const Quantum
644 *pixels;
645
646 ssize_t
647 x;
648
649 assert(iterator != (PixelIterator *) NULL);
650 assert(iterator->signature == MagickWandSignature);
651 if (iterator->debug != MagickFalse)
652 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
653 *number_wands=0;
654 if (iterator->active != MagickFalse)
655 iterator->y++;
656 if (PixelSetIteratorRow(iterator,iterator->y) == MagickFalse)
657 return((PixelWand **) NULL);
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)
662 return((PixelWand **) NULL);
663 for (x=0; x < (ssize_t) iterator->region.width; x++)
664 {
665 PixelSetQuantumPixel(GetCacheViewImage(iterator->view),pixels,
666 iterator->pixel_wands[x]);
667 pixels+=GetPixelChannels(GetCacheViewImage(iterator->view));
668 }
669 *number_wands=iterator->region.width;
670 return(iterator->pixel_wands);
671}
672
673/*
674%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
675% %
676% %
677% %
678% 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 %
679% %
680% %
681% %
682%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
683%
684% PixelGetPreviousIteratorRow() returns the previous row as an array of pixel
685% wands from the pixel iterator.
686%
687% The format of the PixelGetPreviousIteratorRow method is:
688%
689% PixelWand **PixelGetPreviousIteratorRow(PixelIterator *iterator,
690% size_t *number_wands)
691%
692% A description of each parameter follows:
693%
694% o iterator: the pixel iterator.
695%
696% o number_wands: the number of pixel wands.
697%
698*/
699WandExport PixelWand **PixelGetPreviousIteratorRow(PixelIterator *iterator,
700 size_t *number_wands)
701{
702 const Quantum
703 *pixels;
704
705 ssize_t
706 x;
707
708 assert(iterator != (PixelIterator *) NULL);
709 assert(iterator->signature == MagickWandSignature);
710 if (iterator->debug != MagickFalse)
711 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
712 *number_wands=0;
713 if (iterator->active != MagickFalse)
714 iterator->y--;
715 if (PixelSetIteratorRow(iterator,iterator->y) == MagickFalse)
716 return((PixelWand **) NULL);
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)
721 return((PixelWand **) NULL);
722 for (x=0; x < (ssize_t) iterator->region.width; x++)
723 {
724 PixelSetQuantumPixel(GetCacheViewImage(iterator->view),pixels,
725 iterator->pixel_wands[x]);
726 pixels+=GetPixelChannels(GetCacheViewImage(iterator->view));
727 }
728 *number_wands=iterator->region.width;
729 return(iterator->pixel_wands);
730}
731
732/*
733%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
734% %
735% %
736% %
737% P i x e l R e s e t I t e r a t o r %
738% %
739% %
740% %
741%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
742%
743% PixelResetIterator() resets the pixel iterator. Use it in conjunction
744% with PixelGetNextIteratorRow() to iterate over all the pixels in a pixel
745% container.
746%
747% The format of the PixelResetIterator method is:
748%
749% void PixelResetIterator(PixelIterator *iterator)
750%
751% A description of each parameter follows:
752%
753% o iterator: the pixel iterator.
754%
755*/
756WandExport void PixelResetIterator(PixelIterator *iterator)
757{
758 assert(iterator != (PixelIterator *) NULL);
759 assert(iterator->signature == MagickWandSignature);
760 if (iterator->debug != MagickFalse)
761 (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
762 iterator->active=MagickFalse;
763 iterator->y=0;
764}
765
766/*
767%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
768% %
769% %
770% %
771% P i x e l S e t F i r s t I t e r a t o r R o w %
772% %
773% %
774% %
775%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
776%
777% PixelSetFirstIteratorRow() sets the pixel iterator to the first pixel row.
778%
779% The format of the PixelSetFirstIteratorRow method is:
780%
781% void PixelSetFirstIteratorRow(PixelIterator *iterator)
782%
783% A description of each parameter follows:
784%
785% o iterator: the magick iterator.
786%
787*/
788WandExport void PixelSetFirstIteratorRow(PixelIterator *iterator)
789{
790 assert(iterator != (PixelIterator *) NULL);
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;
796}
797
798/*
799%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
800% %
801% %
802% %
803% P i x e l S e t I t e r a t o r R o w %
804% %
805% %
806% %
807%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
808%
809% PixelSetIteratorRow() set the pixel iterator row.
810%
811% The format of the PixelSetIteratorRow method is:
812%
813% MagickBooleanType PixelSetIteratorRow(PixelIterator *iterator,
814% const ssize_t row)
815%
816% A description of each parameter follows:
817%
818% o iterator: the pixel iterator.
819%
820*/
821WandExport MagickBooleanType PixelSetIteratorRow(PixelIterator *iterator,
822 const ssize_t row)
823{
824 assert(iterator != (const PixelIterator *) NULL);
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))
829 return(MagickFalse);
830 iterator->active=MagickTrue;
831 iterator->y=row;
832 return(MagickTrue);
833}
834
835/*
836%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
837% %
838% %
839% %
840% P i x e l S e t L a s t I t e r a t o r R o w %
841% %
842% %
843% %
844%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
845%
846% PixelSetLastIteratorRow() sets the pixel iterator to the last pixel row.
847%
848% The format of the PixelSetLastIteratorRow method is:
849%
850% void PixelSetLastIteratorRow(PixelIterator *iterator)
851%
852% A description of each parameter follows:
853%
854% o iterator: the magick iterator.
855%
856*/
857WandExport void PixelSetLastIteratorRow(PixelIterator *iterator)
858{
859 assert(iterator != (PixelIterator *) NULL);
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;
865}
866
867/*
868%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
869% %
870% %
871% %
872% P i x e l S y n c I t e r a t o r %
873% %
874% %
875% %
876%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
877%
878% PixelSyncIterator() syncs the pixel iterator.
879%
880% The format of the PixelSyncIterator method is:
881%
882% MagickBooleanType PixelSyncIterator(PixelIterator *iterator)
883%
884% A description of each parameter follows:
885%
886% o iterator: the pixel iterator.
887%
888*/
889WandExport MagickBooleanType PixelSyncIterator(PixelIterator *iterator)
890{
891 MagickBooleanType
892 status;
893
894 Quantum
895 *magick_restrict pixels;
896
897 ssize_t
898 x;
899
900 assert(iterator != (const PixelIterator *) NULL);
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)
907 return(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)
912 return(MagickFalse);
913 for (x=0; x < (ssize_t) iterator->region.width; x++)
914 {
915 PixelGetQuantumPixel(GetCacheViewImage(iterator->view),
916 iterator->pixel_wands[x],pixels);
917 pixels+=GetPixelChannels(GetCacheViewImage(iterator->view));
918 }
919 if (SyncCacheViewAuthenticPixels(iterator->view,iterator->exception) == MagickFalse)
920 return(MagickFalse);
921 return(MagickTrue);
922}