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