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