MagickWand  6.7.5
pixel-iterator.c
Go to the documentation of this file.
00001 /*
00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00003 %                                                                             %
00004 %                                                                             %
00005 %                                                                             %
00006 %                      PPPP   IIIII  X   X  EEEEE  L                          %
00007 %                      P   P    I     X X   E      L                          %
00008 %                      PPPP     I      X    EEE    L                          %
00009 %                      P        I     X X   E      L                          %
00010 %                      P      IIIII  X   X  EEEEE  LLLLL                      %
00011 %                                                                             %
00012 %            IIIII  TTTTT EEEEE  RRRR    AAA   TTTTT   OOO   RRRR             %
00013 %              I      T   E      R   R  A   A    T    O   O  R   R            %
00014 %              I      T   EEE    RRRR   AAAAA    T    O   O  RRRR             %
00015 %              I      T   E      R R    A   A    T    O   O  R R              %
00016 %            IIIII    T   EEEEE  R  R   A   A    T     OOO   R  R             %
00017 %                                                                             %
00018 %                                                                             %
00019 %                   ImageMagick Image Pixel Iterator Methods                  %
00020 %                                                                             %
00021 %                              Software Design                                %
00022 %                                John Cristy                                  %
00023 %                                March 2003                                   %
00024 %                                                                             %
00025 %                                                                             %
00026 %  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
00027 %  dedicated to making software imaging solutions freely available.           %
00028 %                                                                             %
00029 %  You may not use this file except in compliance with the License.  You may  %
00030 %  obtain a copy of the License at                                            %
00031 %                                                                             %
00032 %    http://www.imagemagick.org/script/license.php                            %
00033 %                                                                             %
00034 %  Unless required by applicable law or agreed to in writing, software        %
00035 %  distributed under the License is distributed on an "AS IS" BASIS,          %
00036 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
00037 %  See the License for the specific language governing permissions and        %
00038 %  limitations under the License.                                             %
00039 %                                                                             %
00040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00041 %
00042 %
00043 %
00044 */
00045 
00046 /*
00047   Include declarations.
00048 */
00049 #include "MagickWand/studio.h"
00050 #include "MagickWand/MagickWand.h"
00051 #include "MagickWand/magick-wand-private.h"
00052 #include "MagickWand/pixel-iterator.h"
00053 #include "MagickWand/pixel-wand.h"
00054 #include "MagickWand/wand.h"
00055 
00056 /*
00057   Define declarations.
00058 */
00059 #define PixelIteratorId  "PixelIterator"
00060 
00061 /*
00062   Typedef declarations.
00063 */
00064 struct _PixelIterator
00065 {
00066   size_t
00067     id;
00068 
00069   char
00070     name[MaxTextExtent];
00071 
00072   ExceptionInfo
00073     *exception;
00074 
00075   Image
00076     *image;
00077 
00078   CacheView
00079     *view;
00080 
00081   RectangleInfo
00082     region;
00083 
00084   MagickBooleanType
00085     active;           /* user has been given pixel data */
00086 
00087   ssize_t
00088     y;
00089 
00090   PixelWand
00091     **pixel_wands;
00092 
00093   MagickBooleanType
00094     debug;
00095 
00096   size_t
00097     signature;
00098 };
00099 
00100 /*
00101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00102 %                                                                             %
00103 %                                                                             %
00104 %                                                                             %
00105 %   C l e a r P i x e l I t e r a t o r                                       %
00106 %                                                                             %
00107 %                                                                             %
00108 %                                                                             %
00109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00110 %
00111 %  ClearPixelIterator() clear resources associated with a PixelIterator.
00112 %
00113 %  The format of the ClearPixelIterator method is:
00114 %
00115 %      PixelIterator *ClearPixelIterator(PixelIterator *iterator)
00116 %
00117 %  A description of each parameter follows:
00118 %
00119 %    o iterator: the pixel iterator.
00120 %
00121 */
00122 WandExport void ClearPixelIterator(PixelIterator *iterator)
00123 {
00124   assert(iterator != (const PixelIterator *) NULL);
00125   assert(iterator->signature == WandSignature);
00126   if (iterator->debug != MagickFalse)
00127     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00128   iterator->pixel_wands=DestroyPixelWands(iterator->pixel_wands,
00129     iterator->region.width);
00130   ClearMagickException(iterator->exception);
00131   iterator->pixel_wands=NewPixelWands(iterator->region.width);
00132   iterator->active=MagickFalse;
00133   iterator->y=0;
00134   iterator->debug=IsEventLogging();
00135 }
00136 
00137 /*
00138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00139 %                                                                             %
00140 %                                                                             %
00141 %                                                                             %
00142 %   C l o n e P i x e l I t e r a t o r                                       %
00143 %                                                                             %
00144 %                                                                             %
00145 %                                                                             %
00146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00147 %
00148 %  ClonePixelIterator() makes an exact copy of the specified iterator.
00149 %
00150 %  The format of the ClonePixelIterator method is:
00151 %
00152 %      PixelIterator *ClonePixelIterator(const PixelIterator *iterator)
00153 %
00154 %  A description of each parameter follows:
00155 %
00156 %    o iterator: the magick iterator.
00157 %
00158 */
00159 WandExport PixelIterator *ClonePixelIterator(const PixelIterator *iterator)
00160 {
00161   PixelIterator
00162     *clone_iterator;
00163 
00164   assert(iterator != (PixelIterator *) NULL);
00165   assert(iterator->signature == WandSignature);
00166   if (iterator->debug != MagickFalse)
00167     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00168   clone_iterator=(PixelIterator *) AcquireMagickMemory(
00169     sizeof(*clone_iterator));
00170   if (clone_iterator == (PixelIterator *) NULL)
00171     ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
00172       iterator->name);
00173   (void) ResetMagickMemory(clone_iterator,0,sizeof(*clone_iterator));
00174   clone_iterator->id=AcquireWandId();
00175   (void) FormatLocaleString(clone_iterator->name,MaxTextExtent,"%s-%.20g",
00176     PixelIteratorId,(double) clone_iterator->id);
00177   clone_iterator->exception=AcquireExceptionInfo();
00178   InheritException(clone_iterator->exception,iterator->exception);
00179   clone_iterator->image=CloneImage(iterator->image,0,0,MagickTrue,
00180     iterator->exception);
00181   clone_iterator->view=CloneCacheView(iterator->view);
00182   clone_iterator->region=iterator->region;
00183   clone_iterator->active=iterator->active;
00184   clone_iterator->y=iterator->y;
00185   clone_iterator->pixel_wands=ClonePixelWands((const PixelWand **)
00186     iterator->pixel_wands,iterator->region.width);
00187   clone_iterator->debug=iterator->debug;
00188   if (clone_iterator->debug != MagickFalse)
00189     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",
00190       clone_iterator->name);
00191   clone_iterator->signature=WandSignature;
00192   return(clone_iterator);
00193 }
00194 
00195 /*
00196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00197 %                                                                             %
00198 %                                                                             %
00199 %                                                                             %
00200 %   D e s t r o y P i x e l I t e r a t o r                                   %
00201 %                                                                             %
00202 %                                                                             %
00203 %                                                                             %
00204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00205 %
00206 %  DestroyPixelIterator() deallocates resources associated with a PixelIterator.
00207 %
00208 %  The format of the DestroyPixelIterator method is:
00209 %
00210 %      PixelIterator *DestroyPixelIterator(PixelIterator *iterator)
00211 %
00212 %  A description of each parameter follows:
00213 %
00214 %    o iterator: the pixel iterator.
00215 %
00216 */
00217 WandExport PixelIterator *DestroyPixelIterator(PixelIterator *iterator)
00218 {
00219   assert(iterator != (const PixelIterator *) NULL);
00220   assert(iterator->signature == WandSignature);
00221   if (iterator->debug != MagickFalse)
00222     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00223   iterator->image=DestroyImage(iterator->image);
00224   iterator->view=DestroyCacheView(iterator->view);
00225   iterator->pixel_wands=DestroyPixelWands(iterator->pixel_wands,
00226     iterator->region.width);
00227   iterator->exception=DestroyExceptionInfo(iterator->exception);
00228   iterator->signature=(~WandSignature);
00229   RelinquishWandId(iterator->id);
00230   iterator=(PixelIterator *) RelinquishMagickMemory(iterator);
00231   return(iterator);
00232 }
00233 
00234 /*
00235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00236 %                                                                             %
00237 %                                                                             %
00238 %                                                                             %
00239 %   I s P i x e l I t e r a t o r                                             %
00240 %                                                                             %
00241 %                                                                             %
00242 %                                                                             %
00243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00244 %
00245 %  IsPixelIterator() returns MagickTrue if the iterator is verified as a pixel
00246 %  iterator.
00247 %
00248 %  The format of the IsPixelIterator method is:
00249 %
00250 %      MagickBooleanType IsPixelIterator(const PixelIterator *iterator)
00251 %
00252 %  A description of each parameter follows:
00253 %
00254 %    o iterator: the magick iterator.
00255 %
00256 */
00257 WandExport MagickBooleanType IsPixelIterator(const PixelIterator *iterator)
00258 {
00259   size_t
00260     length;
00261 
00262   if (iterator == (const PixelIterator *) NULL)
00263     return(MagickFalse);
00264   if (iterator->signature != WandSignature)
00265     return(MagickFalse);
00266   length=strlen(PixelIteratorId);
00267   if (LocaleNCompare(iterator->name,PixelIteratorId,length) != 0)
00268     return(MagickFalse);
00269   return(MagickTrue);
00270 }
00271 
00272 /*
00273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00274 %                                                                             %
00275 %                                                                             %
00276 %                                                                             %
00277 %   N e w P i x e l I t e r a t o r                                           %
00278 %                                                                             %
00279 %                                                                             %
00280 %                                                                             %
00281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00282 %
00283 %  NewPixelIterator() returns a new pixel iterator.
00284 %
00285 %  The format of the NewPixelIterator method is:
00286 %
00287 %      PixelIterator *NewPixelIterator(MagickWand *wand)
00288 %
00289 %  A description of each parameter follows:
00290 %
00291 %    o wand: the magick wand.
00292 %
00293 */
00294 WandExport PixelIterator *NewPixelIterator(MagickWand *wand)
00295 {
00296   const char
00297     *quantum;
00298 
00299   Image
00300     *image;
00301 
00302   PixelIterator
00303     *iterator;
00304 
00305   size_t
00306     depth;
00307 
00308   CacheView
00309     *view;
00310 
00311   depth=MAGICKCORE_QUANTUM_DEPTH;
00312   quantum=GetMagickQuantumDepth(&depth);
00313   if (depth != MAGICKCORE_QUANTUM_DEPTH)
00314     ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
00315   assert(wand != (MagickWand *) NULL);
00316   image=GetImageFromMagickWand(wand);
00317   if (image == (Image *) NULL)
00318     return((PixelIterator *) NULL);
00319   view=AcquireCacheView(image);
00320   if (view == (CacheView *) NULL)
00321     return((PixelIterator *) NULL);
00322   iterator=(PixelIterator *) AcquireMagickMemory(sizeof(*iterator));
00323   if (iterator == (PixelIterator *) NULL)
00324     ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
00325       GetExceptionMessage(errno));
00326   (void) ResetMagickMemory(iterator,0,sizeof(*iterator));
00327   iterator->id=AcquireWandId();
00328   (void) FormatLocaleString(iterator->name,MaxTextExtent,"%s-%.20g",
00329     PixelIteratorId,(double) iterator->id);
00330   iterator->exception=AcquireExceptionInfo();
00331   iterator->image=CloneImage(image,0,0,MagickTrue,iterator->exception);
00332   iterator->view=view;
00333   SetGeometry(image,&iterator->region);
00334   iterator->region.width=image->columns;
00335   iterator->region.height=image->rows;
00336   iterator->region.x=0;
00337   iterator->region.y=0;
00338   iterator->pixel_wands=NewPixelWands(iterator->region.width);
00339   iterator->y=0;
00340   iterator->debug=IsEventLogging();
00341   if (iterator->debug != MagickFalse)
00342     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00343   iterator->signature=WandSignature;
00344   return(iterator);
00345 }
00346 
00347 /*
00348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00349 %                                                                             %
00350 %                                                                             %
00351 %                                                                             %
00352 %   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                     %
00353 %                                                                             %
00354 %                                                                             %
00355 %                                                                             %
00356 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00357 %
00358 %  PixelClearIteratorException() clear any exceptions associated with the
00359 %  iterator.
00360 %
00361 %  The format of the PixelClearIteratorException method is:
00362 %
00363 %      MagickBooleanType PixelClearIteratorException(PixelIterator *wand)
00364 %
00365 %  A description of each parameter follows:
00366 %
00367 %    o wand: the pixel wand.
00368 %
00369 */
00370 WandExport MagickBooleanType PixelClearIteratorException(
00371   PixelIterator *iterator)
00372 {
00373   assert(iterator != (PixelIterator *) NULL);
00374   assert(iterator->signature == WandSignature);
00375   if (iterator->debug != MagickFalse)
00376     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00377   ClearMagickException(iterator->exception);
00378   return(MagickTrue);
00379 }
00380 
00381 /*
00382 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00383 %                                                                             %
00384 %                                                                             %
00385 %                                                                             %
00386 %   N e w P i x e l R e g i o n I t e r a t o r                               %
00387 %                                                                             %
00388 %                                                                             %
00389 %                                                                             %
00390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00391 %
00392 %  NewPixelRegionIterator() returns a new pixel iterator.
00393 %
00394 %  The format of the NewPixelRegionIterator method is:
00395 %
00396 %      PixelIterator NewPixelRegionIterator(MagickWand *wand,const ssize_t x,
00397 %        const ssize_t y,const size_t width,const size_t height)
00398 %
00399 %  A description of each parameter follows:
00400 %
00401 %    o wand: the magick wand.
00402 %
00403 %    o x,y,columns,rows:  These values define the perimeter of a region of
00404 %      pixels.
00405 %
00406 */
00407 WandExport PixelIterator *NewPixelRegionIterator(MagickWand *wand,
00408   const ssize_t x,const ssize_t y,const size_t width,const size_t height)
00409 {
00410   CacheView
00411     *view;
00412 
00413   const char
00414     *quantum;
00415 
00416   Image
00417     *image;
00418 
00419   PixelIterator
00420     *iterator;
00421 
00422   size_t
00423     depth;
00424 
00425   assert(wand != (MagickWand *) NULL);
00426   depth=MAGICKCORE_QUANTUM_DEPTH;
00427   quantum=GetMagickQuantumDepth(&depth);
00428   if (depth != MAGICKCORE_QUANTUM_DEPTH)
00429     ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
00430   if ((width == 0) || (width == 0))
00431     ThrowWandFatalException(WandError,"ZeroRegionSize",quantum);
00432   image=GetImageFromMagickWand(wand);
00433   if (image == (Image *) NULL)
00434     return((PixelIterator *) NULL);
00435   view=AcquireCacheView(image);
00436   if (view == (CacheView *) NULL)
00437     return((PixelIterator *) NULL);
00438   iterator=(PixelIterator *) AcquireMagickMemory(sizeof(*iterator));
00439   if (iterator == (PixelIterator *) NULL)
00440     ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
00441       wand->name);
00442   (void) ResetMagickMemory(iterator,0,sizeof(*iterator));
00443   iterator->id=AcquireWandId();
00444   (void) FormatLocaleString(iterator->name,MaxTextExtent,"%s-%.20g",
00445     PixelIteratorId,(double) iterator->id);
00446   iterator->exception=AcquireExceptionInfo();
00447   iterator->view=view;
00448   SetGeometry(image,&iterator->region);
00449   iterator->region.width=width;
00450   iterator->region.height=height;
00451   iterator->region.x=x;
00452   iterator->region.y=y;
00453   iterator->pixel_wands=NewPixelWands(iterator->region.width);
00454   iterator->y=0;
00455   iterator->debug=IsEventLogging();
00456   if (iterator->debug != MagickFalse)
00457     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00458   iterator->signature=WandSignature;
00459   return(iterator);
00460 }
00461 
00462 /*
00463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00464 %                                                                             %
00465 %                                                                             %
00466 %                                                                             %
00467 %   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                       %
00468 %                                                                             %
00469 %                                                                             %
00470 %                                                                             %
00471 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00472 %
00473 %  PixelGetCurrentIteratorRow() returns the current row as an array of pixel
00474 %  wands from the pixel iterator.
00475 %
00476 %  The format of the PixelGetCurrentIteratorRow method is:
00477 %
00478 %      PixelWand **PixelGetCurrentIteratorRow(PixelIterator *iterator,
00479 %        size_t *number_wands)
00480 %
00481 %  A description of each parameter follows:
00482 %
00483 %    o iterator: the pixel iterator.
00484 %
00485 %    o number_wands: the number of pixel wands.
00486 %
00487 */
00488 WandExport PixelWand **PixelGetCurrentIteratorRow(PixelIterator *iterator,
00489   size_t *number_wands)
00490 {
00491   register const Quantum
00492     *pixels;
00493 
00494   register ssize_t
00495     x;
00496 
00497   assert(iterator != (PixelIterator *) NULL);
00498   assert(iterator->signature == WandSignature);
00499   if (iterator->debug != MagickFalse)
00500     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00501   *number_wands=0;
00502   iterator->active=MagickTrue;
00503   pixels=GetCacheViewVirtualPixels(iterator->view,iterator->region.x,
00504     iterator->region.y+iterator->y,iterator->region.width,1,
00505     iterator->exception);
00506   if (pixels == (const Quantum *) NULL)
00507     return((PixelWand **) NULL);
00508   for (x=0; x < (ssize_t) iterator->region.width; x++)
00509   {
00510     PixelSetQuantumPixel(iterator->image,pixels,iterator->pixel_wands[x]);
00511     pixels+=GetPixelChannels(iterator->image);
00512   }
00513   *number_wands=iterator->region.width;
00514   return(iterator->pixel_wands);
00515 }
00516 
00517 /*
00518 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00519 %                                                                             %
00520 %                                                                             %
00521 %                                                                             %
00522 %   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                         %
00523 %                                                                             %
00524 %                                                                             %
00525 %                                                                             %
00526 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00527 %
00528 %  PixelGetIteratorException() returns the severity, reason, and description of
00529 %  any error that occurs when using other methods in this API.
00530 %
00531 %  The format of the PixelGetIteratorException method is:
00532 %
00533 %      char *PixelGetIteratorException(const Pixeliterator *iterator,
00534 %        ExceptionType *severity)
00535 %
00536 %  A description of each parameter follows:
00537 %
00538 %    o iterator: the pixel iterator.
00539 %
00540 %    o severity: the severity of the error is returned here.
00541 %
00542 */
00543 WandExport char *PixelGetIteratorException(const PixelIterator *iterator,
00544   ExceptionType *severity)
00545 {
00546   char
00547     *description;
00548 
00549   assert(iterator != (const PixelIterator *) NULL);
00550   assert(iterator->signature == WandSignature);
00551   if (iterator->debug != MagickFalse)
00552     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00553   assert(severity != (ExceptionType *) NULL);
00554   *severity=iterator->exception->severity;
00555   description=(char *) AcquireQuantumMemory(2UL*MaxTextExtent,
00556     sizeof(*description));
00557   if (description == (char *) NULL)
00558     ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
00559       iterator->name);
00560   *description='\0';
00561   if (iterator->exception->reason != (char *) NULL)
00562     (void) CopyMagickString(description,GetLocaleExceptionMessage(
00563       iterator->exception->severity,iterator->exception->reason),MaxTextExtent);
00564   if (iterator->exception->description != (char *) NULL)
00565     {
00566       (void) ConcatenateMagickString(description," (",MaxTextExtent);
00567       (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
00568         iterator->exception->severity,iterator->exception->description),
00569         MaxTextExtent);
00570       (void) ConcatenateMagickString(description,")",MaxTextExtent);
00571     }
00572   return(description);
00573 }
00574 
00575 /*
00576 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00577 %                                                                             %
00578 %                                                                             %
00579 %                                                                             %
00580 %   P i x e l G e t E x c e p t i o n T y p e                                 %
00581 %                                                                             %
00582 %                                                                             %
00583 %                                                                             %
00584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00585 %
00586 %  PixelGetIteratorExceptionType() the exception type associated with the wand.
00587 %  If no exception has occurred, UndefinedExceptionType is returned.
00588 %
00589 %  The format of the PixelGetIteratorExceptionType method is:
00590 %
00591 %      ExceptionType PixelGetIteratorExceptionType(const PixelWand *wand)
00592 %
00593 %  A description of each parameter follows:
00594 %
00595 %    o wand: the magick wand.
00596 %
00597 */
00598 WandExport ExceptionType PixelGetIteratorExceptionType(
00599   const PixelIterator *wand)
00600 {
00601   assert(wand != (const PixelIterator *) NULL);
00602   assert(wand->signature == WandSignature);
00603   if (wand->debug != MagickFalse)
00604     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00605   return(wand->exception->severity);
00606 }
00607 
00608 /*
00609 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00610 %                                                                             %
00611 %                                                                             %
00612 %                                                                             %
00613 %   P i x e l G e t I t e r a t o r R o w                                     %
00614 %                                                                             %
00615 %                                                                             %
00616 %                                                                             %
00617 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00618 %
00619 %  PixelGetIteratorRow() returns the current pixel iterator row.
00620 %
00621 %  The format of the PixelGetIteratorRow method is:
00622 %
00623 %      MagickBooleanType PixelGetIteratorRow(PixelIterator *iterator)
00624 %
00625 %  A description of each parameter follows:
00626 %
00627 %    o iterator: the pixel iterator.
00628 %
00629 */
00630 WandExport ssize_t PixelGetIteratorRow(PixelIterator *iterator)
00631 {
00632   assert(iterator != (const PixelIterator *) NULL);
00633   assert(iterator->signature == WandSignature);
00634   if (iterator->debug != MagickFalse)
00635     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00636   return(iterator->y);
00637 }
00638 
00639 /*
00640 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00641 %                                                                             %
00642 %                                                                             %
00643 %                                                                             %
00644 %   P i x e l G e t N e x t I t e r a t o r R o w                             %
00645 %                                                                             %
00646 %                                                                             %
00647 %                                                                             %
00648 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00649 %
00650 %  PixelGetNextIteratorRow() returns the next row as an array of pixel wands
00651 %  from the pixel iterator.
00652 %
00653 %  The format of the PixelGetNextIteratorRow method is:
00654 %
00655 %      PixelWand **PixelGetNextIteratorRow(PixelIterator *iterator,
00656 %        size_t *number_wands)
00657 %
00658 %  A description of each parameter follows:
00659 %
00660 %    o iterator: the pixel iterator.
00661 %
00662 %    o number_wands: the number of pixel wands.
00663 %
00664 */
00665 WandExport PixelWand **PixelGetNextIteratorRow(PixelIterator *iterator,
00666   size_t *number_wands)
00667 {
00668   register const Quantum
00669     *pixels;
00670 
00671   register ssize_t
00672     x;
00673 
00674   assert(iterator != (PixelIterator *) NULL);
00675   assert(iterator->signature == WandSignature);
00676   if (iterator->debug != MagickFalse)
00677     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00678   *number_wands=0;
00679   if (iterator->active != MagickFalse)
00680     iterator->y++;
00681   if (PixelSetIteratorRow(iterator,iterator->y) == MagickFalse)
00682     return((PixelWand **) NULL);
00683   pixels=GetCacheViewVirtualPixels(iterator->view,iterator->region.x,
00684     iterator->region.y+iterator->y,iterator->region.width,1,
00685     iterator->exception);
00686   if (pixels == (const Quantum *) NULL)
00687     return((PixelWand **) NULL);
00688   for (x=0; x < (ssize_t) iterator->region.width; x++)
00689   {
00690     PixelSetQuantumPixel(iterator->image,pixels,iterator->pixel_wands[x]);
00691     pixels+=GetPixelChannels(iterator->image);
00692   }
00693   *number_wands=iterator->region.width;
00694   return(iterator->pixel_wands);
00695 }
00696 
00697 /*
00698 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00699 %                                                                             %
00700 %                                                                             %
00701 %                                                                             %
00702 %   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                     %
00703 %                                                                             %
00704 %                                                                             %
00705 %                                                                             %
00706 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00707 %
00708 %  PixelGetPreviousIteratorRow() returns the previous row as an array of pixel
00709 %  wands from the pixel iterator.
00710 %
00711 %  The format of the PixelGetPreviousIteratorRow method is:
00712 %
00713 %      PixelWand **PixelGetPreviousIteratorRow(PixelIterator *iterator,
00714 %        size_t *number_wands)
00715 %
00716 %  A description of each parameter follows:
00717 %
00718 %    o iterator: the pixel iterator.
00719 %
00720 %    o number_wands: the number of pixel wands.
00721 %
00722 */
00723 WandExport PixelWand **PixelGetPreviousIteratorRow(PixelIterator *iterator,
00724   size_t *number_wands)
00725 {
00726   register const Quantum
00727     *pixels;
00728 
00729   register ssize_t
00730     x;
00731 
00732   assert(iterator != (PixelIterator *) NULL);
00733   assert(iterator->signature == WandSignature);
00734   if (iterator->debug != MagickFalse)
00735     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00736   *number_wands=0;
00737   if (iterator->active != MagickFalse)
00738     iterator->y--;
00739   if (PixelSetIteratorRow(iterator,iterator->y) == MagickFalse)
00740     return((PixelWand **) NULL);
00741   pixels=GetCacheViewVirtualPixels(iterator->view,iterator->region.x,
00742     iterator->region.y+iterator->y,iterator->region.width,1,
00743     iterator->exception);
00744   if (pixels == (const Quantum *) NULL)
00745     return((PixelWand **) NULL);
00746   for (x=0; x < (ssize_t) iterator->region.width; x++)
00747   {
00748     PixelSetQuantumPixel(iterator->image,pixels,iterator->pixel_wands[x]);
00749     pixels+=GetPixelChannels(iterator->image);
00750   }
00751   *number_wands=iterator->region.width;
00752   return(iterator->pixel_wands);
00753 }
00754 
00755 /*
00756 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00757 %                                                                             %
00758 %                                                                             %
00759 %                                                                             %
00760 %   P i x e l R e s e t I t e r a t o r                                       %
00761 %                                                                             %
00762 %                                                                             %
00763 %                                                                             %
00764 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00765 %
00766 %  PixelResetIterator() resets the pixel iterator.  Use it in conjunction
00767 %  with PixelGetNextIteratorRow() to iterate over all the pixels in a pixel
00768 %  container.
00769 %
00770 %  The format of the PixelResetIterator method is:
00771 %
00772 %      void PixelResetIterator(PixelIterator *iterator)
00773 %
00774 %  A description of each parameter follows:
00775 %
00776 %    o iterator: the pixel iterator.
00777 %
00778 */
00779 WandExport void PixelResetIterator(PixelIterator *iterator)
00780 {
00781   assert(iterator != (PixelIterator *) NULL);
00782   assert(iterator->signature == WandSignature);
00783   if (iterator->debug != MagickFalse)
00784     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00785   iterator->active=MagickFalse;
00786   iterator->y=0;
00787 }
00788 
00789 /*
00790 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00791 %                                                                             %
00792 %                                                                             %
00793 %                                                                             %
00794 %   P i x e l S e t F i r s t I t e r a t o r R o w                           %
00795 %                                                                             %
00796 %                                                                             %
00797 %                                                                             %
00798 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00799 %
00800 %  PixelSetFirstIteratorRow() sets the pixel iterator to the first pixel row.
00801 %
00802 %  The format of the PixelSetFirstIteratorRow method is:
00803 %
00804 %      void PixelSetFirstIteratorRow(PixelIterator *iterator)
00805 %
00806 %  A description of each parameter follows:
00807 %
00808 %    o iterator: the magick iterator.
00809 %
00810 */
00811 WandExport void PixelSetFirstIteratorRow(PixelIterator *iterator)
00812 {
00813   assert(iterator != (PixelIterator *) NULL);
00814   assert(iterator->signature == WandSignature);
00815   if (iterator->debug != MagickFalse)
00816     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00817   iterator->active=MagickFalse;
00818   iterator->y=iterator->region.y;
00819 }
00820 
00821 /*
00822 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00823 %                                                                             %
00824 %                                                                             %
00825 %                                                                             %
00826 %   P i x e l S e t I t e r a t o r R o w                                     %
00827 %                                                                             %
00828 %                                                                             %
00829 %                                                                             %
00830 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00831 %
00832 %  PixelSetIteratorRow() set the pixel iterator row.
00833 %
00834 %  The format of the PixelSetIteratorRow method is:
00835 %
00836 %      MagickBooleanType PixelSetIteratorRow(PixelIterator *iterator,
00837 %        const ssize_t row)
00838 %
00839 %  A description of each parameter follows:
00840 %
00841 %    o iterator: the pixel iterator.
00842 %
00843 */
00844 WandExport MagickBooleanType PixelSetIteratorRow(PixelIterator *iterator,
00845   const ssize_t row)
00846 {
00847   assert(iterator != (const PixelIterator *) NULL);
00848   assert(iterator->signature == WandSignature);
00849   if (iterator->debug != MagickFalse)
00850     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00851   if ((row < 0) || (row >= (ssize_t) iterator->region.height))
00852     return(MagickFalse);
00853   iterator->active=MagickTrue;
00854   iterator->y=row;
00855   return(MagickTrue);
00856 }
00857 
00858 /*
00859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00860 %                                                                             %
00861 %                                                                             %
00862 %                                                                             %
00863 %   P i x e l S e t L a s t I t e r a t o r R o w                             %
00864 %                                                                             %
00865 %                                                                             %
00866 %                                                                             %
00867 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00868 %
00869 %  PixelSetLastIteratorRow() sets the pixel iterator to the last pixel row.
00870 %
00871 %  The format of the PixelSetLastIteratorRow method is:
00872 %
00873 %      void PixelSetLastIteratorRow(PixelIterator *iterator)
00874 %
00875 %  A description of each parameter follows:
00876 %
00877 %    o iterator: the magick iterator.
00878 %
00879 */
00880 WandExport void PixelSetLastIteratorRow(PixelIterator *iterator)
00881 {
00882   assert(iterator != (PixelIterator *) NULL);
00883   assert(iterator->signature == WandSignature);
00884   if (iterator->debug != MagickFalse)
00885     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00886   iterator->active=MagickFalse;
00887   iterator->y=(ssize_t) iterator->region.height-1;
00888 }
00889 
00890 /*
00891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00892 %                                                                             %
00893 %                                                                             %
00894 %                                                                             %
00895 %   P i x e l S y n c I t e r a t o r                                         %
00896 %                                                                             %
00897 %                                                                             %
00898 %                                                                             %
00899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00900 %
00901 %  PixelSyncIterator() syncs the pixel iterator.
00902 %
00903 %  The format of the PixelSyncIterator method is:
00904 %
00905 %      MagickBooleanType PixelSyncIterator(PixelIterator *iterator)
00906 %
00907 %  A description of each parameter follows:
00908 %
00909 %    o iterator: the pixel iterator.
00910 %
00911 */
00912 WandExport MagickBooleanType PixelSyncIterator(PixelIterator *iterator)
00913 {
00914   MagickBooleanType
00915     status;
00916 
00917   register ssize_t
00918     x;
00919 
00920   register Quantum
00921     *restrict pixels;
00922 
00923   assert(iterator != (const PixelIterator *) NULL);
00924   assert(iterator->signature == WandSignature);
00925   if (iterator->debug != MagickFalse)
00926     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
00927   status=SetCacheViewStorageClass(iterator->view,DirectClass,
00928     iterator->exception);
00929   if (status == MagickFalse)
00930     return(MagickFalse);
00931   pixels=GetCacheViewAuthenticPixels(iterator->view,iterator->region.x,
00932     iterator->region.y+iterator->y,iterator->region.width,1,
00933     iterator->exception);
00934   if (pixels == (Quantum *) NULL)
00935     return(MagickFalse);
00936   for (x=0; x < (ssize_t) iterator->region.width; x++)
00937   {
00938     PixelGetQuantumPixel(iterator->image,iterator->pixel_wands[x],pixels);
00939     pixels+=GetPixelChannels(iterator->image);
00940   }
00941   if (SyncCacheViewAuthenticPixels(iterator->view,iterator->exception) == MagickFalse)
00942     return(MagickFalse);
00943   return(MagickTrue);
00944 }