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