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-2010 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/colorspace.h"
00053 #include "magick/composite.h"
00054 #include "magick/composite-private.h"
00055 #include "magick/constitute.h"
00056 #include "magick/deprecate.h"
00057 #include "magick/draw.h"
00058 #include "magick/draw-private.h"
00059 #include "magick/effect.h"
00060 #include "magick/exception.h"
00061 #include "magick/exception-private.h"
00062 #include "magick/geometry.h"
00063 #include "magick/identify.h"
00064 #include "magick/image.h"
00065 #include "magick/image-private.h"
00066 #include "magick/list.h"
00067 #include "magick/log.h"
00068 #include "magick/memory_.h"
00069 #include "magick/magick.h"
00070 #include "magick/monitor.h"
00071 #include "magick/monitor-private.h"
00072 #include "magick/paint.h"
00073 #include "magick/pixel.h"
00074 #include "magick/pixel-private.h"
00075 #include "magick/quantize.h"
00076 #include "magick/random_.h"
00077 #include "magick/resource_.h"
00078 #include "magick/semaphore.h"
00079 #include "magick/segment.h"
00080 #include "magick/splay-tree.h"
00081 #include "magick/string_.h"
00082 #include "magick/threshold.h"
00083 #include "magick/transform.h"
00084 #include "magick/utility.h"
00085 
00086 #if !defined(MAGICKCORE_EXCLUDE_DEPRECATED)
00087 /*
00088   Global declarations.
00089 */
00090 static MonitorHandler
00091   monitor_handler = (MonitorHandler) NULL;
00092 
00093 /*
00094 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00095 %                                                                             %
00096 %                                                                             %
00097 %                                                                             %
00098 %   A c q u i r e C a c h e V i e w I n d e x e s                             %
00099 %                                                                             %
00100 %                                                                             %
00101 %                                                                             %
00102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00103 %
00104 %  AcquireCacheViewIndexes() returns the indexes associated with the specified
00105 %  view.
00106 %
00107 %  The format of the AcquireCacheViewIndexes method is:
00108 %
00109 %      const IndexPacket *AcquireCacheViewIndexes(const ViewInfo *cache_view)
00110 %
00111 %  A description of each parameter follows:
00112 %
00113 %    o cache_view: the cache view.
00114 %
00115 */
00116 MagickExport const IndexPacket *AcquireCacheViewIndexes(
00117   const ViewInfo *cache_view)
00118 {
00119   return(GetCacheViewVirtualIndexQueue(cache_view));
00120 }
00121 
00122 /*
00123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00124 %                                                                             %
00125 %                                                                             %
00126 %                                                                             %
00127 %   A c q u i r e C a c h e V i e w P i x e l s                               %
00128 %                                                                             %
00129 %                                                                             %
00130 %                                                                             %
00131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00132 %
00133 %  AcquireCacheViewPixels() gets pixels from the in-memory or disk pixel cache
00134 %  as defined by the geometry parameters.   A pointer to the pixels is returned
00135 %  if the pixels are transferred, otherwise a NULL is returned.
00136 %
00137 %  The format of the AcquireCacheViewPixels method is:
00138 %
00139 %      const PixelPacket *AcquireCacheViewPixels(const ViewInfo *cache_view,
00140 %        const long x,const long y,const unsigned long columns,
00141 %        const unsigned long rows,ExceptionInfo *exception)
00142 %
00143 %  A description of each parameter follows:
00144 %
00145 %    o cache_view: the cache view.
00146 %
00147 %    o x,y,columns,rows:  These values define the perimeter of a region of
00148 %      pixels.
00149 %
00150 %    o exception: return any errors or warnings in this structure.
00151 %
00152 */
00153 MagickExport const PixelPacket *AcquireCacheViewPixels(
00154   const ViewInfo *cache_view,const long x,const long y,
00155   const unsigned long columns,const unsigned long rows,ExceptionInfo *exception)
00156 {
00157   return(GetCacheViewVirtualPixels(cache_view,x,y,columns,rows,exception));
00158 }
00159 
00160 /*
00161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00162 %                                                                             %
00163 %                                                                             %
00164 %                                                                             %
00165 %   A c q u i r e I m a g e P i x e l s                                        %
00166 %                                                                             %
00167 %                                                                             %
00168 %                                                                             %
00169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00170 %
00171 %  AcquireImagePixels() returns an immutable pixel region. If the
00172 %  region is successfully accessed, a pointer to it is returned, otherwise
00173 %  NULL is returned. The returned pointer may point to a temporary working
00174 %  copy of the pixels or it may point to the original pixels in memory.
00175 %  Performance is maximized if the selected region is part of one row, or one
00176 %  or more full rows, since there is opportunity to access the pixels in-place
00177 %  (without a copy) if the image is in RAM, or in a memory-mapped file.  The
00178 %  returned pointer should *never* be deallocated by the user.
00179 %
00180 %  Pixels accessed via the returned pointer represent a simple array of type
00181 %  PixelPacket.  If the image type is CMYK or the storage class is PseudoClass,
00182 %  call GetAuthenticIndexQueue() after invoking GetAuthenticPixels() to access the
00183 %  black color component or to obtain the colormap indexes (of type IndexPacket)
00184 %  corresponding to the region.
00185 %
00186 %  If you plan to modify the pixels, use GetAuthenticPixels() instead.
00187 %
00188 %  Note, the AcquireImagePixels() and GetAuthenticPixels() methods are not
00189 %  thread-safe.  In a threaded environment, use GetCacheViewVirtualPixels() or
00190 %  GetCacheViewAuthenticPixels() instead.
00191 %
00192 %  The format of the AcquireImagePixels() method is:
00193 %
00194 %      const PixelPacket *AcquireImagePixels(const Image *image,const long x,
00195 %        const long y,const unsigned long columns,const unsigned long rows,
00196 %        ExceptionInfo *exception)
00197 %
00198 %  A description of each parameter follows:
00199 %
00200 %    o image: the image.
00201 %
00202 %    o x,y,columns,rows:  These values define the perimeter of a region of
00203 %      pixels.
00204 %
00205 %    o exception: return any errors or warnings in this structure.
00206 %
00207 */
00208 MagickExport const PixelPacket *AcquireImagePixels(const Image *image,
00209   const long x,const long y,const unsigned long columns,
00210   const unsigned long rows,ExceptionInfo *exception)
00211 {
00212   return(GetVirtualPixels(image,x,y,columns,rows,exception));
00213 }
00214 
00215 /*
00216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00217 %                                                                             %
00218 %                                                                             %
00219 %                                                                             %
00220 %   A c q u i r e I n d e x e s                                               %
00221 %                                                                             %
00222 %                                                                             %
00223 %                                                                             %
00224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00225 %
00226 %  AcquireIndexes() returns the black channel or the colormap indexes
00227 %  associated with the last call to QueueAuthenticPixels() or GetVirtualPixels().
00228 %  NULL is returned if the black channel or colormap indexes are not available.
00229 %
00230 %  The format of the AcquireIndexes() method is:
00231 %
00232 %      const IndexPacket *AcquireIndexes(const Image *image)
00233 %
00234 %  A description of each parameter follows:
00235 %
00236 %    o indexes: AcquireIndexes() returns the indexes associated with the last
00237 %      call to QueueAuthenticPixels() or GetVirtualPixels().
00238 %
00239 %    o image: the image.
00240 %
00241 */
00242 MagickExport const IndexPacket *AcquireIndexes(const Image *image)
00243 {
00244   return(GetVirtualIndexQueue(image));
00245 }
00246 
00247 /*
00248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00249 %                                                                             %
00250 %                                                                             %
00251 %                                                                             %
00252 %   A c q u i r e M e m o r y                                                 %
00253 %                                                                             %
00254 %                                                                             %
00255 %                                                                             %
00256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00257 %
00258 %  AcquireMemory() returns a pointer to a block of memory at least size bytes
00259 %  suitably aligned for any use.
00260 %
00261 %  The format of the AcquireMemory method is:
00262 %
00263 %      void *AcquireMemory(const size_t size)
00264 %
00265 %  A description of each parameter follows:
00266 %
00267 %    o size: the size of the memory in bytes to allocate.
00268 %
00269 */
00270 MagickExport void *AcquireMemory(const size_t size)
00271 {
00272   void
00273     *allocation;
00274 
00275   assert(size != 0);
00276   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
00277   allocation=malloc(size);
00278   return(allocation);
00279 }
00280 
00281 /*
00282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00283 %                                                                             %
00284 %                                                                             %
00285 %                                                                             %
00286 %   A c q u i r e O n e C a c h e V i e w P i x e l                           %
00287 %                                                                             %
00288 %                                                                             %
00289 %                                                                             %
00290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00291 %
00292 %  AcquireOneCacheViewPixel() returns a single pixel at the specified (x,y)
00293 %  location.  The image background color is returned if an error occurs.  If
00294 %  you plan to modify the pixel, use GetOneCacheViewAuthenticPixel() instead.
00295 %
00296 %  The format of the AcquireOneCacheViewPixel method is:
00297 %
00298 %      MagickBooleanType AcquireOneCacheViewPixel(const ViewInfo *cache_view,
00299 %        const long x,const long y,PixelPacket *pixel,ExceptionInfo *exception)
00300 %
00301 %  A description of each parameter follows:
00302 %
00303 %    o cache_view: the cache view.
00304 %
00305 %    o x,y:  These values define the offset of the pixel.
00306 %
00307 %    o pixel: return a pixel at the specified (x,y) location.
00308 %
00309 %    o exception: return any errors or warnings in this structure.
00310 %
00311 */
00312 MagickExport MagickBooleanType AcquireOneCacheViewPixel(
00313   const ViewInfo *cache_view,const long x,const long y,PixelPacket *pixel,
00314   ExceptionInfo *exception)
00315 {
00316   return(GetOneCacheViewVirtualPixel(cache_view,x,y,pixel,exception));
00317 }
00318 
00319 /*
00320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00321 %                                                                             %
00322 %                                                                             %
00323 %                                                                             %
00324 %   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             %
00325 %                                                                             %
00326 %                                                                             %
00327 %                                                                             %
00328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00329 %
00330 %  AcquireOneCacheViewVirtualPixel() returns a single pixel at the specified
00331 %  (x,y) location.  The image background color is returned if an error occurs.
00332 %  If you plan to modify the pixel, use GetOneCacheViewAuthenticPixel() instead.
00333 %
00334 %  The format of the AcquireOneCacheViewPixel method is:
00335 %
00336 %      MagickBooleanType AcquireOneCacheViewVirtualPixel(
00337 %        const ViewInfo *cache_view,
00338 %        const VirtualPixelMethod virtual_pixel_method,const long x,
00339 %        const long y,PixelPacket *pixel,ExceptionInfo *exception)
00340 %
00341 %  A description of each parameter follows:
00342 %
00343 %    o cache_view: the cache view.
00344 %
00345 %    o virtual_pixel_method: the virtual pixel method.
00346 %
00347 %    o x,y:  These values define the offset of the pixel.
00348 %
00349 %    o pixel: return a pixel at the specified (x,y) location.
00350 %
00351 %    o exception: return any errors or warnings in this structure.
00352 %
00353 */
00354 MagickExport MagickBooleanType AcquireOneCacheViewVirtualPixel(
00355   const ViewInfo *cache_view,const VirtualPixelMethod virtual_pixel_method,
00356   const long x,const long y,PixelPacket *pixel,ExceptionInfo *exception)
00357 {
00358   MagickBooleanType
00359     status;
00360 
00361   status=GetOneCacheViewVirtualMethodPixel(cache_view,virtual_pixel_method,
00362     x,y,pixel,exception);
00363   return(status);
00364 }
00365 
00366 /*
00367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00368 %                                                                             %
00369 %                                                                             %
00370 %                                                                             %
00371 %   A c q u i r e O n e M a g i c k P i x e l                                 %
00372 %                                                                             %
00373 %                                                                             %
00374 %                                                                             %
00375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00376 %
00377 %  AcquireOneMagickPixel() returns a single pixel at the specified (x,y)
00378 %  location.  The image background color is returned if an error occurs.  If
00379 %  you plan to modify the pixel, use GetOnePixel() instead.
00380 %
00381 %  The format of the AcquireOneMagickPixel() method is:
00382 %
00383 %      MagickPixelPacket AcquireOneMagickPixel(const Image image,const long x,
00384 %        const long y,ExceptionInfo exception)
00385 %
00386 %  A description of each parameter follows:
00387 %
00388 %    o image: the image.
00389 %
00390 %    o x,y:  These values define the location of the pixel to return.
00391 %
00392 %    o exception: return any errors or warnings in this structure.
00393 %
00394 */
00395 MagickExport MagickPixelPacket AcquireOneMagickPixel(const Image *image,
00396   const long x,const long y,ExceptionInfo *exception)
00397 {
00398   MagickPixelPacket
00399     pixel;
00400 
00401   (void) GetOneVirtualMagickPixel(image,x,y,&pixel,exception);
00402   return(pixel);
00403 }
00404 
00405 /*
00406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00407 %                                                                             %
00408 %                                                                             %
00409 %                                                                             %
00410 %   A c q u i r e O n e P i x e l                                             %
00411 %                                                                             %
00412 %                                                                             %
00413 %                                                                             %
00414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00415 %
00416 %  AcquireOnePixel() returns a single pixel at the specified (x,y) location.
00417 %  The image background color is returned if an error occurs.  If you plan to
00418 %  modify the pixel, use GetOnePixel() instead.
00419 %
00420 %  The format of the AcquireOnePixel() method is:
00421 %
00422 %      PixelPacket AcquireOnePixel(const Image image,const long x,
00423 %        const long y,ExceptionInfo exception)
00424 %
00425 %  A description of each parameter follows:
00426 %
00427 %    o image: the image.
00428 %
00429 %    o x,y:  These values define the location of the pixel to return.
00430 %
00431 %    o exception: return any errors or warnings in this structure.
00432 %
00433 */
00434 MagickExport PixelPacket AcquireOnePixel(const Image *image,const long x,
00435   const long y,ExceptionInfo *exception)
00436 {
00437   PixelPacket
00438     pixel;
00439 
00440   (void) GetOneVirtualPixel(image,x,y,&pixel,exception);
00441   return(pixel);
00442 }
00443 
00444 /*
00445 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00446 %                                                                             %
00447 %                                                                             %
00448 %                                                                             %
00449 %   A c q u i r e O n e V i r t u a l P i x e l                               %
00450 %                                                                             %
00451 %                                                                             %
00452 %                                                                             %
00453 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00454 %
00455 %  AcquireOneVirtualPixel() returns a single pixel at the specified (x,y)
00456 %  location as defined by specified pixel method.  The image background color
00457 %  is returned if an error occurs.  If you plan to modify the pixel, use
00458 %  GetOnePixel() instead.
00459 %
00460 %  The format of the AcquireOneVirtualPixel() method is:
00461 %
00462 %      PixelPacket AcquireOneVirtualPixel(const Image image,
00463 %        const VirtualPixelMethod virtual_pixel_method,const long x,
00464 %        const long y,ExceptionInfo exception)
00465 %
00466 %  A description of each parameter follows:
00467 %
00468 %    o virtual_pixel_method: the virtual pixel method.
00469 %
00470 %    o image: the image.
00471 %
00472 %    o x,y:  These values define the location of the pixel to return.
00473 %
00474 %    o exception: return any errors or warnings in this structure.
00475 %
00476 */
00477 MagickExport PixelPacket AcquireOneVirtualPixel(const Image *image,
00478   const VirtualPixelMethod virtual_pixel_method,const long x,const long y,
00479   ExceptionInfo *exception)
00480 {
00481   PixelPacket
00482     pixel;
00483 
00484   (void) GetOneVirtualMethodPixel(image,virtual_pixel_method,x,y,&pixel,
00485     exception);
00486   return(pixel);
00487 }
00488 
00489 /*
00490 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00491 %                                                                             %
00492 %                                                                             %
00493 %                                                                             %
00494 %   A c q u i r e P i x e l s                                                 %
00495 %                                                                             %
00496 %                                                                             %
00497 %                                                                             %
00498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00499 %
00500 %  AcquirePixels() returns the pixels associated with the last call to
00501 %  QueueAuthenticPixels() or GetVirtualPixels().
00502 %
00503 %  The format of the AcquirePixels() method is:
00504 %
00505 %      const PixelPacket *AcquirePixels(const Image image)
00506 %
00507 %  A description of each parameter follows:
00508 %
00509 %    o image: the image.
00510 %
00511 */
00512 MagickExport const PixelPacket *AcquirePixels(const Image *image)
00513 {
00514   return(GetVirtualPixelQueue(image));
00515 }
00516 
00517 /*
00518 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00519 %                                                                             %
00520 %                                                                             %
00521 %                                                                             %
00522 %   A f f i n i t y I m a g e                                                 %
00523 %                                                                             %
00524 %                                                                             %
00525 %                                                                             %
00526 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00527 %
00528 %  AffinityImage() replaces the colors of an image with the closest color from
00529 %  a reference image.
00530 %
00531 %  The format of the AffinityImage method is:
00532 %
00533 %      MagickBooleanType AffinityImage(const QuantizeInfo *quantize_info,
00534 %        Image *image,const Image *affinity_image)
00535 %
00536 %  A description of each parameter follows:
00537 %
00538 %    o quantize_info: Specifies a pointer to an QuantizeInfo structure.
00539 %
00540 %    o image: the image.
00541 %
00542 %    o affinity_image: the reference image.
00543 %
00544 */
00545 MagickExport MagickBooleanType AffinityImage(const QuantizeInfo *quantize_info,
00546   Image *image,const Image *affinity_image)
00547 {
00548   return(RemapImage(quantize_info,image,affinity_image));
00549 }
00550 
00551 /*
00552 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00553 %                                                                             %
00554 %                                                                             %
00555 %                                                                             %
00556 %   A f f i n i t y I m a g e s                                               %
00557 %                                                                             %
00558 %                                                                             %
00559 %                                                                             %
00560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00561 %
00562 %  AffinityImages() replaces the colors of a sequence of images with the
00563 %  closest color from a reference image.
00564 %
00565 %  The format of the AffinityImage method is:
00566 %
00567 %      MagickBooleanType AffinityImages(const QuantizeInfo *quantize_info,
00568 %        Image *images,Image *affinity_image)
00569 %
00570 %  A description of each parameter follows:
00571 %
00572 %    o quantize_info: Specifies a pointer to an QuantizeInfo structure.
00573 %
00574 %    o images: the image sequence.
00575 %
00576 %    o affinity_image: the reference image.
00577 %
00578 */
00579 MagickExport MagickBooleanType AffinityImages(const QuantizeInfo *quantize_info,
00580   Image *images,const Image *affinity_image)
00581 {
00582   return(RemapImages(quantize_info,images,affinity_image));
00583 }
00584 
00585 /*
00586 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00587 %                                                                             %
00588 %                                                                             %
00589 %                                                                             %
00590 %   A l l o c a t e I m a g e                                                 %
00591 %                                                                             %
00592 %                                                                             %
00593 %                                                                             %
00594 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00595 %
00596 %  AllocateImage() returns a pointer to an image structure initialized to
00597 %  default values.
00598 %
00599 %  The format of the AllocateImage method is:
00600 %
00601 %      Image *AllocateImage(const ImageInfo *image_info)
00602 %
00603 %  A description of each parameter follows:
00604 %
00605 %    o image_info: Many of the image default values are set from this
00606 %      structure.  For example, filename, compression, depth, background color,
00607 %      and others.
00608 %
00609 */
00610 MagickExport Image *AllocateImage(const ImageInfo *image_info)
00611 {
00612   return(AcquireImage(image_info));
00613 }
00614 
00615 /*
00616 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00617 %                                                                             %
00618 %                                                                             %
00619 %                                                                             %
00620 %   A l l o c a t e I m a g e C o l o r m a p                                 %
00621 %                                                                             %
00622 %                                                                             %
00623 %                                                                             %
00624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00625 %
00626 %  AllocateImageColormap() allocates an image colormap and initializes
00627 %  it to a linear gray colorspace.  If the image already has a colormap,
00628 %  it is replaced.  AllocateImageColormap() returns MagickTrue if successful,
00629 %  otherwise MagickFalse if there is not enough memory.
00630 %
00631 %  The format of the AllocateImageColormap method is:
00632 %
00633 %      MagickBooleanType AllocateImageColormap(Image *image,
00634 %        const unsigned long colors)
00635 %
00636 %  A description of each parameter follows:
00637 %
00638 %    o image: the image.
00639 %
00640 %    o colors: the number of colors in the image colormap.
00641 %
00642 */
00643 MagickExport MagickBooleanType AllocateImageColormap(Image *image,
00644   const unsigned long colors)
00645 {
00646   return(AcquireImageColormap(image,colors));
00647 }
00648 
00649 /*
00650 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00651 %                                                                             %
00652 %                                                                             %
00653 %                                                                             %
00654 %   A l l o c a t e N e x t I m a g e                                         %
00655 %                                                                             %
00656 %                                                                             %
00657 %                                                                             %
00658 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00659 %
00660 %  AllocateNextImage() initializes the next image in a sequence to
00661 %  default values.  The next member of image points to the newly allocated
00662 %  image.  If there is a memory shortage, next is assigned NULL.
00663 %
00664 %  The format of the AllocateNextImage method is:
00665 %
00666 %      void AllocateNextImage(const ImageInfo *image_info,Image *image)
00667 %
00668 %  A description of each parameter follows:
00669 %
00670 %    o image_info: Many of the image default values are set from this
00671 %      structure.  For example, filename, compression, depth, background color,
00672 %      and others.
00673 %
00674 %    o image: the image.
00675 %
00676 */
00677 MagickExport void AllocateNextImage(const ImageInfo *image_info,Image *image)
00678 {
00679   AcquireNextImage(image_info,image);
00680 }
00681 
00682 /*
00683 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00684 %                                                                             %
00685 %                                                                             %
00686 %                                                                             %
00687 %   A c q u i r e S t r i n g                                                 %
00688 %                                                                             %
00689 %                                                                             %
00690 %                                                                             %
00691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00692 %
00693 %  AllocateString() allocates memory for a string and copies the source string
00694 %  to that memory location (and returns it).
00695 %
00696 %  The format of the AllocateString method is:
00697 %
00698 %      char *AllocateString(const char *source)
00699 %
00700 %  A description of each parameter follows:
00701 %
00702 %    o source: A character string.
00703 %
00704 */
00705 MagickExport char *AllocateString(const char *source)
00706 {
00707   char
00708     *destination;
00709 
00710   size_t
00711     length;
00712 
00713   assert(source != (const char *) NULL);
00714   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
00715   length=strlen(source)+MaxTextExtent+1;
00716   destination=(char *) AcquireQuantumMemory(length,sizeof(*destination));
00717   if (destination == (char *) NULL)
00718     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
00719   *destination='\0';
00720   if (source != (char *) NULL)
00721     (void) CopyMagickString(destination,source,length);
00722   return(destination);
00723 }
00724 
00725 /*
00726 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00727 %                                                                             %
00728 %                                                                             %
00729 %                                                                             %
00730 %     C h a n n e l I m a g e                                                 %
00731 %                                                                             %
00732 %                                                                             %
00733 %                                                                             %
00734 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00735 %
00736 %  Extract a channel from the image.  A channel is a particular color component
00737 %  of each pixel in the image.
00738 %
00739 %  The format of the ChannelImage method is:
00740 %
00741 %      unsigned int ChannelImage(Image *image,const ChannelType channel)
00742 %
00743 %  A description of each parameter follows:
00744 %
00745 %    o image: the image.
00746 %
00747 %    o channel: Identify which channel to extract: RedChannel, GreenChannel,
00748 %      BlueChannel, OpacityChannel, CyanChannel, MagentaChannel, YellowChannel,
00749 %      or BlackChannel.
00750 %
00751 */
00752 MagickExport unsigned int ChannelImage(Image *image,const ChannelType channel)
00753 {
00754   return(SeparateImageChannel(image,channel));
00755 }
00756 
00757 /*
00758 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00759 %                                                                             %
00760 %                                                                             %
00761 %                                                                             %
00762 %     C h a n n e l T h r e s h o l d I m a g e                               %
00763 %                                                                             %
00764 %                                                                             %
00765 %                                                                             %
00766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00767 %
00768 %  ChannelThresholdImage() changes the value of individual pixels based on
00769 %  the intensity of each pixel channel.  The result is a high-contrast image.
00770 %
00771 %  The format of the ChannelThresholdImage method is:
00772 %
00773 %      unsigned int ChannelThresholdImage(Image *image,const char *level)
00774 %
00775 %  A description of each parameter follows:
00776 %
00777 %    o image: the image.
00778 %
00779 %    o level: define the threshold values.
00780 %
00781 */
00782 MagickExport unsigned int ChannelThresholdImage(Image *image,const char *level)
00783 {
00784   MagickPixelPacket
00785     threshold;
00786 
00787   GeometryInfo
00788     geometry_info;
00789 
00790   unsigned int
00791     flags,
00792     status;
00793 
00794   assert(image != (Image *) NULL);
00795   assert(image->signature == MagickSignature);
00796   if (image->debug != MagickFalse)
00797     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00798   if (image->debug != MagickFalse)
00799     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
00800   if (level == (char *) NULL)
00801     return(MagickFalse);
00802   flags=ParseGeometry(level,&geometry_info);
00803   threshold.red=geometry_info.rho;
00804   threshold.green=geometry_info.sigma;
00805   if ((flags & SigmaValue) == 0)
00806     threshold.green=threshold.red;
00807   threshold.blue=geometry_info.xi;
00808   if ((flags & XiValue) == 0)
00809     threshold.blue=threshold.red;
00810   status=BilevelImageChannel(image,RedChannel,threshold.red);
00811   status|=BilevelImageChannel(image,GreenChannel,threshold.green);
00812   status|=BilevelImageChannel(image,BlueChannel,threshold.blue);
00813   return(status);
00814 }
00815 
00816 /*
00817 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00818 %                                                                             %
00819 %                                                                             %
00820 %                                                                             %
00821 %   C l i p I m a g e P a t h                                                 %
00822 %                                                                             %
00823 %                                                                             %
00824 %                                                                             %
00825 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00826 %
00827 %  ClipPathImage() sets the image clip mask based any clipping path information
00828 %  if it exists.
00829 %
00830 %  The format of the ClipImage method is:
00831 %
00832 %      MagickBooleanType ClipPathImage(Image *image,const char *pathname,
00833 %        const MagickBooleanType inside)
00834 %
00835 %  A description of each parameter follows:
00836 %
00837 %    o image: the image.
00838 %
00839 %    o pathname: name of clipping path resource. If name is preceded by #, use
00840 %      clipping path numbered by name.
00841 %
00842 %    o inside: if non-zero, later operations take effect inside clipping path.
00843 %      Otherwise later operations take effect outside clipping path.
00844 %
00845 */
00846 MagickExport MagickBooleanType ClipPathImage(Image *image,const char *pathname,
00847   const MagickBooleanType inside)
00848 {
00849   return(ClipImagePath(image,pathname,inside));
00850 }
00851 
00852 /*
00853 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00854 %                                                                             %
00855 %                                                                             %
00856 %                                                                             %
00857 %   C l o n e I m a g e A t t r i b u t e s                                   %
00858 %                                                                             %
00859 %                                                                             %
00860 %                                                                             %
00861 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00862 %
00863 %  CloneImageAttributes() clones one or more image attributes.
00864 %
00865 %  The format of the CloneImageAttributes method is:
00866 %
00867 %      MagickBooleanType CloneImageAttributes(Image *image,
00868 %        const Image *clone_image)
00869 %
00870 %  A description of each parameter follows:
00871 %
00872 %    o image: the image.
00873 %
00874 %    o clone_image: the clone image.
00875 %
00876 */
00877 MagickExport MagickBooleanType CloneImageAttributes(Image *image,
00878   const Image *clone_image)
00879 {
00880   return(CloneImageProperties(image,clone_image));
00881 }
00882 
00883 /*
00884 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00885 %                                                                             %
00886 %                                                                             %
00887 %                                                                             %
00888 %   C l o n e M e m o r y                                                     %
00889 %                                                                             %
00890 %                                                                             %
00891 %                                                                             %
00892 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00893 %
00894 %  CloneMemory() copies size bytes from memory area source to the destination.
00895 %  Copying between objects that overlap will take place correctly.  It returns
00896 %  destination.
00897 %
00898 %  The format of the CloneMemory method is:
00899 %
00900 %      void *CloneMemory(void *destination,const void *source,
00901 %        const size_t size)
00902 %
00903 %  A description of each parameter follows:
00904 %
00905 %    o destination: the destination.
00906 %
00907 %    o source: the source.
00908 %
00909 %    o size: the size of the memory in bytes to allocate.
00910 %
00911 */
00912 MagickExport void *CloneMemory(void *destination,const void *source,
00913   const size_t size)
00914 {
00915   register const unsigned char
00916     *p;
00917 
00918   register unsigned char
00919     *q;
00920 
00921   register long
00922     i;
00923 
00924   assert(destination != (void *) NULL);
00925   assert(source != (const void *) NULL);
00926   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
00927   p=(const unsigned char *) source;
00928   q=(unsigned char *) destination;
00929   if ((p <= q) || ((p+size) >= q))
00930     return(CopyMagickMemory(destination,source,size));
00931   /*
00932     Overlap, copy backwards.
00933   */
00934   p+=size;
00935   q+=size;
00936   for (i=(long) (size-1); i >= 0; i--)
00937     *--q=(*--p);
00938   return(destination);
00939 }
00940 
00941 /*
00942 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00943 %                                                                             %
00944 %                                                                             %
00945 %                                                                             %
00946 %   C l o s e C a c h e V i e w                                               %
00947 %                                                                             %
00948 %                                                                             %
00949 %                                                                             %
00950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00951 %
00952 %  CloseCacheView() closes the specified view returned by a previous call to
00953 %  OpenCacheView().
00954 %
00955 %  The format of the CloseCacheView method is:
00956 %
00957 %      ViewInfo *CloseCacheView(ViewInfo *view_info)
00958 %
00959 %  A description of each parameter follows:
00960 %
00961 %    o view_info: the address of a structure of type ViewInfo.
00962 %
00963 */
00964 MagickExport ViewInfo *CloseCacheView(ViewInfo *view_info)
00965 {
00966   return(DestroyCacheView(view_info));
00967 }
00968 
00969 /*
00970 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00971 %                                                                             %
00972 %                                                                             %
00973 %                                                                             %
00974 %   C o l o r F l o o d f i l l I m a g e                                     %
00975 %                                                                             %
00976 %                                                                             %
00977 %                                                                             %
00978 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00979 %
00980 %  ColorFloodfill() changes the color value of any pixel that matches
00981 %  target and is an immediate neighbor.  If the method FillToBorderMethod is
00982 %  specified, the color value is changed for any neighbor pixel that does not
00983 %  match the bordercolor member of image.
00984 %
00985 %  By default target must match a particular pixel color exactly.
00986 %  However, in many cases two colors may differ by a small amount.  The
00987 %  fuzz member of image defines how much tolerance is acceptable to
00988 %  consider two colors as the same.  For example, set fuzz to 10 and the
00989 %  color red at intensities of 100 and 102 respectively are now
00990 %  interpreted as the same color for the purposes of the floodfill.
00991 %
00992 %  The format of the ColorFloodfillImage method is:
00993 %
00994 %      MagickBooleanType ColorFloodfillImage(Image *image,
00995 %        const DrawInfo *draw_info,const PixelPacket target,
00996 %        const long x_offset,const long y_offset,const PaintMethod method)
00997 %
00998 %  A description of each parameter follows:
00999 %
01000 %    o image: the image.
01001 %
01002 %    o draw_info: the draw info.
01003 %
01004 %    o target: the RGB value of the target color.
01005 %
01006 %    o x,y: the starting location of the operation.
01007 %
01008 %    o method: Choose either FloodfillMethod or FillToBorderMethod.
01009 %
01010 */
01011 
01012 #define MaxStacksize  (1UL << 15)
01013 #define PushSegmentStack(up,left,right,delta) \
01014 { \
01015   if (s >= (segment_stack+MaxStacksize)) \
01016     ThrowBinaryException(DrawError,"SegmentStackOverflow",image->filename) \
01017   else \
01018     { \
01019       if ((((up)+(delta)) >= 0) && (((up)+(delta)) < (long) image->rows)) \
01020         { \
01021           s->x1=(double) (left); \
01022           s->y1=(double) (up); \
01023           s->x2=(double) (right); \
01024           s->y2=(double) (delta); \
01025           s++; \
01026         } \
01027     } \
01028 }
01029 
01030 MagickExport MagickBooleanType ColorFloodfillImage(Image *image,
01031   const DrawInfo *draw_info,const PixelPacket target,const long x_offset,
01032   const long y_offset,const PaintMethod method)
01033 {
01034   Image
01035     *floodplane_image;
01036 
01037   long
01038     offset,
01039     start,
01040     x,
01041     x1,
01042     x2,
01043     y;
01044 
01045   MagickBooleanType
01046     skip;
01047 
01048   PixelPacket
01049     fill_color;
01050 
01051   register SegmentInfo
01052     *s;
01053 
01054   SegmentInfo
01055     *segment_stack;
01056 
01057   /*
01058     Check boundary conditions.
01059   */
01060   assert(image != (Image *) NULL);
01061   assert(image->signature == MagickSignature);
01062   if (image->debug != MagickFalse)
01063     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
01064   assert(draw_info != (DrawInfo *) NULL);
01065   assert(draw_info->signature == MagickSignature);
01066   if ((x_offset < 0) || (x_offset >= (long) image->columns))
01067     return(MagickFalse);
01068   if ((y_offset < 0) || (y_offset >= (long) image->rows))
01069     return(MagickFalse);
01070   if (SetImageStorageClass(image,DirectClass) == MagickFalse)
01071     return(MagickFalse);
01072   if (image->matte == MagickFalse)
01073     (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
01074   floodplane_image=CloneImage(image,image->columns,image->rows,MagickTrue,
01075     &image->exception);
01076   if (floodplane_image == (Image *) NULL)
01077     return(MagickFalse);
01078   (void) SetImageAlphaChannel(floodplane_image,OpaqueAlphaChannel);
01079   /*
01080     Set floodfill color.
01081   */
01082   segment_stack=(SegmentInfo *) AcquireQuantumMemory(MaxStacksize,
01083     sizeof(*segment_stack));
01084   if (segment_stack == (SegmentInfo *) NULL)
01085     {
01086       floodplane_image=DestroyImage(floodplane_image);
01087       ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
01088         image->filename);
01089     }
01090   /*
01091     Push initial segment on stack.
01092   */
01093   x=x_offset;
01094   y=y_offset;
01095   start=0;
01096   s=segment_stack;
01097   PushSegmentStack(y,x,x,1);
01098   PushSegmentStack(y+1,x,x,-1);
01099   while (s > segment_stack)
01100   {
01101     register const PixelPacket
01102       *__restrict p;
01103 
01104     register long
01105       x;
01106 
01107     register PixelPacket
01108       *__restrict q;
01109 
01110     /*
01111       Pop segment off stack.
01112     */
01113     s--;
01114     x1=(long) s->x1;
01115     x2=(long) s->x2;
01116     offset=(long) s->y2;
01117     y=(long) s->y1+offset;
01118     /*
01119       Recolor neighboring pixels.
01120     */
01121     p=GetVirtualPixels(image,0,y,(unsigned long) (x1+1),1,&image->exception);
01122     q=GetAuthenticPixels(floodplane_image,0,y,(unsigned long) (x1+1),1,
01123       &image->exception);
01124     if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
01125       break;
01126     p+=x1;
01127     q+=x1;
01128     for (x=x1; x >= 0; x--)
01129     {
01130       if (q->opacity == (Quantum) TransparentOpacity)
01131         break;
01132       if (method == FloodfillMethod)
01133         {
01134           if (IsColorSimilar(image,p,&target) == MagickFalse)
01135             break;
01136         }
01137       else
01138         if (IsColorSimilar(image,p,&target) != MagickFalse)
01139           break;
01140       q->opacity=(Quantum) TransparentOpacity;
01141       p--;
01142       q--;
01143     }
01144     if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse)
01145       break;
01146     skip=x >= x1 ? MagickTrue : MagickFalse;
01147     if (skip == MagickFalse)
01148       {
01149         start=x+1;
01150         if (start < x1)
01151           PushSegmentStack(y,start,x1-1,-offset);
01152         x=x1+1;
01153       }
01154     do
01155     {
01156       if (skip == MagickFalse)
01157         {
01158           if (x < (long) image->columns)
01159             {
01160               p=GetVirtualPixels(image,x,y,image->columns-x,1,
01161                 &image->exception);
01162               q=GetAuthenticPixels(floodplane_image,x,y,image->columns-x,1,
01163                 &image->exception);
01164               if ((p == (const PixelPacket *) NULL) ||
01165                   (q == (PixelPacket *) NULL))
01166                 break;
01167               for ( ; x < (long) image->columns; x++)
01168               {
01169                 if (q->opacity == (Quantum) TransparentOpacity)
01170                   break;
01171                 if (method == FloodfillMethod)
01172                   {
01173                     if (IsColorSimilar(image,p,&target) == MagickFalse)
01174                       break;
01175                   }
01176                 else
01177                   if (IsColorSimilar(image,p,&target) != MagickFalse)
01178                     break;
01179                 q->opacity=(Quantum) TransparentOpacity;
01180                 p++;
01181                 q++;
01182               }
01183               if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse)
01184                 break;
01185             }
01186           PushSegmentStack(y,start,x-1,offset);
01187           if (x > (x2+1))
01188             PushSegmentStack(y,x2+1,x-1,-offset);
01189         }
01190       skip=MagickFalse;
01191       x++;
01192       if (x <= x2)
01193         {
01194           p=GetVirtualPixels(image,x,y,(unsigned long) (x2-x+1),1,
01195             &image->exception);
01196           q=GetAuthenticPixels(floodplane_image,x,y,(unsigned long) (x2-x+1),1,
01197             &image->exception);
01198           if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
01199             break;
01200           for ( ; x <= x2; x++)
01201           {
01202             if (q->opacity == (Quantum) TransparentOpacity)
01203               break;
01204             if (method == FloodfillMethod)
01205               {
01206                 if (IsColorSimilar(image,p,&target) != MagickFalse)
01207                   break;
01208               }
01209             else
01210               if (IsColorSimilar(image,p,&target) == MagickFalse)
01211                 break;
01212             p++;
01213             q++;
01214           }
01215         }
01216       start=x;
01217     } while (x <= x2);
01218   }
01219   for (y=0; y < (long) image->rows; y++)
01220   {
01221     register const PixelPacket
01222       *__restrict p;
01223 
01224     register long
01225       x;
01226 
01227     register PixelPacket
01228       *__restrict q;
01229 
01230     /*
01231       Tile fill color onto floodplane.
01232     */
01233     p=GetVirtualPixels(floodplane_image,0,y,image->columns,1,
01234       &image->exception);
01235     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
01236     if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
01237       break;
01238     for (x=0; x < (long) image->columns; x++)
01239     {
01240       if (p->opacity != OpaqueOpacity)
01241         {
01242           (void) GetFillColor(draw_info,x,y,&fill_color);
01243           MagickCompositeOver(&fill_color,(MagickRealType) fill_color.opacity,q,
01244             (MagickRealType) q->opacity,q);
01245         }
01246       p++;
01247       q++;
01248     }
01249     if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
01250       break;
01251   }
01252   segment_stack=(SegmentInfo *) RelinquishMagickMemory(segment_stack);
01253   floodplane_image=DestroyImage(floodplane_image);
01254   return(y == (long) image->rows ? MagickTrue : MagickFalse);
01255 }
01256 
01257 /*
01258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01259 %                                                                             %
01260 %                                                                             %
01261 %                                                                             %
01262 %   D e l e t e I m a g e A t t r i b u t e                                   %
01263 %                                                                             %
01264 %                                                                             %
01265 %                                                                             %
01266 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01267 %
01268 %  DeleteImageAttribute() deletes an attribute from the image.
01269 %
01270 %  The format of the DeleteImageAttribute method is:
01271 %
01272 %      MagickBooleanType DeleteImageAttribute(Image *image,const char *key)
01273 %
01274 %  A description of each parameter follows:
01275 %
01276 %    o image: the image info.
01277 %
01278 %    o key: the image key.
01279 %
01280 */
01281 MagickExport MagickBooleanType DeleteImageAttribute(Image *image,
01282   const char *key)
01283 {
01284   return(DeleteImageProperty(image,key));
01285 }
01286 
01287 /*
01288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01289 %                                                                             %
01290 %                                                                             %
01291 %                                                                             %
01292 %   D e l e t e I m a g e L i s t                                             %
01293 %                                                                             %
01294 %                                                                             %
01295 %                                                                             %
01296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01297 %
01298 %  DeleteImageList() deletes an image at the specified position in the list.
01299 %
01300 %  The format of the DeleteImageList method is:
01301 %
01302 %      unsigned int DeleteImageList(Image *images,const long offset)
01303 %
01304 %  A description of each parameter follows:
01305 %
01306 %    o images: the image list.
01307 %
01308 %    o offset: the position within the list.
01309 %
01310 */
01311 MagickExport unsigned int DeleteImageList(Image *images,const long offset)
01312 {
01313   register long
01314     i;
01315 
01316   if (images->debug != MagickFalse)
01317     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
01318   while (GetPreviousImageInList(images) != (Image *) NULL)
01319     images=GetPreviousImageInList(images);
01320   for (i=0; i < offset; i++)
01321   {
01322     if (GetNextImageInList(images) == (Image *) NULL)
01323       return(MagickFalse);
01324     images=GetNextImageInList(images);
01325   }
01326   DeleteImageFromList(&images);
01327   return(MagickTrue);
01328 }
01329 
01330 /*
01331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01332 %                                                                             %
01333 %                                                                             %
01334 %                                                                             %
01335 %   D e l e t e M a g i c k R e g i s t r y                                   %
01336 %                                                                             %
01337 %                                                                             %
01338 %                                                                             %
01339 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01340 %
01341 %  DeleteMagickRegistry() deletes an entry in the registry as defined by the id.
01342 %  It returns MagickTrue if the entry is deleted otherwise MagickFalse if no
01343 %  entry is found in the registry that matches the id.
01344 %
01345 %  The format of the DeleteMagickRegistry method is:
01346 %
01347 %      MagickBooleanType DeleteMagickRegistry(const long id)
01348 %
01349 %  A description of each parameter follows:
01350 %
01351 %    o id: the registry id.
01352 %
01353 */
01354 MagickExport MagickBooleanType DeleteMagickRegistry(const long id)
01355 {
01356   char
01357     key[MaxTextExtent];
01358 
01359   (void) FormatMagickString(key,MaxTextExtent,"%ld\n",id);
01360   return(DeleteImageRegistry(key));
01361 }
01362 
01363 /*
01364 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01365 %                                                                             %
01366 %                                                                             %
01367 %                                                                             %
01368 +   D e s t r o y M a g i c k R e g i s t r y                                 %
01369 %                                                                             %
01370 %                                                                             %
01371 %                                                                             %
01372 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01373 %
01374 %  DestroyMagickRegistry() deallocates memory associated the magick registry.
01375 %
01376 %  The format of the DestroyMagickRegistry method is:
01377 %
01378 %       void DestroyMagickRegistry(void)
01379 %
01380 */
01381 MagickExport void DestroyMagickRegistry(void)
01382 {
01383   DestroyImageRegistry();
01384 }
01385 
01386 /*
01387 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01388 %                                                                             %
01389 %                                                                             %
01390 %                                                                             %
01391 %   D e s c r i b e I m a g e                                                 %
01392 %                                                                             %
01393 %                                                                             %
01394 %                                                                             %
01395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01396 %
01397 %  DescribeImage() describes an image by printing its attributes to the file.
01398 %  Attributes include the image width, height, size, and others.
01399 %
01400 %  The format of the DescribeImage method is:
01401 %
01402 %      MagickBooleanType DescribeImage(Image *image,FILE *file,
01403 %        const MagickBooleanType verbose)
01404 %
01405 %  A description of each parameter follows:
01406 %
01407 %    o image: the image.
01408 %
01409 %    o file: the file, typically stdout.
01410 %
01411 %    o verbose: A value other than zero prints more detailed information
01412 %      about the image.
01413 %
01414 */
01415 MagickExport MagickBooleanType DescribeImage(Image *image,FILE *file,
01416   const MagickBooleanType verbose)
01417 {
01418   return(IdentifyImage(image,file,verbose));
01419 }
01420 
01421 /*
01422 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01423 %                                                                             %
01424 %                                                                             %
01425 %                                                                             %
01426 %   D e s t r o y I m a g e A t t r i b u t e s                               %
01427 %                                                                             %
01428 %                                                                             %
01429 %                                                                             %
01430 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01431 %
01432 %  DestroyImageAttributes() deallocates memory associated with the image
01433 %  attribute list.
01434 %
01435 %  The format of the DestroyImageAttributes method is:
01436 %
01437 %      DestroyImageAttributes(Image *image)
01438 %
01439 %  A description of each parameter follows:
01440 %
01441 %    o image: the image.
01442 %
01443 */
01444 MagickExport void DestroyImageAttributes(Image *image)
01445 {
01446   assert(image != (Image *) NULL);
01447   assert(image->signature == MagickSignature);
01448   if (image->debug != MagickFalse)
01449     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
01450   if (image->attributes != (void *) NULL)
01451     image->attributes=(void *) DestroySplayTree((SplayTreeInfo *)
01452       image->attributes);
01453 }
01454 
01455 /*
01456 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01457 %                                                                             %
01458 %                                                                             %
01459 %                                                                             %
01460 %   D e s t r o y I m a g e s                                                 %
01461 %                                                                             %
01462 %                                                                             %
01463 %                                                                             %
01464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01465 %
01466 %  DestroyImages() destroys an image list.
01467 %
01468 %  The format of the DestroyImages method is:
01469 %
01470 %      void DestroyImages(Image *image)
01471 %
01472 %  A description of each parameter follows:
01473 %
01474 %    o image: the image sequence.
01475 %
01476 */
01477 MagickExport void DestroyImages(Image *image)
01478 {
01479   if (image == (Image *) NULL)
01480     return;
01481   if (image->debug != MagickFalse)
01482     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.4.3");
01483   image=DestroyImageList(image);
01484 }
01485 
01486 /*
01487 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01488 %                                                                             %
01489 %                                                                             %
01490 %                                                                             %
01491 %   D e s t r o y M a g i c k                                                 %
01492 %                                                                             %
01493 %                                                                             %
01494 %                                                                             %
01495 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01496 %
01497 %  DestroyMagick() destroys the ImageMagick environment.
01498 %
01499 %  The format of the DestroyMagick function is:
01500 %
01501 %      DestroyMagick(void)
01502 %
01503 */
01504 MagickExport void DestroyMagick(void)
01505 {
01506   MagickCoreTerminus();
01507 }
01508 
01509 /*
01510 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01511 %                                                                             %
01512 %                                                                             %
01513 %                                                                             %
01514 %   D i s p a t c h I m a g e                                                 %
01515 %                                                                             %
01516 %                                                                             %
01517 %                                                                             %
01518 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01519 %
01520 %  DispatchImage() extracts pixel data from an image and returns it to you.
01521 %  The method returns MagickFalse on success otherwise MagickTrue if an error is
01522 %  encountered.  The data is returned as char, short int, int, long, float,
01523 %  or double in the order specified by map.
01524 %
01525 %  Suppose you want to extract the first scanline of a 640x480 image as
01526 %  character data in red-green-blue order:
01527 %
01528 %      DispatchImage(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
01529 %
01530 %  The format of the DispatchImage method is:
01531 %
01532 %      unsigned int DispatchImage(const Image *image,const long x_offset,
01533 %        const long y_offset,const unsigned long columns,
01534 %        const unsigned long rows,const char *map,const StorageType type,
01535 %        void *pixels,ExceptionInfo *exception)
01536 %
01537 %  A description of each parameter follows:
01538 %
01539 %    o image: the image.
01540 %
01541 %    o x_offset, y_offset, columns, rows:  These values define the perimeter
01542 %      of a region of pixels you want to extract.
01543 %
01544 %    o map:  This string reflects the expected ordering of the pixel array.
01545 %      It can be any combination or order of R = red, G = green, B = blue,
01546 %      A = alpha, C = cyan, Y = yellow, M = magenta, K = black, or
01547 %      I = intensity (for grayscale).
01548 %
01549 %    o type: Define the data type of the pixels.  Float and double types are
01550 %      normalized to [0..1] otherwise [0..QuantumRange].  Choose from these
01551 %      types: CharPixel, ShortPixel, IntegerPixel, LongPixel, FloatPixel, or
01552 %      DoublePixel.
01553 %
01554 %    o pixels: This array of values contain the pixel components as defined by
01555 %      map and type.  You must preallocate this array where the expected
01556 %      length varies depending on the values of width, height, map, and type.
01557 %
01558 %    o exception: return any errors or warnings in this structure.
01559 %
01560 */
01561 MagickExport unsigned int DispatchImage(const Image *image,const long x_offset,
01562   const long y_offset,const unsigned long columns,const unsigned long rows,
01563   const char *map,const StorageType type,void *pixels,ExceptionInfo *exception)
01564 {
01565   unsigned int
01566     status;
01567 
01568   if (image->debug != MagickFalse)
01569     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.6");
01570   status=ExportImagePixels(image,x_offset,y_offset,columns,rows,map,type,pixels,
01571     exception);
01572   return(status);
01573 }
01574 
01575 /*
01576 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01577 %                                                                             %
01578 %                                                                             %
01579 %                                                                             %
01580 %   E x t r a c t S u b i m a g e F r o m I m a g e                           %
01581 %                                                                             %
01582 %                                                                             %
01583 %                                                                             %
01584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01585 %
01586 %  ExtractSubimageFromImageImage() extracts a region of the image that most
01587 %  closely resembles the referemce.
01588 %
01589 %  The format of the ExtractSubimageFromImageImage method is:
01590 %
01591 %      Image *ExtractSubimageFromImage(const Image *image,const Image *referemce,
01592 %        ExceptionInfo *exception)
01593 %
01594 %  A description of each parameter follows:
01595 %
01596 %    o image: the image.
01597 %
01598 %    o referemce: find an area of the image that closely resembles this image.
01599 %
01600 %    o exception: return any errors or warnings in this structure.
01601 %
01602 */
01603 
01604 static double GetSimilarityMetric(const Image *image,const Image *referemce,
01605   const long x_offset,const long y_offset,const double similarity_threshold,
01606   ExceptionInfo *exception)
01607 {
01608   long
01609     y;
01610 
01611   double
01612     channels,
01613     normalized_similarity,
01614     similarity;
01615 
01616   ViewInfo
01617     *image_view,
01618     *referemce_view;
01619 
01620   /*
01621     Compute the similarity in pixels between two images.
01622   */
01623   normalized_similarity=1.0;
01624   similarity=0.0;
01625   channels=3;
01626   if ((image->matte != MagickFalse) && (referemce->matte != MagickFalse))
01627     channels++;
01628   if ((image->colorspace == CMYKColorspace) &&
01629       (referemce->colorspace == CMYKColorspace))
01630     channels++;
01631   image_view=AcquireCacheView(image);
01632   referemce_view=AcquireCacheView(referemce);
01633   for (y=0; y < (long) referemce->rows; y++)
01634   {
01635     register const IndexPacket
01636       *indexes,
01637       *referemce_indexes;
01638 
01639     register const PixelPacket
01640       *p,
01641       *q;
01642 
01643     register long
01644       x;
01645 
01646     p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset+y,
01647       referemce->columns,1,exception);
01648     q=GetCacheViewVirtualPixels(referemce_view,0,y,referemce->columns,1,
01649       exception);
01650     if ((p == (const PixelPacket *) NULL) || (q == (const PixelPacket *) NULL))
01651       continue;
01652     indexes=GetCacheViewVirtualIndexQueue(image_view);
01653     referemce_indexes=GetCacheViewVirtualIndexQueue(referemce_view);
01654     for (x=0; x < (long) referemce->columns; x++)
01655     {
01656       MagickRealType
01657         pixel;
01658 
01659       pixel=QuantumScale*(p->red-(double) q->red);
01660       similarity+=pixel*pixel;
01661       pixel=QuantumScale*(p->green-(double) q->green);
01662       similarity+=pixel*pixel;
01663       pixel=QuantumScale*(p->blue-(double) q->blue);
01664       similarity+=pixel*pixel;
01665       if ((image->matte != MagickFalse) && (referemce->matte != MagickFalse))
01666         {
01667           pixel=QuantumScale*(p->opacity-(double) q->opacity);
01668           similarity+=pixel*pixel;
01669         }
01670       if ((image->colorspace == CMYKColorspace) &&
01671           (referemce->colorspace == CMYKColorspace))
01672         {
01673           pixel=QuantumScale*(indexes[x]-(double) referemce_indexes[x]);
01674           similarity+=pixel*pixel;
01675         }
01676       p++;
01677       q++;
01678     }
01679     normalized_similarity=sqrt(similarity)/referemce->columns/referemce->rows/
01680       channels;
01681     if (normalized_similarity > similarity_threshold)
01682       break;
01683   }
01684   referemce_view=DestroyCacheView(referemce_view);
01685   image_view=DestroyCacheView(image_view);
01686   return(normalized_similarity);
01687 }
01688 
01689 MagickExport Image *ExtractSubimageFromImage(Image *image,const Image *referemce,
01690   ExceptionInfo *exception)
01691 {
01692   long
01693     y;
01694 
01695   double
01696     similarity_threshold;
01697 
01698   RectangleInfo
01699     offset;
01700 
01701   /*
01702     Extract referemce from image.
01703   */
01704   if ((referemce->columns > image->columns) || (referemce->rows > image->rows))
01705     return((Image *) NULL);
01706   similarity_threshold=HUGE_VAL;
01707   SetGeometry(referemce,&offset);
01708 #if defined(MAGICKCORE_OPENMP_SUPPORT)
01709   #pragma omp parallel for schedule(dynamic,4)
01710 #endif
01711   for (y=0; y < (long) (image->rows-referemce->rows); y++)
01712   {
01713     double
01714       similarity;
01715 
01716     register long
01717       x;
01718 
01719     for (x=0; x < (long) (image->columns-referemce->columns); x++)
01720     {
01721       similarity=GetSimilarityMetric(image,referemce,x,y,similarity_threshold,
01722         exception);
01723 #if defined(MAGICKCORE_OPENMP_SUPPORT)
01724   #pragma omp critical (MagickCore_ExtractSubimageFromImage)
01725 #endif
01726       if (similarity < similarity_threshold)
01727         {
01728           similarity_threshold=similarity;
01729           offset.x=x;
01730           offset.y=y;
01731         }
01732     }
01733   }
01734   if (similarity_threshold > (QuantumScale*referemce->fuzz/100.0))
01735     return((Image *) NULL);
01736   return(CropImage(image,&offset,exception));
01737 }
01738 
01739 /*
01740 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01741 %                                                                             %
01742 %                                                                             %
01743 %                                                                             %
01744 %     F l a t t e n I m a g e                                                 %
01745 %                                                                             %
01746 %                                                                             %
01747 %                                                                             %
01748 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01749 %
01750 %  FlattenImages() Obsolete Function: Use MergeImageLayers() instead.
01751 %
01752 %  The format of the FlattenImage method is:
01753 %
01754 %      Image *FlattenImage(Image *image,ExceptionInfo *exception)
01755 %
01756 %  A description of each parameter follows:
01757 %
01758 %    o image: the image sequence.
01759 %
01760 %    o exception: return any errors or warnings in this structure.
01761 %
01762 */
01763 MagickExport Image *FlattenImages(Image *image,ExceptionInfo *exception)
01764 {
01765   return(MergeImageLayers(image,FlattenLayer,exception));
01766 }
01767 
01768 /*
01769 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01770 %                                                                             %
01771 %                                                                             %
01772 %                                                                             %
01773 %  F o r m a t I m a g e A t t r i b u t e                                    %
01774 %                                                                             %
01775 %                                                                             %
01776 %                                                                             %
01777 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01778 %
01779 %  FormatImageAttribute() permits formatted key/value pairs to be saved as an
01780 %  image attribute.
01781 %
01782 %  The format of the FormatImageAttribute method is:
01783 %
01784 %      MagickBooleanType FormatImageAttribute(Image *image,const char *key,
01785 %        const char *format,...)
01786 %
01787 %  A description of each parameter follows.
01788 %
01789 %   o  image:  The image.
01790 %
01791 %   o  key:  The attribute key.
01792 %
01793 %   o  format:  A string describing the format to use to write the remaining
01794 %      arguments.
01795 %
01796 */
01797 
01798 MagickExport MagickBooleanType FormatImageAttributeList(Image *image,
01799   const char *key,const char *format,va_list operands)
01800 {
01801   char
01802     value[MaxTextExtent];
01803 
01804   int
01805     n;
01806 
01807 #if defined(MAGICKCORE_HAVE_VSNPRINTF)
01808   n=vsnprintf(value,MaxTextExtent,format,operands);
01809 #else
01810   n=vsprintf(value,format,operands);
01811 #endif
01812   if (n < 0)
01813     value[MaxTextExtent-1]='\0';
01814   return(SetImageAttribute(image,key,value));
01815 }
01816 
01817 MagickExport MagickBooleanType FormatImageAttribute(Image *image,
01818   const char *key,const char *format,...)
01819 {
01820   MagickBooleanType
01821     status;
01822 
01823   va_list
01824     operands;
01825 
01826   va_start(operands,format);
01827   status=FormatImageAttributeList(image,key,format,operands);
01828   va_end(operands);
01829   return(status);
01830 }
01831 
01832 /*
01833 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01834 %                                                                             %
01835 %                                                                             %
01836 %                                                                             %
01837 %  F o r m a t S t r i n g                                                    %
01838 %                                                                             %
01839 %                                                                             %
01840 %                                                                             %
01841 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01842 %
01843 %  FormatString() prints formatted output of a variable argument list.
01844 %
01845 %  The format of the FormatString method is:
01846 %
01847 %      void FormatString(char *string,const char *format,...)
01848 %
01849 %  A description of each parameter follows.
01850 %
01851 %   o  string:  Method FormatString returns the formatted string in this
01852 %      character buffer.
01853 %
01854 %   o  format:  A string describing the format to use to write the remaining
01855 %      arguments.
01856 %
01857 */
01858 
01859 MagickExport void FormatStringList(char *string,const char *format,
01860   va_list operands)
01861 {
01862   int
01863     n;
01864 
01865  (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
01866 #if defined(MAGICKCORE_HAVE_VSNPRINTF)
01867   n=vsnprintf(string,MaxTextExtent,format,operands);
01868 #else
01869   n=vsprintf(string,format,operands);
01870 #endif
01871   if (n < 0)
01872     string[MaxTextExtent-1]='\0';
01873 }
01874 
01875 MagickExport void FormatString(char *string,const char *format,...)
01876 {
01877   va_list
01878     operands;
01879 
01880   va_start(operands,format);
01881   FormatStringList(string,format,operands);
01882   va_end(operands);
01883   return;
01884 }
01885 
01886 /*
01887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01888 %                                                                             %
01889 %                                                                             %
01890 %                                                                             %
01891 +   F u z z y C o l o r M a t c h                                             %
01892 %                                                                             %
01893 %                                                                             %
01894 %                                                                             %
01895 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01896 %
01897 %  FuzzyColorMatch() returns true if two pixels are identical in color.
01898 %
01899 %  The format of the ColorMatch method is:
01900 %
01901 %      void FuzzyColorMatch(const PixelPacket *p,const PixelPacket *q,
01902 %        const double fuzz)
01903 %
01904 %  A description of each parameter follows:
01905 %
01906 %    o p: Pixel p.
01907 %
01908 %    o q: Pixel q.
01909 %
01910 %    o distance:  Define how much tolerance is acceptable to consider
01911 %      two colors as the same.
01912 %
01913 */
01914 MagickExport unsigned int FuzzyColorMatch(const PixelPacket *p,
01915   const PixelPacket *q,const double fuzz)
01916 {
01917   MagickPixelPacket
01918     pixel;
01919 
01920   register MagickRealType
01921     distance;
01922 
01923   if ((fuzz == 0.0) && (p->red == q->red) && (p->green == q->green) &&
01924       (p->blue == q->blue))
01925     return(MagickTrue);
01926   pixel.red=p->red-(MagickRealType) q->red;
01927   distance=pixel.red*pixel.red;
01928   if (distance > (fuzz*fuzz))
01929     return(MagickFalse);
01930   pixel.green=p->green-(MagickRealType) q->green;
01931   distance+=pixel.green*pixel.green;
01932   if (distance > (fuzz*fuzz))
01933     return(MagickFalse);
01934   pixel.blue=p->blue-(MagickRealType) q->blue;
01935   distance+=pixel.blue*pixel.blue;
01936   if (distance > (fuzz*fuzz))
01937     return(MagickFalse);
01938   return(MagickTrue);
01939 }
01940 
01941 /*
01942 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01943 %                                                                             %
01944 %                                                                             %
01945 %                                                                             %
01946 +   F u z z y C o l o r C o m p a r e                                         %
01947 %                                                                             %
01948 %                                                                             %
01949 %                                                                             %
01950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01951 %
01952 %  FuzzyColorCompare() returns MagickTrue if the distance between two colors is
01953 %  less than the specified distance in a linear three dimensional color space.
01954 %  This method is used by ColorFloodFill() and other algorithms which
01955 %  compare two colors.
01956 %
01957 %  The format of the FuzzyColorCompare method is:
01958 %
01959 %      void FuzzyColorCompare(const Image *image,const PixelPacket *p,
01960 %        const PixelPacket *q)
01961 %
01962 %  A description of each parameter follows:
01963 %
01964 %    o image: the image.
01965 %
01966 %    o p: Pixel p.
01967 %
01968 %    o q: Pixel q.
01969 %
01970 */
01971 MagickExport MagickBooleanType FuzzyColorCompare(const Image *image,
01972   const PixelPacket *p,const PixelPacket *q)
01973 {
01974   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.5");
01975   return(IsColorSimilar(image,p,q));
01976 }
01977 
01978 /*
01979 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01980 %                                                                             %
01981 %                                                                             %
01982 %                                                                             %
01983 +   F u z z y O p a c i t y C o m p a r e                                     %
01984 %                                                                             %
01985 %                                                                             %
01986 %                                                                             %
01987 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01988 %
01989 %  FuzzyOpacityCompare() returns true if the distance between two opacity
01990 %  values is less than the specified distance in a linear color space.  This
01991 %  method is used by MatteFloodFill() and other algorithms which compare
01992 %  two opacity values.
01993 %
01994 %  The format of the FuzzyOpacityCompare method is:
01995 %
01996 %      void FuzzyOpacityCompare(const Image *image,const PixelPacket *p,
01997 %        const PixelPacket *q)
01998 %
01999 %  A description of each parameter follows:
02000 %
02001 %    o image: the image.
02002 %
02003 %    o p: Pixel p.
02004 %
02005 %    o q: Pixel q.
02006 %
02007 */
02008 MagickExport MagickBooleanType FuzzyOpacityCompare(const Image *image,
02009   const PixelPacket *p,const PixelPacket *q)
02010 {
02011   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.5");
02012   return(IsOpacitySimilar(image,p,q));
02013 }
02014 
02015 /*
02016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02017 %                                                                             %
02018 %                                                                             %
02019 %                                                                             %
02020 %  G e t C o n f i g u r e B l o b                                            %
02021 %                                                                             %
02022 %                                                                             %
02023 %                                                                             %
02024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02025 %
02026 %  GetConfigureBlob() returns the specified configure file as a blob.
02027 %
02028 %  The format of the GetConfigureBlob method is:
02029 %
02030 %      void *GetConfigureBlob(const char *filename,ExceptionInfo *exception)
02031 %
02032 %  A description of each parameter follows:
02033 %
02034 %    o filename: the configure file name.
02035 %
02036 %    o path: return the full path information of the configure file.
02037 %
02038 %    o length: This pointer to a size_t integer sets the initial length of the
02039 %      blob.  On return, it reflects the actual length of the blob.
02040 %
02041 %    o exception: return any errors or warnings in this structure.
02042 %
02043 */
02044 MagickExport void *GetConfigureBlob(const char *filename,char *path,
02045   size_t *length,ExceptionInfo *exception)
02046 {
02047   void
02048     *blob;
02049 
02050   assert(filename != (const char *) NULL);
02051   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
02052   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
02053   assert(path != (char *) NULL);
02054   assert(length != (size_t *) NULL);
02055   assert(exception != (ExceptionInfo *) NULL);
02056   blob=(void *) NULL;
02057   (void) CopyMagickString(path,filename,MaxTextExtent);
02058 #if defined(MAGICKCORE_INSTALLED_SUPPORT)
02059 #if defined(MAGICKCORE_LIBRARY_PATH)
02060   if (blob == (void *) NULL)
02061     {
02062       /*
02063         Search hard coded paths.
02064       */
02065       (void) FormatMagickString(path,MaxTextExtent,"%s%s",
02066         MAGICKCORE_LIBRARY_PATH,filename);
02067       if (IsPathAccessible(path) != MagickFalse)
02068         blob=FileToBlob(path,~0,length,exception);
02069     }
02070 #endif
02071 #if defined(__WINDOWS__) && !(defined(MAGICKCORE_CONFIGURE_PATH) || defined(MAGICKCORE_SHARE_CONFIGURE_PATH))
02072   if (blob == (void *) NULL)
02073     {
02074       char
02075         *key_value;
02076 
02077       /*
02078         Locate file via registry key.
02079       */
02080       key_value=NTRegistryKeyLookup("ConfigurePath");
02081       if (key_value != (char *) NULL)
02082         {
02083           (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",key_value,
02084             DirectorySeparator,filename);
02085           if (IsPathAccessible(path) != MagickFalse)
02086             blob=FileToBlob(path,~0,length,exception);
02087         }
02088     }
02089 #endif
02090 #else
02091   if (blob == (void *) NULL)
02092     {
02093       char
02094         *home;
02095 
02096       home=GetEnvironmentValue("MAGICK_HOME");
02097       if (home != (char *) NULL)
02098         {
02099           /*
02100             Search MAGICK_HOME.
02101           */
02102 #if !defined(MAGICKCORE_POSIX_SUPPORT)
02103           (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",home,
02104             DirectorySeparator,filename);
02105 #else
02106           (void) FormatMagickString(path,MaxTextExtent,"%s/lib/%s/%s",home,
02107             MAGICKCORE_LIBRARY_RELATIVE_PATH,filename);
02108 #endif
02109           if (IsPathAccessible(path) != MagickFalse)
02110             blob=FileToBlob(path,~0,length,exception);
02111           home=DestroyString(home);
02112         }
02113       home=GetEnvironmentValue("HOME");
02114       if (home == (char *) NULL)
02115         home=GetEnvironmentValue("USERPROFILE");
02116       if (home != (char *) NULL)
02117         {
02118           /*
02119             Search $HOME/.magick.
02120           */
02121           (void) FormatMagickString(path,MaxTextExtent,"%s%s.magick%s%s",home,
02122             DirectorySeparator,DirectorySeparator,filename);
02123           if ((IsPathAccessible(path) != MagickFalse) && (blob == (void *) NULL))
02124             blob=FileToBlob(path,~0,length,exception);
02125           home=DestroyString(home);
02126         }
02127     }
02128   if ((blob == (void *) NULL) && (*GetClientPath() != '\0'))
02129     {
02130 #if !defined(MAGICKCORE_POSIX_SUPPORT)
02131       (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",GetClientPath(),
02132         DirectorySeparator,filename);
02133 #else
02134       char
02135         prefix[MaxTextExtent];
02136 
02137       /*
02138         Search based on executable directory if directory is known.
02139       */
02140       (void) CopyMagickString(prefix,GetClientPath(),
02141         MaxTextExtent);
02142       ChopPathComponents(prefix,1);
02143       (void) FormatMagickString(path,MaxTextExtent,"%s/lib/%s/%s",prefix,
02144         MAGICKCORE_LIBRARY_RELATIVE_PATH,filename);
02145 #endif
02146       if (IsPathAccessible(path) != MagickFalse)
02147         blob=FileToBlob(path,~0,length,exception);
02148     }
02149   /*
02150     Search current directory.
02151   */
02152   if ((blob == (void *) NULL) && (IsPathAccessible(path) != MagickFalse))
02153     blob=FileToBlob(path,~0,length,exception);
02154 #if defined(__WINDOWS__)
02155   /*
02156     Search Windows registry.
02157   */
02158   if (blob == (void *) NULL)
02159     blob=NTResourceToBlob(filename);
02160 #endif
02161 #endif
02162   if (blob == (void *) NULL)
02163     (void) ThrowMagickException(exception,GetMagickModule(),ConfigureWarning,
02164       "UnableToOpenConfigureFile","`%s'",path);
02165   return(blob);
02166 }
02167 
02168 /*
02169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02170 %                                                                             %
02171 %                                                                             %
02172 %                                                                             %
02173 %   G e t C a c h e V i e w                                                   %
02174 %                                                                             %
02175 %                                                                             %
02176 %                                                                             %
02177 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02178 %
02179 %  GetCacheView() gets pixels from the in-memory or disk pixel cache as
02180 %  defined by the geometry parameters.   A pointer to the pixels is returned if
02181 %  the pixels are transferred, otherwise a NULL is returned.
02182 %
02183 %  The format of the GetCacheView method is:
02184 %
02185 %      PixelPacket *GetCacheView(ViewInfo *cache_view,const long x,
02186 %        const long y,const unsigned long columns,const unsigned long rows)
02187 %
02188 %  A description of each parameter follows:
02189 %
02190 %    o cache_view: the address of a structure of type ViewInfo.
02191 %
02192 %    o x,y,columns,rows:  These values define the perimeter of a region of
02193 %      pixels.
02194 %
02195 */
02196 MagickExport PixelPacket *GetCacheView(ViewInfo *cache_view,const long x,
02197   const long y,const unsigned long columns,const unsigned long rows)
02198 {
02199   PixelPacket
02200     *pixels;
02201 
02202   pixels=GetCacheViewAuthenticPixels(cache_view,x,y,columns,rows,
02203     GetCacheViewException(cache_view));
02204   return(pixels);
02205 }
02206 
02207 /*
02208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02209 %                                                                             %
02210 %                                                                             %
02211 %                                                                             %
02212 %   G e t C a c h e V i e w I n d e x e s                                     %
02213 %                                                                             %
02214 %                                                                             %
02215 %                                                                             %
02216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02217 %
02218 %  GetCacheViewIndexes() returns the indexes associated with the specified
02219 %  view.
02220 %
02221 %  The format of the GetCacheViewIndexes method is:
02222 %
02223 %      IndexPacket *GetCacheViewIndexes(ViewInfo *cache_view)
02224 %
02225 %  A description of each parameter follows:
02226 %
02227 %    o cache_view: the cache view.
02228 %
02229 */
02230 MagickExport IndexPacket *GetCacheViewIndexes(ViewInfo *cache_view)
02231 {
02232   return(GetCacheViewAuthenticIndexQueue(cache_view));
02233 }
02234 
02235 /*
02236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02237 %                                                                             %
02238 %                                                                             %
02239 %                                                                             %
02240 %   G e t C a c h e V i e w P i x e l s                                       %
02241 %                                                                             %
02242 %                                                                             %
02243 %                                                                             %
02244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02245 %
02246 %  GetCacheViewPixels() gets pixels from the in-memory or disk pixel cache as
02247 %  defined by the geometry parameters.   A pointer to the pixels is returned if
02248 %  the pixels are transferred, otherwise a NULL is returned.
02249 %
02250 %  The format of the GetCacheViewPixels method is:
02251 %
02252 %      PixelPacket *GetCacheViewPixels(ViewInfo *cache_view,const long x,
02253 %        const long y,const unsigned long columns,const unsigned long rows)
02254 %
02255 %  A description of each parameter follows:
02256 %
02257 %    o cache_view: the cache view.
02258 %
02259 %    o x,y,columns,rows:  These values define the perimeter of a region of
02260 %      pixels.
02261 %
02262 */
02263 MagickExport PixelPacket *GetCacheViewPixels(ViewInfo *cache_view,const long x,
02264   const long y,const unsigned long columns,const unsigned long rows)
02265 {
02266   PixelPacket
02267     *pixels;
02268 
02269   pixels=GetCacheViewAuthenticPixels(cache_view,x,y,columns,rows,
02270     GetCacheViewException(cache_view));
02271   return(pixels);
02272 }
02273 
02274 /*
02275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02276 %                                                                             %
02277 %                                                                             %
02278 %                                                                             %
02279 %   G e t I m a g e A t t r i b u t e                                         %
02280 %                                                                             %
02281 %                                                                             %
02282 %                                                                             %
02283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02284 %
02285 %  GetImageAttribute() searches the list of image attributes and returns
02286 %  a pointer to the attribute if it exists otherwise NULL.
02287 %
02288 %  The format of the GetImageAttribute method is:
02289 %
02290 %      const ImageAttribute *GetImageAttribute(const Image *image,
02291 %        const char *key)
02292 %
02293 %  A description of each parameter follows:
02294 %
02295 %    o image: the image.
02296 %
02297 %    o key:  These character strings are the name of an image attribute to
02298 %      return.
02299 %
02300 */
02301 
02302 static void *DestroyAttribute(void *attribute)
02303 {
02304   register ImageAttribute
02305     *p;
02306 
02307   p=(ImageAttribute *) attribute;
02308   if (p->value != (char *) NULL)
02309     p->value=DestroyString(p->value);
02310   return(RelinquishMagickMemory(p));
02311 }
02312 
02313 MagickExport const ImageAttribute *GetImageAttribute(const Image *image,
02314   const char *key)
02315 {
02316   const char
02317     *value;
02318 
02319   ImageAttribute
02320     *attribute;
02321 
02322   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.3.1");
02323   value=GetImageProperty(image,key);
02324   if (value == (const char *) NULL)
02325     return((const ImageAttribute *) NULL);
02326   if (image->attributes == (void *) NULL)
02327     ((Image *) image)->attributes=NewSplayTree(CompareSplayTreeString,
02328       RelinquishMagickMemory,DestroyAttribute);
02329   else
02330     {
02331       const ImageAttribute
02332         *attribute;
02333 
02334       attribute=(const ImageAttribute *) GetValueFromSplayTree((SplayTreeInfo *)
02335         image->attributes,key);
02336       if (attribute != (const ImageAttribute *) NULL)
02337         return(attribute);
02338     }
02339   attribute=(ImageAttribute *) AcquireMagickMemory(sizeof(*attribute));
02340   if (attribute == (ImageAttribute *) NULL)
02341     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
02342   (void) ResetMagickMemory(attribute,0,sizeof(*attribute));
02343   attribute->key=ConstantString(key);
02344   attribute->value=ConstantString(value);
02345   (void) AddValueToSplayTree((SplayTreeInfo *) ((Image *) image)->attributes,
02346     attribute->key,attribute);
02347   return((const ImageAttribute *) attribute);
02348 }
02349 
02350 /*
02351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02352 %                                                                             %
02353 %                                                                             %
02354 %                                                                             %
02355 %   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                 %
02356 %                                                                             %
02357 %                                                                             %
02358 %                                                                             %
02359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02360 %
02361 %  GetImageClippingPathAttribute() searches the list of image attributes and
02362 %  returns a pointer to a clipping path if it exists otherwise NULL.
02363 %
02364 %  The format of the GetImageClippingPathAttribute method is:
02365 %
02366 %      const ImageAttribute *GetImageClippingPathAttribute(Image *image)
02367 %
02368 %  A description of each parameter follows:
02369 %
02370 %    o attribute:  Method GetImageClippingPathAttribute returns the clipping
02371 %      path if it exists otherwise NULL.
02372 %
02373 %    o image: the image.
02374 %
02375 */
02376 MagickExport const ImageAttribute *GetImageClippingPathAttribute(Image *image)
02377 {
02378   return(GetImageAttribute(image,"8BIM:1999,2998"));
02379 }
02380 
02381 /*
02382 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02383 %                                                                             %
02384 %                                                                             %
02385 %                                                                             %
02386 %   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                       %
02387 %                                                                             %
02388 %                                                                             %
02389 %                                                                             %
02390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02391 %
02392 %  GetImageFromMagickRegistry() gets an image from the registry as defined by
02393 %  its name.  If the image is not found, a NULL image is returned.
02394 %
02395 %  The format of the GetImageFromMagickRegistry method is:
02396 %
02397 %      Image *GetImageFromMagickRegistry(const char *name,long *id,
02398 %        ExceptionInfo *exception)
02399 %
02400 %  A description of each parameter follows:
02401 %
02402 %    o name: the name of the image to retrieve from the registry.
02403 %
02404 %    o id: the registry id.
02405 %
02406 %    o exception: return any errors or warnings in this structure.
02407 %
02408 */
02409 MagickExport Image *GetImageFromMagickRegistry(const char *name,long *id,
02410   ExceptionInfo *exception)
02411 {
02412   *id=0L;
02413   return((Image *) GetImageRegistry(ImageRegistryType,name,exception));
02414 }
02415 
02416 /*
02417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02418 %                                                                             %
02419 %                                                                             %
02420 %                                                                             %
02421 %   G e t M a g i c k R e g i s t r y                                         %
02422 %                                                                             %
02423 %                                                                             %
02424 %                                                                             %
02425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02426 %
02427 %  GetMagickRegistry() gets a blob from the registry as defined by the id.  If
02428 %  the blob that matches the id is not found, NULL is returned.
02429 %
02430 %  The format of the GetMagickRegistry method is:
02431 %
02432 %      const void *GetMagickRegistry(const long id,RegistryType *type,
02433 %        size_t *length,ExceptionInfo *exception)
02434 %
02435 %  A description of each parameter follows:
02436 %
02437 %    o id: the registry id.
02438 %
02439 %    o type: the registry type.
02440 %
02441 %    o length: the blob length in number of bytes.
02442 %
02443 %    o exception: return any errors or warnings in this structure.
02444 %
02445 */
02446 MagickExport void *GetMagickRegistry(const long id,RegistryType *type,
02447   size_t *length,ExceptionInfo *exception)
02448 {
02449   char
02450     key[MaxTextExtent];
02451 
02452   void
02453     *blob;
02454 
02455   *type=UndefinedRegistryType;
02456   *length=0;
02457   (void) FormatMagickString(key,MaxTextExtent,"%ld\n",id);
02458   blob=(void *) GetImageRegistry(ImageRegistryType,key,exception);
02459   if (blob != (void *) NULL)
02460     return(blob);
02461   blob=(void *) GetImageRegistry(ImageInfoRegistryType,key,exception);
02462   if (blob != (void *) NULL)
02463     return(blob);
02464   return((void *) GetImageRegistry(UndefinedRegistryType,key,exception));
02465 }
02466 
02467 /*
02468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02469 %                                                                             %
02470 %                                                                             %
02471 %                                                                             %
02472 %   G e t I m a g e G e o m e t r y                                           %
02473 %                                                                             %
02474 %                                                                             %
02475 %                                                                             %
02476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02477 %
02478 %  GetImageGeometry() returns a region as defined by the geometry string with
02479 %  respect to the image and its gravity.
02480 %
02481 %  The format of the GetImageGeometry method is:
02482 %
02483 %      int GetImageGeometry(Image *image,const char *geometry,
02484 %        const unsigned int size_to_fit,RectangeInfo *region_info)
02485 %
02486 %  A description of each parameter follows:
02487 %
02488 %    o flags:  Method GetImageGeometry returns a bitmask that indicates
02489 %      which of the four values were located in the geometry string.
02490 %
02491 %    o geometry:  The geometry (e.g. 100x100+10+10).
02492 %
02493 %    o size_to_fit:  A value other than 0 means to scale the region so it
02494 %      fits within the specified width and height.
02495 %
02496 %    o region_info: the region as defined by the geometry string with
02497 %      respect to the image and its gravity.
02498 %
02499 */
02500 MagickExport int GetImageGeometry(Image *image,const char *geometry,
02501   const unsigned int size_to_fit,RectangleInfo *region_info)
02502 {
02503   if (image->debug != MagickFalse)
02504     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.4");
02505   if (size_to_fit != MagickFalse)
02506     return((int) ParseRegionGeometry(image,geometry,region_info,&image->exception));
02507   return((int) ParsePageGeometry(image,geometry,region_info,&image->exception));
02508 }
02509 
02510 /*
02511 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02512 %                                                                             %
02513 %                                                                             %
02514 %                                                                             %
02515 %   G e t I m a g e L i s t                                                   %
02516 %                                                                             %
02517 %                                                                             %
02518 %                                                                             %
02519 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02520 %
02521 %  GetImageList() returns an image at the specified position in the list.
02522 %
02523 %  The format of the GetImageList method is:
02524 %
02525 %      Image *GetImageList(const Image *images,const long offset,
02526 %        ExceptionInfo *exception)
02527 %
02528 %  A description of each parameter follows:
02529 %
02530 %    o images: the image list.
02531 %
02532 %    o offset: the position within the list.
02533 %
02534 %    o exception: return any errors or warnings in this structure.
02535 %
02536 */
02537 MagickExport Image *GetImageList(const Image *images,const long offset,
02538   ExceptionInfo *exception)
02539 {
02540   Image
02541     *image;
02542 
02543   if (images->debug != MagickFalse)
02544     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
02545   image=CloneImage(GetImageFromList(images,(long) offset),0,0,MagickTrue,
02546     exception);
02547   return(image);
02548 }
02549 
02550 /*
02551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02552 %                                                                             %
02553 %                                                                             %
02554 %                                                                             %
02555 %   G e t I m a g e L i s t I n d e x                                         %
02556 %                                                                             %
02557 %                                                                             %
02558 %                                                                             %
02559 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02560 %
02561 %  GetImageListIndex() returns the position in the list of the specified
02562 %  image.
02563 %
02564 %  The format of the GetImageListIndex method is:
02565 %
02566 %      long GetImageListIndex(const Image *images)
02567 %
02568 %  A description of each parameter follows:
02569 %
02570 %    o images: the image list.
02571 %
02572 */
02573 MagickExport long GetImageListIndex(const Image *images)
02574 {
02575   if (images->debug != MagickFalse)
02576     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
02577   return(GetImageIndexInList(images));
02578 }
02579 
02580 /*
02581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02582 %                                                                             %
02583 %                                                                             %
02584 %                                                                             %
02585 %   G e t I m a g e L i s t S i z e                                           %
02586 %                                                                             %
02587 %                                                                             %
02588 %                                                                             %
02589 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02590 %
02591 %  GetImageListSize() returns the number of images in the list.
02592 %
02593 %  The format of the GetImageListSize method is:
02594 %
02595 %      unsigned long GetImageListSize(const Image *images)
02596 %
02597 %  A description of each parameter follows:
02598 %
02599 %    o images: the image list.
02600 %
02601 */
02602 MagickExport unsigned long GetImageListSize(const Image *images)
02603 {
02604   if (images->debug != MagickFalse)
02605     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
02606   return(GetImageListLength(images));
02607 }
02608 
02609 /*
02610 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02611 %                                                                             %
02612 %                                                                             %
02613 %                                                                             %
02614 %   G e t I m a g e P i x e l s                                               %
02615 %                                                                             %
02616 %                                                                             %
02617 %                                                                             %
02618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02619 %
02620 %  GetImagePixels() obtains a pixel region for read/write access. If the
02621 %  region is successfully accessed, a pointer to a PixelPacket array
02622 %  representing the region is returned, otherwise NULL is returned.
02623 %
02624 %  The returned pointer may point to a temporary working copy of the pixels
02625 %  or it may point to the original pixels in memory. Performance is maximized
02626 %  if the selected region is part of one row, or one or more full rows, since
02627 %  then there is opportunity to access the pixels in-place (without a copy)
02628 %  if the image is in RAM, or in a memory-mapped file. The returned pointer
02629 %  should *never* be deallocated by the user.
02630 %
02631 %  Pixels accessed via the returned pointer represent a simple array of type
02632 %  PixelPacket. If the image type is CMYK or if the storage class is
02633 %  PseduoClass, call GetAuthenticIndexQueue() after invoking GetImagePixels()
02634 %  to obtain the black color component or colormap indexes (of type IndexPacket)
02635 %  corresponding to the region.  Once the PixelPacket (and/or IndexPacket)
02636 %  array has been updated, the changes must be saved back to the underlying
02637 %  image using SyncAuthenticPixels() or they may be lost.
02638 %
02639 %  The format of the GetImagePixels() method is:
02640 %
02641 %      PixelPacket *GetImagePixels(Image *image,const long x,const long y,
02642 %        const unsigned long columns,const unsigned long rows)
02643 %
02644 %  A description of each parameter follows:
02645 %
02646 %    o image: the image.
02647 %
02648 %    o x,y,columns,rows:  These values define the perimeter of a region of
02649 %      pixels.
02650 %
02651 */
02652 MagickExport PixelPacket *GetImagePixels(Image *image,const long x,const long y,
02653   const unsigned long columns,const unsigned long rows)
02654 {
02655   return(GetAuthenticPixels(image,x,y,columns,rows,&image->exception));
02656 }
02657 
02658 /*
02659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02660 %                                                                             %
02661 %                                                                             %
02662 %                                                                             %
02663 %   G e t I n d e x e s                                                       %
02664 %                                                                             %
02665 %                                                                             %
02666 %                                                                             %
02667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02668 %
02669 %  GetIndexes() returns the black channel or the colormap indexes associated
02670 %  with the last call to QueueAuthenticPixels() or GetVirtualPixels().  NULL is
02671 %  returned if the black channel or colormap indexes are not available.
02672 %
02673 %  The format of the GetIndexes() method is:
02674 %
02675 %      IndexPacket *GetIndexes(const Image *image)
02676 %
02677 %  A description of each parameter follows:
02678 %
02679 %    o indexes: GetIndexes() returns the indexes associated with the last
02680 %      call to QueueAuthenticPixels() or GetAuthenticPixels().
02681 %
02682 %    o image: the image.
02683 %
02684 */
02685 MagickExport IndexPacket *GetIndexes(const Image *image)
02686 {
02687   return(GetAuthenticIndexQueue(image));
02688 }
02689 
02690 /*
02691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02692 %                                                                             %
02693 %                                                                             %
02694 %                                                                             %
02695 +   G e t M a g i c k G e o m e t r y                                         %
02696 %                                                                             %
02697 %                                                                             %
02698 %                                                                             %
02699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02700 %
02701 %  GetMagickGeometry() is similar to GetGeometry() except the returned
02702 %  geometry is modified as determined by the meta characters:  %, !, <, >,
02703 %  and ~.
02704 %
02705 %  The format of the GetMagickGeometry method is:
02706 %
02707 %      unsigned int GetMagickGeometry(const char *geometry,long *x,long *y,
02708 %        unsigned long *width,unsigned long *height)
02709 %
02710 %  A description of each parameter follows:
02711 %
02712 %    o geometry:  Specifies a character string representing the geometry
02713 %      specification.
02714 %
02715 %    o x,y:  A pointer to an integer.  The x and y offset as determined by
02716 %      the geometry specification is returned here.
02717 %
02718 %    o width,height:  A pointer to an unsigned integer.  The width and height
02719 %      as determined by the geometry specification is returned here.
02720 %
02721 */
02722 MagickExport unsigned int GetMagickGeometry(const char *geometry,long *x,
02723   long *y,unsigned long *width,unsigned long *height)
02724 {
02725   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.3");
02726   return(ParseMetaGeometry(geometry,x,y,width,height));
02727 }
02728 
02729 /*
02730 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02731 %                                                                             %
02732 %                                                                             %
02733 %                                                                             %
02734 %   G e t N e x t I m a g e                                                   %
02735 %                                                                             %
02736 %                                                                             %
02737 %                                                                             %
02738 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02739 %
02740 %  GetNextImage() returns the next image in a list.
02741 %
02742 %  The format of the GetNextImage method is:
02743 %
02744 %      Image *GetNextImage(const Image *images)
02745 %
02746 %  A description of each parameter follows:
02747 %
02748 %    o images: the image list.
02749 %
02750 */
02751 MagickExport Image *GetNextImage(const Image *images)
02752 {
02753   if (images->debug != MagickFalse)
02754     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
02755   return(GetNextImageInList(images));
02756 }
02757 
02758 /*
02759 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02760 %                                                                             %
02761 %                                                                             %
02762 %                                                                             %
02763 %   G e t N e x t I m a g e A t t r i b u t e                                 %
02764 %                                                                             %
02765 %                                                                             %
02766 %                                                                             %
02767 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02768 %
02769 %  GetNextImageAttribute() gets the next image attribute.
02770 %
02771 %  The format of the GetNextImageAttribute method is:
02772 %
02773 %      const ImageAttribute *GetNextImageAttribute(const Image *image)
02774 %
02775 %  A description of each parameter follows:
02776 %
02777 %    o image: the image.
02778 %
02779 */
02780 MagickExport const ImageAttribute *GetNextImageAttribute(const Image *image)
02781 {
02782   const char
02783     *property;
02784 
02785   property=GetNextImageProperty(image);
02786   if (property == (const char *) NULL)
02787     return((const ImageAttribute *) NULL);
02788   return(GetImageAttribute(image,property));
02789 }
02790 
02791 /*
02792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02793 %                                                                             %
02794 %                                                                             %
02795 %                                                                             %
02796 %   G e t N u m b e r S c e n e s                                             %
02797 %                                                                             %
02798 %                                                                             %
02799 %                                                                             %
02800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02801 %
02802 %  GetNumberScenes() returns the number of images in the list.
02803 %
02804 %  The format of the GetNumberScenes method is:
02805 %
02806 %      unsigned int GetNumberScenes(const Image *images)
02807 %
02808 %  A description of each parameter follows:
02809 %
02810 %    o images: the image list.
02811 %
02812 */
02813 MagickExport unsigned int GetNumberScenes(const Image *image)
02814 {
02815   if (image->debug != MagickFalse)
02816     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
02817   return((unsigned int) GetImageListLength(image));
02818 }
02819 
02820 /*
02821 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02822 %                                                                             %
02823 %                                                                             %
02824 %                                                                             %
02825 %   G e t O n e P i x e l                                                     %
02826 %                                                                             %
02827 %                                                                             %
02828 %                                                                             %
02829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02830 %
02831 %  GetOnePixel() returns a single pixel at the specified (x,y) location.
02832 %  The image background color is returned if an error occurs.
02833 %
02834 %  The format of the GetOnePixel() method is:
02835 %
02836 %      PixelPacket GetOnePixel(const Image image,const long x,const long y)
02837 %
02838 %  A description of each parameter follows:
02839 %
02840 %    o image: the image.
02841 %
02842 %    o x,y:  These values define the location of the pixel to return.
02843 %
02844 */
02845 MagickExport PixelPacket GetOnePixel(Image *image,const long x,const long y)
02846 {
02847   PixelPacket
02848     pixel;
02849 
02850   (void) GetOneAuthenticPixel(image,x,y,&pixel,&image->exception);
02851   return(pixel);
02852 }
02853 
02854 /*
02855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02856 %                                                                             %
02857 %                                                                             %
02858 %                                                                             %
02859 %   G e t P i x e l s                                                         %
02860 %                                                                             %
02861 %                                                                             %
02862 %                                                                             %
02863 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02864 %
02865 %  GetPixels() returns the pixels associated with the last call to
02866 %  QueueAuthenticPixels() or GetAuthenticPixels().
02867 %
02868 %  The format of the GetPixels() method is:
02869 %
02870 %      PixelPacket *GetPixels(const Image image)
02871 %
02872 %  A description of each parameter follows:
02873 %
02874 %    o pixels: GetPixels() returns the pixels associated with the last call
02875 %      to QueueAuthenticPixels() or GetAuthenticPixels().
02876 %
02877 %    o image: the image.
02878 %
02879 */
02880 MagickExport PixelPacket *GetPixels(const Image *image)
02881 {
02882   return(GetAuthenticPixelQueue(image));
02883 }
02884 
02885 /*
02886 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02887 %                                                                             %
02888 %                                                                             %
02889 %                                                                             %
02890 %   G e t P r e v i o u s I m a g e                                           %
02891 %                                                                             %
02892 %                                                                             %
02893 %                                                                             %
02894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02895 %
02896 %  GetPreviousImage() returns the previous image in a list.
02897 %
02898 %  The format of the GetPreviousImage method is:
02899 %
02900 %      Image *GetPreviousImage(const Image *images)
02901 %
02902 %  A description of each parameter follows:
02903 %
02904 %    o images: the image list.
02905 %
02906 */
02907 MagickExport Image *GetPreviousImage(const Image *images)
02908 {
02909   if (images->debug != MagickFalse)
02910     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
02911   return(GetPreviousImageInList(images));
02912 }
02913 
02914 /*
02915 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02916 %                                                                             %
02917 %                                                                             %
02918 %                                                                             %
02919 %   H S L T r a n s f o r m                                                   %
02920 %                                                                             %
02921 %                                                                             %
02922 %                                                                             %
02923 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02924 %
02925 %  HSLTransform() converts a (hue, saturation, lightness) to a (red, green,
02926 %  blue) triple.
02927 %
02928 %  The format of the HSLTransformImage method is:
02929 %
02930 %      void HSLTransform(const double hue,const double saturation,
02931 %        const double lightness,Quantum *red,Quantum *green,Quantum *blue)
02932 %
02933 %  A description of each parameter follows:
02934 %
02935 %    o hue, saturation, lightness: A double value representing a
02936 %      component of the HSL color space.
02937 %
02938 %    o red, green, blue: A pointer to a pixel component of type Quantum.
02939 %
02940 */
02941 
02942 static inline MagickRealType HueToRGB(MagickRealType m1,MagickRealType m2,
02943   MagickRealType hue)
02944 {
02945   if (hue < 0.0)
02946     hue+=1.0;
02947   if (hue > 1.0)
02948     hue-=1.0;
02949   if ((6.0*hue) < 1.0)
02950     return(m1+6.0*(m2-m1)*hue);
02951   if ((2.0*hue) < 1.0)
02952     return(m2);
02953   if ((3.0*hue) < 2.0)
02954     return(m1+6.0*(m2-m1)*(2.0/3.0-hue));
02955   return(m1);
02956 }
02957 
02958 MagickExport void HSLTransform(const double hue,const double saturation,
02959   const double lightness,Quantum *red,Quantum *green,Quantum *blue)
02960 {
02961   MagickRealType
02962     b,
02963     g,
02964     r,
02965     m1,
02966     m2;
02967 
02968   /*
02969     Convert HSL to RGB colorspace.
02970   */
02971   assert(red != (Quantum *) NULL);
02972   assert(green != (Quantum *) NULL);
02973   assert(blue != (Quantum *) NULL);
02974   if (lightness <= 0.5)
02975     m2=lightness*(saturation+1.0);
02976   else
02977     m2=lightness+saturation-lightness*saturation;
02978   m1=2.0*lightness-m2;
02979   r=HueToRGB(m1,m2,hue+1.0/3.0);
02980   g=HueToRGB(m1,m2,hue);
02981   b=HueToRGB(m1,m2,hue-1.0/3.0);
02982   *red=RoundToQuantum((MagickRealType) QuantumRange*r);
02983   *green=RoundToQuantum((MagickRealType) QuantumRange*g);
02984   *blue=RoundToQuantum((MagickRealType) QuantumRange*b);
02985 }
02986 
02987 /*
02988 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02989 %                                                                             %
02990 %                                                                             %
02991 %                                                                             %
02992 %   I d e n t i t y A f f i n e                                               %
02993 %                                                                             %
02994 %                                                                             %
02995 %                                                                             %
02996 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
02997 %
02998 %  IdentityAffine() initializes the affine transform to the identity matrix.
02999 %
03000 %  The format of the IdentityAffine method is:
03001 %
03002 %      IdentityAffine(AffineMatrix *affine)
03003 %
03004 %  A description of each parameter follows:
03005 %
03006 %    o affine: A pointer the affine transform of type AffineMatrix.
03007 %
03008 */
03009 MagickExport void IdentityAffine(AffineMatrix *affine)
03010 {
03011   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
03012   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
03013   assert(affine != (AffineMatrix *) NULL);
03014   (void) ResetMagickMemory(affine,0,sizeof(AffineMatrix));
03015   affine->sx=1.0;
03016   affine->sy=1.0;
03017 }
03018 
03019 /*
03020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03021 %                                                                             %
03022 %                                                                             %
03023 %                                                                             %
03024 %   I n i t i a l i z e M a g i c k                                           %
03025 %                                                                             %
03026 %                                                                             %
03027 %                                                                             %
03028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03029 %
03030 %  InitializeMagick() initializes the ImageMagick environment.
03031 %
03032 %  The format of the InitializeMagick function is:
03033 %
03034 %      InitializeMagick(const char *path)
03035 %
03036 %  A description of each parameter follows:
03037 %
03038 %    o path: the execution path of the current ImageMagick client.
03039 %
03040 */
03041 MagickExport void InitializeMagick(const char *path)
03042 {
03043   MagickCoreGenesis(path,MagickFalse);
03044 }
03045 
03046 /*
03047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03048 %                                                                             %
03049 %                                                                             %
03050 %                                                                             %
03051 %   I n t e r p o l a t e P i x e l C o l o r                                 %
03052 %                                                                             %
03053 %                                                                             %
03054 %                                                                             %
03055 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03056 %
03057 %  InterpolatePixelColor() applies bi-linear or tri-linear interpolation
03058 %  between a pixel and it's neighbors.
03059 %
03060 %  The format of the InterpolatePixelColor method is:
03061 %
03062 %      MagickPixelPacket InterpolatePixelColor(const Image *image,
03063 %        ViewInfo *view_info,InterpolatePixelMethod method,const double x,
03064 %        const double y,ExceptionInfo *exception)
03065 %
03066 %  A description of each parameter follows:
03067 %
03068 %    o image: the image.
03069 %
03070 %    o image_view: the image cache view.
03071 %
03072 %    o type:  the type of pixel color interpolation.
03073 %
03074 %    o x,y: A double representing the current (x,y) position of the pixel.
03075 %
03076 %    o exception: return any errors or warnings in this structure.
03077 %
03078 */
03079 
03080 static inline double MagickMax(const double x,const double y)
03081 {
03082   if (x > y)
03083     return(x);
03084   return(y);
03085 }
03086 
03087 static void BicubicInterpolate(const MagickPixelPacket *pixels,const double dx,
03088   MagickPixelPacket *pixel)
03089 {
03090   MagickRealType
03091     dx2,
03092     p,
03093     q,
03094     r,
03095     s;
03096 
03097   dx2=dx*dx;
03098   p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red);
03099   q=(pixels[0].red-pixels[1].red)-p;
03100   r=pixels[2].red-pixels[0].red;
03101   s=pixels[1].red;
03102   pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
03103   p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green);
03104   q=(pixels[0].green-pixels[1].green)-p;
03105   r=pixels[2].green-pixels[0].green;
03106   s=pixels[1].green;
03107   pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
03108   p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue);
03109   q=(pixels[0].blue-pixels[1].blue)-p;
03110   r=pixels[2].blue-pixels[0].blue;
03111   s=pixels[1].blue;
03112   pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
03113   p=(pixels[3].opacity-pixels[2].opacity)-(pixels[0].opacity-pixels[1].opacity);
03114   q=(pixels[0].opacity-pixels[1].opacity)-p;
03115   r=pixels[2].opacity-pixels[0].opacity;
03116   s=pixels[1].opacity;
03117   pixel->opacity=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
03118   if (pixel->colorspace == CMYKColorspace)
03119     {
03120       p=(pixels[3].index-pixels[2].index)-(pixels[0].index-pixels[1].index);
03121       q=(pixels[0].index-pixels[1].index)-p;
03122       r=pixels[2].index-pixels[0].index;
03123       s=pixels[1].index;
03124       pixel->index=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
03125     }
03126 }
03127 
03128 static inline MagickRealType CubicWeightingFunction(const MagickRealType x)
03129 {
03130   MagickRealType
03131     alpha,
03132     gamma;
03133 
03134   alpha=MagickMax(x+2.0,0.0);
03135   gamma=1.0*alpha*alpha*alpha;
03136   alpha=MagickMax(x+1.0,0.0);
03137   gamma-=4.0*alpha*alpha*alpha;
03138   alpha=MagickMax(x+0.0,0.0);
03139   gamma+=6.0*alpha*alpha*alpha;
03140   alpha=MagickMax(x-1.0,0.0);
03141   gamma-=4.0*alpha*alpha*alpha;
03142   return(gamma/6.0);
03143 }
03144 
03145 static inline double MeshInterpolate(const PointInfo *delta,const double p,
03146   const double x,const double y)
03147 {
03148   return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
03149 }
03150 
03151 static inline long NearestNeighbor(MagickRealType x)
03152 {
03153   if (x >= 0.0)
03154     return((long) (x+0.5));
03155   return((long) (x-0.5));
03156 }
03157 
03158 MagickExport MagickPixelPacket InterpolatePixelColor(const Image *image,
03159   ViewInfo *image_view,const InterpolatePixelMethod method,const double x,
03160   const double y,ExceptionInfo *exception)
03161 {
03162   MagickPixelPacket
03163     pixel;
03164 
03165   register const IndexPacket
03166     *indexes;
03167 
03168   register const PixelPacket
03169     *p;
03170 
03171   register long
03172     i;
03173 
03174   assert(image != (Image *) NULL);
03175   assert(image->signature == MagickSignature);
03176   assert(image_view != (ViewInfo *) NULL);
03177   GetMagickPixelPacket(image,&pixel);
03178   switch (method)
03179   {
03180     case AverageInterpolatePixel:
03181     {
03182       MagickPixelPacket
03183         pixels[16];
03184 
03185       MagickRealType
03186         alpha[16],
03187         gamma;
03188 
03189       p=GetCacheViewVirtualPixels(image_view,(long) floor(x)-1,(long) floor(y)-1,
03190         4,4,exception);
03191       if (p == (const PixelPacket *) NULL)
03192         break;
03193       indexes=GetCacheViewVirtualIndexQueue(image_view);
03194       for (i=0; i < 16L; i++)
03195       {
03196         GetMagickPixelPacket(image,pixels+i);
03197         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
03198         alpha[i]=1.0;
03199         if (image->matte != MagickFalse)
03200           {
03201             alpha[i]=QuantumScale*((MagickRealType) QuantumRange-p->opacity);
03202             pixels[i].red*=alpha[i];
03203             pixels[i].green*=alpha[i];
03204             pixels[i].blue*=alpha[i];
03205             if (image->colorspace == CMYKColorspace)
03206               pixels[i].index*=alpha[i];
03207           }
03208         gamma=alpha[i];
03209         gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
03210         pixel.red+=gamma*0.0625*pixels[i].red;
03211         pixel.green+=gamma*0.0625*pixels[i].green;
03212         pixel.blue+=gamma*0.0625*pixels[i].blue;
03213         pixel.opacity+=0.0625*pixels[i].opacity;
03214         if (image->colorspace == CMYKColorspace)
03215           pixel.index+=gamma*0.0625*pixels[i].index;
03216         p++;
03217       }
03218       break;
03219     }
03220     case BicubicInterpolatePixel:
03221     {
03222       MagickPixelPacket
03223         pixels[16],
03224         u[4];
03225 
03226       MagickRealType
03227         alpha[16];
03228 
03229       PointInfo
03230         delta;
03231 
03232       p=GetCacheViewVirtualPixels(image_view,(long) floor(x)-1,(long) floor(y)-1,
03233         4,4,exception);
03234       if (p == (const PixelPacket *) NULL)
03235         break;
03236       indexes=GetCacheViewVirtualIndexQueue(image_view);
03237       for (i=0; i < 16L; i++)
03238       {
03239         GetMagickPixelPacket(image,pixels+i);
03240         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
03241         alpha[i]=1.0;
03242         if (image->matte != MagickFalse)
03243           {
03244             alpha[i]=QuantumScale*((MagickRealType) QuantumRange-p->opacity);
03245             pixels[i].red*=alpha[i];
03246             pixels[i].green*=alpha[i];
03247             pixels[i].blue*=alpha[i];
03248             if (image->colorspace == CMYKColorspace)
03249               pixels[i].index*=alpha[i];
03250           }
03251         p++;
03252       }
03253       delta.x=x-floor(x);
03254       for (i=0; i < 4L; i++)
03255         BicubicInterpolate(pixels+4*i,delta.x,u+i);
03256       delta.y=y-floor(y);
03257       BicubicInterpolate(u,delta.y,&pixel);
03258       break;
03259     }
03260     case BilinearInterpolatePixel:
03261     default:
03262     {
03263       MagickPixelPacket
03264         pixels[16];
03265 
03266       MagickRealType
03267         alpha[16],
03268         gamma;
03269 
03270       PointInfo
03271         delta;
03272 
03273       p=GetCacheViewVirtualPixels(image_view,(long) floor(x),(long) floor(y),2,2,
03274         exception);
03275       if (p == (const PixelPacket *) NULL)
03276         break;
03277       indexes=GetCacheViewVirtualIndexQueue(image_view);
03278       for (i=0; i < 4L; i++)
03279       {
03280         GetMagickPixelPacket(image,pixels+i);
03281         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
03282         alpha[i]=1.0;
03283         if (image->matte != MagickFalse)
03284           {
03285             alpha[i]=QuantumScale*((MagickRealType) QuantumRange-p->opacity);
03286             pixels[i].red*=alpha[i];
03287             pixels[i].green*=alpha[i];
03288             pixels[i].blue*=alpha[i];
03289             if (image->colorspace == CMYKColorspace)
03290               pixels[i].index*=alpha[i];
03291           }
03292         p++;
03293       }
03294       delta.x=x-floor(x);
03295       delta.y=y-floor(y);
03296       gamma=(((1.0-delta.y)*((1.0-delta.x)*alpha[0]+delta.x*alpha[1])+delta.y*
03297         ((1.0-delta.x)*alpha[2]+delta.x*alpha[3])));
03298       gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
03299       pixel.red=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].red+delta.x*
03300         pixels[1].red)+delta.y*((1.0-delta.x)*pixels[2].red+delta.x*
03301         pixels[3].red));
03302       pixel.green=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].green+delta.x*
03303         pixels[1].green)+delta.y*((1.0-delta.x)*pixels[2].green+
03304         delta.x*pixels[3].green));
03305       pixel.blue=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].blue+delta.x*
03306         pixels[1].blue)+delta.y*((1.0-delta.x)*pixels[2].blue+delta.x*
03307         pixels[3].blue));
03308       pixel.opacity=((1.0-delta.y)*((1.0-delta.x)*pixels[0].opacity+delta.x*
03309         pixels[1].opacity)+delta.y*((1.0-delta.x)*pixels[2].opacity+delta.x*
03310         pixels[3].opacity));
03311       if (image->colorspace == CMYKColorspace)
03312         pixel.index=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].index+delta.x*
03313           pixels[1].index)+delta.y*((1.0-delta.x)*pixels[2].index+delta.x*
03314           pixels[3].index));
03315       break;
03316     }
03317     case FilterInterpolatePixel:
03318     {
03319       Image
03320         *excerpt_image,
03321         *filter_image;
03322 
03323       MagickPixelPacket
03324         pixels[1];
03325 
03326       RectangleInfo
03327         geometry;
03328 
03329       geometry.width=4L;
03330       geometry.height=4L;
03331       geometry.x=(long) floor(x)-1L;
03332       geometry.y=(long) floor(y)-1L;
03333       excerpt_image=ExcerptImage(image,&geometry,exception);
03334       if (excerpt_image == (Image *) NULL)
03335         break;
03336       filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
03337         exception);
03338       excerpt_image=DestroyImage(excerpt_image);
03339       if (filter_image == (Image *) NULL)
03340         break;
03341       p=GetVirtualPixels(filter_image,0,0,1,1,exception);
03342       if (p == (const PixelPacket *) NULL)
03343         {
03344           filter_image=DestroyImage(filter_image);
03345           break;
03346         }
03347       indexes=GetVirtualIndexQueue(filter_image);
03348       GetMagickPixelPacket(image,pixels);
03349       SetMagickPixelPacket(image,p,indexes,&pixel);
03350       filter_image=DestroyImage(filter_image);
03351       break;
03352     }
03353     case IntegerInterpolatePixel:
03354     {
03355       MagickPixelPacket
03356         pixels[1];
03357 
03358       p=GetCacheViewVirtualPixels(image_view,(long) floor(x),(long) floor(y),1,1,
03359         exception);
03360       if (p == (const PixelPacket *) NULL)
03361         break;
03362       indexes=GetCacheViewVirtualIndexQueue(image_view);
03363       GetMagickPixelPacket(image,pixels);
03364       SetMagickPixelPacket(image,p,indexes,&pixel);
03365       break;
03366     }
03367     case MeshInterpolatePixel:
03368     {
03369       MagickPixelPacket
03370         pixels[4];
03371 
03372       MagickRealType
03373         alpha[4],
03374         gamma;
03375 
03376       PointInfo
03377         delta,
03378         luminance;
03379 
03380       p=GetCacheViewVirtualPixels(image_view,(long) floor(x),(long) floor(y),
03381         2,2,exception);
03382       if (p == (const PixelPacket *) NULL)
03383         break;
03384       indexes=GetCacheViewVirtualIndexQueue(image_view);
03385       for (i=0; i < 4L; i++)
03386       {
03387         GetMagickPixelPacket(image,pixels+i);
03388         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
03389         alpha[i]=1.0;
03390         if (image->matte != MagickFalse)
03391           {
03392             alpha[i]=QuantumScale*((MagickRealType) QuantumRange-p->opacity);
03393             pixels[i].red*=alpha[i];
03394             pixels[i].green*=alpha[i];
03395             pixels[i].blue*=alpha[i];
03396             if (image->colorspace == CMYKColorspace)
03397               pixels[i].index*=alpha[i];
03398           }
03399         p++;
03400       }
03401       delta.x=x-floor(x);
03402       delta.y=y-floor(y);
03403       luminance.x=MagickPixelLuminance(pixels+0)-MagickPixelLuminance(pixels+3);
03404       luminance.y=MagickPixelLuminance(pixels+1)-MagickPixelLuminance(pixels+2);
03405       if (fabs(luminance.x) < fabs(luminance.y))
03406         {
03407           /*
03408             Diagonal 0-3 NW-SE.
03409           */
03410           if (delta.x <= delta.y)
03411             {
03412               /*
03413                 Bottom-left triangle  (pixel:2, diagonal: 0-3).
03414               */
03415               delta.y=1.0-delta.y;
03416               gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
03417               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
03418               pixel.red=gamma*MeshInterpolate(&delta,pixels[2].red,
03419                 pixels[3].red,pixels[0].red);
03420               pixel.green=gamma*MeshInterpolate(&delta,pixels[2].green,
03421                 pixels[3].green,pixels[0].green);
03422               pixel.blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
03423                 pixels[3].blue,pixels[0].blue);
03424               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[2].opacity,
03425                 pixels[3].opacity,pixels[0].opacity);
03426               if (image->colorspace == CMYKColorspace)
03427                 pixel.index=gamma*MeshInterpolate(&delta,pixels[2].index,
03428                   pixels[3].index,pixels[0].index);
03429             }
03430           else
03431             {
03432               /*
03433                 Top-right triangle (pixel:1, diagonal: 0-3).
03434               */
03435               delta.x=1.0-delta.x;
03436               gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
03437               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
03438               pixel.red=gamma*MeshInterpolate(&delta,pixels[1].red,
03439                 pixels[0].red,pixels[3].red);
03440               pixel.green=gamma*MeshInterpolate(&delta,pixels[1].green,
03441                 pixels[0].green,pixels[3].green);
03442               pixel.blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
03443                 pixels[0].blue,pixels[3].blue);
03444               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[1].opacity,
03445                 pixels[0].opacity,pixels[3].opacity);
03446               if (image->colorspace == CMYKColorspace)
03447                 pixel.index=gamma*MeshInterpolate(&delta,pixels[1].index,
03448                   pixels[0].index,pixels[3].index);
03449             }
03450         }
03451       else
03452         {
03453           /*
03454             Diagonal 1-2 NE-SW.
03455           */
03456           if (delta.x <= (1.0-delta.y))
03457             {
03458               /*
03459                 Top-left triangle (pixel 0, diagonal: 1-2).
03460               */
03461               gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
03462               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
03463               pixel.red=gamma*MeshInterpolate(&delta,pixels[0].red,
03464                 pixels[1].red,pixels[2].red);
03465               pixel.green=gamma*MeshInterpolate(&delta,pixels[0].green,
03466                 pixels[1].green,pixels[2].green);
03467               pixel.blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
03468                 pixels[1].blue,pixels[2].blue);
03469               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[0].opacity,
03470                 pixels[1].opacity,pixels[2].opacity);
03471               if (image->colorspace == CMYKColorspace)
03472                 pixel.index=gamma*MeshInterpolate(&delta,pixels[0].index,
03473                   pixels[1].index,pixels[2].index);
03474             }
03475           else
03476             {
03477               /*
03478                 Bottom-right triangle (pixel: 3, diagonal: 1-2).
03479               */
03480               delta.x=1.0-delta.x;
03481               delta.y=1.0-delta.y;
03482               gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
03483               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
03484               pixel.red=gamma*MeshInterpolate(&delta,pixels[3].red,
03485                 pixels[2].red,pixels[1].red);
03486               pixel.green=gamma*MeshInterpolate(&delta,pixels[3].green,
03487                 pixels[2].green,pixels[1].green);
03488               pixel.blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
03489                 pixels[2].blue,pixels[1].blue);
03490               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[3].opacity,
03491                 pixels[2].opacity,pixels[1].opacity);
03492               if (image->colorspace == CMYKColorspace)
03493                 pixel.index=gamma*MeshInterpolate(&delta,pixels[3].index,
03494                   pixels[2].index,pixels[1].index);
03495             }
03496         }
03497       break;
03498     }
03499     case NearestNeighborInterpolatePixel:
03500     {
03501       MagickPixelPacket
03502         pixels[1];
03503 
03504       p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),NearestNeighbor(y),
03505         1,1,exception);
03506       if (p == (const PixelPacket *) NULL)
03507         break;
03508       indexes=GetCacheViewVirtualIndexQueue(image_view);
03509       GetMagickPixelPacket(image,pixels);
03510       SetMagickPixelPacket(image,p,indexes,&pixel);
03511       break;
03512     }
03513     case SplineInterpolatePixel:
03514     {
03515       long
03516         j,
03517         n;
03518 
03519       MagickPixelPacket
03520         pixels[16];
03521 
03522       MagickRealType
03523         alpha[16],
03524         dx,
03525         dy,
03526         gamma;
03527 
03528       PointInfo
03529         delta;
03530 
03531       p=GetCacheViewVirtualPixels(image_view,(long) floor(x)-1,(long) floor(y)-1,
03532         4,4,exception);
03533       if (p == (const PixelPacket *) NULL)
03534         break;
03535       indexes=GetCacheViewVirtualIndexQueue(image_view);
03536       n=0;
03537       delta.x=x-floor(x);
03538       delta.y=y-floor(y);
03539       for (i=(-1); i < 3L; i++)
03540       {
03541         dy=CubicWeightingFunction((MagickRealType) i-delta.y);
03542         for (j=(-1); j < 3L; j++)
03543         {
03544           GetMagickPixelPacket(image,pixels+n);
03545           SetMagickPixelPacket(image,p,indexes+n,pixels+n);
03546           alpha[n]=1.0;
03547           if (image->matte != MagickFalse)
03548             {
03549               alpha[n]=QuantumScale*((MagickRealType) QuantumRange-p->opacity);
03550               pixels[n].red*=alpha[n];
03551               pixels[n].green*=alpha[n];
03552               pixels[n].blue*=alpha[n];
03553               if (image->colorspace == CMYKColorspace)
03554                 pixels[n].index*=alpha[n];
03555             }
03556           dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
03557           gamma=alpha[n];
03558           gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
03559           pixel.red+=gamma*dx*dy*pixels[n].red;
03560           pixel.green+=gamma*dx*dy*pixels[n].green;
03561           pixel.blue+=gamma*dx*dy*pixels[n].blue;
03562           if (image->matte != MagickFalse)
03563             pixel.opacity+=dx*dy*pixels[n].opacity;
03564           if (image->colorspace == CMYKColorspace)
03565             pixel.index+=gamma*dx*dy*pixels[n].index;
03566           n++;
03567           p++;
03568         }
03569       }
03570       break;
03571     }
03572   }
03573   return(pixel);
03574 }
03575 
03576 /*
03577 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03578 %                                                                             %
03579 %                                                                             %
03580 %                                                                             %
03581 %   I n t e r p r e t I m a g e A t t r i b u t e s                           %
03582 %                                                                             %
03583 %                                                                             %
03584 %                                                                             %
03585 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03586 %
03587 %  InterpretImageAttributes() replaces any embedded formatting characters with
03588 %  the appropriate image attribute and returns the translated text.
03589 %
03590 %  The format of the InterpretImageAttributes method is:
03591 %
03592 %      char *InterpretImageAttributes(const ImageInfo *image_info,Image *image,
03593 %        const char *embed_text)
03594 %
03595 %  A description of each parameter follows:
03596 %
03597 %    o image_info: the image info.
03598 %
03599 %    o image: the image.
03600 %
03601 %    o embed_text: the address of a character string containing the embedded
03602 %      formatting characters.
03603 %
03604 */
03605 MagickExport char *InterpretImageAttributes(const ImageInfo *image_info,
03606   Image *image,const char *embed_text)
03607 {
03608   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.3.1");
03609   return(InterpretImageProperties(image_info,image,embed_text));
03610 }
03611 
03612 /*
03613 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03614 %                                                                             %
03615 %                                                                             %
03616 %                                                                             %
03617 +     I s S u b i m a g e                                                     %
03618 %                                                                             %
03619 %                                                                             %
03620 %                                                                             %
03621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03622 %
03623 %  IsSubimage() returns MagickTrue if the geometry is a valid subimage
03624 %  specification (e.g. [1], [1-9], [1,7,4]).
03625 %
03626 %  The format of the IsSubimage method is:
03627 %
03628 %      unsigned int IsSubimage(const char *geometry,const unsigned int pedantic)
03629 %
03630 %  A description of each parameter follows:
03631 %
03632 %    o geometry: This string is the geometry specification.
03633 %
03634 %    o pedantic: A value other than 0 invokes a more restrictive set of
03635 %      conditions for a valid specification (e.g. [1], [1-4], [4-1]).
03636 %
03637 */
03638 MagickExport unsigned int IsSubimage(const char *geometry,
03639   const unsigned int pedantic)
03640 {
03641   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
03642   if (geometry == (const char *) NULL)
03643     return(MagickFalse);
03644   if ((strchr(geometry,'x') != (char *) NULL) ||
03645       (strchr(geometry,'X') != (char *) NULL))
03646     return(MagickFalse);
03647   if ((pedantic != MagickFalse) && (strchr(geometry,',') != (char *) NULL))
03648     return(MagickFalse);
03649   return(MagickTrue);
03650 }
03651 
03652 /*
03653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03654 %                                                                             %
03655 %                                                                             %
03656 %                                                                             %
03657 %   L i b e r a t e M e m o r y                                               %
03658 %                                                                             %
03659 %                                                                             %
03660 %                                                                             %
03661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03662 %
03663 %  LiberateMemory() frees memory that has already been allocated, and NULL's
03664 %  the pointer to it.
03665 %
03666 %  The format of the LiberateMemory method is:
03667 %
03668 %      void LiberateMemory(void **memory)
03669 %
03670 %  A description of each parameter follows:
03671 %
03672 %    o memory: A pointer to a block of memory to free for reuse.
03673 %
03674 */
03675 MagickExport void LiberateMemory(void **memory)
03676 {
03677   assert(memory != (void **) NULL);
03678   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
03679   if (*memory == (void *) NULL)
03680     return;
03681   free(*memory);
03682   *memory=(void *) NULL;
03683 }
03684 
03685 /*
03686 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03687 %                                                                             %
03688 %                                                                             %
03689 %                                                                             %
03690 %   L i b e r a t e S e m a p h o r e I n f o                                 %
03691 %                                                                             %
03692 %                                                                             %
03693 %                                                                             %
03694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03695 %
03696 %  LiberateSemaphoreInfo() relinquishes a semaphore.
03697 %
03698 %  The format of the LiberateSemaphoreInfo method is:
03699 %
03700 %      LiberateSemaphoreInfo(void **semaphore_info)
03701 %
03702 %  A description of each parameter follows:
03703 %
03704 %    o semaphore_info: Specifies a pointer to an SemaphoreInfo structure.
03705 %
03706 */
03707 MagickExport void LiberateSemaphoreInfo(SemaphoreInfo **semaphore_info)
03708 {
03709   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
03710   RelinquishSemaphoreInfo(*semaphore_info);
03711 }
03712 
03713 /*
03714 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03715 %                                                                             %
03716 %                                                                             %
03717 %                                                                             %
03718 %   M a g i c k I n c a r n a t e                                             %
03719 %                                                                             %
03720 %                                                                             %
03721 %                                                                             %
03722 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03723 %
03724 %  MagickIncarnate() initializes the ImageMagick environment.
03725 %
03726 %  The format of the MagickIncarnate function is:
03727 %
03728 %      MagickIncarnate(const char *path)
03729 %
03730 %  A description of each parameter follows:
03731 %
03732 %    o path: the execution path of the current ImageMagick client.
03733 %
03734 */
03735 
03736 MagickExport void MagickIncarnate(const char *path)
03737 {
03738   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1");
03739   InitializeMagick(path);
03740 }
03741 
03742 /*
03743 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03744 %                                                                             %
03745 %                                                                             %
03746 %                                                                             %
03747 %   M a g i c k M o n i t o r                                                 %
03748 %                                                                             %
03749 %                                                                             %
03750 %                                                                             %
03751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03752 %
03753 %  MagickMonitor() calls the monitor handler method with a text string that
03754 %  describes the task and a measure of completion.  The method returns
03755 %  MagickTrue on success otherwise MagickFalse if an error is encountered, e.g.
03756 %  if there was a user interrupt.
03757 %
03758 %  The format of the MagickMonitor method is:
03759 %
03760 %      MagickBooleanType MagickMonitor(const char *text,
03761 %        const MagickOffsetType offset,const MagickSizeType span,
03762 %        void *client_data)
03763 %
03764 %  A description of each parameter follows:
03765 %
03766 %    o offset: the position relative to the span parameter which represents
03767 %      how much progress has been made toward completing a task.
03768 %
03769 %    o span: the span relative to completing a task.
03770 %
03771 %    o client_data: the client data.
03772 %
03773 */
03774 MagickExport MagickBooleanType MagickMonitor(const char *text,
03775   const MagickOffsetType offset,const MagickSizeType span,
03776   void *magick_unused(client_data))
03777 {
03778   ExceptionInfo
03779     *exception;
03780 
03781   MagickBooleanType
03782     status;
03783 
03784   assert(text != (const char *) NULL);
03785   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",text);
03786   ProcessPendingEvents(text);
03787   status=MagickTrue;
03788   exception=AcquireExceptionInfo();
03789   if (monitor_handler != (MonitorHandler) NULL)
03790     status=(*monitor_handler)(text,offset,span,exception);
03791   exception=DestroyExceptionInfo(exception);
03792   return(status);
03793 }
03794 
03795 /*
03796 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03797 %                                                                             %
03798 %                                                                             %
03799 %                                                                             %
03800 %   M a p I m a g e                                                           %
03801 %                                                                             %
03802 %                                                                             %
03803 %                                                                             %
03804 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03805 %
03806 %  MapImage() replaces the colors of an image with the closest color from a
03807 %  reference image.
03808 %
03809 %  The format of the MapImage method is:
03810 %
03811 %      MagickBooleanType MapImage(Image *image,const Image *map_image,
03812 %        const MagickBooleanType dither)
03813 %
03814 %  A description of each parameter follows:
03815 %
03816 %    o image: Specifies a pointer to an Image structure.
03817 %
03818 %    o map_image: the image.  Reduce image to a set of colors represented by
03819 %      this image.
03820 %
03821 %    o dither: Set this integer value to something other than zero to
03822 %      dither the mapped image.
03823 %
03824 */
03825 MagickExport MagickBooleanType MapImage(Image *image,const Image *map_image,
03826   const MagickBooleanType dither)
03827 {
03828   QuantizeInfo
03829     quantize_info;
03830 
03831   /*
03832     Initialize color cube.
03833   */
03834   assert(image != (Image *) NULL);
03835   assert(image->signature == MagickSignature);
03836   if (image->debug != MagickFalse)
03837     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
03838   assert(map_image != (Image *) NULL);
03839   assert(map_image->signature == MagickSignature);
03840   GetQuantizeInfo(&quantize_info);
03841   quantize_info.dither=dither;
03842   return(RemapImage(&quantize_info,image,map_image));
03843 }
03844 
03845 /*
03846 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03847 %                                                                             %
03848 %                                                                             %
03849 %                                                                             %
03850 %   M a p I m a g e s                                                         %
03851 %                                                                             %
03852 %                                                                             %
03853 %                                                                             %
03854 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03855 %
03856 %  MapImages() replaces the colors of a sequence of images with the closest
03857 %  color from a reference image.
03858 %
03859 %  The format of the MapImage method is:
03860 %
03861 %      MagickBooleanType MapImages(Image *images,Image *map_image,
03862 %        const MagickBooleanType dither)
03863 %
03864 %  A description of each parameter follows:
03865 %
03866 %    o image: Specifies a pointer to a set of Image structures.
03867 %
03868 %    o map_image: the image.  Reduce image to a set of colors represented by
03869 %      this image.
03870 %
03871 %    o dither: Set this integer value to something other than zero to
03872 %      dither the quantized image.
03873 %
03874 */
03875 MagickExport MagickBooleanType MapImages(Image *images,const Image *map_image,
03876   const MagickBooleanType dither)
03877 {
03878   QuantizeInfo
03879     quantize_info;
03880 
03881   assert(images != (Image *) NULL);
03882   assert(images->signature == MagickSignature);
03883   if (images->debug != MagickFalse)
03884     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
03885   GetQuantizeInfo(&quantize_info);
03886   quantize_info.dither=dither;
03887   return(RemapImages(&quantize_info,images,map_image));
03888 }
03889 
03890 /*
03891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03892 %                                                                             %
03893 %                                                                             %
03894 %                                                                             %
03895 %   M a t t e F l o o d f i l l I m a g e                                     %
03896 %                                                                             %
03897 %                                                                             %
03898 %                                                                             %
03899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
03900 %
03901 %  MatteFloodfill() changes the transparency value of any pixel that matches
03902 %  target and is an immediate neighbor.  If the method FillToBorderMethod
03903 %  is specified, the transparency value is changed for any neighbor pixel
03904 %  that does not match the bordercolor member of image.
03905 %
03906 %  By default target must match a particular pixel transparency exactly.
03907 %  However, in many cases two transparency values may differ by a
03908 %  small amount.  The fuzz member of image defines how much tolerance is
03909 %  acceptable to consider two transparency values as the same.  For example,
03910 %  set fuzz to 10 and the opacity values of 100 and 102 respectively are
03911 %  now interpreted as the same value for the purposes of the floodfill.
03912 %
03913 %  The format of the MatteFloodfillImage method is:
03914 %
03915 %      MagickBooleanType MatteFloodfillImage(Image *image,
03916 %        const PixelPacket target,const Quantum opacity,const long x_offset,
03917 %        const long y_offset,const PaintMethod method)
03918 %
03919 %  A description of each parameter follows:
03920 %
03921 %    o image: the image.
03922 %
03923 %    o target: the RGB value of the target color.
03924 %
03925 %    o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
03926 %      fully transparent.
03927 %
03928 %    o x,y: the starting location of the operation.
03929 %
03930 %    o method:  Choose either FloodfillMethod or FillToBorderMethod.
03931 %
03932 */
03933 MagickExport MagickBooleanType MatteFloodfillImage(Image *image,
03934   const PixelPacket target,const Quantum opacity,const long x_offset,
03935   const long y_offset,const PaintMethod method)
03936 {
03937   Image
03938     *floodplane_image;
03939 
03940   long
03941     offset,
03942     start,
03943     x,
03944     x1,
03945     x2,
03946     y;
03947 
03948   MagickBooleanType
03949     skip;
03950 
03951   register SegmentInfo
03952     *s;
03953 
03954   SegmentInfo
03955     *segment_stack;
03956 
03957   /*
03958     Check boundary conditions.
03959   */
03960   assert(image != (Image *) NULL);
03961   assert(image->signature == MagickSignature);
03962   if (image->debug != MagickFalse)
03963     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
03964   if ((x_offset < 0) || (x_offset >= (long) image->columns))
03965     return(MagickFalse);
03966   if ((y_offset < 0) || (y_offset >= (long) image->rows))
03967     return(MagickFalse);
03968   if (SetImageStorageClass(image,DirectClass) == MagickFalse)
03969     return(MagickFalse);
03970   if (image->matte == MagickFalse)
03971     (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
03972   floodplane_image=CloneImage(image,image->columns,image->rows,MagickTrue,
03973     &image->exception);
03974   if (floodplane_image == (Image *) NULL)
03975     return(MagickFalse);
03976   (void) SetImageAlphaChannel(floodplane_image,OpaqueAlphaChannel);
03977   /*
03978     Set floodfill color.
03979   */
03980   segment_stack=(SegmentInfo *) AcquireQuantumMemory(MaxStacksize,
03981     sizeof(*segment_stack));
03982   if (segment_stack == (SegmentInfo *) NULL)
03983     {
03984       floodplane_image=DestroyImage(floodplane_image);
03985       ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
03986         image->filename);
03987     }
03988   /*
03989     Push initial segment on stack.
03990   */
03991   x=x_offset;
03992   y=y_offset;
03993   start=0;
03994   s=segment_stack;
03995   PushSegmentStack(y,x,x,1);
03996   PushSegmentStack(y+1,x,x,-1);
03997   while (s > segment_stack)
03998   {
03999     register const PixelPacket
04000       *__restrict p;
04001 
04002     register long
04003       x;
04004 
04005     register PixelPacket
04006       *__restrict q;
04007 
04008     /*
04009       Pop segment off stack.
04010     */
04011     s--;
04012     x1=(long) s->x1;
04013     x2=(long) s->x2;
04014     offset=(long) s->y2;
04015     y=(long) s->y1+offset;
04016     /*
04017       Recolor neighboring pixels.
04018     */
04019     p=GetVirtualPixels(image,0,y,(unsigned long) (x1+1),1,&image->exception);
04020     q=GetAuthenticPixels(floodplane_image,0,y,(unsigned long) (x1+1),1,
04021       &image->exception);
04022     if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
04023       break;
04024     p+=x1;
04025     q+=x1;
04026     for (x=x1; x >= 0; x--)
04027     {
04028       if (q->opacity == (Quantum) TransparentOpacity)
04029         break;
04030       if (method == FloodfillMethod)
04031         {
04032           if (IsColorSimilar(image,p,&target) == MagickFalse)
04033             break;
04034         }
04035       else
04036         if (IsColorSimilar(image,p,&target) != MagickFalse)
04037           break;
04038       q->opacity=(Quantum) TransparentOpacity;
04039       q--;
04040       p--;
04041     }
04042     if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse)
04043       break;
04044     skip=x >= x1 ? MagickTrue : MagickFalse;
04045     if (skip == MagickFalse)
04046       {
04047         start=x+1;
04048         if (start < x1)
04049           PushSegmentStack(y,start,x1-1,-offset);
04050         x=x1+1;
04051       }
04052     do
04053     {
04054       if (skip == MagickFalse)
04055         {
04056           if (x < (long) image->columns)
04057             {
04058               p=GetVirtualPixels(image,x,y,image->columns-x,1,
04059                 &image->exception);
04060               q=GetAuthenticPixels(floodplane_image,x,y,image->columns-x,1,
04061                 &image->exception);
04062               if ((p == (const PixelPacket *) NULL) ||
04063                   (q == (PixelPacket *) NULL))
04064                 break;
04065               for ( ; x < (long) image->columns; x++)
04066               {
04067                 if (q->opacity == (Quantum) TransparentOpacity)
04068                   break;
04069                 if (method == FloodfillMethod)
04070                   {
04071                     if (IsColorSimilar(image,p,&target) == MagickFalse)
04072                       break;
04073                   }
04074                 else
04075                   if (IsColorSimilar(image,p,&target) != MagickFalse)
04076                     break;
04077                 q->opacity=(Quantum) TransparentOpacity;
04078                 q++;
04079                 p++;
04080               }
04081               if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse)
04082                 break;
04083             }
04084           PushSegmentStack(y,start,x-1,offset);
04085           if (x > (x2+1))
04086             PushSegmentStack(y,x2+1,x-1,-offset);
04087         }
04088       skip=MagickFalse;
04089       x++;
04090       if (x <= x2)
04091         {
04092           p=GetVirtualPixels(image,x,y,(unsigned long) (x2-x+1),1,
04093             &image->exception);
04094           q=GetAuthenticPixels(floodplane_image,x,y,(unsigned long) (x2-x+1),1,
04095             &image->exception);
04096           if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
04097             break;
04098           for ( ; x <= x2; x++)
04099           {
04100             if (q->opacity == (Quantum) TransparentOpacity)
04101               break;
04102             if (method == FloodfillMethod)
04103               {
04104                 if (IsColorSimilar(image,p,&target) != MagickFalse)
04105                   break;
04106               }
04107             else
04108               if (IsColorSimilar(image,p,&target) == MagickFalse)
04109                 break;
04110             p++;
04111             q++;
04112           }
04113         }
04114       start=x;
04115     } while (x <= x2);
04116   }
04117   for (y=0; y < (long) image->rows; y++)
04118   {
04119     register const PixelPacket
04120       *__restrict p;
04121 
04122     register long
04123       x;
04124 
04125     register PixelPacket
04126       *__restrict q;
04127 
04128     /*
04129       Tile fill color onto floodplane.
04130     */
04131     p=GetVirtualPixels(floodplane_image,0,y,image->columns,1,
04132       &image->exception);
04133     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
04134     if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
04135       break;
04136     for (x=0; x < (long) image->columns; x++)
04137     {
04138       if (p->opacity != OpaqueOpacity)
04139         q->opacity=opacity;
04140       p++;
04141       q++;
04142     }
04143     if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
04144       break;
04145   }
04146   segment_stack=(SegmentInfo *) RelinquishMagickMemory(segment_stack);
04147   floodplane_image=DestroyImage(floodplane_image);
04148   return(y == (long) image->rows ? MagickTrue : MagickFalse);
04149 }
04150 
04151 /*
04152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04153 %                                                                             %
04154 %                                                                             %
04155 %                                                                             %
04156 %     M o s a i c I m a g e s                                                 %
04157 %                                                                             %
04158 %                                                                             %
04159 %                                                                             %
04160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04161 %
04162 %  MosaicImages() Obsolete Function: Use MergeImageLayers() instead.
04163 %
04164 %  The format of the MosaicImage method is:
04165 %
04166 %      Image *MosaicImages(const Image *image,ExceptionInfo *exception)
04167 %
04168 %  A description of each parameter follows:
04169 %
04170 %    o image: the image list to be composited together
04171 %
04172 %    o exception: return any errors or warnings in this structure.
04173 %
04174 */
04175 MagickExport Image *MosaicImages(Image *image,ExceptionInfo *exception)
04176 {
04177   return(MergeImageLayers(image,MosaicLayer,exception));
04178 }
04179 
04180 /*
04181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04182 %                                                                             %
04183 %                                                                             %
04184 %                                                                             %
04185 %     O p a q u e I m a g e                                                   %
04186 %                                                                             %
04187 %                                                                             %
04188 %                                                                             %
04189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04190 %
04191 %  OpaqueImage() changes any pixel that matches color with the color
04192 %  defined by fill.
04193 %
04194 %  By default color must match a particular pixel color exactly.  However,
04195 %  in many cases two colors may differ by a small amount.  Fuzz defines
04196 %  how much tolerance is acceptable to consider two colors as the same.
04197 %  For example, set fuzz to 10 and the color red at intensities of 100 and
04198 %  102 respectively are now interpreted as the same color.
04199 %
04200 %  The format of the OpaqueImage method is:
04201 %
04202 %      MagickBooleanType OpaqueImage(Image *image,
04203 %        const PixelPacket *target,const PixelPacket fill)
04204 %
04205 %  A description of each parameter follows:
04206 %
04207 %    o image: the image.
04208 %
04209 %    o target: the RGB value of the target color.
04210 %
04211 %    o fill: the replacement color.
04212 %
04213 */
04214 MagickExport MagickBooleanType OpaqueImage(Image *image,
04215   const PixelPacket target,const PixelPacket fill)
04216 {
04217 #define OpaqueImageTag  "Opaque/Image"
04218 
04219   long
04220     y;
04221 
04222   MagickBooleanType
04223     proceed;
04224 
04225   register long
04226     i;
04227 
04228   /*
04229     Make image color opaque.
04230   */
04231   assert(image != (Image *) NULL);
04232   assert(image->signature == MagickSignature);
04233   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.1.0");
04234   if (image->debug != MagickFalse)
04235     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
04236   switch (image->storage_class)
04237   {
04238     case DirectClass:
04239     default:
04240     {
04241       /*
04242         Make DirectClass image opaque.
04243       */
04244       for (y=0; y < (long) image->rows; y++)
04245       {
04246         register long
04247           x;
04248 
04249         register PixelPacket
04250           *__restrict q;
04251 
04252         q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
04253         if (q == (PixelPacket *) NULL)
04254           break;
04255         for (x=0; x < (long) image->columns; x++)
04256         {
04257           if (IsColorSimilar(image,q,&target) != MagickFalse)
04258             *q=fill;
04259           q++;
04260         }
04261         if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
04262           break;
04263         proceed=SetImageProgress(image,OpaqueImageTag,y,image->rows);
04264         if (proceed == MagickFalse)
04265           break;
04266       }
04267       break;
04268     }
04269     case PseudoClass:
04270     {
04271       /*
04272         Make PseudoClass image opaque.
04273       */
04274       for (i=0; i < (long) image->colors; i++)
04275       {
04276         if (IsColorSimilar(image,&image->colormap[i],&target) != MagickFalse)
04277           image->colormap[i]=fill;
04278       }
04279       if (fill.opacity != OpaqueOpacity)
04280         {
04281           for (y=0; y < (long) image->rows; y++)
04282           {
04283             register long
04284               x;
04285 
04286             register PixelPacket
04287               *__restrict q;
04288 
04289             q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
04290             if (q == (PixelPacket *) NULL)
04291               break;
04292             for (x=0; x < (long) image->columns; x++)
04293             {
04294               if (IsColorSimilar(image,q,&target) != MagickFalse)
04295                 q->opacity=fill.opacity;
04296               q++;
04297             }
04298             if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
04299               break;
04300           }
04301         }
04302       (void) SyncImage(image);
04303       break;
04304     }
04305   }
04306   if (fill.opacity != OpaqueOpacity)
04307     image->matte=MagickTrue;
04308   return(MagickTrue);
04309 }
04310 
04311 /*
04312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04313 %                                                                             %
04314 %                                                                             %
04315 %                                                                             %
04316 %   O p e n C a c h e V i e w                                                 %
04317 %                                                                             %
04318 %                                                                             %
04319 %                                                                             %
04320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04321 %
04322 %  OpenCacheView() opens a view into the pixel cache, using the
04323 %  VirtualPixelMethod that is defined within the given image itself.
04324 %
04325 %  The format of the OpenCacheView method is:
04326 %
04327 %      ViewInfo *OpenCacheView(const Image *image)
04328 %
04329 %  A description of each parameter follows:
04330 %
04331 %    o image: the image.
04332 %
04333 */
04334 MagickExport ViewInfo *OpenCacheView(const Image *image)
04335 {
04336   return(AcquireCacheView(image));
04337 }
04338 
04339 /*
04340 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04341 %                                                                             %
04342 %                                                                             %
04343 %                                                                             %
04344 %   P a i n t F l o o d f i l l I m a g e                                     %
04345 %                                                                             %
04346 %                                                                             %
04347 %                                                                             %
04348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04349 %
04350 %  PaintFloodfill() changes the color value of any pixel that matches
04351 %  target and is an immediate neighbor.  If the method FillToBorderMethod is
04352 %  specified, the color value is changed for any neighbor pixel that does not
04353 %  match the bordercolor member of image.
04354 %
04355 %  By default target must match a particular pixel color exactly.
04356 %  However, in many cases two colors may differ by a small amount.  The
04357 %  fuzz member of image defines how much tolerance is acceptable to
04358 %  consider two colors as the same.  For example, set fuzz to 10 and the
04359 %  color red at intensities of 100 and 102 respectively are now
04360 %  interpreted as the same color for the purposes of the floodfill.
04361 %
04362 %  The format of the PaintFloodfillImage method is:
04363 %
04364 %      MagickBooleanType PaintFloodfillImage(Image *image,
04365 %        const ChannelType channel,const MagickPixelPacket target,const long x,
04366 %        const long y,const DrawInfo *draw_info,const PaintMethod method)
04367 %
04368 %  A description of each parameter follows:
04369 %
04370 %    o image: the image.
04371 %
04372 %    o channel: the channel(s).
04373 %
04374 %    o target: the RGB value of the target color.
04375 %
04376 %    o x,y: the starting location of the operation.
04377 %
04378 %    o draw_info: the draw info.
04379 %
04380 %    o method: Choose either FloodfillMethod or FillToBorderMethod.
04381 %
04382 */
04383 MagickExport MagickBooleanType PaintFloodfillImage(Image *image,
04384   const ChannelType channel,const MagickPixelPacket *target,const long x,
04385   const long y,const DrawInfo *draw_info,const PaintMethod method)
04386 {
04387   MagickBooleanType
04388     status;
04389 
04390   status=FloodfillPaintImage(image,channel,draw_info,target,x,y,
04391     method == FloodfillMethod ? MagickFalse : MagickTrue);
04392   return(status);
04393 }
04394 
04395 /*
04396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04397 %                                                                             %
04398 %                                                                             %
04399 %     P a i n t O p a q u e I m a g e                                         %
04400 %                                                                             %
04401 %                                                                             %
04402 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04403 %
04404 %  PaintOpaqueImage() changes any pixel that matches color with the color
04405 %  defined by fill.
04406 %
04407 %  By default color must match a particular pixel color exactly.  However,
04408 %  in many cases two colors may differ by a small amount.  Fuzz defines
04409 %  how much tolerance is acceptable to consider two colors as the same.
04410 %  For example, set fuzz to 10 and the color red at intensities of 100 and
04411 %  102 respectively are now interpreted as the same color.
04412 %
04413 %  The format of the PaintOpaqueImage method is:
04414 %
04415 %      MagickBooleanType PaintOpaqueImage(Image *image,
04416 %        const PixelPacket *target,const PixelPacket *fill)
04417 %      MagickBooleanType PaintOpaqueImageChannel(Image *image,
04418 %        const ChannelType channel,const PixelPacket *target,
04419 %        const PixelPacket *fill)
04420 %
04421 %  A description of each parameter follows:
04422 %
04423 %    o image: the image.
04424 %
04425 %    o channel: the channel(s).
04426 %
04427 %    o target: the RGB value of the target color.
04428 %
04429 %    o fill: the replacement color.
04430 %
04431 */
04432 
04433 MagickExport MagickBooleanType PaintOpaqueImage(Image *image,
04434   const MagickPixelPacket *target,const MagickPixelPacket *fill)
04435 {
04436   return(PaintOpaqueImageChannel(image,DefaultChannels,target,fill));
04437 }
04438 
04439 MagickExport MagickBooleanType PaintOpaqueImageChannel(Image *image,
04440   const ChannelType channel,const MagickPixelPacket *target,
04441   const MagickPixelPacket *fill)
04442 {
04443   return(OpaquePaintImageChannel(image,channel,target,fill,MagickFalse));
04444 }
04445 
04446 /*
04447 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04448 %                                                                             %
04449 %                                                                             %
04450 %                                                                             %
04451 %     P a i n t T r a n s p a r e n t I m a g e                               %
04452 %                                                                             %
04453 %                                                                             %
04454 %                                                                             %
04455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04456 %
04457 %  PaintTransparentImage() changes the opacity value associated with any pixel
04458 %  that matches color to the value defined by opacity.
04459 %
04460 %  By default color must match a particular pixel color exactly.  However,
04461 %  in many cases two colors may differ by a small amount.  Fuzz defines
04462 %  how much tolerance is acceptable to consider two colors as the same.
04463 %  For example, set fuzz to 10 and the color red at intensities of 100 and
04464 %  102 respectively are now interpreted as the same color.
04465 %
04466 %  The format of the PaintTransparentImage method is:
04467 %
04468 %      MagickBooleanType PaintTransparentImage(Image *image,
04469 %        const MagickPixelPacket *target,const Quantum opacity)
04470 %
04471 %  A description of each parameter follows:
04472 %
04473 %    o image: the image.
04474 %
04475 %    o target: the RGB value of the target color.
04476 %
04477 %    o opacity: the replacement opacity value.
04478 %
04479 */
04480 MagickExport MagickBooleanType PaintTransparentImage(Image *image,
04481   const MagickPixelPacket *target,const Quantum opacity)
04482 {
04483   return(TransparentPaintImage(image,target,opacity,MagickFalse));
04484 }
04485 
04486 /*
04487 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04488 %                                                                             %
04489 %                                                                             %
04490 %                                                                             %
04491 +   P a r s e I m a g e G e o m e t r y                                       %
04492 %                                                                             %
04493 %                                                                             %
04494 %                                                                             %
04495 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04496 %
04497 %  ParseImageGeometry() is similar to GetGeometry() except the returned
04498 %  geometry is modified as determined by the meta characters:  %, !, <,
04499 %  and >.
04500 %
04501 %  The format of the ParseImageGeometry method is:
04502 %
04503 %      int ParseImageGeometry(char *geometry,long *x,long *y,
04504 %        unsigned long *width,unsigned long *height)
04505 %
04506 %  A description of each parameter follows:
04507 %
04508 %    o flags:  Method ParseImageGeometry returns a bitmask that indicates
04509 %      which of the four values were located in the geometry string.
04510 %
04511 %    o image_geometry:  Specifies a character string representing the geometry
04512 %      specification.
04513 %
04514 %    o x,y:  A pointer to an integer.  The x and y offset as determined by
04515 %      the geometry specification is returned here.
04516 %
04517 %    o width,height:  A pointer to an unsigned integer.  The width and height
04518 %      as determined by the geometry specification is returned here.
04519 %
04520 */
04521 MagickExport int ParseImageGeometry(const char *geometry,long *x,long *y,
04522   unsigned long *width,unsigned long *height)
04523 {
04524   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1");
04525   return((int) ParseMetaGeometry(geometry,x,y,width,height));
04526 }
04527 
04528 /*
04529 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04530 %                                                                             %
04531 %                                                                             %
04532 %                                                                             %
04533 %   P a r s e S i z e G e o m e t r y                                         %
04534 %                                                                             %
04535 %                                                                             %
04536 %                                                                             %
04537 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04538 %
04539 %  ParseSizeGeometry() returns a region as defined by the geometry string with
04540 %  respect to the image dimensions and aspect ratio.
04541 %
04542 %  The format of the ParseSizeGeometry method is:
04543 %
04544 %      MagickStatusType ParseSizeGeometry(const Image *image,
04545 %        const char *geometry,RectangeInfo *region_info)
04546 %
04547 %  A description of each parameter follows:
04548 %
04549 %    o geometry:  The geometry (e.g. 100x100+10+10).
04550 %
04551 %    o region_info: the region as defined by the geometry string.
04552 %
04553 */
04554 MagickExport MagickStatusType ParseSizeGeometry(const Image *image,
04555   const char *geometry,RectangleInfo *region_info)
04556 {
04557   MagickStatusType
04558     flags;
04559 
04560   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.4.7");
04561   SetGeometry(image,region_info);
04562   flags=ParseMetaGeometry(geometry,&region_info->x,&region_info->y,
04563     &region_info->width,&region_info->height);
04564   return(flags);
04565 }
04566 
04567 /*
04568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04569 %                                                                             %
04570 %                                                                             %
04571 %                                                                             %
04572 %   P o p I m a g e L i s t                                                   %
04573 %                                                                             %
04574 %                                                                             %
04575 %                                                                             %
04576 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04577 %
04578 %  PopImageList() removes the last image in the list.
04579 %
04580 %  The format of the PopImageList method is:
04581 %
04582 %      Image *PopImageList(Image **images)
04583 %
04584 %  A description of each parameter follows:
04585 %
04586 %    o images: the image list.
04587 %
04588 */
04589 MagickExport Image *PopImageList(Image **images)
04590 {
04591   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
04592   return(RemoveLastImageFromList(images));
04593 }
04594 
04595 /*
04596 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04597 %                                                                             %
04598 %                                                                             %
04599 %                                                                             %
04600 %   P o p I m a g e P i x e l s                                               %
04601 %                                                                             %
04602 %                                                                             %
04603 %                                                                             %
04604 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04605 %
04606 %  PopImagePixels() transfers one or more pixel components from the image pixel
04607 %  cache to a user supplied buffer.  The pixels are returned in network byte
04608 %  order.  MagickTrue is returned if the pixels are successfully transferred,
04609 %  otherwise MagickFalse.
04610 %
04611 %  The format of the PopImagePixels method is:
04612 %
04613 %      size_t PopImagePixels(Image *,const QuantumType quantum,
04614 %        unsigned char *destination)
04615 %
04616 %  A description of each parameter follows:
04617 %
04618 %    o image: the image.
04619 %
04620 %    o quantum: Declare which pixel components to transfer (RGB, RGBA, etc).
04621 %
04622 %    o destination:  The components are transferred to this buffer.
04623 %
04624 */
04625 MagickExport size_t PopImagePixels(Image *image,const QuantumType quantum,
04626   unsigned char *destination)
04627 {
04628   QuantumInfo
04629     *quantum_info;
04630 
04631   size_t
04632     length;
04633 
04634   quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
04635   if (quantum_info == (QuantumInfo *) NULL)
04636     return(0);
04637   length=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
04638     quantum,destination,&image->exception);
04639   quantum_info=DestroyQuantumInfo(quantum_info);
04640   return(length);
04641 }
04642 
04643 /*
04644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04645 %                                                                             %
04646 %                                                                             %
04647 %                                                                             %
04648 %  P o s t s c r i p t G e o m e t r y                                        %
04649 %                                                                             %
04650 %                                                                             %
04651 %                                                                             %
04652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04653 %
04654 %  PostscriptGeometry() replaces any page mneumonic with the equivalent size in
04655 %  picas.
04656 %
04657 %  The format of the PostscriptGeometry method is:
04658 %
04659 %      char *PostscriptGeometry(const char *page)
04660 %
04661 %  A description of each parameter follows.
04662 %
04663 %   o  page:  Specifies a pointer to an array of characters.
04664 %      The string is either a Postscript page name (e.g. A4) or a postscript
04665 %      page geometry (e.g. 612x792+36+36).
04666 %
04667 */
04668 MagickExport char *PostscriptGeometry(const char *page)
04669 {
04670   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1");
04671   return(GetPageGeometry(page));
04672 }
04673 
04674 /*
04675 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04676 %                                                                             %
04677 %                                                                             %
04678 %                                                                             %
04679 %   P u s h I m a g e L i s t                                                 %
04680 %                                                                             %
04681 %                                                                             %
04682 %                                                                             %
04683 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04684 %
04685 %  PushImageList() adds an image to the end of the list.
04686 %
04687 %  The format of the PushImageList method is:
04688 %
04689 %      unsigned int PushImageList(Image *images,const Image *image,
04690 %        ExceptionInfo *exception)
04691 %
04692 %  A description of each parameter follows:
04693 %
04694 %    o images: the image list.
04695 %
04696 %    o image: the image.
04697 %
04698 %    o exception: return any errors or warnings in this structure.
04699 %
04700 */
04701 MagickExport unsigned int PushImageList(Image **images,const Image *image,
04702   ExceptionInfo *exception)
04703 {
04704   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
04705   AppendImageToList(images,CloneImageList(image,exception));
04706   return(MagickTrue);
04707 }
04708 
04709 /*
04710 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04711 %                                                                             %
04712 %                                                                             %
04713 %                                                                             %
04714 %   P u s h I m a g e P i x e l s                                             %
04715 %                                                                             %
04716 %                                                                             %
04717 %                                                                             %
04718 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04719 %
04720 %  PushImagePixels() transfers one or more pixel components from a user
04721 %  supplied buffer into the image pixel cache of an image.  The pixels are
04722 %  expected in network byte order.  It returns MagickTrue if the pixels are
04723 %  successfully transferred, otherwise MagickFalse.
04724 %
04725 %  The format of the PushImagePixels method is:
04726 %
04727 %      size_t PushImagePixels(Image *image,const QuantumType quantum,
04728 %        const unsigned char *source)
04729 %
04730 %  A description of each parameter follows:
04731 %
04732 %    o image: the image.
04733 %
04734 %    o quantum: Declare which pixel components to transfer (red, green, blue,
04735 %      opacity, RGB, or RGBA).
04736 %
04737 %    o source:  The pixel components are transferred from this buffer.
04738 %
04739 */
04740 MagickExport size_t PushImagePixels(Image *image,const QuantumType quantum,
04741   const unsigned char *source)
04742 {
04743   QuantumInfo
04744     *quantum_info;
04745 
04746   size_t
04747     length;
04748 
04749   quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
04750   if (quantum_info == (QuantumInfo *) NULL)
04751     return(0);
04752   length=ImportQuantumPixels(image,(ViewInfo *) NULL,quantum_info,quantum,
04753     source,&image->exception);
04754   quantum_info=DestroyQuantumInfo(quantum_info);
04755   return(length);
04756 }
04757 
04758 /*
04759 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04760 %                                                                             %
04761 %                                                                             %
04762 %                                                                             %
04763 %  Q u a n t i z a t i o n E r r o r                                          %
04764 %                                                                             %
04765 %                                                                             %
04766 %                                                                             %
04767 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04768 %
04769 %  QuantizationError() measures the difference between the original and
04770 %  quantized images.  This difference is the total quantization error.  The
04771 %  error is computed by summing over all pixels in an image the distance
04772 %  squared in RGB space between each reference pixel value and its quantized
04773 %  value.  These values are computed:
04774 %
04775 %    o mean_error_per_pixel:  This value is the mean error for any single
04776 %      pixel in the image.
04777 %
04778 %    o normalized_mean_square_error:  This value is the normalized mean
04779 %      quantization error for any single pixel in the image.  This distance
04780 %      measure is normalized to a range between 0 and 1.  It is independent
04781 %      of the range of red, green, and blue values in the image.
04782 %
04783 %    o normalized_maximum_square_error:  Thsi value is the normalized
04784 %      maximum quantization error for any single pixel in the image.  This
04785 %      distance measure is normalized to a range between 0 and 1.  It is
04786 %      independent of the range of red, green, and blue values in your image.
04787 %
04788 %
04789 %  The format of the QuantizationError method is:
04790 %
04791 %      unsigned int QuantizationError(Image *image)
04792 %
04793 %  A description of each parameter follows.
04794 %
04795 %    o image: Specifies a pointer to an Image structure;  returned from
04796 %      ReadImage.
04797 %
04798 */
04799 MagickExport unsigned int QuantizationError(Image *image)
04800 {
04801   if (image->debug != MagickFalse)
04802     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.3");
04803   return(GetImageQuantizeError(image));
04804 }
04805 
04806 /*
04807 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04808 %                                                                             %
04809 %                                                                             %
04810 %     R a n d o m C h a n n e l T h r e s h o l d I m a g e                   %
04811 %                                                                             %
04812 %                                                                             %
04813 %                                                                             %
04814 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
04815 %
04816 %  RandomChannelThresholdImage() changes the value of individual pixels based
04817 %  on the intensity of each pixel compared to a random threshold.  The result
04818 %  is a low-contrast, two color image.
04819 %
04820 %  The format of the RandomChannelThresholdImage method is:
04821 %
04822 %      unsigned int RandomChannelThresholdImage(Image *image,
04823 %         const char *channel, const char *thresholds,
04824 %         ExceptionInfo *exception)
04825 %
04826 %  A description of each parameter follows:
04827 %
04828 %    o image: the image.
04829 %
04830 %    o channel: the channel or channels to be thresholded.
04831 %
04832 %    o thresholds: a geometry string containing LOWxHIGH thresholds.
04833 %      If the string contains 2x2, 3x3, or 4x4, then an ordered
04834 %      dither of order 2, 3, or 4 will be performed instead.
04835 %
04836 %    o exception: return any errors or warnings in this structure.
04837 %
04838 */
04839 MagickExport unsigned int RandomChannelThresholdImage(Image *image,const char
04840     *channel,const char *thresholds,ExceptionInfo *exception)
04841 {
04842 #define RandomChannelThresholdImageText  "  RandomChannelThreshold image...  "
04843 
04844   double
04845     lower_threshold,
04846     upper_threshold;
04847 
04848   long
04849     count,
04850     y;
04851 
04852   RandomInfo
04853     *random_info;
04854 
04855   static MagickRealType
04856     o2[4]={0.2f, 0.6f, 0.8f, 0.4f}, 
04857     o3[9]={0.1f, 0.6f, 0.3f, 0.7f, 0.5f, 0.8f, 0.4f, 0.9f, 0.2f}, 
04858     o4[16]={0.1f, 0.7f, 1.1f, 0.3f, 1.0f, 0.5f, 1.5f, 0.8f, 1.4f, 1.6f, 0.6f,
04859       1.2f, 0.4f, 0.9f, 1.3f, 0.2f}, 
04860     threshold=128;
04861 
04862   unsigned int
04863     status;
04864 
04865   unsigned long
04866     order;
04867 
04868   /*
04869     Threshold image.
04870   */
04871   assert(image != (Image *) NULL);
04872   assert(image->signature == MagickSignature);
04873   if (image->debug != MagickFalse)
04874     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
04875   assert(exception != (ExceptionInfo *) NULL);
04876   assert(exception->signature == MagickSignature);
04877   if (image->debug != MagickFalse)
04878     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
04879   if (thresholds == (const char *) NULL)
04880     return(MagickTrue);
04881   if (LocaleCompare(thresholds,"2x2") == 0)
04882     order=2;
04883   else
04884     if (LocaleCompare(thresholds,"3x3") == 0)
04885       order=3;
04886     else
04887       if (LocaleCompare(thresholds,"4x4") == 0)
04888         order=4;
04889       else
04890         {
04891           order=1;
04892           lower_threshold=0;
04893           upper_threshold=0;
04894           count=sscanf(thresholds,"%lf[/x%%]%lf",&lower_threshold,
04895             &upper_threshold);
04896           if (strchr(thresholds,'%') != (char *) NULL)
04897             {
04898               upper_threshold*=(.01*QuantumRange);
04899               lower_threshold*=(.01*QuantumRange);
04900             }
04901           if (count == 1)
04902             upper_threshold=(MagickRealType) QuantumRange-lower_threshold;
04903         }
04904   if (image->debug != MagickFalse)
04905     (void) LogMagickEvent(TransformEvent,GetMagickModule(),
04906       "  RandomChannelThresholdImage: channel type=%s",channel);
04907   if (image->debug != MagickFalse)
04908     (void) LogMagickEvent(TransformEvent,GetMagickModule(),
04909       "    Thresholds: %s (%fx%f)",thresholds,lower_threshold,upper_threshold);
04910   if (LocaleCompare(channel,"all") == 0 ||
04911       LocaleCompare(channel,"intensity") == 0)
04912     if (AcquireImageColormap(image,2) == MagickFalse)
04913       ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
04914         image->filename);
04915   random_info=AcquireRandomInfo();
04916   for (y=0; y < (long) image->rows; y++)
04917   {
04918     register long
04919       x;
04920 
04921     register IndexPacket
04922       index,
04923       *__restrict indexes;
04924 
04925     register PixelPacket
04926       *__restrict q;
04927 
04928     q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
04929     if (q == (PixelPacket *) NULL)
04930       break;
04931     if (LocaleCompare(channel,"all") == 0 ||
04932         LocaleCompare(channel,"intensity") == 0)
04933       {
04934         indexes=GetAuthenticIndexQueue(image);
04935         for (x=0; x < (long) image->columns; x++)
04936           {
04937             MagickRealType
04938               intensity;
04939 
04940             intensity=(MagickRealType) PixelIntensityToQuantum(q);
04941             if (order == 1)
04942               {
04943                 if (intensity < lower_threshold)
04944                   threshold=lower_threshold;
04945                 else if (intensity > upper_threshold)
04946                   threshold=upper_threshold;
04947                 else
04948                   threshold=(MagickRealType) (QuantumRange*
04949                     GetPseudoRandomValue(random_info));
04950               }
04951             else if (order == 2)
04952               threshold=(MagickRealType) QuantumRange*o2[(x%2)+2*(y%2)];
04953             else if (order == 3)
04954               threshold=(MagickRealType) QuantumRange*o3[(x%3)+3*(y%3)];
04955             else if (order == 4)
04956               threshold=(MagickRealType) QuantumRange*o4[(x%4)+4*(y%4)];
04957             q->red=q->green=q->blue=(Quantum) (intensity <=
04958                threshold ? 0 : QuantumRange);
04959             index=(IndexPacket) (intensity <= threshold ? 0 : 1);
04960             *indexes++=index;
04961             q->red=q->green=q->blue=image->colormap[(long) index].red;
04962             q++;
04963           }
04964       }
04965     if (LocaleCompare(channel,"opacity") == 0 ||
04966         LocaleCompare(channel,"all") == 0 ||
04967         LocaleCompare(channel,"matte") == 0)
04968       {
04969         if (image->matte != MagickFalse)
04970           for (x=0; x < (long) image->columns; x++)
04971             {
04972               if (order == 1)
04973                 {
04974                   if ((MagickRealType) q->opacity < lower_threshold)
04975                     threshold=lower_threshold;
04976                   else if ((MagickRealType) q->opacity > upper_threshold)
04977                     threshold=upper_threshold;
04978                   else
04979                     threshold=(MagickRealType) (QuantumRange*
04980                       GetPseudoRandomValue(random_info));
04981                 }
04982               else if (order == 2)
04983                 threshold=(MagickRealType) QuantumRange*o2[(x%2)+2*(y%2)];
04984               else if (order == 3)
04985                 threshold=(MagickRealType) QuantumRange*o3[(x%3)+3*(y%3)];
04986               else if (order == 4)
04987                 threshold=(MagickRealType) QuantumRange*o4[(x%4)+4*(y%4)]/1.7;
04988               q->opacity=(Quantum) ((MagickRealType) q->opacity <= threshold ?
04989                  0 : QuantumRange);
04990               q++;
04991             }
04992       }
04993     else
04994       {
04995         /* To Do: red, green, blue, cyan, magenta, yellow, black */
04996         if (LocaleCompare(channel,"intensity") != 0)
04997           ThrowBinaryException(OptionError,"UnrecognizedChannelType",
04998             image->filename);
04999       }
05000     if (SyncAuthenticPixels(image,exception) == MagickFalse)
05001       break;
05002     if (QuantumTick(y,image->rows) != MagickFalse)
05003       {
05004         status=MagickMonitor(RandomChannelThresholdImageText,y,image->rows,
05005           exception);
05006         if (status == MagickFalse)
05007           break;
05008       }
05009   }
05010   random_info=DestroyRandomInfo(random_info);
05011   return(MagickTrue);
05012 }
05013 
05014 /*
05015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05016 %                                                                             %
05017 %                                                                             %
05018 %                                                                             %
05019 %   R e a c q u i r e M e m o r y                                             %
05020 %                                                                             %
05021 %                                                                             %
05022 %                                                                             %
05023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05024 %
05025 %  ReacquireMemory() changes the size of the memory and returns a pointer to
05026 %  the (possibly moved) block.  The contents will be unchanged up to the
05027 %  lesser of the new and old sizes.
05028 %
05029 %  The format of the ReacquireMemory method is:
05030 %
05031 %      void ReacquireMemory(void **memory,const size_t size)
05032 %
05033 %  A description of each parameter follows:
05034 %
05035 %    o memory: A pointer to a memory allocation.  On return the pointer
05036 %      may change but the contents of the original allocation will not.
05037 %
05038 %    o size: the new size of the allocated memory.
05039 %
05040 */
05041 MagickExport void ReacquireMemory(void **memory,const size_t size)
05042 {
05043   void
05044     *allocation;
05045 
05046   assert(memory != (void **) NULL);
05047   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
05048   if (*memory == (void *) NULL)
05049     {
05050       *memory=AcquireMagickMemory(size);
05051       return;
05052     }
05053   allocation=realloc(*memory,size);
05054   if (allocation == (void *) NULL)
05055     *memory=RelinquishMagickMemory(*memory);
05056   *memory=allocation;
05057 }
05058 
05059 /*
05060 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05061 %                                                                             %
05062 %                                                                             %
05063 %                                                                             %
05064 %   R e s e t I m a g e A t t r i b u t e I t e r a t o r                     %
05065 %                                                                             %
05066 %                                                                             %
05067 %                                                                             %
05068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05069 %
05070 %  ResetImageAttributeIterator() resets the image attributes iterator.  Use it
05071 %  in conjunction with GetNextImageAttribute() to iterate over all the values
05072 %  associated with an image.
05073 %
05074 %  The format of the ResetImageAttributeIterator method is:
05075 %
05076 %      ResetImageAttributeIterator(const ImageInfo *image)
05077 %
05078 %  A description of each parameter follows:
05079 %
05080 %    o image: the image.
05081 %
05082 */
05083 MagickExport void ResetImageAttributeIterator(const Image *image)
05084 {
05085   ResetImagePropertyIterator(image);
05086 }
05087 
05088 /*
05089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05090 %                                                                             %
05091 %                                                                             %
05092 %                                                                             %
05093 %   S e t C a c h e V i e w P i x e l s                                       %
05094 %                                                                             %
05095 %                                                                             %
05096 %                                                                             %
05097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05098 %
05099 %  SetCacheViewPixels() gets pixels from the in-memory or disk pixel cache as
05100 %  defined by the geometry parameters.   A pointer to the pixels is returned
05101 %  if the pixels are transferred, otherwise a NULL is returned.
05102 %
05103 %  The format of the SetCacheViewPixels method is:
05104 %
05105 %      PixelPacket *SetCacheViewPixels(ViewInfo *cache_view,const long x,
05106 %        const long y,const unsigned long columns,const unsigned long rows)
05107 %
05108 %  A description of each parameter follows:
05109 %
05110 %    o cache_view: the cache view.
05111 %
05112 %    o x,y,columns,rows:  These values define the perimeter of a region of
05113 %      pixels.
05114 %
05115 */
05116 MagickExport PixelPacket *SetCacheViewPixels(ViewInfo *cache_view,const long x,
05117   const long y,const unsigned long columns,const unsigned long rows)
05118 {
05119   PixelPacket
05120     *pixels;
05121 
05122   pixels=QueueCacheViewAuthenticPixels(cache_view,x,y,columns,rows,
05123     GetCacheViewException(cache_view));
05124   return(pixels);
05125 }
05126 
05127 /*
05128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05129 %                                                                             %
05130 %                                                                             %
05131 %                                                                             %
05132 +   S e t C a c h e T h e s h o l d                                           %
05133 %                                                                             %
05134 %                                                                             %
05135 %                                                                             %
05136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05137 %
05138 %  SetCacheThreshold() sets the amount of free memory allocated for the pixel
05139 %  cache.  Once this threshold is exceeded, all subsequent pixels cache
05140 %  operations are to/from disk.
05141 %
05142 %  The format of the SetCacheThreshold() method is:
05143 %
05144 %      void SetCacheThreshold(const size_t threshold)
05145 %
05146 %  A description of each parameter follows:
05147 %
05148 %    o threshold: the number of megabytes of memory available to the pixel
05149 %      cache.
05150 %
05151 */
05152 MagickExport void SetCacheThreshold(const unsigned long size)
05153 {
05154   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1");
05155   (void) SetMagickResourceLimit(MemoryResource,size*1024*1024);
05156   (void) SetMagickResourceLimit(MapResource,2*size*1024*1024);
05157 }
05158 
05159 /*
05160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05161 %                                                                             %
05162 %                                                                             %
05163 %                                                                             %
05164 %   S e t E x c e p t i o n I n f o                                           %
05165 %                                                                             %
05166 %                                                                             %
05167 %                                                                             %
05168 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05169 %
05170 %  SetExceptionInfo() sets the exception severity.
05171 %
05172 %  The format of the SetExceptionInfo method is:
05173 %
05174 %      MagickBooleanType SetExceptionInfo(ExceptionInfo *exception,
05175 %        ExceptionType severity)
05176 %
05177 %  A description of each parameter follows:
05178 %
05179 %    o exception: the exception info.
05180 %
05181 %    o severity: the exception severity.
05182 %
05183 */
05184 MagickExport MagickBooleanType SetExceptionInfo(ExceptionInfo *exception,
05185   ExceptionType severity)
05186 {
05187   assert(exception != (ExceptionInfo *) NULL);
05188   ClearMagickException(exception);
05189   exception->severity=severity;
05190   return(MagickTrue);
05191 }
05192 
05193 /*
05194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05195 %                                                                             %
05196 %                                                                             %
05197 %                                                                             %
05198 %   S e t I m a g e                                                           %
05199 %                                                                             %
05200 %                                                                             %
05201 %                                                                             %
05202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05203 %
05204 %  SetImage() sets the red, green, and blue components of each pixel to
05205 %  the image background color and the opacity component to the specified
05206 %  level of transparency.  The background color is defined by the
05207 %  background_color member of the image.
05208 %
05209 %  The format of the SetImage method is:
05210 %
05211 %      void SetImage(Image *image,const Quantum opacity)
05212 %
05213 %  A description of each parameter follows:
05214 %
05215 %    o image: the image.
05216 %
05217 %    o opacity: Set each pixel to this level of transparency.
05218 %
05219 */
05220 MagickExport void SetImage(Image *image,const Quantum opacity)
05221 {
05222   long
05223     y;
05224 
05225   PixelPacket
05226     background_color;
05227 
05228   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.0");
05229   assert(image != (Image *) NULL);
05230   if (image->debug != MagickFalse)
05231     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
05232   assert(image->signature == MagickSignature);
05233   background_color=image->background_color;
05234   if (opacity != OpaqueOpacity)
05235     background_color.opacity=opacity;
05236   if (background_color.opacity != OpaqueOpacity)
05237     {
05238       (void) SetImageStorageClass(image,DirectClass);
05239       image->matte=MagickTrue;
05240     }
05241   if ((image->storage_class == PseudoClass) ||
05242       (image->colorspace == CMYKColorspace))
05243     {
05244       /*
05245         Set colormapped or CMYK image.
05246       */
05247       for (y=0; y < (long) image->rows; y++)
05248       {
05249         register IndexPacket
05250           *__restrict indexes;
05251 
05252         register long
05253           x;
05254 
05255         register PixelPacket
05256           *__restrict q;
05257 
05258         q=QueueAuthenticPixels(image,0,y,image->columns,1,&image->exception);
05259         if (q == (PixelPacket *) NULL)
05260           break;
05261         for (x=0; x < (long) image->columns; x++)
05262           *q++=background_color;
05263         indexes=GetAuthenticIndexQueue(image);
05264         for (x=0; x < (long) image->columns; x++)
05265           indexes[x]=(IndexPacket) 0;
05266         if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
05267           break;
05268       }
05269       return;
05270     }
05271   /*
05272     Set DirectClass image.
05273   */
05274   for (y=0; y < (long) image->rows; y++)
05275   {
05276     register long
05277       x;
05278 
05279     register PixelPacket
05280       *__restrict q;
05281 
05282     q=QueueAuthenticPixels(image,0,y,image->columns,1,&image->exception);
05283     if (q == (PixelPacket *) NULL)
05284       break;
05285     for (x=0; x < (long) image->columns; x++)
05286       *q++=background_color;
05287     if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
05288       break;
05289   }
05290 }
05291 
05292 /*
05293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05294 %                                                                             %
05295 %                                                                             %
05296 %                                                                             %
05297 %   S e t I m a g e A t t r i b u t e                                         %
05298 %                                                                             %
05299 %                                                                             %
05300 %                                                                             %
05301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05302 %
05303 %  SetImageAttribute() searches the list of image attributes and replaces the
05304 %  attribute value.  If it is not found in the list, the attribute name
05305 %  and value is added to the list.   
05306 %
05307 %  The format of the SetImageAttribute method is:
05308 %
05309 %       MagickBooleanType SetImageAttribute(Image *image,const char *key,
05310 %         const char *value)
05311 %
05312 %  A description of each parameter follows:
05313 %
05314 %    o image: the image.
05315 %
05316 %    o key: the key.
05317 %
05318 %    o value: the value.
05319 %
05320 */
05321 MagickExport MagickBooleanType SetImageAttribute(Image *image,const char *key,
05322   const char *value)
05323 {
05324   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.3.1");
05325   return(SetImageProperty(image,key,value));
05326 }
05327 
05328 /*
05329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05330 %                                                                             %
05331 %                                                                             %
05332 %                                                                             %
05333 %   S e t I m a g e L i s t                                                   %
05334 %                                                                             %
05335 %                                                                             %
05336 %                                                                             %
05337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05338 %
05339 %  SetImageList() inserts an image into the list at the specified position.
05340 %
05341 %  The format of the SetImageList method is:
05342 %
05343 %      unsigned int SetImageList(Image *images,const Image *image,
05344 %        const long offset,ExceptionInfo *exception)
05345 %
05346 %  A description of each parameter follows:
05347 %
05348 %    o images: the image list.
05349 %
05350 %    o image: the image.
05351 %
05352 %    o offset: the position within the list.
05353 %
05354 %    o exception: return any errors or warnings in this structure.
05355 %
05356 */
05357 MagickExport unsigned int SetImageList(Image **images,const Image *image,
05358   const long offset,ExceptionInfo *exception)
05359 {
05360   Image
05361     *clone;
05362 
05363   register long
05364     i;
05365 
05366   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
05367   clone=CloneImageList(image,exception);
05368   while (GetPreviousImageInList(*images) != (Image *) NULL)
05369     (*images)=GetPreviousImageInList(*images);
05370   for (i=0; i < offset; i++)
05371   {
05372     if (GetNextImageInList(*images) == (Image *) NULL)
05373       return(MagickFalse);
05374     (*images)=GetNextImageInList(*images);
05375   }
05376   InsertImageInList(images,clone);
05377   return(MagickTrue);
05378 }
05379 
05380 /*
05381 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05382 %                                                                             %
05383 %                                                                             %
05384 %                                                                             %
05385 %   S e t I m a g e P i x e l s                                               %
05386 %                                                                             %
05387 %                                                                             %
05388 %                                                                             %
05389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05390 %
05391 %  SetImagePixels() queues a mutable pixel region.
05392 %  If the region is successfully intialized a pointer to a PixelPacket
05393 %  array representing the region is returned, otherwise NULL is returned.
05394 %  The returned pointer may point to a temporary working buffer for the
05395 %  pixels or it may point to the final location of the pixels in memory.
05396 %
05397 %  Write-only access means that any existing pixel values corresponding to
05398 %  the region are ignored.  This useful while the initial image is being
05399 %  created from scratch, or if the existing pixel values are to be
05400 %  completely replaced without need to refer to their pre-existing values.
05401 %  The application is free to read and write the pixel buffer returned by
05402 %  SetImagePixels() any way it pleases. SetImagePixels() does not initialize
05403 %  the pixel array values. Initializing pixel array values is the
05404 %  application's responsibility.
05405 %
05406 %  Performance is maximized if the selected region is part of one row, or
05407 %  one or more full rows, since then there is opportunity to access the
05408 %  pixels in-place (without a copy) if the image is in RAM, or in a
05409 %  memory-mapped file. The returned pointer should *never* be deallocated
05410 %  by the user.
05411 %
05412 %  Pixels accessed via the returned pointer represent a simple array of type
05413 %  PixelPacket. If the image type is CMYK or the storage class is PseudoClass,
05414 %  call GetAuthenticIndexQueue() after invoking GetAuthenticPixels() to obtain
05415 %  the black color component or the colormap indexes (of type IndexPacket)
05416 %  corresponding to the region.  Once the PixelPacket (and/or IndexPacket)
05417 %  array has been updated, the changes must be saved back to the underlying
05418 %  image using SyncAuthenticPixels() or they may be lost.
05419 %
05420 %  The format of the SetImagePixels() method is:
05421 %
05422 %      PixelPacket *SetImagePixels(Image *image,const long x,const long y,
05423 %        const unsigned long columns,const unsigned long rows)
05424 %
05425 %  A description of each parameter follows:
05426 %
05427 %    o pixels: SetImagePixels returns a pointer to the pixels if they are
05428 %      transferred, otherwise a NULL is returned.
05429 %
05430 %    o image: the image.
05431 %
05432 %    o x,y,columns,rows:  These values define the perimeter of a region of
05433 %      pixels.
05434 %
05435 */
05436 MagickExport PixelPacket *SetImagePixels(Image *image,const long x,const long y,
05437   const unsigned long columns,const unsigned long rows)
05438 {
05439   return(QueueAuthenticPixels(image,x,y,columns,rows,&image->exception));
05440 }
05441 
05442 /*
05443 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05444 %                                                                             %
05445 %                                                                             %
05446 %                                                                             %
05447 %   S e t M a g i c k R e g i s t r y                                         %
05448 %                                                                             %
05449 %                                                                             %
05450 %                                                                             %
05451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05452 %
05453 %  SetMagickRegistry() sets a blob into the registry and returns a unique ID.
05454 %  If an error occurs, -1 is returned.
05455 %
05456 %  The format of the SetMagickRegistry method is:
05457 %
05458 %      long SetMagickRegistry(const RegistryType type,const void *blob,
05459 %        const size_t length,ExceptionInfo *exception)
05460 %
05461 %  A description of each parameter follows:
05462 %
05463 %    o type: the registry type.
05464 %
05465 %    o blob: the address of a Binary Large OBject.
05466 %
05467 %    o length: For a registry type of ImageRegistryType use sizeof(Image)
05468 %      otherise the blob length in number of bytes.
05469 %
05470 %    o exception: return any errors or warnings in this structure.
05471 %
05472 */
05473 MagickExport long SetMagickRegistry(const RegistryType type,const void *blob,
05474   const size_t magick_unused(length),ExceptionInfo *exception)
05475 {
05476   char
05477     key[MaxTextExtent];
05478 
05479   MagickBooleanType
05480     status;
05481 
05482   static long
05483     id = 0;
05484 
05485   (void) FormatMagickString(key,MaxTextExtent,"%ld\n",id);
05486   status=SetImageRegistry(type,key,blob,exception);
05487   if (status == MagickFalse)
05488     return(-1);
05489   return(id++);
05490 }
05491 
05492 /*
05493 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05494 %                                                                             %
05495 %                                                                             %
05496 %                                                                             %
05497 %   S e t M o n i t o r H a n d l e r                                         %
05498 %                                                                             %
05499 %                                                                             %
05500 %                                                                             %
05501 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05502 %
05503 %  SetMonitorHandler() sets the monitor handler to the specified method
05504 %  and returns the previous monitor handler.
05505 %
05506 %  The format of the SetMonitorHandler method is:
05507 %
05508 %      MonitorHandler SetMonitorHandler(MonitorHandler handler)
05509 %
05510 %  A description of each parameter follows:
05511 %
05512 %    o handler: Specifies a pointer to a method to handle monitors.
05513 %
05514 */
05515 
05516 MagickExport MonitorHandler GetMonitorHandler(void)
05517 {
05518   return(monitor_handler);
05519 }
05520 
05521 MagickExport MonitorHandler SetMonitorHandler(MonitorHandler handler)
05522 {
05523   MonitorHandler
05524     previous_handler;
05525 
05526   previous_handler=monitor_handler;
05527   monitor_handler=handler;
05528   return(previous_handler);
05529 }
05530 
05531 /*
05532 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05533 %                                                                             %
05534 %                                                                             %
05535 %                                                                             %
05536 %   S h i f t I m a g e L i s t                                               %
05537 %                                                                             %
05538 %                                                                             %
05539 %                                                                             %
05540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05541 %
05542 %  ShiftImageList() removes an image from the beginning of the list.
05543 %
05544 %  The format of the ShiftImageList method is:
05545 %
05546 %      Image *ShiftImageList(Image **images)
05547 %
05548 %  A description of each parameter follows:
05549 %
05550 %    o images: the image list.
05551 %
05552 */
05553 MagickExport Image *ShiftImageList(Image **images)
05554 {
05555   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
05556   return(RemoveFirstImageFromList(images));
05557 }
05558 
05559 /*
05560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05561 %                                                                             %
05562 %                                                                             %
05563 %                                                                             %
05564 +  S i z e B l o b                                                            %
05565 %                                                                             %
05566 %                                                                             %
05567 %                                                                             %
05568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05569 %
05570 %  SizeBlob() returns the current length of the image file or blob.
05571 %
05572 %  The format of the SizeBlob method is:
05573 %
05574 %      off_t SizeBlob(Image *image)
05575 %
05576 %  A description of each parameter follows:
05577 %
05578 %    o size:  Method SizeBlob returns the current length of the image file
05579 %      or blob.
05580 %
05581 %    o image: the image.
05582 %
05583 */
05584 MagickExport MagickOffsetType SizeBlob(Image *image)
05585 {
05586   if (image->debug != MagickFalse)
05587     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.4.3");
05588   return((MagickOffsetType) GetBlobSize(image));
05589 }
05590 
05591 /*
05592 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05593 %                                                                             %
05594 %                                                                             %
05595 %                                                                             %
05596 %   S p l i c e I m a g e L i s t                                             %
05597 %                                                                             %
05598 %                                                                             %
05599 %                                                                             %
05600 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05601 %
05602 %  SpliceImageList() removes the images designated by offset and length from
05603 %  the list and replaces them with the specified list.
05604 %
05605 %  The format of the SpliceImageList method is:
05606 %
05607 %      Image *SpliceImageList(Image *images,const long offset,
05608 %        const unsigned long length,const Image *splices,
05609 %        ExceptionInfo *exception)
05610 %
05611 %  A description of each parameter follows:
05612 %
05613 %    o images: the image list.
05614 %
05615 %    o offset: the position within the list.
05616 %
05617 %    o length: the length of the image list to remove.
05618 %
05619 %    o splice: Replace the removed image list with this list.
05620 %
05621 %    o exception: return any errors or warnings in this structure.
05622 %
05623 */
05624 MagickExport Image *SpliceImageList(Image *images,const long offset,
05625   const unsigned long length,const Image *splices,ExceptionInfo *exception)
05626 {
05627   Image
05628     *clone;
05629 
05630   register long
05631     i;
05632 
05633   if (images->debug != MagickFalse)
05634     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
05635   clone=CloneImageList(splices,exception);
05636   while (GetPreviousImageInList(images) != (Image *) NULL)
05637     images=GetPreviousImageInList(images);
05638   for (i=0; i < offset; i++)
05639   {
05640     if (GetNextImageInList(images) == (Image *) NULL)
05641       return((Image *) NULL);
05642     images=GetNextImageInList(images);
05643   }
05644   (void) SpliceImageIntoList(&images,length,clone);
05645   return(images);
05646 }
05647 
05648 /*
05649 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05650 %                                                                             %
05651 %                                                                             %
05652 %                                                                             %
05653 %   S t r i p                                                                 %
05654 %                                                                             %
05655 %                                                                             %
05656 %                                                                             %
05657 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05658 %
05659 %  Strip() strips any whitespace or quotes from the beginning and end of a
05660 %  string of characters.
05661 %
05662 %  The format of the Strip method is:
05663 %
05664 %      void Strip(char *message)
05665 %
05666 %  A description of each parameter follows:
05667 %
05668 %    o message: Specifies an array of characters.
05669 %
05670 */
05671 MagickExport void Strip(char *message)
05672 {
05673   register char
05674     *p,
05675     *q;
05676 
05677   assert(message != (char *) NULL);
05678   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
05679   if (*message == '\0')
05680     return;
05681   if (strlen(message) == 1)
05682     return;
05683   p=message;
05684   while (isspace((int) ((unsigned char) *p)) != 0)
05685     p++;
05686   if ((*p == '\'') || (*p == '"'))
05687     p++;
05688   q=message+strlen(message)-1;
05689   while ((isspace((int) ((unsigned char) *q)) != 0) && (q > p))
05690     q--;
05691   if (q > p)
05692     if ((*q == '\'') || (*q == '"'))
05693       q--;
05694   (void) CopyMagickMemory(message,p,(size_t) (q-p+1));
05695   message[q-p+1]='\0';
05696 }
05697 
05698 /*
05699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05700 %                                                                             %
05701 %                                                                             %
05702 %                                                                             %
05703 %   S y n c C a c h e V i e w                                                 %
05704 %                                                                             %
05705 %                                                                             %
05706 %                                                                             %
05707 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05708 %
05709 %  SyncCacheView() saves the cache view pixels to the in-memory or disk
05710 %  cache.  It returns MagickTrue if the pixel region is synced, otherwise
05711 %  MagickFalse.
05712 %
05713 %  The format of the SyncCacheView method is:
05714 %
05715 %      MagickBooleanType SyncCacheView(ViewInfo *cache_view)
05716 %
05717 %  A description of each parameter follows:
05718 %
05719 %    o cache_view: the cache view.
05720 %
05721 */
05722 MagickExport MagickBooleanType SyncCacheView(ViewInfo *cache_view)
05723 {
05724   MagickBooleanType
05725     status;
05726 
05727   status=SyncCacheViewAuthenticPixels(cache_view,
05728     GetCacheViewException(cache_view));
05729   return(status);
05730 }
05731 
05732 /*
05733 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05734 %                                                                             %
05735 %                                                                             %
05736 %                                                                             %
05737 %   S y n c C a c h e V i e w P i x e l s                                     %
05738 %                                                                             %
05739 %                                                                             %
05740 %                                                                             %
05741 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05742 %
05743 %  SyncCacheViewPixels() saves the cache view pixels to the in-memory
05744 %  or disk cache.  It returns MagickTrue if the pixel region is flushed,
05745 %  otherwise MagickFalse.
05746 %
05747 %  The format of the SyncCacheViewPixels method is:
05748 %
05749 %      MagickBooleanType SyncCacheViewPixels(ViewInfo *cache_view)
05750 %
05751 %  A description of each parameter follows:
05752 %
05753 %    o cache_view: the cache view.
05754 %
05755 %    o exception: return any errors or warnings in this structure.
05756 %
05757 */
05758 MagickExport MagickBooleanType SyncCacheViewPixels(ViewInfo *cache_view)
05759 {
05760   MagickBooleanType
05761     status;
05762 
05763   status=SyncCacheViewAuthenticPixels(cache_view,
05764     GetCacheViewException(cache_view));
05765   return(status);
05766 }
05767 
05768 /*
05769 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05770 %                                                                             %
05771 %                                                                             %
05772 %                                                                             %
05773 %   S y n c I m a g e P i x e l s                                             %
05774 %                                                                             %
05775 %                                                                             %
05776 %                                                                             %
05777 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05778 %
05779 %  SyncImagePixels() saves the image pixels to the in-memory or disk cache.
05780 %  The method returns MagickTrue if the pixel region is synced, otherwise
05781 %  MagickFalse.
05782 %
05783 %  The format of the SyncImagePixels() method is:
05784 %
05785 %      MagickBooleanType SyncImagePixels(Image *image)
05786 %
05787 %  A description of each parameter follows:
05788 %
05789 %    o image: the image.
05790 %
05791 */
05792 MagickExport MagickBooleanType SyncImagePixels(Image *image)
05793 {
05794   return(SyncAuthenticPixels(image,&image->exception));
05795 }
05796 
05797 /*
05798 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05799 %                                                                             %
05800 %                                                                             %
05801 %                                                                             %
05802 %  T e m p o r a r y F i l e n a m e                                          %
05803 %                                                                             %
05804 %                                                                             %
05805 %                                                                             %
05806 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05807 %
05808 %  TemporaryFilename() replaces the contents of path by a unique path name.
05809 %
05810 %  The format of the TemporaryFilename method is:
05811 %
05812 %      void TemporaryFilename(char *path)
05813 %
05814 %  A description of each parameter follows.
05815 %
05816 %   o  path:  Specifies a pointer to an array of characters.  The unique path
05817 %      name is returned in this array.
05818 %
05819 */
05820 MagickExport void TemporaryFilename(char *path)
05821 {
05822   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.6");
05823   (void) AcquireUniqueFilename(path);
05824   (void) RelinquishUniqueFileResource(path);
05825 }
05826 
05827 /*
05828 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05829 %                                                                             %
05830 %                                                                             %
05831 %                                                                             %
05832 %     T h r e s h o l d I m a g e                                             %
05833 %                                                                             %
05834 %                                                                             %
05835 %                                                                             %
05836 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05837 %
05838 %  ThresholdImage() changes the value of individual pixels based on
05839 %  the intensity of each pixel compared to threshold.  The result is a
05840 %  high-contrast, two color image.
05841 %
05842 %  The format of the ThresholdImage method is:
05843 %
05844 %      unsigned int ThresholdImage(Image *image,const double threshold)
05845 %
05846 %  A description of each parameter follows:
05847 %
05848 %    o image: the image.
05849 %
05850 %    o threshold: Define the threshold value
05851 %
05852 */
05853 MagickExport unsigned int ThresholdImage(Image *image,const double threshold)
05854 {
05855 #define ThresholdImageTag  "Threshold/Image"
05856 
05857   IndexPacket
05858     index;
05859 
05860   long
05861     y;
05862 
05863   /*
05864     Threshold image.
05865   */
05866   assert(image != (Image *) NULL);
05867   assert(image->signature == MagickSignature);
05868   if (image->debug != MagickFalse)
05869     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
05870   if (image->debug != MagickFalse)
05871     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
05872   if (!AcquireImageColormap(image,2))
05873     ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
05874       "UnableToThresholdImage");
05875   for (y=0; y < (long) image->rows; y++)
05876   {
05877     register IndexPacket
05878       *__restrict indexes;
05879 
05880     register long
05881       x;
05882 
05883     register PixelPacket
05884       *__restrict q;
05885 
05886     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
05887     if (q == (PixelPacket *) NULL)
05888       break;
05889     indexes=GetAuthenticIndexQueue(image);
05890     for (x=0; x < (long) image->columns; x++)
05891     {
05892       index=(IndexPacket) ((MagickRealType)
05893         PixelIntensityToQuantum(q) <= threshold ? 0 : 1);
05894       indexes[x]=index;
05895       q->red=image->colormap[(long) index].red;
05896       q->green=image->colormap[(long) index].green;
05897       q->blue=image->colormap[(long) index].blue;
05898       q++;
05899     }
05900     if (!SyncAuthenticPixels(image,&image->exception))
05901       break;
05902   }
05903   return(MagickTrue);
05904 }
05905 
05906 /*
05907 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05908 %                                                                             %
05909 %                                                                             %
05910 %                                                                             %
05911 %     T h r e s h o l d I m a g e C h a n n e l                               %
05912 %                                                                             %
05913 %                                                                             %
05914 %                                                                             %
05915 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
05916 %
05917 %  ThresholdImageChannel() changes the value of individual pixels based on
05918 %  the intensity of each pixel channel.  The result is a high-contrast image.
05919 %
05920 %  The format of the ThresholdImageChannel method is:
05921 %
05922 %      unsigned int ThresholdImageChannel(Image *image,const char *threshold)
05923 %
05924 %  A description of each parameter follows:
05925 %
05926 %    o image: the image.
05927 %
05928 %    o threshold: define the threshold values.
05929 %
05930 */
05931 MagickExport unsigned int ThresholdImageChannel(Image *image,
05932   const char *threshold)
05933 {
05934 #define ThresholdImageTag  "Threshold/Image"
05935 
05936   MagickPixelPacket
05937     pixel;
05938 
05939   GeometryInfo
05940     geometry_info;
05941 
05942   IndexPacket
05943     index;
05944 
05945   long
05946     y;
05947 
05948   unsigned int
05949     flags;
05950 
05951   /*
05952     Threshold image.
05953   */
05954   assert(image != (Image *) NULL);
05955   assert(image->signature == MagickSignature);
05956   if (image->debug != MagickFalse)
05957     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
05958   if (threshold == (const char *) NULL)
05959     return(MagickTrue);
05960   if (SetImageStorageClass(image,DirectClass) == MagickFalse)
05961     return(MagickFalse);
05962   flags=ParseGeometry(threshold,&geometry_info);
05963   pixel.red=geometry_info.rho;
05964   if (flags & SigmaValue)
05965     pixel.green=geometry_info.sigma;
05966   else
05967     pixel.green=pixel.red;
05968   if (flags & XiValue)
05969     pixel.blue=geometry_info.xi;
05970   else
05971     pixel.blue=pixel.red;
05972   if (flags & PsiValue)
05973     pixel.opacity=geometry_info.psi;
05974   else
05975     pixel.opacity=(MagickRealType) OpaqueOpacity;
05976   if (flags & PercentValue)
05977     {
05978       pixel.red*=QuantumRange/100.0f;
05979       pixel.green*=QuantumRange/100.0f;
05980       pixel.blue*=QuantumRange/100.0f;
05981       pixel.opacity*=QuantumRange/100.0f;
05982     }
05983   if (!(flags & SigmaValue))
05984     {
05985       if (!AcquireImageColormap(image,2))
05986         ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
05987           "UnableToThresholdImage");
05988       if (pixel.red == 0)
05989         (void) GetImageDynamicThreshold(image,2.0,2.0,&pixel,&image->exception);
05990     }
05991   for (y=0; y < (long) image->rows; y++)
05992   {
05993     register IndexPacket
05994       *__restrict indexes;
05995 
05996     register long
05997       x;
05998 
05999     register PixelPacket
06000       *__restrict q;
06001 
06002     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
06003     if (q == (PixelPacket *) NULL)
06004       break;
06005     indexes=GetAuthenticIndexQueue(image);
06006     if (IsMagickGray(&pixel) != MagickFalse)
06007       for (x=0; x < (long) image->columns; x++)
06008       {
06009         index=(IndexPacket) ((MagickRealType)
06010           PixelIntensityToQuantum(q) <= pixel.red ? 0 : 1);
06011         indexes[x]=index;
06012         q->red=image->colormap[(long) index].red;
06013         q->green=image->colormap[(long) index].green;
06014         q->blue=image->colormap[(long) index].blue;
06015         q++;
06016       }
06017     else
06018       for (x=0; x < (long) image->columns; x++)
06019       {
06020         q->red=(Quantum) ((MagickRealType)
06021           q->red <= pixel.red ? 0 : QuantumRange);
06022         q->green=(Quantum) ((MagickRealType)
06023           q->green <= pixel.green ? 0 : QuantumRange);
06024         q->blue=(Quantum) ((MagickRealType)
06025           q->blue <= pixel.blue ? 0 : QuantumRange);
06026         q->opacity=(Quantum) ((MagickRealType)
06027           q->opacity <= pixel.opacity ? 0 : QuantumRange);
06028         q++;
06029       }
06030     if (!SyncAuthenticPixels(image,&image->exception))
06031       break;
06032   }
06033   return(MagickTrue);
06034 }
06035 
06036 /*
06037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
06038 %                                                                              %
06039 %                                                                              %
06040 %                                                                              %
06041 +     T r a n s f o r m C o l o r s p a c e                                    %
06042 %                                                                              %
06043 %                                                                              %
06044 %                                                                              %
06045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
06046 %
06047 %  TransformColorspace() converts the image to a specified colorspace.
06048 %  If the image is already in the requested colorspace, no work is performed.
06049 %  Note that the current colorspace is stored in the image colorspace member.
06050 %  The transformation matrices are not necessarily the standard ones: the
06051 %  weights are rescaled to normalize the range of the transformed values to
06052 %  be [0..QuantumRange].
06053 %
06054 %  The format of the TransformColorspace method is:
06055 %
06056 %      unsigned int (void) TransformColorspace(Image *image,
06057 %        const ColorspaceType colorspace)
06058 %
06059 %  A description of each parameter follows:
06060 %
06061 %    o image: the image to transform
06062 %
06063 %    o colorspace: the desired colorspace.
06064 %
06065 */
06066 MagickExport unsigned int TransformColorspace(Image *image,
06067   const ColorspaceType colorspace)
06068 {
06069   assert(image != (Image *) NULL);
06070   assert(image->signature == MagickSignature);
06071   if (image->debug != MagickFalse)
06072     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.6");
06073   return(TransformImageColorspace(image,colorspace));
06074 }
06075 
06076 /*
06077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
06078 %                                                                             %
06079 %                                                                             %
06080 %                                                                             %
06081 %   T r a n s f o r m H S L                                                   %
06082 %                                                                             %
06083 %                                                                             %
06084 %                                                                             %
06085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
06086 %
06087 %  TransformHSL() converts a (red, green, blue) to a (hue, saturation,
06088 %  lightness) triple.
06089 %
06090 %  The format of the TransformHSL method is:
06091 %
06092 %      void TransformHSL(const Quantum red,const Quantum green,
06093 %        const Quantum blue,double *hue,double *saturation,double *lightness)
06094 %
06095 %  A description of each parameter follows:
06096 %
06097 %    o red, green, blue: A Quantum value representing the red, green, and
06098 %      blue component of a pixel..
06099 %
06100 %    o hue, saturation, lightness: A pointer to a double value representing a
06101 %      component of the HSL color space.
06102 %
06103 */
06104 
06105 static inline double MagickMin(const double x,const double y)
06106 {
06107   if (x < y)
06108     return(x);
06109   return(y);
06110 }
06111 
06112 MagickExport void TransformHSL(const Quantum red,const Quantum green,
06113   const Quantum blue,double *hue,double *saturation,double *lightness)
06114 {
06115   MagickRealType
06116     b,
06117     delta,
06118     g,
06119     max,
06120     min,
06121     r;
06122 
06123   /*
06124     Convert RGB to HSL colorspace.
06125   */
06126   assert(hue != (double *) NULL);
06127   assert(saturation != (double *) NULL);
06128   assert(lightness != (double *) NULL);
06129   r=QuantumScale*red;
06130   g=QuantumScale*green;
06131   b=QuantumScale*blue;
06132   max=MagickMax(r,MagickMax(g,b));
06133   min=MagickMin(r,MagickMin(g,b));
06134   *hue=0.0;
06135   *saturation=0.0;
06136   *lightness=(double) ((min+max)/2.0);
06137   delta=max-min;
06138   if (delta == 0.0)
06139     return;
06140   *saturation=(double) (delta/((*lightness < 0.5) ? (min+max) :
06141     (2.0-max-min)));
06142   if (r == max)
06143     *hue=(double) (g == min ? 5.0+(max-b)/delta : 1.0-(max-g)/delta);
06144   else
06145     if (g == max)
06146       *hue=(double) (b == min ? 1.0+(max-r)/delta : 3.0-(max-b)/delta);
06147     else
06148       *hue=(double) (r == min ? 3.0+(max-g)/delta : 5.0-(max-r)/delta);
06149   *hue/=6.0;
06150 }
06151 
06152 /*
06153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
06154 %                                                                             %
06155 %                                                                             %
06156 %                                                                             %
06157 %   T r a n s l a t e T e x t                                                 %
06158 %                                                                             %
06159 %                                                                             %
06160 %                                                                             %
06161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
06162 %
06163 %  TranslateText() replaces any embedded formatting characters with the
06164 %  appropriate image attribute and returns the translated text.
06165 %
06166 %  The format of the TranslateText method is:
06167 %
06168 %      char *TranslateText(const ImageInfo *image_info,Image *image,
06169 %        const char *embed_text)
06170 %
06171 %  A description of each parameter follows:
06172 %
06173 %    o image_info: the image info.
06174 %
06175 %    o image: the image.
06176 %
06177 %    o embed_text: the address of a character string containing the embedded
06178 %      formatting characters.
06179 %
06180 */
06181 MagickExport char *TranslateText(const ImageInfo *image_info,Image *image,
06182   const char *embed_text)
06183 {
06184   assert(image != (Image *) NULL);
06185   assert(image->signature == MagickSignature);
06186   if (image->debug != MagickFalse)
06187     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.6");
06188   return(InterpretImageProperties(image_info,image,embed_text));
06189 }
06190 
06191 /*
06192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
06193 %                                                                             %
06194 %                                                                             %
06195 %                                                                             %
06196 %     T r a n s p a r e n t I m a g e                                         %
06197 %                                                                             %
06198 %                                                                             %
06199 %                                                                             %
06200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
06201 %
06202 %  TransparentImage() changes the opacity value associated with any pixel
06203 %  that matches color to the value defined by opacity.
06204 %
06205 %  By default color must match a particular pixel color exactly.  However,
06206 %  in many cases two colors may differ by a small amount.  Fuzz defines
06207 %  how much tolerance is acceptable to consider two colors as the same.
06208 %  For example, set fuzz to 10 and the color red at intensities of 100 and
06209 %  102 respectively are now interpreted as the same color.
06210 %
06211 %  The format of the TransparentImage method is:
06212 %
06213 %      MagickBooleanType TransparentImage(Image *image,
06214 %        const PixelPacket target,const Quantum opacity)
06215 %
06216 %  A description of each parameter follows:
06217 %
06218 %    o image: the image.
06219 %
06220 %    o target: the RGB value of the target color.
06221 %
06222 %    o opacity: the replacement opacity value.
06223 %
06224 */
06225 MagickExport MagickBooleanType TransparentImage(Image *image,
06226   const PixelPacket target,const Quantum opacity)
06227 {
06228 #define TransparentImageTag  "Transparent/Image"
06229 
06230   long
06231     y;
06232 
06233   MagickBooleanType
06234     proceed;
06235 
06236   /*
06237     Make image color transparent.
06238   */
06239   assert(image != (Image *) NULL);
06240   assert(image->signature == MagickSignature);
06241   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.1.0");
06242   if (image->debug != MagickFalse)
06243     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
06244   if (image->matte == MagickFalse)
06245     (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
06246   for (y=0; y < (long) image->rows; y++)
06247   {
06248     register long
06249       x;
06250 
06251     register PixelPacket
06252       *__restrict q;
06253 
06254     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
06255     if (q == (PixelPacket *) NULL)
06256       break;
06257     for (x=0; x < (long) image->columns; x++)
06258     {
06259       if (IsColorSimilar(image,q,&target) != MagickFalse)
06260         q->opacity=opacity;
06261       q++;
06262     }
06263     if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
06264       break;
06265     proceed=SetImageProgress(image,TransparentImageTag,y,image->rows);
06266     if (proceed == MagickFalse)
06267       break;
06268   }
06269   return(MagickTrue);
06270 }
06271 
06272 /*
06273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
06274 %                                                                             %
06275 %                                                                             %
06276 %                                                                             %
06277 %   U n s h i f t I m a g e L i s t                                           %
06278 %                                                                             %
06279 %                                                                             %
06280 %                                                                             %
06281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
06282 %
06283 %  UnshiftImageList() adds the image to the beginning of the list.
06284 %
06285 %  The format of the UnshiftImageList method is:
06286 %
06287 %      unsigned int UnshiftImageList(Image *images,const Image *image,
06288 %        ExceptionInfo *exception)
06289 %
06290 %  A description of each parameter follows:
06291 %
06292 %    o images: the image list.
06293 %
06294 %    o image: the image.
06295 %
06296 %    o exception: return any errors or warnings in this structure.
06297 %
06298 */
06299 MagickExport unsigned int UnshiftImageList(Image **images,const Image *image,
06300   ExceptionInfo *exception)
06301 {
06302   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
06303   PrependImageToList(images,CloneImageList(image,exception));
06304   return(MagickTrue);
06305 }
06306 
06307 /*
06308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
06309 %                                                                             %
06310 %                                                                             %
06311 %                                                                             %
06312 +   V a l i d a t e C o l o r m a p I n d e x                                 %
06313 %                                                                             %
06314 %                                                                             %
06315 %                                                                             %
06316 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
06317 %
06318 %  ValidateColormapIndex() validates the colormap index.  If the index does
06319 %  not range from 0 to the number of colors in the colormap an exception
06320 %  issued and 0 is returned.
06321 %
06322 %  The format of the ValidateColormapIndex method is:
06323 %
06324 %      IndexPacket ValidateColormapIndex(Image *image,const unsigned int index)
06325 %
06326 %  A description of each parameter follows:
06327 %
06328 %    o index: Method ValidateColormapIndex returns colormap index if it is
06329 %      valid other an exception issued and 0 is returned.
06330 %
06331 %    o image: the image.
06332 %
06333 %    o index: This integer is the colormap index.
06334 %
06335 */
06336 
06337 MagickExport IndexPacket ValidateColormapIndex(Image *image,
06338   const unsigned long index)
06339 {
06340   if (image->debug != MagickFalse)
06341     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.4.4");
06342   return(ConstrainColormapIndex(image,index));
06343 }
06344 #endif

Generated on Thu Jul 2 12:03:14 2009 for MagickCore by  doxygen 1.5.8