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