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