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