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