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

Generated on Sat Nov 22 23:45:26 2008 for MagickWand by  doxygen 1.5.7.1