]> 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-2010 ImageMagick Studio LLC, a non-profit organization      %
21 %  dedicated to making software imaging solutions freely available.           %
22 %                                                                             %
23 %  You may not use this file except in compliance with the License.  You may  %
24 %  obtain a copy of the License at                                            %
25 %                                                                             %
26 %    http://www.imagemagick.org/script/license.php                            %
27 %                                                                             %
28 %  Unless required by applicable law or agreed to in writing, software        %
29 %  distributed under the License is distributed on an "AS IS" BASIS,          %
30 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
31 %  See the License for the specific language governing permissions and        %
32 %  limitations under the License.                                             %
33 %                                                                             %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 %
37 %
38 */
39 \f
40 /*
41   Include declarations.
42 */
43 #include "magick/studio.h"
44 #include "magick/property.h"
45 #include "magick/blob.h"
46 #include "magick/blob-private.h"
47 #include "magick/cache.h"
48 #include "magick/cache-view.h"
49 #include "magick/client.h"
50 #include "magick/color.h"
51 #include "magick/color-private.h"
52 #include "magick/colormap.h"
53 #include "magick/colormap-private.h"
54 #include "magick/colorspace.h"
55 #include "magick/composite.h"
56 #include "magick/composite-private.h"
57 #include "magick/constitute.h"
58 #include "magick/deprecate.h"
59 #include "magick/draw.h"
60 #include "magick/draw-private.h"
61 #include "magick/effect.h"
62 #include "magick/enhance.h"
63 #include "magick/exception.h"
64 #include "magick/exception-private.h"
65 #include "magick/fx.h"
66 #include "magick/geometry.h"
67 #include "magick/identify.h"
68 #include "magick/image.h"
69 #include "magick/image-private.h"
70 #include "magick/list.h"
71 #include "magick/log.h"
72 #include "magick/memory_.h"
73 #include "magick/magick.h"
74 #include "magick/monitor.h"
75 #include "magick/monitor-private.h"
76 #include "magick/morphology.h"
77 #include "magick/paint.h"
78 #include "magick/pixel.h"
79 #include "magick/pixel-private.h"
80 #include "magick/quantize.h"
81 #include "magick/random_.h"
82 #include "magick/resource_.h"
83 #include "magick/semaphore.h"
84 #include "magick/segment.h"
85 #include "magick/splay-tree.h"
86 #include "magick/statistic.h"
87 #include "magick/string_.h"
88 #include "magick/threshold.h"
89 #include "magick/transform.h"
90 #include "magick/utility.h"
91 \f
92 #if !defined(MAGICKCORE_EXCLUDE_DEPRECATED)
93 /*
94   Global declarations.
95 */
96 static MonitorHandler
97   monitor_handler = (MonitorHandler) NULL;
98 \f
99 /*
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 %                                                                             %
102 %                                                                             %
103 %                                                                             %
104 %   A c q u i r e C a c h e V i e w I n d e x e s                             %
105 %                                                                             %
106 %                                                                             %
107 %                                                                             %
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 %
110 %  AcquireCacheViewIndexes() returns the indexes associated with the specified
111 %  view.
112 %
113 %  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 long x,const long y,const unsigned long columns,
155 %        const unsigned long 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 long x,const long y,
169   const unsigned long columns,const unsigned long 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 long x,
212 %        const long y,const unsigned long columns,const unsigned long 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 long x,const long y,const unsigned long columns,
227   const unsigned long 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 long x,const long 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 long x,const long 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 long x,
370 %        const long 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 long x,const long 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 long x,
420 %        const long 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 long x,const long 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 long x,
464 %        const long 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 long x,
476   const long 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 long x,
510 %        const long 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 long x,const long 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 unsigned long 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 unsigned long 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 long
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=(long) (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 long x_offset,const long 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)) < (long) 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 long x_offset,
1155   const long y_offset,const PaintMethod method)
1156 {
1157   Image
1158     *floodplane_image;
1159
1160   long
1161     offset,
1162     start,
1163     x,
1164     x1,
1165     x2,
1166     y;
1167
1168   MagickBooleanType
1169     skip;
1170
1171   PixelPacket
1172     fill_color;
1173
1174   register SegmentInfo
1175     *s;
1176
1177   SegmentInfo
1178     *segment_stack;
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 >= (long) image->columns))
1190     return(MagickFalse);
1191   if ((y_offset < 0) || (y_offset >= (long) 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 long
1228       x;
1229
1230     register PixelPacket
1231       *restrict q;
1232
1233     /*
1234       Pop segment off stack.
1235     */
1236     s--;
1237     x1=(long) s->x1;
1238     x2=(long) s->x2;
1239     offset=(long) s->y2;
1240     y=(long) s->y1+offset;
1241     /*
1242       Recolor neighboring pixels.
1243     */
1244     p=GetVirtualPixels(image,0,y,(unsigned long) (x1+1),1,&image->exception);
1245     q=GetAuthenticPixels(floodplane_image,0,y,(unsigned long) (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 < (long) 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 < (long) 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,(unsigned long) (x2-x+1),1,
1318             &image->exception);
1319           q=GetAuthenticPixels(floodplane_image,x,y,(unsigned long) (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 < (long) image->rows; y++)
1343   {
1344     register const PixelPacket
1345       *restrict p;
1346
1347     register long
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 < (long) image->columns; x++)
1362     {
1363       if (p->opacity != 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 == (long) 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 long 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 long offset)
1439 {
1440   register long
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 %    FormatMagickString(key,MaxTextExtent,"%ld\n",id);
1476 %    DeleteImageRegistry(key);
1477 %
1478 %  The format of the DeleteMagickRegistry method is:
1479 %
1480 %      MagickBooleanType DeleteMagickRegistry(const long id)
1481 %
1482 %  A description of each parameter follows:
1483 %
1484 %    o id: the registry id.
1485 %
1486 */
1487 MagickExport MagickBooleanType DeleteMagickRegistry(const long id)
1488 {
1489   char
1490     key[MaxTextExtent];
1491
1492   (void) FormatMagickString(key,MaxTextExtent,"%ld\n",id);
1493   return(DeleteImageRegistry(key));
1494 }
1495 \f
1496 /*
1497 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1498 %                                                                             %
1499 %                                                                             %
1500 %                                                                             %
1501 +   D e s t r o y M a g i c k R e g i s t r y                                 %
1502 %                                                                             %
1503 %                                                                             %
1504 %                                                                             %
1505 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1506 %
1507 %  DestroyMagickRegistry() deallocates memory associated the magick registry.
1508 %
1509 %  Deprecated, replace with:
1510 %
1511 %    RegistryComponentTerminus();
1512 %
1513 %  The format of the DestroyMagickRegistry method is:
1514 %
1515 %       void DestroyMagickRegistry(void)
1516 %
1517 */
1518 MagickExport void DestroyMagickRegistry(void)
1519 {
1520   RegistryComponentTerminus();
1521 }
1522 \f
1523 /*
1524 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1525 %                                                                             %
1526 %                                                                             %
1527 %                                                                             %
1528 %   D e s c r i b e I m a g e                                                 %
1529 %                                                                             %
1530 %                                                                             %
1531 %                                                                             %
1532 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1533 %
1534 %  DescribeImage() describes an image by printing its attributes to the file.
1535 %  Attributes include the image width, height, size, and others.
1536 %
1537 %  Deprecated, replace with:
1538 %
1539 %    IdentifyImage(image,file,verbose);
1540 %
1541 %  The format of the DescribeImage method is:
1542 %
1543 %      MagickBooleanType DescribeImage(Image *image,FILE *file,
1544 %        const MagickBooleanType verbose)
1545 %
1546 %  A description of each parameter follows:
1547 %
1548 %    o image: the image.
1549 %
1550 %    o file: the file, typically stdout.
1551 %
1552 %    o verbose: A value other than zero prints more detailed information
1553 %      about the image.
1554 %
1555 */
1556 MagickExport MagickBooleanType DescribeImage(Image *image,FILE *file,
1557   const MagickBooleanType verbose)
1558 {
1559   return(IdentifyImage(image,file,verbose));
1560 }
1561 \f
1562 /*
1563 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1564 %                                                                             %
1565 %                                                                             %
1566 %                                                                             %
1567 %   D e s t r o y I m a g e A t t r i b u t e s                               %
1568 %                                                                             %
1569 %                                                                             %
1570 %                                                                             %
1571 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1572 %
1573 %  DestroyImageAttributes() deallocates memory associated with the image
1574 %  attribute list.
1575 %
1576 %  The format of the DestroyImageAttributes method is:
1577 %
1578 %      DestroyImageAttributes(Image *image)
1579 %
1580 %  A description of each parameter follows:
1581 %
1582 %    o image: the image.
1583 %
1584 */
1585 MagickExport void DestroyImageAttributes(Image *image)
1586 {
1587   assert(image != (Image *) NULL);
1588   assert(image->signature == MagickSignature);
1589   if (image->debug != MagickFalse)
1590     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1591   if (image->attributes != (void *) NULL)
1592     image->attributes=(void *) DestroySplayTree((SplayTreeInfo *)
1593       image->attributes);
1594 }
1595 \f
1596 /*
1597 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1598 %                                                                             %
1599 %                                                                             %
1600 %                                                                             %
1601 %   D e s t r o y I m a g e s                                                 %
1602 %                                                                             %
1603 %                                                                             %
1604 %                                                                             %
1605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1606 %
1607 %  DestroyImages() destroys an image list.
1608 %
1609 %  Deprecated, replace with:
1610 %
1611 %    DestroyImageList(image);
1612 %
1613 %  The format of the DestroyImages method is:
1614 %
1615 %      void DestroyImages(Image *image)
1616 %
1617 %  A description of each parameter follows:
1618 %
1619 %    o image: the image sequence.
1620 %
1621 */
1622 MagickExport void DestroyImages(Image *image)
1623 {
1624   if (image == (Image *) NULL)
1625     return;
1626   if (image->debug != MagickFalse)
1627     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.4.3");
1628   image=DestroyImageList(image);
1629 }
1630 \f
1631 /*
1632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1633 %                                                                             %
1634 %                                                                             %
1635 %                                                                             %
1636 %   D e s t r o y M a g i c k                                                 %
1637 %                                                                             %
1638 %                                                                             %
1639 %                                                                             %
1640 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1641 %
1642 %  DestroyMagick() destroys the ImageMagick environment.
1643 %
1644 %  Deprecated, replace with:
1645 %
1646 %    MagickCoreTerminus();
1647 %
1648 %  The format of the DestroyMagick function is:
1649 %
1650 %      DestroyMagick(void)
1651 %
1652 */
1653 MagickExport void DestroyMagick(void)
1654 {
1655   MagickCoreTerminus();
1656 }
1657 \f
1658 /*
1659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1660 %                                                                             %
1661 %                                                                             %
1662 %                                                                             %
1663 %   D i s p a t c h I m a g e                                                 %
1664 %                                                                             %
1665 %                                                                             %
1666 %                                                                             %
1667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1668 %
1669 %  DispatchImage() extracts pixel data from an image and returns it to you.
1670 %  The method returns MagickFalse on success otherwise MagickTrue if an error is
1671 %  encountered.  The data is returned as char, short int, int, long, float,
1672 %  or double in the order specified by map.
1673 %
1674 %  Suppose you want to extract the first scanline of a 640x480 image as
1675 %  character data in red-green-blue order:
1676 %
1677 %      DispatchImage(image,0,0,640,1,"RGB",CharPixel,pixels,exception);
1678 %
1679 %  Deprecated, replace with:
1680 %
1681 %    ExportImagePixels(image,x_offset,y_offset,columns,rows,map,type,pixels,
1682 %      exception);
1683 %
1684 %  The format of the DispatchImage method is:
1685 %
1686 %      unsigned int DispatchImage(const Image *image,const long x_offset,
1687 %        const long y_offset,const unsigned long columns,
1688 %        const unsigned long rows,const char *map,const StorageType type,
1689 %        void *pixels,ExceptionInfo *exception)
1690 %
1691 %  A description of each parameter follows:
1692 %
1693 %    o image: the image.
1694 %
1695 %    o x_offset, y_offset, columns, rows:  These values define the perimeter
1696 %      of a region of pixels you want to extract.
1697 %
1698 %    o map:  This string reflects the expected ordering of the pixel array.
1699 %      It can be any combination or order of R = red, G = green, B = blue,
1700 %      A = alpha, C = cyan, Y = yellow, M = magenta, K = black, or
1701 %      I = intensity (for grayscale).
1702 %
1703 %    o type: Define the data type of the pixels.  Float and double types are
1704 %      normalized to [0..1] otherwise [0..QuantumRange].  Choose from these
1705 %      types: CharPixel, ShortPixel, IntegerPixel, LongPixel, FloatPixel, or
1706 %      DoublePixel.
1707 %
1708 %    o pixels: This array of values contain the pixel components as defined by
1709 %      map and type.  You must preallocate this array where the expected
1710 %      length varies depending on the values of width, height, map, and type.
1711 %
1712 %    o exception: return any errors or warnings in this structure.
1713 %
1714 */
1715 MagickExport unsigned int DispatchImage(const Image *image,const long x_offset,
1716   const long y_offset,const unsigned long columns,const unsigned long rows,
1717   const char *map,const StorageType type,void *pixels,ExceptionInfo *exception)
1718 {
1719   unsigned int
1720     status;
1721
1722   if (image->debug != MagickFalse)
1723     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.6");
1724   status=ExportImagePixels(image,x_offset,y_offset,columns,rows,map,type,pixels,
1725     exception);
1726   return(status);
1727 }
1728 \f
1729 /*
1730 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1731 %                                                                             %
1732 %                                                                             %
1733 %                                                                             %
1734 %   E x t r a c t S u b i m a g e F r o m I m a g e                           %
1735 %                                                                             %
1736 %                                                                             %
1737 %                                                                             %
1738 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1739 %
1740 %  ExtractSubimageFromImageImage() extracts a region of the image that most
1741 %  closely resembles the reference.
1742 %
1743 %  The format of the ExtractSubimageFromImageImage method is:
1744 %
1745 %      Image *ExtractSubimageFromImage(const Image *image,
1746 %        const Image *reference,ExceptionInfo *exception)
1747 %
1748 %  A description of each parameter follows:
1749 %
1750 %    o image: the image.
1751 %
1752 %    o reference: find an area of the image that closely resembles this image.
1753 %
1754 %    o exception: return any errors or warnings in this structure.
1755 %
1756 */
1757
1758 static double GetSimilarityMetric(const Image *image,const Image *reference,
1759   const long x_offset,const long y_offset,const double similarity_threshold,
1760   ExceptionInfo *exception)
1761 {
1762   CacheView
1763     *image_view,
1764     *reference_view;
1765
1766   long
1767     y;
1768
1769   double
1770     channels,
1771     normalized_similarity,
1772     similarity;
1773
1774   /*
1775     Compute the similarity in pixels between two images.
1776   */
1777   normalized_similarity=1.0;
1778   similarity=0.0;
1779   channels=3;
1780   if ((image->matte != MagickFalse) && (reference->matte != MagickFalse))
1781     channels++;
1782   if ((image->colorspace == CMYKColorspace) &&
1783       (reference->colorspace == CMYKColorspace))
1784     channels++;
1785   image_view=AcquireCacheView(image);
1786   reference_view=AcquireCacheView(reference);
1787   for (y=0; y < (long) reference->rows; y++)
1788   {
1789     register const IndexPacket
1790       *indexes,
1791       *reference_indexes;
1792
1793     register const PixelPacket
1794       *p,
1795       *q;
1796
1797     register long
1798       x;
1799
1800     p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset+y,
1801       reference->columns,1,exception);
1802     q=GetCacheViewVirtualPixels(reference_view,0,y,reference->columns,1,
1803       exception);
1804     if ((p == (const PixelPacket *) NULL) || (q == (const PixelPacket *) NULL))
1805       continue;
1806     indexes=GetCacheViewVirtualIndexQueue(image_view);
1807     reference_indexes=GetCacheViewVirtualIndexQueue(reference_view);
1808     for (x=0; x < (long) reference->columns; x++)
1809     {
1810       MagickRealType
1811         pixel;
1812
1813       pixel=QuantumScale*(p->red-(double) q->red);
1814       similarity+=pixel*pixel;
1815       pixel=QuantumScale*(p->green-(double) q->green);
1816       similarity+=pixel*pixel;
1817       pixel=QuantumScale*(p->blue-(double) q->blue);
1818       similarity+=pixel*pixel;
1819       if ((image->matte != MagickFalse) && (reference->matte != MagickFalse))
1820         {
1821           pixel=QuantumScale*(p->opacity-(double) q->opacity);
1822           similarity+=pixel*pixel;
1823         }
1824       if ((image->colorspace == CMYKColorspace) &&
1825           (reference->colorspace == CMYKColorspace))
1826         {
1827           pixel=QuantumScale*(indexes[x]-(double) reference_indexes[x]);
1828           similarity+=pixel*pixel;
1829         }
1830       p++;
1831       q++;
1832     }
1833     normalized_similarity=sqrt(similarity)/reference->columns/reference->rows/
1834       channels;
1835     if (normalized_similarity > similarity_threshold)
1836       break;
1837   }
1838   reference_view=DestroyCacheView(reference_view);
1839   image_view=DestroyCacheView(image_view);
1840   return(normalized_similarity);
1841 }
1842
1843 MagickExport Image *ExtractSubimageFromImage(Image *image,
1844   const Image *reference,ExceptionInfo *exception)
1845 {
1846   long
1847     y;
1848
1849   double
1850     similarity_threshold;
1851
1852   RectangleInfo
1853     offset;
1854
1855   /*
1856     Extract reference from image.
1857   */
1858   if ((reference->columns > image->columns) || (reference->rows > image->rows))
1859     return((Image *) NULL);
1860   similarity_threshold=(double) image->columns*image->rows;
1861   SetGeometry(reference,&offset);
1862 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1863   #pragma omp parallel for schedule(dynamic,4)
1864 #endif
1865   for (y=0; y < (long) (image->rows-reference->rows); y++)
1866   {
1867     double
1868       similarity;
1869
1870     register long
1871       x;
1872
1873     for (x=0; x < (long) (image->columns-reference->columns); x++)
1874     {
1875       similarity=GetSimilarityMetric(image,reference,x,y,similarity_threshold,
1876         exception);
1877 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1878   #pragma omp critical (MagickCore_ExtractSubimageFromImage)
1879 #endif
1880       if (similarity < similarity_threshold)
1881         {
1882           similarity_threshold=similarity;
1883           offset.x=x;
1884           offset.y=y;
1885         }
1886     }
1887   }
1888   if (similarity_threshold > (QuantumScale*reference->fuzz/100.0))
1889     return((Image *) NULL);
1890   return(CropImage(image,&offset,exception));
1891 }
1892 \f
1893 /*
1894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1895 %                                                                             %
1896 %                                                                             %
1897 %                                                                             %
1898 %     F l a t t e n I m a g e                                                 %
1899 %                                                                             %
1900 %                                                                             %
1901 %                                                                             %
1902 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1903 %
1904 %  FlattenImages() Obsolete Function: Use MergeImageLayers() instead.
1905 %
1906 %  Deprecated, replace with:
1907 %
1908 %    MergeImageLayers(image,FlattenLayer,exception);
1909 %
1910 %  The format of the FlattenImage method is:
1911 %
1912 %      Image *FlattenImage(Image *image,ExceptionInfo *exception)
1913 %
1914 %  A description of each parameter follows:
1915 %
1916 %    o image: the image sequence.
1917 %
1918 %    o exception: return any errors or warnings in this structure.
1919 %
1920 */
1921 MagickExport Image *FlattenImages(Image *image,ExceptionInfo *exception)
1922 {
1923   return(MergeImageLayers(image,FlattenLayer,exception));
1924 }
1925 \f
1926 /*
1927 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1928 %                                                                             %
1929 %                                                                             %
1930 %                                                                             %
1931 %  F o r m a t I m a g e A t t r i b u t e                                    %
1932 %                                                                             %
1933 %                                                                             %
1934 %                                                                             %
1935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1936 %
1937 %  FormatImageAttribute() permits formatted key/value pairs to be saved as an
1938 %  image attribute.
1939 %
1940 %  The format of the FormatImageAttribute method is:
1941 %
1942 %      MagickBooleanType FormatImageAttribute(Image *image,const char *key,
1943 %        const char *format,...)
1944 %
1945 %  A description of each parameter follows.
1946 %
1947 %   o  image:  The image.
1948 %
1949 %   o  key:  The attribute key.
1950 %
1951 %   o  format:  A string describing the format to use to write the remaining
1952 %      arguments.
1953 %
1954 */
1955
1956 MagickExport MagickBooleanType FormatImageAttributeList(Image *image,
1957   const char *key,const char *format,va_list operands)
1958 {
1959   char
1960     value[MaxTextExtent];
1961
1962   int
1963     n;
1964
1965 #if defined(MAGICKCORE_HAVE_VSNPRINTF)
1966   n=vsnprintf(value,MaxTextExtent,format,operands);
1967 #else
1968   n=vsprintf(value,format,operands);
1969 #endif
1970   if (n < 0)
1971     value[MaxTextExtent-1]='\0';
1972   return(SetImageProperty(image,key,value));
1973 }
1974
1975 MagickExport MagickBooleanType FormatImageAttribute(Image *image,
1976   const char *key,const char *format,...)
1977 {
1978   MagickBooleanType
1979     status;
1980
1981   va_list
1982     operands;
1983
1984   va_start(operands,format);
1985   status=FormatImagePropertyList(image,key,format,operands);
1986   va_end(operands);
1987   return(status);
1988 }
1989 \f
1990 /*
1991 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1992 %                                                                             %
1993 %                                                                             %
1994 %                                                                             %
1995 %  F o r m a t S t r i n g                                                    %
1996 %                                                                             %
1997 %                                                                             %
1998 %                                                                             %
1999 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2000 %
2001 %  FormatString() prints formatted output of a variable argument list.
2002 %
2003 %  The format of the FormatString method is:
2004 %
2005 %      void FormatString(char *string,const char *format,...)
2006 %
2007 %  A description of each parameter follows.
2008 %
2009 %   o  string:  Method FormatString returns the formatted string in this
2010 %      character buffer.
2011 %
2012 %   o  format:  A string describing the format to use to write the remaining
2013 %      arguments.
2014 %
2015 */
2016
2017 MagickExport void FormatStringList(char *string,const char *format,
2018   va_list operands)
2019 {
2020   int
2021     n;
2022
2023  (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
2024 #if defined(MAGICKCORE_HAVE_VSNPRINTF)
2025   n=vsnprintf(string,MaxTextExtent,format,operands);
2026 #else
2027   n=vsprintf(string,format,operands);
2028 #endif
2029   if (n < 0)
2030     string[MaxTextExtent-1]='\0';
2031 }
2032
2033 MagickExport void FormatString(char *string,const char *format,...)
2034 {
2035   va_list
2036     operands;
2037
2038   va_start(operands,format);
2039   (void) FormatMagickStringList(string,MaxTextExtent,format,operands);
2040   va_end(operands);
2041   return;
2042 }
2043 \f
2044 /*
2045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2046 %                                                                             %
2047 %                                                                             %
2048 %                                                                             %
2049 +   F u z z y C o l o r M a t c h                                             %
2050 %                                                                             %
2051 %                                                                             %
2052 %                                                                             %
2053 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2054 %
2055 %  FuzzyColorMatch() returns true if two pixels are identical in color.
2056 %
2057 %  The format of the ColorMatch method is:
2058 %
2059 %      void FuzzyColorMatch(const PixelPacket *p,const PixelPacket *q,
2060 %        const double fuzz)
2061 %
2062 %  A description of each parameter follows:
2063 %
2064 %    o p: Pixel p.
2065 %
2066 %    o q: Pixel q.
2067 %
2068 %    o distance:  Define how much tolerance is acceptable to consider
2069 %      two colors as the same.
2070 %
2071 */
2072 MagickExport unsigned int FuzzyColorMatch(const PixelPacket *p,
2073   const PixelPacket *q,const double fuzz)
2074 {
2075   MagickPixelPacket
2076     pixel;
2077
2078   register MagickRealType
2079     distance;
2080
2081   if ((fuzz == 0.0) && (p->red == q->red) && (p->green == q->green) &&
2082       (p->blue == q->blue))
2083     return(MagickTrue);
2084   pixel.red=p->red-(MagickRealType) q->red;
2085   distance=pixel.red*pixel.red;
2086   if (distance > (fuzz*fuzz))
2087     return(MagickFalse);
2088   pixel.green=p->green-(MagickRealType) q->green;
2089   distance+=pixel.green*pixel.green;
2090   if (distance > (fuzz*fuzz))
2091     return(MagickFalse);
2092   pixel.blue=p->blue-(MagickRealType) q->blue;
2093   distance+=pixel.blue*pixel.blue;
2094   if (distance > (fuzz*fuzz))
2095     return(MagickFalse);
2096   return(MagickTrue);
2097 }
2098 \f
2099 /*
2100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2101 %                                                                             %
2102 %                                                                             %
2103 %                                                                             %
2104 +   F u z z y C o l o r C o m p a r e                                         %
2105 %                                                                             %
2106 %                                                                             %
2107 %                                                                             %
2108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2109 %
2110 %  FuzzyColorCompare() returns MagickTrue if the distance between two colors is
2111 %  less than the specified distance in a linear three dimensional color space.
2112 %  This method is used by ColorFloodFill() and other algorithms which
2113 %  compare two colors.
2114 %
2115 %  The format of the FuzzyColorCompare method is:
2116 %
2117 %      void FuzzyColorCompare(const Image *image,const PixelPacket *p,
2118 %        const PixelPacket *q)
2119 %
2120 %  A description of each parameter follows:
2121 %
2122 %    o image: the image.
2123 %
2124 %    o p: Pixel p.
2125 %
2126 %    o q: Pixel q.
2127 %
2128 */
2129 MagickExport MagickBooleanType FuzzyColorCompare(const Image *image,
2130   const PixelPacket *p,const PixelPacket *q)
2131 {
2132   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.5");
2133   return(IsColorSimilar(image,p,q));
2134 }
2135 \f
2136 /*
2137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2138 %                                                                             %
2139 %                                                                             %
2140 %                                                                             %
2141 +   F u z z y O p a c i t y C o m p a r e                                     %
2142 %                                                                             %
2143 %                                                                             %
2144 %                                                                             %
2145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2146 %
2147 %  FuzzyOpacityCompare() returns true if the distance between two opacity
2148 %  values is less than the specified distance in a linear color space.  This
2149 %  method is used by MatteFloodFill() and other algorithms which compare
2150 %  two opacity values.
2151 %
2152 %  Deprecated, replace with:
2153 %
2154 %    IsOpacitySimilar(image,p,q);
2155 %
2156 %  The format of the FuzzyOpacityCompare method is:
2157 %
2158 %      void FuzzyOpacityCompare(const Image *image,const PixelPacket *p,
2159 %        const PixelPacket *q)
2160 %
2161 %  A description of each parameter follows:
2162 %
2163 %    o image: the image.
2164 %
2165 %    o p: Pixel p.
2166 %
2167 %    o q: Pixel q.
2168 %
2169 */
2170 MagickExport MagickBooleanType FuzzyOpacityCompare(const Image *image,
2171   const PixelPacket *p,const PixelPacket *q)
2172 {
2173   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.5");
2174   return(IsOpacitySimilar(image,p,q));
2175 }
2176 \f
2177 /*
2178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2179 %                                                                             %
2180 %                                                                             %
2181 %                                                                             %
2182 %  G e t C o n f i g u r e B l o b                                            %
2183 %                                                                             %
2184 %                                                                             %
2185 %                                                                             %
2186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2187 %
2188 %  GetConfigureBlob() returns the specified configure file as a blob.
2189 %
2190 %  The format of the GetConfigureBlob method is:
2191 %
2192 %      void *GetConfigureBlob(const char *filename,ExceptionInfo *exception)
2193 %
2194 %  A description of each parameter follows:
2195 %
2196 %    o filename: the configure file name.
2197 %
2198 %    o path: return the full path information of the configure file.
2199 %
2200 %    o length: This pointer to a size_t integer sets the initial length of the
2201 %      blob.  On return, it reflects the actual length of the blob.
2202 %
2203 %    o exception: return any errors or warnings in this structure.
2204 %
2205 */
2206 MagickExport void *GetConfigureBlob(const char *filename,char *path,
2207   size_t *length,ExceptionInfo *exception)
2208 {
2209   void
2210     *blob;
2211
2212   assert(filename != (const char *) NULL);
2213   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
2214   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
2215   assert(path != (char *) NULL);
2216   assert(length != (size_t *) NULL);
2217   assert(exception != (ExceptionInfo *) NULL);
2218   blob=(void *) NULL;
2219   (void) CopyMagickString(path,filename,MaxTextExtent);
2220 #if defined(MAGICKCORE_INSTALLED_SUPPORT)
2221 #if defined(MAGICKCORE_LIBRARY_PATH)
2222   if (blob == (void *) NULL)
2223     {
2224       /*
2225         Search hard coded paths.
2226       */
2227       (void) FormatMagickString(path,MaxTextExtent,"%s%s",
2228         MAGICKCORE_LIBRARY_PATH,filename);
2229       if (IsPathAccessible(path) != MagickFalse)
2230         blob=FileToBlob(path,~0,length,exception);
2231     }
2232 #endif
2233 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !(defined(MAGICKCORE_CONFIGURE_PATH) || defined(MAGICKCORE_SHARE_CONFIGURE_PATH))
2234   if (blob == (void *) NULL)
2235     {
2236       char
2237         *key_value;
2238
2239       /*
2240         Locate file via registry key.
2241       */
2242       key_value=NTRegistryKeyLookup("ConfigurePath");
2243       if (key_value != (char *) NULL)
2244         {
2245           (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",key_value,
2246             DirectorySeparator,filename);
2247           if (IsPathAccessible(path) != MagickFalse)
2248             blob=FileToBlob(path,~0,length,exception);
2249         }
2250     }
2251 #endif
2252 #else
2253   if (blob == (void *) NULL)
2254     {
2255       char
2256         *home;
2257
2258       home=GetEnvironmentValue("MAGICK_HOME");
2259       if (home != (char *) NULL)
2260         {
2261           /*
2262             Search MAGICK_HOME.
2263           */
2264 #if !defined(MAGICKCORE_POSIX_SUPPORT)
2265           (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",home,
2266             DirectorySeparator,filename);
2267 #else
2268           (void) FormatMagickString(path,MaxTextExtent,"%s/lib/%s/%s",home,
2269             MAGICKCORE_LIBRARY_RELATIVE_PATH,filename);
2270 #endif
2271           if (IsPathAccessible(path) != MagickFalse)
2272             blob=FileToBlob(path,~0,length,exception);
2273           home=DestroyString(home);
2274         }
2275       home=GetEnvironmentValue("HOME");
2276       if (home == (char *) NULL)
2277         home=GetEnvironmentValue("USERPROFILE");
2278       if (home != (char *) NULL)
2279         {
2280           /*
2281             Search $HOME/.magick.
2282           */
2283           (void) FormatMagickString(path,MaxTextExtent,"%s%s.magick%s%s",home,
2284             DirectorySeparator,DirectorySeparator,filename);
2285           if ((IsPathAccessible(path) != MagickFalse) && (blob == (void *) NULL))
2286             blob=FileToBlob(path,~0,length,exception);
2287           home=DestroyString(home);
2288         }
2289     }
2290   if ((blob == (void *) NULL) && (*GetClientPath() != '\0'))
2291     {
2292 #if !defined(MAGICKCORE_POSIX_SUPPORT)
2293       (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",GetClientPath(),
2294         DirectorySeparator,filename);
2295 #else
2296       char
2297         prefix[MaxTextExtent];
2298
2299       /*
2300         Search based on executable directory if directory is known.
2301       */
2302       (void) CopyMagickString(prefix,GetClientPath(),
2303         MaxTextExtent);
2304       ChopPathComponents(prefix,1);
2305       (void) FormatMagickString(path,MaxTextExtent,"%s/lib/%s/%s",prefix,
2306         MAGICKCORE_LIBRARY_RELATIVE_PATH,filename);
2307 #endif
2308       if (IsPathAccessible(path) != MagickFalse)
2309         blob=FileToBlob(path,~0,length,exception);
2310     }
2311   /*
2312     Search current directory.
2313   */
2314   if ((blob == (void *) NULL) && (IsPathAccessible(path) != MagickFalse))
2315     blob=FileToBlob(path,~0,length,exception);
2316 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
2317   /*
2318     Search Windows registry.
2319   */
2320   if (blob == (void *) NULL)
2321     blob=NTResourceToBlob(filename);
2322 #endif
2323 #endif
2324   if (blob == (void *) NULL)
2325     (void) ThrowMagickException(exception,GetMagickModule(),ConfigureWarning,
2326       "UnableToOpenConfigureFile","`%s'",path);
2327   return(blob);
2328 }
2329 \f
2330 /*
2331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2332 %                                                                             %
2333 %                                                                             %
2334 %                                                                             %
2335 %   G e t C a c h e V i e w                                                   %
2336 %                                                                             %
2337 %                                                                             %
2338 %                                                                             %
2339 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2340 %
2341 %  GetCacheView() gets pixels from the in-memory or disk pixel cache as
2342 %  defined by the geometry parameters.   A pointer to the pixels is returned if
2343 %  the pixels are transferred, otherwise a NULL is returned.
2344 %
2345 %  Deprecated, replace with:
2346 %
2347 %    GetCacheViewAuthenticPixels(cache_view,x,y,columns,rows,
2348 %      GetCacheViewException(cache_view));
2349 %
2350 %  The format of the GetCacheView method is:
2351 %
2352 %      PixelPacket *GetCacheView(CacheView *cache_view,const long x,
2353 %        const long y,const unsigned long columns,const unsigned long rows)
2354 %
2355 %  A description of each parameter follows:
2356 %
2357 %    o cache_view: the address of a structure of type CacheView.
2358 %
2359 %    o x,y,columns,rows:  These values define the perimeter of a region of
2360 %      pixels.
2361 %
2362 */
2363 MagickExport PixelPacket *GetCacheView(CacheView *cache_view,const long x,
2364   const long y,const unsigned long columns,const unsigned long rows)
2365 {
2366   PixelPacket
2367     *pixels;
2368
2369   pixels=GetCacheViewAuthenticPixels(cache_view,x,y,columns,rows,
2370     GetCacheViewException(cache_view));
2371   return(pixels);
2372 }
2373 \f
2374 /*
2375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2376 %                                                                             %
2377 %                                                                             %
2378 %                                                                             %
2379 %   G e t C a c h e V i e w I n d e x e s                                     %
2380 %                                                                             %
2381 %                                                                             %
2382 %                                                                             %
2383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2384 %
2385 %  GetCacheViewIndexes() returns the indexes associated with the specified
2386 %  view.
2387 %
2388 %  Deprecated, replace with:
2389 %
2390 %    GetCacheViewAuthenticIndexQueue(cache_view);
2391 %
2392 %  The format of the GetCacheViewIndexes method is:
2393 %
2394 %      IndexPacket *GetCacheViewIndexes(CacheView *cache_view)
2395 %
2396 %  A description of each parameter follows:
2397 %
2398 %    o cache_view: the cache view.
2399 %
2400 */
2401 MagickExport IndexPacket *GetCacheViewIndexes(CacheView *cache_view)
2402 {
2403   return(GetCacheViewAuthenticIndexQueue(cache_view));
2404 }
2405 \f
2406 /*
2407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2408 %                                                                             %
2409 %                                                                             %
2410 %                                                                             %
2411 %   G e t C a c h e V i e w P i x e l s                                       %
2412 %                                                                             %
2413 %                                                                             %
2414 %                                                                             %
2415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2416 %
2417 %  GetCacheViewPixels() gets pixels from the in-memory or disk pixel cache as
2418 %  defined by the geometry parameters.   A pointer to the pixels is returned if
2419 %  the pixels are transferred, otherwise a NULL is returned.
2420 %
2421 %  Deprecated, replace with:
2422 %
2423 %    GetCacheViewAuthenticPixels(cache_view,x,y,columns,rows,
2424 %      GetCacheViewException(cache_view));
2425 %
2426 %  The format of the GetCacheViewPixels method is:
2427 %
2428 %      PixelPacket *GetCacheViewPixels(CacheView *cache_view,const long x,
2429 %        const long y,const unsigned long columns,const unsigned long rows)
2430 %
2431 %  A description of each parameter follows:
2432 %
2433 %    o cache_view: the cache view.
2434 %
2435 %    o x,y,columns,rows:  These values define the perimeter of a region of
2436 %      pixels.
2437 %
2438 */
2439 MagickExport PixelPacket *GetCacheViewPixels(CacheView *cache_view,const long x,
2440   const long y,const unsigned long columns,const unsigned long rows)
2441 {
2442   PixelPacket
2443     *pixels;
2444
2445   pixels=GetCacheViewAuthenticPixels(cache_view,x,y,columns,rows,
2446     GetCacheViewException(cache_view));
2447   return(pixels);
2448 }
2449 \f
2450 /*
2451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2452 %                                                                             %
2453 %                                                                             %
2454 %                                                                             %
2455 %   G e t I m a g e A t t r i b u t e                                         %
2456 %                                                                             %
2457 %                                                                             %
2458 %                                                                             %
2459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2460 %
2461 %  GetImageAttribute() searches the list of image attributes and returns
2462 %  a pointer to the attribute if it exists otherwise NULL.
2463 %
2464 %  The format of the GetImageAttribute method is:
2465 %
2466 %      const ImageAttribute *GetImageAttribute(const Image *image,
2467 %        const char *key)
2468 %
2469 %  A description of each parameter follows:
2470 %
2471 %    o image: the image.
2472 %
2473 %    o key:  These character strings are the name of an image attribute to
2474 %      return.
2475 %
2476 */
2477
2478 static void *DestroyAttribute(void *attribute)
2479 {
2480   register ImageAttribute
2481     *p;
2482
2483   p=(ImageAttribute *) attribute;
2484   if (p->value != (char *) NULL)
2485     p->value=DestroyString(p->value);
2486   return(RelinquishMagickMemory(p));
2487 }
2488
2489 MagickExport const ImageAttribute *GetImageAttribute(const Image *image,
2490   const char *key)
2491 {
2492   const char
2493     *value;
2494
2495   ImageAttribute
2496     *attribute;
2497
2498   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.3.1");
2499   value=GetImageProperty(image,key);
2500   if (value == (const char *) NULL)
2501     return((const ImageAttribute *) NULL);
2502   if (image->attributes == (void *) NULL)
2503     ((Image *) image)->attributes=NewSplayTree(CompareSplayTreeString,
2504       RelinquishMagickMemory,DestroyAttribute);
2505   else
2506     {
2507       const ImageAttribute
2508         *attribute;
2509
2510       attribute=(const ImageAttribute *) GetValueFromSplayTree((SplayTreeInfo *)
2511         image->attributes,key);
2512       if (attribute != (const ImageAttribute *) NULL)
2513         return(attribute);
2514     }
2515   attribute=(ImageAttribute *) AcquireAlignedMemory(1,sizeof(*attribute));
2516   if (attribute == (ImageAttribute *) NULL)
2517     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
2518   (void) ResetMagickMemory(attribute,0,sizeof(*attribute));
2519   attribute->key=ConstantString(key);
2520   attribute->value=ConstantString(value);
2521   (void) AddValueToSplayTree((SplayTreeInfo *) ((Image *) image)->attributes,
2522     attribute->key,attribute);
2523   return((const ImageAttribute *) attribute);
2524 }
2525 \f
2526 /*
2527 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2528 %                                                                             %
2529 %                                                                             %
2530 %                                                                             %
2531 %   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                 %
2532 %                                                                             %
2533 %                                                                             %
2534 %                                                                             %
2535 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2536 %
2537 %  GetImageClippingPathAttribute() searches the list of image attributes and
2538 %  returns a pointer to a clipping path if it exists otherwise NULL.
2539 %
2540 %  Deprecated, replace with:
2541 %
2542 %    GetImageAttribute(image,"8BIM:1999,2998");
2543 %
2544 %  The format of the GetImageClippingPathAttribute method is:
2545 %
2546 %      const ImageAttribute *GetImageClippingPathAttribute(Image *image)
2547 %
2548 %  A description of each parameter follows:
2549 %
2550 %    o attribute:  Method GetImageClippingPathAttribute returns the clipping
2551 %      path if it exists otherwise NULL.
2552 %
2553 %    o image: the image.
2554 %
2555 */
2556 MagickExport const ImageAttribute *GetImageClippingPathAttribute(Image *image)
2557 {
2558   return(GetImageAttribute(image,"8BIM:1999,2998"));
2559 }
2560 \f
2561 /*
2562 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2563 %                                                                             %
2564 %                                                                             %
2565 %                                                                             %
2566 %   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                       %
2567 %                                                                             %
2568 %                                                                             %
2569 %                                                                             %
2570 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2571 %
2572 %  GetImageFromMagickRegistry() gets an image from the registry as defined by
2573 %  its name.  If the image is not found, a NULL image is returned.
2574 %
2575 %  Deprecated, replace with:
2576 %
2577 %    GetImageRegistry(ImageRegistryType,name,exception);
2578 %
2579 %  The format of the GetImageFromMagickRegistry method is:
2580 %
2581 %      Image *GetImageFromMagickRegistry(const char *name,long *id,
2582 %        ExceptionInfo *exception)
2583 %
2584 %  A description of each parameter follows:
2585 %
2586 %    o name: the name of the image to retrieve from the registry.
2587 %
2588 %    o id: the registry id.
2589 %
2590 %    o exception: return any errors or warnings in this structure.
2591 %
2592 */
2593 MagickExport Image *GetImageFromMagickRegistry(const char *name,long *id,
2594   ExceptionInfo *exception)
2595 {
2596   *id=0L;
2597   return((Image *) GetImageRegistry(ImageRegistryType,name,exception));
2598 }
2599 \f
2600 /*
2601 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2602 %                                                                             %
2603 %                                                                             %
2604 %                                                                             %
2605 %   G e t M a g i c k R e g i s t r y                                         %
2606 %                                                                             %
2607 %                                                                             %
2608 %                                                                             %
2609 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2610 %
2611 %  GetMagickRegistry() gets a blob from the registry as defined by the id.  If
2612 %  the blob that matches the id is not found, NULL is returned.
2613 %
2614 %  The format of the GetMagickRegistry method is:
2615 %
2616 %      const void *GetMagickRegistry(const long id,RegistryType *type,
2617 %        size_t *length,ExceptionInfo *exception)
2618 %
2619 %  A description of each parameter follows:
2620 %
2621 %    o id: the registry id.
2622 %
2623 %    o type: the registry type.
2624 %
2625 %    o length: the blob length in number of bytes.
2626 %
2627 %    o exception: return any errors or warnings in this structure.
2628 %
2629 */
2630 MagickExport void *GetMagickRegistry(const long id,RegistryType *type,
2631   size_t *length,ExceptionInfo *exception)
2632 {
2633   char
2634     key[MaxTextExtent];
2635
2636   void
2637     *blob;
2638
2639   *type=UndefinedRegistryType;
2640   *length=0;
2641   (void) FormatMagickString(key,MaxTextExtent,"%ld\n",id);
2642   blob=(void *) GetImageRegistry(ImageRegistryType,key,exception);
2643   if (blob != (void *) NULL)
2644     return(blob);
2645   blob=(void *) GetImageRegistry(ImageInfoRegistryType,key,exception);
2646   if (blob != (void *) NULL)
2647     return(blob);
2648   return((void *) GetImageRegistry(UndefinedRegistryType,key,exception));
2649 }
2650 \f
2651 /*
2652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2653 %                                                                             %
2654 %                                                                             %
2655 %                                                                             %
2656 %   G e t I m a g e G e o m e t r y                                           %
2657 %                                                                             %
2658 %                                                                             %
2659 %                                                                             %
2660 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2661 %
2662 %  GetImageGeometry() returns a region as defined by the geometry string with
2663 %  respect to the image and its gravity.
2664 %
2665 %  Deprecated, replace with:
2666 %
2667 %    if (size_to_fit != MagickFalse)
2668 %      ParseRegionGeometry(image,geometry,region_info,&image->exception); else
2669 %      ParsePageGeometry(image,geometry,region_info,&image->exception);
2670 %
2671 %  The format of the GetImageGeometry method is:
2672 %
2673 %      int GetImageGeometry(Image *image,const char *geometry,
2674 %        const unsigned int size_to_fit,RectangeInfo *region_info)
2675 %
2676 %  A description of each parameter follows:
2677 %
2678 %    o flags:  Method GetImageGeometry returns a bitmask that indicates
2679 %      which of the four values were located in the geometry string.
2680 %
2681 %    o geometry:  The geometry (e.g. 100x100+10+10).
2682 %
2683 %    o size_to_fit:  A value other than 0 means to scale the region so it
2684 %      fits within the specified width and height.
2685 %
2686 %    o region_info: the region as defined by the geometry string with
2687 %      respect to the image and its gravity.
2688 %
2689 */
2690 MagickExport int GetImageGeometry(Image *image,const char *geometry,
2691   const unsigned int size_to_fit,RectangleInfo *region_info)
2692 {
2693   if (image->debug != MagickFalse)
2694     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.4");
2695   if (size_to_fit != MagickFalse)
2696     return((int) ParseRegionGeometry(image,geometry,region_info,&image->exception));
2697   return((int) ParsePageGeometry(image,geometry,region_info,&image->exception));
2698 }
2699 \f
2700 /*
2701 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2702 %                                                                             %
2703 %                                                                             %
2704 %                                                                             %
2705 %   G e t I m a g e L i s t                                                   %
2706 %                                                                             %
2707 %                                                                             %
2708 %                                                                             %
2709 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2710 %
2711 %  GetImageList() returns an image at the specified position in the list.
2712 %
2713 %  Deprecated, replace with:
2714 %
2715 %    CloneImage(GetImageFromList(images,(long) offset),0,0,MagickTrue,
2716 %      exception);
2717 %
2718 %  The format of the GetImageList method is:
2719 %
2720 %      Image *GetImageList(const Image *images,const long offset,
2721 %        ExceptionInfo *exception)
2722 %
2723 %  A description of each parameter follows:
2724 %
2725 %    o images: the image list.
2726 %
2727 %    o offset: the position within the list.
2728 %
2729 %    o exception: return any errors or warnings in this structure.
2730 %
2731 */
2732 MagickExport Image *GetImageList(const Image *images,const long offset,
2733   ExceptionInfo *exception)
2734 {
2735   Image
2736     *image;
2737
2738   if (images->debug != MagickFalse)
2739     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
2740   image=CloneImage(GetImageFromList(images,(long) offset),0,0,MagickTrue,
2741     exception);
2742   return(image);
2743 }
2744 \f
2745 /*
2746 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2747 %                                                                             %
2748 %                                                                             %
2749 %                                                                             %
2750 %   G e t I m a g e L i s t I n d e x                                         %
2751 %                                                                             %
2752 %                                                                             %
2753 %                                                                             %
2754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2755 %
2756 %  GetImageListIndex() returns the position in the list of the specified
2757 %  image.
2758 %
2759 %  Deprecated, replace with:
2760 %
2761 %    GetImageIndexInList(images);
2762 %
2763 %  The format of the GetImageListIndex method is:
2764 %
2765 %      long GetImageListIndex(const Image *images)
2766 %
2767 %  A description of each parameter follows:
2768 %
2769 %    o images: the image list.
2770 %
2771 */
2772 MagickExport long GetImageListIndex(const Image *images)
2773 {
2774   if (images->debug != MagickFalse)
2775     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
2776   return(GetImageIndexInList(images));
2777 }
2778 \f
2779 /*
2780 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2781 %                                                                             %
2782 %                                                                             %
2783 %                                                                             %
2784 %   G e t I m a g e L i s t S i z e                                           %
2785 %                                                                             %
2786 %                                                                             %
2787 %                                                                             %
2788 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2789 %
2790 %  GetImageListSize() returns the number of images in the list.
2791 %
2792 %  Deprecated, replace with:
2793 %
2794 %    GetImageListLength(images);
2795 %
2796 %  The format of the GetImageListSize method is:
2797 %
2798 %      unsigned long GetImageListSize(const Image *images)
2799 %
2800 %  A description of each parameter follows:
2801 %
2802 %    o images: the image list.
2803 %
2804 */
2805 MagickExport unsigned long GetImageListSize(const Image *images)
2806 {
2807   if (images->debug != MagickFalse)
2808     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
2809   return(GetImageListLength(images));
2810 }
2811 \f
2812 /*
2813 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2814 %                                                                             %
2815 %                                                                             %
2816 %                                                                             %
2817 %   G e t I m a g e P i x e l s                                               %
2818 %                                                                             %
2819 %                                                                             %
2820 %                                                                             %
2821 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2822 %
2823 %  GetImagePixels() obtains a pixel region for read/write access. If the
2824 %  region is successfully accessed, a pointer to a PixelPacket array
2825 %  representing the region is returned, otherwise NULL is returned.
2826 %
2827 %  The returned pointer may point to a temporary working copy of the pixels
2828 %  or it may point to the original pixels in memory. Performance is maximized
2829 %  if the selected region is part of one row, or one or more full rows, since
2830 %  then there is opportunity to access the pixels in-place (without a copy)
2831 %  if the image is in RAM, or in a memory-mapped file. The returned pointer
2832 %  should *never* be deallocated by the user.
2833 %
2834 %  Pixels accessed via the returned pointer represent a simple array of type
2835 %  PixelPacket. If the image type is CMYK or if the storage class is
2836 %  PseduoClass, call GetAuthenticIndexQueue() after invoking GetImagePixels()
2837 %  to obtain the black color component or colormap indexes (of type IndexPacket)
2838 %  corresponding to the region.  Once the PixelPacket (and/or IndexPacket)
2839 %  array has been updated, the changes must be saved back to the underlying
2840 %  image using SyncAuthenticPixels() or they may be lost.
2841 %
2842 %  Deprecated, replace with:
2843 %
2844 %    GetAuthenticPixels(image,x,y,columns,rows,&image->exception);
2845 %
2846 %  The format of the GetImagePixels() method is:
2847 %
2848 %      PixelPacket *GetImagePixels(Image *image,const long x,const long y,
2849 %        const unsigned long columns,const unsigned long rows)
2850 %
2851 %  A description of each parameter follows:
2852 %
2853 %    o image: the image.
2854 %
2855 %    o x,y,columns,rows:  These values define the perimeter of a region of
2856 %      pixels.
2857 %
2858 */
2859 MagickExport PixelPacket *GetImagePixels(Image *image,const long x,const long y,
2860   const unsigned long columns,const unsigned long rows)
2861 {
2862   return(GetAuthenticPixels(image,x,y,columns,rows,&image->exception));
2863 }
2864 \f
2865 /*
2866 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2867 %                                                                             %
2868 %                                                                             %
2869 %                                                                             %
2870 %   G e t I n d e x e s                                                       %
2871 %                                                                             %
2872 %                                                                             %
2873 %                                                                             %
2874 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2875 %
2876 %  GetIndexes() returns the black channel or the colormap indexes associated
2877 %  with the last call to QueueAuthenticPixels() or GetVirtualPixels().  NULL is
2878 %  returned if the black channel or colormap indexes are not available.
2879 %
2880 %  Deprecated, replace with:
2881 %
2882 %    GetAuthenticIndexQueue(image);
2883 %
2884 %  The format of the GetIndexes() method is:
2885 %
2886 %      IndexPacket *GetIndexes(const Image *image)
2887 %
2888 %  A description of each parameter follows:
2889 %
2890 %    o indexes: GetIndexes() returns the indexes associated with the last
2891 %      call to QueueAuthenticPixels() or GetAuthenticPixels().
2892 %
2893 %    o image: the image.
2894 %
2895 */
2896 MagickExport IndexPacket *GetIndexes(const Image *image)
2897 {
2898   return(GetAuthenticIndexQueue(image));
2899 }
2900 \f
2901 /*
2902 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2903 %                                                                             %
2904 %                                                                             %
2905 %                                                                             %
2906 +   G e t M a g i c k G e o m e t r y                                         %
2907 %                                                                             %
2908 %                                                                             %
2909 %                                                                             %
2910 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2911 %
2912 %  GetMagickGeometry() is similar to GetGeometry() except the returned
2913 %  geometry is modified as determined by the meta characters:  %, !, <, >,
2914 %  and ~.
2915 %
2916 %  Deprecated, replace with:
2917 %
2918 %    ParseMetaGeometry(geometry,x,y,width,height);
2919 %
2920 %  The format of the GetMagickGeometry method is:
2921 %
2922 %      unsigned int GetMagickGeometry(const char *geometry,long *x,long *y,
2923 %        unsigned long *width,unsigned long *height)
2924 %
2925 %  A description of each parameter follows:
2926 %
2927 %    o geometry:  Specifies a character string representing the geometry
2928 %      specification.
2929 %
2930 %    o x,y:  A pointer to an integer.  The x and y offset as determined by
2931 %      the geometry specification is returned here.
2932 %
2933 %    o width,height:  A pointer to an unsigned integer.  The width and height
2934 %      as determined by the geometry specification is returned here.
2935 %
2936 */
2937 MagickExport unsigned int GetMagickGeometry(const char *geometry,long *x,
2938   long *y,unsigned long *width,unsigned long *height)
2939 {
2940   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.3");
2941   return(ParseMetaGeometry(geometry,x,y,width,height));
2942 }
2943 \f
2944 /*
2945 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2946 %                                                                             %
2947 %                                                                             %
2948 %                                                                             %
2949 %   G e t N e x t I m a g e                                                   %
2950 %                                                                             %
2951 %                                                                             %
2952 %                                                                             %
2953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2954 %
2955 %  GetNextImage() returns the next image in a list.
2956 %
2957 %  Deprecated, replace with:
2958 %
2959 %    GetNextImageInList(images);
2960 %
2961 %  The format of the GetNextImage method is:
2962 %
2963 %      Image *GetNextImage(const Image *images)
2964 %
2965 %  A description of each parameter follows:
2966 %
2967 %    o images: the image list.
2968 %
2969 */
2970 MagickExport Image *GetNextImage(const Image *images)
2971 {
2972   if (images->debug != MagickFalse)
2973     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
2974   return(GetNextImageInList(images));
2975 }
2976 \f
2977 /*
2978 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2979 %                                                                             %
2980 %                                                                             %
2981 %                                                                             %
2982 %   G e t N e x t I m a g e A t t r i b u t e                                 %
2983 %                                                                             %
2984 %                                                                             %
2985 %                                                                             %
2986 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2987 %
2988 %  GetNextImageAttribute() gets the next image attribute.
2989 %
2990 %  Deprecated, replace with:
2991 %
2992 %    const char *property;
2993 %    property=GetNextImageProperty(image);
2994 %    if (property != (const char *) NULL) 
2995 %      GetImageAttribute(image,property);
2996 %
2997 %  The format of the GetNextImageAttribute method is:
2998 %
2999 %      const ImageAttribute *GetNextImageAttribute(const Image *image)
3000 %
3001 %  A description of each parameter follows:
3002 %
3003 %    o image: the image.
3004 %
3005 */
3006 MagickExport const ImageAttribute *GetNextImageAttribute(const Image *image)
3007 {
3008   const char
3009     *property;
3010
3011   property=GetNextImageProperty(image);
3012   if (property == (const char *) NULL)
3013     return((const ImageAttribute *) NULL);
3014   return(GetImageAttribute(image,property));
3015 }
3016 \f
3017 /*
3018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3019 %                                                                             %
3020 %                                                                             %
3021 %                                                                             %
3022 %   G e t N u m b e r S c e n e s                                             %
3023 %                                                                             %
3024 %                                                                             %
3025 %                                                                             %
3026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3027 %
3028 %  GetNumberScenes() returns the number of images in the list.
3029 %
3030 %  Deprecated, replace with:
3031 %
3032 %    GetImageListLength(image);
3033 %
3034 %  The format of the GetNumberScenes method is:
3035 %
3036 %      unsigned int GetNumberScenes(const Image *images)
3037 %
3038 %  A description of each parameter follows:
3039 %
3040 %    o images: the image list.
3041 %
3042 */
3043 MagickExport unsigned int GetNumberScenes(const Image *image)
3044 {
3045   if (image->debug != MagickFalse)
3046     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
3047   return((unsigned int) GetImageListLength(image));
3048 }
3049 \f
3050 /*
3051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3052 %                                                                             %
3053 %                                                                             %
3054 %                                                                             %
3055 %   G e t O n e P i x e l                                                     %
3056 %                                                                             %
3057 %                                                                             %
3058 %                                                                             %
3059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3060 %
3061 %  GetOnePixel() returns a single pixel at the specified (x,y) location.
3062 %  The image background color is returned if an error occurs.
3063 %
3064 %  Deprecated, replace with:
3065 %
3066 %    GetOneAuthenticPixel(image,x,y,&pixel,&image->exception);
3067 %
3068 %  The format of the GetOnePixel() method is:
3069 %
3070 %      PixelPacket GetOnePixel(const Image image,const long x,const long y)
3071 %
3072 %  A description of each parameter follows:
3073 %
3074 %    o image: the image.
3075 %
3076 %    o x,y:  These values define the location of the pixel to return.
3077 %
3078 */
3079 MagickExport PixelPacket GetOnePixel(Image *image,const long x,const long y)
3080 {
3081   PixelPacket
3082     pixel;
3083
3084   (void) GetOneAuthenticPixel(image,x,y,&pixel,&image->exception);
3085   return(pixel);
3086 }
3087 \f
3088 /*
3089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3090 %                                                                             %
3091 %                                                                             %
3092 %                                                                             %
3093 %   G e t P i x e l s                                                         %
3094 %                                                                             %
3095 %                                                                             %
3096 %                                                                             %
3097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3098 %
3099 %  GetPixels() returns the pixels associated with the last call to
3100 %  QueueAuthenticPixels() or GetAuthenticPixels().
3101 %
3102 %  Deprecated, replace with:
3103 %
3104 %    GetAuthenticPixelQueue(image);
3105 %
3106 %  The format of the GetPixels() method is:
3107 %
3108 %      PixelPacket *GetPixels(const Image image)
3109 %
3110 %  A description of each parameter follows:
3111 %
3112 %    o pixels: GetPixels() returns the pixels associated with the last call
3113 %      to QueueAuthenticPixels() or GetAuthenticPixels().
3114 %
3115 %    o image: the image.
3116 %
3117 */
3118 MagickExport PixelPacket *GetPixels(const Image *image)
3119 {
3120   return(GetAuthenticPixelQueue(image));
3121 }
3122 \f
3123 /*
3124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3125 %                                                                             %
3126 %                                                                             %
3127 %                                                                             %
3128 %   G e t P r e v i o u s I m a g e                                           %
3129 %                                                                             %
3130 %                                                                             %
3131 %                                                                             %
3132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3133 %
3134 %  GetPreviousImage() returns the previous image in a list.
3135 %
3136 %  Deprecated, replace with:
3137 %
3138 %    GetPreviousImageInList(images));
3139 %
3140 %  The format of the GetPreviousImage method is:
3141 %
3142 %      Image *GetPreviousImage(const Image *images)
3143 %
3144 %  A description of each parameter follows:
3145 %
3146 %    o images: the image list.
3147 %
3148 */
3149 MagickExport Image *GetPreviousImage(const Image *images)
3150 {
3151   if (images->debug != MagickFalse)
3152     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
3153   return(GetPreviousImageInList(images));
3154 }
3155 \f
3156 /*
3157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3158 %                                                                             %
3159 %                                                                             %
3160 %                                                                             %
3161 %   H S L T r a n s f o r m                                                   %
3162 %                                                                             %
3163 %                                                                             %
3164 %                                                                             %
3165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3166 %
3167 %  HSLTransform() converts a (hue, saturation, lightness) to a (red, green,
3168 %  blue) triple.
3169 %
3170 %  The format of the HSLTransformImage method is:
3171 %
3172 %      void HSLTransform(const double hue,const double saturation,
3173 %        const double lightness,Quantum *red,Quantum *green,Quantum *blue)
3174 %
3175 %  A description of each parameter follows:
3176 %
3177 %    o hue, saturation, lightness: A double value representing a
3178 %      component of the HSL color space.
3179 %
3180 %    o red, green, blue: A pointer to a pixel component of type Quantum.
3181 %
3182 */
3183
3184 static inline MagickRealType HueToRGB(MagickRealType m1,MagickRealType m2,
3185   MagickRealType hue)
3186 {
3187   if (hue < 0.0)
3188     hue+=1.0;
3189   if (hue > 1.0)
3190     hue-=1.0;
3191   if ((6.0*hue) < 1.0)
3192     return(m1+6.0*(m2-m1)*hue);
3193   if ((2.0*hue) < 1.0)
3194     return(m2);
3195   if ((3.0*hue) < 2.0)
3196     return(m1+6.0*(m2-m1)*(2.0/3.0-hue));
3197   return(m1);
3198 }
3199
3200 MagickExport void HSLTransform(const double hue,const double saturation,
3201   const double lightness,Quantum *red,Quantum *green,Quantum *blue)
3202 {
3203   MagickRealType
3204     b,
3205     g,
3206     r,
3207     m1,
3208     m2;
3209
3210   /*
3211     Convert HSL to RGB colorspace.
3212   */
3213   assert(red != (Quantum *) NULL);
3214   assert(green != (Quantum *) NULL);
3215   assert(blue != (Quantum *) NULL);
3216   if (lightness <= 0.5)
3217     m2=lightness*(saturation+1.0);
3218   else
3219     m2=lightness+saturation-lightness*saturation;
3220   m1=2.0*lightness-m2;
3221   r=HueToRGB(m1,m2,hue+1.0/3.0);
3222   g=HueToRGB(m1,m2,hue);
3223   b=HueToRGB(m1,m2,hue-1.0/3.0);
3224   *red=ClampToQuantum((MagickRealType) QuantumRange*r);
3225   *green=ClampToQuantum((MagickRealType) QuantumRange*g);
3226   *blue=ClampToQuantum((MagickRealType) QuantumRange*b);
3227 }
3228 \f
3229 /*
3230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3231 %                                                                             %
3232 %                                                                             %
3233 %                                                                             %
3234 %   I d e n t i t y A f f i n e                                               %
3235 %                                                                             %
3236 %                                                                             %
3237 %                                                                             %
3238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3239 %
3240 %  IdentityAffine() initializes the affine transform to the identity matrix.
3241 %
3242 %  The format of the IdentityAffine method is:
3243 %
3244 %      IdentityAffine(AffineMatrix *affine)
3245 %
3246 %  A description of each parameter follows:
3247 %
3248 %    o affine: A pointer the affine transform of type AffineMatrix.
3249 %
3250 */
3251 MagickExport void IdentityAffine(AffineMatrix *affine)
3252 {
3253   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3254   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
3255   assert(affine != (AffineMatrix *) NULL);
3256   (void) ResetMagickMemory(affine,0,sizeof(AffineMatrix));
3257   affine->sx=1.0;
3258   affine->sy=1.0;
3259 }
3260 \f
3261 /*
3262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3263 %                                                                             %
3264 %                                                                             %
3265 %                                                                             %
3266 %   I n i t i a l i z e M a g i c k                                           %
3267 %                                                                             %
3268 %                                                                             %
3269 %                                                                             %
3270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3271 %
3272 %  InitializeMagick() initializes the ImageMagick environment.
3273 %
3274 %  Deprecated, replace with:
3275 %
3276 %    MagickCoreGenesis(path,MagickFalse);
3277 %
3278 %  The format of the InitializeMagick function is:
3279 %
3280 %      InitializeMagick(const char *path)
3281 %
3282 %  A description of each parameter follows:
3283 %
3284 %    o path: the execution path of the current ImageMagick client.
3285 %
3286 */
3287 MagickExport void InitializeMagick(const char *path)
3288 {
3289   MagickCoreGenesis(path,MagickFalse);
3290 }
3291 \f
3292 /*
3293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3294 %                                                                             %
3295 %                                                                             %
3296 %                                                                             %
3297 %   I n t e r p o l a t e P i x e l C o l o r                                 %
3298 %                                                                             %
3299 %                                                                             %
3300 %                                                                             %
3301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3302 %
3303 %  InterpolatePixelColor() applies bi-linear or tri-linear interpolation
3304 %  between a pixel and it's neighbors.
3305 %
3306 %  The format of the InterpolatePixelColor method is:
3307 %
3308 %      MagickPixelPacket InterpolatePixelColor(const Image *image,
3309 %        CacheView *view_info,InterpolatePixelMethod method,const double x,
3310 %        const double y,ExceptionInfo *exception)
3311 %
3312 %  A description of each parameter follows:
3313 %
3314 %    o image: the image.
3315 %
3316 %    o image_view: the image cache view.
3317 %
3318 %    o type:  the type of pixel color interpolation.
3319 %
3320 %    o x,y: A double representing the current (x,y) position of the pixel.
3321 %
3322 %    o exception: return any errors or warnings in this structure.
3323 %
3324 */
3325
3326 static inline double MagickMax(const double x,const double y)
3327 {
3328   if (x > y)
3329     return(x);
3330   return(y);
3331 }
3332
3333 static void BicubicInterpolate(const MagickPixelPacket *pixels,const double dx,
3334   MagickPixelPacket *pixel)
3335 {
3336   MagickRealType
3337     dx2,
3338     p,
3339     q,
3340     r,
3341     s;
3342
3343   dx2=dx*dx;
3344   p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red);
3345   q=(pixels[0].red-pixels[1].red)-p;
3346   r=pixels[2].red-pixels[0].red;
3347   s=pixels[1].red;
3348   pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
3349   p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green);
3350   q=(pixels[0].green-pixels[1].green)-p;
3351   r=pixels[2].green-pixels[0].green;
3352   s=pixels[1].green;
3353   pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
3354   p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue);
3355   q=(pixels[0].blue-pixels[1].blue)-p;
3356   r=pixels[2].blue-pixels[0].blue;
3357   s=pixels[1].blue;
3358   pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
3359   p=(pixels[3].opacity-pixels[2].opacity)-(pixels[0].opacity-pixels[1].opacity);
3360   q=(pixels[0].opacity-pixels[1].opacity)-p;
3361   r=pixels[2].opacity-pixels[0].opacity;
3362   s=pixels[1].opacity;
3363   pixel->opacity=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
3364   if (pixel->colorspace == CMYKColorspace)
3365     {
3366       p=(pixels[3].index-pixels[2].index)-(pixels[0].index-pixels[1].index);
3367       q=(pixels[0].index-pixels[1].index)-p;
3368       r=pixels[2].index-pixels[0].index;
3369       s=pixels[1].index;
3370       pixel->index=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
3371     }
3372 }
3373
3374 static inline MagickRealType CubicWeightingFunction(const MagickRealType x)
3375 {
3376   MagickRealType
3377     alpha,
3378     gamma;
3379
3380   alpha=MagickMax(x+2.0,0.0);
3381   gamma=1.0*alpha*alpha*alpha;
3382   alpha=MagickMax(x+1.0,0.0);
3383   gamma-=4.0*alpha*alpha*alpha;
3384   alpha=MagickMax(x+0.0,0.0);
3385   gamma+=6.0*alpha*alpha*alpha;
3386   alpha=MagickMax(x-1.0,0.0);
3387   gamma-=4.0*alpha*alpha*alpha;
3388   return(gamma/6.0);
3389 }
3390
3391 static inline double MeshInterpolate(const PointInfo *delta,const double p,
3392   const double x,const double y)
3393 {
3394   return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
3395 }
3396
3397 static inline long NearestNeighbor(MagickRealType x)
3398 {
3399   if (x >= 0.0)
3400     return((long) (x+0.5));
3401   return((long) (x-0.5));
3402 }
3403
3404 MagickExport MagickPixelPacket InterpolatePixelColor(const Image *image,
3405   CacheView *image_view,const InterpolatePixelMethod method,const double x,
3406   const double y,ExceptionInfo *exception)
3407 {
3408   MagickPixelPacket
3409     pixel;
3410
3411   register const IndexPacket
3412     *indexes;
3413
3414   register const PixelPacket
3415     *p;
3416
3417   register long
3418     i;
3419
3420   assert(image != (Image *) NULL);
3421   assert(image->signature == MagickSignature);
3422   assert(image_view != (CacheView *) NULL);
3423   GetMagickPixelPacket(image,&pixel);
3424   switch (method)
3425   {
3426     case AverageInterpolatePixel:
3427     {
3428       MagickPixelPacket
3429         pixels[16];
3430
3431       MagickRealType
3432         alpha[16],
3433         gamma;
3434
3435       p=GetCacheViewVirtualPixels(image_view,(long) floor(x)-1,(long) floor(y)-
3436         1,4,4,exception);
3437       if (p == (const PixelPacket *) NULL)
3438         break;
3439       indexes=GetCacheViewVirtualIndexQueue(image_view);
3440       for (i=0; i < 16L; i++)
3441       {
3442         GetMagickPixelPacket(image,pixels+i);
3443         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
3444         alpha[i]=1.0;
3445         if (image->matte != MagickFalse)
3446           {
3447             alpha[i]=QuantumScale*((MagickRealType) GetAlphaPixelComponent(p));
3448             pixels[i].red*=alpha[i];
3449             pixels[i].green*=alpha[i];
3450             pixels[i].blue*=alpha[i];
3451             if (image->colorspace == CMYKColorspace)
3452               pixels[i].index*=alpha[i];
3453           }
3454         gamma=alpha[i];
3455         gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3456         pixel.red+=gamma*0.0625*pixels[i].red;
3457         pixel.green+=gamma*0.0625*pixels[i].green;
3458         pixel.blue+=gamma*0.0625*pixels[i].blue;
3459         pixel.opacity+=0.0625*pixels[i].opacity;
3460         if (image->colorspace == CMYKColorspace)
3461           pixel.index+=gamma*0.0625*pixels[i].index;
3462         p++;
3463       }
3464       break;
3465     }
3466     case BicubicInterpolatePixel:
3467     {
3468       MagickPixelPacket
3469         pixels[16],
3470         u[4];
3471
3472       MagickRealType
3473         alpha[16];
3474
3475       PointInfo
3476         delta;
3477
3478       p=GetCacheViewVirtualPixels(image_view,(long) floor(x)-1,(long) floor(y)-
3479         1,4,4,exception);
3480       if (p == (const PixelPacket *) NULL)
3481         break;
3482       indexes=GetCacheViewVirtualIndexQueue(image_view);
3483       for (i=0; i < 16L; i++)
3484       {
3485         GetMagickPixelPacket(image,pixels+i);
3486         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
3487         alpha[i]=1.0;
3488         if (image->matte != MagickFalse)
3489           {
3490             alpha[i]=QuantumScale*((MagickRealType) GetAlphaPixelComponent(p));
3491             pixels[i].red*=alpha[i];
3492             pixels[i].green*=alpha[i];
3493             pixels[i].blue*=alpha[i];
3494             if (image->colorspace == CMYKColorspace)
3495               pixels[i].index*=alpha[i];
3496           }
3497         p++;
3498       }
3499       delta.x=x-floor(x);
3500       for (i=0; i < 4L; i++)
3501         BicubicInterpolate(pixels+4*i,delta.x,u+i);
3502       delta.y=y-floor(y);
3503       BicubicInterpolate(u,delta.y,&pixel);
3504       break;
3505     }
3506     case BilinearInterpolatePixel:
3507     default:
3508     {
3509       MagickPixelPacket
3510         pixels[16];
3511
3512       MagickRealType
3513         alpha[16],
3514         gamma;
3515
3516       PointInfo
3517         delta;
3518
3519       p=GetCacheViewVirtualPixels(image_view,(long) floor(x),(long) floor(y),2,
3520         2,exception);
3521       if (p == (const PixelPacket *) NULL)
3522         break;
3523       indexes=GetCacheViewVirtualIndexQueue(image_view);
3524       for (i=0; i < 4L; i++)
3525       {
3526         GetMagickPixelPacket(image,pixels+i);
3527         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
3528         alpha[i]=1.0;
3529         if (image->matte != MagickFalse)
3530           {
3531             alpha[i]=QuantumScale*((MagickRealType) GetAlphaPixelComponent(p));
3532             pixels[i].red*=alpha[i];
3533             pixels[i].green*=alpha[i];
3534             pixels[i].blue*=alpha[i];
3535             if (image->colorspace == CMYKColorspace)
3536               pixels[i].index*=alpha[i];
3537           }
3538         p++;
3539       }
3540       delta.x=x-floor(x);
3541       delta.y=y-floor(y);
3542       gamma=(((1.0-delta.y)*((1.0-delta.x)*alpha[0]+delta.x*alpha[1])+delta.y*
3543         ((1.0-delta.x)*alpha[2]+delta.x*alpha[3])));
3544       gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3545       pixel.red=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].red+delta.x*
3546         pixels[1].red)+delta.y*((1.0-delta.x)*pixels[2].red+delta.x*
3547         pixels[3].red));
3548       pixel.green=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].green+delta.x*
3549         pixels[1].green)+delta.y*((1.0-delta.x)*pixels[2].green+
3550         delta.x*pixels[3].green));
3551       pixel.blue=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].blue+delta.x*
3552         pixels[1].blue)+delta.y*((1.0-delta.x)*pixels[2].blue+delta.x*
3553         pixels[3].blue));
3554       pixel.opacity=((1.0-delta.y)*((1.0-delta.x)*pixels[0].opacity+delta.x*
3555         pixels[1].opacity)+delta.y*((1.0-delta.x)*pixels[2].opacity+delta.x*
3556         pixels[3].opacity));
3557       if (image->colorspace == CMYKColorspace)
3558         pixel.index=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].index+delta.x*
3559           pixels[1].index)+delta.y*((1.0-delta.x)*pixels[2].index+delta.x*
3560           pixels[3].index));
3561       break;
3562     }
3563     case FilterInterpolatePixel:
3564     {
3565       Image
3566         *excerpt_image,
3567         *filter_image;
3568
3569       MagickPixelPacket
3570         pixels[1];
3571
3572       RectangleInfo
3573         geometry;
3574
3575       geometry.width=4L;
3576       geometry.height=4L;
3577       geometry.x=(long) floor(x)-1L;
3578       geometry.y=(long) floor(y)-1L;
3579       excerpt_image=ExcerptImage(image,&geometry,exception);
3580       if (excerpt_image == (Image *) NULL)
3581         break;
3582       filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
3583         exception);
3584       excerpt_image=DestroyImage(excerpt_image);
3585       if (filter_image == (Image *) NULL)
3586         break;
3587       p=GetVirtualPixels(filter_image,0,0,1,1,exception);
3588       if (p == (const PixelPacket *) NULL)
3589         {
3590           filter_image=DestroyImage(filter_image);
3591           break;
3592         }
3593       indexes=GetVirtualIndexQueue(filter_image);
3594       GetMagickPixelPacket(image,pixels);
3595       SetMagickPixelPacket(image,p,indexes,&pixel);
3596       filter_image=DestroyImage(filter_image);
3597       break;
3598     }
3599     case IntegerInterpolatePixel:
3600     {
3601       MagickPixelPacket
3602         pixels[1];
3603
3604       p=GetCacheViewVirtualPixels(image_view,(long) floor(x),(long) floor(y),1,
3605         1,exception);
3606       if (p == (const PixelPacket *) NULL)
3607         break;
3608       indexes=GetCacheViewVirtualIndexQueue(image_view);
3609       GetMagickPixelPacket(image,pixels);
3610       SetMagickPixelPacket(image,p,indexes,&pixel);
3611       break;
3612     }
3613     case MeshInterpolatePixel:
3614     {
3615       MagickPixelPacket
3616         pixels[4];
3617
3618       MagickRealType
3619         alpha[4],
3620         gamma;
3621
3622       PointInfo
3623         delta,
3624         luminance;
3625
3626       p=GetCacheViewVirtualPixels(image_view,(long) floor(x),(long) floor(y),
3627         2,2,exception);
3628       if (p == (const PixelPacket *) NULL)
3629         break;
3630       indexes=GetCacheViewVirtualIndexQueue(image_view);
3631       for (i=0; i < 4L; i++)
3632       {
3633         GetMagickPixelPacket(image,pixels+i);
3634         SetMagickPixelPacket(image,p,indexes+i,pixels+i);
3635         alpha[i]=1.0;
3636         if (image->matte != MagickFalse)
3637           {
3638             alpha[i]=QuantumScale*((MagickRealType) GetAlphaPixelComponent(p));
3639             pixels[i].red*=alpha[i];
3640             pixels[i].green*=alpha[i];
3641             pixels[i].blue*=alpha[i];
3642             if (image->colorspace == CMYKColorspace)
3643               pixels[i].index*=alpha[i];
3644           }
3645         p++;
3646       }
3647       delta.x=x-floor(x);
3648       delta.y=y-floor(y);
3649       luminance.x=MagickPixelLuminance(pixels+0)-MagickPixelLuminance(pixels+3);
3650       luminance.y=MagickPixelLuminance(pixels+1)-MagickPixelLuminance(pixels+2);
3651       if (fabs(luminance.x) < fabs(luminance.y))
3652         {
3653           /*
3654             Diagonal 0-3 NW-SE.
3655           */
3656           if (delta.x <= delta.y)
3657             {
3658               /*
3659                 Bottom-left triangle  (pixel:2, diagonal: 0-3).
3660               */
3661               delta.y=1.0-delta.y;
3662               gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
3663               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3664               pixel.red=gamma*MeshInterpolate(&delta,pixels[2].red,
3665                 pixels[3].red,pixels[0].red);
3666               pixel.green=gamma*MeshInterpolate(&delta,pixels[2].green,
3667                 pixels[3].green,pixels[0].green);
3668               pixel.blue=gamma*MeshInterpolate(&delta,pixels[2].blue,
3669                 pixels[3].blue,pixels[0].blue);
3670               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[2].opacity,
3671                 pixels[3].opacity,pixels[0].opacity);
3672               if (image->colorspace == CMYKColorspace)
3673                 pixel.index=gamma*MeshInterpolate(&delta,pixels[2].index,
3674                   pixels[3].index,pixels[0].index);
3675             }
3676           else
3677             {
3678               /*
3679                 Top-right triangle (pixel:1, diagonal: 0-3).
3680               */
3681               delta.x=1.0-delta.x;
3682               gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
3683               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3684               pixel.red=gamma*MeshInterpolate(&delta,pixels[1].red,
3685                 pixels[0].red,pixels[3].red);
3686               pixel.green=gamma*MeshInterpolate(&delta,pixels[1].green,
3687                 pixels[0].green,pixels[3].green);
3688               pixel.blue=gamma*MeshInterpolate(&delta,pixels[1].blue,
3689                 pixels[0].blue,pixels[3].blue);
3690               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[1].opacity,
3691                 pixels[0].opacity,pixels[3].opacity);
3692               if (image->colorspace == CMYKColorspace)
3693                 pixel.index=gamma*MeshInterpolate(&delta,pixels[1].index,
3694                   pixels[0].index,pixels[3].index);
3695             }
3696         }
3697       else
3698         {
3699           /*
3700             Diagonal 1-2 NE-SW.
3701           */
3702           if (delta.x <= (1.0-delta.y))
3703             {
3704               /*
3705                 Top-left triangle (pixel 0, diagonal: 1-2).
3706               */
3707               gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
3708               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3709               pixel.red=gamma*MeshInterpolate(&delta,pixels[0].red,
3710                 pixels[1].red,pixels[2].red);
3711               pixel.green=gamma*MeshInterpolate(&delta,pixels[0].green,
3712                 pixels[1].green,pixels[2].green);
3713               pixel.blue=gamma*MeshInterpolate(&delta,pixels[0].blue,
3714                 pixels[1].blue,pixels[2].blue);
3715               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[0].opacity,
3716                 pixels[1].opacity,pixels[2].opacity);
3717               if (image->colorspace == CMYKColorspace)
3718                 pixel.index=gamma*MeshInterpolate(&delta,pixels[0].index,
3719                   pixels[1].index,pixels[2].index);
3720             }
3721           else
3722             {
3723               /*
3724                 Bottom-right triangle (pixel: 3, diagonal: 1-2).
3725               */
3726               delta.x=1.0-delta.x;
3727               delta.y=1.0-delta.y;
3728               gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
3729               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3730               pixel.red=gamma*MeshInterpolate(&delta,pixels[3].red,
3731                 pixels[2].red,pixels[1].red);
3732               pixel.green=gamma*MeshInterpolate(&delta,pixels[3].green,
3733                 pixels[2].green,pixels[1].green);
3734               pixel.blue=gamma*MeshInterpolate(&delta,pixels[3].blue,
3735                 pixels[2].blue,pixels[1].blue);
3736               pixel.opacity=gamma*MeshInterpolate(&delta,pixels[3].opacity,
3737                 pixels[2].opacity,pixels[1].opacity);
3738               if (image->colorspace == CMYKColorspace)
3739                 pixel.index=gamma*MeshInterpolate(&delta,pixels[3].index,
3740                   pixels[2].index,pixels[1].index);
3741             }
3742         }
3743       break;
3744     }
3745     case NearestNeighborInterpolatePixel:
3746     {
3747       MagickPixelPacket
3748         pixels[1];
3749
3750       p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
3751         NearestNeighbor(y),1,1,exception);
3752       if (p == (const PixelPacket *) NULL)
3753         break;
3754       indexes=GetCacheViewVirtualIndexQueue(image_view);
3755       GetMagickPixelPacket(image,pixels);
3756       SetMagickPixelPacket(image,p,indexes,&pixel);
3757       break;
3758     }
3759     case SplineInterpolatePixel:
3760     {
3761       long
3762         j,
3763         n;
3764
3765       MagickPixelPacket
3766         pixels[16];
3767
3768       MagickRealType
3769         alpha[16],
3770         dx,
3771         dy,
3772         gamma;
3773
3774       PointInfo
3775         delta;
3776
3777       p=GetCacheViewVirtualPixels(image_view,(long) floor(x)-1,(long) floor(y)-
3778         1,4,4,exception);
3779       if (p == (const PixelPacket *) NULL)
3780         break;
3781       indexes=GetCacheViewVirtualIndexQueue(image_view);
3782       n=0;
3783       delta.x=x-floor(x);
3784       delta.y=y-floor(y);
3785       for (i=(-1); i < 3L; i++)
3786       {
3787         dy=CubicWeightingFunction((MagickRealType) i-delta.y);
3788         for (j=(-1); j < 3L; j++)
3789         {
3790           GetMagickPixelPacket(image,pixels+n);
3791           SetMagickPixelPacket(image,p,indexes+n,pixels+n);
3792           alpha[n]=1.0;
3793           if (image->matte != MagickFalse)
3794             {
3795               alpha[n]=QuantumScale*((MagickRealType)
3796                 GetAlphaPixelComponent(p));
3797               pixels[n].red*=alpha[n];
3798               pixels[n].green*=alpha[n];
3799               pixels[n].blue*=alpha[n];
3800               if (image->colorspace == CMYKColorspace)
3801                 pixels[n].index*=alpha[n];
3802             }
3803           dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
3804           gamma=alpha[n];
3805           gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
3806           pixel.red+=gamma*dx*dy*pixels[n].red;
3807           pixel.green+=gamma*dx*dy*pixels[n].green;
3808           pixel.blue+=gamma*dx*dy*pixels[n].blue;
3809           if (image->matte != MagickFalse)
3810             pixel.opacity+=dx*dy*pixels[n].opacity;
3811           if (image->colorspace == CMYKColorspace)
3812             pixel.index+=gamma*dx*dy*pixels[n].index;
3813           n++;
3814           p++;
3815         }
3816       }
3817       break;
3818     }
3819   }
3820   return(pixel);
3821 }
3822 \f
3823 /*
3824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3825 %                                                                             %
3826 %                                                                             %
3827 %                                                                             %
3828 %   I n t e r p r e t I m a g e A t t r i b u t e s                           %
3829 %                                                                             %
3830 %                                                                             %
3831 %                                                                             %
3832 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3833 %
3834 %  InterpretImageAttributes() replaces any embedded formatting characters with
3835 %  the appropriate image attribute and returns the translated text.
3836 %
3837 %  Deprecated, replace with:
3838 %
3839 %    InterpretImageProperties(image_info,image,embed_text);
3840 %
3841 %  The format of the InterpretImageAttributes method is:
3842 %
3843 %      char *InterpretImageAttributes(const ImageInfo *image_info,Image *image,
3844 %        const char *embed_text)
3845 %
3846 %  A description of each parameter follows:
3847 %
3848 %    o image_info: the image info.
3849 %
3850 %    o image: the image.
3851 %
3852 %    o embed_text: the address of a character string containing the embedded
3853 %      formatting characters.
3854 %
3855 */
3856 MagickExport char *InterpretImageAttributes(const ImageInfo *image_info,
3857   Image *image,const char *embed_text)
3858 {
3859   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.3.1");
3860   return(InterpretImageProperties(image_info,image,embed_text));
3861 }
3862 \f
3863 /*
3864 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3865 %                                                                             %
3866 %                                                                             %
3867 %                                                                             %
3868 +     I s S u b i m a g e                                                     %
3869 %                                                                             %
3870 %                                                                             %
3871 %                                                                             %
3872 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3873 %
3874 %  IsSubimage() returns MagickTrue if the geometry is a valid subimage
3875 %  specification (e.g. [1], [1-9], [1,7,4]).
3876 %
3877 %  The format of the IsSubimage method is:
3878 %
3879 %      unsigned int IsSubimage(const char *geometry,const unsigned int pedantic)
3880 %
3881 %  A description of each parameter follows:
3882 %
3883 %    o geometry: This string is the geometry specification.
3884 %
3885 %    o pedantic: A value other than 0 invokes a more restrictive set of
3886 %      conditions for a valid specification (e.g. [1], [1-4], [4-1]).
3887 %
3888 */
3889 MagickExport unsigned int IsSubimage(const char *geometry,
3890   const unsigned int pedantic)
3891 {
3892   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
3893   if (geometry == (const char *) NULL)
3894     return(MagickFalse);
3895   if ((strchr(geometry,'x') != (char *) NULL) ||
3896       (strchr(geometry,'X') != (char *) NULL))
3897     return(MagickFalse);
3898   if ((pedantic != MagickFalse) && (strchr(geometry,',') != (char *) NULL))
3899     return(MagickFalse);
3900   return(MagickTrue);
3901 }
3902 \f
3903 /*
3904 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3905 %                                                                             %
3906 %                                                                             %
3907 %                                                                             %
3908 %     L e v e l I m a g e C o l o r s                                         %
3909 %                                                                             %
3910 %                                                                             %
3911 %                                                                             %
3912 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3913 %
3914 %  LevelImageColor() will map the given color to "black" and "white"
3915 %  values, limearly spreading out the colors, and level values on a channel by
3916 %  channel bases, as per LevelImage().  The given colors allows you to specify
3917 %  different level ranges for each of the color channels seperatally.
3918 %
3919 %  If the boolean 'invert' is set true the image values will modifyed in the
3920 %  reverse direction. That is any existing "black" and "white" colors in the
3921 %  image will become the color values given, with all other values compressed
3922 %  appropriatally.  This effectivally maps a greyscale gradient into the given
3923 %  color gradient.
3924 %
3925 %  Deprecated, replace with:
3926 %
3927 %    LevelColorsImageChannel(image,channel,black_color,white_color,invert);
3928 %
3929 %  The format of the LevelImageColors method is:
3930 %
3931 %  MagickBooleanType LevelImageColors(Image *image,const ChannelType channel,
3932 %    const MagickPixelPacket *black_color,const MagickPixelPacket *white_color,
3933 %    const MagickBooleanType invert)
3934 %
3935 %  A description of each parameter follows:
3936 %
3937 %    o image: the image.
3938 %
3939 %    o channel: the channel.
3940 %
3941 %    o black_color: The color to map black to/from
3942 %
3943 %    o white_point: The color to map white to/from
3944 %
3945 %    o invert: if true map the colors (levelize), rather than from (level)
3946 %
3947 */
3948 MagickBooleanType LevelImageColors(Image *image,const ChannelType channel,
3949   const MagickPixelPacket *black_color,const MagickPixelPacket *white_color,
3950   const MagickBooleanType invert)
3951 {
3952   return(LevelColorsImageChannel(image,channel,black_color,white_color,invert));
3953 }
3954 \f
3955 /*
3956 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3957 %                                                                             %
3958 %                                                                             %
3959 %                                                                             %
3960 %   L i b e r a t e M e m o r y                                               %
3961 %                                                                             %
3962 %                                                                             %
3963 %                                                                             %
3964 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3965 %
3966 %  LiberateMemory() frees memory that has already been allocated, and NULL's
3967 %  the pointer to it.
3968 %
3969 %  The format of the LiberateMemory method is:
3970 %
3971 %      void LiberateMemory(void **memory)
3972 %
3973 %  A description of each parameter follows:
3974 %
3975 %    o memory: A pointer to a block of memory to free for reuse.
3976 %
3977 */
3978 MagickExport void LiberateMemory(void **memory)
3979 {
3980   assert(memory != (void **) NULL);
3981   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
3982   if (*memory == (void *) NULL)
3983     return;
3984   free(*memory);
3985   *memory=(void *) NULL;
3986 }
3987 \f
3988 /*
3989 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3990 %                                                                             %
3991 %                                                                             %
3992 %                                                                             %
3993 %   L i b e r a t e S e m a p h o r e I n f o                                 %
3994 %                                                                             %
3995 %                                                                             %
3996 %                                                                             %
3997 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3998 %
3999 %  LiberateSemaphoreInfo() relinquishes a semaphore.
4000 %
4001 %  Deprecated, replace with:
4002 %
4003 %    UnlockSemaphoreInfo(*semaphore_info);
4004 %
4005 %  The format of the LiberateSemaphoreInfo method is:
4006 %
4007 %      LiberateSemaphoreInfo(void **semaphore_info)
4008 %
4009 %  A description of each parameter follows:
4010 %
4011 %    o semaphore_info: Specifies a pointer to an SemaphoreInfo structure.
4012 %
4013 */
4014 MagickExport void LiberateSemaphoreInfo(SemaphoreInfo **semaphore_info)
4015 {
4016   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
4017   UnlockSemaphoreInfo(*semaphore_info);
4018 }
4019 \f
4020 /*
4021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4022 %                                                                             %
4023 %                                                                             %
4024 %                                                                             %
4025 %   M a g i c k I n c a r n a t e                                             %
4026 %                                                                             %
4027 %                                                                             %
4028 %                                                                             %
4029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4030 %
4031 %  MagickIncarnate() initializes the ImageMagick environment.
4032 %
4033 %  Deprecated, replace with:
4034 %
4035 %    MagickCoreGenesis(path,MagickFalse);
4036 %
4037 %  The format of the MagickIncarnate function is:
4038 %
4039 %      MagickIncarnate(const char *path)
4040 %
4041 %  A description of each parameter follows:
4042 %
4043 %    o path: the execution path of the current ImageMagick client.
4044 %
4045 */
4046
4047 MagickExport void MagickIncarnate(const char *path)
4048 {
4049   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1");
4050   MagickCoreGenesis(path,MagickFalse);
4051 }
4052 \f
4053 /*
4054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4055 %                                                                             %
4056 %                                                                             %
4057 %                                                                             %
4058 %   M a g i c k M o n i t o r                                                 %
4059 %                                                                             %
4060 %                                                                             %
4061 %                                                                             %
4062 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4063 %
4064 %  MagickMonitor() calls the monitor handler method with a text string that
4065 %  describes the task and a measure of completion.  The method returns
4066 %  MagickTrue on success otherwise MagickFalse if an error is encountered, e.g.
4067 %  if there was a user interrupt.
4068 %
4069 %  The format of the MagickMonitor method is:
4070 %
4071 %      MagickBooleanType MagickMonitor(const char *text,
4072 %        const MagickOffsetType offset,const MagickSizeType span,
4073 %        void *client_data)
4074 %
4075 %  A description of each parameter follows:
4076 %
4077 %    o offset: the position relative to the span parameter which represents
4078 %      how much progress has been made toward completing a task.
4079 %
4080 %    o span: the span relative to completing a task.
4081 %
4082 %    o client_data: the client data.
4083 %
4084 */
4085 MagickExport MagickBooleanType MagickMonitor(const char *text,
4086   const MagickOffsetType offset,const MagickSizeType span,
4087   void *magick_unused(client_data))
4088 {
4089   ExceptionInfo
4090     *exception;
4091
4092   MagickBooleanType
4093     status;
4094
4095   assert(text != (const char *) NULL);
4096   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",text);
4097   ProcessPendingEvents(text);
4098   status=MagickTrue;
4099   exception=AcquireExceptionInfo();
4100   if (monitor_handler != (MonitorHandler) NULL)
4101     status=(*monitor_handler)(text,offset,span,exception);
4102   exception=DestroyExceptionInfo(exception);
4103   return(status);
4104 }
4105 \f
4106 /*
4107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4108 %                                                                             %
4109 %                                                                             %
4110 %                                                                             %
4111 %   M a p I m a g e                                                           %
4112 %                                                                             %
4113 %                                                                             %
4114 %                                                                             %
4115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4116 %
4117 %  MapImage() replaces the colors of an image with the closest color from a
4118 %  reference image.
4119 %
4120 %  Deprecated, replace with:
4121 %
4122 %     QuantizeInfo quantize_info;
4123 %     GetQuantizeInfo(&quantize_info);
4124 %     quantize_info.dither=dither;
4125 %     RemapImage(&quantize_info,image,map_image);
4126 %
4127 %  The format of the MapImage method is:
4128 %
4129 %      MagickBooleanType MapImage(Image *image,const Image *map_image,
4130 %        const MagickBooleanType dither)
4131 %
4132 %  A description of each parameter follows:
4133 %
4134 %    o image: Specifies a pointer to an Image structure.
4135 %
4136 %    o map_image: the image.  Reduce image to a set of colors represented by
4137 %      this image.
4138 %
4139 %    o dither: Set this integer value to something other than zero to
4140 %      dither the mapped image.
4141 %
4142 */
4143 MagickExport MagickBooleanType MapImage(Image *image,const Image *map_image,
4144   const MagickBooleanType dither)
4145 {
4146   QuantizeInfo
4147     quantize_info;
4148
4149   /*
4150     Initialize color cube.
4151   */
4152   assert(image != (Image *) NULL);
4153   assert(image->signature == MagickSignature);
4154   if (image->debug != MagickFalse)
4155     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4156   assert(map_image != (Image *) NULL);
4157   assert(map_image->signature == MagickSignature);
4158   GetQuantizeInfo(&quantize_info);
4159   quantize_info.dither=dither;
4160   return(RemapImage(&quantize_info,image,map_image));
4161 }
4162 \f
4163 /*
4164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4165 %                                                                             %
4166 %                                                                             %
4167 %                                                                             %
4168 %   M a p I m a g e s                                                         %
4169 %                                                                             %
4170 %                                                                             %
4171 %                                                                             %
4172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4173 %
4174 %  MapImages() replaces the colors of a sequence of images with the closest
4175 %  color from a reference image.
4176 %
4177 %  Deprecated, replace with:
4178 %
4179 %     QuantizeInfo quantize_info;
4180 %     GetQuantizeInfo(&quantize_info);
4181 %     quantize_info.dither=dither;
4182 %     RemapImages(&quantize_info,images,map_image);
4183 %
4184 %  The format of the MapImage method is:
4185 %
4186 %      MagickBooleanType MapImages(Image *images,Image *map_image,
4187 %        const MagickBooleanType dither)
4188 %
4189 %  A description of each parameter follows:
4190 %
4191 %    o image: Specifies a pointer to a set of Image structures.
4192 %
4193 %    o map_image: the image.  Reduce image to a set of colors represented by
4194 %      this image.
4195 %
4196 %    o dither: Set this integer value to something other than zero to
4197 %      dither the quantized image.
4198 %
4199 */
4200 MagickExport MagickBooleanType MapImages(Image *images,const Image *map_image,
4201   const MagickBooleanType dither)
4202 {
4203   QuantizeInfo
4204     quantize_info;
4205
4206   assert(images != (Image *) NULL);
4207   assert(images->signature == MagickSignature);
4208   if (images->debug != MagickFalse)
4209     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4210   GetQuantizeInfo(&quantize_info);
4211   quantize_info.dither=dither;
4212   return(RemapImages(&quantize_info,images,map_image));
4213 }
4214 \f
4215 /*
4216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4217 %                                                                             %
4218 %                                                                             %
4219 %                                                                             %
4220 %   M a t t e F l o o d f i l l I m a g e                                     %
4221 %                                                                             %
4222 %                                                                             %
4223 %                                                                             %
4224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4225 %
4226 %  MatteFloodfill() changes the transparency value of any pixel that matches
4227 %  target and is an immediate neighbor.  If the method FillToBorderMethod
4228 %  is specified, the transparency value is changed for any neighbor pixel
4229 %  that does not match the bordercolor member of image.
4230 %
4231 %  By default target must match a particular pixel transparency exactly.
4232 %  However, in many cases two transparency values may differ by a
4233 %  small amount.  The fuzz member of image defines how much tolerance is
4234 %  acceptable to consider two transparency values as the same.  For example,
4235 %  set fuzz to 10 and the opacity values of 100 and 102 respectively are
4236 %  now interpreted as the same value for the purposes of the floodfill.
4237 %
4238 %  The format of the MatteFloodfillImage method is:
4239 %
4240 %      MagickBooleanType MatteFloodfillImage(Image *image,
4241 %        const PixelPacket target,const Quantum opacity,const long x_offset,
4242 %        const long y_offset,const PaintMethod method)
4243 %
4244 %  A description of each parameter follows:
4245 %
4246 %    o image: the image.
4247 %
4248 %    o target: the RGB value of the target color.
4249 %
4250 %    o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
4251 %      fully transparent.
4252 %
4253 %    o x,y: the starting location of the operation.
4254 %
4255 %    o method:  Choose either FloodfillMethod or FillToBorderMethod.
4256 %
4257 */
4258 MagickExport MagickBooleanType MatteFloodfillImage(Image *image,
4259   const PixelPacket target,const Quantum opacity,const long x_offset,
4260   const long y_offset,const PaintMethod method)
4261 {
4262   Image
4263     *floodplane_image;
4264
4265   long
4266     offset,
4267     start,
4268     x,
4269     x1,
4270     x2,
4271     y;
4272
4273   MagickBooleanType
4274     skip;
4275
4276   register SegmentInfo
4277     *s;
4278
4279   SegmentInfo
4280     *segment_stack;
4281
4282   /*
4283     Check boundary conditions.
4284   */
4285   assert(image != (Image *) NULL);
4286   assert(image->signature == MagickSignature);
4287   if (image->debug != MagickFalse)
4288     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4289   if ((x_offset < 0) || (x_offset >= (long) image->columns))
4290     return(MagickFalse);
4291   if ((y_offset < 0) || (y_offset >= (long) image->rows))
4292     return(MagickFalse);
4293   if (SetImageStorageClass(image,DirectClass) == MagickFalse)
4294     return(MagickFalse);
4295   if (image->matte == MagickFalse)
4296     (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
4297   floodplane_image=CloneImage(image,image->columns,image->rows,MagickTrue,
4298     &image->exception);
4299   if (floodplane_image == (Image *) NULL)
4300     return(MagickFalse);
4301   (void) SetImageAlphaChannel(floodplane_image,OpaqueAlphaChannel);
4302   /*
4303     Set floodfill color.
4304   */
4305   segment_stack=(SegmentInfo *) AcquireQuantumMemory(MaxStacksize,
4306     sizeof(*segment_stack));
4307   if (segment_stack == (SegmentInfo *) NULL)
4308     {
4309       floodplane_image=DestroyImage(floodplane_image);
4310       ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
4311         image->filename);
4312     }
4313   /*
4314     Push initial segment on stack.
4315   */
4316   x=x_offset;
4317   y=y_offset;
4318   start=0;
4319   s=segment_stack;
4320   PushSegmentStack(y,x,x,1);
4321   PushSegmentStack(y+1,x,x,-1);
4322   while (s > segment_stack)
4323   {
4324     register const PixelPacket
4325       *restrict p;
4326
4327     register long
4328       x;
4329
4330     register PixelPacket
4331       *restrict q;
4332
4333     /*
4334       Pop segment off stack.
4335     */
4336     s--;
4337     x1=(long) s->x1;
4338     x2=(long) s->x2;
4339     offset=(long) s->y2;
4340     y=(long) s->y1+offset;
4341     /*
4342       Recolor neighboring pixels.
4343     */
4344     p=GetVirtualPixels(image,0,y,(unsigned long) (x1+1),1,&image->exception);
4345     q=GetAuthenticPixels(floodplane_image,0,y,(unsigned long) (x1+1),1,
4346       &image->exception);
4347     if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
4348       break;
4349     p+=x1;
4350     q+=x1;
4351     for (x=x1; x >= 0; x--)
4352     {
4353       if (q->opacity == (Quantum) TransparentOpacity)
4354         break;
4355       if (method == FloodfillMethod)
4356         {
4357           if (IsColorSimilar(image,p,&target) == MagickFalse)
4358             break;
4359         }
4360       else
4361         if (IsColorSimilar(image,p,&target) != MagickFalse)
4362           break;
4363       q->opacity=(Quantum) TransparentOpacity;
4364       q--;
4365       p--;
4366     }
4367     if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse)
4368       break;
4369     skip=x >= x1 ? MagickTrue : MagickFalse;
4370     if (skip == MagickFalse)
4371       {
4372         start=x+1;
4373         if (start < x1)
4374           PushSegmentStack(y,start,x1-1,-offset);
4375         x=x1+1;
4376       }
4377     do
4378     {
4379       if (skip == MagickFalse)
4380         {
4381           if (x < (long) image->columns)
4382             {
4383               p=GetVirtualPixels(image,x,y,image->columns-x,1,
4384                 &image->exception);
4385               q=GetAuthenticPixels(floodplane_image,x,y,image->columns-x,1,
4386                 &image->exception);
4387               if ((p == (const PixelPacket *) NULL) ||
4388                   (q == (PixelPacket *) NULL))
4389                 break;
4390               for ( ; x < (long) image->columns; x++)
4391               {
4392                 if (q->opacity == (Quantum) TransparentOpacity)
4393                   break;
4394                 if (method == FloodfillMethod)
4395                   {
4396                     if (IsColorSimilar(image,p,&target) == MagickFalse)
4397                       break;
4398                   }
4399                 else
4400                   if (IsColorSimilar(image,p,&target) != MagickFalse)
4401                     break;
4402                 q->opacity=(Quantum) TransparentOpacity;
4403                 q++;
4404                 p++;
4405               }
4406               if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse)
4407                 break;
4408             }
4409           PushSegmentStack(y,start,x-1,offset);
4410           if (x > (x2+1))
4411             PushSegmentStack(y,x2+1,x-1,-offset);
4412         }
4413       skip=MagickFalse;
4414       x++;
4415       if (x <= x2)
4416         {
4417           p=GetVirtualPixels(image,x,y,(unsigned long) (x2-x+1),1,
4418             &image->exception);
4419           q=GetAuthenticPixels(floodplane_image,x,y,(unsigned long) (x2-x+1),1,
4420             &image->exception);
4421           if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
4422             break;
4423           for ( ; x <= x2; x++)
4424           {
4425             if (q->opacity == (Quantum) TransparentOpacity)
4426               break;
4427             if (method == FloodfillMethod)
4428               {
4429                 if (IsColorSimilar(image,p,&target) != MagickFalse)
4430                   break;
4431               }
4432             else
4433               if (IsColorSimilar(image,p,&target) == MagickFalse)
4434                 break;
4435             p++;
4436             q++;
4437           }
4438         }
4439       start=x;
4440     } while (x <= x2);
4441   }
4442   for (y=0; y < (long) image->rows; y++)
4443   {
4444     register const PixelPacket
4445       *restrict p;
4446
4447     register long
4448       x;
4449
4450     register PixelPacket
4451       *restrict q;
4452
4453     /*
4454       Tile fill color onto floodplane.
4455     */
4456     p=GetVirtualPixels(floodplane_image,0,y,image->columns,1,
4457       &image->exception);
4458     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
4459     if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
4460       break;
4461     for (x=0; x < (long) image->columns; x++)
4462     {
4463       if (p->opacity != OpaqueOpacity)
4464         q->opacity=opacity;
4465       p++;
4466       q++;
4467     }
4468     if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
4469       break;
4470   }
4471   segment_stack=(SegmentInfo *) RelinquishMagickMemory(segment_stack);
4472   floodplane_image=DestroyImage(floodplane_image);
4473   return(y == (long) image->rows ? MagickTrue : MagickFalse);
4474 }
4475 \f
4476 /*
4477 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4478 %                                                                             %
4479 %                                                                             %
4480 %                                                                             %
4481 %     M a x i m u m I m a g e s                                               %
4482 %                                                                             %
4483 %                                                                             %
4484 %                                                                             %
4485 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4486 %
4487 %  MaximumImages() returns the maximum intensity of an image sequence.
4488 %
4489 %  Deprecated, replace with:
4490 %
4491 %    EvaluateImages(images,MinEvaluateOperator,exception);
4492 %
4493 %  The format of the MaxImages method is:
4494 %
4495 %      Image *MaximumImages(Image *images,ExceptionInfo *exception)
4496 %
4497 %  A description of each parameter follows:
4498 %
4499 %    o images: the image sequence.
4500 %
4501 %    o exception: return any errors or warnings in this structure.
4502 %
4503 */
4504 MagickExport Image *MaximumImages(const Image *images,ExceptionInfo *exception)
4505 {
4506   return(EvaluateImages(images,MinEvaluateOperator,exception));
4507 }
4508 \f
4509 /*
4510 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4511 %                                                                             %
4512 %                                                                             %
4513 %                                                                             %
4514 %     M i n i m u m I m a g e s                                               %
4515 %                                                                             %
4516 %                                                                             %
4517 %                                                                             %
4518 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4519 %
4520 %  MinimumImages() returns the minimum intensity of an image sequence.
4521 %
4522 %  Deprecated, replace with:
4523 %
4524 %    EvaluateImages(images,MinEvaluateOperator,exception);
4525 %
4526 %  The format of the MinimumImages method is:
4527 %
4528 %      Image *MinimumImages(Image *images,ExceptionInfo *exception)
4529 %
4530 %  A description of each parameter follows:
4531 %
4532 %    o images: the image sequence.
4533 %
4534 %    o exception: return any errors or warnings in this structure.
4535 %
4536 */
4537 MagickExport Image *MinimumImages(const Image *images,ExceptionInfo *exception)
4538 {
4539   return(EvaluateImages(images,MinEvaluateOperator,exception));
4540 }
4541 \f
4542 /*
4543 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4544 %                                                                             %
4545 %                                                                             %
4546 %                                                                             %
4547 %     M o s a i c I m a g e s                                                 %
4548 %                                                                             %
4549 %                                                                             %
4550 %                                                                             %
4551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4552 %
4553 %  MosaicImages() Obsolete Function: Use MergeImageLayers() instead.
4554 %
4555 %  Deprecated, replace with:
4556 %
4557 %    MergeImageLayers(image,MosaicLayer,exception);
4558 %
4559 %  The format of the MosaicImage method is:
4560 %
4561 %      Image *MosaicImages(const Image *image,ExceptionInfo *exception)
4562 %
4563 %  A description of each parameter follows:
4564 %
4565 %    o image: the image list to be composited together
4566 %
4567 %    o exception: return any errors or warnings in this structure.
4568 %
4569 */
4570 MagickExport Image *MosaicImages(Image *image,ExceptionInfo *exception)
4571 {
4572   return(MergeImageLayers(image,MosaicLayer,exception));
4573 }
4574 \f
4575 /*
4576 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4577 %                                                                             %
4578 %                                                                             %
4579 %                                                                             %
4580 %     O p a q u e I m a g e                                                   %
4581 %                                                                             %
4582 %                                                                             %
4583 %                                                                             %
4584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4585 %
4586 %  OpaqueImage() changes any pixel that matches color with the color
4587 %  defined by fill.
4588 %
4589 %  By default color must match a particular pixel color exactly.  However,
4590 %  in many cases two colors may differ by a small amount.  Fuzz defines
4591 %  how much tolerance is acceptable to consider two colors as the same.
4592 %  For example, set fuzz to 10 and the color red at intensities of 100 and
4593 %  102 respectively are now interpreted as the same color.
4594 %
4595 %  The format of the OpaqueImage method is:
4596 %
4597 %      MagickBooleanType OpaqueImage(Image *image,
4598 %        const PixelPacket *target,const PixelPacket fill)
4599 %
4600 %  A description of each parameter follows:
4601 %
4602 %    o image: the image.
4603 %
4604 %    o target: the RGB value of the target color.
4605 %
4606 %    o fill: the replacement color.
4607 %
4608 */
4609 MagickExport MagickBooleanType OpaqueImage(Image *image,
4610   const PixelPacket target,const PixelPacket fill)
4611 {
4612 #define OpaqueImageTag  "Opaque/Image"
4613
4614   long
4615     y;
4616
4617   MagickBooleanType
4618     proceed;
4619
4620   register long
4621     i;
4622
4623   /*
4624     Make image color opaque.
4625   */
4626   assert(image != (Image *) NULL);
4627   assert(image->signature == MagickSignature);
4628   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.1.0");
4629   if (image->debug != MagickFalse)
4630     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4631   switch (image->storage_class)
4632   {
4633     case DirectClass:
4634     default:
4635     {
4636       /*
4637         Make DirectClass image opaque.
4638       */
4639       for (y=0; y < (long) image->rows; y++)
4640       {
4641         register long
4642           x;
4643
4644         register PixelPacket
4645           *restrict q;
4646
4647         q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
4648         if (q == (PixelPacket *) NULL)
4649           break;
4650         for (x=0; x < (long) image->columns; x++)
4651         {
4652           if (IsColorSimilar(image,q,&target) != MagickFalse)
4653             *q=fill;
4654           q++;
4655         }
4656         if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
4657           break;
4658         proceed=SetImageProgress(image,OpaqueImageTag,y,image->rows);
4659         if (proceed == MagickFalse)
4660           break;
4661       }
4662       break;
4663     }
4664     case PseudoClass:
4665     {
4666       /*
4667         Make PseudoClass image opaque.
4668       */
4669       for (i=0; i < (long) image->colors; i++)
4670       {
4671         if (IsColorSimilar(image,&image->colormap[i],&target) != MagickFalse)
4672           image->colormap[i]=fill;
4673       }
4674       if (fill.opacity != OpaqueOpacity)
4675         {
4676           for (y=0; y < (long) image->rows; y++)
4677           {
4678             register long
4679               x;
4680
4681             register PixelPacket
4682               *restrict q;
4683
4684             q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
4685             if (q == (PixelPacket *) NULL)
4686               break;
4687             for (x=0; x < (long) image->columns; x++)
4688             {
4689               if (IsColorSimilar(image,q,&target) != MagickFalse)
4690                 q->opacity=fill.opacity;
4691               q++;
4692             }
4693             if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
4694               break;
4695           }
4696         }
4697       (void) SyncImage(image);
4698       break;
4699     }
4700   }
4701   if (fill.opacity != OpaqueOpacity)
4702     image->matte=MagickTrue;
4703   return(MagickTrue);
4704 }
4705 \f
4706 /*
4707 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4708 %                                                                             %
4709 %                                                                             %
4710 %                                                                             %
4711 %   O p e n C a c h e V i e w                                                 %
4712 %                                                                             %
4713 %                                                                             %
4714 %                                                                             %
4715 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4716 %
4717 %  OpenCacheView() opens a view into the pixel cache, using the
4718 %  VirtualPixelMethod that is defined within the given image itself.
4719 %
4720 %  Deprecated, replace with:
4721 %
4722 %    AcquireCacheView(image);
4723 %
4724 %  The format of the OpenCacheView method is:
4725 %
4726 %      CacheView *OpenCacheView(const Image *image)
4727 %
4728 %  A description of each parameter follows:
4729 %
4730 %    o image: the image.
4731 %
4732 */
4733 MagickExport CacheView *OpenCacheView(const Image *image)
4734 {
4735   return(AcquireCacheView(image));
4736 }
4737 \f
4738 /*
4739 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4740 %                                                                             %
4741 %                                                                             %
4742 %                                                                             %
4743 %   P a i n t F l o o d f i l l I m a g e                                     %
4744 %                                                                             %
4745 %                                                                             %
4746 %                                                                             %
4747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4748 %
4749 %  PaintFloodfill() changes the color value of any pixel that matches
4750 %  target and is an immediate neighbor.  If the method FillToBorderMethod is
4751 %  specified, the color value is changed for any neighbor pixel that does not
4752 %  match the bordercolor member of image.
4753 %
4754 %  By default target must match a particular pixel color exactly.
4755 %  However, in many cases two colors may differ by a small amount.  The
4756 %  fuzz member of image defines how much tolerance is acceptable to
4757 %  consider two colors as the same.  For example, set fuzz to 10 and the
4758 %  color red at intensities of 100 and 102 respectively are now
4759 %  interpreted as the same color for the purposes of the floodfill.
4760 %
4761 %  Deprecated, replace with:
4762 %
4763 %    FloodfillPaintImage(image,channel,draw_info,target,x,y,
4764 %      method == FloodfillMethod ? MagickFalse : MagickTrue);
4765 %
4766 %  The format of the PaintFloodfillImage method is:
4767 %
4768 %      MagickBooleanType PaintFloodfillImage(Image *image,
4769 %        const ChannelType channel,const MagickPixelPacket target,const long x,
4770 %        const long y,const DrawInfo *draw_info,const PaintMethod method)
4771 %
4772 %  A description of each parameter follows:
4773 %
4774 %    o image: the image.
4775 %
4776 %    o channel: the channel(s).
4777 %
4778 %    o target: the RGB value of the target color.
4779 %
4780 %    o x,y: the starting location of the operation.
4781 %
4782 %    o draw_info: the draw info.
4783 %
4784 %    o method: Choose either FloodfillMethod or FillToBorderMethod.
4785 %
4786 */
4787 MagickExport MagickBooleanType PaintFloodfillImage(Image *image,
4788   const ChannelType channel,const MagickPixelPacket *target,const long x,
4789   const long y,const DrawInfo *draw_info,const PaintMethod method)
4790 {
4791   MagickBooleanType
4792     status;
4793
4794   status=FloodfillPaintImage(image,channel,draw_info,target,x,y,
4795     method == FloodfillMethod ? MagickFalse : MagickTrue);
4796   return(status);
4797 }
4798 \f
4799 /*
4800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4801 %                                                                             %
4802 %                                                                             %
4803 %     P a i n t O p a q u e I m a g e                                         %
4804 %                                                                             %
4805 %                                                                             %
4806 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4807 %
4808 %  PaintOpaqueImage() changes any pixel that matches color with the color
4809 %  defined by fill.
4810 %
4811 %  By default color must match a particular pixel color exactly.  However,
4812 %  in many cases two colors may differ by a small amount.  Fuzz defines
4813 %  how much tolerance is acceptable to consider two colors as the same.
4814 %  For example, set fuzz to 10 and the color red at intensities of 100 and
4815 %  102 respectively are now interpreted as the same color.
4816 %
4817 %  Deprecated, replace with:
4818 %
4819 %    OpaquePaintImageChannel(image,DefaultChannels,target,fill,MagickFalse);
4820 %    OpaquePaintImageChannel(image,channel,target,fill,MagickFalse);
4821 %
4822 %  The format of the PaintOpaqueImage method is:
4823 %
4824 %      MagickBooleanType PaintOpaqueImage(Image *image,
4825 %        const PixelPacket *target,const PixelPacket *fill)
4826 %      MagickBooleanType PaintOpaqueImageChannel(Image *image,
4827 %        const ChannelType channel,const PixelPacket *target,
4828 %        const PixelPacket *fill)
4829 %
4830 %  A description of each parameter follows:
4831 %
4832 %    o image: the image.
4833 %
4834 %    o channel: the channel(s).
4835 %
4836 %    o target: the RGB value of the target color.
4837 %
4838 %    o fill: the replacement color.
4839 %
4840 */
4841
4842 MagickExport MagickBooleanType PaintOpaqueImage(Image *image,
4843   const MagickPixelPacket *target,const MagickPixelPacket *fill)
4844 {
4845   MagickBooleanType
4846     status;
4847
4848   status=OpaquePaintImageChannel(image,DefaultChannels,target,fill,MagickFalse);
4849   return(status);
4850 }
4851
4852 MagickExport MagickBooleanType PaintOpaqueImageChannel(Image *image,
4853   const ChannelType channel,const MagickPixelPacket *target,
4854   const MagickPixelPacket *fill)
4855 {
4856   return(OpaquePaintImageChannel(image,channel,target,fill,MagickFalse));
4857 }
4858 \f
4859 /*
4860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4861 %                                                                             %
4862 %                                                                             %
4863 %                                                                             %
4864 %     P a i n t T r a n s p a r e n t I m a g e                               %
4865 %                                                                             %
4866 %                                                                             %
4867 %                                                                             %
4868 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4869 %
4870 %  PaintTransparentImage() changes the opacity value associated with any pixel
4871 %  that matches color to the value defined by opacity.
4872 %
4873 %  By default color must match a particular pixel color exactly.  However,
4874 %  in many cases two colors may differ by a small amount.  Fuzz defines
4875 %  how much tolerance is acceptable to consider two colors as the same.
4876 %  For example, set fuzz to 10 and the color red at intensities of 100 and
4877 %  102 respectively are now interpreted as the same color.
4878 %
4879 %  Deprecated, replace with:
4880 %
4881 %    TransparentPaintImage(image,target,opacity,MagickFalse);
4882 %
4883 %  The format of the PaintTransparentImage method is:
4884 %
4885 %      MagickBooleanType PaintTransparentImage(Image *image,
4886 %        const MagickPixelPacket *target,const Quantum opacity)
4887 %
4888 %  A description of each parameter follows:
4889 %
4890 %    o image: the image.
4891 %
4892 %    o target: the RGB value of the target color.
4893 %
4894 %    o opacity: the replacement opacity value.
4895 %
4896 */
4897 MagickExport MagickBooleanType PaintTransparentImage(Image *image,
4898   const MagickPixelPacket *target,const Quantum opacity)
4899 {
4900   return(TransparentPaintImage(image,target,opacity,MagickFalse));
4901 }
4902 \f
4903 /*
4904 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4905 %                                                                             %
4906 %                                                                             %
4907 %                                                                             %
4908 +   P a r s e I m a g e G e o m e t r y                                       %
4909 %                                                                             %
4910 %                                                                             %
4911 %                                                                             %
4912 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4913 %
4914 %  ParseImageGeometry() is similar to GetGeometry() except the returned
4915 %  geometry is modified as determined by the meta characters:  %, !, <,
4916 %  and >.
4917 %
4918 %  Deprecated, replace with:
4919 %
4920 %    ParseMetaGeometry(geometry,x,y,width,height);
4921 %
4922 %  The format of the ParseImageGeometry method is:
4923 %
4924 %      int ParseImageGeometry(char *geometry,long *x,long *y,
4925 %        unsigned long *width,unsigned long *height)
4926 %
4927 %  A description of each parameter follows:
4928 %
4929 %    o flags:  Method ParseImageGeometry returns a bitmask that indicates
4930 %      which of the four values were located in the geometry string.
4931 %
4932 %    o image_geometry:  Specifies a character string representing the geometry
4933 %      specification.
4934 %
4935 %    o x,y:  A pointer to an integer.  The x and y offset as determined by
4936 %      the geometry specification is returned here.
4937 %
4938 %    o width,height:  A pointer to an unsigned integer.  The width and height
4939 %      as determined by the geometry specification is returned here.
4940 %
4941 */
4942 MagickExport int ParseImageGeometry(const char *geometry,long *x,long *y,
4943   unsigned long *width,unsigned long *height)
4944 {
4945   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1");
4946   return((int) ParseMetaGeometry(geometry,x,y,width,height));
4947 }
4948 \f
4949 /*
4950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4951 %                                                                             %
4952 %                                                                             %
4953 %                                                                             %
4954 %   P a r s e S i z e G e o m e t r y                                         %
4955 %                                                                             %
4956 %                                                                             %
4957 %                                                                             %
4958 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4959 %
4960 %  ParseSizeGeometry() returns a region as defined by the geometry string with
4961 %  respect to the image dimensions and aspect ratio.
4962 %
4963 %  Deprecated, replace with:
4964 %
4965 %    ParseMetaGeometry(geometry,&region_info->x,&region_info->y,
4966 %      &region_info->width,&region_info->height);
4967 %
4968 %  The format of the ParseSizeGeometry method is:
4969 %
4970 %      MagickStatusType ParseSizeGeometry(const Image *image,
4971 %        const char *geometry,RectangeInfo *region_info)
4972 %
4973 %  A description of each parameter follows:
4974 %
4975 %    o geometry:  The geometry (e.g. 100x100+10+10).
4976 %
4977 %    o region_info: the region as defined by the geometry string.
4978 %
4979 */
4980 MagickExport MagickStatusType ParseSizeGeometry(const Image *image,
4981   const char *geometry,RectangleInfo *region_info)
4982 {
4983   MagickStatusType
4984     flags;
4985
4986   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.4.7");
4987   SetGeometry(image,region_info);
4988   flags=ParseMetaGeometry(geometry,&region_info->x,&region_info->y,
4989     &region_info->width,&region_info->height);
4990   return(flags);
4991 }
4992 \f
4993 /*
4994 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4995 %                                                                             %
4996 %                                                                             %
4997 %                                                                             %
4998 %   P o p I m a g e L i s t                                                   %
4999 %                                                                             %
5000 %                                                                             %
5001 %                                                                             %
5002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5003 %
5004 %  PopImageList() removes the last image in the list.
5005 %
5006 %  Deprecated, replace with:
5007 %
5008 %    RemoveLastImageFromList(images);
5009 %
5010 %  The format of the PopImageList method is:
5011 %
5012 %      Image *PopImageList(Image **images)
5013 %
5014 %  A description of each parameter follows:
5015 %
5016 %    o images: the image list.
5017 %
5018 */
5019 MagickExport Image *PopImageList(Image **images)
5020 {
5021   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
5022   return(RemoveLastImageFromList(images));
5023 }
5024 \f
5025 /*
5026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5027 %                                                                             %
5028 %                                                                             %
5029 %                                                                             %
5030 %   P o p I m a g e P i x e l s                                               %
5031 %                                                                             %
5032 %                                                                             %
5033 %                                                                             %
5034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5035 %
5036 %  PopImagePixels() transfers one or more pixel components from the image pixel
5037 %  cache to a user supplied buffer.  The pixels are returned in network byte
5038 %  order.  MagickTrue is returned if the pixels are successfully transferred,
5039 %  otherwise MagickFalse.
5040 %
5041 %  The format of the PopImagePixels method is:
5042 %
5043 %      size_t PopImagePixels(Image *,const QuantumType quantum,
5044 %        unsigned char *destination)
5045 %
5046 %  A description of each parameter follows:
5047 %
5048 %    o image: the image.
5049 %
5050 %    o quantum: Declare which pixel components to transfer (RGB, RGBA, etc).
5051 %
5052 %    o destination:  The components are transferred to this buffer.
5053 %
5054 */
5055 MagickExport size_t PopImagePixels(Image *image,const QuantumType quantum,
5056   unsigned char *destination)
5057 {
5058   QuantumInfo
5059     *quantum_info;
5060
5061   size_t
5062     length;
5063
5064   quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
5065   if (quantum_info == (QuantumInfo *) NULL)
5066     return(0);
5067   length=ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
5068     quantum,destination,&image->exception);
5069   quantum_info=DestroyQuantumInfo(quantum_info);
5070   return(length);
5071 }
5072 \f
5073 /*
5074 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5075 %                                                                             %
5076 %                                                                             %
5077 %                                                                             %
5078 %  P o s t s c r i p t G e o m e t r y                                        %
5079 %                                                                             %
5080 %                                                                             %
5081 %                                                                             %
5082 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5083 %
5084 %  PostscriptGeometry() replaces any page mneumonic with the equivalent size in
5085 %  picas.
5086 %
5087 %  Deprecated, replace with:
5088 %
5089 %    GetPageGeometry(page);
5090 %
5091 %  The format of the PostscriptGeometry method is:
5092 %
5093 %      char *PostscriptGeometry(const char *page)
5094 %
5095 %  A description of each parameter follows.
5096 %
5097 %   o  page:  Specifies a pointer to an array of characters.
5098 %      The string is either a Postscript page name (e.g. A4) or a postscript
5099 %      page geometry (e.g. 612x792+36+36).
5100 %
5101 */
5102 MagickExport char *PostscriptGeometry(const char *page)
5103 {
5104   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1");
5105   return(GetPageGeometry(page));
5106 }
5107 \f
5108 /*
5109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5110 %                                                                             %
5111 %                                                                             %
5112 %                                                                             %
5113 %   P u s h I m a g e L i s t                                                 %
5114 %                                                                             %
5115 %                                                                             %
5116 %                                                                             %
5117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5118 %
5119 %  PushImageList() adds an image to the end of the list.
5120 %
5121 %  Deprecated, replace with:
5122 %
5123 %    AppendImageToList(images,CloneImageList(image,exception));
5124 %
5125 %  The format of the PushImageList method is:
5126 %
5127 %      unsigned int PushImageList(Image *images,const Image *image,
5128 %        ExceptionInfo *exception)
5129 %
5130 %  A description of each parameter follows:
5131 %
5132 %    o images: the image list.
5133 %
5134 %    o image: the image.
5135 %
5136 %    o exception: return any errors or warnings in this structure.
5137 %
5138 */
5139 MagickExport unsigned int PushImageList(Image **images,const Image *image,
5140   ExceptionInfo *exception)
5141 {
5142   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
5143   AppendImageToList(images,CloneImageList(image,exception));
5144   return(MagickTrue);
5145 }
5146 \f
5147 /*
5148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5149 %                                                                             %
5150 %                                                                             %
5151 %                                                                             %
5152 %   P u s h I m a g e P i x e l s                                             %
5153 %                                                                             %
5154 %                                                                             %
5155 %                                                                             %
5156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5157 %
5158 %  PushImagePixels() transfers one or more pixel components from a user
5159 %  supplied buffer into the image pixel cache of an image.  The pixels are
5160 %  expected in network byte order.  It returns MagickTrue if the pixels are
5161 %  successfully transferred, otherwise MagickFalse.
5162 %
5163 %  The format of the PushImagePixels method is:
5164 %
5165 %      size_t PushImagePixels(Image *image,const QuantumType quantum,
5166 %        const unsigned char *source)
5167 %
5168 %  A description of each parameter follows:
5169 %
5170 %    o image: the image.
5171 %
5172 %    o quantum: Declare which pixel components to transfer (red, green, blue,
5173 %      opacity, RGB, or RGBA).
5174 %
5175 %    o source:  The pixel components are transferred from this buffer.
5176 %
5177 */
5178 MagickExport size_t PushImagePixels(Image *image,const QuantumType quantum,
5179   const unsigned char *source)
5180 {
5181   QuantumInfo
5182     *quantum_info;
5183
5184   size_t
5185     length;
5186
5187   quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
5188   if (quantum_info == (QuantumInfo *) NULL)
5189     return(0);
5190   length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,quantum,
5191     source,&image->exception);
5192   quantum_info=DestroyQuantumInfo(quantum_info);
5193   return(length);
5194 }
5195 \f
5196 /*
5197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5198 %                                                                             %
5199 %                                                                             %
5200 %                                                                             %
5201 %  Q u a n t i z a t i o n E r r o r                                          %
5202 %                                                                             %
5203 %                                                                             %
5204 %                                                                             %
5205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5206 %
5207 %  QuantizationError() measures the difference between the original and
5208 %  quantized images.  This difference is the total quantization error.  The
5209 %  error is computed by summing over all pixels in an image the distance
5210 %  squared in RGB space between each reference pixel value and its quantized
5211 %  value.  These values are computed:
5212 %
5213 %    o mean_error_per_pixel:  This value is the mean error for any single
5214 %      pixel in the image.
5215 %
5216 %    o normalized_mean_square_error:  This value is the normalized mean
5217 %      quantization error for any single pixel in the image.  This distance
5218 %      measure is normalized to a range between 0 and 1.  It is independent
5219 %      of the range of red, green, and blue values in the image.
5220 %
5221 %    o normalized_maximum_square_error:  Thsi value is the normalized
5222 %      maximum quantization error for any single pixel in the image.  This
5223 %      distance measure is normalized to a range between 0 and 1.  It is
5224 %      independent of the range of red, green, and blue values in your image.
5225 %
5226 %  Deprecated, replace with:
5227 %
5228 %    GetImageQuantizeError(image);
5229 %
5230 %  The format of the QuantizationError method is:
5231 %
5232 %      unsigned int QuantizationError(Image *image)
5233 %
5234 %  A description of each parameter follows.
5235 %
5236 %    o image: Specifies a pointer to an Image structure;  returned from
5237 %      ReadImage.
5238 %
5239 */
5240 MagickExport unsigned int QuantizationError(Image *image)
5241 {
5242   if (image->debug != MagickFalse)
5243     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.3");
5244   return(GetImageQuantizeError(image));
5245 }
5246 \f
5247 /*
5248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5249 %                                                                             %
5250 %                                                                             %
5251 %     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                   %
5252 %                                                                             %
5253 %                                                                             %
5254 %                                                                             %
5255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5256 %
5257 %  RandomChannelThresholdImage() changes the value of individual pixels based
5258 %  on the intensity of each pixel compared to a random threshold.  The result
5259 %  is a low-contrast, two color image.
5260 %
5261 %  The format of the RandomChannelThresholdImage method is:
5262 %
5263 %      unsigned int RandomChannelThresholdImage(Image *image,
5264 %         const char *channel, const char *thresholds,
5265 %         ExceptionInfo *exception)
5266 %
5267 %  A description of each parameter follows:
5268 %
5269 %    o image: the image.
5270 %
5271 %    o channel: the channel or channels to be thresholded.
5272 %
5273 %    o thresholds: a geometry string containing LOWxHIGH thresholds.
5274 %      If the string contains 2x2, 3x3, or 4x4, then an ordered
5275 %      dither of order 2, 3, or 4 will be performed instead.
5276 %
5277 %    o exception: return any errors or warnings in this structure.
5278 %
5279 */
5280 MagickExport unsigned int RandomChannelThresholdImage(Image *image,const char
5281     *channel,const char *thresholds,ExceptionInfo *exception)
5282 {
5283 #define RandomChannelThresholdImageText  "  RandomChannelThreshold image...  "
5284
5285   double
5286     lower_threshold,
5287     upper_threshold;
5288
5289   long
5290     count,
5291     y;
5292
5293   RandomInfo
5294     *random_info;
5295
5296   static MagickRealType
5297     o2[4]={0.2f, 0.6f, 0.8f, 0.4f},
5298     o3[9]={0.1f, 0.6f, 0.3f, 0.7f, 0.5f, 0.8f, 0.4f, 0.9f, 0.2f},
5299     o4[16]={0.1f, 0.7f, 1.1f, 0.3f, 1.0f, 0.5f, 1.5f, 0.8f, 1.4f, 1.6f, 0.6f,
5300       1.2f, 0.4f, 0.9f, 1.3f, 0.2f},
5301     threshold=128;
5302
5303   unsigned long
5304     order;
5305
5306   /*
5307     Threshold image.
5308   */
5309   assert(image != (Image *) NULL);
5310   assert(image->signature == MagickSignature);
5311   if (image->debug != MagickFalse)
5312     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5313   assert(exception != (ExceptionInfo *) NULL);
5314   assert(exception->signature == MagickSignature);
5315   if (image->debug != MagickFalse)
5316     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
5317   if (thresholds == (const char *) NULL)
5318     return(MagickTrue);
5319   if (LocaleCompare(thresholds,"2x2") == 0)
5320     order=2;
5321   else
5322     if (LocaleCompare(thresholds,"3x3") == 0)
5323       order=3;
5324     else
5325       if (LocaleCompare(thresholds,"4x4") == 0)
5326         order=4;
5327       else
5328         {
5329           order=1;
5330           lower_threshold=0;
5331           upper_threshold=0;
5332           count=sscanf(thresholds,"%lf[/x%%]%lf",&lower_threshold,
5333             &upper_threshold);
5334           if (strchr(thresholds,'%') != (char *) NULL)
5335             {
5336               upper_threshold*=(.01*QuantumRange);
5337               lower_threshold*=(.01*QuantumRange);
5338             }
5339           if (count == 1)
5340             upper_threshold=(MagickRealType) QuantumRange-lower_threshold;
5341         }
5342   if (image->debug != MagickFalse)
5343     (void) LogMagickEvent(TransformEvent,GetMagickModule(),
5344       "  RandomChannelThresholdImage: channel type=%s",channel);
5345   if (image->debug != MagickFalse)
5346     (void) LogMagickEvent(TransformEvent,GetMagickModule(),
5347       "    Thresholds: %s (%fx%f)",thresholds,lower_threshold,upper_threshold);
5348   if (LocaleCompare(channel,"all") == 0 ||
5349       LocaleCompare(channel,"intensity") == 0)
5350     if (AcquireImageColormap(image,2) == MagickFalse)
5351       ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
5352         image->filename);
5353   random_info=AcquireRandomInfo();
5354   for (y=0; y < (long) image->rows; y++)
5355   {
5356     register long
5357       x;
5358
5359     register IndexPacket
5360       index,
5361       *restrict indexes;
5362
5363     register PixelPacket
5364       *restrict q;
5365
5366     q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
5367     if (q == (PixelPacket *) NULL)
5368       break;
5369     if (LocaleCompare(channel,"all") == 0 ||
5370         LocaleCompare(channel,"intensity") == 0)
5371       {
5372         indexes=GetAuthenticIndexQueue(image);
5373         for (x=0; x < (long) image->columns; x++)
5374           {
5375             MagickRealType
5376               intensity;
5377
5378             intensity=(MagickRealType) PixelIntensityToQuantum(q);
5379             if (order == 1)
5380               {
5381                 if (intensity < lower_threshold)
5382                   threshold=lower_threshold;
5383                 else if (intensity > upper_threshold)
5384                   threshold=upper_threshold;
5385                 else
5386                   threshold=(MagickRealType) (QuantumRange*
5387                     GetPseudoRandomValue(random_info));
5388               }
5389             else if (order == 2)
5390               threshold=(MagickRealType) QuantumRange*o2[(x%2)+2*(y%2)];
5391             else if (order == 3)
5392               threshold=(MagickRealType) QuantumRange*o3[(x%3)+3*(y%3)];
5393             else if (order == 4)
5394               threshold=(MagickRealType) QuantumRange*o4[(x%4)+4*(y%4)];
5395             q->red=q->green=q->blue=(Quantum) (intensity <=
5396                threshold ? 0 : QuantumRange);
5397             index=(IndexPacket) (intensity <= threshold ? 0 : 1);
5398             *indexes++=index;
5399             q->red=q->green=q->blue=image->colormap[(long) index].red;
5400             q++;
5401           }
5402       }
5403     if (LocaleCompare(channel,"opacity") == 0 ||
5404         LocaleCompare(channel,"all") == 0 ||
5405         LocaleCompare(channel,"matte") == 0)
5406       {
5407         if (image->matte != MagickFalse)
5408           for (x=0; x < (long) image->columns; x++)
5409             {
5410               if (order == 1)
5411                 {
5412                   if ((MagickRealType) q->opacity < lower_threshold)
5413                     threshold=lower_threshold;
5414                   else if ((MagickRealType) q->opacity > upper_threshold)
5415                     threshold=upper_threshold;
5416                   else
5417                     threshold=(MagickRealType) (QuantumRange*
5418                       GetPseudoRandomValue(random_info));
5419                 }
5420               else if (order == 2)
5421                 threshold=(MagickRealType) QuantumRange*o2[(x%2)+2*(y%2)];
5422               else if (order == 3)
5423                 threshold=(MagickRealType) QuantumRange*o3[(x%3)+3*(y%3)];
5424               else if (order == 4)
5425                 threshold=(MagickRealType) QuantumRange*o4[(x%4)+4*(y%4)]/1.7;
5426               q->opacity=(Quantum) ((MagickRealType) q->opacity <= threshold ?
5427                  0 : QuantumRange);
5428               q++;
5429             }
5430       }
5431     else
5432       {
5433         /* To Do: red, green, blue, cyan, magenta, yellow, black */
5434         if (LocaleCompare(channel,"intensity") != 0)
5435           ThrowBinaryException(OptionError,"UnrecognizedChannelType",
5436             image->filename);
5437       }
5438     if (SyncAuthenticPixels(image,exception) == MagickFalse)
5439       break;
5440   }
5441   random_info=DestroyRandomInfo(random_info);
5442   return(MagickTrue);
5443 }
5444 \f
5445 /*
5446 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5447 %                                                                             %
5448 %                                                                             %
5449 %                                                                             %
5450 %   R e a c q u i r e M e m o r y                                             %
5451 %                                                                             %
5452 %                                                                             %
5453 %                                                                             %
5454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5455 %
5456 %  ReacquireMemory() changes the size of the memory and returns a pointer to
5457 %  the (possibly moved) block.  The contents will be unchanged up to the
5458 %  lesser of the new and old sizes.
5459 %
5460 %  The format of the ReacquireMemory method is:
5461 %
5462 %      void ReacquireMemory(void **memory,const size_t size)
5463 %
5464 %  A description of each parameter follows:
5465 %
5466 %    o memory: A pointer to a memory allocation.  On return the pointer
5467 %      may change but the contents of the original allocation will not.
5468 %
5469 %    o size: the new size of the allocated memory.
5470 %
5471 */
5472 MagickExport void ReacquireMemory(void **memory,const size_t size)
5473 {
5474   void
5475     *allocation;
5476
5477   assert(memory != (void **) NULL);
5478   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
5479   if (*memory == (void *) NULL)
5480     {
5481       *memory=AcquireMagickMemory(size);
5482       return;
5483     }
5484   allocation=realloc(*memory,size);
5485   if (allocation == (void *) NULL)
5486     *memory=RelinquishMagickMemory(*memory);
5487   *memory=allocation;
5488 }
5489 \f
5490 /*
5491 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5492 %                                                                             %
5493 %                                                                             %
5494 %                                                                             %
5495 %     R e c o l o r I m a g e                                                 %
5496 %                                                                             %
5497 %                                                                             %
5498 %                                                                             %
5499 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5500 %
5501 %  RecolorImage() apply color transformation to an image. The method permits
5502 %  saturation changes, hue rotation, luminance to alpha, and various other
5503 %  effects.  Although variable-sized transformation matrices can be used,
5504 %  typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
5505 %  (or RGBA with offsets).  The matrix is similar to those used by Adobe Flash
5506 %  except offsets are in column 6 rather than 5 (in support of CMYKA images)
5507 %  and offsets are normalized (divide Flash offset by 255).
5508 %
5509 %  The format of the RecolorImage method is:
5510 %
5511 %      Image *RecolorImage(const Image *image,const unsigned long order,
5512 %        const double *color_matrix,ExceptionInfo *exception)
5513 %
5514 %  A description of each parameter follows:
5515 %
5516 %    o image: the image.
5517 %
5518 %    o order: the number of columns and rows in the recolor matrix.
5519 %
5520 %    o color_matrix: An array of double representing the recolor matrix.
5521 %
5522 %    o exception: return any errors or warnings in this structure.
5523 %
5524 */
5525 MagickExport Image *RecolorImage(const Image *image,const unsigned long order,
5526   const double *color_matrix,ExceptionInfo *exception)
5527 {
5528   KernelInfo
5529     *kernel_info;
5530
5531   Image
5532     *recolor_image;
5533
5534   kernel_info=AcquireKernelInfo("1");
5535   if (kernel_info == (KernelInfo *) NULL)
5536     return((Image *) NULL);
5537   kernel_info->width=order;
5538   kernel_info->height=order;
5539   kernel_info->values=(double *) color_matrix;
5540   recolor_image=ColorMatrixImage(image,kernel_info,exception);
5541   kernel_info->values=(double *) NULL;
5542   kernel_info=DestroyKernelInfo(kernel_info);
5543   return(recolor_image);
5544 }
5545 \f
5546 /*
5547 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5548 %                                                                             %
5549 %                                                                             %
5550 %                                                                             %
5551 %   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                     %
5552 %                                                                             %
5553 %                                                                             %
5554 %                                                                             %
5555 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5556 %
5557 %  ResetImageAttributeIterator() resets the image attributes iterator.  Use it
5558 %  in conjunction with GetNextImageAttribute() to iterate over all the values
5559 %  associated with an image.
5560 %
5561 %  Deprecated, replace with:
5562 %
5563 %    ResetImagePropertyIterator(image);
5564 %
5565 %  The format of the ResetImageAttributeIterator method is:
5566 %
5567 %      ResetImageAttributeIterator(const ImageInfo *image)
5568 %
5569 %  A description of each parameter follows:
5570 %
5571 %    o image: the image.
5572 %
5573 */
5574 MagickExport void ResetImageAttributeIterator(const Image *image)
5575 {
5576   ResetImagePropertyIterator(image);
5577 }
5578 \f
5579 /*
5580 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5581 %                                                                             %
5582 %                                                                             %
5583 %                                                                             %
5584 %   S e t C a c h e V i e w P i x e l s                                       %
5585 %                                                                             %
5586 %                                                                             %
5587 %                                                                             %
5588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5589 %
5590 %  SetCacheViewPixels() gets pixels from the in-memory or disk pixel cache as
5591 %  defined by the geometry parameters.   A pointer to the pixels is returned
5592 %  if the pixels are transferred, otherwise a NULL is returned.
5593 %
5594 %  Deprecated, replace with:
5595 %
5596 %    QueueCacheViewAuthenticPixels(cache_view,x,y,columns,rows,
5597 %      GetCacheViewException(cache_view));
5598 %
5599 %  The format of the SetCacheViewPixels method is:
5600 %
5601 %      PixelPacket *SetCacheViewPixels(CacheView *cache_view,const long x,
5602 %        const long y,const unsigned long columns,const unsigned long rows)
5603 %
5604 %  A description of each parameter follows:
5605 %
5606 %    o cache_view: the cache view.
5607 %
5608 %    o x,y,columns,rows:  These values define the perimeter of a region of
5609 %      pixels.
5610 %
5611 */
5612 MagickExport PixelPacket *SetCacheViewPixels(CacheView *cache_view,const long x,
5613   const long y,const unsigned long columns,const unsigned long rows)
5614 {
5615   PixelPacket
5616     *pixels;
5617
5618   pixels=QueueCacheViewAuthenticPixels(cache_view,x,y,columns,rows,
5619     GetCacheViewException(cache_view));
5620   return(pixels);
5621 }
5622 \f
5623 /*
5624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5625 %                                                                             %
5626 %                                                                             %
5627 %                                                                             %
5628 +   S e t C a c h e T h e s h o l d                                           %
5629 %                                                                             %
5630 %                                                                             %
5631 %                                                                             %
5632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5633 %
5634 %  SetCacheThreshold() sets the amount of free memory allocated for the pixel
5635 %  cache.  Once this threshold is exceeded, all subsequent pixels cache
5636 %  operations are to/from disk.
5637 %
5638 %  The format of the SetCacheThreshold() method is:
5639 %
5640 %      void SetCacheThreshold(const size_t threshold)
5641 %
5642 %  A description of each parameter follows:
5643 %
5644 %    o threshold: the number of megabytes of memory available to the pixel
5645 %      cache.
5646 %
5647 */
5648 MagickExport void SetCacheThreshold(const unsigned long size)
5649 {
5650   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1");
5651   (void) SetMagickResourceLimit(MemoryResource,size*1024*1024);
5652   (void) SetMagickResourceLimit(MapResource,2*size*1024*1024);
5653 }
5654 \f
5655 /*
5656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5657 %                                                                             %
5658 %                                                                             %
5659 %                                                                             %
5660 %   S e t E x c e p t i o n I n f o                                           %
5661 %                                                                             %
5662 %                                                                             %
5663 %                                                                             %
5664 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5665 %
5666 %  SetExceptionInfo() sets the exception severity.
5667 %
5668 %  The format of the SetExceptionInfo method is:
5669 %
5670 %      MagickBooleanType SetExceptionInfo(ExceptionInfo *exception,
5671 %        ExceptionType severity)
5672 %
5673 %  A description of each parameter follows:
5674 %
5675 %    o exception: the exception info.
5676 %
5677 %    o severity: the exception severity.
5678 %
5679 */
5680 MagickExport MagickBooleanType SetExceptionInfo(ExceptionInfo *exception,
5681   ExceptionType severity)
5682 {
5683   assert(exception != (ExceptionInfo *) NULL);
5684   ClearMagickException(exception);
5685   exception->severity=severity;
5686   return(MagickTrue);
5687 }
5688 \f
5689 /*
5690 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5691 %                                                                             %
5692 %                                                                             %
5693 %                                                                             %
5694 %   S e t I m a g e                                                           %
5695 %                                                                             %
5696 %                                                                             %
5697 %                                                                             %
5698 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5699 %
5700 %  SetImage() sets the red, green, and blue components of each pixel to
5701 %  the image background color and the opacity component to the specified
5702 %  level of transparency.  The background color is defined by the
5703 %  background_color member of the image.
5704 %
5705 %  The format of the SetImage method is:
5706 %
5707 %      void SetImage(Image *image,const Quantum opacity)
5708 %
5709 %  A description of each parameter follows:
5710 %
5711 %    o image: the image.
5712 %
5713 %    o opacity: Set each pixel to this level of transparency.
5714 %
5715 */
5716 MagickExport void SetImage(Image *image,const Quantum opacity)
5717 {
5718   long
5719     y;
5720
5721   PixelPacket
5722     background_color;
5723
5724   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.0");
5725   assert(image != (Image *) NULL);
5726   if (image->debug != MagickFalse)
5727     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5728   assert(image->signature == MagickSignature);
5729   background_color=image->background_color;
5730   if (opacity != OpaqueOpacity)
5731     background_color.opacity=opacity;
5732   if (background_color.opacity != OpaqueOpacity)
5733     {
5734       (void) SetImageStorageClass(image,DirectClass);
5735       image->matte=MagickTrue;
5736     }
5737   if ((image->storage_class == PseudoClass) ||
5738       (image->colorspace == CMYKColorspace))
5739     {
5740       /*
5741         Set colormapped or CMYK image.
5742       */
5743       for (y=0; y < (long) image->rows; y++)
5744       {
5745         register IndexPacket
5746           *restrict indexes;
5747
5748         register long
5749           x;
5750
5751         register PixelPacket
5752           *restrict q;
5753
5754         q=QueueAuthenticPixels(image,0,y,image->columns,1,&image->exception);
5755         if (q == (PixelPacket *) NULL)
5756           break;
5757         for (x=0; x < (long) image->columns; x++)
5758           *q++=background_color;
5759         indexes=GetAuthenticIndexQueue(image);
5760         for (x=0; x < (long) image->columns; x++)
5761           indexes[x]=(IndexPacket) 0;
5762         if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
5763           break;
5764       }
5765       return;
5766     }
5767   /*
5768     Set DirectClass image.
5769   */
5770   for (y=0; y < (long) image->rows; y++)
5771   {
5772     register long
5773       x;
5774
5775     register PixelPacket
5776       *restrict q;
5777
5778     q=QueueAuthenticPixels(image,0,y,image->columns,1,&image->exception);
5779     if (q == (PixelPacket *) NULL)
5780       break;
5781     for (x=0; x < (long) image->columns; x++)
5782       *q++=background_color;
5783     if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
5784       break;
5785   }
5786 }
5787 \f
5788 /*
5789 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5790 %                                                                             %
5791 %                                                                             %
5792 %                                                                             %
5793 %   S e t I m a g e A t t r i b u t e                                         %
5794 %                                                                             %
5795 %                                                                             %
5796 %                                                                             %
5797 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5798 %
5799 %  SetImageAttribute() searches the list of image attributes and replaces the
5800 %  attribute value.  If it is not found in the list, the attribute name
5801 %  and value is added to the list.
5802 %
5803 %  Deprecated, replace with:
5804 %
5805 %    SetImageProperty(image,key,value);
5806 %
5807 %  The format of the SetImageAttribute method is:
5808 %
5809 %       MagickBooleanType SetImageAttribute(Image *image,const char *key,
5810 %         const char *value)
5811 %
5812 %  A description of each parameter follows:
5813 %
5814 %    o image: the image.
5815 %
5816 %    o key: the key.
5817 %
5818 %    o value: the value.
5819 %
5820 */
5821 MagickExport MagickBooleanType SetImageAttribute(Image *image,const char *key,
5822   const char *value)
5823 {
5824   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.3.1");
5825   return(SetImageProperty(image,key,value));
5826 }
5827 \f
5828 /*
5829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5830 %                                                                             %
5831 %                                                                             %
5832 %                                                                             %
5833 %   S e t I m a g e L i s t                                                   %
5834 %                                                                             %
5835 %                                                                             %
5836 %                                                                             %
5837 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5838 %
5839 %  SetImageList() inserts an image into the list at the specified position.
5840 %
5841 %  The format of the SetImageList method is:
5842 %
5843 %      unsigned int SetImageList(Image *images,const Image *image,
5844 %        const long offset,ExceptionInfo *exception)
5845 %
5846 %  A description of each parameter follows:
5847 %
5848 %    o images: the image list.
5849 %
5850 %    o image: the image.
5851 %
5852 %    o offset: the position within the list.
5853 %
5854 %    o exception: return any errors or warnings in this structure.
5855 %
5856 */
5857 MagickExport unsigned int SetImageList(Image **images,const Image *image,
5858   const long offset,ExceptionInfo *exception)
5859 {
5860   Image
5861     *clone;
5862
5863   register long
5864     i;
5865
5866   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
5867   clone=CloneImageList(image,exception);
5868   while (GetPreviousImageInList(*images) != (Image *) NULL)
5869     (*images)=GetPreviousImageInList(*images);
5870   for (i=0; i < offset; i++)
5871   {
5872     if (GetNextImageInList(*images) == (Image *) NULL)
5873       return(MagickFalse);
5874     (*images)=GetNextImageInList(*images);
5875   }
5876   InsertImageInList(images,clone);
5877   return(MagickTrue);
5878 }
5879 \f
5880 /*
5881 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5882 %                                                                             %
5883 %                                                                             %
5884 %                                                                             %
5885 %   S e t I m a g e P i x e l s                                               %
5886 %                                                                             %
5887 %                                                                             %
5888 %                                                                             %
5889 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5890 %
5891 %  SetImagePixels() queues a mutable pixel region.
5892 %  If the region is successfully intialized a pointer to a PixelPacket
5893 %  array representing the region is returned, otherwise NULL is returned.
5894 %  The returned pointer may point to a temporary working buffer for the
5895 %  pixels or it may point to the final location of the pixels in memory.
5896 %
5897 %  Write-only access means that any existing pixel values corresponding to
5898 %  the region are ignored.  This useful while the initial image is being
5899 %  created from scratch, or if the existing pixel values are to be
5900 %  completely replaced without need to refer to their pre-existing values.
5901 %  The application is free to read and write the pixel buffer returned by
5902 %  SetImagePixels() any way it pleases. SetImagePixels() does not initialize
5903 %  the pixel array values. Initializing pixel array values is the
5904 %  application's responsibility.
5905 %
5906 %  Performance is maximized if the selected region is part of one row, or
5907 %  one or more full rows, since then there is opportunity to access the
5908 %  pixels in-place (without a copy) if the image is in RAM, or in a
5909 %  memory-mapped file. The returned pointer should *never* be deallocated
5910 %  by the user.
5911 %
5912 %  Pixels accessed via the returned pointer represent a simple array of type
5913 %  PixelPacket. If the image type is CMYK or the storage class is PseudoClass,
5914 %  call GetAuthenticIndexQueue() after invoking GetAuthenticPixels() to obtain
5915 %  the black color component or the colormap indexes (of type IndexPacket)
5916 %  corresponding to the region.  Once the PixelPacket (and/or IndexPacket)
5917 %  array has been updated, the changes must be saved back to the underlying
5918 %  image using SyncAuthenticPixels() or they may be lost.
5919 %
5920 %  Deprecated, replace with:
5921 %
5922 %    QueueAuthenticPixels(image,x,y,columns,rows,&image->exception);
5923 %
5924 %  The format of the SetImagePixels() method is:
5925 %
5926 %      PixelPacket *SetImagePixels(Image *image,const long x,const long y,
5927 %        const unsigned long columns,const unsigned long rows)
5928 %
5929 %  A description of each parameter follows:
5930 %
5931 %    o pixels: SetImagePixels returns a pointer to the pixels if they are
5932 %      transferred, otherwise a NULL is returned.
5933 %
5934 %    o image: the image.
5935 %
5936 %    o x,y,columns,rows:  These values define the perimeter of a region of
5937 %      pixels.
5938 %
5939 */
5940 MagickExport PixelPacket *SetImagePixels(Image *image,const long x,const long y,
5941   const unsigned long columns,const unsigned long rows)
5942 {
5943   return(QueueAuthenticPixels(image,x,y,columns,rows,&image->exception));
5944 }
5945 \f
5946 /*
5947 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5948 %                                                                             %
5949 %                                                                             %
5950 %                                                                             %
5951 %   S e t M a g i c k R e g i s t r y                                         %
5952 %                                                                             %
5953 %                                                                             %
5954 %                                                                             %
5955 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5956 %
5957 %  SetMagickRegistry() sets a blob into the registry and returns a unique ID.
5958 %  If an error occurs, -1 is returned.
5959 %
5960 %  The format of the SetMagickRegistry method is:
5961 %
5962 %      long SetMagickRegistry(const RegistryType type,const void *blob,
5963 %        const size_t length,ExceptionInfo *exception)
5964 %
5965 %  A description of each parameter follows:
5966 %
5967 %    o type: the registry type.
5968 %
5969 %    o blob: the address of a Binary Large OBject.
5970 %
5971 %    o length: For a registry type of ImageRegistryType use sizeof(Image)
5972 %      otherise the blob length in number of bytes.
5973 %
5974 %    o exception: return any errors or warnings in this structure.
5975 %
5976 */
5977 MagickExport long SetMagickRegistry(const RegistryType type,const void *blob,
5978   const size_t magick_unused(length),ExceptionInfo *exception)
5979 {
5980   char
5981     key[MaxTextExtent];
5982
5983   MagickBooleanType
5984     status;
5985
5986   static long
5987     id = 0;
5988
5989   (void) FormatMagickString(key,MaxTextExtent,"%ld\n",id);
5990   status=SetImageRegistry(type,key,blob,exception);
5991   if (status == MagickFalse)
5992     return(-1);
5993   return(id++);
5994 }
5995 \f
5996 /*
5997 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5998 %                                                                             %
5999 %                                                                             %
6000 %                                                                             %
6001 %   S e t M o n i t o r H a n d l e r                                         %
6002 %                                                                             %
6003 %                                                                             %
6004 %                                                                             %
6005 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6006 %
6007 %  SetMonitorHandler() sets the monitor handler to the specified method
6008 %  and returns the previous monitor handler.
6009 %
6010 %  The format of the SetMonitorHandler method is:
6011 %
6012 %      MonitorHandler SetMonitorHandler(MonitorHandler handler)
6013 %
6014 %  A description of each parameter follows:
6015 %
6016 %    o handler: Specifies a pointer to a method to handle monitors.
6017 %
6018 */
6019
6020 MagickExport MonitorHandler GetMonitorHandler(void)
6021 {
6022   return(monitor_handler);
6023 }
6024
6025 MagickExport MonitorHandler SetMonitorHandler(MonitorHandler handler)
6026 {
6027   MonitorHandler
6028     previous_handler;
6029
6030   previous_handler=monitor_handler;
6031   monitor_handler=handler;
6032   return(previous_handler);
6033 }
6034 \f
6035 /*
6036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6037 %                                                                             %
6038 %                                                                             %
6039 %                                                                             %
6040 %   S h i f t I m a g e L i s t                                               %
6041 %                                                                             %
6042 %                                                                             %
6043 %                                                                             %
6044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6045 %
6046 %  ShiftImageList() removes an image from the beginning of the list.
6047 %
6048 %  Deprecated, replace with:
6049 %
6050 %    RemoveFirstImageFromList(images);
6051 %
6052 %  The format of the ShiftImageList method is:
6053 %
6054 %      Image *ShiftImageList(Image **images)
6055 %
6056 %  A description of each parameter follows:
6057 %
6058 %    o images: the image list.
6059 %
6060 */
6061 MagickExport Image *ShiftImageList(Image **images)
6062 {
6063   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
6064   return(RemoveFirstImageFromList(images));
6065 }
6066 \f
6067 /*
6068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6069 %                                                                             %
6070 %                                                                             %
6071 %                                                                             %
6072 +  S i z e B l o b                                                            %
6073 %                                                                             %
6074 %                                                                             %
6075 %                                                                             %
6076 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6077 %
6078 %  SizeBlob() returns the current length of the image file or blob.
6079 %
6080 %  Deprecated, replace with:
6081 %
6082 %    GetBlobSize(image);
6083 %
6084 %  The format of the SizeBlob method is:
6085 %
6086 %      off_t SizeBlob(Image *image)
6087 %
6088 %  A description of each parameter follows:
6089 %
6090 %    o size:  Method SizeBlob returns the current length of the image file
6091 %      or blob.
6092 %
6093 %    o image: the image.
6094 %
6095 */
6096 MagickExport MagickOffsetType SizeBlob(Image *image)
6097 {
6098   if (image->debug != MagickFalse)
6099     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.4.3");
6100   return((MagickOffsetType) GetBlobSize(image));
6101 }
6102 \f
6103 /*
6104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6105 %                                                                             %
6106 %                                                                             %
6107 %                                                                             %
6108 %   S p l i c e I m a g e L i s t                                             %
6109 %                                                                             %
6110 %                                                                             %
6111 %                                                                             %
6112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6113 %
6114 %  SpliceImageList() removes the images designated by offset and length from
6115 %  the list and replaces them with the specified list.
6116 %
6117 %  The format of the SpliceImageList method is:
6118 %
6119 %      Image *SpliceImageList(Image *images,const long offset,
6120 %        const unsigned long length,const Image *splices,
6121 %        ExceptionInfo *exception)
6122 %
6123 %  A description of each parameter follows:
6124 %
6125 %    o images: the image list.
6126 %
6127 %    o offset: the position within the list.
6128 %
6129 %    o length: the length of the image list to remove.
6130 %
6131 %    o splice: Replace the removed image list with this list.
6132 %
6133 %    o exception: return any errors or warnings in this structure.
6134 %
6135 */
6136 MagickExport Image *SpliceImageList(Image *images,const long offset,
6137   const unsigned long length,const Image *splices,ExceptionInfo *exception)
6138 {
6139   Image
6140     *clone;
6141
6142   register long
6143     i;
6144
6145   if (images->debug != MagickFalse)
6146     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
6147   clone=CloneImageList(splices,exception);
6148   while (GetPreviousImageInList(images) != (Image *) NULL)
6149     images=GetPreviousImageInList(images);
6150   for (i=0; i < offset; i++)
6151   {
6152     if (GetNextImageInList(images) == (Image *) NULL)
6153       return((Image *) NULL);
6154     images=GetNextImageInList(images);
6155   }
6156   (void) SpliceImageIntoList(&images,length,clone);
6157   return(images);
6158 }
6159 \f
6160 /*
6161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6162 %                                                                             %
6163 %                                                                             %
6164 %                                                                             %
6165 %   S t r i p                                                                 %
6166 %                                                                             %
6167 %                                                                             %
6168 %                                                                             %
6169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6170 %
6171 %  Strip() strips any whitespace or quotes from the beginning and end of a
6172 %  string of characters.
6173 %
6174 %  The format of the Strip method is:
6175 %
6176 %      void Strip(char *message)
6177 %
6178 %  A description of each parameter follows:
6179 %
6180 %    o message: Specifies an array of characters.
6181 %
6182 */
6183 MagickExport void Strip(char *message)
6184 {
6185   register char
6186     *p,
6187     *q;
6188
6189   assert(message != (char *) NULL);
6190   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
6191   if (*message == '\0')
6192     return;
6193   if (strlen(message) == 1)
6194     return;
6195   p=message;
6196   while (isspace((int) ((unsigned char) *p)) != 0)
6197     p++;
6198   if ((*p == '\'') || (*p == '"'))
6199     p++;
6200   q=message+strlen(message)-1;
6201   while ((isspace((int) ((unsigned char) *q)) != 0) && (q > p))
6202     q--;
6203   if (q > p)
6204     if ((*q == '\'') || (*q == '"'))
6205       q--;
6206   (void) CopyMagickMemory(message,p,(size_t) (q-p+1));
6207   message[q-p+1]='\0';
6208 }
6209 \f
6210 /*
6211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6212 %                                                                             %
6213 %                                                                             %
6214 %                                                                             %
6215 %   S y n c C a c h e V i e w                                                 %
6216 %                                                                             %
6217 %                                                                             %
6218 %                                                                             %
6219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6220 %
6221 %  SyncCacheView() saves the cache view pixels to the in-memory or disk
6222 %  cache.  It returns MagickTrue if the pixel region is synced, otherwise
6223 %  MagickFalse.
6224 %
6225 %  Deprecated, replace with:
6226 %
6227 %    SyncCacheViewAuthenticPixels(cache_view,GetCacheViewException(cache_view));
6228 %
6229 %  The format of the SyncCacheView method is:
6230 %
6231 %      MagickBooleanType SyncCacheView(CacheView *cache_view)
6232 %
6233 %  A description of each parameter follows:
6234 %
6235 %    o cache_view: the cache view.
6236 %
6237 */
6238 MagickExport MagickBooleanType SyncCacheView(CacheView *cache_view)
6239 {
6240   MagickBooleanType
6241     status;
6242
6243   status=SyncCacheViewAuthenticPixels(cache_view,
6244     GetCacheViewException(cache_view));
6245   return(status);
6246 }
6247 \f
6248 /*
6249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6250 %                                                                             %
6251 %                                                                             %
6252 %                                                                             %
6253 %   S y n c C a c h e V i e w P i x e l s                                     %
6254 %                                                                             %
6255 %                                                                             %
6256 %                                                                             %
6257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6258 %
6259 %  SyncCacheViewPixels() saves the cache view pixels to the in-memory
6260 %  or disk cache.  It returns MagickTrue if the pixel region is flushed,
6261 %  otherwise MagickFalse.
6262 %
6263 %  Deprecated, replace with:
6264 %
6265 %    SyncCacheViewAuthenticPixels(cache_view,GetCacheViewException(cache_view));
6266 %
6267 %  The format of the SyncCacheViewPixels method is:
6268 %
6269 %      MagickBooleanType SyncCacheViewPixels(CacheView *cache_view)
6270 %
6271 %  A description of each parameter follows:
6272 %
6273 %    o cache_view: the cache view.
6274 %
6275 %    o exception: return any errors or warnings in this structure.
6276 %
6277 */
6278 MagickExport MagickBooleanType SyncCacheViewPixels(CacheView *cache_view)
6279 {
6280   MagickBooleanType
6281     status;
6282
6283   status=SyncCacheViewAuthenticPixels(cache_view,
6284     GetCacheViewException(cache_view));
6285   return(status);
6286 }
6287 \f
6288 /*
6289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6290 %                                                                             %
6291 %                                                                             %
6292 %                                                                             %
6293 %   S y n c I m a g e P i x e l s                                             %
6294 %                                                                             %
6295 %                                                                             %
6296 %                                                                             %
6297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6298 %
6299 %  SyncImagePixels() saves the image pixels to the in-memory or disk cache.
6300 %  The method returns MagickTrue if the pixel region is synced, otherwise
6301 %  MagickFalse.
6302 %
6303 %  Deprecated, replace with:
6304 %
6305 %    SyncAuthenticPixels(image,&image->exception);
6306 %
6307 %  The format of the SyncImagePixels() method is:
6308 %
6309 %      MagickBooleanType SyncImagePixels(Image *image)
6310 %
6311 %  A description of each parameter follows:
6312 %
6313 %    o image: the image.
6314 %
6315 */
6316 MagickExport MagickBooleanType SyncImagePixels(Image *image)
6317 {
6318   return(SyncAuthenticPixels(image,&image->exception));
6319 }
6320 \f
6321 /*
6322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6323 %                                                                             %
6324 %                                                                             %
6325 %                                                                             %
6326 %  T e m p o r a r y F i l e n a m e                                          %
6327 %                                                                             %
6328 %                                                                             %
6329 %                                                                             %
6330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6331 %
6332 %  TemporaryFilename() replaces the contents of path by a unique path name.
6333 %
6334 %  The format of the TemporaryFilename method is:
6335 %
6336 %      void TemporaryFilename(char *path)
6337 %
6338 %  A description of each parameter follows.
6339 %
6340 %   o  path:  Specifies a pointer to an array of characters.  The unique path
6341 %      name is returned in this array.
6342 %
6343 */
6344 MagickExport void TemporaryFilename(char *path)
6345 {
6346   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.6");
6347   (void) AcquireUniqueFilename(path);
6348   (void) RelinquishUniqueFileResource(path);
6349 }
6350 \f
6351 /*
6352 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6353 %                                                                             %
6354 %                                                                             %
6355 %                                                                             %
6356 %     T h r e s h o l d I m a g e                                             %
6357 %                                                                             %
6358 %                                                                             %
6359 %                                                                             %
6360 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6361 %
6362 %  ThresholdImage() changes the value of individual pixels based on
6363 %  the intensity of each pixel compared to threshold.  The result is a
6364 %  high-contrast, two color image.
6365 %
6366 %  The format of the ThresholdImage method is:
6367 %
6368 %      unsigned int ThresholdImage(Image *image,const double threshold)
6369 %
6370 %  A description of each parameter follows:
6371 %
6372 %    o image: the image.
6373 %
6374 %    o threshold: Define the threshold value
6375 %
6376 */
6377 MagickExport unsigned int ThresholdImage(Image *image,const double threshold)
6378 {
6379 #define ThresholdImageTag  "Threshold/Image"
6380
6381   IndexPacket
6382     index;
6383
6384   long
6385     y;
6386
6387   /*
6388     Threshold image.
6389   */
6390   assert(image != (Image *) NULL);
6391   assert(image->signature == MagickSignature);
6392   if (image->debug != MagickFalse)
6393     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6394   if (image->debug != MagickFalse)
6395     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7");
6396   if (!AcquireImageColormap(image,2))
6397     ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
6398       "UnableToThresholdImage");
6399   for (y=0; y < (long) image->rows; y++)
6400   {
6401     register IndexPacket
6402       *restrict indexes;
6403
6404     register long
6405       x;
6406
6407     register PixelPacket
6408       *restrict q;
6409
6410     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
6411     if (q == (PixelPacket *) NULL)
6412       break;
6413     indexes=GetAuthenticIndexQueue(image);
6414     for (x=0; x < (long) image->columns; x++)
6415     {
6416       index=(IndexPacket) ((MagickRealType)
6417         PixelIntensityToQuantum(q) <= threshold ? 0 : 1);
6418       indexes[x]=index;
6419       q->red=image->colormap[(long) index].red;
6420       q->green=image->colormap[(long) index].green;
6421       q->blue=image->colormap[(long) index].blue;
6422       q++;
6423     }
6424     if (!SyncAuthenticPixels(image,&image->exception))
6425       break;
6426   }
6427   return(MagickTrue);
6428 }
6429 \f
6430 /*
6431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6432 %                                                                             %
6433 %                                                                             %
6434 %                                                                             %
6435 %     T h r e s h o l d I m a g e C h a n n e l                               %
6436 %                                                                             %
6437 %                                                                             %
6438 %                                                                             %
6439 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6440 %
6441 %  ThresholdImageChannel() changes the value of individual pixels based on
6442 %  the intensity of each pixel channel.  The result is a high-contrast image.
6443 %
6444 %  The format of the ThresholdImageChannel method is:
6445 %
6446 %      unsigned int ThresholdImageChannel(Image *image,const char *threshold)
6447 %
6448 %  A description of each parameter follows:
6449 %
6450 %    o image: the image.
6451 %
6452 %    o threshold: define the threshold values.
6453 %
6454 */
6455 MagickExport unsigned int ThresholdImageChannel(Image *image,
6456   const char *threshold)
6457 {
6458 #define ThresholdImageTag  "Threshold/Image"
6459
6460   MagickPixelPacket
6461     pixel;
6462
6463   GeometryInfo
6464     geometry_info;
6465
6466   IndexPacket
6467     index;
6468
6469   long
6470     y;
6471
6472   unsigned int
6473     flags;
6474
6475   /*
6476     Threshold image.
6477   */
6478   assert(image != (Image *) NULL);
6479   assert(image->signature == MagickSignature);
6480   if (image->debug != MagickFalse)
6481     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6482   if (threshold == (const char *) NULL)
6483     return(MagickTrue);
6484   if (SetImageStorageClass(image,DirectClass) == MagickFalse)
6485     return(MagickFalse);
6486   flags=ParseGeometry(threshold,&geometry_info);
6487   pixel.red=geometry_info.rho;
6488   if (flags & SigmaValue)
6489     pixel.green=geometry_info.sigma;
6490   else
6491     pixel.green=pixel.red;
6492   if (flags & XiValue)
6493     pixel.blue=geometry_info.xi;
6494   else
6495     pixel.blue=pixel.red;
6496   if (flags & PsiValue)
6497     pixel.opacity=geometry_info.psi;
6498   else
6499     pixel.opacity=(MagickRealType) OpaqueOpacity;
6500   if (flags & PercentValue)
6501     {
6502       pixel.red*=QuantumRange/100.0f;
6503       pixel.green*=QuantumRange/100.0f;
6504       pixel.blue*=QuantumRange/100.0f;
6505       pixel.opacity*=QuantumRange/100.0f;
6506     }
6507   if (!(flags & SigmaValue))
6508     {
6509       if (!AcquireImageColormap(image,2))
6510         ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
6511           "UnableToThresholdImage");
6512       if (pixel.red == 0)
6513         (void) GetImageDynamicThreshold(image,2.0,2.0,&pixel,&image->exception);
6514     }
6515   for (y=0; y < (long) image->rows; y++)
6516   {
6517     register IndexPacket
6518       *restrict indexes;
6519
6520     register long
6521       x;
6522
6523     register PixelPacket
6524       *restrict q;
6525
6526     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
6527     if (q == (PixelPacket *) NULL)
6528       break;
6529     indexes=GetAuthenticIndexQueue(image);
6530     if (IsMagickGray(&pixel) != MagickFalse)
6531       for (x=0; x < (long) image->columns; x++)
6532       {
6533         index=(IndexPacket) ((MagickRealType)
6534           PixelIntensityToQuantum(q) <= pixel.red ? 0 : 1);
6535         indexes[x]=index;
6536         q->red=image->colormap[(long) index].red;
6537         q->green=image->colormap[(long) index].green;
6538         q->blue=image->colormap[(long) index].blue;
6539         q++;
6540       }
6541     else
6542       for (x=0; x < (long) image->columns; x++)
6543       {
6544         q->red=(Quantum) ((MagickRealType)
6545           q->red <= pixel.red ? 0 : QuantumRange);
6546         q->green=(Quantum) ((MagickRealType)
6547           q->green <= pixel.green ? 0 : QuantumRange);
6548         q->blue=(Quantum) ((MagickRealType)
6549           q->blue <= pixel.blue ? 0 : QuantumRange);
6550         q->opacity=(Quantum) ((MagickRealType)
6551           q->opacity <= pixel.opacity ? 0 : QuantumRange);
6552         q++;
6553       }
6554     if (!SyncAuthenticPixels(image,&image->exception))
6555       break;
6556   }
6557   return(MagickTrue);
6558 }
6559 \f
6560 /*
6561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6562 %                                                                              %
6563 %                                                                              %
6564 %                                                                              %
6565 +     T r a n s f o r m C o l o r s p a c e                                    %
6566 %                                                                              %
6567 %                                                                              %
6568 %                                                                              %
6569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6570 %
6571 %  TransformColorspace() converts the image to a specified colorspace.
6572 %  If the image is already in the requested colorspace, no work is performed.
6573 %  Note that the current colorspace is stored in the image colorspace member.
6574 %  The transformation matrices are not necessarily the standard ones: the
6575 %  weights are rescaled to normalize the range of the transformed values to
6576 %  be [0..QuantumRange].
6577 %
6578 %  Deprecated, replace with:
6579 %
6580 %    TransformImageColorspace(image,colorspace);
6581 %
6582 %  The format of the TransformColorspace method is:
6583 %
6584 %      unsigned int (void) TransformColorspace(Image *image,
6585 %        const ColorspaceType colorspace)
6586 %
6587 %  A description of each parameter follows:
6588 %
6589 %    o image: the image to transform
6590 %
6591 %    o colorspace: the desired colorspace.
6592 %
6593 */
6594 MagickExport unsigned int TransformColorspace(Image *image,
6595   const ColorspaceType colorspace)
6596 {
6597   assert(image != (Image *) NULL);
6598   assert(image->signature == MagickSignature);
6599   if (image->debug != MagickFalse)
6600     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.6");
6601   return(TransformImageColorspace(image,colorspace));
6602 }
6603 \f
6604 /*
6605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6606 %                                                                             %
6607 %                                                                             %
6608 %                                                                             %
6609 %   T r a n s f o r m H S L                                                   %
6610 %                                                                             %
6611 %                                                                             %
6612 %                                                                             %
6613 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6614 %
6615 %  TransformHSL() converts a (red, green, blue) to a (hue, saturation,
6616 %  lightness) triple.
6617 %
6618 %  The format of the TransformHSL method is:
6619 %
6620 %      void TransformHSL(const Quantum red,const Quantum green,
6621 %        const Quantum blue,double *hue,double *saturation,double *lightness)
6622 %
6623 %  A description of each parameter follows:
6624 %
6625 %    o red, green, blue: A Quantum value representing the red, green, and
6626 %      blue component of a pixel..
6627 %
6628 %    o hue, saturation, lightness: A pointer to a double value representing a
6629 %      component of the HSL color space.
6630 %
6631 */
6632
6633 static inline double MagickMin(const double x,const double y)
6634 {
6635   if (x < y)
6636     return(x);
6637   return(y);
6638 }
6639
6640 MagickExport void TransformHSL(const Quantum red,const Quantum green,
6641   const Quantum blue,double *hue,double *saturation,double *lightness)
6642 {
6643   MagickRealType
6644     b,
6645     delta,
6646     g,
6647     max,
6648     min,
6649     r;
6650
6651   /*
6652     Convert RGB to HSL colorspace.
6653   */
6654   assert(hue != (double *) NULL);
6655   assert(saturation != (double *) NULL);
6656   assert(lightness != (double *) NULL);
6657   r=QuantumScale*red;
6658   g=QuantumScale*green;
6659   b=QuantumScale*blue;
6660   max=MagickMax(r,MagickMax(g,b));
6661   min=MagickMin(r,MagickMin(g,b));
6662   *hue=0.0;
6663   *saturation=0.0;
6664   *lightness=(double) ((min+max)/2.0);
6665   delta=max-min;
6666   if (delta == 0.0)
6667     return;
6668   *saturation=(double) (delta/((*lightness < 0.5) ? (min+max) :
6669     (2.0-max-min)));
6670   if (r == max)
6671     *hue=(double) (g == min ? 5.0+(max-b)/delta : 1.0-(max-g)/delta);
6672   else
6673     if (g == max)
6674       *hue=(double) (b == min ? 1.0+(max-r)/delta : 3.0-(max-b)/delta);
6675     else
6676       *hue=(double) (r == min ? 3.0+(max-g)/delta : 5.0-(max-r)/delta);
6677   *hue/=6.0;
6678 }
6679 \f
6680 /*
6681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6682 %                                                                             %
6683 %                                                                             %
6684 %                                                                             %
6685 %   T r a n s l a t e T e x t                                                 %
6686 %                                                                             %
6687 %                                                                             %
6688 %                                                                             %
6689 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6690 %
6691 %  TranslateText() replaces any embedded formatting characters with the
6692 %  appropriate image attribute and returns the translated text.
6693 %
6694 %  Deprecated, replace with:
6695 %
6696 %    InterpretImageProperties(image_info,image,embed_text);
6697 %
6698 %  The format of the TranslateText method is:
6699 %
6700 %      char *TranslateText(const ImageInfo *image_info,Image *image,
6701 %        const char *embed_text)
6702 %
6703 %  A description of each parameter follows:
6704 %
6705 %    o image_info: the image info.
6706 %
6707 %    o image: the image.
6708 %
6709 %    o embed_text: the address of a character string containing the embedded
6710 %      formatting characters.
6711 %
6712 */
6713 MagickExport char *TranslateText(const ImageInfo *image_info,Image *image,
6714   const char *embed_text)
6715 {
6716   assert(image != (Image *) NULL);
6717   assert(image->signature == MagickSignature);
6718   if (image->debug != MagickFalse)
6719     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.6");
6720   return(InterpretImageProperties(image_info,image,embed_text));
6721 }
6722 \f
6723 /*
6724 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6725 %                                                                             %
6726 %                                                                             %
6727 %                                                                             %
6728 %     T r a n s p a r e n t I m a g e                                         %
6729 %                                                                             %
6730 %                                                                             %
6731 %                                                                             %
6732 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6733 %
6734 %  TransparentImage() changes the opacity value associated with any pixel
6735 %  that matches color to the value defined by opacity.
6736 %
6737 %  By default color must match a particular pixel color exactly.  However,
6738 %  in many cases two colors may differ by a small amount.  Fuzz defines
6739 %  how much tolerance is acceptable to consider two colors as the same.
6740 %  For example, set fuzz to 10 and the color red at intensities of 100 and
6741 %  102 respectively are now interpreted as the same color.
6742 %
6743 %  The format of the TransparentImage method is:
6744 %
6745 %      MagickBooleanType TransparentImage(Image *image,
6746 %        const PixelPacket target,const Quantum opacity)
6747 %
6748 %  A description of each parameter follows:
6749 %
6750 %    o image: the image.
6751 %
6752 %    o target: the RGB value of the target color.
6753 %
6754 %    o opacity: the replacement opacity value.
6755 %
6756 */
6757 MagickExport MagickBooleanType TransparentImage(Image *image,
6758   const PixelPacket target,const Quantum opacity)
6759 {
6760 #define TransparentImageTag  "Transparent/Image"
6761
6762   long
6763     y;
6764
6765   MagickBooleanType
6766     proceed;
6767
6768   /*
6769     Make image color transparent.
6770   */
6771   assert(image != (Image *) NULL);
6772   assert(image->signature == MagickSignature);
6773   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.1.0");
6774   if (image->debug != MagickFalse)
6775     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6776   if (image->matte == MagickFalse)
6777     (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
6778   for (y=0; y < (long) image->rows; y++)
6779   {
6780     register long
6781       x;
6782
6783     register PixelPacket
6784       *restrict q;
6785
6786     q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception);
6787     if (q == (PixelPacket *) NULL)
6788       break;
6789     for (x=0; x < (long) image->columns; x++)
6790     {
6791       if (IsColorSimilar(image,q,&target) != MagickFalse)
6792         q->opacity=opacity;
6793       q++;
6794     }
6795     if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
6796       break;
6797     proceed=SetImageProgress(image,TransparentImageTag,y,image->rows);
6798     if (proceed == MagickFalse)
6799       break;
6800   }
6801   return(MagickTrue);
6802 }
6803 \f
6804 /*
6805 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6806 %                                                                             %
6807 %                                                                             %
6808 %                                                                             %
6809 %   U n s h i f t I m a g e L i s t                                           %
6810 %                                                                             %
6811 %                                                                             %
6812 %                                                                             %
6813 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6814 %
6815 %  UnshiftImageList() adds the image to the beginning of the list.
6816 %
6817 %  Deprecated, replace with:
6818 %
6819 %    PrependImageToList(images,CloneImageList(image,exception));
6820 %
6821 %  The format of the UnshiftImageList method is:
6822 %
6823 %      unsigned int UnshiftImageList(Image *images,const Image *image,
6824 %        ExceptionInfo *exception)
6825 %
6826 %  A description of each parameter follows:
6827 %
6828 %    o images: the image list.
6829 %
6830 %    o image: the image.
6831 %
6832 %    o exception: return any errors or warnings in this structure.
6833 %
6834 */
6835 MagickExport unsigned int UnshiftImageList(Image **images,const Image *image,
6836   ExceptionInfo *exception)
6837 {
6838   (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2");
6839   PrependImageToList(images,CloneImageList(image,exception));
6840   return(MagickTrue);
6841 }
6842 \f
6843 /*
6844 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6845 %                                                                             %
6846 %                                                                             %
6847 %                                                                             %
6848 +   V a l i d a t e C o l o r m a p I n d e x                                 %
6849 %                                                                             %
6850 %                                                                             %
6851 %                                                                             %
6852 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6853 %
6854 %  ValidateColormapIndex() validates the colormap index.  If the index does
6855 %  not range from 0 to the number of colors in the colormap an exception
6856 %  issued and 0 is returned.
6857 %
6858 %  Deprecated, replace with:
6859 %
6860 %    ConstrainColormapIndex(image,index);
6861 %
6862 %  The format of the ValidateColormapIndex method is:
6863 %
6864 %      IndexPacket ValidateColormapIndex(Image *image,const unsigned int index)
6865 %
6866 %  A description of each parameter follows:
6867 %
6868 %    o index: Method ValidateColormapIndex returns colormap index if it is
6869 %      valid other an exception issued and 0 is returned.
6870 %
6871 %    o image: the image.
6872 %
6873 %    o index: This integer is the colormap index.
6874 %
6875 */
6876 MagickExport IndexPacket ValidateColormapIndex(Image *image,
6877   const unsigned long index)
6878 {
6879   if (image->debug != MagickFalse)
6880     (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.4.4");
6881   return(ConstrainColormapIndex(image,index));
6882 }
6883 #endif