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