]> granicus.if.org Git - imagemagick/blob - magick/deprecate.c
Remove previous geometry changes
[imagemagick] / magick / deprecate.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %        DDDD   EEEEE  PPPP   RRRR   EEEEE   CCCC   AAA   TTTTT  EEEEE        %
7 %        D   D  E      P   P  R   R  E      C      A   A    T    E            %
8 %        D   D  EEE    PPPPP  RRRR   EEE    C      AAAAA    T    EEE          %
9 %        D   D  E      P      R R    E      C      A   A    T    E            %
10 %        DDDD   EEEEE  P      R  R   EEEEE   CCCC  A   A    T    EEEEE        %
11 %                                                                             %
12 %                                                                             %
13 %                        MagickCore Deprecated Methods                        %
14 %                                                                             %
15 %                              Software Design                                %
16 %                                John Cristy                                  %
17 %                                October 2002                                 %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      %
21 %  dedicated to making software imaging solutions freely available.           %
22 %                                                                             %
23 %  You may not use this file except in compliance with the License.  You may  %
24 %  obtain a copy of the License at                                            %
25 %                                                                             %
26 %    http://www.imagemagick.org/script/license.php                            %
27 %                                                                             %
28 %  Unless required by applicable law or agreed to in writing, software        %
29 %  distributed under the License is distributed on an "AS IS" BASIS,          %
30 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
31 %  See the License for the specific language governing permissions and        %
32 %  limitations under the License.                                             %
33 %                                                                             %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 %
37 %
38 */
39 \f
40 /*
41   Include declarations.
42 */
43 #include "magick/studio.h"
44 #include "magick/property.h"
45 #include "magick/blob.h"
46 #include "magick/blob-private.h"
47 #include "magick/cache.h"
48 #include "magick/cache-view.h"
49 #include "magick/client.h"
50 #include "magick/color.h"
51 #include "magick/color-private.h"
52 #include "magick/colormap.h"
53 #include "magick/colormap-private.h"
54 #include "magick/colorspace.h"
55 #include "magick/composite.h"
56 #include "magick/composite-private.h"
57 #include "magick/constitute.h"
58 #include "magick/deprecate.h"
59 #include "magick/draw.h"
60 #include "magick/draw-private.h"
61 #include "magick/effect.h"
62 #include "magick/enhance.h"
63 #include "magick/exception.h"
64 #include "magick/exception-private.h"
65 #include "magick/fx.h"
66 #include "magick/geometry.h"
67 #include "magick/identify.h"
68 #include "magick/image.h"
69 #include "magick/image-private.h"
70 #include "magick/list.h"
71 #include "magick/log.h"
72 #include "magick/memory_.h"
73 #include "magick/magick.h"
74 #include "magick/monitor.h"
75 #include "magick/monitor-private.h"
76 #include "magick/morphology.h"
77 #include "magick/paint.h"
78 #include "magick/pixel.h"
79 #include "magick/pixel-private.h"
80 #include "magick/quantize.h"
81 #include "magick/random_.h"
82 #include "magick/resource_.h"
83 #include "magick/semaphore.h"
84 #include "magick/segment.h"
85 #include "magick/splay-tree.h"
86 #include "magick/statistic.h"
87 #include "magick/string_.h"
88 #include "magick/threshold.h"
89 #include "magick/transform.h"
90 #include "magick/utility.h"
91 \f
92 #if !defined(MAGICKCORE_EXCLUDE_DEPRECATED)
93 /*
94   Global declarations.
95 */
96 static MonitorHandler
97   monitor_handler = (MonitorHandler) NULL;
98 \f
99 /*
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 %                                                                             %
102 %                                                                             %
103 %                                                                             %
104 %   A c q u i r e C a c h e V i e w I n d e x e s                             %
105 %                                                                             %
106 %                                                                             %
107 %                                                                             %
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 %
110 %  AcquireCacheViewIndexes() returns the indexes associated with the specified
111 %  view.
112 %
113 %  The format of the AcquireCacheViewIndexes method is:
114 %
115 %      const IndexPacket *AcquireCacheViewIndexes(const CacheView *cache_view)
116 %
117 %  A description of each parameter follows:
118 %
119 %    o cache_view: the cache view.
120 %
121 */
122 MagickExport const IndexPacket *AcquireCacheViewIndexes(
123   const CacheView *cache_view)
124 {
125   return(GetCacheViewVirtualIndexQueue(cache_view));
126 }
127 \f
128 /*
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 %                                                                             %
131 %                                                                             %
132 %                                                                             %
133 %   A c q u i r e C a c h e V i e w P i x e l s                               %
134 %                                                                             %
135 %                                                                             %
136 %                                                                             %
137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138 %
139 %  AcquireCacheViewPixels() gets pixels from the in-memory or disk pixel cache
140 %  as defined by the geometry parameters.   A pointer to the pixels is returned
141 %  if the pixels are transferred, otherwise a NULL is returned.
142 %
143 %  The format of the AcquireCacheViewPixels method is:
144 %
145 %      const PixelPacket *AcquireCacheViewPixels(const CacheView *cache_view,
146 %        const long x,const long y,const unsigned long columns,
147 %        const unsigned long rows,ExceptionInfo *exception)
148 %
149 %  A description of each parameter follows:
150 %
151 %    o cache_view: the cache view.
152 %
153 %    o x,y,columns,rows:  These values define the perimeter of a region of
154 %      pixels.
155 %
156 %    o exception: return any errors or warnings in this structure.
157 %
158 */
159 MagickExport const PixelPacket *AcquireCacheViewPixels(
160   const CacheView *cache_view,const long x,const long y,
161   const unsigned long columns,const unsigned long rows,ExceptionInfo *exception)
162 {
163   return(GetCacheViewVirtualPixels(cache_view,x,y,columns,rows,exception));
164 }
165 \f
166 /*
167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 %                                                                             %
169 %                                                                             %
170 %                                                                             %
171 %   A c q u i r e I m a g e P i x e l s                                        %
172 %                                                                             % %                                                                             %
173 %                                                                             %
174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175 %
176 %  AcquireImagePixels() returns an immutable pixel region. If the
177 %  region is successfully accessed, a pointer to it is returned, otherwise
178 %  NULL is returned. The returned pointer may point to a temporary working
179 %  copy of the pixels or it may point to the original pixels in memory.
180 %  Performance is maximized if the selected region is part of one row, or one
181 %  or more full rows, since there is opportunity to access the pixels in-place
182 %  (without a copy) if the image is in RAM, or in a memory-mapped file.  The
183 %  returned pointer should *never* be deallocated by the user.
184 %
185 %  Pixels accessed via the returned pointer represent a simple array of type
186 %  PixelPacket.  If the image type is CMYK or the storage class is PseudoClass,
187 %  call GetAuthenticIndexQueue() after invoking GetAuthenticPixels() to access
188 %  the black color component or to obtain the colormap indexes (of type
189 %  IndexPacket) corresponding to the region.
190 %
191 %  If you plan to modify the pixels, use GetAuthenticPixels() instead.
192 %
193 %  Note, the AcquireImagePixels() and GetAuthenticPixels() methods are not
194 %  thread-safe.  In a threaded environment, use GetCacheViewVirtualPixels() or
195 %  GetCacheViewAuthenticPixels() instead.
196 %
197 %  The format of the AcquireImagePixels() method is:
198 %
199 %      const PixelPacket *AcquireImagePixels(const Image *image,const long x,
200 %        const long y,const unsigned long columns,const unsigned long rows,
201 %        ExceptionInfo *exception)
202 %
203 %  A description of each parameter follows:
204 %
205 %    o image: the image.
206 %
207 %    o x,y,columns,rows:  These values define the perimeter of a region of
208 %      pixels.
209 %
210 %    o exception: return any errors or warnings in this structure.
211 %
212 */
213 MagickExport const PixelPacket *AcquireImagePixels(const Image *image,
214   const long x,const long y,const unsigned long columns,
215   const unsigned long rows,ExceptionInfo *exception)
216 {
217   return(GetVirtualPixels(image,x,y,columns,rows,exception));
218 }
219 \f
220 /*
221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222 %                                                                             %
223 %                                                                             %
224 %                                                                             %
225 %   A c q u i r e I n d e x e s                                               %
226 %                                                                             %
227 %                                                                             %
228 %                                                                             %
229 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230 %
231 %  AcquireIndexes() returns the black channel or the colormap indexes
232 %  associated with the last call to QueueAuthenticPixels() or GetVirtualPixels().
233 %  NULL is returned if the black channel or colormap indexes are not available.
234 %
235 %  The format of the AcquireIndexes() method is:
236 %
237 %      const IndexPacket *AcquireIndexes(const Image *image)
238 %
239 %  A description of each parameter follows:
240 %
241 %    o indexes: AcquireIndexes() returns the indexes associated with the last
242 %      call to QueueAuthenticPixels() or GetVirtualPixels().
243 %
244 %    o image: the image.
245 %
246 */
247 MagickExport const IndexPacket *AcquireIndexes(const Image *image)
248 {
249   return(GetVirtualIndexQueue(image));
250 }
251 \f
252 /*
253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254 %                                                                             %
255 %                                                                             %
256 %                                                                             %
257 %   A c q u i r e M e m o r y                                                 %
258 %                                                                             %
259 %                                                                             %
260 %                                                                             %
261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262 %
263 %  AcquireMemory() returns a pointer to a block of memory at least size bytes
264 %  suitably aligned for any use.
265 %
266 %  The format of the AcquireMemory method is:
267 %
268 %      void *AcquireMemory(const size_t size)
269 %
270 %  A description of each parameter follows:
271 %
272 %    o size: the size of the memory in bytes to allocate.
273 %
274 */
275 MagickExport void *AcquireMemory(const size_t size)
276 {
277   void
278     *allocation;
279
280   assert(size != 0);
281   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
282   allocation=malloc(size);
283   return(allocation);
284 }
285 \f
286 /*
287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
288 %                                                                             %
289 %                                                                             %
290 %                                                                             %
291 %   A c q u i r e O n e C a c h e V i e w P i x e l                           %
292 %                                                                             %
293 %                                                                             %
294 %                                                                             %
295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 %
297 %  AcquireOneCacheViewPixel() returns a single pixel at the specified (x,y)
298 %  location.  The image background color is returned if an error occurs.  If
299 %  you plan to modify the pixel, use GetOneCacheViewAuthenticPixel() instead.
300 %
301 %  The format of the AcquireOneCacheViewPixel method is:
302 %
303 %      MagickBooleanType AcquireOneCacheViewPixel(const CacheView *cache_view,
304 %        const long x,const long y,PixelPacket *pixel,ExceptionInfo *exception)
305 %
306 %  A description of each parameter follows:
307 %
308 %    o cache_view: the cache view.
309 %
310 %    o x,y:  These values define the offset of the pixel.
311 %
312 %    o pixel: return a pixel at the specified (x,y) location.
313 %
314 %    o exception: return any errors or warnings in this structure.
315 %
316 */
317 MagickExport MagickBooleanType AcquireOneCacheViewPixel(
318   const CacheView *cache_view,const long x,const long y,PixelPacket *pixel,
319   ExceptionInfo *exception)
320 {
321   return(GetOneCacheViewVirtualPixel(cache_view,x,y,pixel,exception));
322 }
323 \f
324 /*
325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
326 %                                                                             %
327 %                                                                             %
328 %                                                                             %
329 %   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             %
330 %                                                                             %
331 %                                                                             %
332 %                                                                             %
333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334 %
335 %  AcquireOneCacheViewVirtualPixel() returns a single pixel at the specified
336 %  (x,y) location.  The image background color is returned if an error occurs.
337 %  If you plan to modify the pixel, use GetOneCacheViewAuthenticPixel() instead.
338 %
339 %  The format of the AcquireOneCacheViewPixel method is:
340 %
341 %      MagickBooleanType AcquireOneCacheViewVirtualPixel(
342 %        const CacheView *cache_view,
343 %        const VirtualPixelMethod virtual_pixel_method,const long x,
344 %        const long y,PixelPacket *pixel,ExceptionInfo *exception)
345 %
346 %  A description of each parameter follows:
347 %
348 %    o cache_view: the cache view.
349 %
350 %    o virtual_pixel_method: the virtual pixel method.
351 %
352 %    o x,y:  These values define the offset of the pixel.
353 %
354 %    o pixel: return a pixel at the specified (x,y) location.
355 %
356 %    o exception: return any errors or warnings in this structure.
357 %
358 */
359 MagickExport MagickBooleanType AcquireOneCacheViewVirtualPixel(
360   const CacheView *cache_view,const VirtualPixelMethod virtual_pixel_method,
361   const long x,const long y,PixelPacket *pixel,ExceptionInfo *exception)
362 {
363   MagickBooleanType
364     status;
365
366   status=GetOneCacheViewVirtualMethodPixel(cache_view,virtual_pixel_method,
367     x,y,pixel,exception);
368   return(status);
369 }
370 \f
371 /*
372 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
373 %                                                                             %
374 %                                                                             %
375 %                                                                             %
376 %   A c q u i r e O n e M a g i c k P i x e l                                 %
377 %                                                                             %
378 %                                                                             %
379 %                                                                             %
380 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
381 %
382 %  AcquireOneMagickPixel() returns a single pixel at the specified (x,y)
383 %  location.  The image background color is returned if an error occurs.  If
384 %  you plan to modify the pixel, use GetOnePixel() instead.
385 %
386 %  The format of the AcquireOneMagickPixel() method is:
387 %
388 %      MagickPixelPacket AcquireOneMagickPixel(const Image image,const long x,
389 %        const long y,ExceptionInfo exception)
390 %
391 %  A description of each parameter follows:
392 %
393 %    o image: the image.
394 %
395 %    o x,y:  These values define the location of the pixel to return.
396 %
397 %    o exception: return any errors or warnings in this structure.
398 %
399 */
400 MagickExport MagickPixelPacket AcquireOneMagickPixel(const Image *image,
401   const long x,const long y,ExceptionInfo *exception)
402 {
403   MagickPixelPacket
404     pixel;
405
406   (void) GetOneVirtualMagickPixel(image,x,y,&pixel,exception);
407   return(pixel);
408 }
409 \f
410 /*
411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
412 %                                                                             %
413 %                                                                             %
414 %                                                                             %
415 %   A c q u i r e O n e P i x e l                                             %
416 %                                                                             %
417 %                                                                             %
418 %                                                                             %
419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
420 %
421 %  AcquireOnePixel() returns a single pixel at the specified (x,y) location.
422 %  The image background color is returned if an error occurs.  If you plan to
423 %  modify the pixel, use GetOnePixel() instead.
424 %
425 %  The format of the AcquireOnePixel() method is:
426 %
427 %      PixelPacket AcquireOnePixel(const Image image,const long x,
428 %        const long y,ExceptionInfo exception)
429 %
430 %  A description of each parameter follows:
431 %
432 %    o image: the image.
433 %
434 %    o x,y:  These values define the location of the pixel to return.
435 %
436 %    o exception: return any errors or warnings in this structure.
437 %
438 */
439 MagickExport PixelPacket AcquireOnePixel(const Image *image,const long x,
440   const long y,ExceptionInfo *exception)
441 {
442   PixelPacket
443     pixel;
444
445   (void) GetOneVirtualPixel(image,x,y,&pixel,exception);
446   return(pixel);
447 }
448 \f
449 /*
450 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451 %                                                                             %
452 %                                                                             %
453 %                                                                             %
454 %   A c q u i r e O n e V i r t u a l P i x e l                               %
455 %                                                                             %
456 %                                                                             %
457 %                                                                             %
458 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
459 %
460 %  AcquireOneVirtualPixel() returns a single pixel at the specified (x,y)
461 %  location as defined by specified pixel method.  The image background color
462 %  is returned if an error occurs.  If you plan to modify the pixel, use
463 %  GetOnePixel() instead.
464 %
465 %  The format of the AcquireOneVirtualPixel() method is:
466 %
467 %      PixelPacket AcquireOneVirtualPixel(const Image image,
468 %        const VirtualPixelMethod virtual_pixel_method,const long x,
469 %        const long y,ExceptionInfo exception)
470 %
471 %  A description of each parameter follows:
472 %
473 %    o virtual_pixel_method: the virtual pixel method.
474 %
475 %    o image: the image.
476 %
477 %    o x,y:  These values define the location of the pixel to return.
478 %
479 %    o exception: return any errors or warnings in this structure.
480 %
481 */
482 MagickExport PixelPacket AcquireOneVirtualPixel(const Image *image,
483   const VirtualPixelMethod virtual_pixel_method,const long x,const long y,
484   ExceptionInfo *exception)
485 {
486   PixelPacket
487     pixel;
488
489   (void) GetOneVirtualMethodPixel(image,virtual_pixel_method,x,y,&pixel,
490     exception);
491   return(pixel);
492 }
493 \f
494 /*
495 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
496 %                                                                             %
497 %                                                                             %
498 %                                                                             %
499 %   A c q u i r e P i x e l s                                                 %
500 %                                                                             %
501 %                                                                             %
502 %                                                                             %
503 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
504 %
505 %  AcquirePixels() returns the pixels associated with the last call to
506 %  QueueAuthenticPixels() or GetVirtualPixels().
507 %
508 %  The format of the AcquirePixels() method is:
509 %
510 %      const PixelPacket *AcquirePixels(const Image image)
511 %
512 %  A description of each parameter follows:
513 %
514 %    o image: the image.
515 %
516 */
517 MagickExport const PixelPacket *AcquirePixels(const Image *image)
518 {
519   return(GetVirtualPixelQueue(image));
520 }
521 \f
522 /*
523 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
524 %                                                                             %
525 %                                                                             %
526 %                                                                             %
527 %   A f f i n i t y I m a g e                                                 %
528 %                                                                             %
529 %                                                                             %
530 %                                                                             %
531 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
532 %
533 %  AffinityImage() replaces the colors of an image with the closest color from
534 %  a reference image.
535 %
536 %  The format of the AffinityImage method is:
537 %
538 %      MagickBooleanType AffinityImage(const QuantizeInfo *quantize_info,
539 %        Image *image,const Image *affinity_image)
540 %
541 %  A description of each parameter follows:
542 %
543 %    o quantize_info: Specifies a pointer to an QuantizeInfo structure.
544 %
545 %    o image: the image.
546 %
547 %    o affinity_image: the reference image.
548 %
549 */
550 MagickExport MagickBooleanType AffinityImage(const QuantizeInfo *quantize_info,
551   Image *image,const Image *affinity_image)
552 {
553   return(RemapImage(quantize_info,image,affinity_image));
554 }
555 \f
556 /*
557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
558 %                                                                             %
559 %                                                                             %
560 %                                                                             %
561 %   A f f i n i t y I m a g e s                                               %
562 %                                                                             %
563 %                                                                             %
564 %                                                                             %
565 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
566 %
567 %  AffinityImages() replaces the colors of a sequence of images with the
568 %  closest color from a reference image.
569 %
570 %  The format of the AffinityImage method is:
571 %
572 %      MagickBooleanType AffinityImages(const QuantizeInfo *quantize_info,
573 %        Image *images,Image *affinity_image)
574 %
575 %  A description of each parameter follows:
576 %
577 %    o quantize_info: Specifies a pointer to an QuantizeInfo structure.
578 %
579 %    o images: the image sequence.
580 %
581 %    o affinity_image: the reference image.
582 %
583 */
584 MagickExport MagickBooleanType AffinityImages(const QuantizeInfo *quantize_info,
585   Image *images,const Image *affinity_image)
586 {
587   return(RemapImages(quantize_info,images,affinity_image));
588 }
589 \f
590 /*
591 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
592 %                                                                             %
593 %                                                                             %
594 %                                                                             %
595 %   A l l o c a t e I m a g e                                                 %
596 %                                                                             %
597 %                                                                             %
598 %                                                                             %
599 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
600 %
601 %  AllocateImage() returns a pointer to an image structure initialized to
602 %  default values.
603 %
604 %  The format of the AllocateImage method is:
605 %
606 %      Image *AllocateImage(const ImageInfo *image_info)
607 %
608 %  A description of each parameter follows:
609 %
610 %    o image_info: Many of the image default values are set from this
611 %      structure.  For example, filename, compression, depth, background color,
612 %      and others.
613 %
614 */
615 MagickExport Image *AllocateImage(const ImageInfo *image_info)
616 {
617   return(AcquireImage(image_info));
618 }
619 \f
620 /*
621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
622 %                                                                             %
623 %                                                                             %
624 %                                                                             %
625 %   A l l o c a t e I m a g e C o l o r m a p                                 %
626 %                                                                             %
627 %                                                                             %
628 %                                                                             %
629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
630 %
631 %  AllocateImageColormap() allocates an image colormap and initializes
632 %  it to a linear gray colorspace.  If the image already has a colormap,
633 %  it is replaced.  AllocateImageColormap() returns MagickTrue if successful,
634 %  otherwise MagickFalse if there is not enough memory.
635 %
636 %  The format of the AllocateImageColormap method is:
637 %
638 %      MagickBooleanType AllocateImageColormap(Image *image,
639 %        const unsigned long colors)
640 %
641 %  A description of each parameter follows:
642 %
643 %    o image: the image.
644 %
645 %    o colors: the number of colors in the image colormap.
646 %
647 */
648 MagickExport MagickBooleanType AllocateImageColormap(Image *image,
649   const unsigned long colors)
650 {
651   return(AcquireImageColormap(image,colors));
652 }
653 \f
654 /*
655 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
656 %                                                                             %
657 %                                                                             %
658 %                                                                             %
659 %   A l l o c a t e N e x t I m a g e                                         %
660 %                                                                             %
661 %                                                                             %
662 %                                                                             %
663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664 %
665 %  AllocateNextImage() initializes the next image in a sequence to
666 %  default values.  The next member of image points to the newly allocated
667 %  image.  If there is a memory shortage, next is assigned NULL.
668 %
669 %  The format of the AllocateNextImage method is:
670 %
671 %      void AllocateNextImage(const ImageInfo *image_info,Image *image)
672 %
673 %  A description of each parameter follows:
674 %
675 %    o image_info: Many of the image default values are set from this
676 %      structure.  For example, filename, compression, depth, background color,
677 %      and others.
678 %
679 %    o image: the image.
680 %
681 */
682 MagickExport void AllocateNextImage(const ImageInfo *image_info,Image *image)
683 {
684   AcquireNextImage(image_info,image);
685 }
686 \f
687 /*
688 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
689 %                                                                             %
690 %                                                                             %
691 %                                                                             %
692 %   A l l o c a t e S t r i n g                                               %
693 %                                                                             %
694 %                                                                             %
695 %                                                                             %
696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
697 %
698 %  AllocateString() allocates memory for a string and copies the source string
699 %  to that memory location (and returns it).
700 %
701 %  The format of the AllocateString method is:
702 %
703 %      char *AllocateString(const char *source)
704 %
705 %  A description of each parameter follows:
706 %
707 %    o source: A character string.
708 %
709 */
710 MagickExport char *AllocateString(const char *source)
711 {
712   char
713     *destination;
714
715   size_t
716     length;
717
718   assert(source != (const char *) NULL);
719   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
720   length=strlen(source)+MaxTextExtent+1;
721   destination=(char *) AcquireQuantumMemory(length,sizeof(*destination));
722   if (destination == (char *) NULL)
723     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
724   *destination='\0';
725   if (source != (char *) NULL)
726     (void) CopyMagickString(destination,source,length);
727   return(destination);
728 }
729 \f
730 /*
731 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
732 %                                                                             %
733 %                                                                             %
734 %                                                                             %
735 %     A v e r a g e I m a g e s                                               %
736 %                                                                             %
737 %                                                                             %
738 %                                                                             %
739 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
740 %
741 %  AverageImages() takes a set of images and averages them together.  Each
742 %  image in the set must have the same width and height.  AverageImages()
743 %  returns a single image with each corresponding pixel component of each
744 %  image averaged.   On failure, a NULL image is returned and exception
745 %  describes the reason for the failure.
746 %
747 %  The format of the AverageImages method is:
748 %
749 %      Image *AverageImages(Image *images,ExceptionInfo *exception)
750 %
751 %  A description of each parameter follows:
752 %
753 %    o image: the image sequence.
754 %
755 %    o exception: return any errors or warnings in this structure.
756 %
757 */
758 MagickExport Image *AverageImages(const Image *images,ExceptionInfo *exception)
759 {
760   return(EvaluateImages(images,MeanEvaluateOperator,exception));
761 }
762 \f
763 /*
764 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
765 %                                                                             %
766 %                                                                             %
767 %                                                                             %
768 %     C h a n n e l I m a g e                                                 %
769 %                                                                             %
770 %                                                                             %
771 %                                                                             %
772 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
773 %
774 %  Extract a channel from the image.  A channel is a particular color component
775 %  of each pixel in the image.
776 %
777 %  The format of the ChannelImage method is:
778 %
779 %      unsigned int ChannelImage(Image *image,const ChannelType channel)
780 %
781 %  A description of each parameter follows:
782 %
783 %    o image: the image.
784 %
785 %    o channel: Identify which channel to extract: RedChannel, GreenChannel,
786 %      BlueChannel, OpacityChannel, CyanChannel, MagentaChannel, YellowChannel,
787 %      or BlackChannel.
788 %
789 */
790 MagickExport unsigned int ChannelImage(Image *image,const ChannelType channel)
791 {
792   return(SeparateImageChannel(image,channel));
793 }
794 \f
795 /*
796 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
797 %                                                                             %
798 %                                                                             %
799 %                                                                             %
800 %     C h a n n e l T h r e s h o l d I m a g e                               %
801 %                                                                             %
802 %                                                                             %
803 %                                                                             %
804 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
805 %
806 %  ChannelThresholdImage() changes the value of individual pixels based on
807 %  the intensity of each pixel channel.  The result is a high-contrast image.
808 %
809 %  The format of the ChannelThresholdImage method is:
810 %
811 %      unsigned int ChannelThresholdImage(Image *image,const char *level)
812 %
813 %  A description of each parameter follows:
814 %
815 %    o image: the image.
816 %
817 %    o level: define the threshold values.
818 %
819 */
820 MagickExport unsigned int ChannelThresholdImage(Image *image,const char *level)
821 {
822   MagickPixelPacket
823     threshold;
824
825   GeometryInfo
826     geometry_info;
827
828   unsigned int
829     flags,
830     status;
831
832   assert(image != (Image *) NULL);
833   assert(image->signature == MagickSignature);
834   if (image->debug != MagickFalse)
835     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
836   if (image->debug != MagickFalse)
837     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
838   if (level == (char *) NULL)
839     return(MagickFalse);
840   flags=ParseGeometry(level,&geometry_info);
841   threshold.red=geometry_info.rho;
842   threshold.green=geometry_info.sigma;
843   if ((flags & SigmaValue) == 0)
844     threshold.green=threshold.red;
845   threshold.blue=geometry_info.xi;
846   if ((flags & XiValue) == 0)
847     threshold.blue=threshold.red;
848   status=BilevelImageChannel(image,RedChannel,threshold.red);
849   status|=BilevelImageChannel(image,GreenChannel,threshold.green);
850   status|=BilevelImageChannel(image,BlueChannel,threshold.blue);
851   return(status);
852 }
853 \f
854 /*
855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
856 %                                                                             %
857 %                                                                             %
858 %                                                                             %
859 %   C l i p I m a g e P a t h                                                 %
860 %                                                                             %
861 %                                                                             %
862 %                                                                             %
863 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
864 %
865 %  ClipPathImage() sets the image clip mask based any clipping path information
866 %  if it exists.
867 %
868 %  The format of the ClipImage method is:
869 %
870 %      MagickBooleanType ClipPathImage(Image *image,const char *pathname,
871 %        const MagickBooleanType inside)
872 %
873 %  A description of each parameter follows:
874 %
875 %    o image: the image.
876 %
877 %    o pathname: name of clipping path resource. If name is preceded by #, use
878 %      clipping path numbered by name.
879 %
880 %    o inside: if non-zero, later operations take effect inside clipping path.
881 %      Otherwise later operations take effect outside clipping path.
882 %
883 */
884 MagickExport MagickBooleanType ClipPathImage(Image *image,const char *pathname,
885   const MagickBooleanType inside)
886 {
887   return(ClipImagePath(image,pathname,inside));
888 }
889 \f
890 /*
891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
892 %                                                                             %
893 %                                                                             %
894 %                                                                             %
895 %   C l o n e I m a g e A t t r i b u t e s                                   %
896 %                                                                             %
897 %                                                                             %
898 %                                                                             %
899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
900 %
901 %  CloneImageAttributes() clones one or more image attributes.
902 %
903 %  The format of the CloneImageAttributes method is:
904 %
905 %      MagickBooleanType CloneImageAttributes(Image *image,
906 %        const Image *clone_image)
907 %
908 %  A description of each parameter follows:
909 %
910 %    o image: the image.
911 %
912 %    o clone_image: the clone image.
913 %
914 */
915 MagickExport MagickBooleanType CloneImageAttributes(Image *image,
916   const Image *clone_image)
917 {
918   return(CloneImageProperties(image,clone_image));
919 }
920 \f
921 /*
922 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
923 %                                                                             %
924 %                                                                             %
925 %                                                                             %
926 %   C l o n e M e m o r y                                                     %
927 %                                                                             %
928 %                                                                             %
929 %                                                                             %
930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
931 %
932 %  CloneMemory() copies size bytes from memory area source to the destination.
933 %  Copying between objects that overlap will take place correctly.  It returns
934 %  destination.
935 %
936 %  The format of the CloneMemory method is:
937 %
938 %      void *CloneMemory(void *destination,const void *source,
939 %        const size_t size)
940 %
941 %  A description of each parameter follows:
942 %
943 %    o destination: the destination.
944 %
945 %    o source: the source.
946 %
947 %    o size: the size of the memory in bytes to allocate.
948 %
949 */
950 MagickExport void *CloneMemory(void *destination,const void *source,
951   const size_t size)
952 {
953   register const unsigned char
954     *p;
955
956   register unsigned char
957     *q;
958
959   register long
960     i;
961
962   assert(destination != (void *) NULL);
963   assert(source != (const void *) NULL);
964   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
965   p=(const unsigned char *) source;
966   q=(unsigned char *) destination;
967   if ((p <= q) || ((p+size) >= q))
968     return(CopyMagickMemory(destination,source,size));
969   /*
970     Overlap, copy backwards.
971   */
972   p+=size;
973   q+=size;
974   for (i=(long) (size-1); i >= 0; i--)
975     *--q=(*--p);
976   return(destination);
977 }
978 \f
979 /*
980 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
981 %                                                                             %
982 %                                                                             %
983 %                                                                             %
984 %   C l o s e C a c h e V i e w                                               %
985 %                                                                             %
986 %                                                                             %
987 %                                                                             %
988 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
989 %
990 %  CloseCacheView() closes the specified view returned by a previous call to
991 %  OpenCacheView().
992 %
993 %  The format of the CloseCacheView method is:
994 %
995 %      CacheView *CloseCacheView(CacheView *view_info)
996 %
997 %  A description of each parameter follows:
998 %
999 %    o view_info: the address of a structure of type CacheView.
1000 %
1001 */
1002 MagickExport CacheView *CloseCacheView(CacheView *view_info)
1003 {
1004   return(DestroyCacheView(view_info));
1005 }
1006 \f
1007 /*
1008 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1009 %                                                                             %
1010 %                                                                             %
1011 %                                                                             %
1012 %   C o l o r F l o o d f i l l I m a g e                                     %
1013 %                                                                             %
1014 %                                                                             %
1015 %                                                                             %
1016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1017 %
1018 %  ColorFloodfill() changes the color value of any pixel that matches
1019 %  target and is an immediate neighbor.  If the method FillToBorderMethod is
1020 %  specified, the color value is changed for any neighbor pixel that does not
1021 %  match the bordercolor member of image.
1022 %
1023 %  By default target must match a particular pixel color exactly.
1024 %  However, in many cases two colors may differ by a small amount.  The
1025 %  fuzz member of image defines how much tolerance is acceptable to
1026 %  consider two colors as the same.  For example, set fuzz to 10 and the
1027 %  color red at intensities of 100 and 102 respectively are now
1028 %  interpreted as the same color for the purposes of the floodfill.
1029 %
1030 %  The format of the ColorFloodfillImage method is:
1031 %
1032 %      MagickBooleanType ColorFloodfillImage(Image *image,
1033 %        const DrawInfo *draw_info,const PixelPacket target,
1034 %        const long x_offset,const long y_offset,const PaintMethod method)
1035 %
1036 %  A description of each parameter follows:
1037 %
1038 %    o image: the image.
1039 %
1040 %    o draw_info: the draw info.
1041 %
1042 %    o target: the RGB value of the target color.
1043 %
1044 %    o x,y: the starting location of the operation.
1045 %
1046 %    o method: Choose either FloodfillMethod or FillToBorderMethod.
1047 %
1048 */
1049
1050 #define MaxStacksize  (1UL << 15)
1051 #define PushSegmentStack(up,left,right,delta) \
1052 { \
1053   if (s >= (segment_stack+MaxStacksize)) \
1054     ThrowBinaryException(DrawError,"SegmentStackOverflow",image->filename) \
1055   else \
1056     { \
1057       if ((((up)+(delta)) >= 0) && (((up)+(delta)) < (long) image->rows)) \
1058         { \
1059           s->x1=(double) (left); \
1060           s->y1=(double) (up); \
1061           s->x2=(double) (right); \
1062           s->y2=(double) (delta); \
1063           s++; \
1064         } \
1065     } \
1066 }
1067
1068 MagickExport MagickBooleanType ColorFloodfillImage(Image *image,
1069   const DrawInfo *draw_info,const PixelPacket target,const long x_offset,
1070   const long y_offset,const PaintMethod method)
1071 {
1072   Image
1073     *floodplane_image;
1074
1075   long
1076     offset,
1077     start,
1078     x,
1079     x1,
1080     x2,
1081     y;
1082
1083   MagickBooleanType
1084     skip;
1085
1086   PixelPacket
1087     fill_color;
1088
1089   register SegmentInfo
1090     *s;
1091
1092   SegmentInfo
1093     *segment_stack;
1094
1095   /*
1096     Check boundary conditions.
1097   */
1098   assert(image != (Image *) NULL);
1099   assert(image->signature == MagickSignature);
1100   if (image->debug != MagickFalse)
1101     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1102   assert(draw_info != (DrawInfo *) NULL);
1103   assert(draw_info->signature == MagickSignature);
1104   if ((x_offset < 0) || (x_offset >= (long) image->columns))
1105     return(MagickFalse);
1106   if ((y_offset < 0) || (y_offset >= (long) image->rows))
1107     return(MagickFalse);
1108   if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1109     return(MagickFalse);
1110   if (image->matte == MagickFalse)
1111     (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
1112   floodplane_image=CloneImage(image,image->columns,image->rows,MagickTrue,
1113     &image->exception);
1114   if (floodplane_image == (Image *) NULL)
1115     return(MagickFalse);
1116   (void) SetImageAlphaChannel(floodplane_image,OpaqueAlphaChannel);
1117   /*
1118     Set floodfill color.
1119   */
1120   segment_stack=(SegmentInfo *) AcquireQuantumMemory(MaxStacksize,
1121     sizeof(*segment_stack));
1122   if (segment_stack == (SegmentInfo *) NULL)
1123     {
1124       floodplane_image=DestroyImage(floodplane_image);
1125       ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1126         image->filename);
1127     }
1128   /*
1129     Push initial segment on stack.
1130   */
1131   x=x_offset;
1132   y=y_offset;
1133   start=0;
1134   s=segment_stack;
1135   PushSegmentStack(y,x,x,1);
1136   PushSegmentStack(y+1,x,x,-1);
1137   while (s > segment_stack)
1138   {
1139     register const PixelPacket
1140       *restrict p;
1141
1142     register long
1143       x;
1144
1145     register PixelPacket
1146       *restrict q;
1147
1148     /*
1149       Pop segment off stack.
1150     */
1151     s--;
1152     x1=(long) s->x1;
1153     x2=(long) s->x2;
1154     offset=(long) s->y2;
1155     y=(long) s->y1+offset;
1156     /*
1157       Recolor neighboring pixels.
1158     */
1159     p=GetVirtualPixels(image,0,y,(unsigned long) (x1+1),1,&image->exception);
1160     q=GetAuthenticPixels(floodplane_image,0,y,(unsigned long) (x1+1),1,
1161       &image->exception);
1162     if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
1163       break;
1164     p+=x1;
1165     q+=x1;
1166     for (x=x1; x >= 0; x--)
1167     {
1168       if (q->opacity == (Quantum) TransparentOpacity)
1169         break;
1170       if (method == FloodfillMethod)
1171         {
1172           if (IsColorSimilar(image,p,&target) == MagickFalse)
1173             break;
1174         }
1175       else
1176         if (IsColorSimilar(image,p,&target) != MagickFalse)
1177           break;
1178       q->opacity=(Quantum) TransparentOpacity;
1179       p--;
1180       q--;
1181     }
1182     if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse)
1183       break;
1184     skip=x >= x1 ? MagickTrue : MagickFalse;
1185     if (skip == MagickFalse)
1186       {
1187         start=x+1;
1188         if (start < x1)
1189           PushSegmentStack(y,start,x1-1,-offset);
1190         x=x1+1;
1191       }
1192     do
1193     {
1194       if (skip == MagickFalse)
1195         {
1196           if (x < (long) image->columns)
1197             {
1198               p=GetVirtualPixels(image,x,y,image->columns-x,1,
1199                 &image->exception);
1200               q=GetAuthenticPixels(floodplane_image,x,y,image->columns-x,1,
1201                 &image->exception);
1202               if ((p == (const PixelPacket *) NULL) ||
1203                   (q == (PixelPacket *) NULL))
1204                 break;
1205               for ( ; x < (long) image->columns; x++)
1206               {
1207                 if (q->opacity == (Quantum) TransparentOpacity)
1208                   break;
1209                 if (method == FloodfillMethod)
1210                   {
1211                     if (IsColorSimilar(image,p,&target) == MagickFalse)
1212                       break;
1213                   }
1214                 else
1215                   if (IsColorSimilar(image,p,&target) != MagickFalse)
1216                     break;
1217                 q->opacity=(Quantum) TransparentOpacity;
1218                 p++;
1219                 q++;
1220               }
1221               if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse)
1222                 break;
1223             }
1224           PushSegmentStack(y,start,x-1,offset);
1225           if (x > (x2+1))
1226             PushSegmentStack(y,x2+1,x-1,-offset);
1227         }
1228       skip=MagickFalse;
1229       x++;
1230       if (x <= x2)
1231         {
1232           p=GetVirtualPixels(image,x,y,(unsigned long) (x2-x+1),1,
1233             &image->exception);
1234           q=GetAuthenticPixels(floodplane_image,x,y,(unsigned long) (x2-x+1),1,
1235             &image->exception);
1236           if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
1237             break;
1238           for ( ; x <= x2; x++)
1239           {
1240             if (q->opacity == (Quantum) TransparentOpacity)
1241               break;
1242             if (method == FloodfillMethod)
1243               {
1244                 if (IsColorSimilar(image,p,&target) != MagickFalse)
1245                   break;
1246               }
1247             else
1248               if (IsColorSimilar(image,p,&target) == MagickFalse)
1249                 break;
1250             p++;
1251             q++;
1252           }
1253         }
1254       start=x;
1255     } while (x <= x2);
1256   }
1257   for (y=0; y < (long) image->rows; y++)
1258   {
1259     register const PixelPacket
1260       *restrict p;
1261
1262     register long
1263       x;
1264
1265     register PixelPacket
1266       *restrict q;
1267
1268     /*
1269       Tile fill color onto floodplane.
1270     */
1271     p=GetVirtualPixels(floodplane_image,0,y,image->columns,1,
1272       &image->exception);
1273     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
1274     if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
1275       break;
1276     for (x=0; x < (long) image->columns; x++)
1277     {
1278       if (p->opacity != OpaqueOpacity)
1279         {
1280           (void) GetFillColor(draw_info,x,y,&fill_color);
1281           MagickCompositeOver(&fill_color,(MagickRealType) fill_color.opacity,q,
1282             (MagickRealType) q->opacity,q);
1283         }
1284       p++;
1285       q++;
1286     }
1287     if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
1288       break;
1289   }
1290   segment_stack=(SegmentInfo *) RelinquishMagickMemory(segment_stack);
1291   floodplane_image=DestroyImage(floodplane_image);
1292   return(y == (long) image->rows ? MagickTrue : MagickFalse);
1293 }
1294 \f
1295 /*
1296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1297 %                                                                             %
1298 %                                                                             %
1299 %                                                                             %
1300 %   D e l e t e I m a g e A t t r i b u t e                                   %
1301 %                                                                             %
1302 %                                                                             %
1303 %                                                                             %
1304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1305 %
1306 %  DeleteImageAttribute() deletes an attribute from the image.
1307 %
1308 %  The format of the DeleteImageAttribute method is:
1309 %
1310 %      MagickBooleanType DeleteImageAttribute(Image *image,const char *key)
1311 %
1312 %  A description of each parameter follows:
1313 %
1314 %    o image: the image info.
1315 %
1316 %    o key: the image key.
1317 %
1318 */
1319 MagickExport MagickBooleanType DeleteImageAttribute(Image *image,
1320   const char *key)
1321 {
1322   return(DeleteImageProperty(image,key));
1323 }
1324 \f
1325 /*
1326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1327 %                                                                             %
1328 %                                                                             %
1329 %                                                                             %
1330 %   D e l e t e I m a g e L i s t                                             %
1331 %                                                                             %
1332 %                                                                             %
1333 %                                                                             %
1334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1335 %
1336 %  DeleteImageList() deletes an image at the specified position in the list.
1337 %
1338 %  The format of the DeleteImageList method is:
1339 %
1340 %      unsigned int DeleteImageList(Image *images,const long offset)
1341 %
1342 %  A description of each parameter follows:
1343 %
1344 %    o images: the image list.
1345 %
1346 %    o offset: the position within the list.
1347 %
1348 */
1349 MagickExport unsigned int DeleteImageList(Image *images,const long offset)
1350 {
1351   register long
1352     i;
1353
1354   if (images->debug != MagickFalse)
1355     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
1356   while (GetPreviousImageInList(images) != (Image *) NULL)
1357     images=GetPreviousImageInList(images);
1358   for (i=0; i < offset; i++)
1359   {
1360     if (GetNextImageInList(images) == (Image *) NULL)
1361       return(MagickFalse);
1362     images=GetNextImageInList(images);
1363   }
1364   DeleteImageFromList(&images);
1365   return(MagickTrue);
1366 }
1367 \f
1368 /*
1369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1370 %                                                                             %
1371 %                                                                             %
1372 %                                                                             %
1373 %   D e l e t e M a g i c k R e g i s t r y                                   %
1374 %                                                                             %
1375 %                                                                             %
1376 %                                                                             %
1377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1378 %
1379 %  DeleteMagickRegistry() deletes an entry in the registry as defined by the id.
1380 %  It returns MagickTrue if the entry is deleted otherwise MagickFalse if no
1381 %  entry is found in the registry that matches the id.
1382 %
1383 %  The format of the DeleteMagickRegistry method is:
1384 %
1385 %      MagickBooleanType DeleteMagickRegistry(const long id)
1386 %
1387 %  A description of each parameter follows:
1388 %
1389 %    o id: the registry id.
1390 %
1391 */
1392 MagickExport MagickBooleanType DeleteMagickRegistry(const long id)
1393 {
1394   char
1395     key[MaxTextExtent];
1396
1397   (void) FormatMagickString(key,MaxTextExtent,"%ld\n",id);
1398   return(DeleteImageRegistry(key));
1399 }
1400 \f
1401 /*
1402 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1403 %                                                                             %
1404 %                                                                             %
1405 %                                                                             %
1406 +   D e s t r o y M a g i c k R e g i s t r y                                 %
1407 %                                                                             %
1408 %                                                                             %
1409 %                                                                             %
1410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1411 %
1412 %  DestroyMagickRegistry() deallocates memory associated the magick registry.
1413 %
1414 %  The format of the DestroyMagickRegistry method is:
1415 %
1416 %       void DestroyMagickRegistry(void)
1417 %
1418 */
1419 MagickExport void DestroyMagickRegistry(void)
1420 {
1421   RegistryComponentTerminus();
1422 }
1423 \f
1424 /*
1425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1426 %                                                                             %
1427 %                                                                             %
1428 %                                                                             %
1429 %   D e s c r i b e I m a g e                                                 %
1430 %                                                                             %
1431 %                                                                             %
1432 %                                                                             %
1433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1434 %
1435 %  DescribeImage() describes an image by printing its attributes to the file.
1436 %  Attributes include the image width, height, size, and others.
1437 %
1438 %  The format of the DescribeImage method is:
1439 %
1440 %      MagickBooleanType DescribeImage(Image *image,FILE *file,
1441 %        const MagickBooleanType verbose)
1442 %
1443 %  A description of each parameter follows:
1444 %
1445 %    o image: the image.
1446 %
1447 %    o file: the file, typically stdout.
1448 %
1449 %    o verbose: A value other than zero prints more detailed information
1450 %      about the image.
1451 %
1452 */
1453 MagickExport MagickBooleanType DescribeImage(Image *image,FILE *file,
1454   const MagickBooleanType verbose)
1455 {
1456   return(IdentifyImage(image,file,verbose));
1457 }
1458 \f
1459 /*
1460 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1461 %                                                                             %
1462 %                                                                             %
1463 %                                                                             %
1464 %   D e s t r o y I m a g e A t t r i b u t e s                               %
1465 %                                                                             %
1466 %                                                                             %
1467 %                                                                             %
1468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1469 %
1470 %  DestroyImageAttributes() deallocates memory associated with the image
1471 %  attribute list.
1472 %
1473 %  The format of the DestroyImageAttributes method is:
1474 %
1475 %      DestroyImageAttributes(Image *image)
1476 %
1477 %  A description of each parameter follows:
1478 %
1479 %    o image: the image.
1480 %
1481 */
1482 MagickExport void DestroyImageAttributes(Image *image)
1483 {
1484   assert(image != (Image *) NULL);
1485   assert(image->signature == MagickSignature);
1486   if (image->debug != MagickFalse)
1487     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1488   if (image->attributes != (void *) NULL)
1489     image->attributes=(void *) DestroySplayTree((SplayTreeInfo *)
1490       image->attributes);
1491 }
1492 \f
1493 /*
1494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1495 %                                                                             %
1496 %                                                                             %
1497 %                                                                             %
1498 %   D e s t r o y I m a g e s                                                 %
1499 %                                                                             %
1500 %                                                                             %
1501 %                                                                             %
1502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1503 %
1504 %  DestroyImages() destroys an image list.
1505 %
1506 %  The format of the DestroyImages method is:
1507 %
1508 %      void DestroyImages(Image *image)
1509 %
1510 %  A description of each parameter follows:
1511 %
1512 %    o image: the image sequence.
1513 %
1514 */
1515 MagickExport void DestroyImages(Image *image)
1516 {
1517   if (image == (Image *) NULL)
1518     return;
1519   if (image->debug != MagickFalse)
1520     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.4.3");
1521   image=DestroyImageList(image);
1522 }
1523 \f
1524 /*
1525 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1526 %                                                                             %
1527 %                                                                             %
1528 %                                                                             %
1529 %   D e s t r o y M a g i c k                                                 %
1530 %                                                                             %
1531 %                                                                             %
1532 %                                                                             %
1533 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1534 %
1535 %  DestroyMagick() destroys the ImageMagick environment.
1536 %
1537 %  The format of the DestroyMagick function is:
1538 %
1539 %      DestroyMagick(void)
1540 %
1541 */
1542 MagickExport void DestroyMagick(void)
1543 {
1544   MagickCoreTerminus();
1545 }
1546 \f
1547 /*
1548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1549 %                                                                             %
1550 %                                                                             %
1551 %                                                                             %
1552 %   D i s p a t c h I m a g e                                                 %
1553 %                                                                             %
1554 %                                                                             %
1555 %                                                                             %
1556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1557 %
1558 %  DispatchImage() extracts pixel data from an image and returns it to you.
1559 %  The method returns MagickFalse on success otherwise MagickTrue if an error is
1560 %  encountered.  The data is returned as char, short int, int, long, float,
1561 %  or double in the order specified by map.
1562 %
1563 %  Suppose you want to extract the first scanline of a 640x480 image as
1564 %  character data in red-green-blue order:
1565 %
1566 %      DispatchImage(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
1567 %
1568 %  The format of the DispatchImage method is:
1569 %
1570 %      unsigned int DispatchImage(const Image *image,const long x_offset,
1571 %        const long y_offset,const unsigned long columns,
1572 %        const unsigned long rows,const char *map,const StorageType type,
1573 %        void *pixels,ExceptionInfo *exception)
1574 %
1575 %  A description of each parameter follows:
1576 %
1577 %    o image: the image.
1578 %
1579 %    o x_offset, y_offset, columns, rows:  These values define the perimeter
1580 %      of a region of pixels you want to extract.
1581 %
1582 %    o map:  This string reflects the expected ordering of the pixel array.
1583 %      It can be any combination or order of R = red, G = green, B = blue,
1584 %      A = alpha, C = cyan, Y = yellow, M = magenta, K = black, or
1585 %      I = intensity (for grayscale).
1586 %
1587 %    o type: Define the data type of the pixels.  Float and double types are
1588 %      normalized to [0..1] otherwise [0..QuantumRange].  Choose from these
1589 %      types: CharPixel, ShortPixel, IntegerPixel, LongPixel, FloatPixel, or
1590 %      DoublePixel.
1591 %
1592 %    o pixels: This array of values contain the pixel components as defined by
1593 %      map and type.  You must preallocate this array where the expected
1594 %      length varies depending on the values of width, height, map, and type.
1595 %
1596 %    o exception: return any errors or warnings in this structure.
1597 %
1598 */
1599 MagickExport unsigned int DispatchImage(const Image *image,const long x_offset,
1600   const long y_offset,const unsigned long columns,const unsigned long rows,
1601   const char *map,const StorageType type,void *pixels,ExceptionInfo *exception)
1602 {
1603   unsigned int
1604     status;
1605
1606   if (image->debug != MagickFalse)
1607     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.6");
1608   status=ExportImagePixels(image,x_offset,y_offset,columns,rows,map,type,pixels,
1609     exception);
1610   return(status);
1611 }
1612 \f
1613 /*
1614 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1615 %                                                                             %
1616 %                                                                             %
1617 %                                                                             %
1618 %   E x t r a c t S u b i m a g e F r o m I m a g e                           %
1619 %                                                                             %
1620 %                                                                             %
1621 %                                                                             %
1622 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1623 %
1624 %  ExtractSubimageFromImageImage() extracts a region of the image that most
1625 %  closely resembles the reference.
1626 %
1627 %  The format of the ExtractSubimageFromImageImage method is:
1628 %
1629 %      Image *ExtractSubimageFromImage(const Image *image,const Image *reference,
1630 %        ExceptionInfo *exception)
1631 %
1632 %  A description of each parameter follows:
1633 %
1634 %    o image: the image.
1635 %
1636 %    o reference: find an area of the image that closely resembles this image.
1637 %
1638 %    o exception: return any errors or warnings in this structure.
1639 %
1640 */
1641
1642 static double GetSimilarityMetric(const Image *image,const Image *reference,
1643   const long x_offset,const long y_offset,const double similarity_threshold,
1644   ExceptionInfo *exception)
1645 {
1646   CacheView
1647     *image_view,
1648     *reference_view;
1649
1650   long
1651     y;
1652
1653   double
1654     channels,
1655     normalized_similarity,
1656     similarity;
1657
1658   /*
1659     Compute the similarity in pixels between two images.
1660   */
1661   normalized_similarity=1.0;
1662   similarity=0.0;
1663   channels=3;
1664   if ((image->matte != MagickFalse) && (reference->matte != MagickFalse))
1665     channels++;
1666   if ((image->colorspace == CMYKColorspace) &&
1667       (reference->colorspace == CMYKColorspace))
1668     channels++;
1669   image_view=AcquireCacheView(image);
1670   reference_view=AcquireCacheView(reference);
1671   for (y=0; y < (long) reference->rows; y++)
1672   {
1673     register const IndexPacket
1674       *indexes,
1675       *reference_indexes;
1676
1677     register const PixelPacket
1678       *p,
1679       *q;
1680
1681     register long
1682       x;
1683
1684     p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset+y,
1685       reference->columns,1,exception);
1686     q=GetCacheViewVirtualPixels(reference_view,0,y,reference->columns,1,
1687       exception);
1688     if ((p == (const PixelPacket *) NULL) || (q == (const PixelPacket *) NULL))
1689       continue;
1690     indexes=GetCacheViewVirtualIndexQueue(image_view);
1691     reference_indexes=GetCacheViewVirtualIndexQueue(reference_view);
1692     for (x=0; x < (long) reference->columns; x++)
1693     {
1694       MagickRealType
1695         pixel;
1696
1697       pixel=QuantumScale*(p->red-(double) q->red);
1698       similarity+=pixel*pixel;
1699       pixel=QuantumScale*(p->green-(double) q->green);
1700       similarity+=pixel*pixel;
1701       pixel=QuantumScale*(p->blue-(double) q->blue);
1702       similarity+=pixel*pixel;
1703       if ((image->matte != MagickFalse) && (reference->matte != MagickFalse))
1704         {
1705           pixel=QuantumScale*(p->opacity-(double) q->opacity);
1706           similarity+=pixel*pixel;
1707         }
1708       if ((image->colorspace == CMYKColorspace) &&
1709           (reference->colorspace == CMYKColorspace))
1710         {
1711           pixel=QuantumScale*(indexes[x]-(double) reference_indexes[x]);
1712           similarity+=pixel*pixel;
1713         }
1714       p++;
1715       q++;
1716     }
1717     normalized_similarity=sqrt(similarity)/reference->columns/reference->rows/
1718       channels;
1719     if (normalized_similarity > similarity_threshold)
1720       break;
1721   }
1722   reference_view=DestroyCacheView(reference_view);
1723   image_view=DestroyCacheView(image_view);
1724   return(normalized_similarity);
1725 }
1726
1727 MagickExport Image *ExtractSubimageFromImage(Image *image,
1728   const Image *reference,ExceptionInfo *exception)
1729 {
1730   long
1731     y;
1732
1733   double
1734     similarity_threshold;
1735
1736   RectangleInfo
1737     offset;
1738
1739   /*
1740     Extract reference from image.
1741   */
1742   if ((reference->columns > image->columns) || (reference->rows > image->rows))
1743     return((Image *) NULL);
1744   similarity_threshold=(double) image->columns*image->rows;
1745   SetGeometry(reference,&offset);
1746 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1747   #pragma omp parallel for schedule(dynamic,4)
1748 #endif
1749   for (y=0; y < (long) (image->rows-reference->rows); y++)
1750   {
1751     double
1752       similarity;
1753
1754     register long
1755       x;
1756
1757     for (x=0; x < (long) (image->columns-reference->columns); x++)
1758     {
1759       similarity=GetSimilarityMetric(image,reference,x,y,similarity_threshold,
1760         exception);
1761 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1762   #pragma omp critical (MagickCore_ExtractSubimageFromImage)
1763 #endif
1764       if (similarity < similarity_threshold)
1765         {
1766           similarity_threshold=similarity;
1767           offset.x=x;
1768           offset.y=y;
1769         }
1770     }
1771   }
1772   if (similarity_threshold > (QuantumScale*reference->fuzz/100.0))
1773     return((Image *) NULL);
1774   return(CropImage(image,&offset,exception));
1775 }
1776 \f
1777 /*
1778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1779 %                                                                             %
1780 %                                                                             %
1781 %                                                                             %
1782 %     F l a t t e n I m a g e                                                 %
1783 %                                                                             %
1784 %                                                                             %
1785 %                                                                             %
1786 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1787 %
1788 %  FlattenImages() Obsolete Function: Use MergeImageLayers() instead.
1789 %
1790 %  The format of the FlattenImage method is:
1791 %
1792 %      Image *FlattenImage(Image *image,ExceptionInfo *exception)
1793 %
1794 %  A description of each parameter follows:
1795 %
1796 %    o image: the image sequence.
1797 %
1798 %    o exception: return any errors or warnings in this structure.
1799 %
1800 */
1801 MagickExport Image *FlattenImages(Image *image,ExceptionInfo *exception)
1802 {
1803   return(MergeImageLayers(image,FlattenLayer,exception));
1804 }
1805 \f
1806 /*
1807 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1808 %                                                                             %
1809 %                                                                             %
1810 %                                                                             %
1811 %  F o r m a t I m a g e A t t r i b u t e                                    %
1812 %                                                                             %
1813 %                                                                             %
1814 %                                                                             %
1815 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1816 %
1817 %  FormatImageAttribute() permits formatted key/value pairs to be saved as an
1818 %  image attribute.
1819 %
1820 %  The format of the FormatImageAttribute method is:
1821 %
1822 %      MagickBooleanType FormatImageAttribute(Image *image,const char *key,
1823 %        const char *format,...)
1824 %
1825 %  A description of each parameter follows.
1826 %
1827 %   o  image:  The image.
1828 %
1829 %   o  key:  The attribute key.
1830 %
1831 %   o  format:  A string describing the format to use to write the remaining
1832 %      arguments.
1833 %
1834 */
1835
1836 MagickExport MagickBooleanType FormatImageAttributeList(Image *image,
1837   const char *key,const char *format,va_list operands)
1838 {
1839   char
1840     value[MaxTextExtent];
1841
1842   int
1843     n;
1844
1845 #if defined(MAGICKCORE_HAVE_VSNPRINTF)
1846   n=vsnprintf(value,MaxTextExtent,format,operands);
1847 #else
1848   n=vsprintf(value,format,operands);
1849 #endif
1850   if (n < 0)
1851     value[MaxTextExtent-1]='\0';
1852   return(SetImageProperty(image,key,value));
1853 }
1854
1855 MagickExport MagickBooleanType FormatImageAttribute(Image *image,
1856   const char *key,const char *format,...)
1857 {
1858   MagickBooleanType
1859     status;
1860
1861   va_list
1862     operands;
1863
1864   va_start(operands,format);
1865   status=FormatImagePropertyList(image,key,format,operands);
1866   va_end(operands);
1867   return(status);
1868 }
1869 \f
1870 /*
1871 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1872 %                                                                             %
1873 %                                                                             %
1874 %                                                                             %
1875 %  F o r m a t S t r i n g                                                    %
1876 %                                                                             %
1877 %                                                                             %
1878 %                                                                             %
1879 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1880 %
1881 %  FormatString() prints formatted output of a variable argument list.
1882 %
1883 %  The format of the FormatString method is:
1884 %
1885 %      void FormatString(char *string,const char *format,...)
1886 %
1887 %  A description of each parameter follows.
1888 %
1889 %   o  string:  Method FormatString returns the formatted string in this
1890 %      character buffer.
1891 %
1892 %   o  format:  A string describing the format to use to write the remaining
1893 %      arguments.
1894 %
1895 */
1896
1897 MagickExport void FormatStringList(char *string,const char *format,
1898   va_list operands)
1899 {
1900   int
1901     n;
1902
1903  (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
1904 #if defined(MAGICKCORE_HAVE_VSNPRINTF)
1905   n=vsnprintf(string,MaxTextExtent,format,operands);
1906 #else
1907   n=vsprintf(string,format,operands);
1908 #endif
1909   if (n < 0)
1910     string[MaxTextExtent-1]='\0';
1911 }
1912
1913 MagickExport void FormatString(char *string,const char *format,...)
1914 {
1915   va_list
1916     operands;
1917
1918   va_start(operands,format);
1919   (void) FormatMagickStringList(string,MaxTextExtent,format,operands);
1920   va_end(operands);
1921   return;
1922 }
1923 \f
1924 /*
1925 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1926 %                                                                             %
1927 %                                                                             %
1928 %                                                                             %
1929 +   F u z z y C o l o r M a t c h                                             %
1930 %                                                                             %
1931 %                                                                             %
1932 %                                                                             %
1933 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1934 %
1935 %  FuzzyColorMatch() returns true if two pixels are identical in color.
1936 %
1937 %  The format of the ColorMatch method is:
1938 %
1939 %      void FuzzyColorMatch(const PixelPacket *p,const PixelPacket *q,
1940 %        const double fuzz)
1941 %
1942 %  A description of each parameter follows:
1943 %
1944 %    o p: Pixel p.
1945 %
1946 %    o q: Pixel q.
1947 %
1948 %    o distance:  Define how much tolerance is acceptable to consider
1949 %      two colors as the same.
1950 %
1951 */
1952 MagickExport unsigned int FuzzyColorMatch(const PixelPacket *p,
1953   const PixelPacket *q,const double fuzz)
1954 {
1955   MagickPixelPacket
1956     pixel;
1957
1958   register MagickRealType
1959     distance;
1960
1961   if ((fuzz == 0.0) && (p->red == q->red) && (p->green == q->green) &&
1962       (p->blue == q->blue))
1963     return(MagickTrue);
1964   pixel.red=p->red-(MagickRealType) q->red;
1965   distance=pixel.red*pixel.red;
1966   if (distance > (fuzz*fuzz))
1967     return(MagickFalse);
1968   pixel.green=p->green-(MagickRealType) q->green;
1969   distance+=pixel.green*pixel.green;
1970   if (distance > (fuzz*fuzz))
1971     return(MagickFalse);
1972   pixel.blue=p->blue-(MagickRealType) q->blue;
1973   distance+=pixel.blue*pixel.blue;
1974   if (distance > (fuzz*fuzz))
1975     return(MagickFalse);
1976   return(MagickTrue);
1977 }
1978 \f
1979 /*
1980 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1981 %                                                                             %
1982 %                                                                             %
1983 %                                                                             %
1984 +   F u z z y C o l o r C o m p a r e                                         %
1985 %                                                                             %
1986 %                                                                             %
1987 %                                                                             %
1988 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1989 %
1990 %  FuzzyColorCompare() returns MagickTrue if the distance between two colors is
1991 %  less than the specified distance in a linear three dimensional color space.
1992 %  This method is used by ColorFloodFill() and other algorithms which
1993 %  compare two colors.
1994 %
1995 %  The format of the FuzzyColorCompare method is:
1996 %
1997 %      void FuzzyColorCompare(const Image *image,const PixelPacket *p,
1998 %        const PixelPacket *q)
1999 %
2000 %  A description of each parameter follows:
2001 %
2002 %    o image: the image.
2003 %
2004 %    o p: Pixel p.
2005 %
2006 %    o q: Pixel q.
2007 %
2008 */
2009 MagickExport MagickBooleanType FuzzyColorCompare(const Image *image,
2010   const PixelPacket *p,const PixelPacket *q)
2011 {
2012   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.5");
2013   return(IsColorSimilar(image,p,q));
2014 }
2015 \f
2016 /*
2017 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2018 %                                                                             %
2019 %                                                                             %
2020 %                                                                             %
2021 +   F u z z y O p a c i t y C o m p a r e                                     %
2022 %                                                                             %
2023 %                                                                             %
2024 %                                                                             %
2025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2026 %
2027 %  FuzzyOpacityCompare() returns true if the distance between two opacity
2028 %  values is less than the specified distance in a linear color space.  This
2029 %  method is used by MatteFloodFill() and other algorithms which compare
2030 %  two opacity values.
2031 %
2032 %  The format of the FuzzyOpacityCompare method is:
2033 %
2034 %      void FuzzyOpacityCompare(const Image *image,const PixelPacket *p,
2035 %        const PixelPacket *q)
2036 %
2037 %  A description of each parameter follows:
2038 %
2039 %    o image: the image.
2040 %
2041 %    o p: Pixel p.
2042 %
2043 %    o q: Pixel q.
2044 %
2045 */
2046 MagickExport MagickBooleanType FuzzyOpacityCompare(const Image *image,
2047   const PixelPacket *p,const PixelPacket *q)
2048 {
2049   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.5");
2050   return(IsOpacitySimilar(image,p,q));
2051 }
2052 \f
2053 /*
2054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2055 %                                                                             %
2056 %                                                                             %
2057 %                                                                             %
2058 %  G e t C o n f i g u r e B l o b                                            %
2059 %                                                                             %
2060 %                                                                             %
2061 %                                                                             %
2062 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2063 %
2064 %  GetConfigureBlob() returns the specified configure file as a blob.
2065 %
2066 %  The format of the GetConfigureBlob method is:
2067 %
2068 %      void *GetConfigureBlob(const char *filename,ExceptionInfo *exception)
2069 %
2070 %  A description of each parameter follows:
2071 %
2072 %    o filename: the configure file name.
2073 %
2074 %    o path: return the full path information of the configure file.
2075 %
2076 %    o length: This pointer to a size_t integer sets the initial length of the
2077 %      blob.  On return, it reflects the actual length of the blob.
2078 %
2079 %    o exception: return any errors or warnings in this structure.
2080 %
2081 */
2082 MagickExport void *GetConfigureBlob(const char *filename,char *path,
2083   size_t *length,ExceptionInfo *exception)
2084 {
2085   void
2086     *blob;
2087
2088   assert(filename != (const char *) NULL);
2089   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
2090   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
2091   assert(path != (char *) NULL);
2092   assert(length != (size_t *) NULL);
2093   assert(exception != (ExceptionInfo *) NULL);
2094   blob=(void *) NULL;
2095   (void) CopyMagickString(path,filename,MaxTextExtent);
2096 #if defined(MAGICKCORE_INSTALLED_SUPPORT)
2097 #if defined(MAGICKCORE_LIBRARY_PATH)
2098   if (blob == (void *) NULL)
2099     {
2100       /*
2101         Search hard coded paths.
2102       */
2103       (void) FormatMagickString(path,MaxTextExtent,"%s%s",
2104         MAGICKCORE_LIBRARY_PATH,filename);
2105       if (IsPathAccessible(path) != MagickFalse)
2106         blob=FileToBlob(path,~0,length,exception);
2107     }
2108 #endif
2109 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !(defined(MAGICKCORE_CONFIGURE_PATH) || defined(MAGICKCORE_SHARE_CONFIGURE_PATH))
2110   if (blob == (void *) NULL)
2111     {
2112       char
2113         *key_value;
2114
2115       /*
2116         Locate file via registry key.
2117       */
2118       key_value=NTRegistryKeyLookup("ConfigurePath");
2119       if (key_value != (char *) NULL)
2120         {
2121           (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",key_value,
2122             DirectorySeparator,filename);
2123           if (IsPathAccessible(path) != MagickFalse)
2124             blob=FileToBlob(path,~0,length,exception);
2125         }
2126     }
2127 #endif
2128 #else
2129   if (blob == (void *) NULL)
2130     {
2131       char
2132         *home;
2133
2134       home=GetEnvironmentValue("MAGICK_HOME");
2135       if (home != (char *) NULL)
2136         {
2137           /*
2138             Search MAGICK_HOME.
2139           */
2140 #if !defined(MAGICKCORE_POSIX_SUPPORT)
2141           (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",home,
2142             DirectorySeparator,filename);
2143 #else
2144           (void) FormatMagickString(path,MaxTextExtent,"%s/lib/%s/%s",home,
2145             MAGICKCORE_LIBRARY_RELATIVE_PATH,filename);
2146 #endif
2147           if (IsPathAccessible(path) != MagickFalse)
2148             blob=FileToBlob(path,~0,length,exception);
2149           home=DestroyString(home);
2150         }
2151       home=GetEnvironmentValue("HOME");
2152       if (home == (char *) NULL)
2153         home=GetEnvironmentValue("USERPROFILE");
2154       if (home != (char *) NULL)
2155         {
2156           /*
2157             Search $HOME/.magick.
2158           */
2159           (void) FormatMagickString(path,MaxTextExtent,"%s%s.magick%s%s",home,
2160             DirectorySeparator,DirectorySeparator,filename);
2161           if ((IsPathAccessible(path) != MagickFalse) && (blob == (void *) NULL))
2162             blob=FileToBlob(path,~0,length,exception);
2163           home=DestroyString(home);
2164         }
2165     }
2166   if ((blob == (void *) NULL) && (*GetClientPath() != '\0'))
2167     {
2168 #if !defined(MAGICKCORE_POSIX_SUPPORT)
2169       (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",GetClientPath(),
2170         DirectorySeparator,filename);
2171 #else
2172       char
2173         prefix[MaxTextExtent];
2174
2175       /*
2176         Search based on executable directory if directory is known.
2177       */
2178       (void) CopyMagickString(prefix,GetClientPath(),
2179         MaxTextExtent);
2180       ChopPathComponents(prefix,1);
2181       (void) FormatMagickString(path,MaxTextExtent,"%s/lib/%s/%s",prefix,
2182         MAGICKCORE_LIBRARY_RELATIVE_PATH,filename);
2183 #endif
2184       if (IsPathAccessible(path) != MagickFalse)
2185         blob=FileToBlob(path,~0,length,exception);
2186     }
2187   /*
2188     Search current directory.
2189   */
2190   if ((blob == (void *) NULL) && (IsPathAccessible(path) != MagickFalse))
2191     blob=FileToBlob(path,~0,length,exception);
2192 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
2193   /*
2194     Search Windows registry.
2195   */
2196   if (blob == (void *) NULL)
2197     blob=NTResourceToBlob(filename);
2198 #endif
2199 #endif
2200   if (blob == (void *) NULL)
2201     (void) ThrowMagickException(exception,GetMagickModule(),ConfigureWarning,
2202       "UnableToOpenConfigureFile","`%s'",path);
2203   return(blob);
2204 }
2205 \f
2206 /*
2207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2208 %                                                                             %
2209 %                                                                             %
2210 %                                                                             %
2211 %   G e t C a c h e V i e w                                                   %
2212 %                                                                             %
2213 %                                                                             %
2214 %                                                                             %
2215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2216 %
2217 %  GetCacheView() gets pixels from the in-memory or disk pixel cache as
2218 %  defined by the geometry parameters.   A pointer to the pixels is returned if
2219 %  the pixels are transferred, otherwise a NULL is returned.
2220 %
2221 %  The format of the GetCacheView method is:
2222 %
2223 %      PixelPacket *GetCacheView(CacheView *cache_view,const long x,
2224 %        const long y,const unsigned long columns,const unsigned long rows)
2225 %
2226 %  A description of each parameter follows:
2227 %
2228 %    o cache_view: the address of a structure of type CacheView.
2229 %
2230 %    o x,y,columns,rows:  These values define the perimeter of a region of
2231 %      pixels.
2232 %
2233 */
2234 MagickExport PixelPacket *GetCacheView(CacheView *cache_view,const long x,
2235   const long y,const unsigned long columns,const unsigned long rows)
2236 {
2237   PixelPacket
2238     *pixels;
2239
2240   pixels=GetCacheViewAuthenticPixels(cache_view,x,y,columns,rows,
2241     GetCacheViewException(cache_view));
2242   return(pixels);
2243 }
2244 \f
2245 /*
2246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2247 %                                                                             %
2248 %                                                                             %
2249 %                                                                             %
2250 %   G e t C a c h e V i e w I n d e x e s                                     %
2251 %                                                                             %
2252 %                                                                             %
2253 %                                                                             %
2254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2255 %
2256 %  GetCacheViewIndexes() returns the indexes associated with the specified
2257 %  view.
2258 %
2259 %  The format of the GetCacheViewIndexes method is:
2260 %
2261 %      IndexPacket *GetCacheViewIndexes(CacheView *cache_view)
2262 %
2263 %  A description of each parameter follows:
2264 %
2265 %    o cache_view: the cache view.
2266 %
2267 */
2268 MagickExport IndexPacket *GetCacheViewIndexes(CacheView *cache_view)
2269 {
2270   return(GetCacheViewAuthenticIndexQueue(cache_view));
2271 }
2272 \f
2273 /*
2274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2275 %                                                                             %
2276 %                                                                             %
2277 %                                                                             %
2278 %   G e t C a c h e V i e w P i x e l s                                       %
2279 %                                                                             %
2280 %                                                                             %
2281 %                                                                             %
2282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2283 %
2284 %  GetCacheViewPixels() gets pixels from the in-memory or disk pixel cache as
2285 %  defined by the geometry parameters.   A pointer to the pixels is returned if
2286 %  the pixels are transferred, otherwise a NULL is returned.
2287 %
2288 %  The format of the GetCacheViewPixels method is:
2289 %
2290 %      PixelPacket *GetCacheViewPixels(CacheView *cache_view,const long x,
2291 %        const long y,const unsigned long columns,const unsigned long rows)
2292 %
2293 %  A description of each parameter follows:
2294 %
2295 %    o cache_view: the cache view.
2296 %
2297 %    o x,y,columns,rows:  These values define the perimeter of a region of
2298 %      pixels.
2299 %
2300 */
2301 MagickExport PixelPacket *GetCacheViewPixels(CacheView *cache_view,const long x,
2302   const long y,const unsigned long columns,const unsigned long rows)
2303 {
2304   PixelPacket
2305     *pixels;
2306
2307   pixels=GetCacheViewAuthenticPixels(cache_view,x,y,columns,rows,
2308     GetCacheViewException(cache_view));
2309   return(pixels);
2310 }
2311 \f
2312 /*
2313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2314 %                                                                             %
2315 %                                                                             %
2316 %                                                                             %
2317 %   G e t I m a g e A t t r i b u t e                                         %
2318 %                                                                             %
2319 %                                                                             %
2320 %                                                                             %
2321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2322 %
2323 %  GetImageAttribute() searches the list of image attributes and returns
2324 %  a pointer to the attribute if it exists otherwise NULL.
2325 %
2326 %  The format of the GetImageAttribute method is:
2327 %
2328 %      const ImageAttribute *GetImageAttribute(const Image *image,
2329 %        const char *key)
2330 %
2331 %  A description of each parameter follows:
2332 %
2333 %    o image: the image.
2334 %
2335 %    o key:  These character strings are the name of an image attribute to
2336 %      return.
2337 %
2338 */
2339
2340 static void *DestroyAttribute(void *attribute)
2341 {
2342   register ImageAttribute
2343     *p;
2344
2345   p=(ImageAttribute *) attribute;
2346   if (p->value != (char *) NULL)
2347     p->value=DestroyString(p->value);
2348   return(RelinquishMagickMemory(p));
2349 }
2350
2351 MagickExport const ImageAttribute *GetImageAttribute(const Image *image,
2352   const char *key)
2353 {
2354   const char
2355     *value;
2356
2357   ImageAttribute
2358     *attribute;
2359
2360   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.3.1");
2361   value=GetImageProperty(image,key);
2362   if (value == (const char *) NULL)
2363     return((const ImageAttribute *) NULL);
2364   if (image->attributes == (void *) NULL)
2365     ((Image *) image)->attributes=NewSplayTree(CompareSplayTreeString,
2366       RelinquishMagickMemory,DestroyAttribute);
2367   else
2368     {
2369       const ImageAttribute
2370         *attribute;
2371
2372       attribute=(const ImageAttribute *) GetValueFromSplayTree((SplayTreeInfo *)
2373         image->attributes,key);
2374       if (attribute != (const ImageAttribute *) NULL)
2375         return(attribute);
2376     }
2377   attribute=(ImageAttribute *) AcquireAlignedMemory(1,sizeof(*attribute));
2378   if (attribute == (ImageAttribute *) NULL)
2379     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
2380   (void) ResetMagickMemory(attribute,0,sizeof(*attribute));
2381   attribute->key=ConstantString(key);
2382   attribute->value=ConstantString(value);
2383   (void) AddValueToSplayTree((SplayTreeInfo *) ((Image *) image)->attributes,
2384     attribute->key,attribute);
2385   return((const ImageAttribute *) attribute);
2386 }
2387 \f
2388 /*
2389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2390 %                                                                             %
2391 %                                                                             %
2392 %                                                                             %
2393 %   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                 %
2394 %                                                                             %
2395 %                                                                             %
2396 %                                                                             %
2397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2398 %
2399 %  GetImageClippingPathAttribute() searches the list of image attributes and
2400 %  returns a pointer to a clipping path if it exists otherwise NULL.
2401 %
2402 %  The format of the GetImageClippingPathAttribute method is:
2403 %
2404 %      const ImageAttribute *GetImageClippingPathAttribute(Image *image)
2405 %
2406 %  A description of each parameter follows:
2407 %
2408 %    o attribute:  Method GetImageClippingPathAttribute returns the clipping
2409 %      path if it exists otherwise NULL.
2410 %
2411 %    o image: the image.
2412 %
2413 */
2414 MagickExport const ImageAttribute *GetImageClippingPathAttribute(Image *image)
2415 {
2416   return(GetImageAttribute(image,"8BIM:1999,2998"));
2417 }
2418 \f
2419 /*
2420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2421 %                                                                             %
2422 %                                                                             %
2423 %                                                                             %
2424 %   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                       %
2425 %                                                                             %
2426 %                                                                             %
2427 %                                                                             %
2428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2429 %
2430 %  GetImageFromMagickRegistry() gets an image from the registry as defined by
2431 %  its name.  If the image is not found, a NULL image is returned.
2432 %
2433 %  The format of the GetImageFromMagickRegistry method is:
2434 %
2435 %      Image *GetImageFromMagickRegistry(const char *name,long *id,
2436 %        ExceptionInfo *exception)
2437 %
2438 %  A description of each parameter follows:
2439 %
2440 %    o name: the name of the image to retrieve from the registry.
2441 %
2442 %    o id: the registry id.
2443 %
2444 %    o exception: return any errors or warnings in this structure.
2445 %
2446 */
2447 MagickExport Image *GetImageFromMagickRegistry(const char *name,long *id,
2448   ExceptionInfo *exception)
2449 {
2450   *id=0L;
2451   return((Image *) GetImageRegistry(ImageRegistryType,name,exception));
2452 }
2453 \f
2454 /*
2455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2456 %                                                                             %
2457 %                                                                             %
2458 %                                                                             %
2459 %   G e t M a g i c k R e g i s t r y                                         %
2460 %                                                                             %
2461 %                                                                             %
2462 %                                                                             %
2463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2464 %
2465 %  GetMagickRegistry() gets a blob from the registry as defined by the id.  If
2466 %  the blob that matches the id is not found, NULL is returned.
2467 %
2468 %  The format of the GetMagickRegistry method is:
2469 %
2470 %      const void *GetMagickRegistry(const long id,RegistryType *type,
2471 %        size_t *length,ExceptionInfo *exception)
2472 %
2473 %  A description of each parameter follows:
2474 %
2475 %    o id: the registry id.
2476 %
2477 %    o type: the registry type.
2478 %
2479 %    o length: the blob length in number of bytes.
2480 %
2481 %    o exception: return any errors or warnings in this structure.
2482 %
2483 */
2484 MagickExport void *GetMagickRegistry(const long id,RegistryType *type,
2485   size_t *length,ExceptionInfo *exception)
2486 {
2487   char
2488     key[MaxTextExtent];
2489
2490   void
2491     *blob;
2492
2493   *type=UndefinedRegistryType;
2494   *length=0;
2495   (void) FormatMagickString(key,MaxTextExtent,"%ld\n",id);
2496   blob=(void *) GetImageRegistry(ImageRegistryType,key,exception);
2497   if (blob != (void *) NULL)
2498     return(blob);
2499   blob=(void *) GetImageRegistry(ImageInfoRegistryType,key,exception);
2500   if (blob != (void *) NULL)
2501     return(blob);
2502   return((void *) GetImageRegistry(UndefinedRegistryType,key,exception));
2503 }
2504 \f
2505 /*
2506 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2507 %                                                                             %
2508 %                                                                             %
2509 %                                                                             %
2510 %   G e t I m a g e G e o m e t r y                                           %
2511 %                                                                             %
2512 %                                                                             %
2513 %                                                                             %
2514 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2515 %
2516 %  GetImageGeometry() returns a region as defined by the geometry string with
2517 %  respect to the image and its gravity.
2518 %
2519 %  The format of the GetImageGeometry method is:
2520 %
2521 %      int GetImageGeometry(Image *image,const char *geometry,
2522 %        const unsigned int size_to_fit,RectangeInfo *region_info)
2523 %
2524 %  A description of each parameter follows:
2525 %
2526 %    o flags:  Method GetImageGeometry returns a bitmask that indicates
2527 %      which of the four values were located in the geometry string.
2528 %
2529 %    o geometry:  The geometry (e.g. 100x100+10+10).
2530 %
2531 %    o size_to_fit:  A value other than 0 means to scale the region so it
2532 %      fits within the specified width and height.
2533 %
2534 %    o region_info: the region as defined by the geometry string with
2535 %      respect to the image and its gravity.
2536 %
2537 */
2538 MagickExport int GetImageGeometry(Image *image,const char *geometry,
2539   const unsigned int size_to_fit,RectangleInfo *region_info)
2540 {
2541   if (image->debug != MagickFalse)
2542     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.4");
2543   if (size_to_fit != MagickFalse)
2544     return((int) ParseRegionGeometry(image,geometry,region_info,&image->exception));
2545   return((int) ParsePageGeometry(image,geometry,region_info,&image->exception));
2546 }
2547 \f
2548 /*
2549 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2550 %                                                                             %
2551 %                                                                             %
2552 %                                                                             %
2553 %   G e t I m a g e L i s t                                                   %
2554 %                                                                             %
2555 %                                                                             %
2556 %                                                                             %
2557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2558 %
2559 %  GetImageList() returns an image at the specified position in the list.
2560 %
2561 %  The format of the GetImageList method is:
2562 %
2563 %      Image *GetImageList(const Image *images,const long offset,
2564 %        ExceptionInfo *exception)
2565 %
2566 %  A description of each parameter follows:
2567 %
2568 %    o images: the image list.
2569 %
2570 %    o offset: the position within the list.
2571 %
2572 %    o exception: return any errors or warnings in this structure.
2573 %
2574 */
2575 MagickExport Image *GetImageList(const Image *images,const long offset,
2576   ExceptionInfo *exception)
2577 {
2578   Image
2579     *image;
2580
2581   if (images->debug != MagickFalse)
2582     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
2583   image=CloneImage(GetImageFromList(images,(long) offset),0,0,MagickTrue,
2584     exception);
2585   return(image);
2586 }
2587 \f
2588 /*
2589 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2590 %                                                                             %
2591 %                                                                             %
2592 %                                                                             %
2593 %   G e t I m a g e L i s t I n d e x                                         %
2594 %                                                                             %
2595 %                                                                             %
2596 %                                                                             %
2597 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2598 %
2599 %  GetImageListIndex() returns the position in the list of the specified
2600 %  image.
2601 %
2602 %  The format of the GetImageListIndex method is:
2603 %
2604 %      long GetImageListIndex(const Image *images)
2605 %
2606 %  A description of each parameter follows:
2607 %
2608 %    o images: the image list.
2609 %
2610 */
2611 MagickExport long GetImageListIndex(const Image *images)
2612 {
2613   if (images->debug != MagickFalse)
2614     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
2615   return(GetImageIndexInList(images));
2616 }
2617 \f
2618 /*
2619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2620 %                                                                             %
2621 %                                                                             %
2622 %                                                                             %
2623 %   G e t I m a g e L i s t S i z e                                           %
2624 %                                                                             %
2625 %                                                                             %
2626 %                                                                             %
2627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2628 %
2629 %  GetImageListSize() returns the number of images in the list.
2630 %
2631 %  The format of the GetImageListSize method is:
2632 %
2633 %      unsigned long GetImageListSize(const Image *images)
2634 %
2635 %  A description of each parameter follows:
2636 %
2637 %    o images: the image list.
2638 %
2639 */
2640 MagickExport unsigned long GetImageListSize(const Image *images)
2641 {
2642   if (images->debug != MagickFalse)
2643     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
2644   return(GetImageListLength(images));
2645 }
2646 \f
2647 /*
2648 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2649 %                                                                             %
2650 %                                                                             %
2651 %                                                                             %
2652 %   G e t I m a g e P i x e l s                                               %
2653 %                                                                             %
2654 %                                                                             %
2655 %                                                                             %
2656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2657 %
2658 %  GetImagePixels() obtains a pixel region for read/write access. If the
2659 %  region is successfully accessed, a pointer to a PixelPacket array
2660 %  representing the region is returned, otherwise NULL is returned.
2661 %
2662 %  The returned pointer may point to a temporary working copy of the pixels
2663 %  or it may point to the original pixels in memory. Performance is maximized
2664 %  if the selected region is part of one row, or one or more full rows, since
2665 %  then there is opportunity to access the pixels in-place (without a copy)
2666 %  if the image is in RAM, or in a memory-mapped file. The returned pointer
2667 %  should *never* be deallocated by the user.
2668 %
2669 %  Pixels accessed via the returned pointer represent a simple array of type
2670 %  PixelPacket. If the image type is CMYK or if the storage class is
2671 %  PseduoClass, call GetAuthenticIndexQueue() after invoking GetImagePixels()
2672 %  to obtain the black color component or colormap indexes (of type IndexPacket)
2673 %  corresponding to the region.  Once the PixelPacket (and/or IndexPacket)
2674 %  array has been updated, the changes must be saved back to the underlying
2675 %  image using SyncAuthenticPixels() or they may be lost.
2676 %
2677 %  The format of the GetImagePixels() method is:
2678 %
2679 %      PixelPacket *GetImagePixels(Image *image,const long x,const long y,
2680 %        const unsigned long columns,const unsigned long rows)
2681 %
2682 %  A description of each parameter follows:
2683 %
2684 %    o image: the image.
2685 %
2686 %    o x,y,columns,rows:  These values define the perimeter of a region of
2687 %      pixels.
2688 %
2689 */
2690 MagickExport PixelPacket *GetImagePixels(Image *image,const long x,const long y,
2691   const unsigned long columns,const unsigned long rows)
2692 {
2693   return(GetAuthenticPixels(image,x,y,columns,rows,&image->exception));
2694 }
2695 \f
2696 /*
2697 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2698 %                                                                             %
2699 %                                                                             %
2700 %                                                                             %
2701 %   G e t I n d e x e s                                                       %
2702 %                                                                             %
2703 %                                                                             %
2704 %                                                                             %
2705 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2706 %
2707 %  GetIndexes() returns the black channel or the colormap indexes associated
2708 %  with the last call to QueueAuthenticPixels() or GetVirtualPixels().  NULL is
2709 %  returned if the black channel or colormap indexes are not available.
2710 %
2711 %  The format of the GetIndexes() method is:
2712 %
2713 %      IndexPacket *GetIndexes(const Image *image)
2714 %
2715 %  A description of each parameter follows:
2716 %
2717 %    o indexes: GetIndexes() returns the indexes associated with the last
2718 %      call to QueueAuthenticPixels() or GetAuthenticPixels().
2719 %
2720 %    o image: the image.
2721 %
2722 */
2723 MagickExport IndexPacket *GetIndexes(const Image *image)
2724 {
2725   return(GetAuthenticIndexQueue(image));
2726 }
2727 \f
2728 /*
2729 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2730 %                                                                             %
2731 %                                                                             %
2732 %                                                                             %
2733 +   G e t M a g i c k G e o m e t r y                                         %
2734 %                                                                             %
2735 %                                                                             %
2736 %                                                                             %
2737 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2738 %
2739 %  GetMagickGeometry() is similar to GetGeometry() except the returned
2740 %  geometry is modified as determined by the meta characters:  %, !, <, >,
2741 %  and ~.
2742 %
2743 %  The format of the GetMagickGeometry method is:
2744 %
2745 %      unsigned int GetMagickGeometry(const char *geometry,long *x,long *y,
2746 %        unsigned long *width,unsigned long *height)
2747 %
2748 %  A description of each parameter follows:
2749 %
2750 %    o geometry:  Specifies a character string representing the geometry
2751 %      specification.
2752 %
2753 %    o x,y:  A pointer to an integer.  The x and y offset as determined by
2754 %      the geometry specification is returned here.
2755 %
2756 %    o width,height:  A pointer to an unsigned integer.  The width and height
2757 %      as determined by the geometry specification is returned here.
2758 %
2759 */
2760 MagickExport unsigned int GetMagickGeometry(const char *geometry,long *x,
2761   long *y,unsigned long *width,unsigned long *height)
2762 {
2763   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.3");
2764   return(ParseMetaGeometry(geometry,x,y,width,height));
2765 }
2766 \f
2767 /*
2768 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2769 %                                                                             %
2770 %                                                                             %
2771 %                                                                             %
2772 %   G e t N e x t I m a g e                                                   %
2773 %                                                                             %
2774 %                                                                             %
2775 %                                                                             %
2776 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2777 %
2778 %  GetNextImage() returns the next image in a list.
2779 %
2780 %  The format of the GetNextImage method is:
2781 %
2782 %      Image *GetNextImage(const Image *images)
2783 %
2784 %  A description of each parameter follows:
2785 %
2786 %    o images: the image list.
2787 %
2788 */
2789 MagickExport Image *GetNextImage(const Image *images)
2790 {
2791   if (images->debug != MagickFalse)
2792     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
2793   return(GetNextImageInList(images));
2794 }
2795 \f
2796 /*
2797 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2798 %                                                                             %
2799 %                                                                             %
2800 %                                                                             %
2801 %   G e t N e x t I m a g e A t t r i b u t e                                 %
2802 %                                                                             %
2803 %                                                                             %
2804 %                                                                             %
2805 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2806 %
2807 %  GetNextImageAttribute() gets the next image attribute.
2808 %
2809 %  The format of the GetNextImageAttribute method is:
2810 %
2811 %      const ImageAttribute *GetNextImageAttribute(const Image *image)
2812 %
2813 %  A description of each parameter follows:
2814 %
2815 %    o image: the image.
2816 %
2817 */
2818 MagickExport const ImageAttribute *GetNextImageAttribute(const Image *image)
2819 {
2820   const char
2821     *property;
2822
2823   property=GetNextImageProperty(image);
2824   if (property == (const char *) NULL)
2825     return((const ImageAttribute *) NULL);
2826   return(GetImageAttribute(image,property));
2827 }
2828 \f
2829 /*
2830 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2831 %                                                                             %
2832 %                                                                             %
2833 %                                                                             %
2834 %   G e t N u m b e r S c e n e s                                             %
2835 %                                                                             %
2836 %                                                                             %
2837 %                                                                             %
2838 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2839 %
2840 %  GetNumberScenes() returns the number of images in the list.
2841 %
2842 %  The format of the GetNumberScenes method is:
2843 %
2844 %      unsigned int GetNumberScenes(const Image *images)
2845 %
2846 %  A description of each parameter follows:
2847 %
2848 %    o images: the image list.
2849 %
2850 */
2851 MagickExport unsigned int GetNumberScenes(const Image *image)
2852 {
2853   if (image->debug != MagickFalse)
2854     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
2855   return((unsigned int) GetImageListLength(image));
2856 }
2857 \f
2858 /*
2859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2860 %                                                                             %
2861 %                                                                             %
2862 %                                                                             %
2863 %   G e t O n e P i x e l                                                     %
2864 %                                                                             %
2865 %                                                                             %
2866 %                                                                             %
2867 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2868 %
2869 %  GetOnePixel() returns a single pixel at the specified (x,y) location.
2870 %  The image background color is returned if an error occurs.
2871 %
2872 %  The format of the GetOnePixel() method is:
2873 %
2874 %      PixelPacket GetOnePixel(const Image image,const long x,const long y)
2875 %
2876 %  A description of each parameter follows:
2877 %
2878 %    o image: the image.
2879 %
2880 %    o x,y:  These values define the location of the pixel to return.
2881 %
2882 */
2883 MagickExport PixelPacket GetOnePixel(Image *image,const long x,const long y)
2884 {
2885   PixelPacket
2886     pixel;
2887
2888   (void) GetOneAuthenticPixel(image,x,y,&pixel,&image->exception);
2889   return(pixel);
2890 }
2891 \f
2892 /*
2893 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2894 %                                                                             %
2895 %                                                                             %
2896 %                                                                             %
2897 %   G e t P i x e l s                                                         %
2898 %                                                                             %
2899 %                                                                             %
2900 %                                                                             %
2901 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2902 %
2903 %  GetPixels() returns the pixels associated with the last call to
2904 %  QueueAuthenticPixels() or GetAuthenticPixels().
2905 %
2906 %  The format of the GetPixels() method is:
2907 %
2908 %      PixelPacket *GetPixels(const Image image)
2909 %
2910 %  A description of each parameter follows:
2911 %
2912 %    o pixels: GetPixels() returns the pixels associated with the last call
2913 %      to QueueAuthenticPixels() or GetAuthenticPixels().
2914 %
2915 %    o image: the image.
2916 %
2917 */
2918 MagickExport PixelPacket *GetPixels(const Image *image)
2919 {
2920   return(GetAuthenticPixelQueue(image));
2921 }
2922 \f
2923 /*
2924 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2925 %                                                                             %
2926 %                                                                             %
2927 %                                                                             %
2928 %   G e t P r e v i o u s I m a g e                                           %
2929 %                                                                             %
2930 %                                                                             %
2931 %                                                                             %
2932 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2933 %
2934 %  GetPreviousImage() returns the previous image in a list.
2935 %
2936 %  The format of the GetPreviousImage method is:
2937 %
2938 %      Image *GetPreviousImage(const Image *images)
2939 %
2940 %  A description of each parameter follows:
2941 %
2942 %    o images: the image list.
2943 %
2944 */
2945 MagickExport Image *GetPreviousImage(const Image *images)
2946 {
2947   if (images->debug != MagickFalse)
2948     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
2949   return(GetPreviousImageInList(images));
2950 }
2951 \f
2952 /*
2953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2954 %                                                                             %
2955 %                                                                             %
2956 %                                                                             %
2957 %   H S L T r a n s f o r m                                                   %
2958 %                                                                             %
2959 %                                                                             %
2960 %                                                                             %
2961 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2962 %
2963 %  HSLTransform() converts a (hue, saturation, lightness) to a (red, green,
2964 %  blue) triple.
2965 %
2966 %  The format of the HSLTransformImage method is:
2967 %
2968 %      void HSLTransform(const double hue,const double saturation,
2969 %        const double lightness,Quantum *red,Quantum *green,Quantum *blue)
2970 %
2971 %  A description of each parameter follows:
2972 %
2973 %    o hue, saturation, lightness: A double value representing a
2974 %      component of the HSL color space.
2975 %
2976 %    o red, green, blue: A pointer to a pixel component of type Quantum.
2977 %
2978 */
2979
2980 static inline MagickRealType HueToRGB(MagickRealType m1,MagickRealType m2,
2981   MagickRealType hue)
2982 {
2983   if (hue < 0.0)
2984     hue+=1.0;
2985   if (hue > 1.0)
2986     hue-=1.0;
2987   if ((6.0*hue) < 1.0)
2988     return(m1+6.0*(m2-m1)*hue);
2989   if ((2.0*hue) < 1.0)
2990     return(m2);
2991   if ((3.0*hue) < 2.0)
2992     return(m1+6.0*(m2-m1)*(2.0/3.0-hue));
2993   return(m1);
2994 }
2995
2996 MagickExport void HSLTransform(const double hue,const double saturation,
2997   const double lightness,Quantum *red,Quantum *green,Quantum *blue)
2998 {
2999   MagickRealType
3000     b,
3001     g,
3002     r,
3003     m1,
3004     m2;
3005
3006   /*
3007     Convert HSL to RGB colorspace.
3008   */
3009   assert(red != (Quantum *) NULL);
3010   assert(green != (Quantum *) NULL);
3011   assert(blue != (Quantum *) NULL);
3012   if (lightness <= 0.5)
3013     m2=lightness*(saturation+1.0);
3014   else
3015     m2=lightness+saturation-lightness*saturation;
3016   m1=2.0*lightness-m2;
3017   r=HueToRGB(m1,m2,hue+1.0/3.0);
3018   g=HueToRGB(m1,m2,hue);
3019   b=HueToRGB(m1,m2,hue-1.0/3.0);
3020   *red=ClampToQuantum((MagickRealType) QuantumRange*r);
3021   *green=ClampToQuantum((MagickRealType) QuantumRange*g);
3022   *blue=ClampToQuantum((MagickRealType) QuantumRange*b);
3023 }
3024 \f
3025 /*
3026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3027 %                                                                             %
3028 %                                                                             %
3029 %                                                                             %
3030 %   I d e n t i t y A f f i n e                                               %
3031 %                                                                             %
3032 %                                                                             %
3033 %                                                                             %
3034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3035 %
3036 %  IdentityAffine() initializes the affine transform to the identity matrix.
3037 %
3038 %  The format of the IdentityAffine method is:
3039 %
3040 %      IdentityAffine(AffineMatrix *affine)
3041 %
3042 %  A description of each parameter follows:
3043 %
3044 %    o affine: A pointer the affine transform of type AffineMatrix.
3045 %
3046 */
3047 MagickExport void IdentityAffine(AffineMatrix *affine)
3048 {
3049   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3050   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
3051   assert(affine != (AffineMatrix *) NULL);
3052   (void) ResetMagickMemory(affine,0,sizeof(AffineMatrix));
3053   affine->sx=1.0;
3054   affine->sy=1.0;
3055 }
3056 \f
3057 /*
3058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3059 %                                                                             %
3060 %                                                                             %
3061 %                                                                             %
3062 %   I n i t i a l i z e M a g i c k                                           %
3063 %                                                                             %
3064 %                                                                             %
3065 %                                                                             %
3066 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3067 %
3068 %  InitializeMagick() initializes the ImageMagick environment.
3069 %
3070 %  The format of the InitializeMagick function is:
3071 %
3072 %      InitializeMagick(const char *path)
3073 %
3074 %  A description of each parameter follows:
3075 %
3076 %    o path: the execution path of the current ImageMagick client.
3077 %
3078 */
3079 MagickExport void InitializeMagick(const char *path)
3080 {
3081   MagickCoreGenesis(path,MagickFalse);
3082 }
3083 \f
3084 /*
3085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3086 %                                                                             %
3087 %                                                                             %
3088 %                                                                             %
3089 %   I n t e r p o l a t e P i x e l C o l o r                                 %
3090 %                                                                             %
3091 %                                                                             %
3092 %                                                                             %
3093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3094 %
3095 %  InterpolatePixelColor() applies bi-linear or tri-linear interpolation
3096 %  between a pixel and it's neighbors.
3097 %
3098 %  The format of the InterpolatePixelColor method is:
3099 %
3100 %      MagickPixelPacket InterpolatePixelColor(const Image *image,
3101 %        CacheView *view_info,InterpolatePixelMethod method,const double x,
3102 %        const double y,ExceptionInfo *exception)
3103 %
3104 %  A description of each parameter follows:
3105 %
3106 %    o image: the image.
3107 %
3108 %    o image_view: the image cache view.
3109 %
3110 %    o type:  the type of pixel color interpolation.
3111 %
3112 %    o x,y: A double representing the current (x,y) position of the pixel.
3113 %
3114 %    o exception: return any errors or warnings in this structure.
3115 %
3116 */
3117
3118 static inline double MagickMax(const double x,const double y)
3119 {
3120   if (x > y)
3121     return(x);
3122   return(y);
3123 }
3124
3125 static void BicubicInterpolate(const MagickPixelPacket *pixels,const double dx,
3126   MagickPixelPacket *pixel)
3127 {
3128   MagickRealType
3129     dx2,
3130     p,
3131     q,
3132     r,
3133     s;
3134
3135   dx2=dx*dx;
3136   p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red);
3137   q=(pixels[0].red-pixels[1].red)-p;
3138   r=pixels[2].red-pixels[0].red;
3139   s=pixels[1].red;
3140   pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
3141   p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green);
3142   q=(pixels[0].green-pixels[1].green)-p;
3143   r=pixels[2].green-pixels[0].green;
3144   s=pixels[1].green;
3145   pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
3146   p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue);
3147   q=(pixels[0].blue-pixels[1].blue)-p;
3148   r=pixels[2].blue-pixels[0].blue;
3149   s=pixels[1].blue;
3150   pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
3151   p=(pixels[3].opacity-pixels[2].opacity)-(pixels[0].opacity-pixels[1].opacity);
3152   q=(pixels[0].opacity-pixels[1].opacity)-p;
3153   r=pixels[2].opacity-pixels[0].opacity;
3154   s=pixels[1].opacity;
3155   pixel->opacity=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
3156   if (pixel->colorspace == CMYKColorspace)
3157     {
3158       p=(pixels[3].index-pixels[2].index)-(pixels[0].index-pixels[1].index);
3159       q=(pixels[0].index-pixels[1].index)-p;
3160       r=pixels[2].index-pixels[0].index;
3161       s=pixels[1].index;
3162       pixel->index=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
3163     }
3164 }
3165
3166 static inline MagickRealType CubicWeightingFunction(const MagickRealType x)
3167 {
3168   MagickRealType
3169     alpha,
3170     gamma;
3171
3172   alpha=MagickMax(x+2.0,0.0);
3173   gamma=1.0*alpha*alpha*alpha;
3174   alpha=MagickMax(x+1.0,0.0);
3175   gamma-=4.0*alpha*alpha*alpha;
3176   alpha=MagickMax(x+0.0,0.0);
3177   gamma+=6.0*alpha*alpha*alpha;
3178   alpha=MagickMax(x-1.0,0.0);
3179   gamma-=4.0*alpha*alpha*alpha;
3180   return(gamma/6.0);
3181 }
3182
3183 static inline double MeshInterpolate(const PointInfo *delta,const double p,
3184   const double x,const double y)
3185 {
3186   return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
3187 }
3188
3189 static inline long NearestNeighbor(MagickRealType x)
3190 {
3191   if (x >= 0.0)
3192     return((long) (x+0.5));
3193   return((long) (x-0.5));
3194 }
3195
3196 MagickExport MagickPixelPacket InterpolatePixelColor(const Image *image,
3197   CacheView *image_view,const InterpolatePixelMethod method,const double x,
3198   const double y,ExceptionInfo *exception)
3199 {
3200   MagickPixelPacket
3201     pixel;
3202
3203   register const IndexPacket
3204     *indexes;
3205
3206   register const PixelPacket
3207     *p;
3208
3209   register long
3210     i;
3211
3212   assert(image != (Image *) NULL);
3213   assert(image->signature == MagickSignature);
3214   assert(image_view != (CacheView *) NULL);
3215   GetMagickPixelPacket(image,&pixel);
3216   switch (method)
3217   {
3218     case AverageInterpolatePixel:
3219     {
3220       MagickPixelPacket
3221         pixels[16];
3222
3223       MagickRealType
3224         alpha[16],
3225         gamma;
3226
3227       p=GetCacheViewVirtualPixels(image_view,(long) floor(x)-1,(long) floor(y)-
3228         1,4,4,exception);
3229       if (p == (const PixelPacket *) NULL)
3230         break;
3231       indexes=GetCacheViewVirtualIndexQueue(image_view);
3232       for (i=0; i < 16L; i++)
3233       {
3234         GetMagickPixelPacket(image,pixels+i);
3235         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
3236         alpha[i]=1.0;
3237         if (image->matte != MagickFalse)
3238           {
3239             alpha[i]=QuantumScale*((MagickRealType) GetAlphaPixelComponent(p));
3240             pixels[i].red*=alpha[i];
3241             pixels[i].green*=alpha[i];
3242             pixels[i].blue*=alpha[i];
3243             if (image->colorspace == CMYKColorspace)
3244               pixels[i].index*=alpha[i];
3245           }
3246         gamma=alpha[i];
3247         gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3248         pixel.red+=gamma*0.0625*pixels[i].red;
3249         pixel.green+=gamma*0.0625*pixels[i].green;
3250         pixel.blue+=gamma*0.0625*pixels[i].blue;
3251         pixel.opacity+=0.0625*pixels[i].opacity;
3252         if (image->colorspace == CMYKColorspace)
3253           pixel.index+=gamma*0.0625*pixels[i].index;
3254         p++;
3255       }
3256       break;
3257     }
3258     case BicubicInterpolatePixel:
3259     {
3260       MagickPixelPacket
3261         pixels[16],
3262         u[4];
3263
3264       MagickRealType
3265         alpha[16];
3266
3267       PointInfo
3268         delta;
3269
3270       p=GetCacheViewVirtualPixels(image_view,(long) floor(x)-1,(long) floor(y)-
3271         1,4,4,exception);
3272       if (p == (const PixelPacket *) NULL)
3273         break;
3274       indexes=GetCacheViewVirtualIndexQueue(image_view);
3275       for (i=0; i < 16L; i++)
3276       {
3277         GetMagickPixelPacket(image,pixels+i);
3278         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
3279         alpha[i]=1.0;
3280         if (image->matte != MagickFalse)
3281           {
3282             alpha[i]=QuantumScale*((MagickRealType) GetAlphaPixelComponent(p));
3283             pixels[i].red*=alpha[i];
3284             pixels[i].green*=alpha[i];
3285             pixels[i].blue*=alpha[i];
3286             if (image->colorspace == CMYKColorspace)
3287               pixels[i].index*=alpha[i];
3288           }
3289         p++;
3290       }
3291       delta.x=x-floor(x);
3292       for (i=0; i < 4L; i++)
3293         BicubicInterpolate(pixels+4*i,delta.x,u+i);
3294       delta.y=y-floor(y);
3295       BicubicInterpolate(u,delta.y,&pixel);
3296       break;
3297     }
3298     case BilinearInterpolatePixel:
3299     default:
3300     {
3301       MagickPixelPacket
3302         pixels[16];
3303
3304       MagickRealType
3305         alpha[16],
3306         gamma;
3307
3308       PointInfo
3309         delta;
3310
3311       p=GetCacheViewVirtualPixels(image_view,(long) floor(x),(long) floor(y),2,
3312         2,exception);
3313       if (p == (const PixelPacket *) NULL)
3314         break;
3315       indexes=GetCacheViewVirtualIndexQueue(image_view);
3316       for (i=0; i < 4L; i++)
3317       {
3318         GetMagickPixelPacket(image,pixels+i);
3319         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
3320         alpha[i]=1.0;
3321         if (image->matte != MagickFalse)
3322           {
3323             alpha[i]=QuantumScale*((MagickRealType) GetAlphaPixelComponent(p));
3324             pixels[i].red*=alpha[i];
3325             pixels[i].green*=alpha[i];
3326             pixels[i].blue*=alpha[i];
3327             if (image->colorspace == CMYKColorspace)
3328               pixels[i].index*=alpha[i];
3329           }
3330         p++;
3331       }
3332       delta.x=x-floor(x);
3333       delta.y=y-floor(y);
3334       gamma=(((1.0-delta.y)*((1.0-delta.x)*alpha[0]+delta.x*alpha[1])+delta.y*
3335         ((1.0-delta.x)*alpha[2]+delta.x*alpha[3])));
3336       gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3337       pixel.red=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].red+delta.x*
3338         pixels[1].red)+delta.y*((1.0-delta.x)*pixels[2].red+delta.x*
3339         pixels[3].red));
3340       pixel.green=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].green+delta.x*
3341         pixels[1].green)+delta.y*((1.0-delta.x)*pixels[2].green+
3342         delta.x*pixels[3].green));
3343       pixel.blue=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].blue+delta.x*
3344         pixels[1].blue)+delta.y*((1.0-delta.x)*pixels[2].blue+delta.x*
3345         pixels[3].blue));
3346       pixel.opacity=((1.0-delta.y)*((1.0-delta.x)*pixels[0].opacity+delta.x*
3347         pixels[1].opacity)+delta.y*((1.0-delta.x)*pixels[2].opacity+delta.x*
3348         pixels[3].opacity));
3349       if (image->colorspace == CMYKColorspace)
3350         pixel.index=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].index+delta.x*
3351           pixels[1].index)+delta.y*((1.0-delta.x)*pixels[2].index+delta.x*
3352           pixels[3].index));
3353       break;
3354     }
3355     case FilterInterpolatePixel:
3356     {
3357       Image
3358         *excerpt_image,
3359         *filter_image;
3360
3361       MagickPixelPacket
3362         pixels[1];
3363
3364       RectangleInfo
3365         geometry;
3366
3367       geometry.width=4L;
3368       geometry.height=4L;
3369       geometry.x=(long) floor(x)-1L;
3370       geometry.y=(long) floor(y)-1L;
3371       excerpt_image=ExcerptImage(image,&geometry,exception);
3372       if (excerpt_image == (Image *) NULL)
3373         break;
3374       filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
3375         exception);
3376       excerpt_image=DestroyImage(excerpt_image);
3377       if (filter_image == (Image *) NULL)
3378         break;
3379       p=GetVirtualPixels(filter_image,0,0,1,1,exception);
3380       if (p == (const PixelPacket *) NULL)
3381         {
3382           filter_image=DestroyImage(filter_image);
3383           break;
3384         }
3385       indexes=GetVirtualIndexQueue(filter_image);
3386       GetMagickPixelPacket(image,pixels);
3387       SetMagickPixelPacket(image,p,indexes,&pixel);
3388       filter_image=DestroyImage(filter_image);
3389       break;
3390     }
3391     case IntegerInterpolatePixel:
3392     {
3393       MagickPixelPacket
3394         pixels[1];
3395
3396       p=GetCacheViewVirtualPixels(image_view,(long) floor(x),(long) floor(y),1,
3397         1,exception);
3398       if (p == (const PixelPacket *) NULL)
3399         break;
3400       indexes=GetCacheViewVirtualIndexQueue(image_view);
3401       GetMagickPixelPacket(image,pixels);
3402       SetMagickPixelPacket(image,p,indexes,&pixel);
3403       break;
3404     }
3405     case MeshInterpolatePixel:
3406     {
3407       MagickPixelPacket
3408         pixels[4];
3409
3410       MagickRealType
3411         alpha[4],
3412         gamma;
3413
3414       PointInfo
3415         delta,
3416         luminance;
3417
3418       p=GetCacheViewVirtualPixels(image_view,(long) floor(x),(long) floor(y),
3419         2,2,exception);
3420       if (p == (const PixelPacket *) NULL)
3421         break;
3422       indexes=GetCacheViewVirtualIndexQueue(image_view);
3423       for (i=0; i < 4L; i++)
3424       {
3425         GetMagickPixelPacket(image,pixels+i);
3426         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
3427         alpha[i]=1.0;
3428         if (image->matte != MagickFalse)
3429           {
3430             alpha[i]=QuantumScale*((MagickRealType) GetAlphaPixelComponent(p));
3431             pixels[i].red*=alpha[i];
3432             pixels[i].green*=alpha[i];
3433             pixels[i].blue*=alpha[i];
3434             if (image->colorspace == CMYKColorspace)
3435               pixels[i].index*=alpha[i];
3436           }
3437         p++;
3438       }
3439       delta.x=x-floor(x);
3440       delta.y=y-floor(y);
3441       luminance.x=MagickPixelLuminance(pixels+0)-MagickPixelLuminance(pixels+3);
3442       luminance.y=MagickPixelLuminance(pixels+1)-MagickPixelLuminance(pixels+2);
3443       if (fabs(luminance.x) < fabs(luminance.y))
3444         {
3445           /*
3446             Diagonal 0-3 NW-SE.
3447           */
3448           if (delta.x <= delta.y)
3449             {
3450               /*
3451                 Bottom-left triangle  (pixel:2, diagonal: 0-3).
3452               */
3453               delta.y=1.0-delta.y;
3454               gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
3455               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3456               pixel.red=gamma*MeshInterpolate(&delta,pixels[2].red,
3457                 pixels[3].red,pixels[0].red);
3458               pixel.green=gamma*MeshInterpolate(&delta,pixels[2].green,
3459                 pixels[3].green,pixels[0].green);
3460               pixel.blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
3461                 pixels[3].blue,pixels[0].blue);
3462               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[2].opacity,
3463                 pixels[3].opacity,pixels[0].opacity);
3464               if (image->colorspace == CMYKColorspace)
3465                 pixel.index=gamma*MeshInterpolate(&delta,pixels[2].index,
3466                   pixels[3].index,pixels[0].index);
3467             }
3468           else
3469             {
3470               /*
3471                 Top-right triangle (pixel:1, diagonal: 0-3).
3472               */
3473               delta.x=1.0-delta.x;
3474               gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
3475               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3476               pixel.red=gamma*MeshInterpolate(&delta,pixels[1].red,
3477                 pixels[0].red,pixels[3].red);
3478               pixel.green=gamma*MeshInterpolate(&delta,pixels[1].green,
3479                 pixels[0].green,pixels[3].green);
3480               pixel.blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
3481                 pixels[0].blue,pixels[3].blue);
3482               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[1].opacity,
3483                 pixels[0].opacity,pixels[3].opacity);
3484               if (image->colorspace == CMYKColorspace)
3485                 pixel.index=gamma*MeshInterpolate(&delta,pixels[1].index,
3486                   pixels[0].index,pixels[3].index);
3487             }
3488         }
3489       else
3490         {
3491           /*
3492             Diagonal 1-2 NE-SW.
3493           */
3494           if (delta.x <= (1.0-delta.y))
3495             {
3496               /*
3497                 Top-left triangle (pixel 0, diagonal: 1-2).
3498               */
3499               gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
3500               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3501               pixel.red=gamma*MeshInterpolate(&delta,pixels[0].red,
3502                 pixels[1].red,pixels[2].red);
3503               pixel.green=gamma*MeshInterpolate(&delta,pixels[0].green,
3504                 pixels[1].green,pixels[2].green);
3505               pixel.blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
3506                 pixels[1].blue,pixels[2].blue);
3507               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[0].opacity,
3508                 pixels[1].opacity,pixels[2].opacity);
3509               if (image->colorspace == CMYKColorspace)
3510                 pixel.index=gamma*MeshInterpolate(&delta,pixels[0].index,
3511                   pixels[1].index,pixels[2].index);
3512             }
3513           else
3514             {
3515               /*
3516                 Bottom-right triangle (pixel: 3, diagonal: 1-2).
3517               */
3518               delta.x=1.0-delta.x;
3519               delta.y=1.0-delta.y;
3520               gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
3521               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3522               pixel.red=gamma*MeshInterpolate(&delta,pixels[3].red,
3523                 pixels[2].red,pixels[1].red);
3524               pixel.green=gamma*MeshInterpolate(&delta,pixels[3].green,
3525                 pixels[2].green,pixels[1].green);
3526               pixel.blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
3527                 pixels[2].blue,pixels[1].blue);
3528               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[3].opacity,
3529                 pixels[2].opacity,pixels[1].opacity);
3530               if (image->colorspace == CMYKColorspace)
3531                 pixel.index=gamma*MeshInterpolate(&delta,pixels[3].index,
3532                   pixels[2].index,pixels[1].index);
3533             }
3534         }
3535       break;
3536     }
3537     case NearestNeighborInterpolatePixel:
3538     {
3539       MagickPixelPacket
3540         pixels[1];
3541
3542       p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
3543         NearestNeighbor(y),1,1,exception);
3544       if (p == (const PixelPacket *) NULL)
3545         break;
3546       indexes=GetCacheViewVirtualIndexQueue(image_view);
3547       GetMagickPixelPacket(image,pixels);
3548       SetMagickPixelPacket(image,p,indexes,&pixel);
3549       break;
3550     }
3551     case SplineInterpolatePixel:
3552     {
3553       long
3554         j,
3555         n;
3556
3557       MagickPixelPacket
3558         pixels[16];
3559
3560       MagickRealType
3561         alpha[16],
3562         dx,
3563         dy,
3564         gamma;
3565
3566       PointInfo
3567         delta;
3568
3569       p=GetCacheViewVirtualPixels(image_view,(long) floor(x)-1,(long) floor(y)-
3570         1,4,4,exception);
3571       if (p == (const PixelPacket *) NULL)
3572         break;
3573       indexes=GetCacheViewVirtualIndexQueue(image_view);
3574       n=0;
3575       delta.x=x-floor(x);
3576       delta.y=y-floor(y);
3577       for (i=(-1); i < 3L; i++)
3578       {
3579         dy=CubicWeightingFunction((MagickRealType) i-delta.y);
3580         for (j=(-1); j < 3L; j++)
3581         {
3582           GetMagickPixelPacket(image,pixels+n);
3583           SetMagickPixelPacket(image,p,indexes+n,pixels+n);
3584           alpha[n]=1.0;
3585           if (image->matte != MagickFalse)
3586             {
3587               alpha[n]=QuantumScale*((MagickRealType) GetAlphaPixelComponent(p));
3588               pixels[n].red*=alpha[n];
3589               pixels[n].green*=alpha[n];
3590               pixels[n].blue*=alpha[n];
3591               if (image->colorspace == CMYKColorspace)
3592                 pixels[n].index*=alpha[n];
3593             }
3594           dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
3595           gamma=alpha[n];
3596           gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3597           pixel.red+=gamma*dx*dy*pixels[n].red;
3598           pixel.green+=gamma*dx*dy*pixels[n].green;
3599           pixel.blue+=gamma*dx*dy*pixels[n].blue;
3600           if (image->matte != MagickFalse)
3601             pixel.opacity+=dx*dy*pixels[n].opacity;
3602           if (image->colorspace == CMYKColorspace)
3603             pixel.index+=gamma*dx*dy*pixels[n].index;
3604           n++;
3605           p++;
3606         }
3607       }
3608       break;
3609     }
3610   }
3611   return(pixel);
3612 }
3613 \f
3614 /*
3615 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3616 %                                                                             %
3617 %                                                                             %
3618 %                                                                             %
3619 %   I n t e r p r e t I m a g e A t t r i b u t e s                           %
3620 %                                                                             %
3621 %                                                                             %
3622 %                                                                             %
3623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3624 %
3625 %  InterpretImageAttributes() replaces any embedded formatting characters with
3626 %  the appropriate image attribute and returns the translated text.
3627 %
3628 %  The format of the InterpretImageAttributes method is:
3629 %
3630 %      char *InterpretImageAttributes(const ImageInfo *image_info,Image *image,
3631 %        const char *embed_text)
3632 %
3633 %  A description of each parameter follows:
3634 %
3635 %    o image_info: the image info.
3636 %
3637 %    o image: the image.
3638 %
3639 %    o embed_text: the address of a character string containing the embedded
3640 %      formatting characters.
3641 %
3642 */
3643 MagickExport char *InterpretImageAttributes(const ImageInfo *image_info,
3644   Image *image,const char *embed_text)
3645 {
3646   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.3.1");
3647   return(InterpretImageProperties(image_info,image,embed_text));
3648 }
3649 \f
3650 /*
3651 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3652 %                                                                             %
3653 %                                                                             %
3654 %                                                                             %
3655 +     I s S u b i m a g e                                                     %
3656 %                                                                             %
3657 %                                                                             %
3658 %                                                                             %
3659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3660 %
3661 %  IsSubimage() returns MagickTrue if the geometry is a valid subimage
3662 %  specification (e.g. [1], [1-9], [1,7,4]).
3663 %
3664 %  The format of the IsSubimage method is:
3665 %
3666 %      unsigned int IsSubimage(const char *geometry,const unsigned int pedantic)
3667 %
3668 %  A description of each parameter follows:
3669 %
3670 %    o geometry: This string is the geometry specification.
3671 %
3672 %    o pedantic: A value other than 0 invokes a more restrictive set of
3673 %      conditions for a valid specification (e.g. [1], [1-4], [4-1]).
3674 %
3675 */
3676 MagickExport unsigned int IsSubimage(const char *geometry,
3677   const unsigned int pedantic)
3678 {
3679   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
3680   if (geometry == (const char *) NULL)
3681     return(MagickFalse);
3682   if ((strchr(geometry,'x') != (char *) NULL) ||
3683       (strchr(geometry,'X') != (char *) NULL))
3684     return(MagickFalse);
3685   if ((pedantic != MagickFalse) && (strchr(geometry,',') != (char *) NULL))
3686     return(MagickFalse);
3687   return(MagickTrue);
3688 }
3689 \f
3690 /*
3691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3692 %                                                                             %
3693 %                                                                             %
3694 %                                                                             %
3695 %     L e v e l I m a g e C o l o r s                                         %
3696 %                                                                             %
3697 %                                                                             %
3698 %                                                                             %
3699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3700 %
3701 %  LevelImageColor() will map the given color to "black" and "white"
3702 %  values, limearly spreading out the colors, and level values on a channel by
3703 %  channel bases, as per LevelImage().  The given colors allows you to specify
3704 %  different level ranges for each of the color channels seperatally.
3705 %
3706 %  If the boolean 'invert' is set true the image values will modifyed in the
3707 %  reverse direction. That is any existing "black" and "white" colors in the
3708 %  image will become the color values given, with all other values compressed
3709 %  appropriatally.  This effectivally maps a greyscale gradient into the given
3710 %  color gradient.
3711 %
3712 %  The format of the LevelImageColors method is:
3713 %
3714 %  MagickBooleanType LevelImageColors(Image *image,const ChannelType channel,
3715 %    const MagickPixelPacket *black_color,const MagickPixelPacket *white_color,
3716 %    const MagickBooleanType invert)
3717 %
3718 %  A description of each parameter follows:
3719 %
3720 %    o image: the image.
3721 %
3722 %    o channel: the channel.
3723 %
3724 %    o black_color: The color to map black to/from
3725 %
3726 %    o white_point: The color to map white to/from
3727 %
3728 %    o invert: if true map the colors (levelize), rather than from (level)
3729 %
3730 */
3731 MagickBooleanType LevelImageColors(Image *image,const ChannelType channel,
3732   const MagickPixelPacket *black_color,const MagickPixelPacket *white_color,
3733   const MagickBooleanType invert)
3734 {
3735   return(LevelColorsImageChannel(image,channel,black_color,white_color,invert));
3736 }
3737 \f
3738 /*
3739 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3740 %                                                                             %
3741 %                                                                             %
3742 %                                                                             %
3743 %   L i b e r a t e M e m o r y                                               %
3744 %                                                                             %
3745 %                                                                             %
3746 %                                                                             %
3747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3748 %
3749 %  LiberateMemory() frees memory that has already been allocated, and NULL's
3750 %  the pointer to it.
3751 %
3752 %  The format of the LiberateMemory method is:
3753 %
3754 %      void LiberateMemory(void **memory)
3755 %
3756 %  A description of each parameter follows:
3757 %
3758 %    o memory: A pointer to a block of memory to free for reuse.
3759 %
3760 */
3761 MagickExport void LiberateMemory(void **memory)
3762 {
3763   assert(memory != (void **) NULL);
3764   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
3765   if (*memory == (void *) NULL)
3766     return;
3767   free(*memory);
3768   *memory=(void *) NULL;
3769 }
3770 \f
3771 /*
3772 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3773 %                                                                             %
3774 %                                                                             %
3775 %                                                                             %
3776 %   L i b e r a t e S e m a p h o r e I n f o                                 %
3777 %                                                                             %
3778 %                                                                             %
3779 %                                                                             %
3780 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3781 %
3782 %  LiberateSemaphoreInfo() relinquishes a semaphore.
3783 %
3784 %  The format of the LiberateSemaphoreInfo method is:
3785 %
3786 %      LiberateSemaphoreInfo(void **semaphore_info)
3787 %
3788 %  A description of each parameter follows:
3789 %
3790 %    o semaphore_info: Specifies a pointer to an SemaphoreInfo structure.
3791 %
3792 */
3793 MagickExport void LiberateSemaphoreInfo(SemaphoreInfo **semaphore_info)
3794 {
3795   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
3796   UnlockSemaphoreInfo(*semaphore_info);
3797 }
3798 \f
3799 /*
3800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3801 %                                                                             %
3802 %                                                                             %
3803 %                                                                             %
3804 %   M a g i c k I n c a r n a t e                                             %
3805 %                                                                             %
3806 %                                                                             %
3807 %                                                                             %
3808 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3809 %
3810 %  MagickIncarnate() initializes the ImageMagick environment.
3811 %
3812 %  The format of the MagickIncarnate function is:
3813 %
3814 %      MagickIncarnate(const char *path)
3815 %
3816 %  A description of each parameter follows:
3817 %
3818 %    o path: the execution path of the current ImageMagick client.
3819 %
3820 */
3821
3822 MagickExport void MagickIncarnate(const char *path)
3823 {
3824   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1");
3825   MagickCoreGenesis(path,MagickFalse);
3826 }
3827 \f
3828 /*
3829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3830 %                                                                             %
3831 %                                                                             %
3832 %                                                                             %
3833 %   M a g i c k M o n i t o r                                                 %
3834 %                                                                             %
3835 %                                                                             %
3836 %                                                                             %
3837 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3838 %
3839 %  MagickMonitor() calls the monitor handler method with a text string that
3840 %  describes the task and a measure of completion.  The method returns
3841 %  MagickTrue on success otherwise MagickFalse if an error is encountered, e.g.
3842 %  if there was a user interrupt.
3843 %
3844 %  The format of the MagickMonitor method is:
3845 %
3846 %      MagickBooleanType MagickMonitor(const char *text,
3847 %        const MagickOffsetType offset,const MagickSizeType span,
3848 %        void *client_data)
3849 %
3850 %  A description of each parameter follows:
3851 %
3852 %    o offset: the position relative to the span parameter which represents
3853 %      how much progress has been made toward completing a task.
3854 %
3855 %    o span: the span relative to completing a task.
3856 %
3857 %    o client_data: the client data.
3858 %
3859 */
3860 MagickExport MagickBooleanType MagickMonitor(const char *text,
3861   const MagickOffsetType offset,const MagickSizeType span,
3862   void *magick_unused(client_data))
3863 {
3864   ExceptionInfo
3865     *exception;
3866
3867   MagickBooleanType
3868     status;
3869
3870   assert(text != (const char *) NULL);
3871   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",text);
3872   ProcessPendingEvents(text);
3873   status=MagickTrue;
3874   exception=AcquireExceptionInfo();
3875   if (monitor_handler != (MonitorHandler) NULL)
3876     status=(*monitor_handler)(text,offset,span,exception);
3877   exception=DestroyExceptionInfo(exception);
3878   return(status);
3879 }
3880 \f
3881 /*
3882 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3883 %                                                                             %
3884 %                                                                             %
3885 %                                                                             %
3886 %   M a p I m a g e                                                           %
3887 %                                                                             %
3888 %                                                                             %
3889 %                                                                             %
3890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3891 %
3892 %  MapImage() replaces the colors of an image with the closest color from a
3893 %  reference image.
3894 %
3895 %  The format of the MapImage method is:
3896 %
3897 %      MagickBooleanType MapImage(Image *image,const Image *map_image,
3898 %        const MagickBooleanType dither)
3899 %
3900 %  A description of each parameter follows:
3901 %
3902 %    o image: Specifies a pointer to an Image structure.
3903 %
3904 %    o map_image: the image.  Reduce image to a set of colors represented by
3905 %      this image.
3906 %
3907 %    o dither: Set this integer value to something other than zero to
3908 %      dither the mapped image.
3909 %
3910 */
3911 MagickExport MagickBooleanType MapImage(Image *image,const Image *map_image,
3912   const MagickBooleanType dither)
3913 {
3914   QuantizeInfo
3915     quantize_info;
3916
3917   /*
3918     Initialize color cube.
3919   */
3920   assert(image != (Image *) NULL);
3921   assert(image->signature == MagickSignature);
3922   if (image->debug != MagickFalse)
3923     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3924   assert(map_image != (Image *) NULL);
3925   assert(map_image->signature == MagickSignature);
3926   GetQuantizeInfo(&quantize_info);
3927   quantize_info.dither=dither;
3928   return(RemapImage(&quantize_info,image,map_image));
3929 }
3930 \f
3931 /*
3932 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3933 %                                                                             %
3934 %                                                                             %
3935 %                                                                             %
3936 %   M a p I m a g e s                                                         %
3937 %                                                                             %
3938 %                                                                             %
3939 %                                                                             %
3940 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3941 %
3942 %  MapImages() replaces the colors of a sequence of images with the closest
3943 %  color from a reference image.
3944 %
3945 %  The format of the MapImage method is:
3946 %
3947 %      MagickBooleanType MapImages(Image *images,Image *map_image,
3948 %        const MagickBooleanType dither)
3949 %
3950 %  A description of each parameter follows:
3951 %
3952 %    o image: Specifies a pointer to a set of Image structures.
3953 %
3954 %    o map_image: the image.  Reduce image to a set of colors represented by
3955 %      this image.
3956 %
3957 %    o dither: Set this integer value to something other than zero to
3958 %      dither the quantized image.
3959 %
3960 */
3961 MagickExport MagickBooleanType MapImages(Image *images,const Image *map_image,
3962   const MagickBooleanType dither)
3963 {
3964   QuantizeInfo
3965     quantize_info;
3966
3967   assert(images != (Image *) NULL);
3968   assert(images->signature == MagickSignature);
3969   if (images->debug != MagickFalse)
3970     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3971   GetQuantizeInfo(&quantize_info);
3972   quantize_info.dither=dither;
3973   return(RemapImages(&quantize_info,images,map_image));
3974 }
3975 \f
3976 /*
3977 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3978 %                                                                             %
3979 %                                                                             %
3980 %                                                                             %
3981 %   M a t t e F l o o d f i l l I m a g e                                     %
3982 %                                                                             %
3983 %                                                                             %
3984 %                                                                             %
3985 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3986 %
3987 %  MatteFloodfill() changes the transparency value of any pixel that matches
3988 %  target and is an immediate neighbor.  If the method FillToBorderMethod
3989 %  is specified, the transparency value is changed for any neighbor pixel
3990 %  that does not match the bordercolor member of image.
3991 %
3992 %  By default target must match a particular pixel transparency exactly.
3993 %  However, in many cases two transparency values may differ by a
3994 %  small amount.  The fuzz member of image defines how much tolerance is
3995 %  acceptable to consider two transparency values as the same.  For example,
3996 %  set fuzz to 10 and the opacity values of 100 and 102 respectively are
3997 %  now interpreted as the same value for the purposes of the floodfill.
3998 %
3999 %  The format of the MatteFloodfillImage method is:
4000 %
4001 %      MagickBooleanType MatteFloodfillImage(Image *image,
4002 %        const PixelPacket target,const Quantum opacity,const long x_offset,
4003 %        const long y_offset,const PaintMethod method)
4004 %
4005 %  A description of each parameter follows:
4006 %
4007 %    o image: the image.
4008 %
4009 %    o target: the RGB value of the target color.
4010 %
4011 %    o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
4012 %      fully transparent.
4013 %
4014 %    o x,y: the starting location of the operation.
4015 %
4016 %    o method:  Choose either FloodfillMethod or FillToBorderMethod.
4017 %
4018 */
4019 MagickExport MagickBooleanType MatteFloodfillImage(Image *image,
4020   const PixelPacket target,const Quantum opacity,const long x_offset,
4021   const long y_offset,const PaintMethod method)
4022 {
4023   Image
4024     *floodplane_image;
4025
4026   long
4027     offset,
4028     start,
4029     x,
4030     x1,
4031     x2,
4032     y;
4033
4034   MagickBooleanType
4035     skip;
4036
4037   register SegmentInfo
4038     *s;
4039
4040   SegmentInfo
4041     *segment_stack;
4042
4043   /*
4044     Check boundary conditions.
4045   */
4046   assert(image != (Image *) NULL);
4047   assert(image->signature == MagickSignature);
4048   if (image->debug != MagickFalse)
4049     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4050   if ((x_offset < 0) || (x_offset >= (long) image->columns))
4051     return(MagickFalse);
4052   if ((y_offset < 0) || (y_offset >= (long) image->rows))
4053     return(MagickFalse);
4054   if (SetImageStorageClass(image,DirectClass) == MagickFalse)
4055     return(MagickFalse);
4056   if (image->matte == MagickFalse)
4057     (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
4058   floodplane_image=CloneImage(image,image->columns,image->rows,MagickTrue,
4059     &image->exception);
4060   if (floodplane_image == (Image *) NULL)
4061     return(MagickFalse);
4062   (void) SetImageAlphaChannel(floodplane_image,OpaqueAlphaChannel);
4063   /*
4064     Set floodfill color.
4065   */
4066   segment_stack=(SegmentInfo *) AcquireQuantumMemory(MaxStacksize,
4067     sizeof(*segment_stack));
4068   if (segment_stack == (SegmentInfo *) NULL)
4069     {
4070       floodplane_image=DestroyImage(floodplane_image);
4071       ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
4072         image->filename);
4073     }
4074   /*
4075     Push initial segment on stack.
4076   */
4077   x=x_offset;
4078   y=y_offset;
4079   start=0;
4080   s=segment_stack;
4081   PushSegmentStack(y,x,x,1);
4082   PushSegmentStack(y+1,x,x,-1);
4083   while (s > segment_stack)
4084   {
4085     register const PixelPacket
4086       *restrict p;
4087
4088     register long
4089       x;
4090
4091     register PixelPacket
4092       *restrict q;
4093
4094     /*
4095       Pop segment off stack.
4096     */
4097     s--;
4098     x1=(long) s->x1;
4099     x2=(long) s->x2;
4100     offset=(long) s->y2;
4101     y=(long) s->y1+offset;
4102     /*
4103       Recolor neighboring pixels.
4104     */
4105     p=GetVirtualPixels(image,0,y,(unsigned long) (x1+1),1,&image->exception);
4106     q=GetAuthenticPixels(floodplane_image,0,y,(unsigned long) (x1+1),1,
4107       &image->exception);
4108     if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
4109       break;
4110     p+=x1;
4111     q+=x1;
4112     for (x=x1; x >= 0; x--)
4113     {
4114       if (q->opacity == (Quantum) TransparentOpacity)
4115         break;
4116       if (method == FloodfillMethod)
4117         {
4118           if (IsColorSimilar(image,p,&target) == MagickFalse)
4119             break;
4120         }
4121       else
4122         if (IsColorSimilar(image,p,&target) != MagickFalse)
4123           break;
4124       q->opacity=(Quantum) TransparentOpacity;
4125       q--;
4126       p--;
4127     }
4128     if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse)
4129       break;
4130     skip=x >= x1 ? MagickTrue : MagickFalse;
4131     if (skip == MagickFalse)
4132       {
4133         start=x+1;
4134         if (start < x1)
4135           PushSegmentStack(y,start,x1-1,-offset);
4136         x=x1+1;
4137       }
4138     do
4139     {
4140       if (skip == MagickFalse)
4141         {
4142           if (x < (long) image->columns)
4143             {
4144               p=GetVirtualPixels(image,x,y,image->columns-x,1,
4145                 &image->exception);
4146               q=GetAuthenticPixels(floodplane_image,x,y,image->columns-x,1,
4147                 &image->exception);
4148               if ((p == (const PixelPacket *) NULL) ||
4149                   (q == (PixelPacket *) NULL))
4150                 break;
4151               for ( ; x < (long) image->columns; x++)
4152               {
4153                 if (q->opacity == (Quantum) TransparentOpacity)
4154                   break;
4155                 if (method == FloodfillMethod)
4156                   {
4157                     if (IsColorSimilar(image,p,&target) == MagickFalse)
4158                       break;
4159                   }
4160                 else
4161                   if (IsColorSimilar(image,p,&target) != MagickFalse)
4162                     break;
4163                 q->opacity=(Quantum) TransparentOpacity;
4164                 q++;
4165                 p++;
4166               }
4167               if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse)
4168                 break;
4169             }
4170           PushSegmentStack(y,start,x-1,offset);
4171           if (x > (x2+1))
4172             PushSegmentStack(y,x2+1,x-1,-offset);
4173         }
4174       skip=MagickFalse;
4175       x++;
4176       if (x <= x2)
4177         {
4178           p=GetVirtualPixels(image,x,y,(unsigned long) (x2-x+1),1,
4179             &image->exception);
4180           q=GetAuthenticPixels(floodplane_image,x,y,(unsigned long) (x2-x+1),1,
4181             &image->exception);
4182           if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
4183             break;
4184           for ( ; x <= x2; x++)
4185           {
4186             if (q->opacity == (Quantum) TransparentOpacity)
4187               break;
4188             if (method == FloodfillMethod)
4189               {
4190                 if (IsColorSimilar(image,p,&target) != MagickFalse)
4191                   break;
4192               }
4193             else
4194               if (IsColorSimilar(image,p,&target) == MagickFalse)
4195                 break;
4196             p++;
4197             q++;
4198           }
4199         }
4200       start=x;
4201     } while (x <= x2);
4202   }
4203   for (y=0; y < (long) image->rows; y++)
4204   {
4205     register const PixelPacket
4206       *restrict p;
4207
4208     register long
4209       x;
4210
4211     register PixelPacket
4212       *restrict q;
4213
4214     /*
4215       Tile fill color onto floodplane.
4216     */
4217     p=GetVirtualPixels(floodplane_image,0,y,image->columns,1,
4218       &image->exception);
4219     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
4220     if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
4221       break;
4222     for (x=0; x < (long) image->columns; x++)
4223     {
4224       if (p->opacity != OpaqueOpacity)
4225         q->opacity=opacity;
4226       p++;
4227       q++;
4228     }
4229     if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
4230       break;
4231   }
4232   segment_stack=(SegmentInfo *) RelinquishMagickMemory(segment_stack);
4233   floodplane_image=DestroyImage(floodplane_image);
4234   return(y == (long) image->rows ? MagickTrue : MagickFalse);
4235 }
4236 \f
4237 /*
4238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4239 %                                                                             %
4240 %                                                                             %
4241 %                                                                             %
4242 %     M a x i m u m I m a g e s                                               %
4243 %                                                                             %
4244 %                                                                             %
4245 %                                                                             %
4246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4247 %
4248 %  MaximumImages() returns the maximum intensity of an image sequence.
4249 %
4250 %  The format of the MaxImages method is:
4251 %
4252 %      Image *MaximumImages(Image *images,ExceptionInfo *exception)
4253 %
4254 %  A description of each parameter follows:
4255 %
4256 %    o images: the image sequence.
4257 %
4258 %    o exception: return any errors or warnings in this structure.
4259 %
4260 */
4261 MagickExport Image *MaximumImages(const Image *images,ExceptionInfo *exception)
4262 {
4263   return(EvaluateImages(images,MinEvaluateOperator,exception));
4264 }
4265 \f
4266 /*
4267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4268 %                                                                             %
4269 %                                                                             %
4270 %                                                                             %
4271 %     M i n i m u m I m a g e s                                               %
4272 %                                                                             %
4273 %                                                                             %
4274 %                                                                             %
4275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4276 %
4277 %  MinimumImages() returns the minimum intensity of an image sequence.
4278 %
4279 %  The format of the MinimumImages method is:
4280 %
4281 %      Image *MinimumImages(Image *images,ExceptionInfo *exception)
4282 %
4283 %  A description of each parameter follows:
4284 %
4285 %    o images: the image sequence.
4286 %
4287 %    o exception: return any errors or warnings in this structure.
4288 %
4289 */
4290 MagickExport Image *MinimumImages(const Image *images,ExceptionInfo *exception)
4291 {
4292   return(EvaluateImages(images,MinEvaluateOperator,exception));
4293 }
4294 \f
4295 /*
4296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4297 %                                                                             %
4298 %                                                                             %
4299 %                                                                             %
4300 %     M o s a i c I m a g e s                                                 %
4301 %                                                                             %
4302 %                                                                             %
4303 %                                                                             %
4304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4305 %
4306 %  MosaicImages() Obsolete Function: Use MergeImageLayers() instead.
4307 %
4308 %  The format of the MosaicImage method is:
4309 %
4310 %      Image *MosaicImages(const Image *image,ExceptionInfo *exception)
4311 %
4312 %  A description of each parameter follows:
4313 %
4314 %    o image: the image list to be composited together
4315 %
4316 %    o exception: return any errors or warnings in this structure.
4317 %
4318 */
4319 MagickExport Image *MosaicImages(Image *image,ExceptionInfo *exception)
4320 {
4321   return(MergeImageLayers(image,MosaicLayer,exception));
4322 }
4323 \f
4324 /*
4325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4326 %                                                                             %
4327 %                                                                             %
4328 %                                                                             %
4329 %     O p a q u e I m a g e                                                   %
4330 %                                                                             %
4331 %                                                                             %
4332 %                                                                             %
4333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4334 %
4335 %  OpaqueImage() changes any pixel that matches color with the color
4336 %  defined by fill.
4337 %
4338 %  By default color must match a particular pixel color exactly.  However,
4339 %  in many cases two colors may differ by a small amount.  Fuzz defines
4340 %  how much tolerance is acceptable to consider two colors as the same.
4341 %  For example, set fuzz to 10 and the color red at intensities of 100 and
4342 %  102 respectively are now interpreted as the same color.
4343 %
4344 %  The format of the OpaqueImage method is:
4345 %
4346 %      MagickBooleanType OpaqueImage(Image *image,
4347 %        const PixelPacket *target,const PixelPacket fill)
4348 %
4349 %  A description of each parameter follows:
4350 %
4351 %    o image: the image.
4352 %
4353 %    o target: the RGB value of the target color.
4354 %
4355 %    o fill: the replacement color.
4356 %
4357 */
4358 MagickExport MagickBooleanType OpaqueImage(Image *image,
4359   const PixelPacket target,const PixelPacket fill)
4360 {
4361 #define OpaqueImageTag  "Opaque/Image"
4362
4363   long
4364     y;
4365
4366   MagickBooleanType
4367     proceed;
4368
4369   register long
4370     i;
4371
4372   /*
4373     Make image color opaque.
4374   */
4375   assert(image != (Image *) NULL);
4376   assert(image->signature == MagickSignature);
4377   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.1.0");
4378   if (image->debug != MagickFalse)
4379     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4380   switch (image->storage_class)
4381   {
4382     case DirectClass:
4383     default:
4384     {
4385       /*
4386         Make DirectClass image opaque.
4387       */
4388       for (y=0; y < (long) image->rows; y++)
4389       {
4390         register long
4391           x;
4392
4393         register PixelPacket
4394           *restrict q;
4395
4396         q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
4397         if (q == (PixelPacket *) NULL)
4398           break;
4399         for (x=0; x < (long) image->columns; x++)
4400         {
4401           if (IsColorSimilar(image,q,&target) != MagickFalse)
4402             *q=fill;
4403           q++;
4404         }
4405         if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
4406           break;
4407         proceed=SetImageProgress(image,OpaqueImageTag,y,image->rows);
4408         if (proceed == MagickFalse)
4409           break;
4410       }
4411       break;
4412     }
4413     case PseudoClass:
4414     {
4415       /*
4416         Make PseudoClass image opaque.
4417       */
4418       for (i=0; i < (long) image->colors; i++)
4419       {
4420         if (IsColorSimilar(image,&image->colormap[i],&target) != MagickFalse)
4421           image->colormap[i]=fill;
4422       }
4423       if (fill.opacity != OpaqueOpacity)
4424         {
4425           for (y=0; y < (long) image->rows; y++)
4426           {
4427             register long
4428               x;
4429
4430             register PixelPacket
4431               *restrict q;
4432
4433             q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
4434             if (q == (PixelPacket *) NULL)
4435               break;
4436             for (x=0; x < (long) image->columns; x++)
4437             {
4438               if (IsColorSimilar(image,q,&target) != MagickFalse)
4439                 q->opacity=fill.opacity;
4440               q++;
4441             }
4442             if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
4443               break;
4444           }
4445         }
4446       (void) SyncImage(image);
4447       break;
4448     }
4449   }
4450   if (fill.opacity != OpaqueOpacity)
4451     image->matte=MagickTrue;
4452   return(MagickTrue);
4453 }
4454 \f
4455 /*
4456 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4457 %                                                                             %
4458 %                                                                             %
4459 %                                                                             %
4460 %   O p e n C a c h e V i e w                                                 %
4461 %                                                                             %
4462 %                                                                             %
4463 %                                                                             %
4464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4465 %
4466 %  OpenCacheView() opens a view into the pixel cache, using the
4467 %  VirtualPixelMethod that is defined within the given image itself.
4468 %
4469 %  The format of the OpenCacheView method is:
4470 %
4471 %      CacheView *OpenCacheView(const Image *image)
4472 %
4473 %  A description of each parameter follows:
4474 %
4475 %    o image: the image.
4476 %
4477 */
4478 MagickExport CacheView *OpenCacheView(const Image *image)
4479 {
4480   return(AcquireCacheView(image));
4481 }
4482 \f
4483 /*
4484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4485 %                                                                             %
4486 %                                                                             %
4487 %                                                                             %
4488 %   P a i n t F l o o d f i l l I m a g e                                     %
4489 %                                                                             %
4490 %                                                                             %
4491 %                                                                             %
4492 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4493 %
4494 %  PaintFloodfill() changes the color value of any pixel that matches
4495 %  target and is an immediate neighbor.  If the method FillToBorderMethod is
4496 %  specified, the color value is changed for any neighbor pixel that does not
4497 %  match the bordercolor member of image.
4498 %
4499 %  By default target must match a particular pixel color exactly.
4500 %  However, in many cases two colors may differ by a small amount.  The
4501 %  fuzz member of image defines how much tolerance is acceptable to
4502 %  consider two colors as the same.  For example, set fuzz to 10 and the
4503 %  color red at intensities of 100 and 102 respectively are now
4504 %  interpreted as the same color for the purposes of the floodfill.
4505 %
4506 %  The format of the PaintFloodfillImage method is:
4507 %
4508 %      MagickBooleanType PaintFloodfillImage(Image *image,
4509 %        const ChannelType channel,const MagickPixelPacket target,const long x,
4510 %        const long y,const DrawInfo *draw_info,const PaintMethod method)
4511 %
4512 %  A description of each parameter follows:
4513 %
4514 %    o image: the image.
4515 %
4516 %    o channel: the channel(s).
4517 %
4518 %    o target: the RGB value of the target color.
4519 %
4520 %    o x,y: the starting location of the operation.
4521 %
4522 %    o draw_info: the draw info.
4523 %
4524 %    o method: Choose either FloodfillMethod or FillToBorderMethod.
4525 %
4526 */
4527 MagickExport MagickBooleanType PaintFloodfillImage(Image *image,
4528   const ChannelType channel,const MagickPixelPacket *target,const long x,
4529   const long y,const DrawInfo *draw_info,const PaintMethod method)
4530 {
4531   MagickBooleanType
4532     status;
4533
4534   status=FloodfillPaintImage(image,channel,draw_info,target,x,y,
4535     method == FloodfillMethod ? MagickFalse : MagickTrue);
4536   return(status);
4537 }
4538 \f
4539 /*
4540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4541 %                                                                             %
4542 %                                                                             %
4543 %     P a i n t O p a q u e I m a g e                                         %
4544 %                                                                             %
4545 %                                                                             %
4546 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4547 %
4548 %  PaintOpaqueImage() changes any pixel that matches color with the color
4549 %  defined by fill.
4550 %
4551 %  By default color must match a particular pixel color exactly.  However,
4552 %  in many cases two colors may differ by a small amount.  Fuzz defines
4553 %  how much tolerance is acceptable to consider two colors as the same.
4554 %  For example, set fuzz to 10 and the color red at intensities of 100 and
4555 %  102 respectively are now interpreted as the same color.
4556 %
4557 %  The format of the PaintOpaqueImage method is:
4558 %
4559 %      MagickBooleanType PaintOpaqueImage(Image *image,
4560 %        const PixelPacket *target,const PixelPacket *fill)
4561 %      MagickBooleanType PaintOpaqueImageChannel(Image *image,
4562 %        const ChannelType channel,const PixelPacket *target,
4563 %        const PixelPacket *fill)
4564 %
4565 %  A description of each parameter follows:
4566 %
4567 %    o image: the image.
4568 %
4569 %    o channel: the channel(s).
4570 %
4571 %    o target: the RGB value of the target color.
4572 %
4573 %    o fill: the replacement color.
4574 %
4575 */
4576
4577 MagickExport MagickBooleanType PaintOpaqueImage(Image *image,
4578   const MagickPixelPacket *target,const MagickPixelPacket *fill)
4579 {
4580   MagickBooleanType
4581     status;
4582
4583   status=OpaquePaintImageChannel(image,DefaultChannels,target,fill,MagickFalse);
4584   return(status);
4585 }
4586
4587 MagickExport MagickBooleanType PaintOpaqueImageChannel(Image *image,
4588   const ChannelType channel,const MagickPixelPacket *target,
4589   const MagickPixelPacket *fill)
4590 {
4591   return(OpaquePaintImageChannel(image,channel,target,fill,MagickFalse));
4592 }
4593 \f
4594 /*
4595 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4596 %                                                                             %
4597 %                                                                             %
4598 %                                                                             %
4599 %     P a i n t T r a n s p a r e n t I m a g e                               %
4600 %                                                                             %
4601 %                                                                             %
4602 %                                                                             %
4603 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4604 %
4605 %  PaintTransparentImage() changes the opacity value associated with any pixel
4606 %  that matches color to the value defined by opacity.
4607 %
4608 %  By default color must match a particular pixel color exactly.  However,
4609 %  in many cases two colors may differ by a small amount.  Fuzz defines
4610 %  how much tolerance is acceptable to consider two colors as the same.
4611 %  For example, set fuzz to 10 and the color red at intensities of 100 and
4612 %  102 respectively are now interpreted as the same color.
4613 %
4614 %  The format of the PaintTransparentImage method is:
4615 %
4616 %      MagickBooleanType PaintTransparentImage(Image *image,
4617 %        const MagickPixelPacket *target,const Quantum opacity)
4618 %
4619 %  A description of each parameter follows:
4620 %
4621 %    o image: the image.
4622 %
4623 %    o target: the RGB value of the target color.
4624 %
4625 %    o opacity: the replacement opacity value.
4626 %
4627 */
4628 MagickExport MagickBooleanType PaintTransparentImage(Image *image,
4629   const MagickPixelPacket *target,const Quantum opacity)
4630 {
4631   return(TransparentPaintImage(image,target,opacity,MagickFalse));
4632 }
4633 \f
4634 /*
4635 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4636 %                                                                             %
4637 %                                                                             %
4638 %                                                                             %
4639 +   P a r s e I m a g e G e o m e t r y                                       %
4640 %                                                                             %
4641 %                                                                             %
4642 %                                                                             %
4643 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4644 %
4645 %  ParseImageGeometry() is similar to GetGeometry() except the returned
4646 %  geometry is modified as determined by the meta characters:  %, !, <,
4647 %  and >.
4648 %
4649 %  The format of the ParseImageGeometry method is:
4650 %
4651 %      int ParseImageGeometry(char *geometry,long *x,long *y,
4652 %        unsigned long *width,unsigned long *height)
4653 %
4654 %  A description of each parameter follows:
4655 %
4656 %    o flags:  Method ParseImageGeometry returns a bitmask that indicates
4657 %      which of the four values were located in the geometry string.
4658 %
4659 %    o image_geometry:  Specifies a character string representing the geometry
4660 %      specification.
4661 %
4662 %    o x,y:  A pointer to an integer.  The x and y offset as determined by
4663 %      the geometry specification is returned here.
4664 %
4665 %    o width,height:  A pointer to an unsigned integer.  The width and height
4666 %      as determined by the geometry specification is returned here.
4667 %
4668 */
4669 MagickExport int ParseImageGeometry(const char *geometry,long *x,long *y,
4670   unsigned long *width,unsigned long *height)
4671 {
4672   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1");
4673   return((int) ParseMetaGeometry(geometry,x,y,width,height));
4674 }
4675 \f
4676 /*
4677 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4678 %                                                                             %
4679 %                                                                             %
4680 %                                                                             %
4681 %   P a r s e S i z e G e o m e t r y                                         %
4682 %                                                                             %
4683 %                                                                             %
4684 %                                                                             %
4685 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4686 %
4687 %  ParseSizeGeometry() returns a region as defined by the geometry string with
4688 %  respect to the image dimensions and aspect ratio.
4689 %
4690 %  The format of the ParseSizeGeometry method is:
4691 %
4692 %      MagickStatusType ParseSizeGeometry(const Image *image,
4693 %        const char *geometry,RectangeInfo *region_info)
4694 %
4695 %  A description of each parameter follows:
4696 %
4697 %    o geometry:  The geometry (e.g. 100x100+10+10).
4698 %
4699 %    o region_info: the region as defined by the geometry string.
4700 %
4701 */
4702 MagickExport MagickStatusType ParseSizeGeometry(const Image *image,
4703   const char *geometry,RectangleInfo *region_info)
4704 {
4705   MagickStatusType
4706     flags;
4707
4708   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.4.7");
4709   SetGeometry(image,region_info);
4710   flags=ParseMetaGeometry(geometry,&region_info->x,&region_info->y,
4711     &region_info->width,&region_info->height);
4712   return(flags);
4713 }
4714 \f
4715 /*
4716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4717 %                                                                             %
4718 %                                                                             %
4719 %                                                                             %
4720 %   P o p I m a g e L i s t                                                   %
4721 %                                                                             %
4722 %                                                                             %
4723 %                                                                             %
4724 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4725 %
4726 %  PopImageList() removes the last image in the list.
4727 %
4728 %  The format of the PopImageList method is:
4729 %
4730 %      Image *PopImageList(Image **images)
4731 %
4732 %  A description of each parameter follows:
4733 %
4734 %    o images: the image list.
4735 %
4736 */
4737 MagickExport Image *PopImageList(Image **images)
4738 {
4739   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
4740   return(RemoveLastImageFromList(images));
4741 }
4742 \f
4743 /*
4744 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4745 %                                                                             %
4746 %                                                                             %
4747 %                                                                             %
4748 %   P o p I m a g e P i x e l s                                               %
4749 %                                                                             %
4750 %                                                                             %
4751 %                                                                             %
4752 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4753 %
4754 %  PopImagePixels() transfers one or more pixel components from the image pixel
4755 %  cache to a user supplied buffer.  The pixels are returned in network byte
4756 %  order.  MagickTrue is returned if the pixels are successfully transferred,
4757 %  otherwise MagickFalse.
4758 %
4759 %  The format of the PopImagePixels method is:
4760 %
4761 %      size_t PopImagePixels(Image *,const QuantumType quantum,
4762 %        unsigned char *destination)
4763 %
4764 %  A description of each parameter follows:
4765 %
4766 %    o image: the image.
4767 %
4768 %    o quantum: Declare which pixel components to transfer (RGB, RGBA, etc).
4769 %
4770 %    o destination:  The components are transferred to this buffer.
4771 %
4772 */
4773 MagickExport size_t PopImagePixels(Image *image,const QuantumType quantum,
4774   unsigned char *destination)
4775 {
4776   QuantumInfo
4777     *quantum_info;
4778
4779   size_t
4780     length;
4781
4782   quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
4783   if (quantum_info == (QuantumInfo *) NULL)
4784     return(0);
4785   length=ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
4786     quantum,destination,&image->exception);
4787   quantum_info=DestroyQuantumInfo(quantum_info);
4788   return(length);
4789 }
4790 \f
4791 /*
4792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4793 %                                                                             %
4794 %                                                                             %
4795 %                                                                             %
4796 %  P o s t s c r i p t G e o m e t r y                                        %
4797 %                                                                             %
4798 %                                                                             %
4799 %                                                                             %
4800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4801 %
4802 %  PostscriptGeometry() replaces any page mneumonic with the equivalent size in
4803 %  picas.
4804 %
4805 %  The format of the PostscriptGeometry method is:
4806 %
4807 %      char *PostscriptGeometry(const char *page)
4808 %
4809 %  A description of each parameter follows.
4810 %
4811 %   o  page:  Specifies a pointer to an array of characters.
4812 %      The string is either a Postscript page name (e.g. A4) or a postscript
4813 %      page geometry (e.g. 612x792+36+36).
4814 %
4815 */
4816 MagickExport char *PostscriptGeometry(const char *page)
4817 {
4818   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1");
4819   return(GetPageGeometry(page));
4820 }
4821 \f
4822 /*
4823 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4824 %                                                                             %
4825 %                                                                             %
4826 %                                                                             %
4827 %   P u s h I m a g e L i s t                                                 %
4828 %                                                                             %
4829 %                                                                             %
4830 %                                                                             %
4831 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4832 %
4833 %  PushImageList() adds an image to the end of the list.
4834 %
4835 %  The format of the PushImageList method is:
4836 %
4837 %      unsigned int PushImageList(Image *images,const Image *image,
4838 %        ExceptionInfo *exception)
4839 %
4840 %  A description of each parameter follows:
4841 %
4842 %    o images: the image list.
4843 %
4844 %    o image: the image.
4845 %
4846 %    o exception: return any errors or warnings in this structure.
4847 %
4848 */
4849 MagickExport unsigned int PushImageList(Image **images,const Image *image,
4850   ExceptionInfo *exception)
4851 {
4852   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
4853   AppendImageToList(images,CloneImageList(image,exception));
4854   return(MagickTrue);
4855 }
4856 \f
4857 /*
4858 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4859 %                                                                             %
4860 %                                                                             %
4861 %                                                                             %
4862 %   P u s h I m a g e P i x e l s                                             %
4863 %                                                                             %
4864 %                                                                             %
4865 %                                                                             %
4866 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4867 %
4868 %  PushImagePixels() transfers one or more pixel components from a user
4869 %  supplied buffer into the image pixel cache of an image.  The pixels are
4870 %  expected in network byte order.  It returns MagickTrue if the pixels are
4871 %  successfully transferred, otherwise MagickFalse.
4872 %
4873 %  The format of the PushImagePixels method is:
4874 %
4875 %      size_t PushImagePixels(Image *image,const QuantumType quantum,
4876 %        const unsigned char *source)
4877 %
4878 %  A description of each parameter follows:
4879 %
4880 %    o image: the image.
4881 %
4882 %    o quantum: Declare which pixel components to transfer (red, green, blue,
4883 %      opacity, RGB, or RGBA).
4884 %
4885 %    o source:  The pixel components are transferred from this buffer.
4886 %
4887 */
4888 MagickExport size_t PushImagePixels(Image *image,const QuantumType quantum,
4889   const unsigned char *source)
4890 {
4891   QuantumInfo
4892     *quantum_info;
4893
4894   size_t
4895     length;
4896
4897   quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
4898   if (quantum_info == (QuantumInfo *) NULL)
4899     return(0);
4900   length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,quantum,
4901     source,&image->exception);
4902   quantum_info=DestroyQuantumInfo(quantum_info);
4903   return(length);
4904 }
4905 \f
4906 /*
4907 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4908 %                                                                             %
4909 %                                                                             %
4910 %                                                                             %
4911 %  Q u a n t i z a t i o n E r r o r                                          %
4912 %                                                                             %
4913 %                                                                             %
4914 %                                                                             %
4915 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4916 %
4917 %  QuantizationError() measures the difference between the original and
4918 %  quantized images.  This difference is the total quantization error.  The
4919 %  error is computed by summing over all pixels in an image the distance
4920 %  squared in RGB space between each reference pixel value and its quantized
4921 %  value.  These values are computed:
4922 %
4923 %    o mean_error_per_pixel:  This value is the mean error for any single
4924 %      pixel in the image.
4925 %
4926 %    o normalized_mean_square_error:  This value is the normalized mean
4927 %      quantization error for any single pixel in the image.  This distance
4928 %      measure is normalized to a range between 0 and 1.  It is independent
4929 %      of the range of red, green, and blue values in the image.
4930 %
4931 %    o normalized_maximum_square_error:  Thsi value is the normalized
4932 %      maximum quantization error for any single pixel in the image.  This
4933 %      distance measure is normalized to a range between 0 and 1.  It is
4934 %      independent of the range of red, green, and blue values in your image.
4935 %
4936 %
4937 %  The format of the QuantizationError method is:
4938 %
4939 %      unsigned int QuantizationError(Image *image)
4940 %
4941 %  A description of each parameter follows.
4942 %
4943 %    o image: Specifies a pointer to an Image structure;  returned from
4944 %      ReadImage.
4945 %
4946 */
4947 MagickExport unsigned int QuantizationError(Image *image)
4948 {
4949   if (image->debug != MagickFalse)
4950     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.3");
4951   return(GetImageQuantizeError(image));
4952 }
4953 \f
4954 /*
4955 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4956 %                                                                             %
4957 %                                                                             %
4958 %     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                   %
4959 %                                                                             %
4960 %                                                                             %
4961 %                                                                             %
4962 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4963 %
4964 %  RandomChannelThresholdImage() changes the value of individual pixels based
4965 %  on the intensity of each pixel compared to a random threshold.  The result
4966 %  is a low-contrast, two color image.
4967 %
4968 %  The format of the RandomChannelThresholdImage method is:
4969 %
4970 %      unsigned int RandomChannelThresholdImage(Image *image,
4971 %         const char *channel, const char *thresholds,
4972 %         ExceptionInfo *exception)
4973 %
4974 %  A description of each parameter follows:
4975 %
4976 %    o image: the image.
4977 %
4978 %    o channel: the channel or channels to be thresholded.
4979 %
4980 %    o thresholds: a geometry string containing LOWxHIGH thresholds.
4981 %      If the string contains 2x2, 3x3, or 4x4, then an ordered
4982 %      dither of order 2, 3, or 4 will be performed instead.
4983 %
4984 %    o exception: return any errors or warnings in this structure.
4985 %
4986 */
4987 MagickExport unsigned int RandomChannelThresholdImage(Image *image,const char
4988     *channel,const char *thresholds,ExceptionInfo *exception)
4989 {
4990 #define RandomChannelThresholdImageText  "  RandomChannelThreshold image...  "
4991
4992   double
4993     lower_threshold,
4994     upper_threshold;
4995
4996   long
4997     count,
4998     y;
4999
5000   RandomInfo
5001     *random_info;
5002
5003   static MagickRealType
5004     o2[4]={0.2f, 0.6f, 0.8f, 0.4f},
5005     o3[9]={0.1f, 0.6f, 0.3f, 0.7f, 0.5f, 0.8f, 0.4f, 0.9f, 0.2f},
5006     o4[16]={0.1f, 0.7f, 1.1f, 0.3f, 1.0f, 0.5f, 1.5f, 0.8f, 1.4f, 1.6f, 0.6f,
5007       1.2f, 0.4f, 0.9f, 1.3f, 0.2f},
5008     threshold=128;
5009
5010   unsigned long
5011     order;
5012
5013   /*
5014     Threshold image.
5015   */
5016   assert(image != (Image *) NULL);
5017   assert(image->signature == MagickSignature);
5018   if (image->debug != MagickFalse)
5019     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5020   assert(exception != (ExceptionInfo *) NULL);
5021   assert(exception->signature == MagickSignature);
5022   if (image->debug != MagickFalse)
5023     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
5024   if (thresholds == (const char *) NULL)
5025     return(MagickTrue);
5026   if (LocaleCompare(thresholds,"2x2") == 0)
5027     order=2;
5028   else
5029     if (LocaleCompare(thresholds,"3x3") == 0)
5030       order=3;
5031     else
5032       if (LocaleCompare(thresholds,"4x4") == 0)
5033         order=4;
5034       else
5035         {
5036           order=1;
5037           lower_threshold=0;
5038           upper_threshold=0;
5039           count=sscanf(thresholds,"%lf[/x%%]%lf",&lower_threshold,
5040             &upper_threshold);
5041           if (strchr(thresholds,'%') != (char *) NULL)
5042             {
5043               upper_threshold*=(.01*QuantumRange);
5044               lower_threshold*=(.01*QuantumRange);
5045             }
5046           if (count == 1)
5047             upper_threshold=(MagickRealType) QuantumRange-lower_threshold;
5048         }
5049   if (image->debug != MagickFalse)
5050     (void) LogMagickEvent(TransformEvent,GetMagickModule(),
5051       "  RandomChannelThresholdImage: channel type=%s",channel);
5052   if (image->debug != MagickFalse)
5053     (void) LogMagickEvent(TransformEvent,GetMagickModule(),
5054       "    Thresholds: %s (%fx%f)",thresholds,lower_threshold,upper_threshold);
5055   if (LocaleCompare(channel,"all") == 0 ||
5056       LocaleCompare(channel,"intensity") == 0)
5057     if (AcquireImageColormap(image,2) == MagickFalse)
5058       ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
5059         image->filename);
5060   random_info=AcquireRandomInfo();
5061   for (y=0; y < (long) image->rows; y++)
5062   {
5063     register long
5064       x;
5065
5066     register IndexPacket
5067       index,
5068       *restrict indexes;
5069
5070     register PixelPacket
5071       *restrict q;
5072
5073     q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
5074     if (q == (PixelPacket *) NULL)
5075       break;
5076     if (LocaleCompare(channel,"all") == 0 ||
5077         LocaleCompare(channel,"intensity") == 0)
5078       {
5079         indexes=GetAuthenticIndexQueue(image);
5080         for (x=0; x < (long) image->columns; x++)
5081           {
5082             MagickRealType
5083               intensity;
5084
5085             intensity=(MagickRealType) PixelIntensityToQuantum(q);
5086             if (order == 1)
5087               {
5088                 if (intensity < lower_threshold)
5089                   threshold=lower_threshold;
5090                 else if (intensity > upper_threshold)
5091                   threshold=upper_threshold;
5092                 else
5093                   threshold=(MagickRealType) (QuantumRange*
5094                     GetPseudoRandomValue(random_info));
5095               }
5096             else if (order == 2)
5097               threshold=(MagickRealType) QuantumRange*o2[(x%2)+2*(y%2)];
5098             else if (order == 3)
5099               threshold=(MagickRealType) QuantumRange*o3[(x%3)+3*(y%3)];
5100             else if (order == 4)
5101               threshold=(MagickRealType) QuantumRange*o4[(x%4)+4*(y%4)];
5102             q->red=q->green=q->blue=(Quantum) (intensity <=
5103                threshold ? 0 : QuantumRange);
5104             index=(IndexPacket) (intensity <= threshold ? 0 : 1);
5105             *indexes++=index;
5106             q->red=q->green=q->blue=image->colormap[(long) index].red;
5107             q++;
5108           }
5109       }
5110     if (LocaleCompare(channel,"opacity") == 0 ||
5111         LocaleCompare(channel,"all") == 0 ||
5112         LocaleCompare(channel,"matte") == 0)
5113       {
5114         if (image->matte != MagickFalse)
5115           for (x=0; x < (long) image->columns; x++)
5116             {
5117               if (order == 1)
5118                 {
5119                   if ((MagickRealType) q->opacity < lower_threshold)
5120                     threshold=lower_threshold;
5121                   else if ((MagickRealType) q->opacity > upper_threshold)
5122                     threshold=upper_threshold;
5123                   else
5124                     threshold=(MagickRealType) (QuantumRange*
5125                       GetPseudoRandomValue(random_info));
5126                 }
5127               else if (order == 2)
5128                 threshold=(MagickRealType) QuantumRange*o2[(x%2)+2*(y%2)];
5129               else if (order == 3)
5130                 threshold=(MagickRealType) QuantumRange*o3[(x%3)+3*(y%3)];
5131               else if (order == 4)
5132                 threshold=(MagickRealType) QuantumRange*o4[(x%4)+4*(y%4)]/1.7;
5133               q->opacity=(Quantum) ((MagickRealType) q->opacity <= threshold ?
5134                  0 : QuantumRange);
5135               q++;
5136             }
5137       }
5138     else
5139       {
5140         /* To Do: red, green, blue, cyan, magenta, yellow, black */
5141         if (LocaleCompare(channel,"intensity") != 0)
5142           ThrowBinaryException(OptionError,"UnrecognizedChannelType",
5143             image->filename);
5144       }
5145     if (SyncAuthenticPixels(image,exception) == MagickFalse)
5146       break;
5147   }
5148   random_info=DestroyRandomInfo(random_info);
5149   return(MagickTrue);
5150 }
5151 \f
5152 /*
5153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5154 %                                                                             %
5155 %                                                                             %
5156 %                                                                             %
5157 %   R e a c q u i r e M e m o r y                                             %
5158 %                                                                             %
5159 %                                                                             %
5160 %                                                                             %
5161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5162 %
5163 %  ReacquireMemory() changes the size of the memory and returns a pointer to
5164 %  the (possibly moved) block.  The contents will be unchanged up to the
5165 %  lesser of the new and old sizes.
5166 %
5167 %  The format of the ReacquireMemory method is:
5168 %
5169 %      void ReacquireMemory(void **memory,const size_t size)
5170 %
5171 %  A description of each parameter follows:
5172 %
5173 %    o memory: A pointer to a memory allocation.  On return the pointer
5174 %      may change but the contents of the original allocation will not.
5175 %
5176 %    o size: the new size of the allocated memory.
5177 %
5178 */
5179 MagickExport void ReacquireMemory(void **memory,const size_t size)
5180 {
5181   void
5182     *allocation;
5183
5184   assert(memory != (void **) NULL);
5185   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
5186   if (*memory == (void *) NULL)
5187     {
5188       *memory=AcquireMagickMemory(size);
5189       return;
5190     }
5191   allocation=realloc(*memory,size);
5192   if (allocation == (void *) NULL)
5193     *memory=RelinquishMagickMemory(*memory);
5194   *memory=allocation;
5195 }
5196 \f
5197 /*
5198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5199 %                                                                             %
5200 %                                                                             %
5201 %                                                                             %
5202 %     R e c o l o r I m a g e                                                 %
5203 %                                                                             %
5204 %                                                                             %
5205 %                                                                             %
5206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5207 %
5208 %  RecolorImage() apply color transformation to an image. The method permits
5209 %  saturation changes, hue rotation, luminance to alpha, and various other
5210 %  effects.  Although variable-sized transformation matrices can be used,
5211 %  typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
5212 %  (or RGBA with offsets).  The matrix is similar to those used by Adobe Flash
5213 %  except offsets are in column 6 rather than 5 (in support of CMYKA images)
5214 %  and offsets are normalized (divide Flash offset by 255).
5215 %
5216 %  The format of the RecolorImage method is:
5217 %
5218 %      Image *RecolorImage(const Image *image,const unsigned long order,
5219 %        const double *color_matrix,ExceptionInfo *exception)
5220 %
5221 %  A description of each parameter follows:
5222 %
5223 %    o image: the image.
5224 %
5225 %    o order: the number of columns and rows in the recolor matrix.
5226 %
5227 %    o color_matrix: An array of double representing the recolor matrix.
5228 %
5229 %    o exception: return any errors or warnings in this structure.
5230 %
5231 */
5232 MagickExport Image *RecolorImage(const Image *image,const unsigned long order,
5233   const double *color_matrix,ExceptionInfo *exception)
5234 {
5235   KernelInfo
5236     *kernel_info;
5237
5238   Image
5239     *recolor_image;
5240
5241   kernel_info=AcquireKernelInfo("1");
5242   if (kernel_info == (KernelInfo *) NULL)
5243     return((Image *) NULL);
5244   kernel_info->width=order;
5245   kernel_info->height=order;
5246   kernel_info->values=(double *) color_matrix;
5247   recolor_image=ColorMatrixImage(image,kernel_info,exception);
5248   kernel_info->values=(double *) NULL;
5249   kernel_info=DestroyKernelInfo(kernel_info);
5250   return(recolor_image);
5251 }
5252 \f
5253 /*
5254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5255 %                                                                             %
5256 %                                                                             %
5257 %                                                                             %
5258 %   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                     %
5259 %                                                                             %
5260 %                                                                             %
5261 %                                                                             %
5262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5263 %
5264 %  ResetImageAttributeIterator() resets the image attributes iterator.  Use it
5265 %  in conjunction with GetNextImageAttribute() to iterate over all the values
5266 %  associated with an image.
5267 %
5268 %  The format of the ResetImageAttributeIterator method is:
5269 %
5270 %      ResetImageAttributeIterator(const ImageInfo *image)
5271 %
5272 %  A description of each parameter follows:
5273 %
5274 %    o image: the image.
5275 %
5276 */
5277 MagickExport void ResetImageAttributeIterator(const Image *image)
5278 {
5279   ResetImagePropertyIterator(image);
5280 }
5281 \f
5282 /*
5283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5284 %                                                                             %
5285 %                                                                             %
5286 %                                                                             %
5287 %   S e t C a c h e V i e w P i x e l s                                       %
5288 %                                                                             %
5289 %                                                                             %
5290 %                                                                             %
5291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5292 %
5293 %  SetCacheViewPixels() gets pixels from the in-memory or disk pixel cache as
5294 %  defined by the geometry parameters.   A pointer to the pixels is returned
5295 %  if the pixels are transferred, otherwise a NULL is returned.
5296 %
5297 %  The format of the SetCacheViewPixels method is:
5298 %
5299 %      PixelPacket *SetCacheViewPixels(CacheView *cache_view,const long x,
5300 %        const long y,const unsigned long columns,const unsigned long rows)
5301 %
5302 %  A description of each parameter follows:
5303 %
5304 %    o cache_view: the cache view.
5305 %
5306 %    o x,y,columns,rows:  These values define the perimeter of a region of
5307 %      pixels.
5308 %
5309 */
5310 MagickExport PixelPacket *SetCacheViewPixels(CacheView *cache_view,const long x,
5311   const long y,const unsigned long columns,const unsigned long rows)
5312 {
5313   PixelPacket
5314     *pixels;
5315
5316   pixels=QueueCacheViewAuthenticPixels(cache_view,x,y,columns,rows,
5317     GetCacheViewException(cache_view));
5318   return(pixels);
5319 }
5320 \f
5321 /*
5322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5323 %                                                                             %
5324 %                                                                             %
5325 %                                                                             %
5326 +   S e t C a c h e T h e s h o l d                                           %
5327 %                                                                             %
5328 %                                                                             %
5329 %                                                                             %
5330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5331 %
5332 %  SetCacheThreshold() sets the amount of free memory allocated for the pixel
5333 %  cache.  Once this threshold is exceeded, all subsequent pixels cache
5334 %  operations are to/from disk.
5335 %
5336 %  The format of the SetCacheThreshold() method is:
5337 %
5338 %      void SetCacheThreshold(const size_t threshold)
5339 %
5340 %  A description of each parameter follows:
5341 %
5342 %    o threshold: the number of megabytes of memory available to the pixel
5343 %      cache.
5344 %
5345 */
5346 MagickExport void SetCacheThreshold(const unsigned long size)
5347 {
5348   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1");
5349   (void) SetMagickResourceLimit(MemoryResource,size*1024*1024);
5350   (void) SetMagickResourceLimit(MapResource,2*size*1024*1024);
5351 }
5352 \f
5353 /*
5354 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5355 %                                                                             %
5356 %                                                                             %
5357 %                                                                             %
5358 %   S e t E x c e p t i o n I n f o                                           %
5359 %                                                                             %
5360 %                                                                             %
5361 %                                                                             %
5362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5363 %
5364 %  SetExceptionInfo() sets the exception severity.
5365 %
5366 %  The format of the SetExceptionInfo method is:
5367 %
5368 %      MagickBooleanType SetExceptionInfo(ExceptionInfo *exception,
5369 %        ExceptionType severity)
5370 %
5371 %  A description of each parameter follows:
5372 %
5373 %    o exception: the exception info.
5374 %
5375 %    o severity: the exception severity.
5376 %
5377 */
5378 MagickExport MagickBooleanType SetExceptionInfo(ExceptionInfo *exception,
5379   ExceptionType severity)
5380 {
5381   assert(exception != (ExceptionInfo *) NULL);
5382   ClearMagickException(exception);
5383   exception->severity=severity;
5384   return(MagickTrue);
5385 }
5386 \f
5387 /*
5388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5389 %                                                                             %
5390 %                                                                             %
5391 %                                                                             %
5392 %   S e t I m a g e                                                           %
5393 %                                                                             %
5394 %                                                                             %
5395 %                                                                             %
5396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5397 %
5398 %  SetImage() sets the red, green, and blue components of each pixel to
5399 %  the image background color and the opacity component to the specified
5400 %  level of transparency.  The background color is defined by the
5401 %  background_color member of the image.
5402 %
5403 %  The format of the SetImage method is:
5404 %
5405 %      void SetImage(Image *image,const Quantum opacity)
5406 %
5407 %  A description of each parameter follows:
5408 %
5409 %    o image: the image.
5410 %
5411 %    o opacity: Set each pixel to this level of transparency.
5412 %
5413 */
5414 MagickExport void SetImage(Image *image,const Quantum opacity)
5415 {
5416   long
5417     y;
5418
5419   PixelPacket
5420     background_color;
5421
5422   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.0");
5423   assert(image != (Image *) NULL);
5424   if (image->debug != MagickFalse)
5425     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5426   assert(image->signature == MagickSignature);
5427   background_color=image->background_color;
5428   if (opacity != OpaqueOpacity)
5429     background_color.opacity=opacity;
5430   if (background_color.opacity != OpaqueOpacity)
5431     {
5432       (void) SetImageStorageClass(image,DirectClass);
5433       image->matte=MagickTrue;
5434     }
5435   if ((image->storage_class == PseudoClass) ||
5436       (image->colorspace == CMYKColorspace))
5437     {
5438       /*
5439         Set colormapped or CMYK image.
5440       */
5441       for (y=0; y < (long) image->rows; y++)
5442       {
5443         register IndexPacket
5444           *restrict indexes;
5445
5446         register long
5447           x;
5448
5449         register PixelPacket
5450           *restrict q;
5451
5452         q=QueueAuthenticPixels(image,0,y,image->columns,1,&image->exception);
5453         if (q == (PixelPacket *) NULL)
5454           break;
5455         for (x=0; x < (long) image->columns; x++)
5456           *q++=background_color;
5457         indexes=GetAuthenticIndexQueue(image);
5458         for (x=0; x < (long) image->columns; x++)
5459           indexes[x]=(IndexPacket) 0;
5460         if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
5461           break;
5462       }
5463       return;
5464     }
5465   /*
5466     Set DirectClass image.
5467   */
5468   for (y=0; y < (long) image->rows; y++)
5469   {
5470     register long
5471       x;
5472
5473     register PixelPacket
5474       *restrict q;
5475
5476     q=QueueAuthenticPixels(image,0,y,image->columns,1,&image->exception);
5477     if (q == (PixelPacket *) NULL)
5478       break;
5479     for (x=0; x < (long) image->columns; x++)
5480       *q++=background_color;
5481     if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
5482       break;
5483   }
5484 }
5485 \f
5486 /*
5487 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5488 %                                                                             %
5489 %                                                                             %
5490 %                                                                             %
5491 %   S e t I m a g e A t t r i b u t e                                         %
5492 %                                                                             %
5493 %                                                                             %
5494 %                                                                             %
5495 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5496 %
5497 %  SetImageAttribute() searches the list of image attributes and replaces the
5498 %  attribute value.  If it is not found in the list, the attribute name
5499 %  and value is added to the list.
5500 %
5501 %  The format of the SetImageAttribute method is:
5502 %
5503 %       MagickBooleanType SetImageAttribute(Image *image,const char *key,
5504 %         const char *value)
5505 %
5506 %  A description of each parameter follows:
5507 %
5508 %    o image: the image.
5509 %
5510 %    o key: the key.
5511 %
5512 %    o value: the value.
5513 %
5514 */
5515 MagickExport MagickBooleanType SetImageAttribute(Image *image,const char *key,
5516   const char *value)
5517 {
5518   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.3.1");
5519   return(SetImageProperty(image,key,value));
5520 }
5521 \f
5522 /*
5523 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5524 %                                                                             %
5525 %                                                                             %
5526 %                                                                             %
5527 %   S e t I m a g e L i s t                                                   %
5528 %                                                                             %
5529 %                                                                             %
5530 %                                                                             %
5531 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5532 %
5533 %  SetImageList() inserts an image into the list at the specified position.
5534 %
5535 %  The format of the SetImageList method is:
5536 %
5537 %      unsigned int SetImageList(Image *images,const Image *image,
5538 %        const long offset,ExceptionInfo *exception)
5539 %
5540 %  A description of each parameter follows:
5541 %
5542 %    o images: the image list.
5543 %
5544 %    o image: the image.
5545 %
5546 %    o offset: the position within the list.
5547 %
5548 %    o exception: return any errors or warnings in this structure.
5549 %
5550 */
5551 MagickExport unsigned int SetImageList(Image **images,const Image *image,
5552   const long offset,ExceptionInfo *exception)
5553 {
5554   Image
5555     *clone;
5556
5557   register long
5558     i;
5559
5560   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
5561   clone=CloneImageList(image,exception);
5562   while (GetPreviousImageInList(*images) != (Image *) NULL)
5563     (*images)=GetPreviousImageInList(*images);
5564   for (i=0; i < offset; i++)
5565   {
5566     if (GetNextImageInList(*images) == (Image *) NULL)
5567       return(MagickFalse);
5568     (*images)=GetNextImageInList(*images);
5569   }
5570   InsertImageInList(images,clone);
5571   return(MagickTrue);
5572 }
5573 \f
5574 /*
5575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5576 %                                                                             %
5577 %                                                                             %
5578 %                                                                             %
5579 %   S e t I m a g e P i x e l s                                               %
5580 %                                                                             %
5581 %                                                                             %
5582 %                                                                             %
5583 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5584 %
5585 %  SetImagePixels() queues a mutable pixel region.
5586 %  If the region is successfully intialized a pointer to a PixelPacket
5587 %  array representing the region is returned, otherwise NULL is returned.
5588 %  The returned pointer may point to a temporary working buffer for the
5589 %  pixels or it may point to the final location of the pixels in memory.
5590 %
5591 %  Write-only access means that any existing pixel values corresponding to
5592 %  the region are ignored.  This useful while the initial image is being
5593 %  created from scratch, or if the existing pixel values are to be
5594 %  completely replaced without need to refer to their pre-existing values.
5595 %  The application is free to read and write the pixel buffer returned by
5596 %  SetImagePixels() any way it pleases. SetImagePixels() does not initialize
5597 %  the pixel array values. Initializing pixel array values is the
5598 %  application's responsibility.
5599 %
5600 %  Performance is maximized if the selected region is part of one row, or
5601 %  one or more full rows, since then there is opportunity to access the
5602 %  pixels in-place (without a copy) if the image is in RAM, or in a
5603 %  memory-mapped file. The returned pointer should *never* be deallocated
5604 %  by the user.
5605 %
5606 %  Pixels accessed via the returned pointer represent a simple array of type
5607 %  PixelPacket. If the image type is CMYK or the storage class is PseudoClass,
5608 %  call GetAuthenticIndexQueue() after invoking GetAuthenticPixels() to obtain
5609 %  the black color component or the colormap indexes (of type IndexPacket)
5610 %  corresponding to the region.  Once the PixelPacket (and/or IndexPacket)
5611 %  array has been updated, the changes must be saved back to the underlying
5612 %  image using SyncAuthenticPixels() or they may be lost.
5613 %
5614 %  The format of the SetImagePixels() method is:
5615 %
5616 %      PixelPacket *SetImagePixels(Image *image,const long x,const long y,
5617 %        const unsigned long columns,const unsigned long rows)
5618 %
5619 %  A description of each parameter follows:
5620 %
5621 %    o pixels: SetImagePixels returns a pointer to the pixels if they are
5622 %      transferred, otherwise a NULL is returned.
5623 %
5624 %    o image: the image.
5625 %
5626 %    o x,y,columns,rows:  These values define the perimeter of a region of
5627 %      pixels.
5628 %
5629 */
5630 MagickExport PixelPacket *SetImagePixels(Image *image,const long x,const long y,
5631   const unsigned long columns,const unsigned long rows)
5632 {
5633   return(QueueAuthenticPixels(image,x,y,columns,rows,&image->exception));
5634 }
5635 \f
5636 /*
5637 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5638 %                                                                             %
5639 %                                                                             %
5640 %                                                                             %
5641 %   S e t M a g i c k R e g i s t r y                                         %
5642 %                                                                             %
5643 %                                                                             %
5644 %                                                                             %
5645 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5646 %
5647 %  SetMagickRegistry() sets a blob into the registry and returns a unique ID.
5648 %  If an error occurs, -1 is returned.
5649 %
5650 %  The format of the SetMagickRegistry method is:
5651 %
5652 %      long SetMagickRegistry(const RegistryType type,const void *blob,
5653 %        const size_t length,ExceptionInfo *exception)
5654 %
5655 %  A description of each parameter follows:
5656 %
5657 %    o type: the registry type.
5658 %
5659 %    o blob: the address of a Binary Large OBject.
5660 %
5661 %    o length: For a registry type of ImageRegistryType use sizeof(Image)
5662 %      otherise the blob length in number of bytes.
5663 %
5664 %    o exception: return any errors or warnings in this structure.
5665 %
5666 */
5667 MagickExport long SetMagickRegistry(const RegistryType type,const void *blob,
5668   const size_t magick_unused(length),ExceptionInfo *exception)
5669 {
5670   char
5671     key[MaxTextExtent];
5672
5673   MagickBooleanType
5674     status;
5675
5676   static long
5677     id = 0;
5678
5679   (void) FormatMagickString(key,MaxTextExtent,"%ld\n",id);
5680   status=SetImageRegistry(type,key,blob,exception);
5681   if (status == MagickFalse)
5682     return(-1);
5683   return(id++);
5684 }
5685 \f
5686 /*
5687 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5688 %                                                                             %
5689 %                                                                             %
5690 %                                                                             %
5691 %   S e t M o n i t o r H a n d l e r                                         %
5692 %                                                                             %
5693 %                                                                             %
5694 %                                                                             %
5695 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5696 %
5697 %  SetMonitorHandler() sets the monitor handler to the specified method
5698 %  and returns the previous monitor handler.
5699 %
5700 %  The format of the SetMonitorHandler method is:
5701 %
5702 %      MonitorHandler SetMonitorHandler(MonitorHandler handler)
5703 %
5704 %  A description of each parameter follows:
5705 %
5706 %    o handler: Specifies a pointer to a method to handle monitors.
5707 %
5708 */
5709
5710 MagickExport MonitorHandler GetMonitorHandler(void)
5711 {
5712   return(monitor_handler);
5713 }
5714
5715 MagickExport MonitorHandler SetMonitorHandler(MonitorHandler handler)
5716 {
5717   MonitorHandler
5718     previous_handler;
5719
5720   previous_handler=monitor_handler;
5721   monitor_handler=handler;
5722   return(previous_handler);
5723 }
5724 \f
5725 /*
5726 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5727 %                                                                             %
5728 %                                                                             %
5729 %                                                                             %
5730 %   S h i f t I m a g e L i s t                                               %
5731 %                                                                             %
5732 %                                                                             %
5733 %                                                                             %
5734 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5735 %
5736 %  ShiftImageList() removes an image from the beginning of the list.
5737 %
5738 %  The format of the ShiftImageList method is:
5739 %
5740 %      Image *ShiftImageList(Image **images)
5741 %
5742 %  A description of each parameter follows:
5743 %
5744 %    o images: the image list.
5745 %
5746 */
5747 MagickExport Image *ShiftImageList(Image **images)
5748 {
5749   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
5750   return(RemoveFirstImageFromList(images));
5751 }
5752 \f
5753 /*
5754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5755 %                                                                             %
5756 %                                                                             %
5757 %                                                                             %
5758 +  S i z e B l o b                                                            %
5759 %                                                                             %
5760 %                                                                             %
5761 %                                                                             %
5762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5763 %
5764 %  SizeBlob() returns the current length of the image file or blob.
5765 %
5766 %  The format of the SizeBlob method is:
5767 %
5768 %      off_t SizeBlob(Image *image)
5769 %
5770 %  A description of each parameter follows:
5771 %
5772 %    o size:  Method SizeBlob returns the current length of the image file
5773 %      or blob.
5774 %
5775 %    o image: the image.
5776 %
5777 */
5778 MagickExport MagickOffsetType SizeBlob(Image *image)
5779 {
5780   if (image->debug != MagickFalse)
5781     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.4.3");
5782   return((MagickOffsetType) GetBlobSize(image));
5783 }
5784 \f
5785 /*
5786 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5787 %                                                                             %
5788 %                                                                             %
5789 %                                                                             %
5790 %   S p l i c e I m a g e L i s t                                             %
5791 %                                                                             %
5792 %                                                                             %
5793 %                                                                             %
5794 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5795 %
5796 %  SpliceImageList() removes the images designated by offset and length from
5797 %  the list and replaces them with the specified list.
5798 %
5799 %  The format of the SpliceImageList method is:
5800 %
5801 %      Image *SpliceImageList(Image *images,const long offset,
5802 %        const unsigned long length,const Image *splices,
5803 %        ExceptionInfo *exception)
5804 %
5805 %  A description of each parameter follows:
5806 %
5807 %    o images: the image list.
5808 %
5809 %    o offset: the position within the list.
5810 %
5811 %    o length: the length of the image list to remove.
5812 %
5813 %    o splice: Replace the removed image list with this list.
5814 %
5815 %    o exception: return any errors or warnings in this structure.
5816 %
5817 */
5818 MagickExport Image *SpliceImageList(Image *images,const long offset,
5819   const unsigned long length,const Image *splices,ExceptionInfo *exception)
5820 {
5821   Image
5822     *clone;
5823
5824   register long
5825     i;
5826
5827   if (images->debug != MagickFalse)
5828     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
5829   clone=CloneImageList(splices,exception);
5830   while (GetPreviousImageInList(images) != (Image *) NULL)
5831     images=GetPreviousImageInList(images);
5832   for (i=0; i < offset; i++)
5833   {
5834     if (GetNextImageInList(images) == (Image *) NULL)
5835       return((Image *) NULL);
5836     images=GetNextImageInList(images);
5837   }
5838   (void) SpliceImageIntoList(&images,length,clone);
5839   return(images);
5840 }
5841 \f
5842 /*
5843 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5844 %                                                                             %
5845 %                                                                             %
5846 %                                                                             %
5847 %   S t r i p                                                                 %
5848 %                                                                             %
5849 %                                                                             %
5850 %                                                                             %
5851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5852 %
5853 %  Strip() strips any whitespace or quotes from the beginning and end of a
5854 %  string of characters.
5855 %
5856 %  The format of the Strip method is:
5857 %
5858 %      void Strip(char *message)
5859 %
5860 %  A description of each parameter follows:
5861 %
5862 %    o message: Specifies an array of characters.
5863 %
5864 */
5865 MagickExport void Strip(char *message)
5866 {
5867   register char
5868     *p,
5869     *q;
5870
5871   assert(message != (char *) NULL);
5872   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
5873   if (*message == '\0')
5874     return;
5875   if (strlen(message) == 1)
5876     return;
5877   p=message;
5878   while (isspace((int) ((unsigned char) *p)) != 0)
5879     p++;
5880   if ((*p == '\'') || (*p == '"'))
5881     p++;
5882   q=message+strlen(message)-1;
5883   while ((isspace((int) ((unsigned char) *q)) != 0) && (q > p))
5884     q--;
5885   if (q > p)
5886     if ((*q == '\'') || (*q == '"'))
5887       q--;
5888   (void) CopyMagickMemory(message,p,(size_t) (q-p+1));
5889   message[q-p+1]='\0';
5890 }
5891 \f
5892 /*
5893 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5894 %                                                                             %
5895 %                                                                             %
5896 %                                                                             %
5897 %   S y n c C a c h e V i e w                                                 %
5898 %                                                                             %
5899 %                                                                             %
5900 %                                                                             %
5901 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5902 %
5903 %  SyncCacheView() saves the cache view pixels to the in-memory or disk
5904 %  cache.  It returns MagickTrue if the pixel region is synced, otherwise
5905 %  MagickFalse.
5906 %
5907 %  The format of the SyncCacheView method is:
5908 %
5909 %      MagickBooleanType SyncCacheView(CacheView *cache_view)
5910 %
5911 %  A description of each parameter follows:
5912 %
5913 %    o cache_view: the cache view.
5914 %
5915 */
5916 MagickExport MagickBooleanType SyncCacheView(CacheView *cache_view)
5917 {
5918   MagickBooleanType
5919     status;
5920
5921   status=SyncCacheViewAuthenticPixels(cache_view,
5922     GetCacheViewException(cache_view));
5923   return(status);
5924 }
5925 \f
5926 /*
5927 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5928 %                                                                             %
5929 %                                                                             %
5930 %                                                                             %
5931 %   S y n c C a c h e V i e w P i x e l s                                     %
5932 %                                                                             %
5933 %                                                                             %
5934 %                                                                             %
5935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5936 %
5937 %  SyncCacheViewPixels() saves the cache view pixels to the in-memory
5938 %  or disk cache.  It returns MagickTrue if the pixel region is flushed,
5939 %  otherwise MagickFalse.
5940 %
5941 %  The format of the SyncCacheViewPixels method is:
5942 %
5943 %      MagickBooleanType SyncCacheViewPixels(CacheView *cache_view)
5944 %
5945 %  A description of each parameter follows:
5946 %
5947 %    o cache_view: the cache view.
5948 %
5949 %    o exception: return any errors or warnings in this structure.
5950 %
5951 */
5952 MagickExport MagickBooleanType SyncCacheViewPixels(CacheView *cache_view)
5953 {
5954   MagickBooleanType
5955     status;
5956
5957   status=SyncCacheViewAuthenticPixels(cache_view,
5958     GetCacheViewException(cache_view));
5959   return(status);
5960 }
5961 \f
5962 /*
5963 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5964 %                                                                             %
5965 %                                                                             %
5966 %                                                                             %
5967 %   S y n c I m a g e P i x e l s                                             %
5968 %                                                                             %
5969 %                                                                             %
5970 %                                                                             %
5971 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5972 %
5973 %  SyncImagePixels() saves the image pixels to the in-memory or disk cache.
5974 %  The method returns MagickTrue if the pixel region is synced, otherwise
5975 %  MagickFalse.
5976 %
5977 %  The format of the SyncImagePixels() method is:
5978 %
5979 %      MagickBooleanType SyncImagePixels(Image *image)
5980 %
5981 %  A description of each parameter follows:
5982 %
5983 %    o image: the image.
5984 %
5985 */
5986 MagickExport MagickBooleanType SyncImagePixels(Image *image)
5987 {
5988   return(SyncAuthenticPixels(image,&image->exception));
5989 }
5990 \f
5991 /*
5992 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5993 %                                                                             %
5994 %                                                                             %
5995 %                                                                             %
5996 %  T e m p o r a r y F i l e n a m e                                          %
5997 %                                                                             %
5998 %                                                                             %
5999 %                                                                             %
6000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6001 %
6002 %  TemporaryFilename() replaces the contents of path by a unique path name.
6003 %
6004 %  The format of the TemporaryFilename method is:
6005 %
6006 %      void TemporaryFilename(char *path)
6007 %
6008 %  A description of each parameter follows.
6009 %
6010 %   o  path:  Specifies a pointer to an array of characters.  The unique path
6011 %      name is returned in this array.
6012 %
6013 */
6014 MagickExport void TemporaryFilename(char *path)
6015 {
6016   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.6");
6017   (void) AcquireUniqueFilename(path);
6018   (void) RelinquishUniqueFileResource(path);
6019 }
6020 \f
6021 /*
6022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6023 %                                                                             %
6024 %                                                                             %
6025 %                                                                             %
6026 %     T h r e s h o l d I m a g e                                             %
6027 %                                                                             %
6028 %                                                                             %
6029 %                                                                             %
6030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6031 %
6032 %  ThresholdImage() changes the value of individual pixels based on
6033 %  the intensity of each pixel compared to threshold.  The result is a
6034 %  high-contrast, two color image.
6035 %
6036 %  The format of the ThresholdImage method is:
6037 %
6038 %      unsigned int ThresholdImage(Image *image,const double threshold)
6039 %
6040 %  A description of each parameter follows:
6041 %
6042 %    o image: the image.
6043 %
6044 %    o threshold: Define the threshold value
6045 %
6046 */
6047 MagickExport unsigned int ThresholdImage(Image *image,const double threshold)
6048 {
6049 #define ThresholdImageTag  "Threshold/Image"
6050
6051   IndexPacket
6052     index;
6053
6054   long
6055     y;
6056
6057   /*
6058     Threshold image.
6059   */
6060   assert(image != (Image *) NULL);
6061   assert(image->signature == MagickSignature);
6062   if (image->debug != MagickFalse)
6063     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6064   if (image->debug != MagickFalse)
6065     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
6066   if (!AcquireImageColormap(image,2))
6067     ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
6068       "UnableToThresholdImage");
6069   for (y=0; y < (long) image->rows; y++)
6070   {
6071     register IndexPacket
6072       *restrict indexes;
6073
6074     register long
6075       x;
6076
6077     register PixelPacket
6078       *restrict q;
6079
6080     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
6081     if (q == (PixelPacket *) NULL)
6082       break;
6083     indexes=GetAuthenticIndexQueue(image);
6084     for (x=0; x < (long) image->columns; x++)
6085     {
6086       index=(IndexPacket) ((MagickRealType)
6087         PixelIntensityToQuantum(q) <= threshold ? 0 : 1);
6088       indexes[x]=index;
6089       q->red=image->colormap[(long) index].red;
6090       q->green=image->colormap[(long) index].green;
6091       q->blue=image->colormap[(long) index].blue;
6092       q++;
6093     }
6094     if (!SyncAuthenticPixels(image,&image->exception))
6095       break;
6096   }
6097   return(MagickTrue);
6098 }
6099 \f
6100 /*
6101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6102 %                                                                             %
6103 %                                                                             %
6104 %                                                                             %
6105 %     T h r e s h o l d I m a g e C h a n n e l                               %
6106 %                                                                             %
6107 %                                                                             %
6108 %                                                                             %
6109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6110 %
6111 %  ThresholdImageChannel() changes the value of individual pixels based on
6112 %  the intensity of each pixel channel.  The result is a high-contrast image.
6113 %
6114 %  The format of the ThresholdImageChannel method is:
6115 %
6116 %      unsigned int ThresholdImageChannel(Image *image,const char *threshold)
6117 %
6118 %  A description of each parameter follows:
6119 %
6120 %    o image: the image.
6121 %
6122 %    o threshold: define the threshold values.
6123 %
6124 */
6125 MagickExport unsigned int ThresholdImageChannel(Image *image,
6126   const char *threshold)
6127 {
6128 #define ThresholdImageTag  "Threshold/Image"
6129
6130   MagickPixelPacket
6131     pixel;
6132
6133   GeometryInfo
6134     geometry_info;
6135
6136   IndexPacket
6137     index;
6138
6139   long
6140     y;
6141
6142   unsigned int
6143     flags;
6144
6145   /*
6146     Threshold image.
6147   */
6148   assert(image != (Image *) NULL);
6149   assert(image->signature == MagickSignature);
6150   if (image->debug != MagickFalse)
6151     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6152   if (threshold == (const char *) NULL)
6153     return(MagickTrue);
6154   if (SetImageStorageClass(image,DirectClass) == MagickFalse)
6155     return(MagickFalse);
6156   flags=ParseGeometry(threshold,&geometry_info);
6157   pixel.red=geometry_info.rho;
6158   if (flags & SigmaValue)
6159     pixel.green=geometry_info.sigma;
6160   else
6161     pixel.green=pixel.red;
6162   if (flags & XiValue)
6163     pixel.blue=geometry_info.xi;
6164   else
6165     pixel.blue=pixel.red;
6166   if (flags & PsiValue)
6167     pixel.opacity=geometry_info.psi;
6168   else
6169     pixel.opacity=(MagickRealType) OpaqueOpacity;
6170   if (flags & PercentValue)
6171     {
6172       pixel.red*=QuantumRange/100.0f;
6173       pixel.green*=QuantumRange/100.0f;
6174       pixel.blue*=QuantumRange/100.0f;
6175       pixel.opacity*=QuantumRange/100.0f;
6176     }
6177   if (!(flags & SigmaValue))
6178     {
6179       if (!AcquireImageColormap(image,2))
6180         ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
6181           "UnableToThresholdImage");
6182       if (pixel.red == 0)
6183         (void) GetImageDynamicThreshold(image,2.0,2.0,&pixel,&image->exception);
6184     }
6185   for (y=0; y < (long) image->rows; y++)
6186   {
6187     register IndexPacket
6188       *restrict indexes;
6189
6190     register long
6191       x;
6192
6193     register PixelPacket
6194       *restrict q;
6195
6196     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
6197     if (q == (PixelPacket *) NULL)
6198       break;
6199     indexes=GetAuthenticIndexQueue(image);
6200     if (IsMagickGray(&pixel) != MagickFalse)
6201       for (x=0; x < (long) image->columns; x++)
6202       {
6203         index=(IndexPacket) ((MagickRealType)
6204           PixelIntensityToQuantum(q) <= pixel.red ? 0 : 1);
6205         indexes[x]=index;
6206         q->red=image->colormap[(long) index].red;
6207         q->green=image->colormap[(long) index].green;
6208         q->blue=image->colormap[(long) index].blue;
6209         q++;
6210       }
6211     else
6212       for (x=0; x < (long) image->columns; x++)
6213       {
6214         q->red=(Quantum) ((MagickRealType)
6215           q->red <= pixel.red ? 0 : QuantumRange);
6216         q->green=(Quantum) ((MagickRealType)
6217           q->green <= pixel.green ? 0 : QuantumRange);
6218         q->blue=(Quantum) ((MagickRealType)
6219           q->blue <= pixel.blue ? 0 : QuantumRange);
6220         q->opacity=(Quantum) ((MagickRealType)
6221           q->opacity <= pixel.opacity ? 0 : QuantumRange);
6222         q++;
6223       }
6224     if (!SyncAuthenticPixels(image,&image->exception))
6225       break;
6226   }
6227   return(MagickTrue);
6228 }
6229 \f
6230 /*
6231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6232 %                                                                              %
6233 %                                                                              %
6234 %                                                                              %
6235 +     T r a n s f o r m C o l o r s p a c e                                    %
6236 %                                                                              %
6237 %                                                                              %
6238 %                                                                              %
6239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6240 %
6241 %  TransformColorspace() converts the image to a specified colorspace.
6242 %  If the image is already in the requested colorspace, no work is performed.
6243 %  Note that the current colorspace is stored in the image colorspace member.
6244 %  The transformation matrices are not necessarily the standard ones: the
6245 %  weights are rescaled to normalize the range of the transformed values to
6246 %  be [0..QuantumRange].
6247 %
6248 %  The format of the TransformColorspace method is:
6249 %
6250 %      unsigned int (void) TransformColorspace(Image *image,
6251 %        const ColorspaceType colorspace)
6252 %
6253 %  A description of each parameter follows:
6254 %
6255 %    o image: the image to transform
6256 %
6257 %    o colorspace: the desired colorspace.
6258 %
6259 */
6260 MagickExport unsigned int TransformColorspace(Image *image,
6261   const ColorspaceType colorspace)
6262 {
6263   assert(image != (Image *) NULL);
6264   assert(image->signature == MagickSignature);
6265   if (image->debug != MagickFalse)
6266     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.6");
6267   return(TransformImageColorspace(image,colorspace));
6268 }
6269 \f
6270 /*
6271 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6272 %                                                                             %
6273 %                                                                             %
6274 %                                                                             %
6275 %   T r a n s f o r m H S L                                                   %
6276 %                                                                             %
6277 %                                                                             %
6278 %                                                                             %
6279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6280 %
6281 %  TransformHSL() converts a (red, green, blue) to a (hue, saturation,
6282 %  lightness) triple.
6283 %
6284 %  The format of the TransformHSL method is:
6285 %
6286 %      void TransformHSL(const Quantum red,const Quantum green,
6287 %        const Quantum blue,double *hue,double *saturation,double *lightness)
6288 %
6289 %  A description of each parameter follows:
6290 %
6291 %    o red, green, blue: A Quantum value representing the red, green, and
6292 %      blue component of a pixel..
6293 %
6294 %    o hue, saturation, lightness: A pointer to a double value representing a
6295 %      component of the HSL color space.
6296 %
6297 */
6298
6299 static inline double MagickMin(const double x,const double y)
6300 {
6301   if (x < y)
6302     return(x);
6303   return(y);
6304 }
6305
6306 MagickExport void TransformHSL(const Quantum red,const Quantum green,
6307   const Quantum blue,double *hue,double *saturation,double *lightness)
6308 {
6309   MagickRealType
6310     b,
6311     delta,
6312     g,
6313     max,
6314     min,
6315     r;
6316
6317   /*
6318     Convert RGB to HSL colorspace.
6319   */
6320   assert(hue != (double *) NULL);
6321   assert(saturation != (double *) NULL);
6322   assert(lightness != (double *) NULL);
6323   r=QuantumScale*red;
6324   g=QuantumScale*green;
6325   b=QuantumScale*blue;
6326   max=MagickMax(r,MagickMax(g,b));
6327   min=MagickMin(r,MagickMin(g,b));
6328   *hue=0.0;
6329   *saturation=0.0;
6330   *lightness=(double) ((min+max)/2.0);
6331   delta=max-min;
6332   if (delta == 0.0)
6333     return;
6334   *saturation=(double) (delta/((*lightness < 0.5) ? (min+max) :
6335     (2.0-max-min)));
6336   if (r == max)
6337     *hue=(double) (g == min ? 5.0+(max-b)/delta : 1.0-(max-g)/delta);
6338   else
6339     if (g == max)
6340       *hue=(double) (b == min ? 1.0+(max-r)/delta : 3.0-(max-b)/delta);
6341     else
6342       *hue=(double) (r == min ? 3.0+(max-g)/delta : 5.0-(max-r)/delta);
6343   *hue/=6.0;
6344 }
6345 \f
6346 /*
6347 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6348 %                                                                             %
6349 %                                                                             %
6350 %                                                                             %
6351 %   T r a n s l a t e T e x t                                                 %
6352 %                                                                             %
6353 %                                                                             %
6354 %                                                                             %
6355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6356 %
6357 %  TranslateText() replaces any embedded formatting characters with the
6358 %  appropriate image attribute and returns the translated text.
6359 %
6360 %  The format of the TranslateText method is:
6361 %
6362 %      char *TranslateText(const ImageInfo *image_info,Image *image,
6363 %        const char *embed_text)
6364 %
6365 %  A description of each parameter follows:
6366 %
6367 %    o image_info: the image info.
6368 %
6369 %    o image: the image.
6370 %
6371 %    o embed_text: the address of a character string containing the embedded
6372 %      formatting characters.
6373 %
6374 */
6375 MagickExport char *TranslateText(const ImageInfo *image_info,Image *image,
6376   const char *embed_text)
6377 {
6378   assert(image != (Image *) NULL);
6379   assert(image->signature == MagickSignature);
6380   if (image->debug != MagickFalse)
6381     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.6");
6382   return(InterpretImageProperties(image_info,image,embed_text));
6383 }
6384 \f
6385 /*
6386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6387 %                                                                             %
6388 %                                                                             %
6389 %                                                                             %
6390 %     T r a n s p a r e n t I m a g e                                         %
6391 %                                                                             %
6392 %                                                                             %
6393 %                                                                             %
6394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6395 %
6396 %  TransparentImage() changes the opacity value associated with any pixel
6397 %  that matches color to the value defined by opacity.
6398 %
6399 %  By default color must match a particular pixel color exactly.  However,
6400 %  in many cases two colors may differ by a small amount.  Fuzz defines
6401 %  how much tolerance is acceptable to consider two colors as the same.
6402 %  For example, set fuzz to 10 and the color red at intensities of 100 and
6403 %  102 respectively are now interpreted as the same color.
6404 %
6405 %  The format of the TransparentImage method is:
6406 %
6407 %      MagickBooleanType TransparentImage(Image *image,
6408 %        const PixelPacket target,const Quantum opacity)
6409 %
6410 %  A description of each parameter follows:
6411 %
6412 %    o image: the image.
6413 %
6414 %    o target: the RGB value of the target color.
6415 %
6416 %    o opacity: the replacement opacity value.
6417 %
6418 */
6419 MagickExport MagickBooleanType TransparentImage(Image *image,
6420   const PixelPacket target,const Quantum opacity)
6421 {
6422 #define TransparentImageTag  "Transparent/Image"
6423
6424   long
6425     y;
6426
6427   MagickBooleanType
6428     proceed;
6429
6430   /*
6431     Make image color transparent.
6432   */
6433   assert(image != (Image *) NULL);
6434   assert(image->signature == MagickSignature);
6435   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.1.0");
6436   if (image->debug != MagickFalse)
6437     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6438   if (image->matte == MagickFalse)
6439     (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
6440   for (y=0; y < (long) image->rows; y++)
6441   {
6442     register long
6443       x;
6444
6445     register PixelPacket
6446       *restrict q;
6447
6448     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
6449     if (q == (PixelPacket *) NULL)
6450       break;
6451     for (x=0; x < (long) image->columns; x++)
6452     {
6453       if (IsColorSimilar(image,q,&target) != MagickFalse)
6454         q->opacity=opacity;
6455       q++;
6456     }
6457     if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
6458       break;
6459     proceed=SetImageProgress(image,TransparentImageTag,y,image->rows);
6460     if (proceed == MagickFalse)
6461       break;
6462   }
6463   return(MagickTrue);
6464 }
6465 \f
6466 /*
6467 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6468 %                                                                             %
6469 %                                                                             %
6470 %                                                                             %
6471 %   U n s h i f t I m a g e L i s t                                           %
6472 %                                                                             %
6473 %                                                                             %
6474 %                                                                             %
6475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6476 %
6477 %  UnshiftImageList() adds the image to the beginning of the list.
6478 %
6479 %  The format of the UnshiftImageList method is:
6480 %
6481 %      unsigned int UnshiftImageList(Image *images,const Image *image,
6482 %        ExceptionInfo *exception)
6483 %
6484 %  A description of each parameter follows:
6485 %
6486 %    o images: the image list.
6487 %
6488 %    o image: the image.
6489 %
6490 %    o exception: return any errors or warnings in this structure.
6491 %
6492 */
6493 MagickExport unsigned int UnshiftImageList(Image **images,const Image *image,
6494   ExceptionInfo *exception)
6495 {
6496   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
6497   PrependImageToList(images,CloneImageList(image,exception));
6498   return(MagickTrue);
6499 }
6500 \f
6501 /*
6502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6503 %                                                                             %
6504 %                                                                             %
6505 %                                                                             %
6506 +   V a l i d a t e C o l o r m a p I n d e x                                 %
6507 %                                                                             %
6508 %                                                                             %
6509 %                                                                             %
6510 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6511 %
6512 %  ValidateColormapIndex() validates the colormap index.  If the index does
6513 %  not range from 0 to the number of colors in the colormap an exception
6514 %  issued and 0 is returned.
6515 %
6516 %  The format of the ValidateColormapIndex method is:
6517 %
6518 %      IndexPacket ValidateColormapIndex(Image *image,const unsigned int index)
6519 %
6520 %  A description of each parameter follows:
6521 %
6522 %    o index: Method ValidateColormapIndex returns colormap index if it is
6523 %      valid other an exception issued and 0 is returned.
6524 %
6525 %    o image: the image.
6526 %
6527 %    o index: This integer is the colormap index.
6528 %
6529 */
6530
6531 MagickExport IndexPacket ValidateColormapIndex(Image *image,
6532   const unsigned long index)
6533 {
6534   if (image->debug != MagickFalse)
6535     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.4.4");
6536   return(ConstrainColormapIndex(image,index));
6537 }
6538 #endif