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