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