]> granicus.if.org Git - imagemagick/blob - MagickCore/image.c
GetImageMask should not return an image with transparency.
[imagemagick] / MagickCore / image.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %                     IIIII  M   M   AAA    GGGG  EEEEE                       %
7 %                       I    MM MM  A   A  G      E                           %
8 %                       I    M M M  AAAAA  G  GG  EEE                         %
9 %                       I    M   M  A   A  G   G  E                           %
10 %                     IIIII  M   M  A   A   GGGG  EEEEE                       %
11 %                                                                             %
12 %                                                                             %
13 %                           MagickCore Image Methods                          %
14 %                                                                             %
15 %                              Software Design                                %
16 %                                   Cristy                                    %
17 %                                 July 1992                                   %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization      %
21 %  dedicated to making software imaging solutions freely available.           %
22 %                                                                             %
23 %  You may not use this file except in compliance with the License.  You may  %
24 %  obtain a copy of the License at                                            %
25 %                                                                             %
26 %    http://www.imagemagick.org/script/license.php                            %
27 %                                                                             %
28 %  Unless required by applicable law or agreed to in writing, software        %
29 %  distributed under the License is distributed on an "AS IS" BASIS,          %
30 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
31 %  See the License for the specific language governing permissions and        %
32 %  limitations under the License.                                             %
33 %                                                                             %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 %
37 %
38 */
39 \f
40 /*
41   Include declarations.
42 */
43 #include "MagickCore/studio.h"
44 #include "MagickCore/animate.h"
45 #include "MagickCore/artifact.h"
46 #include "MagickCore/attribute.h"
47 #include "MagickCore/blob.h"
48 #include "MagickCore/blob-private.h"
49 #include "MagickCore/cache.h"
50 #include "MagickCore/cache-private.h"
51 #include "MagickCore/cache-view.h"
52 #include "MagickCore/client.h"
53 #include "MagickCore/color.h"
54 #include "MagickCore/color-private.h"
55 #include "MagickCore/colormap.h"
56 #include "MagickCore/colorspace.h"
57 #include "MagickCore/colorspace-private.h"
58 #include "MagickCore/composite.h"
59 #include "MagickCore/composite-private.h"
60 #include "MagickCore/compress.h"
61 #include "MagickCore/constitute.h"
62 #include "MagickCore/display.h"
63 #include "MagickCore/draw.h"
64 #include "MagickCore/enhance.h"
65 #include "MagickCore/exception.h"
66 #include "MagickCore/exception-private.h"
67 #include "MagickCore/gem.h"
68 #include "MagickCore/geometry.h"
69 #include "MagickCore/histogram.h"
70 #include "MagickCore/image-private.h"
71 #include "MagickCore/list.h"
72 #include "MagickCore/magic.h"
73 #include "MagickCore/magick.h"
74 #include "MagickCore/magick-private.h"
75 #include "MagickCore/memory_.h"
76 #include "MagickCore/module.h"
77 #include "MagickCore/monitor.h"
78 #include "MagickCore/monitor-private.h"
79 #include "MagickCore/option.h"
80 #include "MagickCore/paint.h"
81 #include "MagickCore/pixel-accessor.h"
82 #include "MagickCore/profile.h"
83 #include "MagickCore/property.h"
84 #include "MagickCore/quantize.h"
85 #include "MagickCore/random_.h"
86 #include "MagickCore/resource_.h"
87 #include "MagickCore/segment.h"
88 #include "MagickCore/semaphore.h"
89 #include "MagickCore/signature-private.h"
90 #include "MagickCore/statistic.h"
91 #include "MagickCore/string_.h"
92 #include "MagickCore/string-private.h"
93 #include "MagickCore/thread-private.h"
94 #include "MagickCore/threshold.h"
95 #include "MagickCore/timer.h"
96 #include "MagickCore/token.h"
97 #include "MagickCore/utility.h"
98 #include "MagickCore/utility-private.h"
99 #include "MagickCore/version.h"
100 #include "MagickCore/xwindow-private.h"
101 \f
102 /*
103   Constant declaration.
104 */
105 const char
106   BackgroundColor[] = "#ffffff",  /* white */
107   BorderColor[] = "#dfdfdf",  /* gray */
108   DefaultTileFrame[] = "15x15+3+3",
109   DefaultTileGeometry[] = "120x120+4+3>",
110   DefaultTileLabel[] = "%f\n%G\n%b",
111   ForegroundColor[] = "#000",  /* black */
112   LoadImageTag[] = "Load/Image",
113   LoadImagesTag[] = "Load/Images",
114   MatteColor[] = "#bdbdbd",  /* gray */
115   PSDensityGeometry[] = "72.0x72.0",
116   PSPageGeometry[] = "612x792",
117   SaveImageTag[] = "Save/Image",
118   SaveImagesTag[] = "Save/Images",
119   TransparentColor[] = "#00000000";  /* transparent black */
120
121 const double
122   DefaultResolution = 72.0;
123 \f
124 /*
125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 %                                                                             %
127 %                                                                             %
128 %                                                                             %
129 %   A c q u i r e I m a g e                                                   %
130 %                                                                             %
131 %                                                                             %
132 %                                                                             %
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 %
135 %  AcquireImage() returns a pointer to an image structure initialized to
136 %  default values.
137 %
138 %  The format of the AcquireImage method is:
139 %
140 %      Image *AcquireImage(const ImageInfo *image_info,ExceptionInfo *exception)
141 %
142 %  A description of each parameter follows:
143 %
144 %    o image_info: Many of the image default values are set from this
145 %      structure.  For example, filename, compression, depth, background color,
146 %      and others.
147 %
148 %    o exception: return any errors or warnings in this structure.
149 %
150 */
151 MagickExport Image *AcquireImage(const ImageInfo *image_info,
152   ExceptionInfo *exception)
153 {
154   const char
155     *option;
156
157   Image
158     *image;
159
160   MagickStatusType
161     flags;
162
163   /*
164     Allocate image structure.
165   */
166   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
167   image=(Image *) AcquireMagickMemory(sizeof(*image));
168   if (image == (Image *) NULL)
169     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
170   (void) ResetMagickMemory(image,0,sizeof(*image));
171   /*
172     Initialize Image structure.
173   */
174   (void) CopyMagickString(image->magick,"MIFF",MagickPathExtent);
175   image->storage_class=DirectClass;
176   image->depth=MAGICKCORE_QUANTUM_DEPTH;
177   image->colorspace=sRGBColorspace;
178   image->rendering_intent=PerceptualIntent;
179   image->gamma=1.000f/2.200f;
180   image->chromaticity.red_primary.x=0.6400f;
181   image->chromaticity.red_primary.y=0.3300f;
182   image->chromaticity.red_primary.z=0.0300f;
183   image->chromaticity.green_primary.x=0.3000f;
184   image->chromaticity.green_primary.y=0.6000f;
185   image->chromaticity.green_primary.z=0.1000f;
186   image->chromaticity.blue_primary.x=0.1500f;
187   image->chromaticity.blue_primary.y=0.0600f;
188   image->chromaticity.blue_primary.z=0.7900f;
189   image->chromaticity.white_point.x=0.3127f;
190   image->chromaticity.white_point.y=0.3290f;
191   image->chromaticity.white_point.z=0.3583f;
192   image->interlace=NoInterlace;
193   image->ticks_per_second=UndefinedTicksPerSecond;
194   image->compose=OverCompositeOp;
195   (void) QueryColorCompliance(BackgroundColor,AllCompliance,
196     &image->background_color,exception);
197   (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
198     exception);
199   (void) QueryColorCompliance(MatteColor,AllCompliance,&image->matte_color,
200     exception);
201   (void) QueryColorCompliance(TransparentColor,AllCompliance,
202     &image->transparent_color,exception);
203   GetTimerInfo(&image->timer);
204   image->cache=AcquirePixelCache(0);
205   image->channel_mask=DefaultChannels;
206   image->channel_map=AcquirePixelChannelMap();
207   image->blob=CloneBlobInfo((BlobInfo *) NULL);
208   image->timestamp=time((time_t *) NULL);
209   image->debug=IsEventLogging();
210   image->reference_count=1;
211   image->semaphore=AcquireSemaphoreInfo();
212   image->signature=MagickCoreSignature;
213   if (image_info == (ImageInfo *) NULL)
214     return(image);
215   /*
216     Transfer image info.
217   */
218   SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
219     MagickFalse);
220   (void) CopyMagickString(image->filename,image_info->filename,
221     MagickPathExtent);
222   (void) CopyMagickString(image->magick_filename,image_info->filename,
223     MagickPathExtent);
224   (void) CopyMagickString(image->magick,image_info->magick,MagickPathExtent);
225   if (image_info->size != (char *) NULL)
226     {
227       (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
228       image->columns=image->extract_info.width;
229       image->rows=image->extract_info.height;
230       image->offset=image->extract_info.x;
231       image->extract_info.x=0;
232       image->extract_info.y=0;
233     }
234   if (image_info->extract != (char *) NULL)
235     {
236       RectangleInfo
237         geometry;
238
239       flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
240       if (((flags & XValue) != 0) || ((flags & YValue) != 0))
241         {
242           image->extract_info=geometry;
243           Swap(image->columns,image->extract_info.width);
244           Swap(image->rows,image->extract_info.height);
245         }
246     }
247   image->compression=image_info->compression;
248   image->quality=image_info->quality;
249   image->endian=image_info->endian;
250   image->interlace=image_info->interlace;
251   image->units=image_info->units;
252   if (image_info->density != (char *) NULL)
253     {
254       GeometryInfo
255         geometry_info;
256
257       flags=ParseGeometry(image_info->density,&geometry_info);
258       image->resolution.x=geometry_info.rho;
259       image->resolution.y=geometry_info.sigma;
260       if ((flags & SigmaValue) == 0)
261         image->resolution.y=image->resolution.x;
262     }
263   if (image_info->page != (char *) NULL)
264     {
265       char
266         *geometry;
267
268       image->page=image->extract_info;
269       geometry=GetPageGeometry(image_info->page);
270       (void) ParseAbsoluteGeometry(geometry,&image->page);
271       geometry=DestroyString(geometry);
272     }
273   if (image_info->depth != 0)
274     image->depth=image_info->depth;
275   image->dither=image_info->dither;
276   image->background_color=image_info->background_color;
277   image->border_color=image_info->border_color;
278   image->matte_color=image_info->matte_color;
279   image->transparent_color=image_info->transparent_color;
280   image->ping=image_info->ping;
281   image->progress_monitor=image_info->progress_monitor;
282   image->client_data=image_info->client_data;
283   if (image_info->cache != (void *) NULL)
284     ClonePixelCacheMethods(image->cache,image_info->cache);
285   /*
286     Set all global options that map to per-image settings.
287   */
288   (void) SyncImageSettings(image_info,image,exception);
289   /*
290     Global options that are only set for new images.
291   */
292   option=GetImageOption(image_info,"delay");
293   if (option != (const char *) NULL)
294     {
295       GeometryInfo
296         geometry_info;
297
298       flags=ParseGeometry(option,&geometry_info);
299       if ((flags & GreaterValue) != 0)
300         {
301           if (image->delay > (size_t) floor(geometry_info.rho+0.5))
302             image->delay=(size_t) floor(geometry_info.rho+0.5);
303         }
304       else
305         if ((flags & LessValue) != 0)
306           {
307             if (image->delay < (size_t) floor(geometry_info.rho+0.5))
308               image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
309           }
310         else
311           image->delay=(size_t) floor(geometry_info.rho+0.5);
312       if ((flags & SigmaValue) != 0)
313         image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
314     }
315   option=GetImageOption(image_info,"dispose");
316   if (option != (const char *) NULL)
317     image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
318       MagickFalse,option);
319   return(image);
320 }
321 \f
322 /*
323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
324 %                                                                             %
325 %                                                                             %
326 %                                                                             %
327 %   A c q u i r e I m a g e I n f o                                           %
328 %                                                                             %
329 %                                                                             %
330 %                                                                             %
331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332 %
333 %  AcquireImageInfo() allocates the ImageInfo structure.
334 %
335 %  The format of the AcquireImageInfo method is:
336 %
337 %      ImageInfo *AcquireImageInfo(void)
338 %
339 */
340 MagickExport ImageInfo *AcquireImageInfo(void)
341 {
342   ImageInfo
343     *image_info;
344
345   image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
346   if (image_info == (ImageInfo *) NULL)
347     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
348   GetImageInfo(image_info);
349   return(image_info);
350 }
351 \f
352 /*
353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
354 %                                                                             %
355 %                                                                             %
356 %                                                                             %
357 %   A c q u i r e N e x t I m a g e                                           %
358 %                                                                             %
359 %                                                                             %
360 %                                                                             %
361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
362 %
363 %  AcquireNextImage() initializes the next image in a sequence to
364 %  default values.  The next member of image points to the newly allocated
365 %  image.  If there is a memory shortage, next is assigned NULL.
366 %
367 %  The format of the AcquireNextImage method is:
368 %
369 %      void AcquireNextImage(const ImageInfo *image_info,Image *image,
370 %        ExceptionInfo *exception)
371 %
372 %  A description of each parameter follows:
373 %
374 %    o image_info: Many of the image default values are set from this
375 %      structure.  For example, filename, compression, depth, background color,
376 %      and others.
377 %
378 %    o image: the image.
379 %
380 %    o exception: return any errors or warnings in this structure.
381 %
382 */
383 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image,
384   ExceptionInfo *exception)
385 {
386   /*
387     Allocate image structure.
388   */
389   assert(image != (Image *) NULL);
390   assert(image->signature == MagickCoreSignature);
391   if (image->debug != MagickFalse)
392     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
393   image->next=AcquireImage(image_info,exception);
394   if (GetNextImageInList(image) == (Image *) NULL)
395     return;
396   (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
397     MagickPathExtent);
398   if (image_info != (ImageInfo *) NULL)
399     (void) CopyMagickString(GetNextImageInList(image)->filename,
400       image_info->filename,MagickPathExtent);
401   DestroyBlob(GetNextImageInList(image));
402   image->next->blob=ReferenceBlob(image->blob);
403   image->next->endian=image->endian;
404   image->next->scene=image->scene+1;
405   image->next->previous=image;
406 }
407 \f
408 /*
409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410 %                                                                             %
411 %                                                                             %
412 %                                                                             %
413 %     A p p e n d I m a g e s                                                 %
414 %                                                                             %
415 %                                                                             %
416 %                                                                             %
417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
418 %
419 %  AppendImages() takes all images from the current image pointer to the end
420 %  of the image list and appends them to each other top-to-bottom if the
421 %  stack parameter is true, otherwise left-to-right.
422 %
423 %  The current gravity setting effects how the image is justified in the
424 %  final image.
425 %
426 %  The format of the AppendImages method is:
427 %
428 %      Image *AppendImages(const Image *images,const MagickBooleanType stack,
429 %        ExceptionInfo *exception)
430 %
431 %  A description of each parameter follows:
432 %
433 %    o images: the image sequence.
434 %
435 %    o stack: A value other than 0 stacks the images top-to-bottom.
436 %
437 %    o exception: return any errors or warnings in this structure.
438 %
439 */
440 MagickExport Image *AppendImages(const Image *images,
441   const MagickBooleanType stack,ExceptionInfo *exception)
442 {
443 #define AppendImageTag  "Append/Image"
444
445   CacheView
446     *append_view;
447
448   Image
449     *append_image;
450
451   MagickBooleanType
452     status;
453
454   MagickOffsetType
455     n;
456
457   PixelTrait
458     alpha_trait;
459
460   RectangleInfo
461     geometry;
462
463   register const Image
464     *next;
465
466   size_t
467     height,
468     number_images,
469     width;
470
471   ssize_t
472     x_offset,
473     y,
474     y_offset;
475
476   /*
477     Compute maximum area of appended area.
478   */
479   assert(images != (Image *) NULL);
480   assert(images->signature == MagickCoreSignature);
481   if (images->debug != MagickFalse)
482     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
483   assert(exception != (ExceptionInfo *) NULL);
484   assert(exception->signature == MagickCoreSignature);
485   alpha_trait=images->alpha_trait;
486   number_images=1;
487   width=images->columns;
488   height=images->rows;
489   next=GetNextImageInList(images);
490   for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
491   {
492     if (next->alpha_trait != UndefinedPixelTrait)
493       alpha_trait=BlendPixelTrait;
494     number_images++;
495     if (stack != MagickFalse)
496       {
497         if (next->columns > width)
498           width=next->columns;
499         height+=next->rows;
500         continue;
501       }
502     width+=next->columns;
503     if (next->rows > height)
504       height=next->rows;
505   }
506   /*
507     Append images.
508   */
509   append_image=CloneImage(images,width,height,MagickTrue,exception);
510   if (append_image == (Image *) NULL)
511     return((Image *) NULL);
512   if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
513     {
514       append_image=DestroyImage(append_image);
515       return((Image *) NULL);
516     }
517   append_image->alpha_trait=alpha_trait;
518   (void) SetImageBackgroundColor(append_image,exception);
519   status=MagickTrue;
520   x_offset=0;
521   y_offset=0;
522   next=images;
523   append_view=AcquireAuthenticCacheView(append_image,exception);
524   for (n=0; n < (MagickOffsetType) number_images; n++)
525   {
526     CacheView
527       *image_view;
528
529     Image
530       *image;
531
532     MagickBooleanType
533       proceed;
534
535     image=CloneImage(next,0,0,MagickTrue,exception);
536     if (image == (Image *) NULL)
537       break;
538     (void) TransformImageColorspace(image,append_image->colorspace,exception);
539     SetGeometry(append_image,&geometry);
540     GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
541     if (stack != MagickFalse)
542       x_offset-=geometry.x;
543     else
544       y_offset-=geometry.y;
545     image_view=AcquireVirtualCacheView(image,exception);
546 #if defined(MAGICKCORE_OPENMP_SUPPORT)
547     #pragma omp parallel for schedule(static,4) shared(status) \
548       magick_threads(image,image,image->rows,1)
549 #endif
550     for (y=0; y < (ssize_t) image->rows; y++)
551     {
552       MagickBooleanType
553         sync;
554
555       PixelInfo
556         pixel;
557
558       register const Quantum
559         *magick_restrict p;
560
561       register Quantum
562         *magick_restrict q;
563
564       register ssize_t
565         x;
566
567       if (status == MagickFalse)
568         continue;
569       p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
570       q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
571         image->columns,1,exception);
572       if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
573         {
574           status=MagickFalse;
575           continue;
576         }
577       GetPixelInfo(image,&pixel);
578       for (x=0; x < (ssize_t) image->columns; x++)
579       {
580         if (GetPixelReadMask(image,p) == 0)
581           {
582             SetPixelBackgoundColor(append_image,q);
583             p+=GetPixelChannels(image);
584             q+=GetPixelChannels(append_image);
585             continue;
586           }
587         GetPixelInfoPixel(image,p,&pixel);
588         SetPixelViaPixelInfo(append_image,&pixel,q);
589         p+=GetPixelChannels(image);
590         q+=GetPixelChannels(append_image);
591       }
592       sync=SyncCacheViewAuthenticPixels(append_view,exception);
593       if (sync == MagickFalse)
594         status=MagickFalse;
595     }
596     image_view=DestroyCacheView(image_view);
597     if (stack == MagickFalse)
598       {
599         x_offset+=(ssize_t) image->columns;
600         y_offset=0;
601       }
602     else
603       {
604         x_offset=0;
605         y_offset+=(ssize_t) image->rows;
606       }
607     image=DestroyImage(image);
608     proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
609     if (proceed == MagickFalse)
610       break;
611     next=GetNextImageInList(next);
612   }
613   append_view=DestroyCacheView(append_view);
614   if (status == MagickFalse)
615     append_image=DestroyImage(append_image);
616   return(append_image);
617 }
618 \f
619 /*
620 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
621 %                                                                             %
622 %                                                                             %
623 %                                                                             %
624 %   C a t c h I m a g e E x c e p t i o n                                     %
625 %                                                                             %
626 %                                                                             %
627 %                                                                             %
628 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
629 %
630 %  CatchImageException() returns if no exceptions are found in the image
631 %  sequence, otherwise it determines the most severe exception and reports
632 %  it as a warning or error depending on the severity.
633 %
634 %  The format of the CatchImageException method is:
635 %
636 %      ExceptionType CatchImageException(Image *image)
637 %
638 %  A description of each parameter follows:
639 %
640 %    o image: An image sequence.
641 %
642 */
643 MagickExport ExceptionType CatchImageException(Image *image)
644 {
645   ExceptionInfo
646     *exception;
647
648   ExceptionType
649     severity;
650
651   assert(image != (const Image *) NULL);
652   assert(image->signature == MagickCoreSignature);
653   if (image->debug != MagickFalse)
654     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
655   exception=AcquireExceptionInfo();
656   CatchException(exception);
657   severity=exception->severity;
658   exception=DestroyExceptionInfo(exception);
659   return(severity);
660 }
661 \f
662 /*
663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664 %                                                                             %
665 %                                                                             %
666 %                                                                             %
667 %   C l i p I m a g e P a t h                                                 %
668 %                                                                             %
669 %                                                                             %
670 %                                                                             %
671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
672 %
673 %  ClipImagePath() sets the image clip mask based any clipping path information
674 %  if it exists.
675 %
676 %  The format of the ClipImagePath method is:
677 %
678 %      MagickBooleanType ClipImagePath(Image *image,const char *pathname,
679 %        const MagickBooleanType inside,ExceptionInfo *exception)
680 %
681 %  A description of each parameter follows:
682 %
683 %    o image: the image.
684 %
685 %    o pathname: name of clipping path resource. If name is preceded by #, use
686 %      clipping path numbered by name.
687 %
688 %    o inside: if non-zero, later operations take effect inside clipping path.
689 %      Otherwise later operations take effect outside clipping path.
690 %
691 %    o exception: return any errors or warnings in this structure.
692 %
693 */
694
695 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
696 {
697   return(ClipImagePath(image,"#1",MagickTrue,exception));
698 }
699
700 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
701   const MagickBooleanType inside,ExceptionInfo *exception)
702 {
703 #define ClipImagePathTag  "ClipPath/Image"
704
705   char
706     *property;
707
708   const char
709     *value;
710
711   Image
712     *clip_mask;
713
714   ImageInfo
715     *image_info;
716
717   assert(image != (const Image *) NULL);
718   assert(image->signature == MagickCoreSignature);
719   if (image->debug != MagickFalse)
720     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
721   assert(pathname != NULL);
722   property=AcquireString(pathname);
723   (void) FormatLocaleString(property,MagickPathExtent,"8BIM:1999,2998:%s",
724     pathname);
725   value=GetImageProperty(image,property,exception);
726   property=DestroyString(property);
727   if (value == (const char *) NULL)
728     {
729       ThrowFileException(exception,OptionError,"NoClipPathDefined",
730         image->filename);
731       return(MagickFalse);
732     }
733   image_info=AcquireImageInfo();
734   (void) CopyMagickString(image_info->filename,image->filename,
735      MagickPathExtent);
736   (void) ConcatenateMagickString(image_info->filename,pathname,
737     MagickPathExtent);
738   clip_mask=BlobToImage(image_info,value,strlen(value),exception);
739   image_info=DestroyImageInfo(image_info);
740   if (clip_mask == (Image *) NULL)
741     return(MagickFalse);
742   if (clip_mask->storage_class == PseudoClass)
743     {
744       (void) SyncImage(clip_mask,exception);
745       if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
746         return(MagickFalse);
747     }
748   if (inside == MagickFalse)
749     (void) NegateImage(clip_mask,MagickFalse,exception);
750   (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
751     "8BIM:1999,2998:%s\nPS",pathname);
752   (void) SetImageMask(image,ReadPixelMask,clip_mask,exception);
753   clip_mask=DestroyImage(clip_mask);
754   return(MagickTrue);
755 }
756 \f
757 /*
758 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
759 %                                                                             %
760 %                                                                             %
761 %                                                                             %
762 %   C l o n e I m a g e                                                       %
763 %                                                                             %
764 %                                                                             %
765 %                                                                             %
766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
767 %
768 %  CloneImage() copies an image and returns the copy as a new image object.
769 %
770 %  If the specified columns and rows is 0, an exact copy of the image is
771 %  returned, otherwise the pixel data is undefined and must be initialized
772 %  with the QueueAuthenticPixels() and SyncAuthenticPixels() methods.  On
773 %  failure, a NULL image is returned and exception describes the reason for the
774 %  failure.
775 %
776 %  The format of the CloneImage method is:
777 %
778 %      Image *CloneImage(const Image *image,const size_t columns,
779 %        const size_t rows,const MagickBooleanType orphan,
780 %        ExceptionInfo *exception)
781 %
782 %  A description of each parameter follows:
783 %
784 %    o image: the image.
785 %
786 %    o columns: the number of columns in the cloned image.
787 %
788 %    o rows: the number of rows in the cloned image.
789 %
790 %    o detach:  With a value other than 0, the cloned image is detached from
791 %      its parent I/O stream.
792 %
793 %    o exception: return any errors or warnings in this structure.
794 %
795 */
796 MagickExport Image *CloneImage(const Image *image,const size_t columns,
797   const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
798 {
799   Image
800     *clone_image;
801
802   double
803     scale;
804
805   size_t
806     length;
807
808   /*
809     Clone the image.
810   */
811   assert(image != (const Image *) NULL);
812   assert(image->signature == MagickCoreSignature);
813   if (image->debug != MagickFalse)
814     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
815   assert(exception != (ExceptionInfo *) NULL);
816   assert(exception->signature == MagickCoreSignature);
817   if ((image->columns == 0) || (image->rows == 0))
818     {
819       (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
820         "NegativeOrZeroImageSize","`%s'",image->filename);
821       return((Image *) NULL);
822     }
823   clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
824   if (clone_image == (Image *) NULL)
825     ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
826   (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
827   clone_image->signature=MagickCoreSignature;
828   clone_image->storage_class=image->storage_class;
829   clone_image->number_channels=image->number_channels;
830   clone_image->number_meta_channels=image->number_meta_channels;
831   clone_image->metacontent_extent=image->metacontent_extent;
832   clone_image->colorspace=image->colorspace;
833   clone_image->read_mask=image->read_mask;
834   clone_image->write_mask=image->write_mask;
835   clone_image->alpha_trait=image->alpha_trait;
836   clone_image->columns=image->columns;
837   clone_image->rows=image->rows;
838   clone_image->dither=image->dither;
839   if (image->colormap != (PixelInfo *) NULL)
840     {
841       /*
842         Allocate and copy the image colormap.
843       */
844       clone_image->colors=image->colors;
845       length=(size_t) image->colors;
846       clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
847         sizeof(*clone_image->colormap));
848       if (clone_image->colormap == (PixelInfo *) NULL)
849         ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
850       (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
851         sizeof(*clone_image->colormap));
852     }
853   clone_image->image_info=CloneImageInfo(image->image_info);
854   (void) CloneImageProfiles(clone_image,image);
855   (void) CloneImageProperties(clone_image,image);
856   (void) CloneImageArtifacts(clone_image,image);
857   GetTimerInfo(&clone_image->timer);
858   if (image->ascii85 != (void *) NULL)
859     Ascii85Initialize(clone_image);
860   clone_image->magick_columns=image->magick_columns;
861   clone_image->magick_rows=image->magick_rows;
862   clone_image->type=image->type;
863   clone_image->channel_mask=image->channel_mask;
864   clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
865   (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
866     MagickPathExtent);
867   (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
868   (void) CopyMagickString(clone_image->filename,image->filename,
869     MagickPathExtent);
870   clone_image->progress_monitor=image->progress_monitor;
871   clone_image->client_data=image->client_data;
872   clone_image->reference_count=1;
873   clone_image->next=image->next;
874   clone_image->previous=image->previous;
875   clone_image->list=NewImageList();
876   if (detach == MagickFalse)
877     clone_image->blob=ReferenceBlob(image->blob);
878   else
879     {
880       clone_image->next=NewImageList();
881       clone_image->previous=NewImageList();
882       clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
883     }
884   clone_image->ping=image->ping;
885   clone_image->debug=IsEventLogging();
886   clone_image->semaphore=AcquireSemaphoreInfo();
887   if ((columns == 0) || (rows == 0))
888     {
889       if (image->montage != (char *) NULL)
890         (void) CloneString(&clone_image->montage,image->montage);
891       if (image->directory != (char *) NULL)
892         (void) CloneString(&clone_image->directory,image->directory);
893       clone_image->cache=ReferencePixelCache(image->cache);
894       return(clone_image);
895     }
896   scale=1.0;
897   if (image->columns != 0)
898     scale=(double) columns/(double) image->columns;
899   clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
900   clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
901   clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
902   scale=1.0;
903   if (image->rows != 0)
904     scale=(double) rows/(double) image->rows;
905   clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
906   clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
907   clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
908   clone_image->columns=columns;
909   clone_image->rows=rows;
910   clone_image->cache=ClonePixelCache(image->cache);
911   return(clone_image);
912 }
913 \f
914 /*
915 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
916 %                                                                             %
917 %                                                                             %
918 %                                                                             %
919 %   C l o n e I m a g e I n f o                                               %
920 %                                                                             %
921 %                                                                             %
922 %                                                                             %
923 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
924 %
925 %  CloneImageInfo() makes a copy of the given image info structure.  If
926 %  NULL is specified, a new image info structure is created initialized to
927 %  default values.
928 %
929 %  The format of the CloneImageInfo method is:
930 %
931 %      ImageInfo *CloneImageInfo(const ImageInfo *image_info)
932 %
933 %  A description of each parameter follows:
934 %
935 %    o image_info: the image info.
936 %
937 */
938 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
939 {
940   ImageInfo
941     *clone_info;
942
943   clone_info=AcquireImageInfo();
944   if (image_info == (ImageInfo *) NULL)
945     return(clone_info);
946   clone_info->compression=image_info->compression;
947   clone_info->temporary=image_info->temporary;
948   clone_info->adjoin=image_info->adjoin;
949   clone_info->antialias=image_info->antialias;
950   clone_info->scene=image_info->scene;
951   clone_info->number_scenes=image_info->number_scenes;
952   clone_info->depth=image_info->depth;
953   (void) CloneString(&clone_info->size,image_info->size);
954   (void) CloneString(&clone_info->extract,image_info->extract);
955   (void) CloneString(&clone_info->scenes,image_info->scenes);
956   (void) CloneString(&clone_info->page,image_info->page);
957   clone_info->interlace=image_info->interlace;
958   clone_info->endian=image_info->endian;
959   clone_info->units=image_info->units;
960   clone_info->quality=image_info->quality;
961   (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
962   (void) CloneString(&clone_info->server_name,image_info->server_name);
963   (void) CloneString(&clone_info->font,image_info->font);
964   (void) CloneString(&clone_info->texture,image_info->texture);
965   (void) CloneString(&clone_info->density,image_info->density);
966   clone_info->pointsize=image_info->pointsize;
967   clone_info->fuzz=image_info->fuzz;
968   clone_info->background_color=image_info->background_color;
969   clone_info->border_color=image_info->border_color;
970   clone_info->matte_color=image_info->matte_color;
971   clone_info->transparent_color=image_info->transparent_color;
972   clone_info->dither=image_info->dither;
973   clone_info->monochrome=image_info->monochrome;
974   clone_info->colorspace=image_info->colorspace;
975   clone_info->type=image_info->type;
976   clone_info->orientation=image_info->orientation;
977   clone_info->preview_type=image_info->preview_type;
978   clone_info->group=image_info->group;
979   clone_info->ping=image_info->ping;
980   clone_info->verbose=image_info->verbose;
981   (void) CloneString(&clone_info->view,image_info->view);
982   clone_info->progress_monitor=image_info->progress_monitor;
983   clone_info->client_data=image_info->client_data;
984   clone_info->cache=image_info->cache;
985   if (image_info->cache != (void *) NULL)
986     clone_info->cache=ReferencePixelCache(image_info->cache);
987   if (image_info->profile != (void *) NULL)
988     clone_info->profile=(void *) CloneStringInfo((StringInfo *)
989       image_info->profile);
990   SetImageInfoFile(clone_info,image_info->file);
991   SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
992   clone_info->stream=image_info->stream;
993   (void) CopyMagickString(clone_info->magick,image_info->magick,
994     MagickPathExtent);
995   (void) CopyMagickString(clone_info->unique,image_info->unique,
996     MagickPathExtent);
997   (void) CopyMagickString(clone_info->zero,image_info->zero,MagickPathExtent);
998   (void) CopyMagickString(clone_info->filename,image_info->filename,
999     MagickPathExtent);
1000   clone_info->channel=image_info->channel;
1001   (void) CloneImageOptions(clone_info,image_info);
1002   clone_info->debug=IsEventLogging();
1003   clone_info->signature=image_info->signature;
1004   return(clone_info);
1005 }
1006 \f
1007 /*
1008 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1009 %                                                                             %
1010 %                                                                             %
1011 %                                                                             %
1012 %   C o p y I m a g e P i x e l s                                             %
1013 %                                                                             %
1014 %                                                                             %
1015 %                                                                             %
1016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1017 %
1018 %  CopyImagePixels() copies pixels from the source image as defined by the
1019 %  geometry the destination image at the specified offset.
1020 %
1021 %  The format of the CopyImagePixels method is:
1022 %
1023 %      MagickBooleanType CopyImagePixels(Image *image,const Image *source_image,
1024 %        const RectangleInfo *geometry,const OffsetInfo *offset,
1025 %        ExceptionInfo *exception);
1026 %
1027 %  A description of each parameter follows:
1028 %
1029 %    o image: the destination image.
1030 %
1031 %    o source_image: the source image.
1032 %
1033 %    o geometry: define the dimensions of the source pixel rectangle.
1034 %
1035 %    o offset: define the offset in the destination image.
1036 %
1037 %    o exception: return any errors or warnings in this structure.
1038 %
1039 */
1040 MagickExport MagickBooleanType CopyImagePixels(Image *image,
1041   const Image *source_image,const RectangleInfo *geometry,
1042   const OffsetInfo *offset,ExceptionInfo *exception)
1043 {
1044 #define CopyImageTag  "Copy/Image"
1045
1046   CacheView
1047     *image_view,
1048     *source_view;
1049
1050   MagickBooleanType
1051     status;
1052
1053   MagickOffsetType
1054     progress;
1055
1056   ssize_t
1057     y;
1058
1059   assert(image != (Image *) NULL);
1060   if (image->debug != MagickFalse)
1061     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1062   assert(source_image != (Image *) NULL);
1063   assert(geometry != (RectangleInfo *) NULL);
1064   assert(offset != (OffsetInfo *) NULL);
1065   if ((offset->x < 0) || (offset->y < 0) ||
1066       ((ssize_t) (offset->x+geometry->width) > (ssize_t) image->columns) ||
1067       ((ssize_t) (offset->y+geometry->height) > (ssize_t) image->rows))
1068     ThrowBinaryException(OptionError,"GeometryDoesNotContainImage",
1069       image->filename);
1070   if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1071     return(MagickFalse);
1072   /*
1073     Copy image pixels.
1074   */
1075   status=MagickTrue;
1076   progress=0;
1077   source_view=AcquireVirtualCacheView(source_image,exception);
1078   image_view=AcquireAuthenticCacheView(image,exception);
1079 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1080   #pragma omp parallel for schedule(static,4) shared(progress,status) \
1081     magick_threads(image,source_image,geometry->height,1)
1082 #endif
1083   for (y=0; y < (ssize_t) geometry->height; y++)
1084   {
1085     MagickBooleanType
1086       sync;
1087
1088     register const Quantum
1089       *magick_restrict p;
1090
1091     register ssize_t
1092       x;
1093
1094     register Quantum
1095       *magick_restrict q;
1096
1097     if (status == MagickFalse)
1098       continue;
1099     p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1100       geometry->width,1,exception);
1101     q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1102       geometry->width,1,exception);
1103     if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1104       {
1105         status=MagickFalse;
1106         continue;
1107       }
1108     for (x=0; x < (ssize_t) geometry->width; x++)
1109     {
1110       register ssize_t
1111         i;
1112
1113       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1114       { 
1115         PixelChannel channel=GetPixelChannelChannel(image,i);
1116         PixelTrait traits=GetPixelChannelTraits(image,channel);
1117         PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1118         if ((traits == UndefinedPixelTrait) ||
1119             (source_traits == UndefinedPixelTrait))
1120           continue;
1121         SetPixelChannel(image,channel,p[i],q);
1122       }
1123       p+=GetPixelChannels(source_image);
1124       q+=GetPixelChannels(image);
1125     }
1126     sync=SyncCacheViewAuthenticPixels(image_view,exception);
1127     if (sync == MagickFalse)
1128       status=MagickFalse;
1129     if (image->progress_monitor != (MagickProgressMonitor) NULL)
1130       {
1131         MagickBooleanType
1132           proceed;
1133
1134 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1135         #pragma omp critical (MagickCore_CopyImage)
1136 #endif
1137         proceed=SetImageProgress(image,CopyImageTag,progress++,image->rows);
1138         if (proceed == MagickFalse)
1139           status=MagickFalse;
1140       }
1141   }
1142   source_view=DestroyCacheView(source_view);
1143   image_view=DestroyCacheView(image_view);
1144   return(status);
1145 }
1146 \f
1147 /*
1148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1149 %                                                                             %
1150 %                                                                             %
1151 %                                                                             %
1152 %   D e s t r o y I m a g e                                                   %
1153 %                                                                             %
1154 %                                                                             %
1155 %                                                                             %
1156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1157 %
1158 %  DestroyImage() dereferences an image, deallocating memory associated with
1159 %  the image if the reference count becomes zero.
1160 %
1161 %  The format of the DestroyImage method is:
1162 %
1163 %      Image *DestroyImage(Image *image)
1164 %
1165 %  A description of each parameter follows:
1166 %
1167 %    o image: the image.
1168 %
1169 */
1170 MagickExport Image *DestroyImage(Image *image)
1171 {
1172   MagickBooleanType
1173     destroy;
1174
1175   /*
1176     Dereference image.
1177   */
1178   assert(image != (Image *) NULL);
1179   assert(image->signature == MagickCoreSignature);
1180   if (image->debug != MagickFalse)
1181     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1182   destroy=MagickFalse;
1183   LockSemaphoreInfo(image->semaphore);
1184   image->reference_count--;
1185   if (image->reference_count == 0)
1186     destroy=MagickTrue;
1187   UnlockSemaphoreInfo(image->semaphore);
1188   if (destroy == MagickFalse)
1189     return((Image *) NULL);
1190   /*
1191     Destroy image.
1192   */
1193   DestroyImagePixels(image);
1194   image->channel_map=DestroyPixelChannelMap(image->channel_map);
1195   if (image->montage != (char *) NULL)
1196     image->montage=DestroyString(image->montage);
1197   if (image->directory != (char *) NULL)
1198     image->directory=DestroyString(image->directory);
1199   if (image->colormap != (PixelInfo *) NULL)
1200     image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1201   if (image->geometry != (char *) NULL)
1202     image->geometry=DestroyString(image->geometry);
1203   DestroyImageProfiles(image);
1204   DestroyImageProperties(image);
1205   DestroyImageArtifacts(image);
1206   if (image->ascii85 != (Ascii85Info *) NULL)
1207     image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1208   if (image->image_info != (ImageInfo *) NULL)
1209     image->image_info=DestroyImageInfo(image->image_info);
1210   DestroyBlob(image);
1211   if (image->semaphore != (SemaphoreInfo *) NULL)
1212     RelinquishSemaphoreInfo(&image->semaphore);
1213   image->signature=(~MagickCoreSignature);
1214   image=(Image *) RelinquishMagickMemory(image);
1215   return(image);
1216 }
1217 \f
1218 /*
1219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1220 %                                                                             %
1221 %                                                                             %
1222 %                                                                             %
1223 %   D e s t r o y I m a g e I n f o                                           %
1224 %                                                                             %
1225 %                                                                             %
1226 %                                                                             %
1227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1228 %
1229 %  DestroyImageInfo() deallocates memory associated with an ImageInfo
1230 %  structure.
1231 %
1232 %  The format of the DestroyImageInfo method is:
1233 %
1234 %      ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1235 %
1236 %  A description of each parameter follows:
1237 %
1238 %    o image_info: the image info.
1239 %
1240 */
1241 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1242 {
1243   assert(image_info != (ImageInfo *) NULL);
1244   assert(image_info->signature == MagickCoreSignature);
1245   if (image_info->debug != MagickFalse)
1246     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1247       image_info->filename);
1248   if (image_info->size != (char *) NULL)
1249     image_info->size=DestroyString(image_info->size);
1250   if (image_info->extract != (char *) NULL)
1251     image_info->extract=DestroyString(image_info->extract);
1252   if (image_info->scenes != (char *) NULL)
1253     image_info->scenes=DestroyString(image_info->scenes);
1254   if (image_info->page != (char *) NULL)
1255     image_info->page=DestroyString(image_info->page);
1256   if (image_info->sampling_factor != (char *) NULL)
1257     image_info->sampling_factor=DestroyString(
1258       image_info->sampling_factor);
1259   if (image_info->server_name != (char *) NULL)
1260     image_info->server_name=DestroyString(
1261       image_info->server_name);
1262   if (image_info->font != (char *) NULL)
1263     image_info->font=DestroyString(image_info->font);
1264   if (image_info->texture != (char *) NULL)
1265     image_info->texture=DestroyString(image_info->texture);
1266   if (image_info->density != (char *) NULL)
1267     image_info->density=DestroyString(image_info->density);
1268   if (image_info->view != (char *) NULL)
1269     image_info->view=DestroyString(image_info->view);
1270   if (image_info->cache != (void *) NULL)
1271     image_info->cache=DestroyPixelCache(image_info->cache);
1272   if (image_info->profile != (StringInfo *) NULL)
1273     image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1274       image_info->profile);
1275   DestroyImageOptions(image_info);
1276   image_info->signature=(~MagickCoreSignature);
1277   image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1278   return(image_info);
1279 }
1280 \f
1281 /*
1282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1283 %                                                                             %
1284 %                                                                             %
1285 %                                                                             %
1286 +   D i s a s s o c i a t e I m a g e S t r e a m                             %
1287 %                                                                             %
1288 %                                                                             %
1289 %                                                                             %
1290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1291 %
1292 %  DisassociateImageStream() disassociates the image stream.  It checks if the
1293 %  blob of the specified image is referenced by other images. If the reference
1294 %  count is higher then 1 a new blob is assigned to the specified image.
1295 %
1296 %  The format of the DisassociateImageStream method is:
1297 %
1298 %      void DisassociateImageStream(const Image *image)
1299 %
1300 %  A description of each parameter follows:
1301 %
1302 %    o image: the image.
1303 %
1304 */
1305 MagickExport void DisassociateImageStream(Image *image)
1306 {
1307   assert(image != (Image *) NULL);
1308   assert(image->signature == MagickCoreSignature);
1309   if (image->debug != MagickFalse)
1310     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1311   DisassociateBlob(image);
1312 }
1313 \f
1314 /*
1315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1316 %                                                                             %
1317 %                                                                             %
1318 %                                                                             %
1319 %   G e t I m a g e I n f o                                                   %
1320 %                                                                             %
1321 %                                                                             %
1322 %                                                                             %
1323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1324 %
1325 %  GetImageInfo() initializes image_info to default values.
1326 %
1327 %  The format of the GetImageInfo method is:
1328 %
1329 %      void GetImageInfo(ImageInfo *image_info)
1330 %
1331 %  A description of each parameter follows:
1332 %
1333 %    o image_info: the image info.
1334 %
1335 */
1336 MagickExport void GetImageInfo(ImageInfo *image_info)
1337 {
1338   char
1339     *synchronize;
1340
1341   ExceptionInfo
1342     *exception;
1343
1344   /*
1345     File and image dimension members.
1346   */
1347   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1348   assert(image_info != (ImageInfo *) NULL);
1349   (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1350   image_info->adjoin=MagickTrue;
1351   image_info->interlace=NoInterlace;
1352   image_info->channel=DefaultChannels;
1353   image_info->quality=UndefinedCompressionQuality;
1354   image_info->antialias=MagickTrue;
1355   image_info->dither=MagickTrue;
1356   synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1357   if (synchronize != (const char *) NULL)
1358     {
1359       image_info->synchronize=IsStringTrue(synchronize);
1360       synchronize=DestroyString(synchronize);
1361     }
1362   exception=AcquireExceptionInfo();
1363   (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1364     &image_info->background_color,exception);
1365   (void) QueryColorCompliance(BorderColor,AllCompliance,
1366     &image_info->border_color,exception);
1367   (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
1368     exception);
1369   (void) QueryColorCompliance(TransparentColor,AllCompliance,
1370     &image_info->transparent_color,exception);
1371   exception=DestroyExceptionInfo(exception);
1372   image_info->debug=IsEventLogging();
1373   image_info->signature=MagickCoreSignature;
1374 }
1375 \f
1376 /*
1377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1378 %                                                                             %
1379 %                                                                             %
1380 %                                                                             %
1381 %   G e t I m a g e I n f o F i l e                                           %
1382 %                                                                             %
1383 %                                                                             %
1384 %                                                                             %
1385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1386 %
1387 %  GetImageInfoFile() returns the image info file member.
1388 %
1389 %  The format of the GetImageInfoFile method is:
1390 %
1391 %      FILE *GetImageInfoFile(const ImageInfo *image_info)
1392 %
1393 %  A description of each parameter follows:
1394 %
1395 %    o image_info: the image info.
1396 %
1397 */
1398 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1399 {
1400   return(image_info->file);
1401 }
1402 \f
1403 /*
1404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1405 %                                                                             %
1406 %                                                                             %
1407 %                                                                             %
1408 %   G e t I m a g e M a s k                                                   %
1409 %                                                                             %
1410 %                                                                             %
1411 %                                                                             %
1412 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1413 %
1414 %  GetImageMask() returns the mask associated with the image.
1415 %
1416 %  The format of the GetImageMask method is:
1417 %
1418 %      Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1419 %
1420 %  A description of each parameter follows:
1421 %
1422 %    o image: the image.
1423 %
1424 */
1425 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1426 {
1427   CacheView
1428     *mask_view,
1429     *image_view;
1430
1431   Image
1432     *mask_image;
1433
1434   MagickBooleanType
1435     status;
1436
1437   ssize_t
1438     y;
1439
1440   /*
1441     Get image mask.
1442   */
1443   assert(image != (Image *) NULL);
1444   if (image->debug != MagickFalse)
1445     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1446   assert(image->signature == MagickCoreSignature);
1447   mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1448   if (mask_image == (Image *) NULL)
1449     return((Image *) NULL);
1450   status=MagickTrue;
1451   (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1452   mask_image->read_mask=MagickFalse;
1453   mask_image->alpha_trait=UndefinedPixelTrait;
1454   image_view=AcquireVirtualCacheView(image,exception);
1455   mask_view=AcquireAuthenticCacheView(mask_image,exception);
1456   for (y=0; y < (ssize_t) image->rows; y++)
1457   {
1458     register const Quantum
1459       *magick_restrict p;
1460
1461     register Quantum
1462       *magick_restrict q;
1463
1464     register ssize_t
1465       x;
1466
1467     if (status == MagickFalse)
1468       continue;
1469     p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1470     q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1471       exception);
1472     if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1473       {
1474         status=MagickFalse;
1475         continue;
1476       }
1477     for (x=0; x < (ssize_t) image->columns; x++)
1478     {
1479       SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1480       p+=GetPixelChannels(image);
1481       q+=GetPixelChannels(mask_image);
1482     }
1483     if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1484       status=MagickFalse;
1485   }
1486   mask_view=DestroyCacheView(mask_view);
1487   image_view=DestroyCacheView(image_view);
1488   if (status == MagickFalse)
1489     mask_image=DestroyImage(mask_image);
1490   return(mask_image);
1491 }
1492 \f
1493 /*
1494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1495 %                                                                             %
1496 %                                                                             %
1497 %                                                                             %
1498 +   G e t I m a g e R e f e r e n c e C o u n t                               %
1499 %                                                                             %
1500 %                                                                             %
1501 %                                                                             %
1502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1503 %
1504 %  GetImageReferenceCount() returns the image reference count.
1505 %
1506 %  The format of the GetReferenceCount method is:
1507 %
1508 %      ssize_t GetImageReferenceCount(Image *image)
1509 %
1510 %  A description of each parameter follows:
1511 %
1512 %    o image: the image.
1513 %
1514 */
1515 MagickExport ssize_t GetImageReferenceCount(Image *image)
1516 {
1517   ssize_t
1518     reference_count;
1519
1520   assert(image != (Image *) NULL);
1521   assert(image->signature == MagickCoreSignature);
1522   if (image->debug != MagickFalse)
1523     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1524   LockSemaphoreInfo(image->semaphore);
1525   reference_count=image->reference_count;
1526   UnlockSemaphoreInfo(image->semaphore);
1527   return(reference_count);
1528 }
1529 \f
1530 /*
1531 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1532 %                                                                             %
1533 %                                                                             %
1534 %                                                                             %
1535 %   G e t I m a g e V i r t u a l P i x e l M e t h o d                       %
1536 %                                                                             %
1537 %                                                                             %
1538 %                                                                             %
1539 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1540 %
1541 %  GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1542 %  image.  A virtual pixel is any pixel access that is outside the boundaries
1543 %  of the image cache.
1544 %
1545 %  The format of the GetImageVirtualPixelMethod() method is:
1546 %
1547 %      VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1548 %
1549 %  A description of each parameter follows:
1550 %
1551 %    o image: the image.
1552 %
1553 */
1554 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1555 {
1556   assert(image != (Image *) NULL);
1557   assert(image->signature == MagickCoreSignature);
1558   if (image->debug != MagickFalse)
1559     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1560   return(GetPixelCacheVirtualMethod(image));
1561 }
1562 \f
1563 /*
1564 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1565 %                                                                             %
1566 %                                                                             %
1567 %                                                                             %
1568 %  I n t e r p r e t I m a g e F i l e n a m e                                %
1569 %                                                                             %
1570 %                                                                             %
1571 %                                                                             %
1572 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1573 %
1574 %  InterpretImageFilename() interprets embedded characters in an image filename.
1575 %  The filename length is returned.
1576 %
1577 %  The format of the InterpretImageFilename method is:
1578 %
1579 %      size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1580 %        const char *format,int value,char *filename,ExceptionInfo *exception)
1581 %
1582 %  A description of each parameter follows.
1583 %
1584 %    o image_info: the image info..
1585 %
1586 %    o image: the image.
1587 %
1588 %    o format:  A filename describing the format to use to write the numeric
1589 %      argument. Only the first numeric format identifier is replaced.
1590 %
1591 %    o value:  Numeric value to substitute into format filename.
1592 %
1593 %    o filename:  return the formatted filename in this character buffer.
1594 %
1595 %    o exception: return any errors or warnings in this structure.
1596 %
1597 */
1598 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1599   Image *image,const char *format,int value,char *filename,
1600   ExceptionInfo *exception)
1601 {
1602   char
1603     *q;
1604
1605   int
1606     c;
1607
1608   MagickBooleanType
1609     canonical;
1610
1611   register const char
1612     *p;
1613
1614   size_t
1615     length;
1616
1617   canonical=MagickFalse;
1618   length=0;
1619   (void) CopyMagickString(filename,format,MagickPathExtent);
1620   for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1621   {
1622     q=(char *) p+1;
1623     if (*q == '%')
1624       {
1625         p=q+1;
1626         continue;
1627       }
1628     if (*q == '0')
1629       {
1630         ssize_t
1631           value;
1632
1633         value=(ssize_t) strtol(q,&q,10);
1634         (void) value;
1635       }
1636     switch (*q)
1637     {
1638       case 'd':
1639       case 'o':
1640       case 'x':
1641       {
1642         q++;
1643         c=(*q);
1644         *q='\0';
1645         (void) FormatLocaleString(filename+(p-format),(size_t)
1646           (MagickPathExtent-(p-format)),p,value);
1647         *q=c;
1648         (void) ConcatenateMagickString(filename,q,MagickPathExtent);
1649         canonical=MagickTrue;
1650         if (*(q-1) != '%')
1651           break;
1652         p++;
1653         break;
1654       }
1655       case '[':
1656       {
1657         char
1658           pattern[MagickPathExtent];
1659
1660         const char
1661           *value;
1662
1663         register char
1664           *r;
1665
1666         register ssize_t
1667           i;
1668
1669         ssize_t
1670           depth;
1671
1672         /*
1673           Image option.
1674         */
1675         /* FUTURE: Compare update with code from InterpretImageProperties()
1676            Note that a 'filename:' property should not need depth recursion.
1677         */
1678         if (strchr(p,']') == (char *) NULL)
1679           break;
1680         depth=1;
1681         r=q+1;
1682         for (i=0; (i < (MagickPathExtent-1L)) && (*r != '\0'); i++)
1683         {
1684           if (*r == '[')
1685             depth++;
1686           if (*r == ']')
1687             depth--;
1688           if (depth <= 0)
1689             break;
1690           pattern[i]=(*r++);
1691         }
1692         pattern[i]='\0';
1693         if (LocaleNCompare(pattern,"filename:",9) != 0)
1694           break;
1695         value=(const char *) NULL;
1696         if (image != (Image *) NULL)
1697           value=GetImageProperty(image,pattern,exception);
1698         if ((value == (const char *) NULL) && (image != (Image *) NULL))
1699           value=GetImageArtifact(image,pattern);
1700         if ((value == (const char *) NULL) &&
1701             (image_info != (ImageInfo *) NULL))
1702           value=GetImageOption(image_info,pattern);
1703         if (value == (const char *) NULL)
1704           break;
1705         q--;
1706         c=(*q);
1707         *q='\0';
1708         (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1709           (MagickPathExtent-(p-format-length)));
1710         length+=strlen(pattern)-1;
1711         *q=c;
1712         (void) ConcatenateMagickString(filename,r+1,MagickPathExtent);
1713         canonical=MagickTrue;
1714         if (*(q-1) != '%')
1715           break;
1716         p++;
1717         break;
1718       }
1719       default:
1720         break;
1721     }
1722   }
1723   for (q=filename; *q != '\0'; q++)
1724     if ((*q == '%') && (*(q+1) == '%'))
1725       {
1726         (void) CopyMagickString(q,q+1,(size_t) (MagickPathExtent-(q-filename)));
1727         canonical=MagickTrue;
1728       }
1729   if (canonical == MagickFalse)
1730     (void) CopyMagickString(filename,format,MagickPathExtent);
1731   return(strlen(filename));
1732 }
1733 \f
1734 /*
1735 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1736 %                                                                             %
1737 %                                                                             %
1738 %                                                                             %
1739 %   I s H i g h D y n a m i c R a n g e I m a g e                             %
1740 %                                                                             %
1741 %                                                                             %
1742 %                                                                             %
1743 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1744 %
1745 %  IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1746 %  non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1747 %  0..65535.
1748 %
1749 %  The format of the IsHighDynamicRangeImage method is:
1750 %
1751 %      MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1752 %        ExceptionInfo *exception)
1753 %
1754 %  A description of each parameter follows:
1755 %
1756 %    o image: the image.
1757 %
1758 %    o exception: return any errors or warnings in this structure.
1759 %
1760 */
1761 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1762   ExceptionInfo *exception)
1763 {
1764 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1765   (void) image;
1766   (void) exception;
1767   return(MagickFalse);
1768 #else
1769   CacheView
1770     *image_view;
1771
1772   MagickBooleanType
1773     status;
1774
1775   ssize_t
1776     y;
1777
1778   assert(image != (Image *) NULL);
1779   assert(image->signature == MagickCoreSignature);
1780   if (image->debug != MagickFalse)
1781     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1782   status=MagickTrue;
1783   image_view=AcquireVirtualCacheView(image,exception);
1784 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1785   #pragma omp parallel for schedule(static,4) shared(status) \
1786     magick_threads(image,image,image->rows,1)
1787 #endif
1788   for (y=0; y < (ssize_t) image->rows; y++)
1789   {
1790     register const Quantum
1791       *p;
1792
1793     register ssize_t
1794       x;
1795
1796     if (status == MagickFalse)
1797       continue;
1798     p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1799     if (p == (const Quantum *) NULL)
1800       {
1801         status=MagickFalse;
1802         continue;
1803       }
1804     for (x=0; x < (ssize_t) image->columns; x++)
1805     {
1806       register ssize_t
1807         i;
1808
1809       if (GetPixelReadMask(image,p) == 0)
1810         {
1811           p+=GetPixelChannels(image);
1812           continue;
1813         }
1814       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1815       {
1816         double
1817           pixel;
1818
1819         PixelTrait
1820           traits;
1821
1822         traits=GetPixelChannelTraits(image,(PixelChannel) i);
1823         if (traits == UndefinedPixelTrait)
1824           continue;
1825         pixel=(double) p[i];
1826         if ((pixel < 0.0) || (pixel > QuantumRange) ||
1827             (pixel != (double) ((QuantumAny) pixel)))
1828           break;
1829       }
1830       p+=GetPixelChannels(image);
1831       if (i < (ssize_t) GetPixelChannels(image))
1832         status=MagickFalse;
1833     }
1834     if (x < (ssize_t) image->columns)
1835       status=MagickFalse;
1836   }
1837   image_view=DestroyCacheView(image_view);
1838   return(status != MagickFalse ? MagickFalse : MagickTrue);
1839 #endif
1840 }
1841 \f
1842 /*
1843 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1844 %                                                                             %
1845 %                                                                             %
1846 %                                                                             %
1847 %     I s I m a g e O b j e c t                                               %
1848 %                                                                             %
1849 %                                                                             %
1850 %                                                                             %
1851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1852 %
1853 %  IsImageObject() returns MagickTrue if the image sequence contains a valid
1854 %  set of image objects.
1855 %
1856 %  The format of the IsImageObject method is:
1857 %
1858 %      MagickBooleanType IsImageObject(const Image *image)
1859 %
1860 %  A description of each parameter follows:
1861 %
1862 %    o image: the image.
1863 %
1864 */
1865 MagickExport MagickBooleanType IsImageObject(const Image *image)
1866 {
1867   register const Image
1868     *p;
1869
1870   assert(image != (Image *) NULL);
1871   if (image->debug != MagickFalse)
1872     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1873   for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1874     if (p->signature != MagickCoreSignature)
1875       return(MagickFalse);
1876   return(MagickTrue);
1877 }
1878 \f
1879 /*
1880 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1881 %                                                                             %
1882 %                                                                             %
1883 %                                                                             %
1884 %     I s T a i n t I m a g e                                                 %
1885 %                                                                             %
1886 %                                                                             %
1887 %                                                                             %
1888 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1889 %
1890 %  IsTaintImage() returns MagickTrue any pixel in the image has been altered
1891 %  since it was first constituted.
1892 %
1893 %  The format of the IsTaintImage method is:
1894 %
1895 %      MagickBooleanType IsTaintImage(const Image *image)
1896 %
1897 %  A description of each parameter follows:
1898 %
1899 %    o image: the image.
1900 %
1901 */
1902 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1903 {
1904   char
1905     magick[MagickPathExtent],
1906     filename[MagickPathExtent];
1907
1908   register const Image
1909     *p;
1910
1911   assert(image != (Image *) NULL);
1912   if (image->debug != MagickFalse)
1913     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1914   assert(image->signature == MagickCoreSignature);
1915   (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1916   (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1917   for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1918   {
1919     if (p->taint != MagickFalse)
1920       return(MagickTrue);
1921     if (LocaleCompare(p->magick,magick) != 0)
1922       return(MagickTrue);
1923     if (LocaleCompare(p->filename,filename) != 0)
1924       return(MagickTrue);
1925   }
1926   return(MagickFalse);
1927 }
1928 \f
1929 /*
1930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1931 %                                                                             %
1932 %                                                                             %
1933 %                                                                             %
1934 %   M o d i f y I m a g e                                                     %
1935 %                                                                             %
1936 %                                                                             %
1937 %                                                                             %
1938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1939 %
1940 %  ModifyImage() ensures that there is only a single reference to the image
1941 %  to be modified, updating the provided image pointer to point to a clone of
1942 %  the original image if necessary.
1943 %
1944 %  The format of the ModifyImage method is:
1945 %
1946 %      MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1947 %
1948 %  A description of each parameter follows:
1949 %
1950 %    o image: the image.
1951 %
1952 %    o exception: return any errors or warnings in this structure.
1953 %
1954 */
1955 MagickExport MagickBooleanType ModifyImage(Image **image,
1956   ExceptionInfo *exception)
1957 {
1958   Image
1959     *clone_image;
1960
1961   assert(image != (Image **) NULL);
1962   assert(*image != (Image *) NULL);
1963   assert((*image)->signature == MagickCoreSignature);
1964   if ((*image)->debug != MagickFalse)
1965     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1966   if (GetImageReferenceCount(*image) <= 1)
1967     return(MagickTrue);
1968   clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1969   LockSemaphoreInfo((*image)->semaphore);
1970   (*image)->reference_count--;
1971   UnlockSemaphoreInfo((*image)->semaphore);
1972   *image=clone_image;
1973   return(MagickTrue);
1974 }
1975 \f
1976 /*
1977 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1978 %                                                                             %
1979 %                                                                             %
1980 %                                                                             %
1981 %   N e w M a g i c k I m a g e                                               %
1982 %                                                                             %
1983 %                                                                             %
1984 %                                                                             %
1985 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1986 %
1987 %  NewMagickImage() creates a blank image canvas of the specified size and
1988 %  background color.
1989 %
1990 %  The format of the NewMagickImage method is:
1991 %
1992 %      Image *NewMagickImage(const ImageInfo *image_info,const size_t width,
1993 %        const size_t height,const PixelInfo *background,
1994 %        ExceptionInfo *exception)
1995 %
1996 %  A description of each parameter follows:
1997 %
1998 %    o image: the image.
1999 %
2000 %    o width: the image width.
2001 %
2002 %    o height: the image height.
2003 %
2004 %    o background: the image color.
2005 %
2006 %    o exception: return any errors or warnings in this structure.
2007 %
2008 */
2009 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2010   const size_t width,const size_t height,const PixelInfo *background,
2011   ExceptionInfo *exception)
2012 {
2013   CacheView
2014     *image_view;
2015
2016   Image
2017     *image;
2018
2019   MagickBooleanType
2020     status;
2021
2022   ssize_t
2023     y;
2024
2025   assert(image_info != (const ImageInfo *) NULL);
2026   if (image_info->debug != MagickFalse)
2027     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2028   assert(image_info->signature == MagickCoreSignature);
2029   assert(background != (const PixelInfo *) NULL);
2030   image=AcquireImage(image_info,exception);
2031   image->columns=width;
2032   image->rows=height;
2033   image->colorspace=background->colorspace;
2034   image->alpha_trait=background->alpha_trait;
2035   image->fuzz=background->fuzz;
2036   image->depth=background->depth;
2037   status=MagickTrue;
2038   image_view=AcquireAuthenticCacheView(image,exception);
2039 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2040   #pragma omp parallel for schedule(static,4) shared(status) \
2041     magick_threads(image,image,image->rows,1)
2042 #endif
2043   for (y=0; y < (ssize_t) image->rows; y++)
2044   {
2045     register Quantum
2046       *magick_restrict q;
2047
2048     register ssize_t
2049       x;
2050
2051     if (status == MagickFalse)
2052       continue;
2053     q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2054     if (q == (Quantum *) NULL)
2055       {
2056         status=MagickFalse;
2057         continue;
2058       }
2059     for (x=0; x < (ssize_t) image->columns; x++)
2060     {
2061       SetPixelViaPixelInfo(image,background,q);
2062       q+=GetPixelChannels(image);
2063     }
2064     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2065       status=MagickFalse;
2066   }
2067   image_view=DestroyCacheView(image_view);
2068   if (status == MagickFalse)
2069     image=DestroyImage(image);
2070   return(image);
2071 }
2072 \f
2073 /*
2074 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2075 %                                                                             %
2076 %                                                                             %
2077 %                                                                             %
2078 %   R e f e r e n c e I m a g e                                               %
2079 %                                                                             %
2080 %                                                                             %
2081 %                                                                             %
2082 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2083 %
2084 %  ReferenceImage() increments the reference count associated with an image
2085 %  returning a pointer to the image.
2086 %
2087 %  The format of the ReferenceImage method is:
2088 %
2089 %      Image *ReferenceImage(Image *image)
2090 %
2091 %  A description of each parameter follows:
2092 %
2093 %    o image: the image.
2094 %
2095 */
2096 MagickExport Image *ReferenceImage(Image *image)
2097 {
2098   assert(image != (Image *) NULL);
2099   if (image->debug != MagickFalse)
2100     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2101   assert(image->signature == MagickCoreSignature);
2102   LockSemaphoreInfo(image->semaphore);
2103   image->reference_count++;
2104   UnlockSemaphoreInfo(image->semaphore);
2105   return(image);
2106 }
2107 \f
2108 /*
2109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2110 %                                                                             %
2111 %                                                                             %
2112 %                                                                             %
2113 %   R e s e t I m a g e P a g e                                               %
2114 %                                                                             %
2115 %                                                                             %
2116 %                                                                             %
2117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2118 %
2119 %  ResetImagePage() resets the image page canvas and position.
2120 %
2121 %  The format of the ResetImagePage method is:
2122 %
2123 %      MagickBooleanType ResetImagePage(Image *image,const char *page)
2124 %
2125 %  A description of each parameter follows:
2126 %
2127 %    o image: the image.
2128 %
2129 %    o page: the relative page specification.
2130 %
2131 */
2132 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2133 {
2134   MagickStatusType
2135     flags;
2136
2137   RectangleInfo
2138     geometry;
2139
2140   assert(image != (Image *) NULL);
2141   assert(image->signature == MagickCoreSignature);
2142   if (image->debug != MagickFalse)
2143     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2144   flags=ParseAbsoluteGeometry(page,&geometry);
2145   if ((flags & WidthValue) != 0)
2146     {
2147       if ((flags & HeightValue) == 0)
2148         geometry.height=geometry.width;
2149       image->page.width=geometry.width;
2150       image->page.height=geometry.height;
2151     }
2152   if ((flags & AspectValue) != 0)
2153     {
2154       if ((flags & XValue) != 0)
2155         image->page.x+=geometry.x;
2156       if ((flags & YValue) != 0)
2157         image->page.y+=geometry.y;
2158     }
2159   else
2160     {
2161       if ((flags & XValue) != 0)
2162         {
2163           image->page.x=geometry.x;
2164           if ((image->page.width == 0) && (geometry.x > 0))
2165             image->page.width=image->columns+geometry.x;
2166         }
2167       if ((flags & YValue) != 0)
2168         {
2169           image->page.y=geometry.y;
2170           if ((image->page.height == 0) && (geometry.y > 0))
2171             image->page.height=image->rows+geometry.y;
2172         }
2173     }
2174   return(MagickTrue);
2175 }
2176 \f
2177 /*
2178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2179 %                                                                             %
2180 %                                                                             %
2181 %                                                                             %
2182 %   S e t I m a g e B a c k g r o u n d C o l o r                             %
2183 %                                                                             %
2184 %                                                                             %
2185 %                                                                             %
2186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2187 %
2188 %  SetImageBackgroundColor() initializes the image pixels to the image
2189 %  background color.  The background color is defined by the background_color
2190 %  member of the image structure.
2191 %
2192 %  The format of the SetImage method is:
2193 %
2194 %      MagickBooleanType SetImageBackgroundColor(Image *image,
2195 %        ExceptionInfo *exception)
2196 %
2197 %  A description of each parameter follows:
2198 %
2199 %    o image: the image.
2200 %
2201 %    o exception: return any errors or warnings in this structure.
2202 %
2203 */
2204 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2205   ExceptionInfo *exception)
2206 {
2207   CacheView
2208     *image_view;
2209
2210   MagickBooleanType
2211     status;
2212
2213   PixelInfo
2214     background;
2215
2216   ssize_t
2217     y;
2218
2219   assert(image != (Image *) NULL);
2220   if (image->debug != MagickFalse)
2221     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2222   assert(image->signature == MagickCoreSignature);
2223   if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2224     return(MagickFalse);
2225   ConformPixelInfo(image,&image->background_color,&background,exception);
2226   /*
2227     Set image background color.
2228   */
2229   status=MagickTrue;
2230   image_view=AcquireAuthenticCacheView(image,exception);
2231   for (y=0; y < (ssize_t) image->rows; y++)
2232   {
2233     register Quantum
2234       *magick_restrict q;
2235
2236     register ssize_t
2237       x;
2238
2239     if (status == MagickFalse)
2240       continue;
2241     q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2242     if (q == (Quantum *) NULL)
2243       {
2244         status=MagickFalse;
2245         continue;
2246       }
2247     for (x=0; x < (ssize_t) image->columns; x++)
2248     {
2249       SetPixelViaPixelInfo(image,&background,q);
2250       q+=GetPixelChannels(image);
2251     }
2252     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2253       status=MagickFalse;
2254   }
2255   image_view=DestroyCacheView(image_view);
2256   return(status);
2257 }
2258 \f
2259 /*
2260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2261 %                                                                             %
2262 %                                                                             %
2263 %                                                                             %
2264 %   S e t I m a g e C h a n n e l M a s k                                     %
2265 %                                                                             %
2266 %                                                                             %
2267 %                                                                             %
2268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2269 %
2270 %  SetImageChannelMask() sets the image channel mask from the specified channel
2271 %  mask.
2272 %
2273 %  The format of the SetImageChannelMask method is:
2274 %
2275 %      ChannelType SetImageChannelMask(Image *image,
2276 %        const ChannelType channel_mask)
2277 %
2278 %  A description of each parameter follows:
2279 %
2280 %    o image: the image.
2281 %
2282 %    o channel_mask: the channel mask.
2283 %
2284 */
2285 MagickExport ChannelType SetImageChannelMask(Image *image,
2286   const ChannelType channel_mask)
2287 {
2288   return(SetPixelChannelMask(image,channel_mask));
2289 }
2290 \f
2291 /*
2292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2293 %                                                                             %
2294 %                                                                             %
2295 %                                                                             %
2296 %   S e t I m a g e C o l o r                                                 %
2297 %                                                                             %
2298 %                                                                             %
2299 %                                                                             %
2300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2301 %
2302 %  SetImageColor() set the entire image canvas to the specified color.
2303 %
2304 %  The format of the SetImageColor method is:
2305 %
2306 %      MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2307 %        ExeptionInfo *exception)
2308 %
2309 %  A description of each parameter follows:
2310 %
2311 %    o image: the image.
2312 %
2313 %    o background: the image color.
2314 %
2315 %    o exception: return any errors or warnings in this structure.
2316 %
2317 */
2318 MagickExport MagickBooleanType SetImageColor(Image *image,
2319   const PixelInfo *color,ExceptionInfo *exception)
2320 {
2321   CacheView
2322     *image_view;
2323
2324   MagickBooleanType
2325     status;
2326
2327   ssize_t
2328     y;
2329
2330   assert(image != (Image *) NULL);
2331   if (image->debug != MagickFalse)
2332     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2333   assert(image->signature == MagickCoreSignature);
2334   assert(color != (const PixelInfo *) NULL);
2335   image->colorspace=color->colorspace;
2336   image->alpha_trait=color->alpha_trait;
2337   image->fuzz=color->fuzz;
2338   image->depth=color->depth;
2339   status=MagickTrue;
2340   image_view=AcquireAuthenticCacheView(image,exception);
2341 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2342   #pragma omp parallel for schedule(static,4) shared(status) \
2343     magick_threads(image,image,image->rows,1)
2344 #endif
2345   for (y=0; y < (ssize_t) image->rows; y++)
2346   {
2347     register Quantum
2348       *magick_restrict q;
2349
2350     register ssize_t
2351       x;
2352
2353     if (status == MagickFalse)
2354       continue;
2355     q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2356     if (q == (Quantum *) NULL)
2357       {
2358         status=MagickFalse;
2359         continue;
2360       }
2361     for (x=0; x < (ssize_t) image->columns; x++)
2362     {
2363       SetPixelViaPixelInfo(image,color,q);
2364       q+=GetPixelChannels(image);
2365     }
2366     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2367       status=MagickFalse;
2368   }
2369   image_view=DestroyCacheView(image_view);
2370   return(status);
2371 }
2372 \f
2373 /*
2374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2375 %                                                                             %
2376 %                                                                             %
2377 %                                                                             %
2378 %   S e t I m a g e S t o r a g e C l a s s                                   %
2379 %                                                                             %
2380 %                                                                             %
2381 %                                                                             %
2382 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2383 %
2384 %  SetImageStorageClass() sets the image class: DirectClass for true color
2385 %  images or PseudoClass for colormapped images.
2386 %
2387 %  The format of the SetImageStorageClass method is:
2388 %
2389 %      MagickBooleanType SetImageStorageClass(Image *image,
2390 %        const ClassType storage_class,ExceptionInfo *exception)
2391 %
2392 %  A description of each parameter follows:
2393 %
2394 %    o image: the image.
2395 %
2396 %    o storage_class:  The image class.
2397 %
2398 %    o exception: return any errors or warnings in this structure.
2399 %
2400 */
2401 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2402   const ClassType storage_class,ExceptionInfo *exception)
2403 {
2404   image->storage_class=storage_class;
2405   return(SyncImagePixelCache(image,exception));
2406 }
2407 \f
2408 /*
2409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2410 %                                                                             %
2411 %                                                                             %
2412 %                                                                             %
2413 %   S e t I m a g e E x t e n t                                               %
2414 %                                                                             %
2415 %                                                                             %
2416 %                                                                             %
2417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2418 %
2419 %  SetImageExtent() sets the image size (i.e. columns & rows).
2420 %
2421 %  The format of the SetImageExtent method is:
2422 %
2423 %      MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2424 %        const size_t rows,ExceptionInfo *exception)
2425 %
2426 %  A description of each parameter follows:
2427 %
2428 %    o image: the image.
2429 %
2430 %    o columns:  The image width in pixels.
2431 %
2432 %    o rows:  The image height in pixels.
2433 %
2434 %    o exception: return any errors or warnings in this structure.
2435 %
2436 */
2437 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2438   const size_t rows,ExceptionInfo *exception)
2439 {
2440   if ((columns == 0) || (rows == 0))
2441     return(MagickFalse);
2442   image->columns=columns;
2443   image->rows=rows;
2444   if (image->depth > (8*sizeof(MagickSizeType)))
2445     ThrowBinaryException(ImageError,"ImageDepthNotSupported",image->filename);
2446   return(SyncImagePixelCache(image,exception));
2447 }
2448 \f
2449 /*
2450 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2451 %                                                                             %
2452 %                                                                             %
2453 %                                                                             %
2454 +   S e t I m a g e I n f o                                                   %
2455 %                                                                             %
2456 %                                                                             %
2457 %                                                                             %
2458 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2459 %
2460 %  SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
2461 %  It is set to a type of image format based on the prefix or suffix of the
2462 %  filename.  For example, 'ps:image' returns PS indicating a Postscript image.
2463 %  JPEG is returned for this filename: 'image.jpg'.  The filename prefix has
2464 %  precendence over the suffix.  Use an optional index enclosed in brackets
2465 %  after a file name to specify a desired scene of a multi-resolution image
2466 %  format like Photo CD (e.g. img0001.pcd[4]).  A True (non-zero) return value
2467 %  indicates success.
2468 %
2469 %  The format of the SetImageInfo method is:
2470 %
2471 %      MagickBooleanType SetImageInfo(ImageInfo *image_info,
2472 %        const unsigned int frames,ExceptionInfo *exception)
2473 %
2474 %  A description of each parameter follows:
2475 %
2476 %    o image_info: the image info.
2477 %
2478 %    o frames: the number of images you intend to write.
2479 %
2480 %    o exception: return any errors or warnings in this structure.
2481 %
2482 */
2483 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2484   const unsigned int frames,ExceptionInfo *exception)
2485 {
2486   char
2487     component[MagickPathExtent],
2488     magic[MagickPathExtent],
2489     *q;
2490
2491   const MagicInfo
2492     *magic_info;
2493
2494   const MagickInfo
2495     *magick_info;
2496
2497   ExceptionInfo
2498     *sans_exception;
2499
2500   Image
2501     *image;
2502
2503   MagickBooleanType
2504     status;
2505
2506   register const char
2507     *p;
2508
2509   ssize_t
2510     count;
2511
2512   /*
2513     Look for 'image.format' in filename.
2514   */
2515   assert(image_info != (ImageInfo *) NULL);
2516   assert(image_info->signature == MagickCoreSignature);
2517   if (image_info->debug != MagickFalse)
2518     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2519       image_info->filename);
2520   *component='\0';
2521   GetPathComponent(image_info->filename,SubimagePath,component);
2522   if (*component != '\0')
2523     {
2524       /*
2525         Look for scene specification (e.g. img0001.pcd[4]).
2526       */
2527       if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2528         {
2529           if (IsGeometry(component) != MagickFalse)
2530             (void) CloneString(&image_info->extract,component);
2531         }
2532       else
2533         {
2534           size_t
2535             first,
2536             last;
2537
2538           (void) CloneString(&image_info->scenes,component);
2539           image_info->scene=StringToUnsignedLong(image_info->scenes);
2540           image_info->number_scenes=image_info->scene;
2541           p=image_info->scenes;
2542           for (q=(char *) image_info->scenes; *q != '\0'; p++)
2543           {
2544             while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2545               p++;
2546             first=(size_t) strtol(p,&q,10);
2547             last=first;
2548             while (isspace((int) ((unsigned char) *q)) != 0)
2549               q++;
2550             if (*q == '-')
2551               last=(size_t) strtol(q+1,&q,10);
2552             if (first > last)
2553               Swap(first,last);
2554             if (first < image_info->scene)
2555               image_info->scene=first;
2556             if (last > image_info->number_scenes)
2557               image_info->number_scenes=last;
2558             p=q;
2559           }
2560           image_info->number_scenes-=image_info->scene-1;
2561         }
2562     }
2563   *component='\0';
2564   if (*image_info->magick == '\0')
2565     GetPathComponent(image_info->filename,ExtensionPath,component);
2566 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2567   if (*component != '\0')
2568     if ((LocaleCompare(component,"gz") == 0) ||
2569         (LocaleCompare(component,"Z") == 0) ||
2570         (LocaleCompare(component,"svgz") == 0) ||
2571         (LocaleCompare(component,"wmz") == 0))
2572       {
2573         char
2574           path[MagickPathExtent];
2575
2576         (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2577         path[strlen(path)-strlen(component)-1]='\0';
2578         GetPathComponent(path,ExtensionPath,component);
2579       }
2580 #endif
2581 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2582   if (*component != '\0')
2583     if (LocaleCompare(component,"bz2") == 0)
2584       {
2585         char
2586           path[MagickPathExtent];
2587
2588         (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2589         path[strlen(path)-strlen(component)-1]='\0';
2590         GetPathComponent(path,ExtensionPath,component);
2591       }
2592 #endif
2593   image_info->affirm=MagickFalse;
2594   sans_exception=AcquireExceptionInfo();
2595   if (*component != '\0')
2596     {
2597       MagickFormatType
2598         format_type;
2599
2600       register ssize_t
2601         i;
2602
2603       static const char
2604         *format_type_formats[] =
2605         {
2606           "AUTOTRACE",
2607           "BROWSE",
2608           "DCRAW",
2609           "EDIT",
2610           "EPHEMERAL",
2611           "LAUNCH",
2612           "MPEG:DECODE",
2613           "MPEG:ENCODE",
2614           "PRINT",
2615           "PS:ALPHA",
2616           "PS:CMYK",
2617           "PS:COLOR",
2618           "PS:GRAY",
2619           "PS:MONO",
2620           "SCAN",
2621           "SHOW",
2622           "WIN",
2623           (char *) NULL
2624         };
2625
2626       /*
2627         User specified image format.
2628       */
2629       (void) CopyMagickString(magic,component,MagickPathExtent);
2630       LocaleUpper(magic);
2631       /*
2632         Look for explicit image formats.
2633       */
2634       format_type=UndefinedFormatType;
2635       magick_info=GetMagickInfo(magic,sans_exception);
2636       if ((magick_info != (const MagickInfo *) NULL) &&
2637           (magick_info->format_type != UndefinedFormatType))
2638         format_type=magick_info->format_type;
2639       i=0;
2640       while ((format_type == UndefinedFormatType) &&
2641              (format_type_formats[i] != (char *) NULL))
2642       {
2643         if ((*magic == *format_type_formats[i]) &&
2644             (LocaleCompare(magic,format_type_formats[i]) == 0))
2645           format_type=ExplicitFormatType;
2646         i++;
2647       }
2648       if (format_type == UndefinedFormatType)
2649         (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2650       else
2651         if (format_type == ExplicitFormatType)
2652           {
2653             image_info->affirm=MagickTrue;
2654             (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2655           }
2656       if (LocaleCompare(magic,"RGB") == 0)
2657         image_info->affirm=MagickFalse;  /* maybe SGI disguised as RGB */
2658     }
2659   /*
2660     Look for explicit 'format:image' in filename.
2661   */
2662   *magic='\0';
2663   GetPathComponent(image_info->filename,MagickPath,magic);
2664   if (*magic == '\0')
2665     (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2666   else
2667     {
2668       /*
2669         User specified image format.
2670       */
2671       LocaleUpper(magic);
2672       if (IsMagickConflict(magic) == MagickFalse)
2673         {
2674           (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2675           if (LocaleCompare(magic,"EPHEMERAL") != 0)
2676             image_info->affirm=MagickTrue;
2677           else
2678             image_info->temporary=MagickTrue;
2679         }
2680     }
2681   magick_info=GetMagickInfo(magic,sans_exception);
2682   sans_exception=DestroyExceptionInfo(sans_exception);
2683   if ((magick_info == (const MagickInfo *) NULL) ||
2684       (GetMagickEndianSupport(magick_info) == MagickFalse))
2685     image_info->endian=UndefinedEndian;
2686   GetPathComponent(image_info->filename,CanonicalPath,component);
2687   (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2688   if ((image_info->adjoin != MagickFalse) && (frames > 1))
2689     {
2690       /*
2691         Test for multiple image support (e.g. image%02d.png).
2692       */
2693       (void) InterpretImageFilename(image_info,(Image *) NULL,
2694         image_info->filename,(int) image_info->scene,component,exception);
2695       if ((LocaleCompare(component,image_info->filename) != 0) &&
2696           (strchr(component,'%') == (char *) NULL))
2697         image_info->adjoin=MagickFalse;
2698     }
2699   if ((image_info->adjoin != MagickFalse) && (frames > 0))
2700     {
2701       /*
2702         Some image formats do not support multiple frames per file.
2703       */
2704       magick_info=GetMagickInfo(magic,exception);
2705       if (magick_info != (const MagickInfo *) NULL)
2706         if (GetMagickAdjoin(magick_info) == MagickFalse)
2707           image_info->adjoin=MagickFalse;
2708     }
2709   if (image_info->affirm != MagickFalse)
2710     return(MagickTrue);
2711   if (frames == 0)
2712     {
2713       unsigned char
2714         *magick;
2715
2716       size_t
2717         magick_size;
2718
2719       /*
2720         Determine the image format from the first few bytes of the file.
2721       */
2722       magick_size=GetMagicPatternExtent(exception);
2723       if (magick_size == 0)
2724         return(MagickFalse);
2725       image=AcquireImage(image_info,exception);
2726       (void) CopyMagickString(image->filename,image_info->filename,
2727         MagickPathExtent);
2728       status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2729       if (status == MagickFalse)
2730         {
2731           image=DestroyImage(image);
2732           return(MagickFalse);
2733         }
2734       if ((IsBlobSeekable(image) == MagickFalse) ||
2735           (IsBlobExempt(image) != MagickFalse))
2736         {
2737           /*
2738             Copy standard input or pipe to temporary file.
2739           */
2740           *component='\0';
2741           status=ImageToFile(image,component,exception);
2742           (void) CloseBlob(image);
2743           if (status == MagickFalse)
2744             {
2745               image=DestroyImage(image);
2746               return(MagickFalse);
2747             }
2748           SetImageInfoFile(image_info,(FILE *) NULL);
2749           (void) CopyMagickString(image->filename,component,MagickPathExtent);
2750           status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2751           if (status == MagickFalse)
2752             {
2753               image=DestroyImage(image);
2754               return(MagickFalse);
2755             }
2756           (void) CopyMagickString(image_info->filename,component,
2757             MagickPathExtent);
2758           image_info->temporary=MagickTrue;
2759         }
2760       magick=(unsigned char *) AcquireMagickMemory(magick_size);
2761       if (magick == (unsigned char *) NULL)
2762         {
2763           (void) CloseBlob(image);
2764           image=DestroyImage(image);
2765           return(MagickFalse);
2766         }
2767       (void) ResetMagickMemory(magick,0,magick_size);
2768       count=ReadBlob(image,magick_size,magick);
2769       (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
2770       (void) CloseBlob(image);
2771       image=DestroyImage(image);
2772       /*
2773         Check magic.xml configuration file.
2774       */
2775       sans_exception=AcquireExceptionInfo();
2776       magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
2777       magick=(unsigned char *) RelinquishMagickMemory(magick);
2778       if ((magic_info != (const MagicInfo *) NULL) &&
2779           (GetMagicName(magic_info) != (char *) NULL))
2780         {
2781           /*
2782             Try to use magick_info that was determined earlier by the extension
2783           */
2784           if ((magick_info != (const MagickInfo *) NULL) &&
2785               (GetMagickUseExtension(magick_info) != MagickFalse) &&
2786               (LocaleCompare(magick_info->module,GetMagicName(
2787                 magic_info)) == 0))
2788             (void) CopyMagickString(image_info->magick,magick_info->name,
2789               MagickPathExtent);
2790           else
2791             {
2792               (void) CopyMagickString(image_info->magick,GetMagicName(
2793                 magic_info),MagickPathExtent);
2794               magick_info=GetMagickInfo(image_info->magick,sans_exception);
2795             }
2796           if ((magick_info == (const MagickInfo *) NULL) ||
2797               (GetMagickEndianSupport(magick_info) == MagickFalse))
2798             image_info->endian=UndefinedEndian;
2799           sans_exception=DestroyExceptionInfo(sans_exception);
2800           return(MagickTrue);
2801         }
2802       magick_info=GetMagickInfo(image_info->magick,sans_exception);
2803       if ((magick_info == (const MagickInfo *) NULL) ||
2804           (GetMagickEndianSupport(magick_info) == MagickFalse))
2805         image_info->endian=UndefinedEndian;
2806       sans_exception=DestroyExceptionInfo(sans_exception);
2807     }
2808   return(MagickTrue);
2809 }
2810 \f
2811 /*
2812 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2813 %                                                                             %
2814 %                                                                             %
2815 %                                                                             %
2816 %   S e t I m a g e I n f o B l o b                                           %
2817 %                                                                             %
2818 %                                                                             %
2819 %                                                                             %
2820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2821 %
2822 %  SetImageInfoBlob() sets the image info blob member.
2823 %
2824 %  The format of the SetImageInfoBlob method is:
2825 %
2826 %      void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2827 %        const size_t length)
2828 %
2829 %  A description of each parameter follows:
2830 %
2831 %    o image_info: the image info.
2832 %
2833 %    o blob: the blob.
2834 %
2835 %    o length: the blob length.
2836 %
2837 */
2838 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2839   const size_t length)
2840 {
2841   assert(image_info != (ImageInfo *) NULL);
2842   assert(image_info->signature == MagickCoreSignature);
2843   if (image_info->debug != MagickFalse)
2844     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2845       image_info->filename);
2846   image_info->blob=(void *) blob;
2847   image_info->length=length;
2848 }
2849 \f
2850 /*
2851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2852 %                                                                             %
2853 %                                                                             %
2854 %                                                                             %
2855 %   S e t I m a g e I n f o F i l e                                           %
2856 %                                                                             %
2857 %                                                                             %
2858 %                                                                             %
2859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2860 %
2861 %  SetImageInfoFile() sets the image info file member.
2862 %
2863 %  The format of the SetImageInfoFile method is:
2864 %
2865 %      void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2866 %
2867 %  A description of each parameter follows:
2868 %
2869 %    o image_info: the image info.
2870 %
2871 %    o file: the file.
2872 %
2873 */
2874 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2875 {
2876   assert(image_info != (ImageInfo *) NULL);
2877   assert(image_info->signature == MagickCoreSignature);
2878   if (image_info->debug != MagickFalse)
2879     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2880       image_info->filename);
2881   image_info->file=file;
2882 }
2883 \f
2884 /*
2885 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2886 %                                                                             %
2887 %                                                                             %
2888 %                                                                             %
2889 %   S e t I m a g e M a s k                                                   %
2890 %                                                                             %
2891 %                                                                             %
2892 %                                                                             %
2893 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2894 %
2895 %  SetImageMask() associates a mask with the image.  The mask must be the same
2896 %  dimensions as the image.
2897 %
2898 %  The format of the SetImageMask method is:
2899 %
2900 %      MagickBooleanType SetImageMask(Image *image,const PixelMask type,
2901 %        const Image *mask,ExceptionInfo *exception)
2902 %
2903 %  A description of each parameter follows:
2904 %
2905 %    o image: the image.
2906 %
2907 %    o type: the mask type, ReadPixelMask or WritePixelMask.
2908 %
2909 %    o mask: the image mask.
2910 %
2911 %    o exception: return any errors or warnings in this structure.
2912 %
2913 */
2914 MagickExport MagickBooleanType SetImageMask(Image *image,const PixelMask type,
2915   const Image *mask,ExceptionInfo *exception)
2916 {
2917   CacheView
2918     *mask_view,
2919     *image_view;
2920
2921   MagickBooleanType
2922     status;
2923
2924   ssize_t
2925     y;
2926
2927   /*
2928     Set image mask.
2929   */
2930   assert(image != (Image *) NULL);
2931   if (image->debug != MagickFalse)
2932     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2933   assert(image->signature == MagickCoreSignature);
2934   if (mask == (const Image *) NULL)
2935     {
2936       switch (type)
2937       {
2938         case WritePixelMask: image->write_mask=MagickFalse; break;
2939         default: image->read_mask=MagickFalse; break;
2940       }
2941       return(SyncImagePixelCache(image,exception));
2942     }
2943   switch (type)
2944   {
2945     case WritePixelMask: image->write_mask=MagickTrue; break;
2946     default: image->read_mask=MagickTrue; break;
2947   }
2948   if (SyncImagePixelCache(image,exception) == MagickFalse)
2949     return(MagickFalse);
2950   status=MagickTrue;
2951   mask_view=AcquireVirtualCacheView(mask,exception);
2952   image_view=AcquireAuthenticCacheView(image,exception);
2953 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2954   #pragma omp parallel for schedule(static,4) shared(status) \
2955     magick_threads(mask,image,1,1)
2956 #endif
2957   for (y=0; y < (ssize_t) image->rows; y++)
2958   {
2959     register const Quantum
2960       *magick_restrict p;
2961
2962     register Quantum
2963       *magick_restrict q;
2964
2965     register ssize_t
2966       x;
2967
2968     if (status == MagickFalse)
2969       continue;
2970     p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
2971     q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2972     if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2973       {
2974         status=MagickFalse;
2975         continue;
2976       }
2977     for (x=0; x < (ssize_t) image->columns; x++)
2978     {
2979       switch (type)
2980       {
2981         case WritePixelMask:
2982         {
2983           SetPixelWriteMask(image,ClampToQuantum(GetPixelIntensity(mask,p)),q);
2984           break;
2985         }
2986         default:
2987         {
2988           SetPixelReadMask(image,ClampToQuantum(GetPixelIntensity(mask,p)),q);
2989           break;
2990         }
2991       }
2992       p+=GetPixelChannels(mask);
2993       q+=GetPixelChannels(image);
2994     }
2995     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2996       status=MagickFalse;
2997   }
2998   mask_view=DestroyCacheView(mask_view);
2999   image_view=DestroyCacheView(image_view);
3000   return(status);
3001 }
3002 \f
3003 /*
3004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3005 %                                                                             %
3006 %                                                                             %
3007 %                                                                             %
3008 %     S e t I m a g e A l p h a                                               %
3009 %                                                                             %
3010 %                                                                             %
3011 %                                                                             %
3012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3013 %
3014 %  SetImageAlpha() sets the alpha levels of the image.
3015 %
3016 %  The format of the SetImageAlpha method is:
3017 %
3018 %      MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3019 %        ExceptionInfo *exception)
3020 %
3021 %  A description of each parameter follows:
3022 %
3023 %    o image: the image.
3024 %
3025 %    o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3026 %      fully transparent.
3027 %
3028 */
3029 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3030   ExceptionInfo *exception)
3031 {
3032   CacheView
3033     *image_view;
3034
3035   MagickBooleanType
3036     status;
3037
3038   ssize_t
3039     y;
3040
3041   assert(image != (Image *) NULL);
3042   if (image->debug != MagickFalse)
3043     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3044   assert(image->signature == MagickCoreSignature);
3045   image->alpha_trait=BlendPixelTrait;
3046   status=MagickTrue;
3047   image_view=AcquireAuthenticCacheView(image,exception);
3048 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3049   #pragma omp parallel for schedule(static,4) shared(status) \
3050     magick_threads(image,image,image->rows,1)
3051 #endif
3052   for (y=0; y < (ssize_t) image->rows; y++)
3053   {
3054     register Quantum
3055       *magick_restrict q;
3056
3057     register ssize_t
3058       x;
3059
3060     if (status == MagickFalse)
3061       continue;
3062     q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3063     if (q == (Quantum *) NULL)
3064       {
3065         status=MagickFalse;
3066         continue;
3067       }
3068     for (x=0; x < (ssize_t) image->columns; x++)
3069     {
3070       if (GetPixelReadMask(image,q) != 0)
3071         SetPixelAlpha(image,alpha,q);
3072       q+=GetPixelChannels(image);
3073     }
3074     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3075       status=MagickFalse;
3076   }
3077   image_view=DestroyCacheView(image_view);
3078   return(status);
3079 }
3080 \f
3081 /*
3082 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3083 %                                                                             %
3084 %                                                                             %
3085 %                                                                             %
3086 %   S e t I m a g e V i r t u a l P i x e l M e t h o d                       %
3087 %                                                                             %
3088 %                                                                             %
3089 %                                                                             %
3090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3091 %
3092 %  SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3093 %  image and returns the previous setting.  A virtual pixel is any pixel access
3094 %  that is outside the boundaries of the image cache.
3095 %
3096 %  The format of the SetImageVirtualPixelMethod() method is:
3097 %
3098 %      VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3099 %        const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3100 %
3101 %  A description of each parameter follows:
3102 %
3103 %    o image: the image.
3104 %
3105 %    o virtual_pixel_method: choose the type of virtual pixel.
3106 %
3107 %    o exception: return any errors or warnings in this structure.
3108 %
3109 */
3110 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3111   const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3112 {
3113   assert(image != (const Image *) NULL);
3114   assert(image->signature == MagickCoreSignature);
3115   if (image->debug != MagickFalse)
3116     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3117   return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3118 }
3119 \f
3120 /*
3121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3122 %                                                                             %
3123 %                                                                             %
3124 %                                                                             %
3125 %     S m u s h I m a g e s                                                   %
3126 %                                                                             %
3127 %                                                                             %
3128 %                                                                             %
3129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3130 %
3131 %  SmushImages() takes all images from the current image pointer to the end
3132 %  of the image list and smushes them to each other top-to-bottom if the
3133 %  stack parameter is true, otherwise left-to-right.
3134 %
3135 %  The current gravity setting now effects how the image is justified in the
3136 %  final image.
3137 %
3138 %  The format of the SmushImages method is:
3139 %
3140 %      Image *SmushImages(const Image *images,const MagickBooleanType stack,
3141 %        ExceptionInfo *exception)
3142 %
3143 %  A description of each parameter follows:
3144 %
3145 %    o images: the image sequence.
3146 %
3147 %    o stack: A value other than 0 stacks the images top-to-bottom.
3148 %
3149 %    o offset: minimum distance in pixels between images.
3150 %
3151 %    o exception: return any errors or warnings in this structure.
3152 %
3153 */
3154
3155 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3156   const ssize_t offset,ExceptionInfo *exception)
3157 {
3158   CacheView
3159     *left_view,
3160     *right_view;
3161
3162   const Image
3163     *left_image,
3164     *right_image;
3165
3166   RectangleInfo
3167     left_geometry,
3168     right_geometry;
3169
3170   register const Quantum
3171     *p;
3172
3173   register ssize_t
3174     i,
3175     y;
3176
3177   size_t
3178     gap;
3179
3180   ssize_t
3181     x;
3182
3183   if (images->previous == (Image *) NULL)
3184     return(0);
3185   right_image=images;
3186   SetGeometry(smush_image,&right_geometry);
3187   GravityAdjustGeometry(right_image->columns,right_image->rows,
3188     right_image->gravity,&right_geometry);
3189   left_image=images->previous;
3190   SetGeometry(smush_image,&left_geometry);
3191   GravityAdjustGeometry(left_image->columns,left_image->rows,
3192     left_image->gravity,&left_geometry);
3193   gap=right_image->columns;
3194   left_view=AcquireVirtualCacheView(left_image,exception);
3195   right_view=AcquireVirtualCacheView(right_image,exception);
3196   for (y=0; y < (ssize_t) smush_image->rows; y++)
3197   {
3198     for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3199     {
3200       p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3201       if ((p == (const Quantum *) NULL) ||
3202           (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3203           ((left_image->columns-x-1) >= gap))
3204         break;
3205     }
3206     i=(ssize_t) left_image->columns-x-1;
3207     for (x=0; x < (ssize_t) right_image->columns; x++)
3208     {
3209       p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3210         exception);
3211       if ((p == (const Quantum *) NULL) ||
3212           (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3213           ((x+i) >= (ssize_t) gap))
3214         break;
3215     }
3216     if ((x+i) < (ssize_t) gap)
3217       gap=(size_t) (x+i);
3218   }
3219   right_view=DestroyCacheView(right_view);
3220   left_view=DestroyCacheView(left_view);
3221   if (y < (ssize_t) smush_image->rows)
3222     return(offset);
3223   return((ssize_t) gap-offset);
3224 }
3225
3226 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3227   const ssize_t offset,ExceptionInfo *exception)
3228 {
3229   CacheView
3230     *bottom_view,
3231     *top_view;
3232
3233   const Image
3234     *bottom_image,
3235     *top_image;
3236
3237   RectangleInfo
3238     bottom_geometry,
3239     top_geometry;
3240
3241   register const Quantum
3242     *p;
3243
3244   register ssize_t
3245     i,
3246     x;
3247
3248   size_t
3249     gap;
3250
3251   ssize_t
3252     y;
3253
3254   if (images->previous == (Image *) NULL)
3255     return(0);
3256   bottom_image=images;
3257   SetGeometry(smush_image,&bottom_geometry);
3258   GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3259     bottom_image->gravity,&bottom_geometry);
3260   top_image=images->previous;
3261   SetGeometry(smush_image,&top_geometry);
3262   GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3263     &top_geometry);
3264   gap=bottom_image->rows;
3265   top_view=AcquireVirtualCacheView(top_image,exception);
3266   bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3267   for (x=0; x < (ssize_t) smush_image->columns; x++)
3268   {
3269     for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3270     {
3271       p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3272       if ((p == (const Quantum *) NULL) ||
3273           (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3274           ((top_image->rows-y-1) >= gap))
3275         break;
3276     }
3277     i=(ssize_t) top_image->rows-y-1;
3278     for (y=0; y < (ssize_t) bottom_image->rows; y++)
3279     {
3280       p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3281         exception);
3282       if ((p == (const Quantum *) NULL) ||
3283           (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3284           ((y+i) >= (ssize_t) gap))
3285         break;
3286     }
3287     if ((y+i) < (ssize_t) gap)
3288       gap=(size_t) (y+i);
3289   }
3290   bottom_view=DestroyCacheView(bottom_view);
3291   top_view=DestroyCacheView(top_view);
3292   if (x < (ssize_t) smush_image->columns)
3293     return(offset);
3294   return((ssize_t) gap-offset);
3295 }
3296
3297 MagickExport Image *SmushImages(const Image *images,
3298   const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3299 {
3300 #define SmushImageTag  "Smush/Image"
3301
3302   const Image
3303     *image;
3304
3305   Image
3306     *smush_image;
3307
3308   MagickBooleanType
3309     proceed,
3310     status;
3311
3312   MagickOffsetType
3313     n;
3314
3315   PixelTrait
3316     alpha_trait;
3317
3318   RectangleInfo
3319     geometry;
3320
3321   register const Image
3322     *next;
3323
3324   size_t
3325     height,
3326     number_images,
3327     width;
3328
3329   ssize_t
3330     x_offset,
3331     y_offset;
3332
3333   /*
3334     Compute maximum area of smushed area.
3335   */
3336   assert(images != (Image *) NULL);
3337   assert(images->signature == MagickCoreSignature);
3338   if (images->debug != MagickFalse)
3339     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3340   assert(exception != (ExceptionInfo *) NULL);
3341   assert(exception->signature == MagickCoreSignature);
3342   image=images;
3343   alpha_trait=image->alpha_trait;
3344   number_images=1;
3345   width=image->columns;
3346   height=image->rows;
3347   next=GetNextImageInList(image);
3348   for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3349   {
3350     if (next->alpha_trait != UndefinedPixelTrait)
3351       alpha_trait=BlendPixelTrait;
3352     number_images++;
3353     if (stack != MagickFalse)
3354       {
3355         if (next->columns > width)
3356           width=next->columns;
3357         height+=next->rows;
3358         if (next->previous != (Image *) NULL)
3359           height+=offset;
3360         continue;
3361       }
3362     width+=next->columns;
3363     if (next->previous != (Image *) NULL)
3364       width+=offset;
3365     if (next->rows > height)
3366       height=next->rows;
3367   }
3368   /*
3369     Smush images.
3370   */
3371   smush_image=CloneImage(image,width,height,MagickTrue,exception);
3372   if (smush_image == (Image *) NULL)
3373     return((Image *) NULL);
3374   if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3375     {
3376       smush_image=DestroyImage(smush_image);
3377       return((Image *) NULL);
3378     }
3379   smush_image->alpha_trait=alpha_trait;
3380   (void) SetImageBackgroundColor(smush_image,exception);
3381   status=MagickTrue;
3382   x_offset=0;
3383   y_offset=0;
3384   for (n=0; n < (MagickOffsetType) number_images; n++)
3385   {
3386     SetGeometry(smush_image,&geometry);
3387     GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3388     if (stack != MagickFalse)
3389       {
3390         x_offset-=geometry.x;
3391         y_offset-=SmushYGap(smush_image,image,offset,exception);
3392       }
3393     else
3394       {
3395         x_offset-=SmushXGap(smush_image,image,offset,exception);
3396         y_offset-=geometry.y;
3397       }
3398     status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3399       y_offset,exception);
3400     proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3401     if (proceed == MagickFalse)
3402       break;
3403     if (stack == MagickFalse)
3404       {
3405         x_offset+=(ssize_t) image->columns;
3406         y_offset=0;
3407       }
3408     else
3409       {
3410         x_offset=0;
3411         y_offset+=(ssize_t) image->rows;
3412       }
3413     image=GetNextImageInList(image);
3414   }
3415   if (stack == MagickFalse)
3416     smush_image->columns=(size_t) x_offset;
3417   else
3418     smush_image->rows=(size_t) y_offset;
3419   if (status == MagickFalse)
3420     smush_image=DestroyImage(smush_image);
3421   return(smush_image);
3422 }
3423 \f
3424 /*
3425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3426 %                                                                             %
3427 %                                                                             %
3428 %                                                                             %
3429 %   S t r i p I m a g e                                                       %
3430 %                                                                             %
3431 %                                                                             %
3432 %                                                                             %
3433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3434 %
3435 %  StripImage() strips an image of all profiles and comments.
3436 %
3437 %  The format of the StripImage method is:
3438 %
3439 %      MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3440 %
3441 %  A description of each parameter follows:
3442 %
3443 %    o image: the image.
3444 %
3445 %    o exception: return any errors or warnings in this structure.
3446 %
3447 */
3448 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3449 {
3450   MagickBooleanType
3451     status;
3452
3453   assert(image != (Image *) NULL);
3454   if (image->debug != MagickFalse)
3455     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3456   (void) exception;
3457   DestroyImageProfiles(image);
3458   (void) DeleteImageProperty(image,"comment");
3459   (void) DeleteImageProperty(image,"date:create");
3460   (void) DeleteImageProperty(image,"date:modify");
3461   status=SetImageArtifact(image,"png:exclude-chunk",
3462     "EXIF,iCCP,iTXt,sRGB,tEXt,zCCP,zTXt,date");
3463   return(status);
3464 }
3465 \f
3466 /*
3467 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3468 %                                                                             %
3469 %                                                                             %
3470 %                                                                             %
3471 +   S y n c I m a g e                                                         %
3472 %                                                                             %
3473 %                                                                             %
3474 %                                                                             %
3475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3476 %
3477 %  SyncImage() initializes the red, green, and blue intensities of each pixel
3478 %  as defined by the colormap index.
3479 %
3480 %  The format of the SyncImage method is:
3481 %
3482 %      MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3483 %
3484 %  A description of each parameter follows:
3485 %
3486 %    o image: the image.
3487 %
3488 %    o exception: return any errors or warnings in this structure.
3489 %
3490 */
3491
3492 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3493   MagickBooleanType *range_exception)
3494 {
3495   if ((size_t) index < image->colors)
3496     return(index);
3497   *range_exception=MagickTrue;
3498   return((Quantum) 0);
3499 }
3500
3501 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3502 {
3503   CacheView
3504     *image_view;
3505
3506   MagickBooleanType
3507     range_exception,
3508     status,
3509     taint;
3510
3511   ssize_t
3512     y;
3513
3514   assert(image != (Image *) NULL);
3515   if (image->debug != MagickFalse)
3516     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3517   assert(image->signature == MagickCoreSignature);
3518   if (image->storage_class == DirectClass)
3519     return(MagickFalse);
3520   range_exception=MagickFalse;
3521   status=MagickTrue;
3522   taint=image->taint;
3523   image_view=AcquireAuthenticCacheView(image,exception);
3524 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3525   #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
3526     magick_threads(image,image,image->rows,1)
3527 #endif
3528   for (y=0; y < (ssize_t) image->rows; y++)
3529   {
3530     Quantum
3531       index;
3532
3533     register Quantum
3534       *magick_restrict q;
3535
3536     register ssize_t
3537       x;
3538
3539     if (status == MagickFalse)
3540       continue;
3541     q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3542     if (q == (Quantum *) NULL)
3543       {
3544         status=MagickFalse;
3545         continue;
3546       }
3547     for (x=0; x < (ssize_t) image->columns; x++)
3548     {
3549       index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3550       SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
3551       q+=GetPixelChannels(image);
3552     }
3553     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3554       status=MagickFalse;
3555   }
3556   image_view=DestroyCacheView(image_view);
3557   image->taint=taint;
3558   if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3559     (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
3560       "InvalidColormapIndex","`%s'",image->filename);
3561   return(status);
3562 }
3563 \f
3564 /*
3565 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3566 %                                                                             %
3567 %                                                                             %
3568 %                                                                             %
3569 %   S y n c I m a g e S e t t i n g s                                         %
3570 %                                                                             %
3571 %                                                                             %
3572 %                                                                             %
3573 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3574 %
3575 %  SyncImageSettings() syncs any image_info global options into per-image
3576 %  attributes.
3577 %
3578 %  Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
3579 %  that operations and coders can find such settings.  In IMv7 if a desired
3580 %  per-image artifact is not set, then it will directly look for a global
3581 %  option as a fallback, as such this copy is no longer needed, only the
3582 %  link set up.
3583 %
3584 %  The format of the SyncImageSettings method is:
3585 %
3586 %      MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3587 %        Image *image,ExceptionInfo *exception)
3588 %      MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3589 %        Image *image,ExceptionInfo *exception)
3590 %
3591 %  A description of each parameter follows:
3592 %
3593 %    o image_info: the image info.
3594 %
3595 %    o image: the image.
3596 %
3597 %    o exception: return any errors or warnings in this structure.
3598 %
3599 */
3600
3601 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3602   Image *images,ExceptionInfo *exception)
3603 {
3604   Image
3605     *image;
3606
3607   assert(image_info != (const ImageInfo *) NULL);
3608   assert(image_info->signature == MagickCoreSignature);
3609   assert(images != (Image *) NULL);
3610   assert(images->signature == MagickCoreSignature);
3611   if (images->debug != MagickFalse)
3612     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3613   image=images;
3614   for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3615     (void) SyncImageSettings(image_info,image,exception);
3616   (void) DeleteImageOption(image_info,"page");
3617   return(MagickTrue);
3618 }
3619
3620 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3621   Image *image,ExceptionInfo *exception)
3622 {
3623   const char
3624     *option;
3625
3626   GeometryInfo
3627     geometry_info;
3628
3629   MagickStatusType
3630     flags;
3631
3632   ResolutionType
3633     units;
3634
3635   /*
3636     Sync image options.
3637   */
3638   assert(image_info != (const ImageInfo *) NULL);
3639   assert(image_info->signature == MagickCoreSignature);
3640   assert(image != (Image *) NULL);
3641   assert(image->signature == MagickCoreSignature);
3642   if (image->debug != MagickFalse)
3643     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3644   option=GetImageOption(image_info,"background");
3645   if (option != (const char *) NULL)
3646     (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
3647       exception);
3648   option=GetImageOption(image_info,"black-point-compensation");
3649   if (option != (const char *) NULL)
3650     image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3651       MagickBooleanOptions,MagickFalse,option);
3652   option=GetImageOption(image_info,"blue-primary");
3653   if (option != (const char *) NULL)
3654     {
3655       flags=ParseGeometry(option,&geometry_info);
3656       image->chromaticity.blue_primary.x=geometry_info.rho;
3657       image->chromaticity.blue_primary.y=geometry_info.sigma;
3658       if ((flags & SigmaValue) == 0)
3659         image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3660     }
3661   option=GetImageOption(image_info,"bordercolor");
3662   if (option != (const char *) NULL)
3663     (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
3664       exception);
3665   /* FUTURE: do not sync compose to per-image compose setting here */
3666   option=GetImageOption(image_info,"compose");
3667   if (option != (const char *) NULL)
3668     image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3669       MagickFalse,option);
3670   /* -- */
3671   option=GetImageOption(image_info,"compress");
3672   if (option != (const char *) NULL)
3673     image->compression=(CompressionType) ParseCommandOption(
3674       MagickCompressOptions,MagickFalse,option);
3675   option=GetImageOption(image_info,"debug");
3676   if (option != (const char *) NULL)
3677     image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3678       MagickFalse,option);
3679   option=GetImageOption(image_info,"density");
3680   if (option != (const char *) NULL)
3681     {
3682       GeometryInfo
3683         geometry_info;
3684
3685       flags=ParseGeometry(option,&geometry_info);
3686       image->resolution.x=geometry_info.rho;
3687       image->resolution.y=geometry_info.sigma;
3688       if ((flags & SigmaValue) == 0)
3689         image->resolution.y=image->resolution.x;
3690     }
3691   option=GetImageOption(image_info,"depth");
3692   if (option != (const char *) NULL)
3693     image->depth=StringToUnsignedLong(option);
3694   option=GetImageOption(image_info,"endian");
3695   if (option != (const char *) NULL)
3696     image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3697       MagickFalse,option);
3698   option=GetImageOption(image_info,"filter");
3699   if (option != (const char *) NULL)
3700     image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
3701       MagickFalse,option);
3702   option=GetImageOption(image_info,"fuzz");
3703   if (option != (const char *) NULL)
3704     image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3705   option=GetImageOption(image_info,"gravity");
3706   if (option != (const char *) NULL)
3707     image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3708       MagickFalse,option);
3709   option=GetImageOption(image_info,"green-primary");
3710   if (option != (const char *) NULL)
3711     {
3712       flags=ParseGeometry(option,&geometry_info);
3713       image->chromaticity.green_primary.x=geometry_info.rho;
3714       image->chromaticity.green_primary.y=geometry_info.sigma;
3715       if ((flags & SigmaValue) == 0)
3716         image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3717     }
3718   option=GetImageOption(image_info,"intent");
3719   if (option != (const char *) NULL)
3720     image->rendering_intent=(RenderingIntent) ParseCommandOption(
3721       MagickIntentOptions,MagickFalse,option);
3722   option=GetImageOption(image_info,"intensity");
3723   if (option != (const char *) NULL)
3724     image->intensity=(PixelIntensityMethod) ParseCommandOption(
3725       MagickPixelIntensityOptions,MagickFalse,option);
3726   option=GetImageOption(image_info,"interlace");
3727   if (option != (const char *) NULL)
3728     image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3729       MagickFalse,option);
3730   option=GetImageOption(image_info,"interpolate");
3731   if (option != (const char *) NULL)
3732     image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
3733       MagickInterpolateOptions,MagickFalse,option);
3734   option=GetImageOption(image_info,"loop");
3735   if (option != (const char *) NULL)
3736     image->iterations=StringToUnsignedLong(option);
3737   option=GetImageOption(image_info,"mattecolor");
3738   if (option != (const char *) NULL)
3739     (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
3740       exception);
3741   option=GetImageOption(image_info,"orient");
3742   if (option != (const char *) NULL)
3743     image->orientation=(OrientationType) ParseCommandOption(
3744       MagickOrientationOptions,MagickFalse,option);
3745   option=GetImageOption(image_info,"page");
3746   if (option != (const char *) NULL)
3747     {
3748       char
3749         *geometry;
3750
3751       geometry=GetPageGeometry(option);
3752       flags=ParseAbsoluteGeometry(geometry,&image->page);
3753       geometry=DestroyString(geometry);
3754     }
3755   option=GetImageOption(image_info,"quality");
3756   if (option != (const char *) NULL)
3757     image->quality=StringToUnsignedLong(option);
3758   option=GetImageOption(image_info,"red-primary");
3759   if (option != (const char *) NULL)
3760     {
3761       flags=ParseGeometry(option,&geometry_info);
3762       image->chromaticity.red_primary.x=geometry_info.rho;
3763       image->chromaticity.red_primary.y=geometry_info.sigma;
3764       if ((flags & SigmaValue) == 0)
3765         image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3766     }
3767   if (image_info->quality != UndefinedCompressionQuality)
3768     image->quality=image_info->quality;
3769   option=GetImageOption(image_info,"scene");
3770   if (option != (const char *) NULL)
3771     image->scene=StringToUnsignedLong(option);
3772   option=GetImageOption(image_info,"taint");
3773   if (option != (const char *) NULL)
3774     image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3775       MagickFalse,option);
3776   option=GetImageOption(image_info,"tile-offset");
3777   if (option != (const char *) NULL)
3778     {
3779       char
3780         *geometry;
3781
3782       geometry=GetPageGeometry(option);
3783       flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3784       geometry=DestroyString(geometry);
3785     }
3786   option=GetImageOption(image_info,"transparent-color");
3787   if (option != (const char *) NULL)
3788     (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
3789       exception);
3790   option=GetImageOption(image_info,"type");
3791   if (option != (const char *) NULL)
3792     image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3793       option);
3794   option=GetImageOption(image_info,"units");
3795   units=image_info->units;
3796   if (option != (const char *) NULL)
3797     units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
3798       MagickFalse,option);
3799   if (units != UndefinedResolution)
3800     {
3801       if (image->units != units)
3802         switch (image->units)
3803         {
3804           case PixelsPerInchResolution:
3805           {
3806             if (units == PixelsPerCentimeterResolution)
3807               {
3808                 image->resolution.x/=2.54;
3809                 image->resolution.y/=2.54;
3810               }
3811             break;
3812           }
3813           case PixelsPerCentimeterResolution:
3814           {
3815             if (units == PixelsPerInchResolution)
3816               {
3817                 image->resolution.x=(double) ((size_t) (100.0*2.54*
3818                   image->resolution.x+0.5))/100.0;
3819                 image->resolution.y=(double) ((size_t) (100.0*2.54*
3820                   image->resolution.y+0.5))/100.0;
3821               }
3822             break;
3823           }
3824           default:
3825             break;
3826         }
3827       image->units=units;
3828     }
3829   option=GetImageOption(image_info,"virtual-pixel");
3830   if (option != (const char *) NULL)
3831     (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
3832       ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
3833       exception);
3834   option=GetImageOption(image_info,"white-point");
3835   if (option != (const char *) NULL)
3836     {
3837       flags=ParseGeometry(option,&geometry_info);
3838       image->chromaticity.white_point.x=geometry_info.rho;
3839       image->chromaticity.white_point.y=geometry_info.sigma;
3840       if ((flags & SigmaValue) == 0)
3841         image->chromaticity.white_point.y=image->chromaticity.white_point.x;
3842     }
3843   /*
3844     Pointer to allow the lookup of pre-image artifact will fallback to a global
3845     option setting/define.  This saves a lot of duplication of global options
3846     into per-image artifacts, while ensuring only specifically set per-image
3847     artifacts are preserved when parenthesis ends.
3848   */
3849   if (image->image_info != (ImageInfo *) NULL)
3850     image->image_info=DestroyImageInfo(image->image_info);
3851   image->image_info=CloneImageInfo(image_info);
3852   return(MagickTrue);
3853 }