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