MagickCore  7.0.8
Convert, Edit, Or Compose Bitmap Images
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-2018 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"
99 #include "MagickCore/token.h"
101 #include "MagickCore/utility.h"
103 #include "MagickCore/version.h"
105 
106 /*
107  Constant declaration.
108 */
109 const char
110  BackgroundColor[] = "#ffffff", /* white */
111  BorderColor[] = "#dfdfdf", /* gray */
112  DefaultTileFrame[] = "15x15+3+3",
113  DefaultTileGeometry[] = "120x120+4+3>",
114  DefaultTileLabel[] = "%f\n%G\n%b",
115  ForegroundColor[] = "#000", /* black */
116  LoadImageTag[] = "Load/Image",
117  LoadImagesTag[] = "Load/Images",
118  MatteColor[] = "#bdbdbd", /* gray */
119  PSDensityGeometry[] = "72.0x72.0",
120  PSPageGeometry[] = "612x792",
121  SaveImageTag[] = "Save/Image",
122  SaveImagesTag[] = "Save/Images",
123  TransparentColor[] = "#00000000"; /* transparent black */
124 
125 const double
127 
128 /*
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 % %
131 % %
132 % %
133 % A c q u i r e I m a g e %
134 % %
135 % %
136 % %
137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138 %
139 % AcquireImage() returns a pointer to an image structure initialized to
140 % default values.
141 %
142 % The format of the AcquireImage method is:
143 %
144 % Image *AcquireImage(const ImageInfo *image_info,ExceptionInfo *exception)
145 %
146 % A description of each parameter follows:
147 %
148 % o image_info: Many of the image default values are set from this
149 % structure. For example, filename, compression, depth, background color,
150 % and others.
151 %
152 % o exception: return any errors or warnings in this structure.
153 %
154 */
157 {
158  const char
159  *option;
160 
161  Image
162  *image;
163 
165  flags;
166 
167  /*
168  Allocate image structure.
169  */
170  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
171  image=(Image *) AcquireCriticalMemory(sizeof(*image));
172  (void) memset(image,0,sizeof(*image));
173  /*
174  Initialize Image structure.
175  */
181  image->gamma=1.000f/2.200f;
182  image->chromaticity.red_primary.x=0.6400f;
183  image->chromaticity.red_primary.y=0.3300f;
184  image->chromaticity.red_primary.z=0.0300f;
188  image->chromaticity.blue_primary.x=0.1500f;
189  image->chromaticity.blue_primary.y=0.0600f;
190  image->chromaticity.blue_primary.z=0.7900f;
191  image->chromaticity.white_point.x=0.3127f;
192  image->chromaticity.white_point.y=0.3290f;
193  image->chromaticity.white_point.z=0.3583f;
198  exception);
202  exception);
209  image->blob=CloneBlobInfo((BlobInfo *) NULL);
210  image->timestamp=time((time_t *) NULL);
215  if (image_info == (ImageInfo *) NULL)
216  return(image);
217  /*
218  Transfer image info.
219  */
220  SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
221  MagickFalse);
222  (void) CopyMagickString(image->filename,image_info->filename,
224  (void) CopyMagickString(image->magick_filename,image_info->filename,
226  (void) CopyMagickString(image->magick,image_info->magick,MagickPathExtent);
227  if (image_info->size != (char *) NULL)
228  {
229  (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
233  image->extract_info.x=0;
234  image->extract_info.y=0;
235  }
236  if (image_info->extract != (char *) NULL)
237  {
239  geometry;
240 
241  (void) memset(&geometry,0,sizeof(geometry));
242  flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
243  if (((flags & XValue) != 0) || ((flags & YValue) != 0))
244  {
245  image->extract_info=geometry;
248  }
249  }
250  image->compression=image_info->compression;
251  image->quality=image_info->quality;
252  image->endian=image_info->endian;
253  image->interlace=image_info->interlace;
254  image->units=image_info->units;
255  if (image_info->density != (char *) NULL)
256  {
258  geometry_info;
259 
260  flags=ParseGeometry(image_info->density,&geometry_info);
261  image->resolution.x=geometry_info.rho;
262  image->resolution.y=geometry_info.sigma;
263  if ((flags & SigmaValue) == 0)
265  }
266  if (image_info->page != (char *) NULL)
267  {
268  char
269  *geometry;
270 
272  geometry=GetPageGeometry(image_info->page);
273  (void) ParseAbsoluteGeometry(geometry,&image->page);
274  geometry=DestroyString(geometry);
275  }
276  if (image_info->depth != 0)
277  image->depth=image_info->depth;
278  image->dither=image_info->dither;
279  image->matte_color=image_info->matte_color;
281  image->border_color=image_info->border_color;
283  image->ping=image_info->ping;
285  image->client_data=image_info->client_data;
286  if (image_info->cache != (void *) NULL)
287  ClonePixelCacheMethods(image->cache,image_info->cache);
288  /*
289  Set all global options that map to per-image settings.
290  */
291  (void) SyncImageSettings(image_info,image,exception);
292  /*
293  Global options that are only set for new images.
294  */
295  option=GetImageOption(image_info,"delay");
296  if (option != (const char *) NULL)
297  {
299  geometry_info;
300 
301  flags=ParseGeometry(option,&geometry_info);
302  if ((flags & GreaterValue) != 0)
303  {
304  if (image->delay > (size_t) floor(geometry_info.rho+0.5))
305  image->delay=(size_t) floor(geometry_info.rho+0.5);
306  }
307  else
308  if ((flags & LessValue) != 0)
309  {
310  if (image->delay < (size_t) floor(geometry_info.rho+0.5))
311  image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
312  }
313  else
314  image->delay=(size_t) floor(geometry_info.rho+0.5);
315  if ((flags & SigmaValue) != 0)
316  image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
317  }
318  option=GetImageOption(image_info,"dispose");
319  if (option != (const char *) NULL)
321  MagickFalse,option);
322  return(image);
323 }
324 
325 /*
326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
327 % %
328 % %
329 % %
330 % A c q u i r e I m a g e I n f o %
331 % %
332 % %
333 % %
334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335 %
336 % AcquireImageInfo() allocates the ImageInfo structure.
337 %
338 % The format of the AcquireImageInfo method is:
339 %
340 % ImageInfo *AcquireImageInfo(void)
341 %
342 */
344 {
345  ImageInfo
346  *image_info;
347 
348  image_info=(ImageInfo *) AcquireCriticalMemory(sizeof(*image_info));
349  GetImageInfo(image_info);
350  return(image_info);
351 }
352 
353 /*
354 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
355 % %
356 % %
357 % %
358 % A c q u i r e N e x t I m a g e %
359 % %
360 % %
361 % %
362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363 %
364 % AcquireNextImage() initializes the next image in a sequence to
365 % default values. The next member of image points to the newly allocated
366 % image. If there is a memory shortage, next is assigned NULL.
367 %
368 % The format of the AcquireNextImage method is:
369 %
370 % void AcquireNextImage(const ImageInfo *image_info,Image *image,
371 % ExceptionInfo *exception)
372 %
373 % A description of each parameter follows:
374 %
375 % o image_info: Many of the image default values are set from this
376 % structure. For example, filename, compression, depth, background color,
377 % and others.
378 %
379 % o image: the image.
380 %
381 % o exception: return any errors or warnings in this structure.
382 %
383 */
386 {
387  /*
388  Allocate image structure.
389  */
390  assert(image != (Image *) NULL);
391  assert(image->signature == MagickCoreSignature);
392  if (image->debug != MagickFalse)
394  image->next=AcquireImage(image_info,exception);
395  if (GetNextImageInList(image) == (Image *) NULL)
396  return;
399  if (image_info != (ImageInfo *) NULL)
400  (void) CopyMagickString(GetNextImageInList(image)->filename,
401  image_info->filename,MagickPathExtent);
405  image->next->scene=image->scene+1;
407 }
408 
409 /*
410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411 % %
412 % %
413 % %
414 % A p p e n d I m a g e s %
415 % %
416 % %
417 % %
418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
419 %
420 % AppendImages() takes all images from the current image pointer to the end
421 % of the image list and appends them to each other top-to-bottom if the
422 % stack parameter is true, otherwise left-to-right.
423 %
424 % The current gravity setting effects how the image is justified in the
425 % final image.
426 %
427 % The format of the AppendImages method is:
428 %
429 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
430 % ExceptionInfo *exception)
431 %
432 % A description of each parameter follows:
433 %
434 % o images: the image sequence.
435 %
436 % o stack: A value other than 0 stacks the images top-to-bottom.
437 %
438 % o exception: return any errors or warnings in this structure.
439 %
440 */
443 {
444 #define AppendImageTag "Append/Image"
445 
446  CacheView
447  *append_view;
448 
449  Image
450  *append_image;
451 
453  homogeneous_colorspace,
454  status;
455 
457  n;
458 
459  PixelTrait
460  alpha_trait;
461 
463  geometry;
464 
465  register const Image
466  *next;
467 
468  size_t
469  depth,
470  height,
471  number_images,
472  width;
473 
474  ssize_t
475  x_offset,
476  y,
477  y_offset;
478 
479  /*
480  Compute maximum area of appended area.
481  */
482  assert(images != (Image *) NULL);
483  assert(images->signature == MagickCoreSignature);
484  if (images->debug != MagickFalse)
485  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
486  assert(exception != (ExceptionInfo *) NULL);
488  alpha_trait=images->alpha_trait;
489  number_images=1;
490  width=images->columns;
491  height=images->rows;
492  depth=images->depth;
493  homogeneous_colorspace=MagickTrue;
494  next=GetNextImageInList(images);
495  for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
496  {
497  if (next->depth > depth)
498  depth=next->depth;
499  if (next->colorspace != images->colorspace)
500  homogeneous_colorspace=MagickFalse;
501  if (next->alpha_trait != UndefinedPixelTrait)
502  alpha_trait=BlendPixelTrait;
503  number_images++;
504  if (stack != MagickFalse)
505  {
506  if (next->columns > width)
507  width=next->columns;
508  height+=next->rows;
509  continue;
510  }
511  width+=next->columns;
512  if (next->rows > height)
513  height=next->rows;
514  }
515  /*
516  Append images.
517  */
518  append_image=CloneImage(images,width,height,MagickTrue,exception);
519  if (append_image == (Image *) NULL)
520  return((Image *) NULL);
522  {
523  append_image=DestroyImage(append_image);
524  return((Image *) NULL);
525  }
526  if (homogeneous_colorspace == MagickFalse)
527  (void) SetImageColorspace(append_image,sRGBColorspace,exception);
528  append_image->depth=depth;
529  append_image->alpha_trait=alpha_trait;
530  append_image->page=images->page;
531  (void) SetImageBackgroundColor(append_image,exception);
532  status=MagickTrue;
533  x_offset=0;
534  y_offset=0;
535  next=images;
536  append_view=AcquireAuthenticCacheView(append_image,exception);
537  for (n=0; n < (MagickOffsetType) number_images; n++)
538  {
539  CacheView
540  *image_view;
541 
543  proceed;
544 
545  SetGeometry(append_image,&geometry);
546  GravityAdjustGeometry(next->columns,next->rows,next->gravity,&geometry);
547  if (stack != MagickFalse)
548  x_offset-=geometry.x;
549  else
550  y_offset-=geometry.y;
551  image_view=AcquireVirtualCacheView(next,exception);
552 #if defined(MAGICKCORE_OPENMP_SUPPORT)
553  #pragma omp parallel for schedule(static) shared(status) \
554  magick_number_threads(next,next,next->rows,1)
555 #endif
556  for (y=0; y < (ssize_t) next->rows; y++)
557  {
559  sync;
560 
561  PixelInfo
562  pixel;
563 
564  register const Quantum
565  *magick_restrict p;
566 
567  register Quantum
568  *magick_restrict q;
569 
570  register ssize_t
571  x;
572 
573  if (status == MagickFalse)
574  continue;
575  p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
576  q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
577  next->columns,1,exception);
578  if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
579  {
580  status=MagickFalse;
581  continue;
582  }
583  GetPixelInfo(next,&pixel);
584  for (x=0; x < (ssize_t) next->columns; x++)
585  {
586  GetPixelInfoPixel(next,p,&pixel);
587  SetPixelViaPixelInfo(append_image,&pixel,q);
588  p+=GetPixelChannels(next);
589  q+=GetPixelChannels(append_image);
590  }
591  sync=SyncCacheViewAuthenticPixels(append_view,exception);
592  if (sync == MagickFalse)
593  status=MagickFalse;
594  }
595  image_view=DestroyCacheView(image_view);
596  if (stack == MagickFalse)
597  {
598  x_offset+=(ssize_t) next->columns;
599  y_offset=0;
600  }
601  else
602  {
603  x_offset=0;
604  y_offset+=(ssize_t) next->rows;
605  }
606  proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
607  if (proceed == MagickFalse)
608  break;
609  next=GetNextImageInList(next);
610  }
611  append_view=DestroyCacheView(append_view);
612  if (status == MagickFalse)
613  append_image=DestroyImage(append_image);
614  return(append_image);
615 }
616 
617 /*
618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
619 % %
620 % %
621 % %
622 % C a t c h I m a g e E x c e p t i o n %
623 % %
624 % %
625 % %
626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
627 %
628 % CatchImageException() returns if no exceptions are found in the image
629 % sequence, otherwise it determines the most severe exception and reports
630 % it as a warning or error depending on the severity.
631 %
632 % The format of the CatchImageException method is:
633 %
634 % ExceptionType CatchImageException(Image *image)
635 %
636 % A description of each parameter follows:
637 %
638 % o image: An image sequence.
639 %
640 */
642 {
644  *exception;
645 
647  severity;
648 
649  assert(image != (const Image *) NULL);
650  assert(image->signature == MagickCoreSignature);
651  if (image->debug != MagickFalse)
655  severity=exception->severity;
657  return(severity);
658 }
659 
660 /*
661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
662 % %
663 % %
664 % %
665 % C l i p I m a g e P a t h %
666 % %
667 % %
668 % %
669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
670 %
671 % ClipImagePath() sets the image clip mask based any clipping path information
672 % if it exists.
673 %
674 % The format of the ClipImagePath method is:
675 %
676 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
677 % const MagickBooleanType inside,ExceptionInfo *exception)
678 %
679 % A description of each parameter follows:
680 %
681 % o image: the image.
682 %
683 % o pathname: name of clipping path resource. If name is preceded by #, use
684 % clipping path numbered by name.
685 %
686 % o inside: if non-zero, later operations take effect inside clipping path.
687 % Otherwise later operations take effect outside clipping path.
688 %
689 % o exception: return any errors or warnings in this structure.
690 %
691 */
692 
694 {
695  return(ClipImagePath(image,"#1",MagickTrue,exception));
696 }
697 
700 {
701 #define ClipImagePathTag "ClipPath/Image"
702 
703  char
704  *property;
705 
706  const char
707  *value;
708 
709  Image
710  *clip_mask;
711 
712  ImageInfo
713  *image_info;
714 
715  assert(image != (const Image *) NULL);
716  assert(image->signature == MagickCoreSignature);
717  if (image->debug != MagickFalse)
719  assert(pathname != NULL);
720  property=AcquireString(pathname);
721  (void) FormatLocaleString(property,MagickPathExtent,"8BIM:1999,2998:%s",
722  pathname);
723  value=GetImageProperty(image,property,exception);
724  property=DestroyString(property);
725  if (value == (const char *) NULL)
726  {
727  ThrowFileException(exception,OptionError,"NoClipPathDefined",
728  image->filename);
729  return(MagickFalse);
730  }
731  image_info=AcquireImageInfo();
732  (void) CopyMagickString(image_info->filename,image->filename,
734  (void) ConcatenateMagickString(image_info->filename,pathname,
736  clip_mask=BlobToImage(image_info,value,strlen(value),exception);
737  image_info=DestroyImageInfo(image_info);
738  if (clip_mask == (Image *) NULL)
739  return(MagickFalse);
740  if (clip_mask->storage_class == PseudoClass)
741  {
742  (void) SyncImage(clip_mask,exception);
744  return(MagickFalse);
745  }
746  if (inside == MagickFalse)
747  (void) NegateImage(clip_mask,MagickFalse,exception);
749  "8BIM:1999,2998:%s\nPS",pathname);
750  (void) SetImageMask(image,WritePixelMask,clip_mask,exception);
751  clip_mask=DestroyImage(clip_mask);
752  return(MagickTrue);
753 }
754 
755 /*
756 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
757 % %
758 % %
759 % %
760 % C l o n e I m a g e %
761 % %
762 % %
763 % %
764 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
765 %
766 % CloneImage() copies an image and returns the copy as a new image object.
767 %
768 % If the specified columns and rows is 0, an exact copy of the image is
769 % returned, otherwise the pixel data is undefined and must be initialized
770 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
771 % failure, a NULL image is returned and exception describes the reason for the
772 % failure.
773 %
774 % The format of the CloneImage method is:
775 %
776 % Image *CloneImage(const Image *image,const size_t columns,
777 % const size_t rows,const MagickBooleanType orphan,
778 % ExceptionInfo *exception)
779 %
780 % A description of each parameter follows:
781 %
782 % o image: the image.
783 %
784 % o columns: the number of columns in the cloned image.
785 %
786 % o rows: the number of rows in the cloned image.
787 %
788 % o detach: With a value other than 0, the cloned image is detached from
789 % its parent I/O stream.
790 %
791 % o exception: return any errors or warnings in this structure.
792 %
793 */
794 MagickExport Image *CloneImage(const Image *image,const size_t columns,
795  const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
796 {
797  Image
798  *clone_image;
799 
800  double
801  scale;
802 
803  size_t
804  length;
805 
806  /*
807  Clone the image.
808  */
809  assert(image != (const Image *) NULL);
810  assert(image->signature == MagickCoreSignature);
811  if (image->debug != MagickFalse)
813  assert(exception != (ExceptionInfo *) NULL);
815  if ((image->columns == 0) || (image->rows == 0))
816  {
818  "NegativeOrZeroImageSize","`%s'",image->filename);
819  return((Image *) NULL);
820  }
821  clone_image=(Image *) AcquireCriticalMemory(sizeof(*clone_image));
822  (void) memset(clone_image,0,sizeof(*clone_image));
823  clone_image->signature=MagickCoreSignature;
824  clone_image->storage_class=image->storage_class;
825  clone_image->number_channels=image->number_channels;
828  clone_image->colorspace=image->colorspace;
829  clone_image->alpha_trait=image->alpha_trait;
830  clone_image->channels=image->channels;
831  clone_image->mask_trait=image->mask_trait;
832  clone_image->columns=image->columns;
833  clone_image->rows=image->rows;
834  clone_image->dither=image->dither;
835  clone_image->image_info=CloneImageInfo(image->image_info);
836  (void) CloneImageProfiles(clone_image,image);
837  (void) CloneImageProperties(clone_image,image);
838  (void) CloneImageArtifacts(clone_image,image);
839  GetTimerInfo(&clone_image->timer);
840  if (image->ascii85 != (void *) NULL)
841  Ascii85Initialize(clone_image);
842  clone_image->magick_columns=image->magick_columns;
843  clone_image->magick_rows=image->magick_rows;
844  clone_image->type=image->type;
845  clone_image->channel_mask=image->channel_mask;
849  (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
850  (void) CopyMagickString(clone_image->filename,image->filename,
853  clone_image->client_data=image->client_data;
854  clone_image->reference_count=1;
855  clone_image->next=image->next;
856  clone_image->previous=image->previous;
857  clone_image->list=NewImageList();
858  if (detach == MagickFalse)
859  clone_image->blob=ReferenceBlob(image->blob);
860  else
861  {
862  clone_image->next=NewImageList();
863  clone_image->previous=NewImageList();
864  clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
865  }
866  clone_image->ping=image->ping;
867  clone_image->debug=IsEventLogging();
868  clone_image->semaphore=AcquireSemaphoreInfo();
869  if (image->colormap != (PixelInfo *) NULL)
870  {
871  /*
872  Allocate and copy the image colormap.
873  */
874  clone_image->colors=image->colors;
875  length=(size_t) image->colors;
876  clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length+1,
877  sizeof(*clone_image->colormap));
878  if (clone_image->colormap == (PixelInfo *) NULL)
879  {
880  clone_image=DestroyImage(clone_image);
881  ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
882  }
883  (void) memcpy(clone_image->colormap,image->colormap,length*
884  sizeof(*clone_image->colormap));
885  }
886  if ((columns == 0) || (rows == 0))
887  {
888  if (image->montage != (char *) NULL)
889  (void) CloneString(&clone_image->montage,image->montage);
890  if (image->directory != (char *) NULL)
891  (void) CloneString(&clone_image->directory,image->directory);
892  clone_image->cache=ReferencePixelCache(image->cache);
893  return(clone_image);
894  }
895  scale=1.0;
896  if (image->columns != 0)
897  scale=(double) columns/(double) image->columns;
898  clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
899  clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
900  clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
901  scale=1.0;
902  if (image->rows != 0)
903  scale=(double) rows/(double) image->rows;
904  clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
905  clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
906  clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
907  clone_image->cache=ClonePixelCache(image->cache);
908  if (SetImageExtent(clone_image,columns,rows,exception) == MagickFalse)
909  clone_image=DestroyImage(clone_image);
910  return(clone_image);
911 }
912 
913 /*
914 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
915 % %
916 % %
917 % %
918 % C l o n e I m a g e I n f o %
919 % %
920 % %
921 % %
922 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
923 %
924 % CloneImageInfo() makes a copy of the given image info structure. If
925 % NULL is specified, a new image info structure is created initialized to
926 % default values.
927 %
928 % The format of the CloneImageInfo method is:
929 %
930 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
931 %
932 % A description of each parameter follows:
933 %
934 % o image_info: the image info.
935 %
936 */
938 {
939  ImageInfo
940  *clone_info;
941 
942  clone_info=AcquireImageInfo();
943  if (image_info == (ImageInfo *) NULL)
944  return(clone_info);
945  clone_info->compression=image_info->compression;
946  clone_info->temporary=image_info->temporary;
947  clone_info->adjoin=image_info->adjoin;
948  clone_info->antialias=image_info->antialias;
949  clone_info->scene=image_info->scene;
950  clone_info->number_scenes=image_info->number_scenes;
951  clone_info->depth=image_info->depth;
952  if (image_info->size != (char *) NULL)
953  (void) CloneString(&clone_info->size,image_info->size);
954  if (image_info->extract != (char *) NULL)
955  (void) CloneString(&clone_info->extract,image_info->extract);
956  if (image_info->scenes != (char *) NULL)
957  (void) CloneString(&clone_info->scenes,image_info->scenes);
958  if (image_info->page != (char *) NULL)
959  (void) CloneString(&clone_info->page,image_info->page);
960  clone_info->interlace=image_info->interlace;
961  clone_info->endian=image_info->endian;
962  clone_info->units=image_info->units;
963  clone_info->quality=image_info->quality;
964  if (image_info->sampling_factor != (char *) NULL)
965  (void) CloneString(&clone_info->sampling_factor,
966  image_info->sampling_factor);
967  if (image_info->server_name != (char *) NULL)
968  (void) CloneString(&clone_info->server_name,image_info->server_name);
969  if (image_info->font != (char *) NULL)
970  (void) CloneString(&clone_info->font,image_info->font);
971  if (image_info->texture != (char *) NULL)
972  (void) CloneString(&clone_info->texture,image_info->texture);
973  if (image_info->density != (char *) NULL)
974  (void) CloneString(&clone_info->density,image_info->density);
975  clone_info->pointsize=image_info->pointsize;
976  clone_info->fuzz=image_info->fuzz;
977  clone_info->matte_color=image_info->matte_color;
978  clone_info->background_color=image_info->background_color;
979  clone_info->border_color=image_info->border_color;
980  clone_info->transparent_color=image_info->transparent_color;
981  clone_info->dither=image_info->dither;
982  clone_info->monochrome=image_info->monochrome;
983  clone_info->colorspace=image_info->colorspace;
984  clone_info->type=image_info->type;
985  clone_info->orientation=image_info->orientation;
986  clone_info->ping=image_info->ping;
987  clone_info->verbose=image_info->verbose;
988  clone_info->progress_monitor=image_info->progress_monitor;
989  clone_info->client_data=image_info->client_data;
990  clone_info->cache=image_info->cache;
991  if (image_info->cache != (void *) NULL)
992  clone_info->cache=ReferencePixelCache(image_info->cache);
993  if (image_info->profile != (void *) NULL)
994  clone_info->profile=(void *) CloneStringInfo((StringInfo *)
995  image_info->profile);
996  SetImageInfoFile(clone_info,image_info->file);
997  SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
998  clone_info->stream=image_info->stream;
999  clone_info->custom_stream=image_info->custom_stream;
1000  (void) CopyMagickString(clone_info->magick,image_info->magick,
1002  (void) CopyMagickString(clone_info->unique,image_info->unique,
1004  (void) CopyMagickString(clone_info->filename,image_info->filename,
1006  clone_info->channel=image_info->channel;
1007  (void) CloneImageOptions(clone_info,image_info);
1008  clone_info->debug=IsEventLogging();
1009  clone_info->signature=image_info->signature;
1010  return(clone_info);
1011 }
1012 
1013 /*
1014 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1015 % %
1016 % %
1017 % %
1018 % C o p y I m a g e P i x e l s %
1019 % %
1020 % %
1021 % %
1022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1023 %
1024 % CopyImagePixels() copies pixels from the source image as defined by the
1025 % geometry the destination image at the specified offset.
1026 %
1027 % The format of the CopyImagePixels method is:
1028 %
1029 % MagickBooleanType CopyImagePixels(Image *image,const Image *source_image,
1030 % const RectangleInfo *geometry,const OffsetInfo *offset,
1031 % ExceptionInfo *exception);
1032 %
1033 % A description of each parameter follows:
1034 %
1035 % o image: the destination image.
1036 %
1037 % o source_image: the source image.
1038 %
1039 % o geometry: define the dimensions of the source pixel rectangle.
1040 %
1041 % o offset: define the offset in the destination image.
1042 %
1043 % o exception: return any errors or warnings in this structure.
1044 %
1045 */
1047  const Image *source_image,const RectangleInfo *geometry,
1048  const OffsetInfo *offset,ExceptionInfo *exception)
1049 {
1050 #define CopyImageTag "Copy/Image"
1051 
1052  CacheView
1053  *image_view,
1054  *source_view;
1055 
1057  status;
1058 
1060  progress;
1061 
1062  ssize_t
1063  y;
1064 
1065  assert(image != (Image *) NULL);
1066  if (image->debug != MagickFalse)
1067  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1068  assert(source_image != (Image *) NULL);
1069  assert(geometry != (RectangleInfo *) NULL);
1070  assert(offset != (OffsetInfo *) NULL);
1071  if ((offset->x < 0) || (offset->y < 0) ||
1072  ((ssize_t) (offset->x+geometry->width) > (ssize_t) image->columns) ||
1073  ((ssize_t) (offset->y+geometry->height) > (ssize_t) image->rows))
1074  ThrowBinaryException(OptionError,"GeometryDoesNotContainImage",
1075  image->filename);
1077  return(MagickFalse);
1078  /*
1079  Copy image pixels.
1080  */
1081  status=MagickTrue;
1082  progress=0;
1083  source_view=AcquireVirtualCacheView(source_image,exception);
1085 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1086  #pragma omp parallel for schedule(static) shared(progress,status) \
1087  magick_number_threads(image,source_image,geometry->height,1)
1088 #endif
1089  for (y=0; y < (ssize_t) geometry->height; y++)
1090  {
1092  sync;
1093 
1094  register const Quantum
1095  *magick_restrict p;
1096 
1097  register ssize_t
1098  x;
1099 
1100  register Quantum
1101  *magick_restrict q;
1102 
1103  if (status == MagickFalse)
1104  continue;
1105  p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1106  geometry->width,1,exception);
1107  q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1108  geometry->width,1,exception);
1109  if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1110  {
1111  status=MagickFalse;
1112  continue;
1113  }
1114  for (x=0; x < (ssize_t) geometry->width; x++)
1115  {
1116  register ssize_t
1117  i;
1118 
1119  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1120  {
1122  PixelTrait traits = GetPixelChannelTraits(image,channel);
1123  PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1124  if ((traits == UndefinedPixelTrait) ||
1125  ((traits & UpdatePixelTrait) == 0) ||
1126  (source_traits == UndefinedPixelTrait))
1127  continue;
1128  SetPixelChannel(image,channel,p[i],q);
1129  }
1130  p+=GetPixelChannels(source_image);
1131  q+=GetPixelChannels(image);
1132  }
1133  sync=SyncCacheViewAuthenticPixels(image_view,exception);
1134  if (sync == MagickFalse)
1135  status=MagickFalse;
1137  {
1139  proceed;
1140 
1141 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1142  #pragma omp critical (MagickCore_CopyImage)
1143 #endif
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  register const Quantum
1489  *magick_restrict p;
1490 
1491  register Quantum
1492  *magick_restrict q;
1493 
1494  register 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  int
1653  c;
1654 
1656  canonical;
1657 
1658  register const char
1659  *p;
1660 
1661  ssize_t
1662  field_width,
1663  offset;
1664 
1665  canonical=MagickFalse;
1666  offset=0;
1667  (void) CopyMagickString(filename,format,MagickPathExtent);
1668  for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1669  {
1670  q=(char *) p+1;
1671  if (*q == '%')
1672  {
1673  p=q+1;
1674  continue;
1675  }
1676  field_width=0;
1677  if (*q == '0')
1678  field_width=(ssize_t) strtol(q,&q,10);
1679  switch (*q)
1680  {
1681  case 'd':
1682  case 'o':
1683  case 'x':
1684  {
1685  q++;
1686  c=(*q);
1687  *q='\0';
1688  (void) FormatLocaleString(filename+(p-format-offset),(size_t)
1689  (MagickPathExtent-(p-format-offset)),p,value);
1690  offset+=(4-field_width);
1691  *q=c;
1692  (void) ConcatenateMagickString(filename,q,MagickPathExtent);
1693  canonical=MagickTrue;
1694  if (*(q-1) != '%')
1695  break;
1696  p++;
1697  break;
1698  }
1699  case '[':
1700  {
1701  char
1702  pattern[MagickPathExtent];
1703 
1704  const char
1705  *option;
1706 
1707  register char
1708  *r;
1709 
1710  register ssize_t
1711  i;
1712 
1713  ssize_t
1714  depth;
1715 
1716  /*
1717  Image option.
1718  */
1719  if (strchr(p,']') == (char *) NULL)
1720  break;
1721  depth=1;
1722  r=q+1;
1723  for (i=0; (i < (MagickPathExtent-1L)) && (*r != '\0'); i++)
1724  {
1725  if (*r == '[')
1726  depth++;
1727  if (*r == ']')
1728  depth--;
1729  if (depth <= 0)
1730  break;
1731  pattern[i]=(*r++);
1732  }
1733  pattern[i]='\0';
1734  if (LocaleNCompare(pattern,"filename:",9) != 0)
1735  break;
1736  option=(const char *) NULL;
1737  if (image != (Image *) NULL)
1738  option=GetImageProperty(image,pattern,exception);
1739  if ((option == (const char *) NULL) && (image != (Image *) NULL))
1740  option=GetImageArtifact(image,pattern);
1741  if ((option == (const char *) NULL) &&
1742  (image_info != (ImageInfo *) NULL))
1743  option=GetImageOption(image_info,pattern);
1744  if (option == (const char *) NULL)
1745  break;
1746  q--;
1747  c=(*q);
1748  *q='\0';
1749  (void) CopyMagickString(filename+(p-format-offset),option,(size_t)
1750  (MagickPathExtent-(p-format-offset)));
1751  offset+=strlen(pattern)-4;
1752  *q=c;
1753  (void) ConcatenateMagickString(filename,r+1,MagickPathExtent);
1754  canonical=MagickTrue;
1755  if (*(q-1) != '%')
1756  break;
1757  p++;
1758  break;
1759  }
1760  default:
1761  break;
1762  }
1763  }
1764  for (q=filename; *q != '\0'; q++)
1765  if ((*q == '%') && (*(q+1) == '%'))
1766  {
1767  (void) CopyMagickString(q,q+1,(size_t) (MagickPathExtent-(q-filename)));
1768  canonical=MagickTrue;
1769  }
1770  if (canonical == MagickFalse)
1771  (void) CopyMagickString(filename,format,MagickPathExtent);
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  register const Quantum
1832  *p;
1833 
1834  register 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  register 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  register 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  register 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  register Quantum
2082  *magick_restrict q;
2083 
2084  register 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  register Quantum
2282  *magick_restrict q;
2283 
2284  register 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  register Quantum
2361  *magick_restrict q;
2362 
2363  register 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  SetPixelAlpha(image,alpha,q);
2377  q+=GetPixelChannels(image);
2378  }
2380  status=MagickFalse;
2381  }
2382  image_view=DestroyCacheView(image_view);
2383  return(status);
2384 }
2385 
2386 /*
2387 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2388 % %
2389 % %
2390 % %
2391 % S e t I m a g e B a c k g r o u n d C o l o r %
2392 % %
2393 % %
2394 % %
2395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2396 %
2397 % SetImageBackgroundColor() initializes the image pixels to the image
2398 % background color. The background color is defined by the background_color
2399 % member of the image structure.
2400 %
2401 % The format of the SetImage method is:
2402 %
2403 % MagickBooleanType SetImageBackgroundColor(Image *image,
2404 % ExceptionInfo *exception)
2405 %
2406 % A description of each parameter follows:
2407 %
2408 % o image: the image.
2409 %
2410 % o exception: return any errors or warnings in this structure.
2411 %
2412 */
2415 {
2416  CacheView
2417  *image_view;
2418 
2420  status;
2421 
2422  PixelInfo
2423  background;
2424 
2425  ssize_t
2426  y;
2427 
2428  assert(image != (Image *) NULL);
2429  if (image->debug != MagickFalse)
2430  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2431  assert(image->signature == MagickCoreSignature);
2433  return(MagickFalse);
2438  /*
2439  Set image background color.
2440  */
2441  status=MagickTrue;
2443  for (y=0; y < (ssize_t) image->rows; y++)
2444  {
2445  register Quantum
2446  *magick_restrict q;
2447 
2448  register ssize_t
2449  x;
2450 
2451  if (status == MagickFalse)
2452  continue;
2454  if (q == (Quantum *) NULL)
2455  {
2456  status=MagickFalse;
2457  continue;
2458  }
2459  for (x=0; x < (ssize_t) image->columns; x++)
2460  {
2461  SetPixelViaPixelInfo(image,&background,q);
2462  q+=GetPixelChannels(image);
2463  }
2465  status=MagickFalse;
2466  }
2467  image_view=DestroyCacheView(image_view);
2468  return(status);
2469 }
2470 
2471 /*
2472 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2473 % %
2474 % %
2475 % %
2476 % S e t I m a g e C h a n n e l M a s k %
2477 % %
2478 % %
2479 % %
2480 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2481 %
2482 % SetImageChannelMask() sets the image channel mask from the specified channel
2483 % mask.
2484 %
2485 % The format of the SetImageChannelMask method is:
2486 %
2487 % ChannelType SetImageChannelMask(Image *image,
2488 % const ChannelType channel_mask)
2489 %
2490 % A description of each parameter follows:
2491 %
2492 % o image: the image.
2493 %
2494 % o channel_mask: the channel mask.
2495 %
2496 */
2498  const ChannelType channel_mask)
2499 {
2500  return(SetPixelChannelMask(image,channel_mask));
2501 }
2502 
2503 /*
2504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2505 % %
2506 % %
2507 % %
2508 % S e t I m a g e C o l o r %
2509 % %
2510 % %
2511 % %
2512 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2513 %
2514 % SetImageColor() set the entire image canvas to the specified color.
2515 %
2516 % The format of the SetImageColor method is:
2517 %
2518 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2519 % ExeptionInfo *exception)
2520 %
2521 % A description of each parameter follows:
2522 %
2523 % o image: the image.
2524 %
2525 % o background: the image color.
2526 %
2527 % o exception: return any errors or warnings in this structure.
2528 %
2529 */
2531  const PixelInfo *color,ExceptionInfo *exception)
2532 {
2533  CacheView
2534  *image_view;
2535 
2537  status;
2538 
2539  ssize_t
2540  y;
2541 
2542  assert(image != (Image *) NULL);
2543  if (image->debug != MagickFalse)
2544  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2545  assert(image->signature == MagickCoreSignature);
2546  assert(color != (const PixelInfo *) NULL);
2547  image->colorspace=color->colorspace;
2548  image->alpha_trait=color->alpha_trait;
2549  image->fuzz=color->fuzz;
2550  image->depth=color->depth;
2551  status=MagickTrue;
2553 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2554  #pragma omp parallel for schedule(static) shared(status) \
2555  magick_number_threads(image,image,image->rows,1)
2556 #endif
2557  for (y=0; y < (ssize_t) image->rows; y++)
2558  {
2559  register Quantum
2560  *magick_restrict q;
2561 
2562  register ssize_t
2563  x;
2564 
2565  if (status == MagickFalse)
2566  continue;
2568  if (q == (Quantum *) NULL)
2569  {
2570  status=MagickFalse;
2571  continue;
2572  }
2573  for (x=0; x < (ssize_t) image->columns; x++)
2574  {
2575  SetPixelViaPixelInfo(image,color,q);
2576  q+=GetPixelChannels(image);
2577  }
2579  status=MagickFalse;
2580  }
2581  image_view=DestroyCacheView(image_view);
2582  return(status);
2583 }
2584 
2585 /*
2586 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2587 % %
2588 % %
2589 % %
2590 % S e t I m a g e S t o r a g e C l a s s %
2591 % %
2592 % %
2593 % %
2594 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2595 %
2596 % SetImageStorageClass() sets the image class: DirectClass for true color
2597 % images or PseudoClass for colormapped images.
2598 %
2599 % The format of the SetImageStorageClass method is:
2600 %
2601 % MagickBooleanType SetImageStorageClass(Image *image,
2602 % const ClassType storage_class,ExceptionInfo *exception)
2603 %
2604 % A description of each parameter follows:
2605 %
2606 % o image: the image.
2607 %
2608 % o storage_class: The image class.
2609 %
2610 % o exception: return any errors or warnings in this structure.
2611 %
2612 */
2614  const ClassType storage_class,ExceptionInfo *exception)
2615 {
2616  assert(image != (Image *) NULL);
2617  assert(image->signature == MagickCoreSignature);
2618  if (image->debug != MagickFalse)
2620  assert(exception != (ExceptionInfo *) NULL);
2622  image->storage_class=storage_class;
2624 }
2625 
2626 /*
2627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2628 % %
2629 % %
2630 % %
2631 % S e t I m a g e E x t e n t %
2632 % %
2633 % %
2634 % %
2635 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2636 %
2637 % SetImageExtent() sets the image size (i.e. columns & rows).
2638 %
2639 % The format of the SetImageExtent method is:
2640 %
2641 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2642 % const size_t rows,ExceptionInfo *exception)
2643 %
2644 % A description of each parameter follows:
2645 %
2646 % o image: the image.
2647 %
2648 % o columns: The image width in pixels.
2649 %
2650 % o rows: The image height in pixels.
2651 %
2652 % o exception: return any errors or warnings in this structure.
2653 %
2654 */
2656  const size_t rows,ExceptionInfo *exception)
2657 {
2658  if ((columns == 0) || (rows == 0))
2659  ThrowBinaryException(ImageError,"NegativeOrZeroImageSize",image->filename);
2660  image->columns=columns;
2661  image->rows=rows;
2662  if ((image->depth == 0) || (image->depth > (8*sizeof(MagickSizeType))))
2663  ThrowBinaryException(ImageError,"ImageDepthNotSupported",image->filename);
2665 }
2666 
2667 /*
2668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2669 % %
2670 % %
2671 % %
2672 + S e t I m a g e I n f o %
2673 % %
2674 % %
2675 % %
2676 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2677 %
2678 % SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
2679 % It is set to a type of image format based on the prefix or suffix of the
2680 % filename. For example, 'ps:image' returns PS indicating a Postscript image.
2681 % JPEG is returned for this filename: 'image.jpg'. The filename prefix has
2682 % precendence over the suffix. Use an optional index enclosed in brackets
2683 % after a file name to specify a desired scene of a multi-resolution image
2684 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2685 % indicates success.
2686 %
2687 % The format of the SetImageInfo method is:
2688 %
2689 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2690 % const unsigned int frames,ExceptionInfo *exception)
2691 %
2692 % A description of each parameter follows:
2693 %
2694 % o image_info: the image info.
2695 %
2696 % o frames: the number of images you intend to write.
2697 %
2698 % o exception: return any errors or warnings in this structure.
2699 %
2700 */
2702  const unsigned int frames,ExceptionInfo *exception)
2703 {
2704  char
2705  component[MagickPathExtent],
2706  magic[MagickPathExtent],
2707  *q;
2708 
2709  const MagicInfo
2710  *magic_info;
2711 
2712  const MagickInfo
2713  *magick_info;
2714 
2716  *sans_exception;
2717 
2718  Image
2719  *image;
2720 
2722  status;
2723 
2724  register const char
2725  *p;
2726 
2727  ssize_t
2728  count;
2729 
2730  /*
2731  Look for 'image.format' in filename.
2732  */
2733  assert(image_info != (ImageInfo *) NULL);
2734  assert(image_info->signature == MagickCoreSignature);
2735  if (image_info->debug != MagickFalse)
2737  image_info->filename);
2738  *component='\0';
2739  GetPathComponent(image_info->filename,SubimagePath,component);
2740  if (*component != '\0')
2741  {
2742  /*
2743  Look for scene specification (e.g. img0001.pcd[4]).
2744  */
2745  if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2746  {
2747  if (IsGeometry(component) != MagickFalse)
2748  (void) CloneString(&image_info->extract,component);
2749  }
2750  else
2751  {
2752  size_t
2753  first,
2754  last;
2755 
2756  (void) CloneString(&image_info->scenes,component);
2757  image_info->scene=StringToUnsignedLong(image_info->scenes);
2758  image_info->number_scenes=image_info->scene;
2759  p=image_info->scenes;
2760  for (q=(char *) image_info->scenes; *q != '\0'; p++)
2761  {
2762  while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2763  p++;
2764  first=(size_t) strtol(p,&q,10);
2765  last=first;
2766  while (isspace((int) ((unsigned char) *q)) != 0)
2767  q++;
2768  if (*q == '-')
2769  last=(size_t) strtol(q+1,&q,10);
2770  if (first > last)
2771  Swap(first,last);
2772  if (first < image_info->scene)
2773  image_info->scene=first;
2774  if (last > image_info->number_scenes)
2775  image_info->number_scenes=last;
2776  p=q;
2777  }
2778  image_info->number_scenes-=image_info->scene-1;
2779  }
2780  }
2781  *component='\0';
2782  if (*image_info->magick == '\0')
2783  GetPathComponent(image_info->filename,ExtensionPath,component);
2784 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2785  if (*component != '\0')
2786  if ((LocaleCompare(component,"gz") == 0) ||
2787  (LocaleCompare(component,"Z") == 0) ||
2788  (LocaleCompare(component,"svgz") == 0) ||
2789  (LocaleCompare(component,"wmz") == 0))
2790  {
2791  char
2792  path[MagickPathExtent];
2793 
2794  (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2795  path[strlen(path)-strlen(component)-1]='\0';
2796  GetPathComponent(path,ExtensionPath,component);
2797  }
2798 #endif
2799 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2800  if (*component != '\0')
2801  if (LocaleCompare(component,"bz2") == 0)
2802  {
2803  char
2804  path[MagickPathExtent];
2805 
2806  (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2807  path[strlen(path)-strlen(component)-1]='\0';
2808  GetPathComponent(path,ExtensionPath,component);
2809  }
2810 #endif
2811  image_info->affirm=MagickFalse;
2812  sans_exception=AcquireExceptionInfo();
2813  if ((*component != '\0') && (IsGlob(component) == MagickFalse))
2814  {
2816  format_type;
2817 
2818  register ssize_t
2819  i;
2820 
2821  static const char
2822  *format_type_formats[] =
2823  {
2824  "AUTOTRACE",
2825  "BROWSE",
2826  "DCRAW",
2827  "EDIT",
2828  "LAUNCH",
2829  "MPEG:DECODE",
2830  "MPEG:ENCODE",
2831  "PRINT",
2832  "PS:ALPHA",
2833  "PS:CMYK",
2834  "PS:COLOR",
2835  "PS:GRAY",
2836  "PS:MONO",
2837  "SCAN",
2838  "SHOW",
2839  "WIN",
2840  (char *) NULL
2841  };
2842 
2843  /*
2844  User specified image format.
2845  */
2846  (void) CopyMagickString(magic,component,MagickPathExtent);
2847  LocaleUpper(magic);
2848  /*
2849  Look for explicit image formats.
2850  */
2851  format_type=UndefinedFormatType;
2852  magick_info=GetMagickInfo(magic,sans_exception);
2853  if ((magick_info != (const MagickInfo *) NULL) &&
2854  (magick_info->format_type != UndefinedFormatType))
2855  format_type=magick_info->format_type;
2856  i=0;
2857  while ((format_type == UndefinedFormatType) &&
2858  (format_type_formats[i] != (char *) NULL))
2859  {
2860  if ((*magic == *format_type_formats[i]) &&
2861  (LocaleCompare(magic,format_type_formats[i]) == 0))
2862  format_type=ExplicitFormatType;
2863  i++;
2864  }
2865  if (format_type == UndefinedFormatType)
2866  (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2867  else
2868  if (format_type == ExplicitFormatType)
2869  {
2870  image_info->affirm=MagickTrue;
2871  (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2872  }
2873  if (LocaleCompare(magic,"RGB") == 0)
2874  image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2875  }
2876  /*
2877  Look for explicit 'format:image' in filename.
2878  */
2879  *magic='\0';
2880  GetPathComponent(image_info->filename,MagickPath,magic);
2881  if (*magic == '\0')
2882  {
2883  (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2884  magick_info=GetMagickInfo(magic,sans_exception);
2885  GetPathComponent(image_info->filename,CanonicalPath,component);
2886  (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2887  }
2888  else
2889  {
2890  const DelegateInfo
2891  *delegate_info;
2892 
2893  /*
2894  User specified image format.
2895  */
2896  LocaleUpper(magic);
2897  magick_info=GetMagickInfo(magic,sans_exception);
2898  delegate_info=GetDelegateInfo(magic,"*",sans_exception);
2899  if (delegate_info == (const DelegateInfo *) NULL)
2900  delegate_info=GetDelegateInfo("*",magic,sans_exception);
2901  if (((magick_info != (const MagickInfo *) NULL) ||
2902  (delegate_info != (const DelegateInfo *) NULL)) &&
2903  (IsMagickConflict(magic) == MagickFalse))
2904  {
2905  image_info->affirm=MagickTrue;
2906  (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2907  GetPathComponent(image_info->filename,CanonicalPath,component);
2908  (void) CopyMagickString(image_info->filename,component,
2910  }
2911  }
2912  sans_exception=DestroyExceptionInfo(sans_exception);
2913  if ((magick_info == (const MagickInfo *) NULL) ||
2914  (GetMagickEndianSupport(magick_info) == MagickFalse))
2915  image_info->endian=UndefinedEndian;
2916  if ((image_info->adjoin != MagickFalse) && (frames > 1))
2917  {
2918  /*
2919  Test for multiple image support (e.g. image%02d.png).
2920  */
2921  (void) InterpretImageFilename(image_info,(Image *) NULL,
2922  image_info->filename,(int) image_info->scene,component,exception);
2923  if ((LocaleCompare(component,image_info->filename) != 0) &&
2924  (strchr(component,'%') == (char *) NULL))
2925  image_info->adjoin=MagickFalse;
2926  }
2927  if ((image_info->adjoin != MagickFalse) && (frames > 0))
2928  {
2929  /*
2930  Some image formats do not support multiple frames per file.
2931  */
2932  magick_info=GetMagickInfo(magic,exception);
2933  if (magick_info != (const MagickInfo *) NULL)
2934  if (GetMagickAdjoin(magick_info) == MagickFalse)
2935  image_info->adjoin=MagickFalse;
2936  }
2937  if (image_info->affirm != MagickFalse)
2938  return(MagickTrue);
2939  if (frames == 0)
2940  {
2941  unsigned char
2942  *magick;
2943 
2944  size_t
2945  magick_size;
2946 
2947  /*
2948  Determine the image format from the first few bytes of the file.
2949  */
2950  magick_size=GetMagicPatternExtent(exception);
2951  if (magick_size == 0)
2952  return(MagickFalse);
2953  image=AcquireImage(image_info,exception);
2954  (void) CopyMagickString(image->filename,image_info->filename,
2956  status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2957  if (status == MagickFalse)
2958  {
2960  return(MagickFalse);
2961  }
2962  if ((IsBlobSeekable(image) == MagickFalse) ||
2964  {
2965  /*
2966  Copy image to seekable temporary file.
2967  */
2968  *component='\0';
2969  status=ImageToFile(image,component,exception);
2970  (void) CloseBlob(image);
2971  if (status == MagickFalse)
2972  {
2974  return(MagickFalse);
2975  }
2976  SetImageInfoFile(image_info,(FILE *) NULL);
2977  (void) CopyMagickString(image->filename,component,MagickPathExtent);
2978  status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2979  if (status == MagickFalse)
2980  {
2982  return(MagickFalse);
2983  }
2984  (void) CopyMagickString(image_info->filename,component,
2986  image_info->temporary=MagickTrue;
2987  }
2988  magick=(unsigned char *) AcquireMagickMemory(magick_size);
2989  if (magick == (unsigned char *) NULL)
2990  {
2991  (void) CloseBlob(image);
2993  return(MagickFalse);
2994  }
2995  (void) memset(magick,0,magick_size);
2996  count=ReadBlob(image,magick_size,magick);
2997  (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
2998  (void) CloseBlob(image);
3000  /*
3001  Check magic cache.
3002  */
3003  sans_exception=AcquireExceptionInfo();
3004  magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3005  magick=(unsigned char *) RelinquishMagickMemory(magick);
3006  if ((magic_info != (const MagicInfo *) NULL) &&
3007  (GetMagicName(magic_info) != (char *) NULL))
3008  {
3009  /*
3010  Try to use magick_info that was determined earlier by the extension
3011  */
3012  if ((magick_info != (const MagickInfo *) NULL) &&
3013  (GetMagickUseExtension(magick_info) != MagickFalse) &&
3014  (LocaleCompare(magick_info->module,GetMagicName(
3015  magic_info)) == 0))
3016  (void) CopyMagickString(image_info->magick,magick_info->name,
3018  else
3019  {
3020  (void) CopyMagickString(image_info->magick,GetMagicName(
3021  magic_info),MagickPathExtent);
3022  magick_info=GetMagickInfo(image_info->magick,sans_exception);
3023  }
3024  if ((magick_info == (const MagickInfo *) NULL) ||
3025  (GetMagickEndianSupport(magick_info) == MagickFalse))
3026  image_info->endian=UndefinedEndian;
3027  sans_exception=DestroyExceptionInfo(sans_exception);
3028  return(MagickTrue);
3029  }
3030  magick_info=GetMagickInfo(image_info->magick,sans_exception);
3031  if ((magick_info == (const MagickInfo *) NULL) ||
3032  (GetMagickEndianSupport(magick_info) == MagickFalse))
3033  image_info->endian=UndefinedEndian;
3034  sans_exception=DestroyExceptionInfo(sans_exception);
3035  }
3036  return(MagickTrue);
3037 }
3038 
3039 /*
3040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3041 % %
3042 % %
3043 % %
3044 % S e t I m a g e I n f o B l o b %
3045 % %
3046 % %
3047 % %
3048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3049 %
3050 % SetImageInfoBlob() sets the image info blob member.
3051 %
3052 % The format of the SetImageInfoBlob method is:
3053 %
3054 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3055 % const size_t length)
3056 %
3057 % A description of each parameter follows:
3058 %
3059 % o image_info: the image info.
3060 %
3061 % o blob: the blob.
3062 %
3063 % o length: the blob length.
3064 %
3065 */
3066 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3067  const size_t length)
3068 {
3069  assert(image_info != (ImageInfo *) NULL);
3070  assert(image_info->signature == MagickCoreSignature);
3071  if (image_info->debug != MagickFalse)
3073  image_info->filename);
3074  image_info->blob=(void *) blob;
3075  image_info->length=length;
3076 }
3077 
3078 /*
3079 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3080 % %
3081 % %
3082 % %
3083 % S e t I m a g e I n f o C u s t o m S t r e a m %
3084 % %
3085 % %
3086 % %
3087 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3088 %
3089 % SetImageInfoCustomStream() sets the image info custom stream handlers.
3090 %
3091 % The format of the SetImageInfoCustomStream method is:
3092 %
3093 % void SetImageInfoCustomStream(ImageInfo *image_info,
3094 % CustomStreamInfo *custom_stream)
3095 %
3096 % A description of each parameter follows:
3097 %
3098 % o image_info: the image info.
3099 %
3100 % o custom_stream: your custom stream methods.
3101 %
3102 */
3104  CustomStreamInfo *custom_stream)
3105 {
3106  assert(image_info != (ImageInfo *) NULL);
3107  assert(image_info->signature == MagickCoreSignature);
3108  if (image_info->debug != MagickFalse)
3110  image_info->filename);
3111  image_info->custom_stream=(CustomStreamInfo *) custom_stream;
3112 }
3113 
3114 /*
3115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3116 % %
3117 % %
3118 % %
3119 % S e t I m a g e I n f o F i l e %
3120 % %
3121 % %
3122 % %
3123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3124 %
3125 % SetImageInfoFile() sets the image info file member.
3126 %
3127 % The format of the SetImageInfoFile method is:
3128 %
3129 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3130 %
3131 % A description of each parameter follows:
3132 %
3133 % o image_info: the image info.
3134 %
3135 % o file: the file.
3136 %
3137 */
3138 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3139 {
3140  assert(image_info != (ImageInfo *) NULL);
3141  assert(image_info->signature == MagickCoreSignature);
3142  if (image_info->debug != MagickFalse)
3144  image_info->filename);
3145  image_info->file=file;
3146 }
3147 
3148 /*
3149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3150 % %
3151 % %
3152 % %
3153 % S e t I m a g e M a s k %
3154 % %
3155 % %
3156 % %
3157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3158 %
3159 % SetImageMask() associates a mask with the image. The mask must be the same
3160 % dimensions as the image.
3161 %
3162 % The format of the SetImageMask method is:
3163 %
3164 % MagickBooleanType SetImageMask(Image *image,const PixelMask type,
3165 % const Image *mask,ExceptionInfo *exception)
3166 %
3167 % A description of each parameter follows:
3168 %
3169 % o image: the image.
3170 %
3171 % o type: the mask type, ReadPixelMask or WritePixelMask.
3172 %
3173 % o mask: the image mask.
3174 %
3175 % o exception: return any errors or warnings in this structure.
3176 %
3177 */
3179  const Image *mask,ExceptionInfo *exception)
3180 {
3181  CacheView
3182  *mask_view,
3183  *image_view;
3184 
3186  status;
3187 
3188  ssize_t
3189  y;
3190 
3191  /*
3192  Set image mask.
3193  */
3194  assert(image != (Image *) NULL);
3195  if (image->debug != MagickFalse)
3196  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3197  assert(image->signature == MagickCoreSignature);
3198  if (mask == (const Image *) NULL)
3199  {
3200  switch (type)
3201  {
3202  case ReadPixelMask:
3203  {
3205  break;
3206  }
3207  case WritePixelMask:
3208  {
3210  }
3211  default:
3212  {
3214  break;
3215  }
3216  }
3218  }
3219  switch (type)
3220  {
3221  case ReadPixelMask:
3222  {
3224  break;
3225  }
3226  case WritePixelMask:
3227  {
3229  break;
3230  }
3231  default:
3232  {
3234  break;
3235  }
3236  }
3238  return(MagickFalse);
3239  status=MagickTrue;
3241  mask_view=AcquireVirtualCacheView(mask,exception);
3243 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3244  #pragma omp parallel for schedule(static) shared(status) \
3245  magick_number_threads(mask,image,image->rows,1)
3246 #endif
3247  for (y=0; y < (ssize_t) image->rows; y++)
3248  {
3249  register const Quantum
3250  *magick_restrict p;
3251 
3252  register Quantum
3253  *magick_restrict q;
3254 
3255  register ssize_t
3256  x;
3257 
3258  if (status == MagickFalse)
3259  continue;
3260  p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3261  q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3262  if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3263  {
3264  status=MagickFalse;
3265  continue;
3266  }
3267  for (x=0; x < (ssize_t) image->columns; x++)
3268  {
3270  intensity;
3271 
3272  intensity=0.0;
3273  if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3274  intensity=GetPixelIntensity(mask,p);
3275  switch (type)
3276  {
3277  case ReadPixelMask:
3278  {
3279  SetPixelReadMask(image,ClampToQuantum(intensity),q);
3280  break;
3281  }
3282  case WritePixelMask:
3283  {
3284  SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3285  break;
3286  }
3287  default:
3288  {
3290  break;
3291  }
3292  }
3293  p+=GetPixelChannels(mask);
3294  q+=GetPixelChannels(image);
3295  }
3297  status=MagickFalse;
3298  }
3300  mask_view=DestroyCacheView(mask_view);
3301  image_view=DestroyCacheView(image_view);
3302  return(status);
3303 }
3304 
3305 /*
3306 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3307 % %
3308 % %
3309 % %
3310 % S e t I m a g e R e g i o n M a s k %
3311 % %
3312 % %
3313 % %
3314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3315 %
3316 % SetImageRegionMask() associates a mask with the image as defined by the
3317 % specified region.
3318 %
3319 % The format of the SetImageRegionMask method is:
3320 %
3321 % MagickBooleanType SetImageRegionMask(Image *image,const PixelMask type,
3322 % const RectangleInfo *region,ExceptionInfo *exception)
3323 %
3324 % A description of each parameter follows:
3325 %
3326 % o image: the image.
3327 %
3328 % o type: the mask type, ReadPixelMask or WritePixelMask.
3329 %
3330 % o geometry: the mask region.
3331 %
3332 % o exception: return any errors or warnings in this structure.
3333 %
3334 */
3336  const PixelMask type,const RectangleInfo *region,ExceptionInfo *exception)
3337 {
3338  CacheView
3339  *image_view;
3340 
3342  status;
3343 
3344  ssize_t
3345  y;
3346 
3347  /*
3348  Set image mask as defined by the region.
3349  */
3350  assert(image != (Image *) NULL);
3351  if (image->debug != MagickFalse)
3352  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3353  assert(image->signature == MagickCoreSignature);
3354  if (region == (const RectangleInfo *) NULL)
3355  {
3356  switch (type)
3357  {
3358  case ReadPixelMask:
3359  {
3361  break;
3362  }
3363  case WritePixelMask:
3364  {
3366  break;
3367  }
3368  default:
3369  {
3371  break;
3372  }
3373  }
3375  }
3376  switch (type)
3377  {
3378  case ReadPixelMask:
3379  {
3381  break;
3382  }
3383  case WritePixelMask:
3384  {
3386  break;
3387  }
3388  default:
3389  {
3391  break;
3392  }
3393  }
3395  return(MagickFalse);
3396  status=MagickTrue;
3399 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3400  #pragma omp parallel for schedule(static) shared(status) \
3401  magick_number_threads(image,image,image->rows,1)
3402 #endif
3403  for (y=0; y < (ssize_t) image->rows; y++)
3404  {
3405  register Quantum
3406  *magick_restrict q;
3407 
3408  register ssize_t
3409  x;
3410 
3411  if (status == MagickFalse)
3412  continue;
3413  q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3414  if (q == (Quantum *) NULL)
3415  {
3416  status=MagickFalse;
3417  continue;
3418  }
3419  for (x=0; x < (ssize_t) image->columns; x++)
3420  {
3421  Quantum
3422  pixel;
3423 
3424  pixel=QuantumRange;
3425  if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3426  ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3427  pixel=(Quantum) 0;
3428  switch (type)
3429  {
3430  case ReadPixelMask:
3431  {
3432  SetPixelReadMask(image,pixel,q);
3433  break;
3434  }
3435  case WritePixelMask:
3436  {
3437  SetPixelWriteMask(image,pixel,q);
3438  break;
3439  }
3440  default:
3441  {
3442  SetPixelCompositeMask(image,pixel,q);
3443  break;
3444  }
3445  }
3446  q+=GetPixelChannels(image);
3447  }
3449  status=MagickFalse;
3450  }
3452  image_view=DestroyCacheView(image_view);
3453  return(status);
3454 }
3455 
3456 /*
3457 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3458 % %
3459 % %
3460 % %
3461 % 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 %
3462 % %
3463 % %
3464 % %
3465 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3466 %
3467 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3468 % image and returns the previous setting. A virtual pixel is any pixel access
3469 % that is outside the boundaries of the image cache.
3470 %
3471 % The format of the SetImageVirtualPixelMethod() method is:
3472 %
3473 % VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3474 % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3475 %
3476 % A description of each parameter follows:
3477 %
3478 % o image: the image.
3479 %
3480 % o virtual_pixel_method: choose the type of virtual pixel.
3481 %
3482 % o exception: return any errors or warnings in this structure.
3483 %
3484 */
3486  const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3487 {
3488  assert(image != (const Image *) NULL);
3489  assert(image->signature == MagickCoreSignature);
3490  if (image->debug != MagickFalse)
3492  return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3493 }
3494 
3495 /*
3496 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3497 % %
3498 % %
3499 % %
3500 % S m u s h I m a g e s %
3501 % %
3502 % %
3503 % %
3504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3505 %
3506 % SmushImages() takes all images from the current image pointer to the end
3507 % of the image list and smushes them to each other top-to-bottom if the
3508 % stack parameter is true, otherwise left-to-right.
3509 %
3510 % The current gravity setting now effects how the image is justified in the
3511 % final image.
3512 %
3513 % The format of the SmushImages method is:
3514 %
3515 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3516 % ExceptionInfo *exception)
3517 %
3518 % A description of each parameter follows:
3519 %
3520 % o images: the image sequence.
3521 %
3522 % o stack: A value other than 0 stacks the images top-to-bottom.
3523 %
3524 % o offset: minimum distance in pixels between images.
3525 %
3526 % o exception: return any errors or warnings in this structure.
3527 %
3528 */
3529 
3530 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3531  const ssize_t offset,ExceptionInfo *exception)
3532 {
3533  CacheView
3534  *left_view,
3535  *right_view;
3536 
3537  const Image
3538  *left_image,
3539  *right_image;
3540 
3542  left_geometry,
3543  right_geometry;
3544 
3545  register const Quantum
3546  *p;
3547 
3548  register ssize_t
3549  i,
3550  y;
3551 
3552  size_t
3553  gap;
3554 
3555  ssize_t
3556  x;
3557 
3558  if (images->previous == (Image *) NULL)
3559  return(0);
3560  right_image=images;
3561  SetGeometry(smush_image,&right_geometry);
3562  GravityAdjustGeometry(right_image->columns,right_image->rows,
3563  right_image->gravity,&right_geometry);
3564  left_image=images->previous;
3565  SetGeometry(smush_image,&left_geometry);
3566  GravityAdjustGeometry(left_image->columns,left_image->rows,
3567  left_image->gravity,&left_geometry);
3568  gap=right_image->columns;
3569  left_view=AcquireVirtualCacheView(left_image,exception);
3570  right_view=AcquireVirtualCacheView(right_image,exception);
3571  for (y=0; y < (ssize_t) smush_image->rows; y++)
3572  {
3573  for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3574  {
3575  p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3576  if ((p == (const Quantum *) NULL) ||
3577  (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3578  ((left_image->columns-x-1) >= gap))
3579  break;
3580  }
3581  i=(ssize_t) left_image->columns-x-1;
3582  for (x=0; x < (ssize_t) right_image->columns; x++)
3583  {
3584  p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3585  exception);
3586  if ((p == (const Quantum *) NULL) ||
3587  (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3588  ((x+i) >= (ssize_t) gap))
3589  break;
3590  }
3591  if ((x+i) < (ssize_t) gap)
3592  gap=(size_t) (x+i);
3593  }
3594  right_view=DestroyCacheView(right_view);
3595  left_view=DestroyCacheView(left_view);
3596  if (y < (ssize_t) smush_image->rows)
3597  return(offset);
3598  return((ssize_t) gap-offset);
3599 }
3600 
3601 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3602  const ssize_t offset,ExceptionInfo *exception)
3603 {
3604  CacheView
3605  *bottom_view,
3606  *top_view;
3607 
3608  const Image
3609  *bottom_image,
3610  *top_image;
3611 
3613  bottom_geometry,
3614  top_geometry;
3615 
3616  register const Quantum
3617  *p;
3618 
3619  register ssize_t
3620  i,
3621  x;
3622 
3623  size_t
3624  gap;
3625 
3626  ssize_t
3627  y;
3628 
3629  if (images->previous == (Image *) NULL)
3630  return(0);
3631  bottom_image=images;
3632  SetGeometry(smush_image,&bottom_geometry);
3633  GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3634  bottom_image->gravity,&bottom_geometry);
3635  top_image=images->previous;
3636  SetGeometry(smush_image,&top_geometry);
3637  GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3638  &top_geometry);
3639  gap=bottom_image->rows;
3640  top_view=AcquireVirtualCacheView(top_image,exception);
3641  bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3642  for (x=0; x < (ssize_t) smush_image->columns; x++)
3643  {
3644  for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3645  {
3646  p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3647  if ((p == (const Quantum *) NULL) ||
3648  (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3649  ((top_image->rows-y-1) >= gap))
3650  break;
3651  }
3652  i=(ssize_t) top_image->rows-y-1;
3653  for (y=0; y < (ssize_t) bottom_image->rows; y++)
3654  {
3655  p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3656  exception);
3657  if ((p == (const Quantum *) NULL) ||
3658  (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3659  ((y+i) >= (ssize_t) gap))
3660  break;
3661  }
3662  if ((y+i) < (ssize_t) gap)
3663  gap=(size_t) (y+i);
3664  }
3665  bottom_view=DestroyCacheView(bottom_view);
3666  top_view=DestroyCacheView(top_view);
3667  if (x < (ssize_t) smush_image->columns)
3668  return(offset);
3669  return((ssize_t) gap-offset);
3670 }
3671 
3673  const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3674 {
3675 #define SmushImageTag "Smush/Image"
3676 
3677  const Image
3678  *image;
3679 
3680  Image
3681  *smush_image;
3682 
3684  proceed,
3685  status;
3686 
3688  n;
3689 
3690  PixelTrait
3691  alpha_trait;
3692 
3694  geometry;
3695 
3696  register const Image
3697  *next;
3698 
3699  size_t
3700  height,
3701  number_images,
3702  width;
3703 
3704  ssize_t
3705  x_offset,
3706  y_offset;
3707 
3708  /*
3709  Compute maximum area of smushed area.
3710  */
3711  assert(images != (Image *) NULL);
3712  assert(images->signature == MagickCoreSignature);
3713  if (images->debug != MagickFalse)
3714  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3715  assert(exception != (ExceptionInfo *) NULL);
3717  image=images;
3718  alpha_trait=image->alpha_trait;
3719  number_images=1;
3720  width=image->columns;
3721  height=image->rows;
3722  next=GetNextImageInList(image);
3723  for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3724  {
3725  if (next->alpha_trait != UndefinedPixelTrait)
3726  alpha_trait=BlendPixelTrait;
3727  number_images++;
3728  if (stack != MagickFalse)
3729  {
3730  if (next->columns > width)
3731  width=next->columns;
3732  height+=next->rows;
3733  if (next->previous != (Image *) NULL)
3734  height+=offset;
3735  continue;
3736  }
3737  width+=next->columns;
3738  if (next->previous != (Image *) NULL)
3739  width+=offset;
3740  if (next->rows > height)
3741  height=next->rows;
3742  }
3743  /*
3744  Smush images.
3745  */
3746  smush_image=CloneImage(image,width,height,MagickTrue,exception);
3747  if (smush_image == (Image *) NULL)
3748  return((Image *) NULL);
3750  {
3751  smush_image=DestroyImage(smush_image);
3752  return((Image *) NULL);
3753  }
3754  smush_image->alpha_trait=alpha_trait;
3755  (void) SetImageBackgroundColor(smush_image,exception);
3756  status=MagickTrue;
3757  x_offset=0;
3758  y_offset=0;
3759  for (n=0; n < (MagickOffsetType) number_images; n++)
3760  {
3761  SetGeometry(smush_image,&geometry);
3763  if (stack != MagickFalse)
3764  {
3765  x_offset-=geometry.x;
3766  y_offset-=SmushYGap(smush_image,image,offset,exception);
3767  }
3768  else
3769  {
3770  x_offset-=SmushXGap(smush_image,image,offset,exception);
3771  y_offset-=geometry.y;
3772  }
3773  status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3774  y_offset,exception);
3775  proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3776  if (proceed == MagickFalse)
3777  break;
3778  if (stack == MagickFalse)
3779  {
3780  x_offset+=(ssize_t) image->columns;
3781  y_offset=0;
3782  }
3783  else
3784  {
3785  x_offset=0;
3786  y_offset+=(ssize_t) image->rows;
3787  }
3789  }
3790  if (stack == MagickFalse)
3791  smush_image->columns=(size_t) x_offset;
3792  else
3793  smush_image->rows=(size_t) y_offset;
3794  if (status == MagickFalse)
3795  smush_image=DestroyImage(smush_image);
3796  return(smush_image);
3797 }
3798 
3799 /*
3800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3801 % %
3802 % %
3803 % %
3804 % S t r i p I m a g e %
3805 % %
3806 % %
3807 % %
3808 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3809 %
3810 % StripImage() strips an image of all profiles and comments.
3811 %
3812 % The format of the StripImage method is:
3813 %
3814 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3815 %
3816 % A description of each parameter follows:
3817 %
3818 % o image: the image.
3819 %
3820 % o exception: return any errors or warnings in this structure.
3821 %
3822 */
3824 {
3826  status;
3827 
3828  assert(image != (Image *) NULL);
3829  if (image->debug != MagickFalse)
3830  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3831  (void) exception;
3833  (void) DeleteImageProperty(image,"comment");
3834  (void) DeleteImageProperty(image,"date:create");
3835  (void) DeleteImageProperty(image,"date:modify");
3836  status=SetImageArtifact(image,"png:exclude-chunk",
3837  "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3838  return(status);
3839 }
3840 
3841 /*
3842 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3843 % %
3844 % %
3845 % %
3846 + S y n c I m a g e %
3847 % %
3848 % %
3849 % %
3850 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3851 %
3852 % SyncImage() initializes the red, green, and blue intensities of each pixel
3853 % as defined by the colormap index.
3854 %
3855 % The format of the SyncImage method is:
3856 %
3857 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3858 %
3859 % A description of each parameter follows:
3860 %
3861 % o image: the image.
3862 %
3863 % o exception: return any errors or warnings in this structure.
3864 %
3865 */
3866 
3867 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3868  MagickBooleanType *range_exception)
3869 {
3870  if ((size_t) index < image->colors)
3871  return(index);
3872  *range_exception=MagickTrue;
3873  return((Quantum) 0);
3874 }
3875 
3877 {
3878  CacheView
3879  *image_view;
3880 
3882  range_exception,
3883  status,
3884  taint;
3885 
3886  ssize_t
3887  y;
3888 
3889  assert(image != (Image *) NULL);
3890  if (image->debug != MagickFalse)
3891  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3892  assert(image->signature == MagickCoreSignature);
3893  if (image->ping != MagickFalse)
3894  return(MagickTrue);
3896  return(MagickFalse);
3897  assert(image->colormap != (PixelInfo *) NULL);
3898  range_exception=MagickFalse;
3899  status=MagickTrue;
3900  taint=image->taint;
3902 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3903  #pragma omp parallel for schedule(static) shared(range_exception,status) \
3904  magick_number_threads(image,image,image->rows,1)
3905 #endif
3906  for (y=0; y < (ssize_t) image->rows; y++)
3907  {
3908  Quantum
3909  index;
3910 
3911  register Quantum
3912  *magick_restrict q;
3913 
3914  register ssize_t
3915  x;
3916 
3917  if (status == MagickFalse)
3918  continue;
3919  q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3920  if (q == (Quantum *) NULL)
3921  {
3922  status=MagickFalse;
3923  continue;
3924  }
3925  for (x=0; x < (ssize_t) image->columns; x++)
3926  {
3927  index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3928  SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
3929  q+=GetPixelChannels(image);
3930  }
3932  status=MagickFalse;
3933  }
3934  image_view=DestroyCacheView(image_view);
3935  image->taint=taint;
3936  if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3938  CorruptImageWarning,"InvalidColormapIndex","`%s'",image->filename);
3939  return(status);
3940 }
3941 
3942 /*
3943 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3944 % %
3945 % %
3946 % %
3947 % S y n c I m a g e S e t t i n g s %
3948 % %
3949 % %
3950 % %
3951 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3952 %
3953 % SyncImageSettings() syncs any image_info global options into per-image
3954 % attributes.
3955 %
3956 % Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
3957 % that operations and coders can find such settings. In IMv7 if a desired
3958 % per-image artifact is not set, then it will directly look for a global
3959 % option as a fallback, as such this copy is no longer needed, only the
3960 % link set up.
3961 %
3962 % The format of the SyncImageSettings method is:
3963 %
3964 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3965 % Image *image,ExceptionInfo *exception)
3966 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3967 % Image *image,ExceptionInfo *exception)
3968 %
3969 % A description of each parameter follows:
3970 %
3971 % o image_info: the image info.
3972 %
3973 % o image: the image.
3974 %
3975 % o exception: return any errors or warnings in this structure.
3976 %
3977 */
3978 
3980  Image *images,ExceptionInfo *exception)
3981 {
3982  Image
3983  *image;
3984 
3985  assert(image_info != (const ImageInfo *) NULL);
3986  assert(image_info->signature == MagickCoreSignature);
3987  assert(images != (Image *) NULL);
3988  assert(images->signature == MagickCoreSignature);
3989  if (images->debug != MagickFalse)
3990  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3991  image=images;
3992  for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3993  (void) SyncImageSettings(image_info,image,exception);
3994  (void) DeleteImageOption(image_info,"page");
3995  return(MagickTrue);
3996 }
3997 
4000 {
4001  const char
4002  *option;
4003 
4004  GeometryInfo
4005  geometry_info;
4006 
4008  flags;
4009 
4011  units;
4012 
4013  /*
4014  Sync image options.
4015  */
4016  assert(image_info != (const ImageInfo *) NULL);
4017  assert(image_info->signature == MagickCoreSignature);
4018  assert(image != (Image *) NULL);
4019  assert(image->signature == MagickCoreSignature);
4020  if (image->debug != MagickFalse)
4022  option=GetImageOption(image_info,"background");
4023  if (option != (const char *) NULL)
4025  exception);
4026  option=GetImageOption(image_info,"black-point-compensation");
4027  if (option != (const char *) NULL)
4030  option=GetImageOption(image_info,"blue-primary");
4031  if (option != (const char *) NULL)
4032  {
4033  flags=ParseGeometry(option,&geometry_info);
4034  image->chromaticity.blue_primary.x=geometry_info.rho;
4035  image->chromaticity.blue_primary.y=geometry_info.sigma;
4036  if ((flags & SigmaValue) == 0)
4038  }
4039  option=GetImageOption(image_info,"bordercolor");
4040  if (option != (const char *) NULL)
4042  exception);
4043  /* FUTURE: do not sync compose to per-image compose setting here */
4044  option=GetImageOption(image_info,"compose");
4045  if (option != (const char *) NULL)
4047  MagickFalse,option);
4048  /* -- */
4049  option=GetImageOption(image_info,"compress");
4050  if (option != (const char *) NULL)
4053  option=GetImageOption(image_info,"debug");
4054  if (option != (const char *) NULL)
4056  MagickFalse,option);
4057  option=GetImageOption(image_info,"density");
4058  if (option != (const char *) NULL)
4059  {
4060  flags=ParseGeometry(option,&geometry_info);
4061  image->resolution.x=geometry_info.rho;
4062  image->resolution.y=geometry_info.sigma;
4063  if ((flags & SigmaValue) == 0)
4065  }
4066  option=GetImageOption(image_info,"depth");
4067  if (option != (const char *) NULL)
4068  image->depth=StringToUnsignedLong(option);
4069  option=GetImageOption(image_info,"endian");
4070  if (option != (const char *) NULL)
4072  MagickFalse,option);
4073  option=GetImageOption(image_info,"filter");
4074  if (option != (const char *) NULL)
4076  MagickFalse,option);
4077  option=GetImageOption(image_info,"fuzz");
4078  if (option != (const char *) NULL)
4079  image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
4080  option=GetImageOption(image_info,"gravity");
4081  if (option != (const char *) NULL)
4083  MagickFalse,option);
4084  option=GetImageOption(image_info,"green-primary");
4085  if (option != (const char *) NULL)
4086  {
4087  flags=ParseGeometry(option,&geometry_info);
4088  image->chromaticity.green_primary.x=geometry_info.rho;
4089  image->chromaticity.green_primary.y=geometry_info.sigma;
4090  if ((flags & SigmaValue) == 0)
4092  }
4093  option=GetImageOption(image_info,"intent");
4094  if (option != (const char *) NULL)
4097  option=GetImageOption(image_info,"intensity");
4098  if (option != (const char *) NULL)
4101  option=GetImageOption(image_info,"interlace");
4102  if (option != (const char *) NULL)
4104  MagickFalse,option);
4105  option=GetImageOption(image_info,"interpolate");
4106  if (option != (const char *) NULL)
4109  option=GetImageOption(image_info,"loop");
4110  if (option != (const char *) NULL)
4112  option=GetImageOption(image_info,"mattecolor");
4113  if (option != (const char *) NULL)
4115  exception);
4116  option=GetImageOption(image_info,"orient");
4117  if (option != (const char *) NULL)
4120  option=GetImageOption(image_info,"page");
4121  if (option != (const char *) NULL)
4122  {
4123  char
4124  *geometry;
4125 
4126  geometry=GetPageGeometry(option);
4127  flags=ParseAbsoluteGeometry(geometry,&image->page);
4128  geometry=DestroyString(geometry);
4129  }
4130  option=GetImageOption(image_info,"quality");
4131  if (option != (const char *) NULL)
4133  option=GetImageOption(image_info,"red-primary");
4134  if (option != (const char *) NULL)
4135  {
4136  flags=ParseGeometry(option,&geometry_info);
4137  image->chromaticity.red_primary.x=geometry_info.rho;
4138  image->chromaticity.red_primary.y=geometry_info.sigma;
4139  if ((flags & SigmaValue) == 0)
4141  }
4142  if (image_info->quality != UndefinedCompressionQuality)
4143  image->quality=image_info->quality;
4144  option=GetImageOption(image_info,"scene");
4145  if (option != (const char *) NULL)
4146  image->scene=StringToUnsignedLong(option);
4147  option=GetImageOption(image_info,"taint");
4148  if (option != (const char *) NULL)
4150  MagickFalse,option);
4151  option=GetImageOption(image_info,"tile-offset");
4152  if (option != (const char *) NULL)
4153  {
4154  char
4155  *geometry;
4156 
4157  geometry=GetPageGeometry(option);
4158  flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4159  geometry=DestroyString(geometry);
4160  }
4161  option=GetImageOption(image_info,"transparent-color");
4162  if (option != (const char *) NULL)
4164  exception);
4165  option=GetImageOption(image_info,"type");
4166  if (option != (const char *) NULL)
4168  option);
4169  option=GetImageOption(image_info,"units");
4170  units=image_info->units;
4171  if (option != (const char *) NULL)
4173  MagickFalse,option);
4174  if (units != UndefinedResolution)
4175  {
4176  if (image->units != units)
4177  switch (image->units)
4178  {
4180  {
4181  if (units == PixelsPerCentimeterResolution)
4182  {
4183  image->resolution.x/=2.54;
4184  image->resolution.y/=2.54;
4185  }
4186  break;
4187  }
4189  {
4190  if (units == PixelsPerInchResolution)
4191  {
4192  image->resolution.x=(double) ((size_t) (100.0*2.54*
4193  image->resolution.x+0.5))/100.0;
4194  image->resolution.y=(double) ((size_t) (100.0*2.54*
4195  image->resolution.y+0.5))/100.0;
4196  }
4197  break;
4198  }
4199  default:
4200  break;
4201  }
4202  image->units=units;
4203  }
4204  option=GetImageOption(image_info,"virtual-pixel");
4205  if (option != (const char *) NULL)
4208  exception);
4209  option=GetImageOption(image_info,"white-point");
4210  if (option != (const char *) NULL)
4211  {
4212  flags=ParseGeometry(option,&geometry_info);
4213  image->chromaticity.white_point.x=geometry_info.rho;
4214  image->chromaticity.white_point.y=geometry_info.sigma;
4215  if ((flags & SigmaValue) == 0)
4217  }
4218  /*
4219  Pointer to allow the lookup of pre-image artifact will fallback to a global
4220  option setting/define. This saves a lot of duplication of global options
4221  into per-image artifacts, while ensuring only specifically set per-image
4222  artifacts are preserved when parenthesis ends.
4223  */
4224  if (image->image_info != (ImageInfo *) NULL)
4226  image->image_info=CloneImageInfo(image_info);
4227  return(MagickTrue);
4228 }
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:970
PixelInfo matte_color
Definition: image.h:357
MagickDoubleType MagickRealType
Definition: magick-type.h:120
MagickExport MagickBooleanType NegateImage(Image *image, const MagickBooleanType grayscale, ExceptionInfo *exception)
Definition: enhance.c:3352
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:182
size_t signature
Definition: image.h:488
static MagickBooleanType SetImageProgress(const Image *image, const char *tag, const MagickOffsetType offset, const MagickSizeType extent)
struct _Image * list
Definition: image.h:348
const char DefaultTileGeometry[]
Definition: image.c:113
PixelInfo * colormap
Definition: image.h:179
MagickExport ImageInfo * AcquireImageInfo(void)
Definition: image.c:343
InterlaceType interlace
Definition: image.h:225
MagickExport void DestroyImagePixels(Image *image)
Definition: cache.c:915
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:641
MagickExport MagickBooleanType SyncImage(Image *image, ExceptionInfo *exception)
Definition: image.c:3876
ssize_t ticks_per_second
Definition: image.h:245
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:2225
PixelTrait alpha_trait
Definition: pixel.h:179
MagickExport void UnlockSemaphoreInfo(SemaphoreInfo *semaphore_info)
Definition: semaphore.c:450
MagickExport void Ascii85Initialize(Image *image)
Definition: compress.c:264
double pointsize
Definition: image.h:420
const char LoadImageTag[]
Definition: image.c:116
ssize_t y
Definition: geometry.h:116
static unsigned long StringToUnsignedLong(const char *magick_restrict value)
const char TransparentColor[]
Definition: image.c:123
MagickExport ssize_t ParseCommandOption(const CommandOption option, const MagickBooleanType list, const char *options)
Definition: option.c:2965
const char SaveImageTag[]
Definition: image.c:121
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:110
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
const char ForegroundColor[]
Definition: image.c:115
double rho
Definition: geometry.h:106
MagickExport MagickStatusType ParseAbsoluteGeometry(const char *geometry, RectangleInfo *region_info)
Definition: geometry.c:703
MagickExport const char * GetMagicName(const MagicInfo *magic_info)
Definition: magic.c:604
EndianType endian
Definition: image.h:228
MagickBooleanType taint
Definition: image.h:169
MagickExport size_t ConcatenateMagickString(char *destination, const char *source, const size_t length)
Definition: string.c:426
PixelIntensityMethod
Definition: pixel.h:96
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:3998
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:445
#define OpaqueAlpha
Definition: image.h:25
MagickExport const DelegateInfo * GetDelegateInfo(const char *decode, const char *encode, ExceptionInfo *exception)
Definition: delegate.c:1174
MagickPrivate MagickBooleanType SyncImagePixelCache(Image *, ExceptionInfo *)
Definition: cache.c:5509
InterlaceType
Definition: image.h:64
VirtualPixelMethod
Definition: cache-view.h:27
const char BorderColor[]
Definition: image.c:111
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:4739
char * module
Definition: magick.h:64
double z
Definition: image.h:99
MagickBooleanType antialias
Definition: image.h:384
char * name
Definition: magick.h:64
MagickExport MagickBooleanType SetImageAlpha(Image *image, const Quantum alpha, ExceptionInfo *exception)
Definition: image.c:2335
const char PSDensityGeometry[]
Definition: image.c:119
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:108
MagickExport void DestroyImageProfiles(Image *image)
Definition: profile.c:245
MagickExport ssize_t FormatLocaleString(char *magick_restrict string, const size_t length, const char *magick_restrict format,...)
Definition: locale.c:504
static void SetPixelViaPixelInfo(const Image *magick_restrict image, const PixelInfo *magick_restrict pixel_info, Quantum *magick_restrict pixel)
static void * AcquireCriticalMemory(const size_t size)
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:3066
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:28
MagickExport MagickBooleanType ImageToFile(Image *image, char *filename, ExceptionInfo *exception)
Definition: blob.c:2250
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
MagickRealType alpha
Definition: pixel.h:191
MagickExport const char * GetImageOption(const ImageInfo *image_info, const char *option)
Definition: option.c:2300
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:84
char * montage
Definition: image.h:201
CompressionType compression
Definition: image.h:160
double sigma
Definition: geometry.h:106
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:130
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:306
#define ThrowBinaryException(severity, tag, context)
Definition: log.h:52
ssize_t MagickOffsetType
Definition: magick-type.h:129
MagickExport void GetPixelInfo(const Image *image, PixelInfo *pixel)
Definition: pixel.c:2170
MagickExport void DestroyImageOptions(ImageInfo *image_info)
Definition: option.c:2261
EndianType
Definition: quantum.h:28
char * size
Definition: image.h:390
MagickExport void SetImageInfoFile(ImageInfo *image_info, FILE *file)
Definition: image.c:3138
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
const char SaveImagesTag[]
Definition: image.c:122
StreamHandler stream
Definition: image.h:468
size_t number_meta_channels
Definition: image.h:283
double x
Definition: geometry.h:123
#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:143
MagickExport MagickBooleanType SetImageMask(Image *image, const PixelMask type, const Image *mask, ExceptionInfo *exception)
Definition: image.c:3178
#define UndefinedTicksPerSecond
Definition: image-private.h:35
MagickExport MagickBooleanType IsGeometry(const char *geometry)
Definition: geometry.c:610
MagickExport Image * BlobToImage(const ImageInfo *image_info, const void *blob, const size_t length, ExceptionInfo *exception)
Definition: blob.c:420
const double DefaultResolution
Definition: image.c:126
static ssize_t SmushXGap(const Image *smush_image, const Image *images, const ssize_t offset, ExceptionInfo *exception)
Definition: image.c:3530
MagickExport void GetPathComponent(const char *path, PathType type, char *component)
Definition: utility.c:1213
ChannelType channel
Definition: image.h:449
MagickExport MagickBooleanType SetImageAlphaChannel(Image *image, const AlphaChannelOption alpha_type, ExceptionInfo *exception)
Definition: channel.c:969
MagickBooleanType
Definition: magick-type.h:158
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:932
PrimaryInfo red_primary
Definition: image.h:125
size_t scene
Definition: image.h:240
unsigned int MagickStatusType
Definition: magick-type.h:121
MagickExport char * AcquireString(const char *source)
Definition: string.c:129
ClassType
Definition: magick-type.h:151
ExceptionInfo * exception
Definition: image-view.c:73
const char PSPageGeometry[]
Definition: image.c:120
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 StringInfo * DestroyStringInfo(StringInfo *string_info)
Definition: string.c:850
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:533
char filename[MagickPathExtent]
Definition: image.h:480
MagickExport MagickBooleanType CloneImageProfiles(Image *image, const Image *clone_image)
Definition: profile.c:168
MagickExport int LocaleNCompare(const char *p, const char *q, const size_t length)
Definition: locale.c:1540
CustomStreamInfo * custom_stream
Definition: image.h:491
double y
Definition: geometry.h:123
void * blob
Definition: image.h:474
const char BackgroundColor[]
Definition: image.c:110
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:698
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
MagickExport void DestroyImageProperties(Image *image)
Definition: property.c:323
size_t magick_columns
Definition: image.h:324
#define UndefinedCompressionQuality
Definition: image-private.h:36
size_t MagickSizeType
Definition: magick-type.h:130
#define MagickPathExtent
void * cache
Definition: image.h:294
ResolutionType units
Definition: image.h:407
MagickExport PixelChannelMap * DestroyPixelChannelMap(PixelChannelMap *channel_map)
Definition: pixel.c:350
const char LoadImagesTag[]
Definition: image.c:117
MagickExport MagickBooleanType IsStringTrue(const char *value)
Definition: string.c:1505
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:717
CompressionType compression
Definition: image.h:378
const char DefaultTileLabel[]
Definition: image.c:114
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:384
MagickExport ChannelType SetPixelChannelMask(Image *image, const ChannelType channel_mask)
Definition: pixel.c:6276
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:4979
MagickExport ChannelType SetImageChannelMask(Image *image, const ChannelType channel_mask)
Definition: image.c:2497
MagickBooleanType monochrome
Definition: image.h:432
MagickExport Quantum * QueueCacheViewAuthenticPixels(CacheView *cache_view, const ssize_t x, const ssize_t y, const size_t columns, const size_t rows, ExceptionInfo *exception)
Definition: cache-view.c:977
MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info, const unsigned int frames, ExceptionInfo *exception)
Definition: image.c:2701
MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image, const VirtualPixelMethod virtual_pixel_method, ExceptionInfo *exception)
Definition: image.c:3485
GravityType
Definition: geometry.h:77
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:1064
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition: log.c:1398
MagickExport MagickOffsetType SeekBlob(Image *, const MagickOffsetType, const int)
MagickExport MagickBooleanType SetImageBackgroundColor(Image *image, ExceptionInfo *exception)
Definition: image.c:2413
size_t signature
Definition: image.h:354
size_t columns
Definition: image.h:172
MagickPrivate MagickBooleanType IsGlob(const char *)
Definition: token.c:592
MagickExport const MagickInfo * GetMagickInfo(const char *name, ExceptionInfo *exception)
Definition: magick.c:603
MagickExport Image * SmushImages(const Image *images, const MagickBooleanType stack, const ssize_t offset, ExceptionInfo *exception)
Definition: image.c:3672
MagickExport MagickBooleanType SetImageColor(Image *image, const PixelInfo *color, ExceptionInfo *exception)
Definition: image.c:2530
MagickExport Image * AcquireImage(const ImageInfo *image_info, ExceptionInfo *exception)
Definition: image.c:155
MagickExport MagickBooleanType OpenBlob(const ImageInfo *, Image *, const BlobMode, ExceptionInfo *)
MagickExport MagickBooleanType GetMagickAdjoin(const MagickInfo *magick_info)
Definition: magick.c:343
MagickBooleanType(* MagickProgressMonitor)(const char *, const MagickOffsetType, const MagickSizeType, void *)
Definition: monitor.h:26
ssize_t x
Definition: geometry.h:134
static Quantum PushColormapIndex(Image *image, const Quantum index, MagickBooleanType *range_exception)
Definition: image.c:3867
MagickExport char * GetEnvironmentValue(const char *name)
Definition: string.c:1262
SemaphoreInfo * semaphore
Definition: image.h:340
struct _Image * next
Definition: image.h:348
size_t height
Definition: geometry.h:130
const char DefaultTileFrame[]
Definition: image.c:112
MagickExport MagickBooleanType QueryColorCompliance(const char *name, const ComplianceType compliance, PixelInfo *color, ExceptionInfo *exception)
Definition: color.c:2216
ChannelType
Definition: pixel.h:33
MagickExport MagickBooleanType SetImageStorageClass(Image *image, const ClassType storage_class, ExceptionInfo *exception)
Definition: image.c:2613
MagickExport void CatchException(ExceptionInfo *exception)
Definition: exception.c:196
static void SetPixelWriteMask(const Image *magick_restrict image, const Quantum mask, Quantum *magick_restrict pixel)
MagickExport size_t CopyMagickString(char *destination, const char *source, const size_t length)
Definition: string.c:755
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:568
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:67
MagickExport MagickBooleanType IsBlobSeekable(const Image *image)
Definition: blob.c:2841
MagickExport MagickBooleanType CopyImagePixels(Image *image, const Image *source_image, const RectangleInfo *geometry, const OffsetInfo *offset, ExceptionInfo *exception)
Definition: image.c:1046
char * texture
Definition: image.h:413
MagickExport MagickBooleanType SetImageExtent(Image *image, const size_t columns, const size_t rows, ExceptionInfo *exception)
Definition: image.c:2655
RenderingIntent
Definition: profile.h:30
double y
Definition: image.h:99
size_t quality
Definition: image.h:163
size_t colors
Definition: image.h:172
size_t depth
Definition: pixel.h:185
TimerInfo timer
Definition: image.h:300
MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info, Image *images, ExceptionInfo *exception)
Definition: image.c:3979
static size_t GetPixelChannels(const Image *magick_restrict image)
MagickExport int LocaleCompare(const char *p, const char *q)
Definition: locale.c:1440
static void SetPixelCompositeMask(const Image *magick_restrict image, const Quantum mask, Quantum *magick_restrict pixel)
PixelInfo border_color
Definition: image.h:424
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:28
MagickExport void GetTimerInfo(TimerInfo *time_info)
Definition: timer.c:280
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 Quantum ClampToQuantum(const MagickRealType value)
Definition: quantum.h:84
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:441
MagickExport MagickBooleanType IsTaintImage(const Image *image)
Definition: image.c:1938
MagickExport MagickBooleanType CloneImageOptions(ImageInfo *image_info, const ImageInfo *clone_info)
Definition: option.c:2128
const char MatteColor[]
Definition: image.c:118
MagickBooleanType synchronize
Definition: image.h:458
unsigned short Quantum
Definition: magick-type.h:82
MagickExport MagickBooleanType SetImageColorspace(Image *image, const ColorspaceType colorspace, ExceptionInfo *exception)
Definition: colorspace.c:1134
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:765
MagickExport char * DestroyString(char *string)
Definition: string.c:823
MagickExport void * AcquireMagickMemory(const size_t size)
Definition: memory.c:462
char * geometry
Definition: image.h:201
MagickExport MagickBooleanType DeleteImageProperty(Image *image, const char *property)
Definition: property.c:288
MagickExport const char * GetImageProperty(const Image *image, const char *property, ExceptionInfo *exception)
Definition: property.c:2266
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:2810
MagickExport MagickBooleanType StripImage(Image *image, ExceptionInfo *exception)
Definition: image.c:3823
MagickExport ImageInfo * CloneImageInfo(const ImageInfo *image_info)
Definition: image.c:937
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:853
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:1658
ssize_t x
Definition: geometry.h:116
MagickExport const MagicInfo * GetMagicInfo(const unsigned char *magic, const size_t length, ExceptionInfo *exception)
Definition: magic.c:280
MagickExport void GetImageInfo(ImageInfo *image_info)
Definition: image.c:1341
MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image, ExceptionInfo *exception)
Definition: image.c:1802
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1054
PointInfo resolution
Definition: image.h:209
MagickExport size_t GetMagicPatternExtent(ExceptionInfo *exception)
Definition: magic.c:363
MagickExport MagickBooleanType ClipImage(Image *image, ExceptionInfo *exception)
Definition: image.c:693
ImageType
Definition: image.h:48
MagickExport void GravityAdjustGeometry(const size_t width, const size_t height, const GravityType gravity, RectangleInfo *region)
Definition: geometry.c:531
MagickExport char * CloneString(char **destination, const char *source)
Definition: string.c:286
#define Swap(x, y)
Definition: studio.h:345
MagickExport void SetImageInfoCustomStream(ImageInfo *image_info, CustomStreamInfo *custom_stream)
Definition: image.c:3103
MagickExport BlobInfo * ReferenceBlob(BlobInfo *)
Definition: blob.c:4819
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
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:134
MagickExport CacheView * AcquireAuthenticCacheView(const Image *image, ExceptionInfo *exception)
Definition: cache-view.c:112
MagickExport void DestroyBlob(Image *image)
Definition: blob.c:898
ColorspaceType colorspace
Definition: pixel.h:176
static ssize_t SmushYGap(const Image *smush_image, const Image *images, const ssize_t offset, ExceptionInfo *exception)
Definition: image.c:3601
MagickBooleanType adjoin
Definition: image.h:384
PixelMask
Definition: pixel.h:127
char * page
Definition: image.h:390
MagickBooleanType ping
Definition: image.h:445
PixelTrait
Definition: pixel.h:135
MagickExport MagickBooleanType IsSceneGeometry(const char *geometry, const MagickBooleanType pedantic)
Definition: geometry.c:651
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
MagickExport MagickBooleanType SetImageRegionMask(Image *image, const PixelMask type, const RectangleInfo *region, ExceptionInfo *exception)
Definition: image.c:3335
MagickExport void RelinquishSemaphoreInfo(SemaphoreInfo **semaphore_info)
Definition: semaphore.c:351
MagickSizeType QuantumAny
Definition: magick-type.h:144
void * client_data
Definition: image.h:306
MagickExport void LocaleUpper(char *string)
Definition: locale.c:1598
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:794
MagickExport ssize_t GetImageReferenceCount(Image *image)
Definition: image.c:1562
double gamma
Definition: image.h:186
PixelInfo background_color
Definition: image.h:424
ColorspaceType colorspace
Definition: image.h:157
MagickExport StringInfo * CloneStringInfo(const StringInfo *string_info)
Definition: string.c:338
MagickExport void DisassociateImageStream(Image *image)
Definition: image.c:1310
#define QuantumRange
Definition: magick-type.h:83
MagickBooleanType temporary
Definition: image.h:384
PixelChannelMap * channel_map
Definition: image.h:291
MagickBooleanType debug
Definition: image.h:334
size_t depth
Definition: image.h:396
void * profile
Definition: image.h:455
MagickPrivate Cache AcquirePixelCac