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