deprecate.c

Go to the documentation of this file.
00001 /*
00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00003 %                                                                             %
00004 %                                                                             %
00005 %                                                                             %
00006 %        DDDD   EEEEE  PPPP   RRRR   EEEEE   CCCC   AAA   TTTTT  EEEEE        %
00007 %        D   D  E      P   P  R   R  E      C      A   A    T    E            %
00008 %        D   D  EEE    PPPPP  RRRR   EEE    C      AAAAA    T    EEE          %
00009 %        D   D  E      P      R R    E      C      A   A    T    E            %
00010 %        DDDD   EEEEE  P      R  R   EEEEE   CCCC  A   A    T    EEEEE        %
00011 %                                                                             %
00012 %                                                                             %
00013 %                        MagickCore Deprecated Methods                        %
00014 %                                                                             %
00015 %                              Software Design                                %
00016 %                                John Cristy                                  %
00017 %                                October 2002                                 %
00018 %                                                                             %
00019 %                                                                             %
00020 %  Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization      %
00021 %  dedicated to making software imaging solutions freely available.           %
00022 %                                                                             %
00023 %  You may not use this file except in compliance with the License.  You may  %
00024 %  obtain a copy of the License at                                            %
00025 %                                                                             %
00026 %    http://www.imagemagick.org/script/license.php                            %
00027 %                                                                             %
00028 %  Unless required by applicable law or agreed to in writing, software        %
00029 %  distributed under the License is distributed on an "AS IS" BASIS,          %
00030 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
00031 %  See the License for the specific language governing permissions and        %
00032 %  limitations under the License.                                             %
00033 %                                                                             %
00034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00035 %
00036 %
00037 %
00038 */
00039 
00040 /*
00041   Include declarations.
00042 */
00043 #include "magick/studio.h"
00044 #include "magick/property.h"
00045 #include "magick/blob.h"
00046 #include "magick/blob-private.h"
00047 #include "magick/cache.h"
00048 #include "magick/cache-view.h"
00049 #include "magick/client.h"
00050 #include "magick/color.h"
00051 #include "magick/color-private.h"
00052 #include "magick/colormap.h"
00053 #include "magick/colormap-private.h"
00054 #include "magick/colorspace.h"
00055 #include "magick/composite.h"
00056 #include "magick/composite-private.h"
00057 #include "magick/constitute.h"
00058 #include "magick/deprecate.h"
00059 #include "magick/draw.h"
00060 #include "magick/draw-private.h"
00061 #include "magick/effect.h"
00062 #include "magick/enhance.h"
00063 #include "magick/exception.h"
00064 #include "magick/exception-private.h"
00065 #include "magick/geometry.h"
00066 #include "magick/identify.h"
00067 #include "magick/image.h"
00068 #include "magick/image-private.h"
00069 #include "magick/list.h"
00070 #include "magick/log.h"
00071 #include "magick/memory_.h"
00072 #include "magick/magick.h"
00073 #include "magick/monitor.h"
00074 #include "magick/monitor-private.h"
00075 #include "magick/paint.h"
00076 #include "magick/pixel.h"
00077 #include "magick/pixel-private.h"
00078 #include "magick/quantize.h"
00079 #include "magick/random_.h"
00080 #include "magick/resource_.h"
00081 #include "magick/semaphore.h"
00082 #include "magick/segment.h"
00083 #include "magick/splay-tree.h"
00084 #include "magick/string_.h"
00085 #include "magick/threshold.h"
00086 #include "magick/transform.h"
00087 #include "magick/utility.h"
00088 
00089 #if !defined(MAGICKCORE_EXCLUDE_DEPRECATED)
00090 /*
00091   Global declarations.
00092 */
00093 static MonitorHandler
00094   monitor_handler = (MonitorHandler) NULL;
00095 
00096 /*
00097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00098 %                                                                             %
00099 %                                                                             %
00100 %                                                                             %
00101 %   A c q u i r e C a c h e V i e w I n d e x e s                             %
00102 %                                                                             %
00103 %                                                                             %
00104 %                                                                             %
00105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00106 %
00107 %  AcquireCacheViewIndexes() returns the indexes associated with the specified
00108 %  view.
00109 %
00110 %  The format of the AcquireCacheViewIndexes method is:
00111 %
00112 %      const IndexPacket *AcquireCacheViewIndexes(const CacheView *cache_view)
00113 %
00114 %  A description of each parameter follows:
00115 %
00116 %    o cache_view: the cache view.
00117 %
00118 */
00119 MagickExport const IndexPacket *AcquireCacheViewIndexes(
00120   const CacheView *cache_view)
00121 {
00122   return(GetCacheViewVirtualIndexQueue(cache_view));
00123 }
00124 
00125 /*
00126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00127 %                                                                             %
00128 %                                                                             %
00129 %                                                                             %
00130 %   A c q u i r e C a c h e V i e w P i x e l s                               %
00131 %                                                                             %
00132 %                                                                             %
00133 %                                                                             %
00134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00135 %
00136 %  AcquireCacheViewPixels() gets pixels from the in-memory or disk pixel cache
00137 %  as defined by the geometry parameters.   A pointer to the pixels is returned
00138 %  if the pixels are transferred, otherwise a NULL is returned.
00139 %
00140 %  The format of the AcquireCacheViewPixels method is:
00141 %
00142 %      const PixelPacket *AcquireCacheViewPixels(const CacheView *cache_view,
00143 %        const long x,const long y,const unsigned long columns,
00144 %        const unsigned long rows,ExceptionInfo *exception)
00145 %
00146 %  A description of each parameter follows:
00147 %
00148 %    o cache_view: the cache view.
00149 %
00150 %    o x,y,columns,rows:  These values define the perimeter of a region of
00151 %      pixels.
00152 %
00153 %    o exception: return any errors or warnings in this structure.
00154 %
00155 */
00156 MagickExport const PixelPacket *AcquireCacheViewPixels(
00157   const CacheView *cache_view,const long x,const long y,
00158   const unsigned long columns,const unsigned long rows,ExceptionInfo *exception)
00159 {
00160   return(GetCacheViewVirtualPixels(cache_view,x,y,columns,rows,exception));
00161 }
00162 
00163 /*
00164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00165 %                                                                             %
00166 %                                                                             %
00167 %                                                                             %
00168 %   A c q u i r e I m a g e P i x e l s                                        %
00169 %                                                                             %
00170 %                                                                             %
00171 %                                                                             %
00172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00173 %
00174 %  AcquireImagePixels() returns an immutable pixel region. If the
00175 %  region is successfully accessed, a pointer to it is returned, otherwise
00176 %  NULL is returned. The returned pointer may point to a temporary working
00177 %  copy of the pixels or it may point to the original pixels in memory.
00178 %  Performance is maximized if the selected region is part of one row, or one
00179 %  or more full rows, since there is opportunity to access the pixels in-place
00180 %  (without a copy) if the image is in RAM, or in a memory-mapped file.  The
00181 %  returned pointer should *never* be deallocated by the user.
00182 %
00183 %  Pixels accessed via the returned pointer represent a simple array of type
00184 %  PixelPacket.  If the image type is CMYK or the storage class is PseudoClass,
00185 %  call GetAuthenticIndexQueue() after invoking GetAuthenticPixels() to access the
00186 %  black color component or to obtain the colormap indexes (of type IndexPacket)
00187 %  corresponding to the region.
00188 %
00189 %  If you plan to modify the pixels, use GetAuthenticPixels() instead.
00190 %
00191 %  Note, the AcquireImagePixels() and GetAuthenticPixels() methods are not
00192 %  thread-safe.  In a threaded environment, use GetCacheViewVirtualPixels() or
00193 %  GetCacheViewAuthenticPixels() instead.
00194 %
00195 %  The format of the AcquireImagePixels() method is:
00196 %
00197 %      const PixelPacket *AcquireImagePixels(const Image *image,const long x,
00198 %        const long y,const unsigned long columns,const unsigned long rows,
00199 %        ExceptionInfo *exception)
00200 %
00201 %  A description of each parameter follows:
00202 %
00203 %    o image: the image.
00204 %
00205 %    o x,y,columns,rows:  These values define the perimeter of a region of
00206 %      pixels.
00207 %
00208 %    o exception: return any errors or warnings in this structure.
00209 %
00210 */
00211 MagickExport const PixelPacket *AcquireImagePixels(const Image *image,
00212   const long x,const long y,const unsigned long columns,
00213   const unsigned long rows,ExceptionInfo *exception)
00214 {
00215   return(GetVirtualPixels(image,x,y,columns,rows,exception));
00216 }
00217 
00218 /*
00219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00220 %                                                                             %
00221 %                                                                             %
00222 %                                                                             %
00223 %   A c q u i r e I n d e x e s                                               %
00224 %                                                                             %
00225 %                                                                             %
00226 %                                                                             %
00227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00228 %
00229 %  AcquireIndexes() returns the black channel or the colormap indexes
00230 %  associated with the last call to QueueAuthenticPixels() or GetVirtualPixels().
00231 %  NULL is returned if the black channel or colormap indexes are not available.
00232 %
00233 %  The format of the AcquireIndexes() method is:
00234 %
00235 %      const IndexPacket *AcquireIndexes(const Image *image)
00236 %
00237 %  A description of each parameter follows:
00238 %
00239 %    o indexes: AcquireIndexes() returns the indexes associated with the last
00240 %      call to QueueAuthenticPixels() or GetVirtualPixels().
00241 %
00242 %    o image: the image.
00243 %
00244 */
00245 MagickExport const IndexPacket *AcquireIndexes(const Image *image)
00246 {
00247   return(GetVirtualIndexQueue(image));
00248 }
00249 
00250 /*
00251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00252 %                                                                             %
00253 %                                                                             %
00254 %                                                                             %
00255 %   A c q u i r e M e m o r y                                                 %
00256 %                                                                             %
00257 %                                                                             %
00258 %                                                                             %
00259 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00260 %
00261 %  AcquireMemory() returns a pointer to a block of memory at least size bytes
00262 %  suitably aligned for any use.
00263 %
00264 %  The format of the AcquireMemory method is:
00265 %
00266 %      void *AcquireMemory(const size_t size)
00267 %
00268 %  A description of each parameter follows:
00269 %
00270 %    o size: the size of the memory in bytes to allocate.
00271 %
00272 */
00273 MagickExport void *AcquireMemory(const size_t size)
00274 {
00275   void
00276     *allocation;
00277 
00278   assert(size != 0);
00279   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
00280   allocation=malloc(size);
00281   return(allocation);
00282 }
00283 
00284 /*
00285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00286 %                                                                             %
00287 %                                                                             %
00288 %                                                                             %
00289 %   A c q u i r e O n e C a c h e V i e w P i x e l                           %
00290 %                                                                             %
00291 %                                                                             %
00292 %                                                                             %
00293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00294 %
00295 %  AcquireOneCacheViewPixel() returns a single pixel at the specified (x,y)
00296 %  location.  The image background color is returned if an error occurs.  If
00297 %  you plan to modify the pixel, use GetOneCacheViewAuthenticPixel() instead.
00298 %
00299 %  The format of the AcquireOneCacheViewPixel method is:
00300 %
00301 %      MagickBooleanType AcquireOneCacheViewPixel(const CacheView *cache_view,
00302 %        const long x,const long y,PixelPacket *pixel,ExceptionInfo *exception)
00303 %
00304 %  A description of each parameter follows:
00305 %
00306 %    o cache_view: the cache view.
00307 %
00308 %    o x,y:  These values define the offset of the pixel.
00309 %
00310 %    o pixel: return a pixel at the specified (x,y) location.
00311 %
00312 %    o exception: return any errors or warnings in this structure.
00313 %
00314 */
00315 MagickExport MagickBooleanType AcquireOneCacheViewPixel(
00316   const CacheView *cache_view,const long x,const long y,PixelPacket *pixel,
00317   ExceptionInfo *exception)
00318 {
00319   return(GetOneCacheViewVirtualPixel(cache_view,x,y,pixel,exception));
00320 }
00321 
00322 /*
00323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00324 %                                                                             %
00325 %                                                                             %
00326 %                                                                             %
00327 %   A c q u i r e O n e C a c h e V i e w V i r t u a l P i x e l             %
00328 %                                                                             %
00329 %                                                                             %
00330 %                                                                             %
00331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00332 %
00333 %  AcquireOneCacheViewVirtualPixel() returns a single pixel at the specified
00334 %  (x,y) location.  The image background color is returned if an error occurs.
00335 %  If you plan to modify the pixel, use GetOneCacheViewAuthenticPixel() instead.
00336 %
00337 %  The format of the AcquireOneCacheViewPixel method is:
00338 %
00339 %      MagickBooleanType AcquireOneCacheViewVirtualPixel(
00340 %        const CacheView *cache_view,
00341 %        const VirtualPixelMethod virtual_pixel_method,const long x,
00342 %        const long y,PixelPacket *pixel,ExceptionInfo *exception)
00343 %
00344 %  A description of each parameter follows:
00345 %
00346 %    o cache_view: the cache view.
00347 %
00348 %    o virtual_pixel_method: the virtual pixel method.
00349 %
00350 %    o x,y:  These values define the offset of the pixel.
00351 %
00352 %    o pixel: return a pixel at the specified (x,y) location.
00353 %
00354 %    o exception: return any errors or warnings in this structure.
00355 %
00356 */
00357 MagickExport MagickBooleanType AcquireOneCacheViewVirtualPixel(
00358   const CacheView *cache_view,const VirtualPixelMethod virtual_pixel_method,
00359   const long x,const long y,PixelPacket *pixel,ExceptionInfo *exception)
00360 {
00361   MagickBooleanType
00362     status;
00363 
00364   status=GetOneCacheViewVirtualMethodPixel(cache_view,virtual_pixel_method,
00365     x,y,pixel,exception);
00366   return(status);
00367 }
00368 
00369 /*
00370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00371 %                                                                             %
00372 %                                                                             %
00373 %                                                                             %
00374 %   A c q u i r e O n e M a g i c k P i x e l                                 %
00375 %                                                                             %
00376 %                                                                             %
00377 %                                                                             %
00378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00379 %
00380 %  AcquireOneMagickPixel() returns a single pixel at the specified (x,y)
00381 %  location.  The image background color is returned if an error occurs.  If
00382 %  you plan to modify the pixel, use GetOnePixel() instead.
00383 %
00384 %  The format of the AcquireOneMagickPixel() method is:
00385 %
00386 %      MagickPixelPacket AcquireOneMagickPixel(const Image image,const long x,
00387 %        const long y,ExceptionInfo exception)
00388 %
00389 %  A description of each parameter follows:
00390 %
00391 %    o image: the image.
00392 %
00393 %    o x,y:  These values define the location of the pixel to return.
00394 %
00395 %    o exception: return any errors or warnings in this structure.
00396 %
00397 */
00398 MagickExport MagickPixelPacket AcquireOneMagickPixel(const Image *image,
00399   const long x,const long y,ExceptionInfo *exception)
00400 {
00401   MagickPixelPacket
00402     pixel;
00403 
00404   (void) GetOneVirtualMagickPixel(image,x,y,&pixel,exception);
00405   return(pixel);
00406 }
00407 
00408 /*
00409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00410 %                                                                             %
00411 %                                                                             %
00412 %                                                                             %
00413 %   A c q u i r e O n e P i x e l                                             %
00414 %                                                                             %
00415 %                                                                             %
00416 %                                                                             %
00417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00418 %
00419 %  AcquireOnePixel() returns a single pixel at the specified (x,y) location.
00420 %  The image background color is returned if an error occurs.  If you plan to
00421 %  modify the pixel, use GetOnePixel() instead.
00422 %
00423 %  The format of the AcquireOnePixel() method is:
00424 %
00425 %      PixelPacket AcquireOnePixel(const Image image,const long x,
00426 %        const long y,ExceptionInfo exception)
00427 %
00428 %  A description of each parameter follows:
00429 %
00430 %    o image: the image.
00431 %
00432 %    o x,y:  These values define the location of the pixel to return.
00433 %
00434 %    o exception: return any errors or warnings in this structure.
00435 %
00436 */
00437 MagickExport PixelPacket AcquireOnePixel(const Image *image,const long x,
00438   const long y,ExceptionInfo *exception)
00439 {
00440   PixelPacket
00441     pixel;
00442 
00443   (void) GetOneVirtualPixel(image,x,y,&pixel,exception);
00444   return(pixel);
00445 }
00446 
00447 /*
00448 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00449 %                                                                             %
00450 %                                                                             %
00451 %                                                                             %
00452 %   A c q u i r e O n e V i r t u a l P i x e l                               %
00453 %                                                                             %
00454 %                                                                             %
00455 %                                                                             %
00456 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00457 %
00458 %  AcquireOneVirtualPixel() returns a single pixel at the specified (x,y)
00459 %  location as defined by specified pixel method.  The image background color
00460 %  is returned if an error occurs.  If you plan to modify the pixel, use
00461 %  GetOnePixel() instead.
00462 %
00463 %  The format of the AcquireOneVirtualPixel() method is:
00464 %
00465 %      PixelPacket AcquireOneVirtualPixel(const Image image,
00466 %        const VirtualPixelMethod virtual_pixel_method,const long x,
00467 %        const long y,ExceptionInfo exception)
00468 %
00469 %  A description of each parameter follows:
00470 %
00471 %    o virtual_pixel_method: the virtual pixel method.
00472 %
00473 %    o image: the image.
00474 %
00475 %    o x,y:  These values define the location of the pixel to return.
00476 %
00477 %    o exception: return any errors or warnings in this structure.
00478 %
00479 */
00480 MagickExport PixelPacket AcquireOneVirtualPixel(const Image *image,
00481   const VirtualPixelMethod virtual_pixel_method,const long x,const long y,
00482   ExceptionInfo *exception)
00483 {
00484   PixelPacket
00485     pixel;
00486 
00487   (void) GetOneVirtualMethodPixel(image,virtual_pixel_method,x,y,&pixel,
00488     exception);
00489   return(pixel);
00490 }
00491 
00492 /*
00493 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00494 %                                                                             %
00495 %                                                                             %
00496 %                                                                             %
00497 %   A c q u i r e P i x e l s                                                 %
00498 %                                                                             %
00499 %                                                                             %
00500 %                                                                             %
00501 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00502 %
00503 %  AcquirePixels() returns the pixels associated with the last call to
00504 %  QueueAuthenticPixels() or GetVirtualPixels().
00505 %
00506 %  The format of the AcquirePixels() method is:
00507 %
00508 %      const PixelPacket *AcquirePixels(const Image image)
00509 %
00510 %  A description of each parameter follows:
00511 %
00512 %    o image: the image.
00513 %
00514 */
00515 MagickExport const PixelPacket *AcquirePixels(const Image *image)
00516 {
00517   return(GetVirtualPixelQueue(image));
00518 }
00519 
00520 /*
00521 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00522 %                                                                             %
00523 %                                                                             %
00524 %                                                                             %
00525 %   A f f i n i t y I m a g e                                                 %
00526 %                                                                             %
00527 %                                                                             %
00528 %                                                                             %
00529 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00530 %
00531 %  AffinityImage() replaces the colors of an image with the closest color from
00532 %  a reference image.
00533 %
00534 %  The format of the AffinityImage method is:
00535 %
00536 %      MagickBooleanType AffinityImage(const QuantizeInfo *quantize_info,
00537 %        Image *image,const Image *affinity_image)
00538 %
00539 %  A description of each parameter follows:
00540 %
00541 %    o quantize_info: Specifies a pointer to an QuantizeInfo structure.
00542 %
00543 %    o image: the image.
00544 %
00545 %    o affinity_image: the reference image.
00546 %
00547 */
00548 MagickExport MagickBooleanType AffinityImage(const QuantizeInfo *quantize_info,
00549   Image *image,const Image *affinity_image)
00550 {
00551   return(RemapImage(quantize_info,image,affinity_image));
00552 }
00553 
00554 /*
00555 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00556 %                                                                             %
00557 %                                                                             %
00558 %                                                                             %
00559 %   A f f i n i t y I m a g e s                                               %
00560 %                                                                             %
00561 %                                                                             %
00562 %                                                                             %
00563 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00564 %
00565 %  AffinityImages() replaces the colors of a sequence of images with the
00566 %  closest color from a reference image.
00567 %
00568 %  The format of the AffinityImage method is:
00569 %
00570 %      MagickBooleanType AffinityImages(const QuantizeInfo *quantize_info,
00571 %        Image *images,Image *affinity_image)
00572 %
00573 %  A description of each parameter follows:
00574 %
00575 %    o quantize_info: Specifies a pointer to an QuantizeInfo structure.
00576 %
00577 %    o images: the image sequence.
00578 %
00579 %    o affinity_image: the reference image.
00580 %
00581 */
00582 MagickExport MagickBooleanType AffinityImages(const QuantizeInfo *quantize_info,
00583   Image *images,const Image *affinity_image)
00584 {
00585   return(RemapImages(quantize_info,images,affinity_image));
00586 }
00587 
00588 /*
00589 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00590 %                                                                             %
00591 %                                                                             %
00592 %                                                                             %
00593 %   A l l o c a t e I m a g e                                                 %
00594 %                                                                             %
00595 %                                                                             %
00596 %                                                                             %
00597 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00598 %
00599 %  AllocateImage() returns a pointer to an image structure initialized to
00600 %  default values.
00601 %
00602 %  The format of the AllocateImage method is:
00603 %
00604 %      Image *AllocateImage(const ImageInfo *image_info)
00605 %
00606 %  A description of each parameter follows:
00607 %
00608 %    o image_info: Many of the image default values are set from this
00609 %      structure.  For example, filename, compression, depth, background color,
00610 %      and others.
00611 %
00612 */
00613 MagickExport Image *AllocateImage(const ImageInfo *image_info)
00614 {
00615   return(AcquireImage(image_info));
00616 }
00617 
00618 /*
00619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00620 %                                                                             %
00621 %                                                                             %
00622 %                                                                             %
00623 %   A l l o c a t e I m a g e C o l o r m a p                                 %
00624 %                                                                             %
00625 %                                                                             %
00626 %                                                                             %
00627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00628 %
00629 %  AllocateImageColormap() allocates an image colormap and initializes
00630 %  it to a linear gray colorspace.  If the image already has a colormap,
00631 %  it is replaced.  AllocateImageColormap() returns MagickTrue if successful,
00632 %  otherwise MagickFalse if there is not enough memory.
00633 %
00634 %  The format of the AllocateImageColormap method is:
00635 %
00636 %      MagickBooleanType AllocateImageColormap(Image *image,
00637 %        const unsigned long colors)
00638 %
00639 %  A description of each parameter follows:
00640 %
00641 %    o image: the image.
00642 %
00643 %    o colors: the number of colors in the image colormap.
00644 %
00645 */
00646 MagickExport MagickBooleanType AllocateImageColormap(Image *image,
00647   const unsigned long colors)
00648 {
00649   return(AcquireImageColormap(image,colors));
00650 }
00651 
00652 /*
00653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00654 %                                                                             %
00655 %                                                                             %
00656 %                                                                             %
00657 %   A l l o c a t e N e x t I m a g e                                         %
00658 %                                                                             %
00659 %                                                                             %
00660 %                                                                             %
00661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00662 %
00663 %  AllocateNextImage() initializes the next image in a sequence to
00664 %  default values.  The next member of image points to the newly allocated
00665 %  image.  If there is a memory shortage, next is assigned NULL.
00666 %
00667 %  The format of the AllocateNextImage method is:
00668 %
00669 %      void AllocateNextImage(const ImageInfo *image_info,Image *image)
00670 %
00671 %  A description of each parameter follows:
00672 %
00673 %    o image_info: Many of the image default values are set from this
00674 %      structure.  For example, filename, compression, depth, background color,
00675 %      and others.
00676 %
00677 %    o image: the image.
00678 %
00679 */
00680 MagickExport void AllocateNextImage(const ImageInfo *image_info,Image *image)
00681 {
00682   AcquireNextImage(image_info,image);
00683 }
00684 
00685 /*
00686 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00687 %                                                                             %
00688 %                                                                             %
00689 %                                                                             %
00690 %   A c q u i r e S t r i n g                                                 %
00691 %                                                                             %
00692 %                                                                             %
00693 %                                                                             %
00694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00695 %
00696 %  AllocateString() allocates memory for a string and copies the source string
00697 %  to that memory location (and returns it).
00698 %
00699 %  The format of the AllocateString method is:
00700 %
00701 %      char *AllocateString(const char *source)
00702 %
00703 %  A description of each parameter follows:
00704 %
00705 %    o source: A character string.
00706 %
00707 */
00708 MagickExport char *AllocateString(const char *source)
00709 {
00710   char
00711     *destination;
00712 
00713   size_t
00714     length;
00715 
00716   assert(source != (const char *) NULL);
00717   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
00718   length=strlen(source)+MaxTextExtent+1;
00719   destination=(char *) AcquireQuantumMemory(length,sizeof(*destination));
00720   if (destination == (char *) NULL)
00721     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
00722   *destination='\0';
00723   if (source != (char *) NULL)
00724     (void) CopyMagickString(destination,source,length);
00725   return(destination);
00726 }
00727 
00728 /*
00729 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00730 %                                                                             %
00731 %                                                                             %
00732 %                                                                             %
00733 %     C h a n n e l I m a g e                                                 %
00734 %                                                                             %
00735 %                                                                             %
00736 %                                                                             %
00737 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00738 %
00739 %  Extract a channel from the image.  A channel is a particular color component
00740 %  of each pixel in the image.
00741 %
00742 %  The format of the ChannelImage method is:
00743 %
00744 %      unsigned int ChannelImage(Image *image,const ChannelType channel)
00745 %
00746 %  A description of each parameter follows:
00747 %
00748 %    o image: the image.
00749 %
00750 %    o channel: Identify which channel to extract: RedChannel, GreenChannel,
00751 %      BlueChannel, OpacityChannel, CyanChannel, MagentaChannel, YellowChannel,
00752 %      or BlackChannel.
00753 %
00754 */
00755 MagickExport unsigned int ChannelImage(Image *image,const ChannelType channel)
00756 {
00757   return(SeparateImageChannel(image,channel));
00758 }
00759 
00760 /*
00761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00762 %                                                                             %
00763 %                                                                             %
00764 %                                                                             %
00765 %     C h a n n e l T h r e s h o l d I m a g e                               %
00766 %                                                                             %
00767 %                                                                             %
00768 %                                                                             %
00769 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00770 %
00771 %  ChannelThresholdImage() changes the value of individual pixels based on
00772 %  the intensity of each pixel channel.  The result is a high-contrast image.
00773 %
00774 %  The format of the ChannelThresholdImage method is:
00775 %
00776 %      unsigned int ChannelThresholdImage(Image *image,const char *level)
00777 %
00778 %  A description of each parameter follows:
00779 %
00780 %    o image: the image.
00781 %
00782 %    o level: define the threshold values.
00783 %
00784 */
00785 MagickExport unsigned int ChannelThresholdImage(Image *image,const char *level)
00786 {
00787   MagickPixelPacket
00788     threshold;
00789 
00790   GeometryInfo
00791     geometry_info;
00792 
00793   unsigned int
00794     flags,
00795     status;
00796 
00797   assert(image != (Image *) NULL);
00798   assert(image->signature == MagickSignature);
00799   if (image->debug != MagickFalse)
00800     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00801   if (image->debug != MagickFalse)
00802     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
00803   if (level == (char *) NULL)
00804     return(MagickFalse);
00805   flags=ParseGeometry(level,&geometry_info);
00806   threshold.red=geometry_info.rho;
00807   threshold.green=geometry_info.sigma;
00808   if ((flags & SigmaValue) == 0)
00809     threshold.green=threshold.red;
00810   threshold.blue=geometry_info.xi;
00811   if ((flags & XiValue) == 0)
00812     threshold.blue=threshold.red;
00813   status=BilevelImageChannel(image,RedChannel,threshold.red);
00814   status|=BilevelImageChannel(image,GreenChannel,threshold.green);
00815   status|=BilevelImageChannel(image,BlueChannel,threshold.blue);
00816   return(status);
00817 }
00818 
00819 /*
00820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00821 %                                                                             %
00822 %                                                                             %
00823 %                                                                             %
00824 %   C l i p I m a g e P a t h                                                 %
00825 %                                                                             %
00826 %                                                                             %
00827 %                                                                             %
00828 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00829 %
00830 %  ClipPathImage() sets the image clip mask based any clipping path information
00831 %  if it exists.
00832 %
00833 %  The format of the ClipImage method is:
00834 %
00835 %      MagickBooleanType ClipPathImage(Image *image,const char *pathname,
00836 %        const MagickBooleanType inside)
00837 %
00838 %  A description of each parameter follows:
00839 %
00840 %    o image: the image.
00841 %
00842 %    o pathname: name of clipping path resource. If name is preceded by #, use
00843 %      clipping path numbered by name.
00844 %
00845 %    o inside: if non-zero, later operations take effect inside clipping path.
00846 %      Otherwise later operations take effect outside clipping path.
00847 %
00848 */
00849 MagickExport MagickBooleanType ClipPathImage(Image *image,const char *pathname,
00850   const MagickBooleanType inside)
00851 {
00852   return(ClipImagePath(image,pathname,inside));
00853 }
00854 
00855 /*
00856 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00857 %                                                                             %
00858 %                                                                             %
00859 %                                                                             %
00860 %   C l o n e I m a g e A t t r i b u t e s                                   %
00861 %                                                                             %
00862 %                                                                             %
00863 %                                                                             %
00864 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00865 %
00866 %  CloneImageAttributes() clones one or more image attributes.
00867 %
00868 %  The format of the CloneImageAttributes method is:
00869 %
00870 %      MagickBooleanType CloneImageAttributes(Image *image,
00871 %        const Image *clone_image)
00872 %
00873 %  A description of each parameter follows:
00874 %
00875 %    o image: the image.
00876 %
00877 %    o clone_image: the clone image.
00878 %
00879 */
00880 MagickExport MagickBooleanType CloneImageAttributes(Image *image,
00881   const Image *clone_image)
00882 {
00883   return(CloneImageProperties(image,clone_image));
00884 }
00885 
00886 /*
00887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00888 %                                                                             %
00889 %                                                                             %
00890 %                                                                             %
00891 %   C l o n e M e m o r y                                                     %
00892 %                                                                             %
00893 %                                                                             %
00894 %                                                                             %
00895 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00896 %
00897 %  CloneMemory() copies size bytes from memory area source to the destination.
00898 %  Copying between objects that overlap will take place correctly.  It returns
00899 %  destination.
00900 %
00901 %  The format of the CloneMemory method is:
00902 %
00903 %      void *CloneMemory(void *destination,const void *source,
00904 %        const size_t size)
00905 %
00906 %  A description of each parameter follows:
00907 %
00908 %    o destination: the destination.
00909 %
00910 %    o source: the source.
00911 %
00912 %    o size: the size of the memory in bytes to allocate.
00913 %
00914 */
00915 MagickExport void *CloneMemory(void *destination,const void *source,
00916   const size_t size)
00917 {
00918   register const unsigned char
00919     *p;
00920 
00921   register unsigned char
00922     *q;
00923 
00924   register long
00925     i;
00926 
00927   assert(destination != (void *) NULL);
00928   assert(source != (const void *) NULL);
00929   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
00930   p=(const unsigned char *) source;
00931   q=(unsigned char *) destination;
00932   if ((p <= q) || ((p+size) >= q))
00933     return(CopyMagickMemory(destination,source,size));
00934   /*
00935     Overlap, copy backwards.
00936   */
00937   p+=size;
00938   q+=size;
00939   for (i=(long) (size-1); i >= 0; i--)
00940     *--q=(*--p);
00941   return(destination);
00942 }
00943 
00944 /*
00945 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00946 %                                                                             %
00947 %                                                                             %
00948 %                                                                             %
00949 %   C l o s e C a c h e V i e w                                               %
00950 %                                                                             %
00951 %                                                                             %
00952 %                                                                             %
00953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00954 %
00955 %  CloseCacheView() closes the specified view returned by a previous call to
00956 %  OpenCacheView().
00957 %
00958 %  The format of the CloseCacheView method is:
00959 %
00960 %      CacheView *CloseCacheView(CacheView *view_info)
00961 %
00962 %  A description of each parameter follows:
00963 %
00964 %    o view_info: the address of a structure of type CacheView.
00965 %
00966 */
00967 MagickExport CacheView *CloseCacheView(CacheView *view_info)
00968 {
00969   return(DestroyCacheView(view_info));
00970 }
00971 
00972 /*
00973 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00974 %                                                                             %
00975 %                                                                             %
00976 %                                                                             %
00977 %   C o l o r F l o o d f i l l I m a g e                                     %
00978 %                                                                             %
00979 %                                                                             %
00980 %                                                                             %
00981 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00982 %
00983 %  ColorFloodfill() changes the color value of any pixel that matches
00984 %  target and is an immediate neighbor.  If the method FillToBorderMethod is
00985 %  specified, the color value is changed for any neighbor pixel that does not
00986 %  match the bordercolor member of image.
00987 %
00988 %  By default target must match a particular pixel color exactly.
00989 %  However, in many cases two colors may differ by a small amount.  The
00990 %  fuzz member of image defines how much tolerance is acceptable to
00991 %  consider two colors as the same.  For example, set fuzz to 10 and the
00992 %  color red at intensities of 100 and 102 respectively are now
00993 %  interpreted as the same color for the purposes of the floodfill.
00994 %
00995 %  The format of the ColorFloodfillImage method is:
00996 %
00997 %      MagickBooleanType ColorFloodfillImage(Image *image,
00998 %        const DrawInfo *draw_info,const PixelPacket target,
00999 %        const long x_offset,const long y_offset,const PaintMethod method)
01000 %
01001 %  A description of each parameter follows:
01002 %
01003 %    o image: the image.
01004 %
01005 %    o draw_info: the draw info.
01006 %
01007 %    o target: the RGB value of the target color.
01008 %
01009 %    o x,y: the starting location of the operation.
01010 %
01011 %    o method: Choose either FloodfillMethod or FillToBorderMethod.
01012 %
01013 */
01014 
01015 #define MaxStacksize  (1UL << 15)
01016 #define PushSegmentStack(up,left,right,delta) \
01017 { \
01018   if (s >= (segment_stack+MaxStacksize)) \
01019     ThrowBinaryException(DrawError,"SegmentStackOverflow",image->filename) \
01020   else \
01021     { \
01022       if ((((up)+(delta)) >= 0) && (((up)+(delta)) < (long) image->rows)) \
01023         { \
01024           s->x1=(double) (left); \
01025           s->y1=(double) (up); \
01026           s->x2=(double) (right); \
01027           s->y2=(double) (delta); \
01028           s++; \
01029         } \
01030     } \
01031 }
01032 
01033 MagickExport MagickBooleanType ColorFloodfillImage(Image *image,
01034   const DrawInfo *draw_info,const PixelPacket target,const long x_offset,
01035   const long y_offset,const PaintMethod method)
01036 {
01037   Image
01038     *floodplane_image;
01039 
01040   long
01041     offset,
01042     start,
01043     x,
01044     x1,
01045     x2,
01046     y;
01047 
01048   MagickBooleanType
01049     skip;
01050 
01051   PixelPacket
01052     fill_color;
01053 
01054   register SegmentInfo
01055     *s;
01056 
01057   SegmentInfo
01058     *segment_stack;
01059 
01060   /*
01061     Check boundary conditions.
01062   */
01063   assert(image != (Image *) NULL);
01064   assert(image->signature == MagickSignature);
01065   if (image->debug != MagickFalse)
01066     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
01067   assert(draw_info != (DrawInfo *) NULL);
01068   assert(draw_info->signature == MagickSignature);
01069   if ((x_offset < 0) || (x_offset >= (long) image->columns))
01070     return(MagickFalse);
01071   if ((y_offset < 0) || (y_offset >= (long) image->rows))
01072     return(MagickFalse);
01073   if (SetImageStorageClass(image,DirectClass) == MagickFalse)
01074     return(MagickFalse);
01075   if (image->matte == MagickFalse)
01076     (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
01077   floodplane_image=CloneImage(image,image->columns,image->rows,MagickTrue,
01078     &image->exception);
01079   if (floodplane_image == (Image *) NULL)
01080     return(MagickFalse);
01081   (void) SetImageAlphaChannel(floodplane_image,OpaqueAlphaChannel);
01082   /*
01083     Set floodfill color.
01084   */
01085   segment_stack=(SegmentInfo *) AcquireQuantumMemory(MaxStacksize,
01086     sizeof(*segment_stack));
01087   if (segment_stack == (SegmentInfo *) NULL)
01088     {
01089       floodplane_image=DestroyImage(floodplane_image);
01090       ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
01091         image->filename);
01092     }
01093   /*
01094     Push initial segment on stack.
01095   */
01096   x=x_offset;
01097   y=y_offset;
01098   start=0;
01099   s=segment_stack;
01100   PushSegmentStack(y,x,x,1);
01101   PushSegmentStack(y+1,x,x,-1);
01102   while (s > segment_stack)
01103   {
01104     register const PixelPacket
01105       *__restrict p;
01106 
01107     register long
01108       x;
01109 
01110     register PixelPacket
01111       *__restrict q;
01112 
01113     /*
01114       Pop segment off stack.
01115     */
01116     s--;
01117     x1=(long) s->x1;
01118     x2=(long) s->x2;
01119     offset=(long) s->y2;
01120     y=(long) s->y1+offset;
01121     /*
01122       Recolor neighboring pixels.
01123     */
01124     p=GetVirtualPixels(image,0,y,(unsigned long) (x1+1),1,&image->exception);
01125     q=GetAuthenticPixels(floodplane_image,0,y,(unsigned long) (x1+1),1,
01126       &image->exception);
01127     if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
01128       break;
01129     p+=x1;
01130     q+=x1;
01131     for (x=x1; x >= 0; x--)
01132     {
01133       if (q->opacity == (Quantum) TransparentOpacity)
01134         break;
01135       if (method == FloodfillMethod)
01136         {
01137           if (IsColorSimilar(image,p,&target) == MagickFalse)
01138             break;
01139         }
01140       else
01141         if (IsColorSimilar(image,p,&target) != MagickFalse)
01142           break;
01143       q->opacity=(Quantum) TransparentOpacity;
01144       p--;
01145       q--;
01146     }
01147     if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse)
01148       break;
01149     skip=x >= x1 ? MagickTrue : MagickFalse;
01150     if (skip == MagickFalse)
01151       {
01152         start=x+1;
01153         if (start < x1)
01154           PushSegmentStack(y,start,x1-1,-offset);
01155         x=x1+1;
01156       }
01157     do
01158     {
01159       if (skip == MagickFalse)
01160         {
01161           if (x < (long) image->columns)
01162             {
01163               p=GetVirtualPixels(image,x,y,image->columns-x,1,
01164                 &image->exception);
01165               q=GetAuthenticPixels(floodplane_image,x,y,image->columns-x,1,
01166                 &image->exception);
01167               if ((p == (const PixelPacket *) NULL) ||
01168                   (q == (PixelPacket *) NULL))
01169                 break;
01170               for ( ; x < (long) image->columns; x++)
01171               {
01172                 if (q->opacity == (Quantum) TransparentOpacity)
01173                   break;
01174                 if (method == FloodfillMethod)
01175                   {
01176                     if (IsColorSimilar(image,p,&target) == MagickFalse)
01177                       break;
01178                   }
01179                 else
01180                   if (IsColorSimilar(image,p,&target) != MagickFalse)
01181                     break;
01182                 q->opacity=(Quantum) TransparentOpacity;
01183                 p++;
01184                 q++;
01185               }
01186               if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse)
01187                 break;
01188             }
01189           PushSegmentStack(y,start,x-1,offset);
01190           if (x > (x2+1))
01191             PushSegmentStack(y,x2+1,x-1,-offset);
01192         }
01193       skip=MagickFalse;
01194       x++;
01195       if (x <= x2)
01196         {
01197           p=GetVirtualPixels(image,x,y,(unsigned long) (x2-x+1),1,
01198             &image->exception);
01199           q=GetAuthenticPixels(floodplane_image,x,y,(unsigned long) (x2-x+1),1,
01200             &image->exception);
01201           if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
01202             break;
01203           for ( ; x <= x2; x++)
01204           {
01205             if (q->opacity == (Quantum) TransparentOpacity)
01206               break;
01207             if (method == FloodfillMethod)
01208               {
01209                 if (IsColorSimilar(image,p,&target) != MagickFalse)
01210                   break;
01211               }
01212             else
01213               if (IsColorSimilar(image,p,&target) == MagickFalse)
01214                 break;
01215             p++;
01216             q++;
01217           }
01218         }
01219       start=x;
01220     } while (x <= x2);
01221   }
01222   for (y=0; y < (long) image->rows; y++)
01223   {
01224     register const PixelPacket
01225       *__restrict p;
01226 
01227     register long
01228       x;
01229 
01230     register PixelPacket
01231       *__restrict q;
01232 
01233     /*
01234       Tile fill color onto floodplane.
01235     */
01236     p=GetVirtualPixels(floodplane_image,0,y,image->columns,1,
01237       &image->exception);
01238     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
01239     if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
01240       break;
01241     for (x=0; x < (long) image->columns; x++)
01242     {
01243       if (p->opacity != OpaqueOpacity)
01244         {
01245           (void) GetFillColor(draw_info,x,y,&fill_color);
01246           MagickCompositeOver(&fill_color,(MagickRealType) fill_color.opacity,q,
01247             (MagickRealType) q->opacity,q);
01248         }
01249       p++;
01250       q++;
01251     }
01252     if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
01253       break;
01254   }
01255   segment_stack=(SegmentInfo *) RelinquishMagickMemory(segment_stack);
01256   floodplane_image=DestroyImage(floodplane_image);
01257   return(y == (long) image->rows ? MagickTrue : MagickFalse);
01258 }
01259 
01260 /*
01261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01262 %                                                                             %
01263 %                                                                             %
01264 %                                                                             %
01265 %   D e l e t e I m a g e A t t r i b u t e                                   %
01266 %                                                                             %
01267 %                                                                             %
01268 %                                                                             %
01269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01270 %
01271 %  DeleteImageAttribute() deletes an attribute from the image.
01272 %
01273 %  The format of the DeleteImageAttribute method is:
01274 %
01275 %      MagickBooleanType DeleteImageAttribute(Image *image,const char *key)
01276 %
01277 %  A description of each parameter follows:
01278 %
01279 %    o image: the image info.
01280 %
01281 %    o key: the image key.
01282 %
01283 */
01284 MagickExport MagickBooleanType DeleteImageAttribute(Image *image,
01285   const char *key)
01286 {
01287   return(DeleteImageProperty(image,key));
01288 }
01289 
01290 /*
01291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01292 %                                                                             %
01293 %                                                                             %
01294 %                                                                             %
01295 %   D e l e t e I m a g e L i s t                                             %
01296 %                                                                             %
01297 %                                                                             %
01298 %                                                                             %
01299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01300 %
01301 %  DeleteImageList() deletes an image at the specified position in the list.
01302 %
01303 %  The format of the DeleteImageList method is:
01304 %
01305 %      unsigned int DeleteImageList(Image *images,const long offset)
01306 %
01307 %  A description of each parameter follows:
01308 %
01309 %    o images: the image list.
01310 %
01311 %    o offset: the position within the list.
01312 %
01313 */
01314 MagickExport unsigned int DeleteImageList(Image *images,const long offset)
01315 {
01316   register long
01317     i;
01318 
01319   if (images->debug != MagickFalse)
01320     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
01321   while (GetPreviousImageInList(images) != (Image *) NULL)
01322     images=GetPreviousImageInList(images);
01323   for (i=0; i < offset; i++)
01324   {
01325     if (GetNextImageInList(images) == (Image *) NULL)
01326       return(MagickFalse);
01327     images=GetNextImageInList(images);
01328   }
01329   DeleteImageFromList(&images);
01330   return(MagickTrue);
01331 }
01332 
01333 /*
01334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01335 %                                                                             %
01336 %                                                                             %
01337 %                                                                             %
01338 %   D e l e t e M a g i c k R e g i s t r y                                   %
01339 %                                                                             %
01340 %                                                                             %
01341 %                                                                             %
01342 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01343 %
01344 %  DeleteMagickRegistry() deletes an entry in the registry as defined by the id.
01345 %  It returns MagickTrue if the entry is deleted otherwise MagickFalse if no
01346 %  entry is found in the registry that matches the id.
01347 %
01348 %  The format of the DeleteMagickRegistry method is:
01349 %
01350 %      MagickBooleanType DeleteMagickRegistry(const long id)
01351 %
01352 %  A description of each parameter follows:
01353 %
01354 %    o id: the registry id.
01355 %
01356 */
01357 MagickExport MagickBooleanType DeleteMagickRegistry(const long id)
01358 {
01359   char
01360     key[MaxTextExtent];
01361 
01362   (void) FormatMagickString(key,MaxTextExtent,"%ld\n",id);
01363   return(DeleteImageRegistry(key));
01364 }
01365 
01366 /*
01367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01368 %                                                                             %
01369 %                                                                             %
01370 %                                                                             %
01371 +   D e s t r o y M a g i c k R e g i s t r y                                 %
01372 %                                                                             %
01373 %                                                                             %
01374 %                                                                             %
01375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01376 %
01377 %  DestroyMagickRegistry() deallocates memory associated the magick registry.
01378 %
01379 %  The format of the DestroyMagickRegistry method is:
01380 %
01381 %       void DestroyMagickRegistry(void)
01382 %
01383 */
01384 MagickExport void DestroyMagickRegistry(void)
01385 {
01386   RegistryComponentTerminus();
01387 }
01388 
01389 /*
01390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01391 %                                                                             %
01392 %                                                                             %
01393 %                                                                             %
01394 %   D e s c r i b e I m a g e                                                 %
01395 %                                                                             %
01396 %                                                                             %
01397 %                                                                             %
01398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01399 %
01400 %  DescribeImage() describes an image by printing its attributes to the file.
01401 %  Attributes include the image width, height, size, and others.
01402 %
01403 %  The format of the DescribeImage method is:
01404 %
01405 %      MagickBooleanType DescribeImage(Image *image,FILE *file,
01406 %        const MagickBooleanType verbose)
01407 %
01408 %  A description of each parameter follows:
01409 %
01410 %    o image: the image.
01411 %
01412 %    o file: the file, typically stdout.
01413 %
01414 %    o verbose: A value other than zero prints more detailed information
01415 %      about the image.
01416 %
01417 */
01418 MagickExport MagickBooleanType DescribeImage(Image *image,FILE *file,
01419   const MagickBooleanType verbose)
01420 {
01421   return(IdentifyImage(image,file,verbose));
01422 }
01423 
01424 /*
01425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01426 %                                                                             %
01427 %                                                                             %
01428 %                                                                             %
01429 %   D e s t r o y I m a g e A t t r i b u t e s                               %
01430 %                                                                             %
01431 %                                                                             %
01432 %                                                                             %
01433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01434 %
01435 %  DestroyImageAttributes() deallocates memory associated with the image
01436 %  attribute list.
01437 %
01438 %  The format of the DestroyImageAttributes method is:
01439 %
01440 %      DestroyImageAttributes(Image *image)
01441 %
01442 %  A description of each parameter follows:
01443 %
01444 %    o image: the image.
01445 %
01446 */
01447 MagickExport void DestroyImageAttributes(Image *image)
01448 {
01449   assert(image != (Image *) NULL);
01450   assert(image->signature == MagickSignature);
01451   if (image->debug != MagickFalse)
01452     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
01453   if (image->attributes != (void *) NULL)
01454     image->attributes=(void *) DestroySplayTree((SplayTreeInfo *)
01455       image->attributes);
01456 }
01457 
01458 /*
01459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01460 %                                                                             %
01461 %                                                                             %
01462 %                                                                             %
01463 %   D e s t r o y I m a g e s                                                 %
01464 %                                                                             %
01465 %                                                                             %
01466 %                                                                             %
01467 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01468 %
01469 %  DestroyImages() destroys an image list.
01470 %
01471 %  The format of the DestroyImages method is:
01472 %
01473 %      void DestroyImages(Image *image)
01474 %
01475 %  A description of each parameter follows:
01476 %
01477 %    o image: the image sequence.
01478 %
01479 */
01480 MagickExport void DestroyImages(Image *image)
01481 {
01482   if (image == (Image *) NULL)
01483     return;
01484   if (image->debug != MagickFalse)
01485     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.4.3");
01486   image=DestroyImageList(image);
01487 }
01488 
01489 /*
01490 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01491 %                                                                             %
01492 %                                                                             %
01493 %                                                                             %
01494 %   D e s t r o y M a g i c k                                                 %
01495 %                                                                             %
01496 %                                                                             %
01497 %                                                                             %
01498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01499 %
01500 %  DestroyMagick() destroys the ImageMagick environment.
01501 %
01502 %  The format of the DestroyMagick function is:
01503 %
01504 %      DestroyMagick(void)
01505 %
01506 */
01507 MagickExport void DestroyMagick(void)
01508 {
01509   MagickCoreTerminus();
01510 }
01511 
01512 /*
01513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01514 %                                                                             %
01515 %                                                                             %
01516 %                                                                             %
01517 %   D i s p a t c h I m a g e                                                 %
01518 %                                                                             %
01519 %                                                                             %
01520 %                                                                             %
01521 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01522 %
01523 %  DispatchImage() extracts pixel data from an image and returns it to you.
01524 %  The method returns MagickFalse on success otherwise MagickTrue if an error is
01525 %  encountered.  The data is returned as char, short int, int, long, float,
01526 %  or double in the order specified by map.
01527 %
01528 %  Suppose you want to extract the first scanline of a 640x480 image as
01529 %  character data in red-green-blue order:
01530 %
01531 %      DispatchImage(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
01532 %
01533 %  The format of the DispatchImage method is:
01534 %
01535 %      unsigned int DispatchImage(const Image *image,const long x_offset,
01536 %        const long y_offset,const unsigned long columns,
01537 %        const unsigned long rows,const char *map,const StorageType type,
01538 %        void *pixels,ExceptionInfo *exception)
01539 %
01540 %  A description of each parameter follows:
01541 %
01542 %    o image: the image.
01543 %
01544 %    o x_offset, y_offset, columns, rows:  These values define the perimeter
01545 %      of a region of pixels you want to extract.
01546 %
01547 %    o map:  This string reflects the expected ordering of the pixel array.
01548 %      It can be any combination or order of R = red, G = green, B = blue,
01549 %      A = alpha, C = cyan, Y = yellow, M = magenta, K = black, or
01550 %      I = intensity (for grayscale).
01551 %
01552 %    o type: Define the data type of the pixels.  Float and double types are
01553 %      normalized to [0..1] otherwise [0..QuantumRange].  Choose from these
01554 %      types: CharPixel, ShortPixel, IntegerPixel, LongPixel, FloatPixel, or
01555 %      DoublePixel.
01556 %
01557 %    o pixels: This array of values contain the pixel components as defined by
01558 %      map and type.  You must preallocate this array where the expected
01559 %      length varies depending on the values of width, height, map, and type.
01560 %
01561 %    o exception: return any errors or warnings in this structure.
01562 %
01563 */
01564 MagickExport unsigned int DispatchImage(const Image *image,const long x_offset,
01565   const long y_offset,const unsigned long columns,const unsigned long rows,
01566   const char *map,const StorageType type,void *pixels,ExceptionInfo *exception)
01567 {
01568   unsigned int
01569     status;
01570 
01571   if (image->debug != MagickFalse)
01572     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.6");
01573   status=ExportImagePixels(image,x_offset,y_offset,columns,rows,map,type,pixels,
01574     exception);
01575   return(status);
01576 }
01577 
01578 /*
01579 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01580 %                                                                             %
01581 %                                                                             %
01582 %                                                                             %
01583 %   E x t r a c t S u b i m a g e F r o m I m a g e                           %
01584 %                                                                             %
01585 %                                                                             %
01586 %                                                                             %
01587 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01588 %
01589 %  ExtractSubimageFromImageImage() extracts a region of the image that most
01590 %  closely resembles the reference.
01591 %
01592 %  The format of the ExtractSubimageFromImageImage method is:
01593 %
01594 %      Image *ExtractSubimageFromImage(const Image *image,const Image *reference,
01595 %        ExceptionInfo *exception)
01596 %
01597 %  A description of each parameter follows:
01598 %
01599 %    o image: the image.
01600 %
01601 %    o reference: find an area of the image that closely resembles this image.
01602 %
01603 %    o exception: return any errors or warnings in this structure.
01604 %
01605 */
01606 
01607 static double GetSimilarityMetric(const Image *image,const Image *reference,
01608   const long x_offset,const long y_offset,const double similarity_threshold,
01609   ExceptionInfo *exception)
01610 {
01611   long
01612     y;
01613 
01614   double
01615     channels,
01616     normalized_similarity,
01617     similarity;
01618 
01619   CacheView
01620     *image_view,
01621     *reference_view;
01622 
01623   /*
01624     Compute the similarity in pixels between two images.
01625   */
01626   normalized_similarity=1.0;
01627   similarity=0.0;
01628   channels=3;
01629   if ((image->matte != MagickFalse) && (reference->matte != MagickFalse))
01630     channels++;
01631   if ((image->colorspace == CMYKColorspace) &&
01632       (reference->colorspace == CMYKColorspace))
01633     channels++;
01634   image_view=AcquireCacheView(image);
01635   reference_view=AcquireCacheView(reference);
01636   for (y=0; y < (long) reference->rows; y++)
01637   {
01638     register const IndexPacket
01639       *indexes,
01640       *reference_indexes;
01641 
01642     register const PixelPacket
01643       *p,
01644       *q;
01645 
01646     register long
01647       x;
01648 
01649     p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset+y,
01650       reference->columns,1,exception);
01651     q=GetCacheViewVirtualPixels(reference_view,0,y,reference->columns,1,
01652       exception);
01653     if ((p == (const PixelPacket *) NULL) || (q == (const PixelPacket *) NULL))
01654       continue;
01655     indexes=GetCacheViewVirtualIndexQueue(image_view);
01656     reference_indexes=GetCacheViewVirtualIndexQueue(reference_view);
01657     for (x=0; x < (long) reference->columns; x++)
01658     {
01659       MagickRealType
01660         pixel;
01661 
01662       pixel=QuantumScale*(p->red-(double) q->red);
01663       similarity+=pixel*pixel;
01664       pixel=QuantumScale*(p->green-(double) q->green);
01665       similarity+=pixel*pixel;
01666       pixel=QuantumScale*(p->blue-(double) q->blue);
01667       similarity+=pixel*pixel;
01668       if ((image->matte != MagickFalse) && (reference->matte != MagickFalse))
01669         {
01670           pixel=QuantumScale*(p->opacity-(double) q->opacity);
01671           similarity+=pixel*pixel;
01672         }
01673       if ((image->colorspace == CMYKColorspace) &&
01674           (reference->colorspace == CMYKColorspace))
01675         {
01676           pixel=QuantumScale*(indexes[x]-(double) reference_indexes[x]);
01677           similarity+=pixel*pixel;
01678         }
01679       p++;
01680       q++;
01681     }
01682     normalized_similarity=sqrt(similarity)/reference->columns/reference->rows/
01683       channels;
01684     if (normalized_similarity > similarity_threshold)
01685       break;
01686   }
01687   reference_view=DestroyCacheView(reference_view);
01688   image_view=DestroyCacheView(image_view);
01689   return(normalized_similarity);
01690 }
01691 
01692 MagickExport Image *ExtractSubimageFromImage(Image *image,
01693   const Image *reference,ExceptionInfo *exception)
01694 {
01695   long
01696     y;
01697 
01698   double
01699     similarity_threshold;
01700 
01701   RectangleInfo
01702     offset;
01703 
01704   /*
01705     Extract reference from image.
01706   */
01707   if ((reference->columns > image->columns) || (reference->rows > image->rows))
01708     return((Image *) NULL);
01709   similarity_threshold=image->columns*image->rows;
01710   SetGeometry(reference,&offset);
01711 #if defined(MAGICKCORE_OPENMP_SUPPORT)
01712   #pragma omp parallel for schedule(dynamic,4)
01713 #endif
01714   for (y=0; y < (long) (image->rows-reference->rows); y++)
01715   {
01716     double
01717       similarity;
01718 
01719     register long
01720       x;
01721 
01722     for (x=0; x < (long) (image->columns-reference->columns); x++)
01723     {
01724       similarity=GetSimilarityMetric(image,reference,x,y,similarity_threshold,
01725         exception);
01726 #if defined(MAGICKCORE_OPENMP_SUPPORT)
01727   #pragma omp critical (MagickCore_ExtractSubimageFromImage)
01728 #endif
01729       if (similarity < similarity_threshold)
01730         {
01731           similarity_threshold=similarity;
01732           offset.x=x;
01733           offset.y=y;
01734         }
01735     }
01736   }
01737   if (similarity_threshold > (QuantumScale*reference->fuzz/100.0))
01738     return((Image *) NULL);
01739   return(CropImage(image,&offset,exception));
01740 }
01741 
01742 /*
01743 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01744 %                                                                             %
01745 %                                                                             %
01746 %                                                                             %
01747 %     F l a t t e n I m a g e                                                 %
01748 %                                                                             %
01749 %                                                                             %
01750 %                                                                             %
01751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01752 %
01753 %  FlattenImages() Obsolete Function: Use MergeImageLayers() instead.
01754 %
01755 %  The format of the FlattenImage method is:
01756 %
01757 %      Image *FlattenImage(Image *image,ExceptionInfo *exception)
01758 %
01759 %  A description of each parameter follows:
01760 %
01761 %    o image: the image sequence.
01762 %
01763 %    o exception: return any errors or warnings in this structure.
01764 %
01765 */
01766 MagickExport Image *FlattenImages(Image *image,ExceptionInfo *exception)
01767 {
01768   return(MergeImageLayers(image,FlattenLayer,exception));
01769 }
01770 
01771 /*
01772 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01773 %                                                                             %
01774 %                                                                             %
01775 %                                                                             %
01776 %  F o r m a t I m a g e A t t r i b u t e                                    %
01777 %                                                                             %
01778 %                                                                             %
01779 %                                                                             %
01780 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01781 %
01782 %  FormatImageAttribute() permits formatted key/value pairs to be saved as an
01783 %  image attribute.
01784 %
01785 %  The format of the FormatImageAttribute method is:
01786 %
01787 %      MagickBooleanType FormatImageAttribute(Image *image,const char *key,
01788 %        const char *format,...)
01789 %
01790 %  A description of each parameter follows.
01791 %
01792 %   o  image:  The image.
01793 %
01794 %   o  key:  The attribute key.
01795 %
01796 %   o  format:  A string describing the format to use to write the remaining
01797 %      arguments.
01798 %
01799 */
01800 
01801 MagickExport MagickBooleanType FormatImageAttributeList(Image *image,
01802   const char *key,const char *format,va_list operands)
01803 {
01804   char
01805     value[MaxTextExtent];
01806 
01807   int
01808     n;
01809 
01810 #if defined(MAGICKCORE_HAVE_VSNPRINTF)
01811   n=vsnprintf(value,MaxTextExtent,format,operands);
01812 #else
01813   n=vsprintf(value,format,operands);
01814 #endif
01815   if (n < 0)
01816     value[MaxTextExtent-1]='\0';
01817   return(SetImageProperty(image,key,value));
01818 }
01819 
01820 MagickExport MagickBooleanType FormatImageAttribute(Image *image,
01821   const char *key,const char *format,...)
01822 {
01823   MagickBooleanType
01824     status;
01825 
01826   va_list
01827     operands;
01828 
01829   va_start(operands,format);
01830   status=FormatImagePropertyList(image,key,format,operands);
01831   va_end(operands);
01832   return(status);
01833 }
01834 
01835 /*
01836 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01837 %                                                                             %
01838 %                                                                             %
01839 %                                                                             %
01840 %  F o r m a t S t r i n g                                                    %
01841 %                                                                             %
01842 %                                                                             %
01843 %                                                                             %
01844 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01845 %
01846 %  FormatString() prints formatted output of a variable argument list.
01847 %
01848 %  The format of the FormatString method is:
01849 %
01850 %      void FormatString(char *string,const char *format,...)
01851 %
01852 %  A description of each parameter follows.
01853 %
01854 %   o  string:  Method FormatString returns the formatted string in this
01855 %      character buffer.
01856 %
01857 %   o  format:  A string describing the format to use to write the remaining
01858 %      arguments.
01859 %
01860 */
01861 
01862 MagickExport void FormatStringList(char *string,const char *format,
01863   va_list operands)
01864 {
01865   int
01866     n;
01867 
01868  (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
01869 #if defined(MAGICKCORE_HAVE_VSNPRINTF)
01870   n=vsnprintf(string,MaxTextExtent,format,operands);
01871 #else
01872   n=vsprintf(string,format,operands);
01873 #endif
01874   if (n < 0)
01875     string[MaxTextExtent-1]='\0';
01876 }
01877 
01878 MagickExport void FormatString(char *string,const char *format,...)
01879 {
01880   va_list
01881     operands;
01882 
01883   va_start(operands,format);
01884   FormatMagickStringList(string,MaxTextExtent,format,operands);
01885   va_end(operands);
01886   return;
01887 }
01888 
01889 /*
01890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01891 %                                                                             %
01892 %                                                                             %
01893 %                                                                             %
01894 +   F u z z y C o l o r M a t c h                                             %
01895 %                                                                             %
01896 %                                                                             %
01897 %                                                                             %
01898 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01899 %
01900 %  FuzzyColorMatch() returns true if two pixels are identical in color.
01901 %
01902 %  The format of the ColorMatch method is:
01903 %
01904 %      void FuzzyColorMatch(const PixelPacket *p,const PixelPacket *q,
01905 %        const double fuzz)
01906 %
01907 %  A description of each parameter follows:
01908 %
01909 %    o p: Pixel p.
01910 %
01911 %    o q: Pixel q.
01912 %
01913 %    o distance:  Define how much tolerance is acceptable to consider
01914 %      two colors as the same.
01915 %
01916 */
01917 MagickExport unsigned int FuzzyColorMatch(const PixelPacket *p,
01918   const PixelPacket *q,const double fuzz)
01919 {
01920   MagickPixelPacket
01921     pixel;
01922 
01923   register MagickRealType
01924     distance;
01925 
01926   if ((fuzz == 0.0) && (p->red == q->red) && (p->green == q->green) &&
01927       (p->blue == q->blue))
01928     return(MagickTrue);
01929   pixel.red=p->red-(MagickRealType) q->red;
01930   distance=pixel.red*pixel.red;
01931   if (distance > (fuzz*fuzz))
01932     return(MagickFalse);
01933   pixel.green=p->green-(MagickRealType) q->green;
01934   distance+=pixel.green*pixel.green;
01935   if (distance > (fuzz*fuzz))
01936     return(MagickFalse);
01937   pixel.blue=p->blue-(MagickRealType) q->blue;
01938   distance+=pixel.blue*pixel.blue;
01939   if (distance > (fuzz*fuzz))
01940     return(MagickFalse);
01941   return(MagickTrue);
01942 }
01943 
01944 /*
01945 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01946 %                                                                             %
01947 %                                                                             %
01948 %                                                                             %
01949 +   F u z z y C o l o r C o m p a r e                                         %
01950 %                                                                             %
01951 %                                                                             %
01952 %                                                                             %
01953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01954 %
01955 %  FuzzyColorCompare() returns MagickTrue if the distance between two colors is
01956 %  less than the specified distance in a linear three dimensional color space.
01957 %  This method is used by ColorFloodFill() and other algorithms which
01958 %  compare two colors.
01959 %
01960 %  The format of the FuzzyColorCompare method is:
01961 %
01962 %      void FuzzyColorCompare(const Image *image,const PixelPacket *p,
01963 %        const PixelPacket *q)
01964 %
01965 %  A description of each parameter follows:
01966 %
01967 %    o image: the image.
01968 %
01969 %    o p: Pixel p.
01970 %
01971 %    o q: Pixel q.
01972 %
01973 */
01974 MagickExport MagickBooleanType FuzzyColorCompare(const Image *image,
01975   const PixelPacket *p,const PixelPacket *q)
01976 {
01977   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.5");
01978   return(IsColorSimilar(image,p,q));
01979 }
01980 
01981 /*
01982 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01983 %                                                                             %
01984 %                                                                             %
01985 %                                                                             %
01986 +   F u z z y O p a c i t y C o m p a r e                                     %
01987 %                                                                             %
01988 %                                                                             %
01989 %                                                                             %
01990 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01991 %
01992 %  FuzzyOpacityCompare() returns true if the distance between two opacity
01993 %  values is less than the specified distance in a linear color space.  This
01994 %  method is used by MatteFloodFill() and other algorithms which compare
01995 %  two opacity values.
01996 %
01997 %  The format of the FuzzyOpacityCompare method is:
01998 %
01999 %      void FuzzyOpacityCompare(const Image *image,const PixelPacket *p,
02000 %        const PixelPacket *q)
02001 %
02002 %  A description of each parameter follows:
02003 %
02004 %    o image: the image.
02005 %
02006 %    o p: Pixel p.
02007 %
02008 %    o q: Pixel q.
02009 %
02010 */
02011 MagickExport MagickBooleanType FuzzyOpacityCompare(const Image *image,
02012   const PixelPacket *p,const PixelPacket *q)
02013 {
02014   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.5");
02015   return(IsOpacitySimilar(image,p,q));
02016 }
02017 
02018 /*
02019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02020 %                                                                             %
02021 %                                                                             %
02022 %                                                                             %
02023 %  G e t C o n f i g u r e B l o b                                            %
02024 %                                                                             %
02025 %                                                                             %
02026 %                                                                             %
02027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02028 %
02029 %  GetConfigureBlob() returns the specified configure file as a blob.
02030 %
02031 %  The format of the GetConfigureBlob method is:
02032 %
02033 %      void *GetConfigureBlob(const char *filename,ExceptionInfo *exception)
02034 %
02035 %  A description of each parameter follows:
02036 %
02037 %    o filename: the configure file name.
02038 %
02039 %    o path: return the full path information of the configure file.
02040 %
02041 %    o length: This pointer to a size_t integer sets the initial length of the
02042 %      blob.  On return, it reflects the actual length of the blob.
02043 %
02044 %    o exception: return any errors or warnings in this structure.
02045 %
02046 */
02047 MagickExport void *GetConfigureBlob(const char *filename,char *path,
02048   size_t *length,ExceptionInfo *exception)
02049 {
02050   void
02051     *blob;
02052 
02053   assert(filename != (const char *) NULL);
02054   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
02055   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
02056   assert(path != (char *) NULL);
02057   assert(length != (size_t *) NULL);
02058   assert(exception != (ExceptionInfo *) NULL);
02059   blob=(void *) NULL;
02060   (void) CopyMagickString(path,filename,MaxTextExtent);
02061 #if defined(MAGICKCORE_INSTALLED_SUPPORT)
02062 #if defined(MAGICKCORE_LIBRARY_PATH)
02063   if (blob == (void *) NULL)
02064     {
02065       /*
02066         Search hard coded paths.
02067       */
02068       (void) FormatMagickString(path,MaxTextExtent,"%s%s",
02069         MAGICKCORE_LIBRARY_PATH,filename);
02070       if (IsPathAccessible(path) != MagickFalse)
02071         blob=FileToBlob(path,~0,length,exception);
02072     }
02073 #endif
02074 #if defined(__WINDOWS__) && !(defined(MAGICKCORE_CONFIGURE_PATH) || defined(MAGICKCORE_SHARE_CONFIGURE_PATH))
02075   if (blob == (void *) NULL)
02076     {
02077       char
02078         *key_value;
02079 
02080       /*
02081         Locate file via registry key.
02082       */
02083       key_value=NTRegistryKeyLookup("ConfigurePath");
02084       if (key_value != (char *) NULL)
02085         {
02086           (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",key_value,
02087             DirectorySeparator,filename);
02088           if (IsPathAccessible(path) != MagickFalse)
02089             blob=FileToBlob(path,~0,length,exception);
02090         }
02091     }
02092 #endif
02093 #else
02094   if (blob == (void *) NULL)
02095     {
02096       char
02097         *home;
02098 
02099       home=GetEnvironmentValue("MAGICK_HOME");
02100       if (home != (char *) NULL)
02101         {
02102           /*
02103             Search MAGICK_HOME.
02104           */
02105 #if !defined(MAGICKCORE_POSIX_SUPPORT)
02106           (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",home,
02107             DirectorySeparator,filename);
02108 #else
02109           (void) FormatMagickString(path,MaxTextExtent,"%s/lib/%s/%s",home,
02110             MAGICKCORE_LIBRARY_RELATIVE_PATH,filename);
02111 #endif
02112           if (IsPathAccessible(path) != MagickFalse)
02113             blob=FileToBlob(path,~0,length,exception);
02114           home=DestroyString(home);
02115         }
02116       home=GetEnvironmentValue("HOME");
02117       if (home == (char *) NULL)
02118         home=GetEnvironmentValue("USERPROFILE");
02119       if (home != (char *) NULL)
02120         {
02121           /*
02122             Search $HOME/.magick.
02123           */
02124           (void) FormatMagickString(path,MaxTextExtent,"%s%s.magick%s%s",home,
02125             DirectorySeparator,DirectorySeparator,filename);
02126           if ((IsPathAccessible(path) != MagickFalse) && (blob == (void *) NULL))
02127             blob=FileToBlob(path,~0,length,exception);
02128           home=DestroyString(home);
02129         }
02130     }
02131   if ((blob == (void *) NULL) && (*GetClientPath() != '\0'))
02132     {
02133 #if !defined(MAGICKCORE_POSIX_SUPPORT)
02134       (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",GetClientPath(),
02135         DirectorySeparator,filename);
02136 #else
02137       char
02138         prefix[MaxTextExtent];
02139 
02140       /*
02141         Search based on executable directory if directory is known.
02142       */
02143       (void) CopyMagickString(prefix,GetClientPath(),
02144         MaxTextExtent);
02145       ChopPathComponents(prefix,1);
02146       (void) FormatMagickString(path,MaxTextExtent,"%s/lib/%s/%s",prefix,
02147         MAGICKCORE_LIBRARY_RELATIVE_PATH,filename);
02148 #endif
02149       if (IsPathAccessible(path) != MagickFalse)
02150         blob=FileToBlob(path,~0,length,exception);
02151     }
02152   /*
02153     Search current directory.
02154   */
02155   if ((blob == (void *) NULL) && (IsPathAccessible(path) != MagickFalse))
02156     blob=FileToBlob(path,~0,length,exception);
02157 #if defined(__WINDOWS__)
02158   /*
02159     Search Windows registry.
02160   */
02161   if (blob == (void *) NULL)
02162     blob=NTResourceToBlob(filename);
02163 #endif
02164 #endif
02165   if (blob == (void *) NULL)
02166     (void) ThrowMagickException(exception,GetMagickModule(),ConfigureWarning,
02167       "UnableToOpenConfigureFile","`%s'",path);
02168   return(blob);
02169 }
02170 
02171 /*
02172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02173 %                                                                             %
02174 %                                                                             %
02175 %                                                                             %
02176 %   G e t C a c h e V i e w                                                   %
02177 %                                                                             %
02178 %                                                                             %
02179 %                                                                             %
02180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02181 %
02182 %  GetCacheView() gets pixels from the in-memory or disk pixel cache as
02183 %  defined by the geometry parameters.   A pointer to the pixels is returned if
02184 %  the pixels are transferred, otherwise a NULL is returned.
02185 %
02186 %  The format of the GetCacheView method is:
02187 %
02188 %      PixelPacket *GetCacheView(CacheView *cache_view,const long x,
02189 %        const long y,const unsigned long columns,const unsigned long rows)
02190 %
02191 %  A description of each parameter follows:
02192 %
02193 %    o cache_view: the address of a structure of type CacheView.
02194 %
02195 %    o x,y,columns,rows:  These values define the perimeter of a region of
02196 %      pixels.
02197 %
02198 */
02199 MagickExport PixelPacket *GetCacheView(CacheView *cache_view,const long x,
02200   const long y,const unsigned long columns,const unsigned long rows)
02201 {
02202   PixelPacket
02203     *pixels;
02204 
02205   pixels=GetCacheViewAuthenticPixels(cache_view,x,y,columns,rows,
02206     GetCacheViewException(cache_view));
02207   return(pixels);
02208 }
02209 
02210 /*
02211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02212 %                                                                             %
02213 %                                                                             %
02214 %                                                                             %
02215 %   G e t C a c h e V i e w I n d e x e s                                     %
02216 %                                                                             %
02217 %                                                                             %
02218 %                                                                             %
02219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02220 %
02221 %  GetCacheViewIndexes() returns the indexes associated with the specified
02222 %  view.
02223 %
02224 %  The format of the GetCacheViewIndexes method is:
02225 %
02226 %      IndexPacket *GetCacheViewIndexes(CacheView *cache_view)
02227 %
02228 %  A description of each parameter follows:
02229 %
02230 %    o cache_view: the cache view.
02231 %
02232 */
02233 MagickExport IndexPacket *GetCacheViewIndexes(CacheView *cache_view)
02234 {
02235   return(GetCacheViewAuthenticIndexQueue(cache_view));
02236 }
02237 
02238 /*
02239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02240 %                                                                             %
02241 %                                                                             %
02242 %                                                                             %
02243 %   G e t C a c h e V i e w P i x e l s                                       %
02244 %                                                                             %
02245 %                                                                             %
02246 %                                                                             %
02247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02248 %
02249 %  GetCacheViewPixels() gets pixels from the in-memory or disk pixel cache as
02250 %  defined by the geometry parameters.   A pointer to the pixels is returned if
02251 %  the pixels are transferred, otherwise a NULL is returned.
02252 %
02253 %  The format of the GetCacheViewPixels method is:
02254 %
02255 %      PixelPacket *GetCacheViewPixels(CacheView *cache_view,const long x,
02256 %        const long y,const unsigned long columns,const unsigned long rows)
02257 %
02258 %  A description of each parameter follows:
02259 %
02260 %    o cache_view: the cache view.
02261 %
02262 %    o x,y,columns,rows:  These values define the perimeter of a region of
02263 %      pixels.
02264 %
02265 */
02266 MagickExport PixelPacket *GetCacheViewPixels(CacheView *cache_view,const long x,
02267   const long y,const unsigned long columns,const unsigned long rows)
02268 {
02269   PixelPacket
02270     *pixels;
02271 
02272   pixels=GetCacheViewAuthenticPixels(cache_view,x,y,columns,rows,
02273     GetCacheViewException(cache_view));
02274   return(pixels);
02275 }
02276 
02277 /*
02278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02279 %                                                                             %
02280 %                                                                             %
02281 %                                                                             %
02282 %   G e t I m a g e A t t r i b u t e                                         %
02283 %                                                                             %
02284 %                                                                             %
02285 %                                                                             %
02286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02287 %
02288 %  GetImageAttribute() searches the list of image attributes and returns
02289 %  a pointer to the attribute if it exists otherwise NULL.
02290 %
02291 %  The format of the GetImageAttribute method is:
02292 %
02293 %      const ImageAttribute *GetImageAttribute(const Image *image,
02294 %        const char *key)
02295 %
02296 %  A description of each parameter follows:
02297 %
02298 %    o image: the image.
02299 %
02300 %    o key:  These character strings are the name of an image attribute to
02301 %      return.
02302 %
02303 */
02304 
02305 static void *DestroyAttribute(void *attribute)
02306 {
02307   register ImageAttribute
02308     *p;
02309 
02310   p=(ImageAttribute *) attribute;
02311   if (p->value != (char *) NULL)
02312     p->value=DestroyString(p->value);
02313   return(RelinquishMagickMemory(p));
02314 }
02315 
02316 MagickExport const ImageAttribute *GetImageAttribute(const Image *image,
02317   const char *key)
02318 {
02319   const char
02320     *value;
02321 
02322   ImageAttribute
02323     *attribute;
02324 
02325   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.3.1");
02326   value=GetImageProperty(image,key);
02327   if (value == (const char *) NULL)
02328     return((const ImageAttribute *) NULL);
02329   if (image->attributes == (void *) NULL)
02330     ((Image *) image)->attributes=NewSplayTree(CompareSplayTreeString,
02331       RelinquishMagickMemory,DestroyAttribute);
02332   else
02333     {
02334       const ImageAttribute
02335         *attribute;
02336 
02337       attribute=(const ImageAttribute *) GetValueFromSplayTree((SplayTreeInfo *)
02338         image->attributes,key);
02339       if (attribute != (const ImageAttribute *) NULL)
02340         return(attribute);
02341     }
02342   attribute=(ImageAttribute *) AcquireMagickMemory(sizeof(*attribute));
02343   if (attribute == (ImageAttribute *) NULL)
02344     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
02345   (void) ResetMagickMemory(attribute,0,sizeof(*attribute));
02346   attribute->key=ConstantString(key);
02347   attribute->value=ConstantString(value);
02348   (void) AddValueToSplayTree((SplayTreeInfo *) ((Image *) image)->attributes,
02349     attribute->key,attribute);
02350   return((const ImageAttribute *) attribute);
02351 }
02352 
02353 /*
02354 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02355 %                                                                             %
02356 %                                                                             %
02357 %                                                                             %
02358 %   G e t I m a g e C l i p p i n g P a t h A t t r i b u t e                 %
02359 %                                                                             %
02360 %                                                                             %
02361 %                                                                             %
02362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02363 %
02364 %  GetImageClippingPathAttribute() searches the list of image attributes and
02365 %  returns a pointer to a clipping path if it exists otherwise NULL.
02366 %
02367 %  The format of the GetImageClippingPathAttribute method is:
02368 %
02369 %      const ImageAttribute *GetImageClippingPathAttribute(Image *image)
02370 %
02371 %  A description of each parameter follows:
02372 %
02373 %    o attribute:  Method GetImageClippingPathAttribute returns the clipping
02374 %      path if it exists otherwise NULL.
02375 %
02376 %    o image: the image.
02377 %
02378 */
02379 MagickExport const ImageAttribute *GetImageClippingPathAttribute(Image *image)
02380 {
02381   return(GetImageAttribute(image,"8BIM:1999,2998"));
02382 }
02383 
02384 /*
02385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02386 %                                                                             %
02387 %                                                                             %
02388 %                                                                             %
02389 %   G e t I m a g e F r o m M a g i c k R e g i s t r y                       %
02390 %                                                                             %
02391 %                                                                             %
02392 %                                                                             %
02393 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02394 %
02395 %  GetImageFromMagickRegistry() gets an image from the registry as defined by
02396 %  its name.  If the image is not found, a NULL image is returned.
02397 %
02398 %  The format of the GetImageFromMagickRegistry method is:
02399 %
02400 %      Image *GetImageFromMagickRegistry(const char *name,long *id,
02401 %        ExceptionInfo *exception)
02402 %
02403 %  A description of each parameter follows:
02404 %
02405 %    o name: the name of the image to retrieve from the registry.
02406 %
02407 %    o id: the registry id.
02408 %
02409 %    o exception: return any errors or warnings in this structure.
02410 %
02411 */
02412 MagickExport Image *GetImageFromMagickRegistry(const char *name,long *id,
02413   ExceptionInfo *exception)
02414 {
02415   *id=0L;
02416   return((Image *) GetImageRegistry(ImageRegistryType,name,exception));
02417 }
02418 
02419 /*
02420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02421 %                                                                             %
02422 %                                                                             %
02423 %                                                                             %
02424 %   G e t M a g i c k R e g i s t r y                                         %
02425 %                                                                             %
02426 %                                                                             %
02427 %                                                                             %
02428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02429 %
02430 %  GetMagickRegistry() gets a blob from the registry as defined by the id.  If
02431 %  the blob that matches the id is not found, NULL is returned.
02432 %
02433 %  The format of the GetMagickRegistry method is:
02434 %
02435 %      const void *GetMagickRegistry(const long id,RegistryType *type,
02436 %        size_t *length,ExceptionInfo *exception)
02437 %
02438 %  A description of each parameter follows:
02439 %
02440 %    o id: the registry id.
02441 %
02442 %    o type: the registry type.
02443 %
02444 %    o length: the blob length in number of bytes.
02445 %
02446 %    o exception: return any errors or warnings in this structure.
02447 %
02448 */
02449 MagickExport void *GetMagickRegistry(const long id,RegistryType *type,
02450   size_t *length,ExceptionInfo *exception)
02451 {
02452   char
02453     key[MaxTextExtent];
02454 
02455   void
02456     *blob;
02457 
02458   *type=UndefinedRegistryType;
02459   *length=0;
02460   (void) FormatMagickString(key,MaxTextExtent,"%ld\n",id);
02461   blob=(void *) GetImageRegistry(ImageRegistryType,key,exception);
02462   if (blob != (void *) NULL)
02463     return(blob);
02464   blob=(void *) GetImageRegistry(ImageInfoRegistryType,key,exception);
02465   if (blob != (void *) NULL)
02466     return(blob);
02467   return((void *) GetImageRegistry(UndefinedRegistryType,key,exception));
02468 }
02469 
02470 /*
02471 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02472 %                                                                             %
02473 %                                                                             %
02474 %                                                                             %
02475 %   G e t I m a g e G e o m e t r y                                           %
02476 %                                                                             %
02477 %                                                                             %
02478 %                                                                             %
02479 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02480 %
02481 %  GetImageGeometry() returns a region as defined by the geometry string with
02482 %  respect to the image and its gravity.
02483 %
02484 %  The format of the GetImageGeometry method is:
02485 %
02486 %      int GetImageGeometry(Image *image,const char *geometry,
02487 %        const unsigned int size_to_fit,RectangeInfo *region_info)
02488 %
02489 %  A description of each parameter follows:
02490 %
02491 %    o flags:  Method GetImageGeometry returns a bitmask that indicates
02492 %      which of the four values were located in the geometry string.
02493 %
02494 %    o geometry:  The geometry (e.g. 100x100+10+10).
02495 %
02496 %    o size_to_fit:  A value other than 0 means to scale the region so it
02497 %      fits within the specified width and height.
02498 %
02499 %    o region_info: the region as defined by the geometry string with
02500 %      respect to the image and its gravity.
02501 %
02502 */
02503 MagickExport int GetImageGeometry(Image *image,const char *geometry,
02504   const unsigned int size_to_fit,RectangleInfo *region_info)
02505 {
02506   if (image->debug != MagickFalse)
02507     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.4");
02508   if (size_to_fit != MagickFalse)
02509     return((int) ParseRegionGeometry(image,geometry,region_info,&image->exception));
02510   return((int) ParsePageGeometry(image,geometry,region_info,&image->exception));
02511 }
02512 
02513 /*
02514 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02515 %                                                                             %
02516 %                                                                             %
02517 %                                                                             %
02518 %   G e t I m a g e L i s t                                                   %
02519 %                                                                             %
02520 %                                                                             %
02521 %                                                                             %
02522 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02523 %
02524 %  GetImageList() returns an image at the specified position in the list.
02525 %
02526 %  The format of the GetImageList method is:
02527 %
02528 %      Image *GetImageList(const Image *images,const long offset,
02529 %        ExceptionInfo *exception)
02530 %
02531 %  A description of each parameter follows:
02532 %
02533 %    o images: the image list.
02534 %
02535 %    o offset: the position within the list.
02536 %
02537 %    o exception: return any errors or warnings in this structure.
02538 %
02539 */
02540 MagickExport Image *GetImageList(const Image *images,const long offset,
02541   ExceptionInfo *exception)
02542 {
02543   Image
02544     *image;
02545 
02546   if (images->debug != MagickFalse)
02547     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
02548   image=CloneImage(GetImageFromList(images,(long) offset),0,0,MagickTrue,
02549     exception);
02550   return(image);
02551 }
02552 
02553 /*
02554 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02555 %                                                                             %
02556 %                                                                             %
02557 %                                                                             %
02558 %   G e t I m a g e L i s t I n d e x                                         %
02559 %                                                                             %
02560 %                                                                             %
02561 %                                                                             %
02562 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02563 %
02564 %  GetImageListIndex() returns the position in the list of the specified
02565 %  image.
02566 %
02567 %  The format of the GetImageListIndex method is:
02568 %
02569 %      long GetImageListIndex(const Image *images)
02570 %
02571 %  A description of each parameter follows:
02572 %
02573 %    o images: the image list.
02574 %
02575 */
02576 MagickExport long GetImageListIndex(const Image *images)
02577 {
02578   if (images->debug != MagickFalse)
02579     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
02580   return(GetImageIndexInList(images));
02581 }
02582 
02583 /*
02584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02585 %                                                                             %
02586 %                                                                             %
02587 %                                                                             %
02588 %   G e t I m a g e L i s t S i z e                                           %
02589 %                                                                             %
02590 %                                                                             %
02591 %                                                                             %
02592 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02593 %
02594 %  GetImageListSize() returns the number of images in the list.
02595 %
02596 %  The format of the GetImageListSize method is:
02597 %
02598 %      unsigned long GetImageListSize(const Image *images)
02599 %
02600 %  A description of each parameter follows:
02601 %
02602 %    o images: the image list.
02603 %
02604 */
02605 MagickExport unsigned long GetImageListSize(const Image *images)
02606 {
02607   if (images->debug != MagickFalse)
02608     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
02609   return(GetImageListLength(images));
02610 }
02611 
02612 /*
02613 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02614 %                                                                             %
02615 %                                                                             %
02616 %                                                                             %
02617 %   G e t I m a g e P i x e l s                                               %
02618 %                                                                             %
02619 %                                                                             %
02620 %                                                                             %
02621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02622 %
02623 %  GetImagePixels() obtains a pixel region for read/write access. If the
02624 %  region is successfully accessed, a pointer to a PixelPacket array
02625 %  representing the region is returned, otherwise NULL is returned.
02626 %
02627 %  The returned pointer may point to a temporary working copy of the pixels
02628 %  or it may point to the original pixels in memory. Performance is maximized
02629 %  if the selected region is part of one row, or one or more full rows, since
02630 %  then there is opportunity to access the pixels in-place (without a copy)
02631 %  if the image is in RAM, or in a memory-mapped file. The returned pointer
02632 %  should *never* be deallocated by the user.
02633 %
02634 %  Pixels accessed via the returned pointer represent a simple array of type
02635 %  PixelPacket. If the image type is CMYK or if the storage class is
02636 %  PseduoClass, call GetAuthenticIndexQueue() after invoking GetImagePixels()
02637 %  to obtain the black color component or colormap indexes (of type IndexPacket)
02638 %  corresponding to the region.  Once the PixelPacket (and/or IndexPacket)
02639 %  array has been updated, the changes must be saved back to the underlying
02640 %  image using SyncAuthenticPixels() or they may be lost.
02641 %
02642 %  The format of the GetImagePixels() method is:
02643 %
02644 %      PixelPacket *GetImagePixels(Image *image,const long x,const long y,
02645 %        const unsigned long columns,const unsigned long rows)
02646 %
02647 %  A description of each parameter follows:
02648 %
02649 %    o image: the image.
02650 %
02651 %    o x,y,columns,rows:  These values define the perimeter of a region of
02652 %      pixels.
02653 %
02654 */
02655 MagickExport PixelPacket *GetImagePixels(Image *image,const long x,const long y,
02656   const unsigned long columns,const unsigned long rows)
02657 {
02658   return(GetAuthenticPixels(image,x,y,columns,rows,&image->exception));
02659 }
02660 
02661 /*
02662 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02663 %                                                                             %
02664 %                                                                             %
02665 %                                                                             %
02666 %   G e t I n d e x e s                                                       %
02667 %                                                                             %
02668 %                                                                             %
02669 %                                                                             %
02670 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02671 %
02672 %  GetIndexes() returns the black channel or the colormap indexes associated
02673 %  with the last call to QueueAuthenticPixels() or GetVirtualPixels().  NULL is
02674 %  returned if the black channel or colormap indexes are not available.
02675 %
02676 %  The format of the GetIndexes() method is:
02677 %
02678 %      IndexPacket *GetIndexes(const Image *image)
02679 %
02680 %  A description of each parameter follows:
02681 %
02682 %    o indexes: GetIndexes() returns the indexes associated with the last
02683 %      call to QueueAuthenticPixels() or GetAuthenticPixels().
02684 %
02685 %    o image: the image.
02686 %
02687 */
02688 MagickExport IndexPacket *GetIndexes(const Image *image)
02689 {
02690   return(GetAuthenticIndexQueue(image));
02691 }
02692 
02693 /*
02694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02695 %                                                                             %
02696 %                                                                             %
02697 %                                                                             %
02698 +   G e t M a g i c k G e o m e t r y                                         %
02699 %                                                                             %
02700 %                                                                             %
02701 %                                                                             %
02702 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02703 %
02704 %  GetMagickGeometry() is similar to GetGeometry() except the returned
02705 %  geometry is modified as determined by the meta characters:  %, !, <, >,
02706 %  and ~.
02707 %
02708 %  The format of the GetMagickGeometry method is:
02709 %
02710 %      unsigned int GetMagickGeometry(const char *geometry,long *x,long *y,
02711 %        unsigned long *width,unsigned long *height)
02712 %
02713 %  A description of each parameter follows:
02714 %
02715 %    o geometry:  Specifies a character string representing the geometry
02716 %      specification.
02717 %
02718 %    o x,y:  A pointer to an integer.  The x and y offset as determined by
02719 %      the geometry specification is returned here.
02720 %
02721 %    o width,height:  A pointer to an unsigned integer.  The width and height
02722 %      as determined by the geometry specification is returned here.
02723 %
02724 */
02725 MagickExport unsigned int GetMagickGeometry(const char *geometry,long *x,
02726   long *y,unsigned long *width,unsigned long *height)
02727 {
02728   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.3");
02729   return(ParseMetaGeometry(geometry,x,y,width,height));
02730 }
02731 
02732 /*
02733 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02734 %                                                                             %
02735 %                                                                             %
02736 %                                                                             %
02737 %   G e t N e x t I m a g e                                                   %
02738 %                                                                             %
02739 %                                                                             %
02740 %                                                                             %
02741 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02742 %
02743 %  GetNextImage() returns the next image in a list.
02744 %
02745 %  The format of the GetNextImage method is:
02746 %
02747 %      Image *GetNextImage(const Image *images)
02748 %
02749 %  A description of each parameter follows:
02750 %
02751 %    o images: the image list.
02752 %
02753 */
02754 MagickExport Image *GetNextImage(const Image *images)
02755 {
02756   if (images->debug != MagickFalse)
02757     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
02758   return(GetNextImageInList(images));
02759 }
02760 
02761 /*
02762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02763 %                                                                             %
02764 %                                                                             %
02765 %                                                                             %
02766 %   G e t N e x t I m a g e A t t r i b u t e                                 %
02767 %                                                                             %
02768 %                                                                             %
02769 %                                                                             %
02770 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02771 %
02772 %  GetNextImageAttribute() gets the next image attribute.
02773 %
02774 %  The format of the GetNextImageAttribute method is:
02775 %
02776 %      const ImageAttribute *GetNextImageAttribute(const Image *image)
02777 %
02778 %  A description of each parameter follows:
02779 %
02780 %    o image: the image.
02781 %
02782 */
02783 MagickExport const ImageAttribute *GetNextImageAttribute(const Image *image)
02784 {
02785   const char
02786     *property;
02787 
02788   property=GetNextImageProperty(image);
02789   if (property == (const char *) NULL)
02790     return((const ImageAttribute *) NULL);
02791   return(GetImageAttribute(image,property));
02792 }
02793 
02794 /*
02795 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02796 %                                                                             %
02797 %                                                                             %
02798 %                                                                             %
02799 %   G e t N u m b e r S c e n e s                                             %
02800 %                                                                             %
02801 %                                                                             %
02802 %                                                                             %
02803 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02804 %
02805 %  GetNumberScenes() returns the number of images in the list.
02806 %
02807 %  The format of the GetNumberScenes method is:
02808 %
02809 %      unsigned int GetNumberScenes(const Image *images)
02810 %
02811 %  A description of each parameter follows:
02812 %
02813 %    o images: the image list.
02814 %
02815 */
02816 MagickExport unsigned int GetNumberScenes(const Image *image)
02817 {
02818   if (image->debug != MagickFalse)
02819     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
02820   return((unsigned int) GetImageListLength(image));
02821 }
02822 
02823 /*
02824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02825 %                                                                             %
02826 %                                                                             %
02827 %                                                                             %
02828 %   G e t O n e P i x e l                                                     %
02829 %                                                                             %
02830 %                                                                             %
02831 %                                                                             %
02832 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02833 %
02834 %  GetOnePixel() returns a single pixel at the specified (x,y) location.
02835 %  The image background color is returned if an error occurs.
02836 %
02837 %  The format of the GetOnePixel() method is:
02838 %
02839 %      PixelPacket GetOnePixel(const Image image,const long x,const long y)
02840 %
02841 %  A description of each parameter follows:
02842 %
02843 %    o image: the image.
02844 %
02845 %    o x,y:  These values define the location of the pixel to return.
02846 %
02847 */
02848 MagickExport PixelPacket GetOnePixel(Image *image,const long x,const long y)
02849 {
02850   PixelPacket
02851     pixel;
02852 
02853   (void) GetOneAuthenticPixel(image,x,y,&pixel,&image->exception);
02854   return(pixel);
02855 }
02856 
02857 /*
02858 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02859 %                                                                             %
02860 %                                                                             %
02861 %                                                                             %
02862 %   G e t P i x e l s                                                         %
02863 %                                                                             %
02864 %                                                                             %
02865 %                                                                             %
02866 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02867 %
02868 %  GetPixels() returns the pixels associated with the last call to
02869 %  QueueAuthenticPixels() or GetAuthenticPixels().
02870 %
02871 %  The format of the GetPixels() method is:
02872 %
02873 %      PixelPacket *GetPixels(const Image image)
02874 %
02875 %  A description of each parameter follows:
02876 %
02877 %    o pixels: GetPixels() returns the pixels associated with the last call
02878 %      to QueueAuthenticPixels() or GetAuthenticPixels().
02879 %
02880 %    o image: the image.
02881 %
02882 */
02883 MagickExport PixelPacket *GetPixels(const Image *image)
02884 {
02885   return(GetAuthenticPixelQueue(image));
02886 }
02887 
02888 /*
02889 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02890 %                                                                             %
02891 %                                                                             %
02892 %                                                                             %
02893 %   G e t P r e v i o u s I m a g e                                           %
02894 %                                                                             %
02895 %                                                                             %
02896 %                                                                             %
02897 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02898 %
02899 %  GetPreviousImage() returns the previous image in a list.
02900 %
02901 %  The format of the GetPreviousImage method is:
02902 %
02903 %      Image *GetPreviousImage(const Image *images)
02904 %
02905 %  A description of each parameter follows:
02906 %
02907 %    o images: the image list.
02908 %
02909 */
02910 MagickExport Image *GetPreviousImage(const Image *images)
02911 {
02912   if (images->debug != MagickFalse)
02913     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
02914   return(GetPreviousImageInList(images));
02915 }
02916 
02917 /*
02918 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02919 %                                                                             %
02920 %                                                                             %
02921 %                                                                             %
02922 %   H S L T r a n s f o r m                                                   %
02923 %                                                                             %
02924 %                                                                             %
02925 %                                                                             %
02926 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02927 %
02928 %  HSLTransform() converts a (hue, saturation, lightness) to a (red, green,
02929 %  blue) triple.
02930 %
02931 %  The format of the HSLTransformImage method is:
02932 %
02933 %      void HSLTransform(const double hue,const double saturation,
02934 %        const double lightness,Quantum *red,Quantum *green,Quantum *blue)
02935 %
02936 %  A description of each parameter follows:
02937 %
02938 %    o hue, saturation, lightness: A double value representing a
02939 %      component of the HSL color space.
02940 %
02941 %    o red, green, blue: A pointer to a pixel component of type Quantum.
02942 %
02943 */
02944 
02945 static inline MagickRealType HueToRGB(MagickRealType m1,MagickRealType m2,
02946   MagickRealType hue)
02947 {
02948   if (hue < 0.0)
02949     hue+=1.0;
02950   if (hue > 1.0)
02951     hue-=1.0;
02952   if ((6.0*hue) < 1.0)
02953     return(m1+6.0*(m2-m1)*hue);
02954   if ((2.0*hue) < 1.0)
02955     return(m2);
02956   if ((3.0*hue) < 2.0)
02957     return(m1+6.0*(m2-m1)*(2.0/3.0-hue));
02958   return(m1);
02959 }
02960 
02961 MagickExport void HSLTransform(const double hue,const double saturation,
02962   const double lightness,Quantum *red,Quantum *green,Quantum *blue)
02963 {
02964   MagickRealType
02965     b,
02966     g,
02967     r,
02968     m1,
02969     m2;
02970 
02971   /*
02972     Convert HSL to RGB colorspace.
02973   */
02974   assert(red != (Quantum *) NULL);
02975   assert(green != (Quantum *) NULL);
02976   assert(blue != (Quantum *) NULL);
02977   if (lightness <= 0.5)
02978     m2=lightness*(saturation+1.0);
02979   else
02980     m2=lightness+saturation-lightness*saturation;
02981   m1=2.0*lightness-m2;
02982   r=HueToRGB(m1,m2,hue+1.0/3.0);
02983   g=HueToRGB(m1,m2,hue);
02984   b=HueToRGB(m1,m2,hue-1.0/3.0);
02985   *red=RoundToQuantum((MagickRealType) QuantumRange*r);
02986   *green=RoundToQuantum((MagickRealType) QuantumRange*g);
02987   *blue=RoundToQuantum((MagickRealType) QuantumRange*b);
02988 }
02989 
02990 /*
02991 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02992 %                                                                             %
02993 %                                                                             %
02994 %                                                                             %
02995 %   I d e n t i t y A f f i n e                                               %
02996 %                                                                             %
02997 %                                                                             %
02998 %                                                                             %
02999 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03000 %
03001 %  IdentityAffine() initializes the affine transform to the identity matrix.
03002 %
03003 %  The format of the IdentityAffine method is:
03004 %
03005 %      IdentityAffine(AffineMatrix *affine)
03006 %
03007 %  A description of each parameter follows:
03008 %
03009 %    o affine: A pointer the affine transform of type AffineMatrix.
03010 %
03011 */
03012 MagickExport void IdentityAffine(AffineMatrix *affine)
03013 {
03014   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
03015   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
03016   assert(affine != (AffineMatrix *) NULL);
03017   (void) ResetMagickMemory(affine,0,sizeof(AffineMatrix));
03018   affine->sx=1.0;
03019   affine->sy=1.0;
03020 }
03021 
03022 /*
03023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03024 %                                                                             %
03025 %                                                                             %
03026 %                                                                             %
03027 %   I n i t i a l i z e M a g i c k                                           %
03028 %                                                                             %
03029 %                                                                             %
03030 %                                                                             %
03031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03032 %
03033 %  InitializeMagick() initializes the ImageMagick environment.
03034 %
03035 %  The format of the InitializeMagick function is:
03036 %
03037 %      InitializeMagick(const char *path)
03038 %
03039 %  A description of each parameter follows:
03040 %
03041 %    o path: the execution path of the current ImageMagick client.
03042 %
03043 */
03044 MagickExport void InitializeMagick(const char *path)
03045 {
03046   MagickCoreGenesis(path,MagickFalse);
03047 }
03048 
03049 /*
03050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03051 %                                                                             %
03052 %                                                                             %
03053 %                                                                             %
03054 %   I n t e r p o l a t e P i x e l C o l o r                                 %
03055 %                                                                             %
03056 %                                                                             %
03057 %                                                                             %
03058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03059 %
03060 %  InterpolatePixelColor() applies bi-linear or tri-linear interpolation
03061 %  between a pixel and it's neighbors.
03062 %
03063 %  The format of the InterpolatePixelColor method is:
03064 %
03065 %      MagickPixelPacket InterpolatePixelColor(const Image *image,
03066 %        CacheView *view_info,InterpolatePixelMethod method,const double x,
03067 %        const double y,ExceptionInfo *exception)
03068 %
03069 %  A description of each parameter follows:
03070 %
03071 %    o image: the image.
03072 %
03073 %    o image_view: the image cache view.
03074 %
03075 %    o type:  the type of pixel color interpolation.
03076 %
03077 %    o x,y: A double representing the current (x,y) position of the pixel.
03078 %
03079 %    o exception: return any errors or warnings in this structure.
03080 %
03081 */
03082 
03083 static inline double MagickMax(const double x,const double y)
03084 {
03085   if (x > y)
03086     return(x);
03087   return(y);
03088 }
03089 
03090 static void BicubicInterpolate(const MagickPixelPacket *pixels,const double dx,
03091   MagickPixelPacket *pixel)
03092 {
03093   MagickRealType
03094     dx2,
03095     p,
03096     q,
03097     r,
03098     s;
03099 
03100   dx2=dx*dx;
03101   p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red);
03102   q=(pixels[0].red-pixels[1].red)-p;
03103   r=pixels[2].red-pixels[0].red;
03104   s=pixels[1].red;
03105   pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
03106   p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green);
03107   q=(pixels[0].green-pixels[1].green)-p;
03108   r=pixels[2].green-pixels[0].green;
03109   s=pixels[1].green;
03110   pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
03111   p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue);
03112   q=(pixels[0].blue-pixels[1].blue)-p;
03113   r=pixels[2].blue-pixels[0].blue;
03114   s=pixels[1].blue;
03115   pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
03116   p=(pixels[3].opacity-pixels[2].opacity)-(pixels[0].opacity-pixels[1].opacity);
03117   q=(pixels[0].opacity-pixels[1].opacity)-p;
03118   r=pixels[2].opacity-pixels[0].opacity;
03119   s=pixels[1].opacity;
03120   pixel->opacity=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
03121   if (pixel->colorspace == CMYKColorspace)
03122     {
03123       p=(pixels[3].index-pixels[2].index)-(pixels[0].index-pixels[1].index);
03124       q=(pixels[0].index-pixels[1].index)-p;
03125       r=pixels[2].index-pixels[0].index;
03126       s=pixels[1].index;
03127       pixel->index=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
03128     }
03129 }
03130 
03131 static inline MagickRealType CubicWeightingFunction(const MagickRealType x)
03132 {
03133   MagickRealType
03134     alpha,
03135     gamma;
03136 
03137   alpha=MagickMax(x+2.0,0.0);
03138   gamma=1.0*alpha*alpha*alpha;
03139   alpha=MagickMax(x+1.0,0.0);
03140   gamma-=4.0*alpha*alpha*alpha;
03141   alpha=MagickMax(x+0.0,0.0);
03142   gamma+=6.0*alpha*alpha*alpha;
03143   alpha=MagickMax(x-1.0,0.0);
03144   gamma-=4.0*alpha*alpha*alpha;
03145   return(gamma/6.0);
03146 }
03147 
03148 static inline double MeshInterpolate(const PointInfo *delta,const double p,
03149   const double x,const double y)
03150 {
03151   return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
03152 }
03153 
03154 static inline long NearestNeighbor(MagickRealType x)
03155 {
03156   if (x >= 0.0)
03157     return((long) (x+0.5));
03158   return((long) (x-0.5));
03159 }
03160 
03161 MagickExport MagickPixelPacket InterpolatePixelColor(const Image *image,
03162   CacheView *image_view,const InterpolatePixelMethod method,const double x,
03163   const double y,ExceptionInfo *exception)
03164 {
03165   MagickPixelPacket
03166     pixel;
03167 
03168   register const IndexPacket
03169     *indexes;
03170 
03171   register const PixelPacket
03172     *p;
03173 
03174   register long
03175     i;
03176 
03177   assert(image != (Image *) NULL);
03178   assert(image->signature == MagickSignature);
03179   assert(image_view != (CacheView *) NULL);
03180   GetMagickPixelPacket(image,&pixel);
03181   switch (method)
03182   {
03183     case AverageInterpolatePixel:
03184     {
03185       MagickPixelPacket
03186         pixels[16];
03187 
03188       MagickRealType
03189         alpha[16],
03190         gamma;
03191 
03192       p=GetCacheViewVirtualPixels(image_view,(long) floor(x)-1,(long) floor(y)-
03193         1,4,4,exception);
03194       if (p == (const PixelPacket *) NULL)
03195         break;
03196       indexes=GetCacheViewVirtualIndexQueue(image_view);
03197       for (i=0; i < 16L; i++)
03198       {
03199         GetMagickPixelPacket(image,pixels+i);
03200         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
03201         alpha[i]=1.0;
03202         if (image->matte != MagickFalse)
03203           {
03204             alpha[i]=QuantumScale*((MagickRealType) QuantumRange-p->opacity);
03205             pixels[i].red*=alpha[i];
03206             pixels[i].green*=alpha[i];
03207             pixels[i].blue*=alpha[i];
03208             if (image->colorspace == CMYKColorspace)
03209               pixels[i].index*=alpha[i];
03210           }
03211         gamma=alpha[i];
03212         gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
03213         pixel.red+=gamma*0.0625*pixels[i].red;
03214         pixel.green+=gamma*0.0625*pixels[i].green;
03215         pixel.blue+=gamma*0.0625*pixels[i].blue;
03216         pixel.opacity+=0.0625*pixels[i].opacity;
03217         if (image->colorspace == CMYKColorspace)
03218           pixel.index+=gamma*0.0625*pixels[i].index;
03219         p++;
03220       }
03221       break;
03222     }
03223     case BicubicInterpolatePixel:
03224     {
03225       MagickPixelPacket
03226         pixels[16],
03227         u[4];
03228 
03229       MagickRealType
03230         alpha[16];
03231 
03232       PointInfo
03233         delta;
03234 
03235       p=GetCacheViewVirtualPixels(image_view,(long) floor(x)-1,(long) floor(y)-
03236         1,4,4,exception);
03237       if (p == (const PixelPacket *) NULL)
03238         break;
03239       indexes=GetCacheViewVirtualIndexQueue(image_view);
03240       for (i=0; i < 16L; i++)
03241       {
03242         GetMagickPixelPacket(image,pixels+i);
03243         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
03244         alpha[i]=1.0;
03245         if (image->matte != MagickFalse)
03246           {
03247             alpha[i]=QuantumScale*((MagickRealType) QuantumRange-p->opacity);
03248             pixels[i].red*=alpha[i];
03249             pixels[i].green*=alpha[i];
03250             pixels[i].blue*=alpha[i];
03251             if (image->colorspace == CMYKColorspace)
03252               pixels[i].index*=alpha[i];
03253           }
03254         p++;
03255       }
03256       delta.x=x-floor(x);
03257       for (i=0; i < 4L; i++)
03258         BicubicInterpolate(pixels+4*i,delta.x,u+i);
03259       delta.y=y-floor(y);
03260       BicubicInterpolate(u,delta.y,&pixel);
03261       break;
03262     }
03263     case BilinearInterpolatePixel:
03264     default:
03265     {
03266       MagickPixelPacket
03267         pixels[16];
03268 
03269       MagickRealType
03270         alpha[16],
03271         gamma;
03272 
03273       PointInfo
03274         delta;
03275 
03276       p=GetCacheViewVirtualPixels(image_view,(long) floor(x),(long) floor(y),2,
03277         2,exception);
03278       if (p == (const PixelPacket *) NULL)
03279         break;
03280       indexes=GetCacheViewVirtualIndexQueue(image_view);
03281       for (i=0; i < 4L; i++)
03282       {
03283         GetMagickPixelPacket(image,pixels+i);
03284         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
03285         alpha[i]=1.0;
03286         if (image->matte != MagickFalse)
03287           {
03288             alpha[i]=QuantumScale*((MagickRealType) QuantumRange-p->opacity);
03289             pixels[i].red*=alpha[i];
03290             pixels[i].green*=alpha[i];
03291             pixels[i].blue*=alpha[i];
03292             if (image->colorspace == CMYKColorspace)
03293               pixels[i].index*=alpha[i];
03294           }
03295         p++;
03296       }
03297       delta.x=x-floor(x);
03298       delta.y=y-floor(y);
03299       gamma=(((1.0-delta.y)*((1.0-delta.x)*alpha[0]+delta.x*alpha[1])+delta.y*
03300         ((1.0-delta.x)*alpha[2]+delta.x*alpha[3])));
03301       gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
03302       pixel.red=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].red+delta.x*
03303         pixels[1].red)+delta.y*((1.0-delta.x)*pixels[2].red+delta.x*
03304         pixels[3].red));
03305       pixel.green=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].green+delta.x*
03306         pixels[1].green)+delta.y*((1.0-delta.x)*pixels[2].green+
03307         delta.x*pixels[3].green));
03308       pixel.blue=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].blue+delta.x*
03309         pixels[1].blue)+delta.y*((1.0-delta.x)*pixels[2].blue+delta.x*
03310         pixels[3].blue));
03311       pixel.opacity=((1.0-delta.y)*((1.0-delta.x)*pixels[0].opacity+delta.x*
03312         pixels[1].opacity)+delta.y*((1.0-delta.x)*pixels[2].opacity+delta.x*
03313         pixels[3].opacity));
03314       if (image->colorspace == CMYKColorspace)
03315         pixel.index=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].index+delta.x*
03316           pixels[1].index)+delta.y*((1.0-delta.x)*pixels[2].index+delta.x*
03317           pixels[3].index));
03318       break;
03319     }
03320     case FilterInterpolatePixel:
03321     {
03322       Image
03323         *excerpt_image,
03324         *filter_image;
03325 
03326       MagickPixelPacket
03327         pixels[1];
03328 
03329       RectangleInfo
03330         geometry;
03331 
03332       geometry.width=4L;
03333       geometry.height=4L;
03334       geometry.x=(long) floor(x)-1L;
03335       geometry.y=(long) floor(y)-1L;
03336       excerpt_image=ExcerptImage(image,&geometry,exception);
03337       if (excerpt_image == (Image *) NULL)
03338         break;
03339       filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
03340         exception);
03341       excerpt_image=DestroyImage(excerpt_image);
03342       if (filter_image == (Image *) NULL)
03343         break;
03344       p=GetVirtualPixels(filter_image,0,0,1,1,exception);
03345       if (p == (const PixelPacket *) NULL)
03346         {
03347           filter_image=DestroyImage(filter_image);
03348           break;
03349         }
03350       indexes=GetVirtualIndexQueue(filter_image);
03351       GetMagickPixelPacket(image,pixels);
03352       SetMagickPixelPacket(image,p,indexes,&pixel);
03353       filter_image=DestroyImage(filter_image);
03354       break;
03355     }
03356     case IntegerInterpolatePixel:
03357     {
03358       MagickPixelPacket
03359         pixels[1];
03360 
03361       p=GetCacheViewVirtualPixels(image_view,(long) floor(x),(long) floor(y),1,
03362         1,exception);
03363       if (p == (const PixelPacket *) NULL)
03364         break;
03365       indexes=GetCacheViewVirtualIndexQueue(image_view);
03366       GetMagickPixelPacket(image,pixels);
03367       SetMagickPixelPacket(image,p,indexes,&pixel);
03368       break;
03369     }
03370     case MeshInterpolatePixel:
03371     {
03372       MagickPixelPacket
03373         pixels[4];
03374 
03375       MagickRealType
03376         alpha[4],
03377         gamma;
03378 
03379       PointInfo
03380         delta,
03381         luminance;
03382 
03383       p=GetCacheViewVirtualPixels(image_view,(long) floor(x),(long) floor(y),
03384         2,2,exception);
03385       if (p == (const PixelPacket *) NULL)
03386         break;
03387       indexes=GetCacheViewVirtualIndexQueue(image_view);
03388       for (i=0; i < 4L; i++)
03389       {
03390         GetMagickPixelPacket(image,pixels+i);
03391         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
03392         alpha[i]=1.0;
03393         if (image->matte != MagickFalse)
03394           {
03395             alpha[i]=QuantumScale*((MagickRealType) QuantumRange-p->opacity);
03396             pixels[i].red*=alpha[i];
03397             pixels[i].green*=alpha[i];
03398             pixels[i].blue*=alpha[i];
03399             if (image->colorspace == CMYKColorspace)
03400               pixels[i].index*=alpha[i];
03401           }
03402         p++;
03403       }
03404       delta.x=x-floor(x);
03405       delta.y=y-floor(y);
03406       luminance.x=MagickPixelLuminance(pixels+0)-MagickPixelLuminance(pixels+3);
03407       luminance.y=MagickPixelLuminance(pixels+1)-MagickPixelLuminance(pixels+2);
03408       if (fabs(luminance.x) < fabs(luminance.y))
03409         {
03410           /*
03411             Diagonal 0-3 NW-SE.
03412           */
03413           if (delta.x <= delta.y)
03414             {
03415               /*
03416                 Bottom-left triangle  (pixel:2, diagonal: 0-3).
03417               */
03418               delta.y=1.0-delta.y;
03419               gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
03420               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
03421               pixel.red=gamma*MeshInterpolate(&delta,pixels[2].red,
03422                 pixels[3].red,pixels[0].red);
03423               pixel.green=gamma*MeshInterpolate(&delta,pixels[2].green,
03424                 pixels[3].green,pixels[0].green);
03425               pixel.blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
03426                 pixels[3].blue,pixels[0].blue);
03427               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[2].opacity,
03428                 pixels[3].opacity,pixels[0].opacity);
03429               if (image->colorspace == CMYKColorspace)
03430                 pixel.index=gamma*MeshInterpolate(&delta,pixels[2].index,
03431                   pixels[3].index,pixels[0].index);
03432             }
03433           else
03434             {
03435               /*
03436                 Top-right triangle (pixel:1, diagonal: 0-3).
03437               */
03438               delta.x=1.0-delta.x;
03439               gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
03440               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
03441               pixel.red=gamma*MeshInterpolate(&delta,pixels[1].red,
03442                 pixels[0].red,pixels[3].red);
03443               pixel.green=gamma*MeshInterpolate(&delta,pixels[1].green,
03444                 pixels[0].green,pixels[3].green);
03445               pixel.blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
03446                 pixels[0].blue,pixels[3].blue);
03447               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[1].opacity,
03448                 pixels[0].opacity,pixels[3].opacity);
03449               if (image->colorspace == CMYKColorspace)
03450                 pixel.index=gamma*MeshInterpolate(&delta,pixels[1].index,
03451                   pixels[0].index,pixels[3].index);
03452             }
03453         }
03454       else
03455         {
03456           /*
03457             Diagonal 1-2 NE-SW.
03458           */
03459           if (delta.x <= (1.0-delta.y))
03460             {
03461               /*
03462                 Top-left triangle (pixel 0, diagonal: 1-2).
03463               */
03464               gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
03465               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
03466               pixel.red=gamma*MeshInterpolate(&delta,pixels[0].red,
03467                 pixels[1].red,pixels[2].red);
03468               pixel.green=gamma*MeshInterpolate(&delta,pixels[0].green,
03469                 pixels[1].green,pixels[2].green);
03470               pixel.blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
03471                 pixels[1].blue,pixels[2].blue);
03472               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[0].opacity,
03473                 pixels[1].opacity,pixels[2].opacity);
03474               if (image->colorspace == CMYKColorspace)
03475                 pixel.index=gamma*MeshInterpolate(&delta,pixels[0].index,
03476                   pixels[1].index,pixels[2].index);
03477             }
03478           else
03479             {
03480               /*
03481                 Bottom-right triangle (pixel: 3, diagonal: 1-2).
03482               */
03483               delta.x=1.0-delta.x;
03484               delta.y=1.0-delta.y;
03485               gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
03486               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
03487               pixel.red=gamma*MeshInterpolate(&delta,pixels[3].red,
03488                 pixels[2].red,pixels[1].red);
03489               pixel.green=gamma*MeshInterpolate(&delta,pixels[3].green,
03490                 pixels[2].green,pixels[1].green);
03491               pixel.blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
03492                 pixels[2].blue,pixels[1].blue);
03493               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[3].opacity,
03494                 pixels[2].opacity,pixels[1].opacity);
03495               if (image->colorspace == CMYKColorspace)
03496                 pixel.index=gamma*MeshInterpolate(&delta,pixels[3].index,
03497                   pixels[2].index,pixels[1].index);
03498             }
03499         }
03500       break;
03501     }
03502     case NearestNeighborInterpolatePixel:
03503     {
03504       MagickPixelPacket
03505         pixels[1];
03506 
03507       p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
03508         NearestNeighbor(y),1,1,exception);
03509       if (p == (const PixelPacket *) NULL)
03510         break;
03511       indexes=GetCacheViewVirtualIndexQueue(image_view);
03512       GetMagickPixelPacket(image,pixels);
03513       SetMagickPixelPacket(image,p,indexes,&pixel);
03514       break;
03515     }
03516     case SplineInterpolatePixel:
03517     {
03518       long
03519         j,
03520         n;
03521 
03522       MagickPixelPacket
03523         pixels[16];
03524 
03525       MagickRealType
03526         alpha[16],
03527         dx,
03528         dy,
03529         gamma;
03530 
03531       PointInfo
03532         delta;
03533 
03534       p=GetCacheViewVirtualPixels(image_view,(long) floor(x)-1,(long) floor(y)-
03535         1,4,4,exception);
03536       if (p == (const PixelPacket *) NULL)
03537         break;
03538       indexes=GetCacheViewVirtualIndexQueue(image_view);
03539       n=0;
03540       delta.x=x-floor(x);
03541       delta.y=y-floor(y);
03542       for (i=(-1); i < 3L; i++)
03543       {
03544         dy=CubicWeightingFunction((MagickRealType) i-delta.y);
03545         for (j=(-1); j < 3L; j++)
03546         {
03547           GetMagickPixelPacket(image,pixels+n);
03548           SetMagickPixelPacket(image,p,indexes+n,pixels+n);
03549           alpha[n]=1.0;
03550           if (image->matte != MagickFalse)
03551             {
03552               alpha[n]=QuantumScale*((MagickRealType) QuantumRange-p->opacity);
03553               pixels[n].red*=alpha[n];
03554               pixels[n].green*=alpha[n];
03555               pixels[n].blue*=alpha[n];
03556               if (image->colorspace == CMYKColorspace)
03557                 pixels[n].index*=alpha[n];
03558             }
03559           dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
03560           gamma=alpha[n];
03561           gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
03562           pixel.red+=gamma*dx*dy*pixels[n].red;
03563           pixel.green+=gamma*dx*dy*pixels[n].green;
03564           pixel.blue+=gamma*dx*dy*pixels[n].blue;
03565           if (image->matte != MagickFalse)
03566             pixel.opacity+=dx*dy*pixels[n].opacity;
03567           if (image->colorspace == CMYKColorspace)
03568             pixel.index+=gamma*dx*dy*pixels[n].index;
03569           n++;
03570           p++;
03571         }
03572       }
03573       break;
03574     }
03575   }
03576   return(pixel);
03577 }
03578 
03579 /*
03580 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03581 %                                                                             %
03582 %                                                                             %
03583 %                                                                             %
03584 %   I n t e r p r e t I m a g e A t t r i b u t e s                           %
03585 %                                                                             %
03586 %                                                                             %
03587 %                                                                             %
03588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03589 %
03590 %  InterpretImageAttributes() replaces any embedded formatting characters with
03591 %  the appropriate image attribute and returns the translated text.
03592 %
03593 %  The format of the InterpretImageAttributes method is:
03594 %
03595 %      char *InterpretImageAttributes(const ImageInfo *image_info,Image *image,
03596 %        const char *embed_text)
03597 %
03598 %  A description of each parameter follows:
03599 %
03600 %    o image_info: the image info.
03601 %
03602 %    o image: the image.
03603 %
03604 %    o embed_text: the address of a character string containing the embedded
03605 %      formatting characters.
03606 %
03607 */
03608 MagickExport char *InterpretImageAttributes(const ImageInfo *image_info,
03609   Image *image,const char *embed_text)
03610 {
03611   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.3.1");
03612   return(InterpretImageProperties(image_info,image,embed_text));
03613 }
03614 
03615 /*
03616 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03617 %                                                                             %
03618 %                                                                             %
03619 %                                                                             %
03620 +     I s S u b i m a g e                                                     %
03621 %                                                                             %
03622 %                                                                             %
03623 %                                                                             %
03624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03625 %
03626 %  IsSubimage() returns MagickTrue if the geometry is a valid subimage
03627 %  specification (e.g. [1], [1-9], [1,7,4]).
03628 %
03629 %  The format of the IsSubimage method is:
03630 %
03631 %      unsigned int IsSubimage(const char *geometry,const unsigned int pedantic)
03632 %
03633 %  A description of each parameter follows:
03634 %
03635 %    o geometry: This string is the geometry specification.
03636 %
03637 %    o pedantic: A value other than 0 invokes a more restrictive set of
03638 %      conditions for a valid specification (e.g. [1], [1-4], [4-1]).
03639 %
03640 */
03641 MagickExport unsigned int IsSubimage(const char *geometry,
03642   const unsigned int pedantic)
03643 {
03644   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
03645   if (geometry == (const char *) NULL)
03646     return(MagickFalse);
03647   if ((strchr(geometry,'x') != (char *) NULL) ||
03648       (strchr(geometry,'X') != (char *) NULL))
03649     return(MagickFalse);
03650   if ((pedantic != MagickFalse) && (strchr(geometry,',') != (char *) NULL))
03651     return(MagickFalse);
03652   return(MagickTrue);
03653 }
03654 
03655 /*
03656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03657 %                                                                             %
03658 %                                                                             %
03659 %                                                                             %
03660 %     L e v e l I m a g e C o l o r s                                         %
03661 %                                                                             %
03662 %                                                                             %
03663 %                                                                             %
03664 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03665 %
03666 %  LevelImageColor() will map the given color to "black" and "white"
03667 %  values, limearly spreading out the colors, and level values on a channel by
03668 %  channel bases, as per LevelImage().  The given colors allows you to specify
03669 %  different level ranges for each of the color channels seperatally.
03670 %
03671 %  If the boolean 'invert' is set true the image values will modifyed in the
03672 %  reverse direction. That is any existing "black" and "white" colors in the
03673 %  image will become the color values given, with all other values compressed
03674 %  appropriatally.  This effectivally maps a greyscale gradient into the given
03675 %  color gradient.
03676 %
03677 %  The format of the LevelImageColors method is:
03678 %
03679 %  MagickBooleanType LevelImageColors(Image *image,const ChannelType channel,
03680 %    const MagickPixelPacket *black_color,const MagickPixelPacket *white_color,
03681 %    const MagickBooleanType invert)
03682 %
03683 %  A description of each parameter follows:
03684 %
03685 %    o image: the image.
03686 %
03687 %    o channel: the channel.
03688 %
03689 %    o black_color: The color to map black to/from
03690 %
03691 %    o white_point: The color to map white to/from
03692 %
03693 %    o invert: if true map the colors (levelize), rather than from (level)
03694 %
03695 */
03696 MagickBooleanType LevelImageColors(Image *image,const ChannelType channel,
03697   const MagickPixelPacket *black_color,const MagickPixelPacket *white_color,
03698   const MagickBooleanType invert)
03699 {
03700   return(LevelColorsImageChannel(image,channel,black_color,white_color,invert));
03701 }
03702 
03703 /*
03704 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03705 %                                                                             %
03706 %                                                                             %
03707 %                                                                             %
03708 %   L i b e r a t e M e m o r y                                               %
03709 %                                                                             %
03710 %                                                                             %
03711 %                                                                             %
03712 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03713 %
03714 %  LiberateMemory() frees memory that has already been allocated, and NULL's
03715 %  the pointer to it.
03716 %
03717 %  The format of the LiberateMemory method is:
03718 %
03719 %      void LiberateMemory(void **memory)
03720 %
03721 %  A description of each parameter follows:
03722 %
03723 %    o memory: A pointer to a block of memory to free for reuse.
03724 %
03725 */
03726 MagickExport void LiberateMemory(void **memory)
03727 {
03728   assert(memory != (void **) NULL);
03729   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
03730   if (*memory == (void *) NULL)
03731     return;
03732   free(*memory);
03733   *memory=(void *) NULL;
03734 }
03735 
03736 /*
03737 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03738 %                                                                             %
03739 %                                                                             %
03740 %                                                                             %
03741 %   L i b e r a t e S e m a p h o r e I n f o                                 %
03742 %                                                                             %
03743 %                                                                             %
03744 %                                                                             %
03745 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03746 %
03747 %  LiberateSemaphoreInfo() relinquishes a semaphore.
03748 %
03749 %  The format of the LiberateSemaphoreInfo method is:
03750 %
03751 %      LiberateSemaphoreInfo(void **semaphore_info)
03752 %
03753 %  A description of each parameter follows:
03754 %
03755 %    o semaphore_info: Specifies a pointer to an SemaphoreInfo structure.
03756 %
03757 */
03758 MagickExport void LiberateSemaphoreInfo(SemaphoreInfo **semaphore_info)
03759 {
03760   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
03761   (void) UnlockSemaphoreInfo(*semaphore_info);
03762 }
03763 
03764 /*
03765 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03766 %                                                                             %
03767 %                                                                             %
03768 %                                                                             %
03769 %   M a g i c k I n c a r n a t e                                             %
03770 %                                                                             %
03771 %                                                                             %
03772 %                                                                             %
03773 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03774 %
03775 %  MagickIncarnate() initializes the ImageMagick environment.
03776 %
03777 %  The format of the MagickIncarnate function is:
03778 %
03779 %      MagickIncarnate(const char *path)
03780 %
03781 %  A description of each parameter follows:
03782 %
03783 %    o path: the execution path of the current ImageMagick client.
03784 %
03785 */
03786 
03787 MagickExport void MagickIncarnate(const char *path)
03788 {
03789   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1");
03790   MagickCoreGenesis(path,MagickFalse);
03791 }
03792 
03793 /*
03794 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03795 %                                                                             %
03796 %                                                                             %
03797 %                                                                             %
03798 %   M a g i c k M o n i t o r                                                 %
03799 %                                                                             %
03800 %                                                                             %
03801 %                                                                             %
03802 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03803 %
03804 %  MagickMonitor() calls the monitor handler method with a text string that
03805 %  describes the task and a measure of completion.  The method returns
03806 %  MagickTrue on success otherwise MagickFalse if an error is encountered, e.g.
03807 %  if there was a user interrupt.
03808 %
03809 %  The format of the MagickMonitor method is:
03810 %
03811 %      MagickBooleanType MagickMonitor(const char *text,
03812 %        const MagickOffsetType offset,const MagickSizeType span,
03813 %        void *client_data)
03814 %
03815 %  A description of each parameter follows:
03816 %
03817 %    o offset: the position relative to the span parameter which represents
03818 %      how much progress has been made toward completing a task.
03819 %
03820 %    o span: the span relative to completing a task.
03821 %
03822 %    o client_data: the client data.
03823 %
03824 */
03825 MagickExport MagickBooleanType MagickMonitor(const char *text,
03826   const MagickOffsetType offset,const MagickSizeType span,
03827   void *magick_unused(client_data))
03828 {
03829   ExceptionInfo
03830     *exception;
03831 
03832   MagickBooleanType
03833     status;
03834 
03835   assert(text != (const char *) NULL);
03836   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",text);
03837   ProcessPendingEvents(text);
03838   status=MagickTrue;
03839   exception=AcquireExceptionInfo();
03840   if (monitor_handler != (MonitorHandler) NULL)
03841     status=(*monitor_handler)(text,offset,span,exception);
03842   exception=DestroyExceptionInfo(exception);
03843   return(status);
03844 }
03845 
03846 /*
03847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03848 %                                                                             %
03849 %                                                                             %
03850 %                                                                             %
03851 %   M a p I m a g e                                                           %
03852 %                                                                             %
03853 %                                                                             %
03854 %                                                                             %
03855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03856 %
03857 %  MapImage() replaces the colors of an image with the closest color from a
03858 %  reference image.
03859 %
03860 %  The format of the MapImage method is:
03861 %
03862 %      MagickBooleanType MapImage(Image *image,const Image *map_image,
03863 %        const MagickBooleanType dither)
03864 %
03865 %  A description of each parameter follows:
03866 %
03867 %    o image: Specifies a pointer to an Image structure.
03868 %
03869 %    o map_image: the image.  Reduce image to a set of colors represented by
03870 %      this image.
03871 %
03872 %    o dither: Set this integer value to something other than zero to
03873 %      dither the mapped image.
03874 %
03875 */
03876 MagickExport MagickBooleanType MapImage(Image *image,const Image *map_image,
03877   const MagickBooleanType dither)
03878 {
03879   QuantizeInfo
03880     quantize_info;
03881 
03882   /*
03883     Initialize color cube.
03884   */
03885   assert(image != (Image *) NULL);
03886   assert(image->signature == MagickSignature);
03887   if (image->debug != MagickFalse)
03888     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
03889   assert(map_image != (Image *) NULL);
03890   assert(map_image->signature == MagickSignature);
03891   GetQuantizeInfo(&quantize_info);
03892   quantize_info.dither=dither;
03893   return(RemapImage(&quantize_info,image,map_image));
03894 }
03895 
03896 /*
03897 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03898 %                                                                             %
03899 %                                                                             %
03900 %                                                                             %
03901 %   M a p I m a g e s                                                         %
03902 %                                                                             %
03903 %                                                                             %
03904 %                                                                             %
03905 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03906 %
03907 %  MapImages() replaces the colors of a sequence of images with the closest
03908 %  color from a reference image.
03909 %
03910 %  The format of the MapImage method is:
03911 %
03912 %      MagickBooleanType MapImages(Image *images,Image *map_image,
03913 %        const MagickBooleanType dither)
03914 %
03915 %  A description of each parameter follows:
03916 %
03917 %    o image: Specifies a pointer to a set of Image structures.
03918 %
03919 %    o map_image: the image.  Reduce image to a set of colors represented by
03920 %      this image.
03921 %
03922 %    o dither: Set this integer value to something other than zero to
03923 %      dither the quantized image.
03924 %
03925 */
03926 MagickExport MagickBooleanType MapImages(Image *images,const Image *map_image,
03927   const MagickBooleanType dither)
03928 {
03929   QuantizeInfo
03930     quantize_info;
03931 
03932   assert(images != (Image *) NULL);
03933   assert(images->signature == MagickSignature);
03934   if (images->debug != MagickFalse)
03935     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
03936   GetQuantizeInfo(&quantize_info);
03937   quantize_info.dither=dither;
03938   return(RemapImages(&quantize_info,images,map_image));
03939 }
03940 
03941 /*
03942 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03943 %                                                                             %
03944 %                                                                             %
03945 %                                                                             %
03946 %   M a t t e F l o o d f i l l I m a g e                                     %
03947 %                                                                             %
03948 %                                                                             %
03949 %                                                                             %
03950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03951 %
03952 %  MatteFloodfill() changes the transparency value of any pixel that matches
03953 %  target and is an immediate neighbor.  If the method FillToBorderMethod
03954 %  is specified, the transparency value is changed for any neighbor pixel
03955 %  that does not match the bordercolor member of image.
03956 %
03957 %  By default target must match a particular pixel transparency exactly.
03958 %  However, in many cases two transparency values may differ by a
03959 %  small amount.  The fuzz member of image defines how much tolerance is
03960 %  acceptable to consider two transparency values as the same.  For example,
03961 %  set fuzz to 10 and the opacity values of 100 and 102 respectively are
03962 %  now interpreted as the same value for the purposes of the floodfill.
03963 %
03964 %  The format of the MatteFloodfillImage method is:
03965 %
03966 %      MagickBooleanType MatteFloodfillImage(Image *image,
03967 %        const PixelPacket target,const Quantum opacity,const long x_offset,
03968 %        const long y_offset,const PaintMethod method)
03969 %
03970 %  A description of each parameter follows:
03971 %
03972 %    o image: the image.
03973 %
03974 %    o target: the RGB value of the target color.
03975 %
03976 %    o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
03977 %      fully transparent.
03978 %
03979 %    o x,y: the starting location of the operation.
03980 %
03981 %    o method:  Choose either FloodfillMethod or FillToBorderMethod.
03982 %
03983 */
03984 MagickExport MagickBooleanType MatteFloodfillImage(Image *image,
03985   const PixelPacket target,const Quantum opacity,const long x_offset,
03986   const long y_offset,const PaintMethod method)
03987 {
03988   Image
03989     *floodplane_image;
03990 
03991   long
03992     offset,
03993     start,
03994     x,
03995     x1,
03996     x2,
03997     y;
03998 
03999   MagickBooleanType
04000     skip;
04001 
04002   register SegmentInfo
04003     *s;
04004 
04005   SegmentInfo
04006     *segment_stack;
04007 
04008   /*
04009     Check boundary conditions.
04010   */
04011   assert(image != (Image *) NULL);
04012   assert(image->signature == MagickSignature);
04013   if (image->debug != MagickFalse)
04014     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
04015   if ((x_offset < 0) || (x_offset >= (long) image->columns))
04016     return(MagickFalse);
04017   if ((y_offset < 0) || (y_offset >= (long) image->rows))
04018     return(MagickFalse);
04019   if (SetImageStorageClass(image,DirectClass) == MagickFalse)
04020     return(MagickFalse);
04021   if (image->matte == MagickFalse)
04022     (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
04023   floodplane_image=CloneImage(image,image->columns,image->rows,MagickTrue,
04024     &image->exception);
04025   if (floodplane_image == (Image *) NULL)
04026     return(MagickFalse);
04027   (void) SetImageAlphaChannel(floodplane_image,OpaqueAlphaChannel);
04028   /*
04029     Set floodfill color.
04030   */
04031   segment_stack=(SegmentInfo *) AcquireQuantumMemory(MaxStacksize,
04032     sizeof(*segment_stack));
04033   if (segment_stack == (SegmentInfo *) NULL)
04034     {
04035       floodplane_image=DestroyImage(floodplane_image);
04036       ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
04037         image->filename);
04038     }
04039   /*
04040     Push initial segment on stack.
04041   */
04042   x=x_offset;
04043   y=y_offset;
04044   start=0;
04045   s=segment_stack;
04046   PushSegmentStack(y,x,x,1);
04047   PushSegmentStack(y+1,x,x,-1);
04048   while (s > segment_stack)
04049   {
04050     register const PixelPacket
04051       *__restrict p;
04052 
04053     register long
04054       x;
04055 
04056     register PixelPacket
04057       *__restrict q;
04058 
04059     /*
04060       Pop segment off stack.
04061     */
04062     s--;
04063     x1=(long) s->x1;
04064     x2=(long) s->x2;
04065     offset=(long) s->y2;
04066     y=(long) s->y1+offset;
04067     /*
04068       Recolor neighboring pixels.
04069     */
04070     p=GetVirtualPixels(image,0,y,(unsigned long) (x1+1),1,&image->exception);
04071     q=GetAuthenticPixels(floodplane_image,0,y,(unsigned long) (x1+1),1,
04072       &image->exception);
04073     if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
04074       break;
04075     p+=x1;
04076     q+=x1;
04077     for (x=x1; x >= 0; x--)
04078     {
04079       if (q->opacity == (Quantum) TransparentOpacity)
04080         break;
04081       if (method == FloodfillMethod)
04082         {
04083           if (IsColorSimilar(image,p,&target) == MagickFalse)
04084             break;
04085         }
04086       else
04087         if (IsColorSimilar(image,p,&target) != MagickFalse)
04088           break;
04089       q->opacity=(Quantum) TransparentOpacity;
04090       q--;
04091       p--;
04092     }
04093     if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse)
04094       break;
04095     skip=x >= x1 ? MagickTrue : MagickFalse;
04096     if (skip == MagickFalse)
04097       {
04098         start=x+1;
04099         if (start < x1)
04100           PushSegmentStack(y,start,x1-1,-offset);
04101         x=x1+1;
04102       }
04103     do
04104     {
04105       if (skip == MagickFalse)
04106         {
04107           if (x < (long) image->columns)
04108             {
04109               p=GetVirtualPixels(image,x,y,image->columns-x,1,
04110                 &image->exception);
04111               q=GetAuthenticPixels(floodplane_image,x,y,image->columns-x,1,
04112                 &image->exception);
04113               if ((p == (const PixelPacket *) NULL) ||
04114                   (q == (PixelPacket *) NULL))
04115                 break;
04116               for ( ; x < (long) image->columns; x++)
04117               {
04118                 if (q->opacity == (Quantum) TransparentOpacity)
04119                   break;
04120                 if (method == FloodfillMethod)
04121                   {
04122                     if (IsColorSimilar(image,p,&target) == MagickFalse)
04123                       break;
04124                   }
04125                 else
04126                   if (IsColorSimilar(image,p,&target) != MagickFalse)
04127                     break;
04128                 q->opacity=(Quantum) TransparentOpacity;
04129                 q++;
04130                 p++;
04131               }
04132               if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse)
04133                 break;
04134             }
04135           PushSegmentStack(y,start,x-1,offset);
04136           if (x > (x2+1))
04137             PushSegmentStack(y,x2+1,x-1,-offset);
04138         }
04139       skip=MagickFalse;
04140       x++;
04141       if (x <= x2)
04142         {
04143           p=GetVirtualPixels(image,x,y,(unsigned long) (x2-x+1),1,
04144             &image->exception);
04145           q=GetAuthenticPixels(floodplane_image,x,y,(unsigned long) (x2-x+1),1,
04146             &image->exception);
04147           if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
04148             break;
04149           for ( ; x <= x2; x++)
04150           {
04151             if (q->opacity == (Quantum) TransparentOpacity)
04152               break;
04153             if (method == FloodfillMethod)
04154               {
04155                 if (IsColorSimilar(image,p,&target) != MagickFalse)
04156                   break;
04157               }
04158             else
04159               if (IsColorSimilar(image,p,&target) == MagickFalse)
04160                 break;
04161             p++;
04162             q++;
04163           }
04164         }
04165       start=x;
04166     } while (x <= x2);
04167   }
04168   for (y=0; y < (long) image->rows; y++)
04169   {
04170     register const PixelPacket
04171       *__restrict p;
04172 
04173     register long
04174       x;
04175 
04176     register PixelPacket
04177       *__restrict q;
04178 
04179     /*
04180       Tile fill color onto floodplane.
04181     */
04182     p=GetVirtualPixels(floodplane_image,0,y,image->columns,1,
04183       &image->exception);
04184     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
04185     if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
04186       break;
04187     for (x=0; x < (long) image->columns; x++)
04188     {
04189       if (p->opacity != OpaqueOpacity)
04190         q->opacity=opacity;
04191       p++;
04192       q++;
04193     }
04194     if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
04195       break;
04196   }
04197   segment_stack=(SegmentInfo *) RelinquishMagickMemory(segment_stack);
04198   floodplane_image=DestroyImage(floodplane_image);
04199   return(y == (long) image->rows ? MagickTrue : MagickFalse);
04200 }
04201 
04202 /*
04203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04204 %                                                                             %
04205 %                                                                             %
04206 %                                                                             %
04207 %     M o s a i c I m a g e s                                                 %
04208 %                                                                             %
04209 %                                                                             %
04210 %                                                                             %
04211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04212 %
04213 %  MosaicImages() Obsolete Function: Use MergeImageLayers() instead.
04214 %
04215 %  The format of the MosaicImage method is:
04216 %
04217 %      Image *MosaicImages(const Image *image,ExceptionInfo *exception)
04218 %
04219 %  A description of each parameter follows:
04220 %
04221 %    o image: the image list to be composited together
04222 %
04223 %    o exception: return any errors or warnings in this structure.
04224 %
04225 */
04226 MagickExport Image *MosaicImages(Image *image,ExceptionInfo *exception)
04227 {
04228   return(MergeImageLayers(image,MosaicLayer,exception));
04229 }
04230 
04231 /*
04232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04233 %                                                                             %
04234 %                                                                             %
04235 %                                                                             %
04236 %     O p a q u e I m a g e                                                   %
04237 %                                                                             %
04238 %                                                                             %
04239 %                                                                             %
04240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04241 %
04242 %  OpaqueImage() changes any pixel that matches color with the color
04243 %  defined by fill.
04244 %
04245 %  By default color must match a particular pixel color exactly.  However,
04246 %  in many cases two colors may differ by a small amount.  Fuzz defines
04247 %  how much tolerance is acceptable to consider two colors as the same.
04248 %  For example, set fuzz to 10 and the color red at intensities of 100 and
04249 %  102 respectively are now interpreted as the same color.
04250 %
04251 %  The format of the OpaqueImage method is:
04252 %
04253 %      MagickBooleanType OpaqueImage(Image *image,
04254 %        const PixelPacket *target,const PixelPacket fill)
04255 %
04256 %  A description of each parameter follows:
04257 %
04258 %    o image: the image.
04259 %
04260 %    o target: the RGB value of the target color.
04261 %
04262 %    o fill: the replacement color.
04263 %
04264 */
04265 MagickExport MagickBooleanType OpaqueImage(Image *image,
04266   const PixelPacket target,const PixelPacket fill)
04267 {
04268 #define OpaqueImageTag  "Opaque/Image"
04269 
04270   long
04271     y;
04272 
04273   MagickBooleanType
04274     proceed;
04275 
04276   register long
04277     i;
04278 
04279   /*
04280     Make image color opaque.
04281   */
04282   assert(image != (Image *) NULL);
04283   assert(image->signature == MagickSignature);
04284   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.1.0");
04285   if (image->debug != MagickFalse)
04286     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
04287   switch (image->storage_class)
04288   {
04289     case DirectClass:
04290     default:
04291     {
04292       /*
04293         Make DirectClass image opaque.
04294       */
04295       for (y=0; y < (long) image->rows; y++)
04296       {
04297         register long
04298           x;
04299 
04300         register PixelPacket
04301           *__restrict q;
04302 
04303         q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
04304         if (q == (PixelPacket *) NULL)
04305           break;
04306         for (x=0; x < (long) image->columns; x++)
04307         {
04308           if (IsColorSimilar(image,q,&target) != MagickFalse)
04309             *q=fill;
04310           q++;
04311         }
04312         if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
04313           break;
04314         proceed=SetImageProgress(image,OpaqueImageTag,y,image->rows);
04315         if (proceed == MagickFalse)
04316           break;
04317       }
04318       break;
04319     }
04320     case PseudoClass:
04321     {
04322       /*
04323         Make PseudoClass image opaque.
04324       */
04325       for (i=0; i < (long) image->colors; i++)
04326       {
04327         if (IsColorSimilar(image,&image->colormap[i],&target) != MagickFalse)
04328           image->colormap[i]=fill;
04329       }
04330       if (fill.opacity != OpaqueOpacity)
04331         {
04332           for (y=0; y < (long) image->rows; y++)
04333           {
04334             register long
04335               x;
04336 
04337             register PixelPacket
04338               *__restrict q;
04339 
04340             q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);