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-2019 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 atomic
1143 #endif
1144  progress++;
1145  proceed=SetImageProgress(image,CopyImageTag,progress,image->rows);
1146  if (proceed == MagickFalse)
1147  status=MagickFalse;
1148  }
1149  }
1150  source_view=DestroyCacheView(source_view);
1151  image_view=DestroyCacheView(image_view);
1152  return(status);
1153 }
1154 
1155 /*
1156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1157 % %
1158 % %
1159 % %
1160 % D e s t r o y I m a g e %
1161 % %
1162 % %
1163 % %
1164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1165 %
1166 % DestroyImage() dereferences an image, deallocating memory associated with
1167 % the image if the reference count becomes zero.
1168 %
1169 % The format of the DestroyImage method is:
1170 %
1171 % Image *DestroyImage(Image *image)
1172 %
1173 % A description of each parameter follows:
1174 %
1175 % o image: the image.
1176 %
1177 */
1179 {
1181  destroy;
1182 
1183  /*
1184  Dereference image.
1185  */
1186  assert(image != (Image *) NULL);
1187  assert(image->signature == MagickCoreSignature);
1188  if (image->debug != MagickFalse)
1190  destroy=MagickFalse;
1193  if (image->reference_count == 0)
1194  destroy=MagickTrue;
1196  if (destroy == MagickFalse)
1197  return((Image *) NULL);
1198  /*
1199  Destroy image.
1200  */
1203  if (image->montage != (char *) NULL)
1205  if (image->directory != (char *) NULL)
1207  if (image->colormap != (PixelInfo *) NULL)
1209  if (image->geometry != (char *) NULL)
1214  if (image->ascii85 != (Ascii85Info *) NULL)
1216  if (image->image_info != (ImageInfo *) NULL)
1218  DestroyBlob(image);
1219  if (image->semaphore != (SemaphoreInfo *) NULL)
1223  return(image);
1224 }
1225 
1226 /*
1227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1228 % %
1229 % %
1230 % %
1231 % D e s t r o y I m a g e I n f o %
1232 % %
1233 % %
1234 % %
1235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1236 %
1237 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1238 % structure.
1239 %
1240 % The format of the DestroyImageInfo method is:
1241 %
1242 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1243 %
1244 % A description of each parameter follows:
1245 %
1246 % o image_info: the image info.
1247 %
1248 */
1250 {
1251  assert(image_info != (ImageInfo *) NULL);
1252  assert(image_info->signature == MagickCoreSignature);
1253  if (image_info->debug != MagickFalse)
1255  image_info->filename);
1256  if (image_info->size != (char *) NULL)
1257  image_info->size=DestroyString(image_info->size);
1258  if (image_info->extract != (char *) NULL)
1259  image_info->extract=DestroyString(image_info->extract);
1260  if (image_info->scenes != (char *) NULL)
1261  image_info->scenes=DestroyString(image_info->scenes);
1262  if (image_info->page != (char *) NULL)
1263  image_info->page=DestroyString(image_info->page);
1264  if (image_info->sampling_factor != (char *) NULL)
1265  image_info->sampling_factor=DestroyString(
1266  image_info->sampling_factor);
1267  if (image_info->server_name != (char *) NULL)
1268  image_info->server_name=DestroyString(
1269  image_info->server_name);
1270  if (image_info->font != (char *) NULL)
1271  image_info->font=DestroyString(image_info->font);
1272  if (image_info->texture != (char *) NULL)
1273  image_info->texture=DestroyString(image_info->texture);
1274  if (image_info->density != (char *) NULL)
1275  image_info->density=DestroyString(image_info->density);
1276  if (image_info->cache != (void *) NULL)
1277  image_info->cache=DestroyPixelCache(image_info->cache);
1278  if (image_info->profile != (StringInfo *) NULL)
1279  image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1280  image_info->profile);
1281  DestroyImageOptions(image_info);
1282  image_info->signature=(~MagickCoreSignature);
1283  image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1284  return(image_info);
1285 }
1286 
1287 /*
1288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1289 % %
1290 % %
1291 % %
1292 + D i s a s s o c i a t e I m a g e S t r e a m %
1293 % %
1294 % %
1295 % %
1296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1297 %
1298 % DisassociateImageStream() disassociates the image stream. It checks if the
1299 % blob of the specified image is referenced by other images. If the reference
1300 % count is higher then 1 a new blob is assigned to the specified image.
1301 %
1302 % The format of the DisassociateImageStream method is:
1303 %
1304 % void DisassociateImageStream(const Image *image)
1305 %
1306 % A description of each parameter follows:
1307 %
1308 % o image: the image.
1309 %
1310 */
1312 {
1313  assert(image != (Image *) NULL);
1314  assert(image->signature == MagickCoreSignature);
1315  if (image->debug != MagickFalse)
1318 }
1319 
1320 /*
1321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1322 % %
1323 % %
1324 % %
1325 % G e t I m a g e I n f o %
1326 % %
1327 % %
1328 % %
1329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1330 %
1331 % GetImageInfo() initializes image_info to default values.
1332 %
1333 % The format of the GetImageInfo method is:
1334 %
1335 % void GetImageInfo(ImageInfo *image_info)
1336 %
1337 % A description of each parameter follows:
1338 %
1339 % o image_info: the image info.
1340 %
1341 */
1343 {
1344  char
1345  *synchronize;
1346 
1348  *exception;
1349 
1350  /*
1351  File and image dimension members.
1352  */
1353  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1354  assert(image_info != (ImageInfo *) NULL);
1355  (void) memset(image_info,0,sizeof(*image_info));
1356  image_info->adjoin=MagickTrue;
1357  image_info->interlace=NoInterlace;
1358  image_info->channel=DefaultChannels;
1360  image_info->antialias=MagickTrue;
1361  image_info->dither=MagickTrue;
1362  synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1363  if (synchronize != (const char *) NULL)
1364  {
1365  image_info->synchronize=IsStringTrue(synchronize);
1366  synchronize=DestroyString(synchronize);
1367  }
1370  &image_info->background_color,exception);
1372  &image_info->border_color,exception);
1374  exception);
1376  &image_info->transparent_color,exception);
1378  image_info->debug=IsEventLogging();
1379  image_info->signature=MagickCoreSignature;
1380 }
1381 
1382 /*
1383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1384 % %
1385 % %
1386 % %
1387 % G e t I m a g e I n f o F i l e %
1388 % %
1389 % %
1390 % %
1391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1392 %
1393 % GetImageInfoFile() returns the image info file member.
1394 %
1395 % The format of the GetImageInfoFile method is:
1396 %
1397 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1398 %
1399 % A description of each parameter follows:
1400 %
1401 % o image_info: the image info.
1402 %
1403 */
1404 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1405 {
1406  return(image_info->file);
1407 }
1408 
1409 /*
1410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1411 % %
1412 % %
1413 % %
1414 % G e t I m a g e M a s k %
1415 % %
1416 % %
1417 % %
1418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1419 %
1420 % GetImageMask() returns the mask associated with the image.
1421 %
1422 % The format of the GetImageMask method is:
1423 %
1424 % Image *GetImageMask(const Image *image,const PixelMask type,
1425 % ExceptionInfo *exception)
1426 %
1427 % A description of each parameter follows:
1428 %
1429 % o image: the image.
1430 %
1431 % o type: the mask type, ReadPixelMask or WritePixelMask.
1432 %
1433 */
1436 {
1437  CacheView
1438  *mask_view,
1439  *image_view;
1440 
1441  Image
1442  *mask_image;
1443 
1445  status;
1446 
1447  ssize_t
1448  y;
1449 
1450  /*
1451  Get image mask.
1452  */
1453  assert(image != (Image *) NULL);
1454  if (image->debug != MagickFalse)
1455  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1456  assert(image->signature == MagickCoreSignature);
1457  switch (type)
1458  {
1459  case ReadPixelMask:
1460  {
1461  if ((image->channels & ReadMaskChannel) == 0)
1462  return((Image *) NULL);
1463  break;
1464  }
1465  case WritePixelMask:
1466  {
1467  if ((image->channels & WriteMaskChannel) == 0)
1468  return((Image *) NULL);
1469  break;
1470  }
1471  default:
1472  {
1473  if ((image->channels & CompositeMaskChannel) == 0)
1474  return((Image *) NULL);
1475  break;
1476  }
1477  }
1478  mask_image=AcquireImage((ImageInfo *) NULL,exception);
1479  status=SetImageExtent(mask_image,image->columns,image->rows,exception);
1480  if (status == MagickFalse)
1481  return(DestroyImage(mask_image));
1482  status=MagickTrue;
1483  mask_image->alpha_trait=UndefinedPixelTrait;
1484  (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1486  mask_view=AcquireAuthenticCacheView(mask_image,exception);
1487  for (y=0; y < (ssize_t) image->rows; y++)
1488  {
1489  register const Quantum
1490  *magick_restrict p;
1491 
1492  register Quantum
1493  *magick_restrict q;
1494 
1495  register ssize_t
1496  x;
1497 
1498  if (status == MagickFalse)
1499  continue;
1500  p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1501  q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1502  exception);
1503  if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1504  {
1505  status=MagickFalse;
1506  continue;
1507  }
1508  for (x=0; x < (ssize_t) image->columns; x++)
1509  {
1510  switch (type)
1511  {
1512  case ReadPixelMask:
1513  {
1514  SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1515  break;
1516  }
1517  case WritePixelMask:
1518  {
1519  SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1520  break;
1521  }
1522  default:
1523  {
1524  SetPixelGray(mask_image,GetPixelCompositeMask(image,p),q);
1525  break;
1526  }
1527  }
1528  p+=GetPixelChannels(image);
1529  q+=GetPixelChannels(mask_image);
1530  }
1532  status=MagickFalse;
1533  }
1534  mask_view=DestroyCacheView(mask_view);
1535  image_view=DestroyCacheView(image_view);
1536  if (status == MagickFalse)
1537  mask_image=DestroyImage(mask_image);
1538  return(mask_image);
1539 }
1540 
1541 /*
1542 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1543 % %
1544 % %
1545 % %
1546 + G e t I m a g e R e f e r e n c e C o u n t %
1547 % %
1548 % %
1549 % %
1550 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1551 %
1552 % GetImageReferenceCount() returns the image reference count.
1553 %
1554 % The format of the GetReferenceCount method is:
1555 %
1556 % ssize_t GetImageReferenceCount(Image *image)
1557 %
1558 % A description of each parameter follows:
1559 %
1560 % o image: the image.
1561 %
1562 */
1564 {
1565  ssize_t
1566  reference_count;
1567 
1568  assert(image != (Image *) NULL);
1569  assert(image->signature == MagickCoreSignature);
1570  if (image->debug != MagickFalse)
1573  reference_count=image->reference_count;
1575  return(reference_count);
1576 }
1577 
1578 /*
1579 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1580 % %
1581 % %
1582 % %
1583 % 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 %
1584 % %
1585 % %
1586 % %
1587 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1588 %
1589 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1590 % image. A virtual pixel is any pixel access that is outside the boundaries
1591 % of the image cache.
1592 %
1593 % The format of the GetImageVirtualPixelMethod() method is:
1594 %
1595 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1596 %
1597 % A description of each parameter follows:
1598 %
1599 % o image: the image.
1600 %
1601 */
1603 {
1604  assert(image != (Image *) NULL);
1605  assert(image->signature == MagickCoreSignature);
1606  if (image->debug != MagickFalse)
1609 }
1610 
1611 /*
1612 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1613 % %
1614 % %
1615 % %
1616 % I n t e r p r e t I m a g e F i l e n a m e %
1617 % %
1618 % %
1619 % %
1620 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1621 %
1622 % InterpretImageFilename() interprets embedded characters in an image filename.
1623 % The filename length is returned.
1624 %
1625 % The format of the InterpretImageFilename method is:
1626 %
1627 % size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1628 % const char *format,int value,char *filename,ExceptionInfo *exception)
1629 %
1630 % A description of each parameter follows.
1631 %
1632 % o image_info: the image info..
1633 %
1634 % o image: the image.
1635 %
1636 % o format: A filename describing the format to use to write the numeric
1637 % argument. Only the first numeric format identifier is replaced.
1638 %
1639 % o value: Numeric value to substitute into format filename.
1640 %
1641 % o filename: return the formatted filename in this character buffer.
1642 %
1643 % o exception: return any errors or warnings in this structure.
1644 %
1645 */
1647  Image *image,const char *format,int value,char *filename,
1649 {
1650  char
1651  *q;
1652 
1653  int
1654  c;
1655 
1657  canonical;
1658 
1659  register const char
1660  *p;
1661 
1662  ssize_t
1663  field_width,
1664  offset;
1665 
1666  canonical=MagickFalse;
1667  offset=0;
1668  (void) CopyMagickString(filename,format,MagickPathExtent);
1669  for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1670  {
1671  q=(char *) p+1;
1672  if (*q == '%')
1673  {
1674  p=q+1;
1675  continue;
1676  }
1677  field_width=0;
1678  if (*q == '0')
1679  field_width=(ssize_t) strtol(q,&q,10);
1680  switch (*q)
1681  {
1682  case 'd':
1683  case 'o':
1684  case 'x':
1685  {
1686  q++;
1687  c=(*q);
1688  *q='\0';
1689  (void) FormatLocaleString(filename+(p-format-offset),(size_t)
1690  (MagickPathExtent-(p-format-offset)),p,value);
1691  offset+=(4-field_width);
1692  *q=c;
1693  (void) ConcatenateMagickString(filename,q,MagickPathExtent);
1694  canonical=MagickTrue;
1695  if (*(q-1) != '%')
1696  break;
1697  p++;
1698  break;
1699  }
1700  case '[':
1701  {
1702  char
1703  pattern[MagickPathExtent];
1704 
1705  const char
1706  *option;
1707 
1708  register char
1709  *r;
1710 
1711  register ssize_t
1712  i;
1713 
1714  ssize_t
1715  depth;
1716 
1717  /*
1718  Image option.
1719  */
1720  if (strchr(p,']') == (char *) NULL)
1721  break;
1722  depth=1;
1723  r=q+1;
1724  for (i=0; (i < (MagickPathExtent-1L)) && (*r != '\0'); i++)
1725  {
1726  if (*r == '[')
1727  depth++;
1728  if (*r == ']')
1729  depth--;
1730  if (depth <= 0)
1731  break;
1732  pattern[i]=(*r++);
1733  }
1734  pattern[i]='\0';
1735  if (LocaleNCompare(pattern,"filename:",9) != 0)
1736  break;
1737  option=(const char *) NULL;
1738  if (image != (Image *) NULL)
1739  option=GetImageProperty(image,pattern,exception);
1740  if ((option == (const char *) NULL) && (image != (Image *) NULL))
1741  option=GetImageArtifact(image,pattern);
1742  if ((option == (const char *) NULL) &&
1743  (image_info != (ImageInfo *) NULL))
1744  option=GetImageOption(image_info,pattern);
1745  if (option == (const char *) NULL)
1746  break;
1747  q--;
1748  c=(*q);
1749  *q='\0';
1750  (void) CopyMagickString(filename+(p-format-offset),option,(size_t)
1751  (MagickPathExtent-(p-format-offset)));
1752  offset+=strlen(pattern)-4;
1753  *q=c;
1754  (void) ConcatenateMagickString(filename,r+1,MagickPathExtent);
1755  canonical=MagickTrue;
1756  if (*(q-1) != '%')
1757  break;
1758  p++;
1759  break;
1760  }
1761  default:
1762  break;
1763  }
1764  }
1765  for (q=filename; *q != '\0'; q++)
1766  if ((*q == '%') && (*(q+1) == '%'))
1767  {
1768  (void) CopyMagickString(q,q+1,(size_t) (MagickPathExtent-(q-filename)));
1769  canonical=MagickTrue;
1770  }
1771  if (canonical == MagickFalse)
1772  (void) CopyMagickString(filename,format,MagickPathExtent);
1773  return(strlen(filename));
1774 }
1775 
1776 /*
1777 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1778 % %
1779 % %
1780 % %
1781 % I s H i g h D y n a m i c R a n g e I m a g e %
1782 % %
1783 % %
1784 % %
1785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1786 %
1787 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1788 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1789 % 0..65535.
1790 %
1791 % The format of the IsHighDynamicRangeImage method is:
1792 %
1793 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1794 % ExceptionInfo *exception)
1795 %
1796 % A description of each parameter follows:
1797 %
1798 % o image: the image.
1799 %
1800 % o exception: return any errors or warnings in this structure.
1801 %
1802 */
1805 {
1806 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1807  (void) image;
1808  (void) exception;
1809  return(MagickFalse);
1810 #else
1811  CacheView
1812  *image_view;
1813 
1815  status;
1816 
1817  ssize_t
1818  y;
1819 
1820  assert(image != (Image *) NULL);
1821  assert(image->signature == MagickCoreSignature);
1822  if (image->debug != MagickFalse)
1824  status=MagickTrue;
1826 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1827  #pragma omp parallel for schedule(static) shared(status) \
1828  magick_number_threads(image,image,image->rows,1)
1829 #endif
1830  for (y=0; y < (ssize_t) image->rows; y++)
1831  {
1832  register const Quantum
1833  *p;
1834 
1835  register ssize_t
1836  x;
1837 
1838  if (status == MagickFalse)
1839  continue;
1840  p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1841  if (p == (const Quantum *) NULL)
1842  {
1843  status=MagickFalse;
1844  continue;
1845  }
1846  for (x=0; x < (ssize_t) image->columns; x++)
1847  {
1848  register ssize_t
1849  i;
1850 
1851  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1852  {
1853  double
1854  pixel;
1855 
1856  PixelTrait
1857  traits;
1858 
1860  if (traits == UndefinedPixelTrait)
1861  continue;
1862  pixel=(double) p[i];
1863  if ((pixel < 0.0) || (pixel > QuantumRange) ||
1864  (pixel != (double) ((QuantumAny) pixel)))
1865  break;
1866  }
1867  p+=GetPixelChannels(image);
1868  if (i < (ssize_t) GetPixelChannels(image))
1869  status=MagickFalse;
1870  }
1871  if (x < (ssize_t) image->columns)
1872  status=MagickFalse;
1873  }
1874  image_view=DestroyCacheView(image_view);
1875  return(status != MagickFalse ? MagickFalse : MagickTrue);
1876 #endif
1877 }
1878 
1879 /*
1880 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1881 % %
1882 % %
1883 % %
1884 % I s I m a g e O b j e c t %
1885 % %
1886 % %
1887 % %
1888 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1889 %
1890 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1891 % set of image objects.
1892 %
1893 % The format of the IsImageObject method is:
1894 %
1895 % MagickBooleanType IsImageObject(const Image *image)
1896 %
1897 % A description of each parameter follows:
1898 %
1899 % o image: the image.
1900 %
1901 */
1903 {
1904  register const Image
1905  *p;
1906 
1907  assert(image != (Image *) NULL);
1908  if (image->debug != MagickFalse)
1909  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1910  for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1911  if (p->signature != MagickCoreSignature)
1912  return(MagickFalse);
1913  return(MagickTrue);
1914 }
1915 
1916 /*
1917 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1918 % %
1919 % %
1920 % %
1921 % I s T a i n t I m a g e %
1922 % %
1923 % %
1924 % %
1925 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1926 %
1927 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1928 % since it was first constituted.
1929 %
1930 % The format of the IsTaintImage method is:
1931 %
1932 % MagickBooleanType IsTaintImage(const Image *image)
1933 %
1934 % A description of each parameter follows:
1935 %
1936 % o image: the image.
1937 %
1938 */
1940 {
1941  char
1942  magick[MagickPathExtent],
1943  filename[MagickPathExtent];
1944 
1945  register const Image
1946  *p;
1947 
1948  assert(image != (Image *) NULL);
1949  if (image->debug != MagickFalse)
1950  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1951  assert(image->signature == MagickCoreSignature);
1953  (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1954  for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1955  {
1956  if (p->taint != MagickFalse)
1957  return(MagickTrue);
1958  if (LocaleCompare(p->magick,magick) != 0)
1959  return(MagickTrue);
1960  if (LocaleCompare(p->filename,filename) != 0)
1961  return(MagickTrue);
1962  }
1963  return(MagickFalse);
1964 }
1965 
1966 /*
1967 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1968 % %
1969 % %
1970 % %
1971 % M o d i f y I m a g e %
1972 % %
1973 % %
1974 % %
1975 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1976 %
1977 % ModifyImage() ensures that there is only a single reference to the image
1978 % to be modified, updating the provided image pointer to point to a clone of
1979 % the original image if necessary.
1980 %
1981 % The format of the ModifyImage method is:
1982 %
1983 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1984 %
1985 % A description of each parameter follows:
1986 %
1987 % o image: the image.
1988 %
1989 % o exception: return any errors or warnings in this structure.
1990 %
1991 */
1994 {
1995  Image
1996  *clone_image;
1997 
1998  assert(image != (Image **) NULL);
1999  assert(*image != (Image *) NULL);
2000  assert((*image)->signature == MagickCoreSignature);
2001  if ((*image)->debug != MagickFalse)
2002  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
2003  if (GetImageReferenceCount(*image) <= 1)
2004  return(MagickTrue);
2005  clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2006  LockSemaphoreInfo((*image)->semaphore);
2007  (*image)->reference_count--;
2008  UnlockSemaphoreInfo((*image)->semaphore);
2009  *image=clone_image;
2010  return(MagickTrue);
2011 }
2012 
2013 /*
2014 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2015 % %
2016 % %
2017 % %
2018 % N e w M a g i c k I m a g e %
2019 % %
2020 % %
2021 % %
2022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2023 %
2024 % NewMagickImage() creates a blank image canvas of the specified size and
2025 % background color.
2026 %
2027 % The format of the NewMagickImage method is:
2028 %
2029 % Image *NewMagickImage(const ImageInfo *image_info,const size_t width,
2030 % const size_t height,const PixelInfo *background,
2031 % ExceptionInfo *exception)
2032 %
2033 % A description of each parameter follows:
2034 %
2035 % o image: the image.
2036 %
2037 % o width: the image width.
2038 %
2039 % o height: the image height.
2040 %
2041 % o background: the image color.
2042 %
2043 % o exception: return any errors or warnings in this structure.
2044 %
2045 */
2047  const size_t width,const size_t height,const PixelInfo *background,
2049 {
2050  CacheView
2051  *image_view;
2052 
2053  Image
2054  *image;
2055 
2057  status;
2058 
2059  ssize_t
2060  y;
2061 
2062  assert(image_info != (const ImageInfo *) NULL);
2063  if (image_info->debug != MagickFalse)
2064  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2065  assert(image_info->signature == MagickCoreSignature);
2066  assert(background != (const PixelInfo *) NULL);
2067  image=AcquireImage(image_info,exception);
2068  image->columns=width;
2069  image->rows=height;
2070  image->colorspace=background->colorspace;
2071  image->alpha_trait=background->alpha_trait;
2072  image->fuzz=background->fuzz;
2073  image->depth=background->depth;
2074  status=MagickTrue;
2076 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2077  #pragma omp parallel for schedule(static) shared(status) \
2078  magick_number_threads(image,image,image->rows,1)
2079 #endif
2080  for (y=0; y < (ssize_t) image->rows; y++)
2081  {
2082  register Quantum
2083  *magick_restrict q;
2084 
2085  register ssize_t
2086  x;
2087 
2088  if (status == MagickFalse)
2089  continue;
2091  if (q == (Quantum *) NULL)
2092  {
2093  status=MagickFalse;
2094  continue;
2095  }
2096  for (x=0; x < (ssize_t) image->columns; x++)
2097  {
2098  SetPixelViaPixelInfo(image,background,q);
2099  q+=GetPixelChannels(image);
2100  }
2102  status=MagickFalse;
2103  }
2104  image_view=DestroyCacheView(image_view);
2105  if (status == MagickFalse)
2107  return(image);
2108 }
2109 
2110 /*
2111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2112 % %
2113 % %
2114 % %
2115 % R e f e r e n c e I m a g e %
2116 % %
2117 % %
2118 % %
2119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2120 %
2121 % ReferenceImage() increments the reference count associated with an image
2122 % returning a pointer to the image.
2123 %
2124 % The format of the ReferenceImage method is:
2125 %
2126 % Image *ReferenceImage(Image *image)
2127 %
2128 % A description of each parameter follows:
2129 %
2130 % o image: the image.
2131 %
2132 */
2134 {
2135  assert(image != (Image *) NULL);
2136  if (image->debug != MagickFalse)
2137  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2138  assert(image->signature == MagickCoreSignature);
2142  return(image);
2143 }
2144 
2145 /*
2146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2147 % %
2148 % %
2149 % %
2150 % R e s e t I m a g e P a g e %
2151 % %
2152 % %
2153 % %
2154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2155 %
2156 % ResetImagePage() resets the image page canvas and position.
2157 %
2158 % The format of the ResetImagePage method is:
2159 %
2160 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2161 %
2162 % A description of each parameter follows:
2163 %
2164 % o image: the image.
2165 %
2166 % o page: the relative page specification.
2167 %
2168 */
2170 {
2172  flags;
2173 
2175  geometry;
2176 
2177  assert(image != (Image *) NULL);
2178  assert(image->signature == MagickCoreSignature);
2179  if (image->debug != MagickFalse)
2181  flags=ParseAbsoluteGeometry(page,&geometry);
2182  if ((flags & WidthValue) != 0)
2183  {
2184  if ((flags & HeightValue) == 0)
2185  geometry.height=geometry.width;
2186  image->page.width=geometry.width;
2187  image->page.height=geometry.height;
2188  }
2189  if ((flags & AspectValue) != 0)
2190  {
2191  if ((flags & XValue) != 0)
2192  image->page.x+=geometry.x;
2193  if ((flags & YValue) != 0)
2194  image->page.y+=geometry.y;
2195  }
2196  else
2197  {
2198  if ((flags & XValue) != 0)
2199  {
2200  image->page.x=geometry.x;
2201  if ((image->page.width == 0) && (geometry.x > 0))
2202  image->page.width=image->columns+geometry.x;
2203  }
2204  if ((flags & YValue) != 0)
2205  {
2206  image->page.y=geometry.y;
2207  if ((image->page.height == 0) && (geometry.y > 0))
2208  image->page.height=image->rows+geometry.y;
2209  }
2210  }
2211  return(MagickTrue);
2212 }
2213 
2214 /*
2215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2216 % %
2217 % %
2218 % %
2219 % R e s e t I m a g e P i x e l s %
2220 % %
2221 % %
2222 % %
2223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2224 %
2225 % ResetImagePixels() reset the image pixels, that is, all the pixel components
2226 % are zereod.
2227 %
2228 % The format of the SetImage method is:
2229 %
2230 % MagickBooleanType ResetImagePixels(Image *image,
2231 % ExceptionInfo *exception)
2232 %
2233 % A description of each parameter follows:
2234 %
2235 % o image: the image.
2236 %
2237 % o exception: return any errors or warnings in this structure.
2238 %
2239 */
2242 {
2243  CacheView
2244  *image_view;
2245 
2247  status;
2248 
2249  size_t
2250  length;
2251 
2252  ssize_t
2253  y;
2254 
2255  void
2256  *pixels;
2257 
2258  assert(image != (Image *) NULL);
2259  if (image->debug != MagickFalse)
2260  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2261  assert(image->signature == MagickCoreSignature);
2262  pixels=AcquirePixelCachePixels(image,&length,exception);
2263  if (pixels != (void *) NULL)
2264  {
2265  /*
2266  Reset in-core image pixels.
2267  */
2268  (void) memset(pixels,0,length);
2269  return(MagickTrue);
2270  }
2271  /*
2272  Reset image pixels.
2273  */
2274  status=MagickTrue;
2276 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2277  #pragma omp parallel for schedule(static) shared(status) \
2278  magick_number_threads(image,image,image->rows,1)
2279 #endif
2280  for (y=0; y < (ssize_t) image->rows; y++)
2281  {
2282  register Quantum
2283  *magick_restrict q;
2284 
2285  register ssize_t
2286  x;
2287 
2288  if (status == MagickFalse)
2289  continue;
2291  if (q == (Quantum *) NULL)
2292  {
2293  status=MagickFalse;
2294  continue;
2295  }
2296  for (x=0; x < (ssize_t) image->columns; x++)
2297  {
2298  (void) memset(q,0,GetPixelChannels(image)*sizeof(Quantum));
2299  q+=GetPixelChannels(image);
2300  }
2302  status=MagickFalse;
2303  }
2304  image_view=DestroyCacheView(image_view);
2305  return(status);
2306 }
2307 
2308 /*
2309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2310 % %
2311 % %
2312 % %
2313 % S e t I m a g e A l p h a %
2314 % %
2315 % %
2316 % %
2317 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2318 %
2319 % SetImageAlpha() sets the alpha levels of the image.
2320 %
2321 % The format of the SetImageAlpha method is:
2322 %
2323 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
2324 % ExceptionInfo *exception)
2325 %
2326 % A description of each parameter follows:
2327 %
2328 % o image: the image.
2329 %
2330 % o alpha: the level of transparency: 0 is fully transparent and QuantumRange
2331 % is fully opaque.
2332 %
2333 % o exception: return any errors or warnings in this structure.
2334 %
2335 */
2338 {
2339  CacheView
2340  *image_view;
2341 
2343  status;
2344 
2345  ssize_t
2346  y;
2347 
2348  assert(image != (Image *) NULL);
2349  if (image->debug != MagickFalse)
2350  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2351  assert(image->signature == MagickCoreSignature);
2353  status=MagickTrue;
2355 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2356  #pragma omp parallel for schedule(static) shared(status) \
2357  magick_number_threads(image,image,image->rows,1)
2358 #endif
2359  for (y=0; y < (ssize_t) image->rows; y++)
2360  {
2361  register Quantum
2362  *magick_restrict q;
2363 
2364  register ssize_t
2365  x;
2366 
2367  if (status == MagickFalse)
2368  continue;
2369  q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2370  if (q == (Quantum *) NULL)
2371  {
2372  status=MagickFalse;
2373  continue;
2374  }
2375  for (x=0; x < (ssize_t) image->columns; x++)
2376  {
2377  SetPixelAlpha(image,alpha,q);
2378  q+=GetPixelChannels(image);
2379  }
2381  status=MagickFalse;
2382  }
2383  image_view=DestroyCacheView(image_view);
2384  return(status);
2385 }
2386 
2387 /*
2388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2389 % %
2390 % %
2391 % %
2392 % S e t I m a g e B a c k g r o u n d C o l o r %
2393 % %
2394 % %
2395 % %
2396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2397 %
2398 % SetImageBackgroundColor() initializes the image pixels to the image
2399 % background color. The background color is defined by the background_color
2400 % member of the image structure.
2401 %
2402 % The format of the SetImage method is:
2403 %
2404 % MagickBooleanType SetImageBackgroundColor(Image *image,
2405 % ExceptionInfo *exception)
2406 %
2407 % A description of each parameter follows:
2408 %
2409 % o image: the image.
2410 %
2411 % o exception: return any errors or warnings in this structure.
2412 %
2413 */
2416 {
2417  CacheView
2418  *image_view;
2419 
2421  status;
2422 
2423  PixelInfo
2424  background;
2425 
2426  ssize_t
2427  y;
2428 
2429  assert(image != (Image *) NULL);
2430  if (image->debug != MagickFalse)
2431  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2432  assert(image->signature == MagickCoreSignature);
2434  return(MagickFalse);
2439  /*
2440  Set image background color.
2441  */
2442  status=MagickTrue;
2444  for (y=0; y < (ssize_t) image->rows; y++)
2445  {
2446  register Quantum
2447  *magick_restrict q;
2448 
2449  register ssize_t
2450  x;
2451 
2452  if (status == MagickFalse)
2453  continue;
2455  if (q == (Quantum *) NULL)
2456  {
2457  status=MagickFalse;
2458  continue;
2459  }
2460  for (x=0; x < (ssize_t) image->columns; x++)
2461  {
2462  SetPixelViaPixelInfo(image,&background,q);
2463  q+=GetPixelChannels(image);
2464  }
2466  status=MagickFalse;
2467  }
2468  image_view=DestroyCacheView(image_view);
2469  return(status);
2470 }
2471 
2472 /*
2473 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2474 % %
2475 % %
2476 % %
2477 % S e t I m a g e C h a n n e l M a s k %
2478 % %
2479 % %
2480 % %
2481 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2482 %
2483 % SetImageChannelMask() sets the image channel mask from the specified channel
2484 % mask.
2485 %
2486 % The format of the SetImageChannelMask method is:
2487 %
2488 % ChannelType SetImageChannelMask(Image *image,
2489 % const ChannelType channel_mask)
2490 %
2491 % A description of each parameter follows:
2492 %
2493 % o image: the image.
2494 %
2495 % o channel_mask: the channel mask.
2496 %
2497 */
2499  const ChannelType channel_mask)
2500 {
2501  return(SetPixelChannelMask(image,channel_mask));
2502 }
2503 
2504 /*
2505 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2506 % %
2507 % %
2508 % %
2509 % S e t I m a g e C o l o r %
2510 % %
2511 % %
2512 % %
2513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2514 %
2515 % SetImageColor() set the entire image canvas to the specified color.
2516 %
2517 % The format of the SetImageColor method is:
2518 %
2519 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2520 % ExeptionInfo *exception)
2521 %
2522 % A description of each parameter follows:
2523 %
2524 % o image: the image.
2525 %
2526 % o background: the image color.
2527 %
2528 % o exception: return any errors or warnings in this structure.
2529 %
2530 */
2532  const PixelInfo *color,ExceptionInfo *exception)
2533 {
2534  CacheView
2535  *image_view;
2536 
2538  status;
2539 
2540  ssize_t
2541  y;
2542 
2543  assert(image != (Image *) NULL);
2544  if (image->debug != MagickFalse)
2545  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2546  assert(image->signature == MagickCoreSignature);
2547  assert(color != (const PixelInfo *) NULL);
2548  image->colorspace=color->colorspace;
2549  image->alpha_trait=color->alpha_trait;
2550  image->fuzz=color->fuzz;
2551  image->depth=color->depth;
2552  status=MagickTrue;
2554 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2555  #pragma omp parallel for schedule(static) shared(status) \
2556  magick_number_threads(image,image,image->rows,1)
2557 #endif
2558  for (y=0; y < (ssize_t) image->rows; y++)
2559  {
2560  register Quantum
2561  *magick_restrict q;
2562 
2563  register ssize_t
2564  x;
2565 
2566  if (status == MagickFalse)
2567  continue;
2569  if (q == (Quantum *) NULL)
2570  {
2571  status=MagickFalse;
2572  continue;
2573  }
2574  for (x=0; x < (ssize_t) image->columns; x++)
2575  {
2576  SetPixelViaPixelInfo(image,color,q);
2577  q+=GetPixelChannels(image);
2578  }
2580  status=MagickFalse;
2581  }
2582  image_view=DestroyCacheView(image_view);
2583  return(status);
2584 }
2585 
2586 /*
2587 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2588 % %
2589 % %
2590 % %
2591 % S e t I m a g e S t o r a g e C l a s s %
2592 % %
2593 % %
2594 % %
2595 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2596 %
2597 % SetImageStorageClass() sets the image class: DirectClass for true color
2598 % images or PseudoClass for colormapped images.
2599 %
2600 % The format of the SetImageStorageClass method is:
2601 %
2602 % MagickBooleanType SetImageStorageClass(Image *image,
2603 % const ClassType storage_class,ExceptionInfo *exception)
2604 %
2605 % A description of each parameter follows:
2606 %
2607 % o image: the image.
2608 %
2609 % o storage_class: The image class.
2610 %
2611 % o exception: return any errors or warnings in this structure.
2612 %
2613 */
2615  const ClassType storage_class,ExceptionInfo *exception)
2616 {
2617  assert(image != (Image *) NULL);
2618  assert(image->signature == MagickCoreSignature);
2619  if (image->debug != MagickFalse)
2621  assert(exception != (ExceptionInfo *) NULL);
2623  image->storage_class=storage_class;
2625 }
2626 
2627 /*
2628 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2629 % %
2630 % %
2631 % %
2632 % S e t I m a g e E x t e n t %
2633 % %
2634 % %
2635 % %
2636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2637 %
2638 % SetImageExtent() sets the image size (i.e. columns & rows).
2639 %
2640 % The format of the SetImageExtent method is:
2641 %
2642 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2643 % const size_t rows,ExceptionInfo *exception)
2644 %
2645 % A description of each parameter follows:
2646 %
2647 % o image: the image.
2648 %
2649 % o columns: The image width in pixels.
2650 %
2651 % o rows: The image height in pixels.
2652 %
2653 % o exception: return any errors or warnings in this structure.
2654 %
2655 */
2657  const size_t rows,ExceptionInfo *exception)
2658 {
2659  if ((columns == 0) || (rows == 0))
2660  ThrowBinaryException(ImageError,"NegativeOrZeroImageSize",image->filename);
2661  image->columns=columns;
2662  image->rows=rows;
2663  if ((image->depth == 0) || (image->depth > (8*sizeof(MagickSizeType))))
2664  ThrowBinaryException(ImageError,"ImageDepthNotSupported",image->filename);
2666 }
2667 
2668 /*
2669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2670 % %
2671 % %
2672 % %
2673 + S e t I m a g e I n f o %
2674 % %
2675 % %
2676 % %
2677 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2678 %
2679 % SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
2680 % It is set to a type of image format based on the prefix or suffix of the
2681 % filename. For example, 'ps:image' returns PS indicating a Postscript image.
2682 % JPEG is returned for this filename: 'image.jpg'. The filename prefix has
2683 % precendence over the suffix. Use an optional index enclosed in brackets
2684 % after a file name to specify a desired scene of a multi-resolution image
2685 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2686 % indicates success.
2687 %
2688 % The format of the SetImageInfo method is:
2689 %
2690 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2691 % const unsigned int frames,ExceptionInfo *exception)
2692 %
2693 % A description of each parameter follows:
2694 %
2695 % o image_info: the image info.
2696 %
2697 % o frames: the number of images you intend to write.
2698 %
2699 % o exception: return any errors or warnings in this structure.
2700 %
2701 */
2703  const unsigned int frames,ExceptionInfo *exception)
2704 {
2705  char
2706  component[MagickPathExtent],
2707  magic[MagickPathExtent],
2708  *q;
2709 
2710  const MagicInfo
2711  *magic_info;
2712 
2713  const MagickInfo
2714  *magick_info;
2715 
2717  *sans_exception;
2718 
2719  Image
2720  *image;
2721 
2723  status;
2724 
2725  register const char
2726  *p;
2727 
2728  ssize_t
2729  count;
2730 
2731  /*
2732  Look for 'image.format' in filename.
2733  */
2734  assert(image_info != (ImageInfo *) NULL);
2735  assert(image_info->signature == MagickCoreSignature);
2736  if (image_info->debug != MagickFalse)
2738  image_info->filename);
2739  *component='\0';
2740  GetPathComponent(image_info->filename,SubimagePath,component);
2741  if (*component != '\0')
2742  {
2743  /*
2744  Look for scene specification (e.g. img0001.pcd[4]).
2745  */
2746  if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2747  {
2748  if (IsGeometry(component) != MagickFalse)
2749  (void) CloneString(&image_info->extract,component);
2750  }
2751  else
2752  {
2753  size_t
2754  first,
2755  last;
2756 
2757  (void) CloneString(&image_info->scenes,component);
2758  image_info->scene=StringToUnsignedLong(image_info->scenes);
2759  image_info->number_scenes=image_info->scene;
2760  p=image_info->scenes;
2761  for (q=(char *) image_info->scenes; *q != '\0'; p++)
2762  {
2763  while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2764  p++;
2765  first=(size_t) strtol(p,&q,10);
2766  last=first;
2767  while (isspace((int) ((unsigned char) *q)) != 0)
2768  q++;
2769  if (*q == '-')
2770  last=(size_t) strtol(q+1,&q,10);
2771  if (first > last)
2772  Swap(first,last);
2773  if (first < image_info->scene)
2774  image_info->scene=first;
2775  if (last > image_info->number_scenes)
2776  image_info->number_scenes=last;
2777  p=q;
2778  }
2779  image_info->number_scenes-=image_info->scene-1;
2780  }
2781  }
2782  *component='\0';
2783  if (*image_info->magick == '\0')
2784  GetPathComponent(image_info->filename,ExtensionPath,component);
2785 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2786  if (*component != '\0')
2787  if ((LocaleCompare(component,"gz") == 0) ||
2788  (LocaleCompare(component,"Z") == 0) ||
2789  (LocaleCompare(component,"svgz") == 0) ||
2790  (LocaleCompare(component,"wmz") == 0))
2791  {
2792  char
2793  path[MagickPathExtent];
2794 
2795  (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2796  path[strlen(path)-strlen(component)-1]='\0';
2797  GetPathComponent(path,ExtensionPath,component);
2798  }
2799 #endif
2800 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2801  if (*component != '\0')
2802  if (LocaleCompare(component,"bz2") == 0)
2803  {
2804  char
2805  path[MagickPathExtent];
2806 
2807  (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2808  path[strlen(path)-strlen(component)-1]='\0';
2809  GetPathComponent(path,ExtensionPath,component);
2810  }
2811 #endif
2812  image_info->affirm=MagickFalse;
2813  sans_exception=AcquireExceptionInfo();
2814  if ((*component != '\0') && (IsGlob(component) == MagickFalse))
2815  {
2817  format_type;
2818 
2819  register ssize_t
2820  i;
2821 
2822  static const char
2823  *format_type_formats[] =
2824  {
2825  "AUTOTRACE",
2826  "BROWSE",
2827  "DCRAW",
2828  "EDIT",
2829  "LAUNCH",
2830  "MPEG:DECODE",
2831  "MPEG:ENCODE",
2832  "PRINT",
2833  "PS:ALPHA",
2834  "PS:CMYK",
2835  "PS:COLOR",
2836  "PS:GRAY",
2837  "PS:MONO",
2838  "SCAN",
2839  "SHOW",
2840  "WIN",
2841  (char *) NULL
2842  };
2843 
2844  /*
2845  User specified image format.
2846  */
2847  (void) CopyMagickString(magic,component,MagickPathExtent);
2848  LocaleUpper(magic);
2849  /*
2850  Look for explicit image formats.
2851  */
2852  format_type=UndefinedFormatType;
2853  magick_info=GetMagickInfo(magic,sans_exception);
2854  if ((magick_info != (const MagickInfo *) NULL) &&
2855  (magick_info->format_type != UndefinedFormatType))
2856  format_type=magick_info->format_type;
2857  i=0;
2858  while ((format_type == UndefinedFormatType) &&
2859  (format_type_formats[i] != (char *) NULL))
2860  {
2861  if ((*magic == *format_type_formats[i]) &&
2862  (LocaleCompare(magic,format_type_formats[i]) == 0))
2863  format_type=ExplicitFormatType;
2864  i++;
2865  }
2866  if (format_type == UndefinedFormatType)
2867  (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2868  else
2869  if (format_type == ExplicitFormatType)
2870  {
2871  image_info->affirm=MagickTrue;
2872  (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2873  }
2874  if (LocaleCompare(magic,"RGB") == 0)
2875  image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2876  }
2877  /*
2878  Look for explicit 'format:image' in filename.
2879  */
2880  *magic='\0';
2881  GetPathComponent(image_info->filename,MagickPath,magic);
2882  if (*magic == '\0')
2883  {
2884  (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2885  magick_info=GetMagickInfo(magic,sans_exception);
2886  if (frames == 0)
2887  GetPathComponent(image_info->filename,CanonicalPath,component);
2888  else
2889  GetPathComponent(image_info->filename,SubcanonicalPath,component);
2890  (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2891  }
2892  else
2893  {
2894  const DelegateInfo
2895  *delegate_info;
2896 
2897  /*
2898  User specified image format.
2899  */
2900  LocaleUpper(magic);
2901  magick_info=GetMagickInfo(magic,sans_exception);
2902  delegate_info=GetDelegateInfo(magic,"*",sans_exception);
2903  if (delegate_info == (const DelegateInfo *) NULL)
2904  delegate_info=GetDelegateInfo("*",magic,sans_exception);
2905  if (((magick_info != (const MagickInfo *) NULL) ||
2906  (delegate_info != (const DelegateInfo *) NULL)) &&
2907  (IsMagickConflict(magic) == MagickFalse))
2908  {
2909  image_info->affirm=MagickTrue;
2910  (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2911  GetPathComponent(image_info->filename,CanonicalPath,component);
2912  (void) CopyMagickString(image_info->filename,component,
2914  }
2915  }
2916  sans_exception=DestroyExceptionInfo(sans_exception);
2917  if ((magick_info == (const MagickInfo *) NULL) ||
2918  (GetMagickEndianSupport(magick_info) == MagickFalse))
2919  image_info->endian=UndefinedEndian;
2920  if ((image_info->adjoin != MagickFalse) && (frames > 1))
2921  {
2922  /*
2923  Test for multiple image support (e.g. image%02d.png).
2924  */
2925  (void) InterpretImageFilename(image_info,(Image *) NULL,
2926  image_info->filename,(int) image_info->scene,component,exception);
2927  if ((LocaleCompare(component,image_info->filename) != 0) &&
2928  (strchr(component,'%') == (char *) NULL))
2929  image_info->adjoin=MagickFalse;
2930  }
2931  if ((image_info->adjoin != MagickFalse) && (frames > 0))
2932  {
2933  /*
2934  Some image formats do not support multiple frames per file.
2935  */
2936  magick_info=GetMagickInfo(magic,exception);
2937  if (magick_info != (const MagickInfo *) NULL)
2938  if (GetMagickAdjoin(magick_info) == MagickFalse)
2939  image_info->adjoin=MagickFalse;
2940  }
2941  if (image_info->affirm != MagickFalse)
2942  return(MagickTrue);
2943  if (frames == 0)
2944  {
2945  unsigned char
2946  *magick;
2947 
2948  size_t
2949  magick_size;
2950 
2951  /*
2952  Determine the image format from the first few bytes of the file.
2953  */
2954  magick_size=GetMagicPatternExtent(exception);
2955  if (magick_size == 0)
2956  return(MagickFalse);
2957  image=AcquireImage(image_info,exception);
2958  (void) CopyMagickString(image->filename,image_info->filename,
2960  status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2961  if (status == MagickFalse)
2962  {
2964  return(MagickFalse);
2965  }
2966  if ((IsBlobSeekable(image) == MagickFalse) ||
2968  {
2969  /*
2970  Copy image to seekable temporary file.
2971  */
2972  *component='\0';
2973  status=ImageToFile(image,component,exception);
2974  (void) CloseBlob(image);
2975  if (status == MagickFalse)
2976  {
2978  return(MagickFalse);
2979  }
2980  SetImageInfoFile(image_info,(FILE *) NULL);
2981  (void) CopyMagickString(image->filename,component,MagickPathExtent);
2982  status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2983  if (status == MagickFalse)
2984  {
2986  return(MagickFalse);
2987  }
2988  (void) CopyMagickString(image_info->filename,component,
2990  image_info->temporary=MagickTrue;
2991  }
2992  magick=(unsigned char *) AcquireMagickMemory(magick_size);
2993  if (magick == (unsigned char *) NULL)
2994  {
2995  (void) CloseBlob(image);
2997  return(MagickFalse);
2998  }
2999  (void) memset(magick,0,magick_size);
3000  count=ReadBlob(image,magick_size,magick);
3001  (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3002  (void) CloseBlob(image);
3004  /*
3005  Check magic cache.
3006  */
3007  sans_exception=AcquireExceptionInfo();
3008  magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3009  magick=(unsigned char *) RelinquishMagickMemory(magick);
3010  if ((magic_info != (const MagicInfo *) NULL) &&
3011  (GetMagicName(magic_info) != (char *) NULL))
3012  {
3013  /*
3014  Try to use magick_info that was determined earlier by the extension
3015  */
3016  if ((magick_info != (const MagickInfo *) NULL) &&
3017  (GetMagickUseExtension(magick_info) != MagickFalse) &&
3018  (LocaleCompare(magick_info->module,GetMagicName(
3019  magic_info)) == 0))
3020  (void) CopyMagickString(image_info->magick,magick_info->name,
3022  else
3023  {
3024  (void) CopyMagickString(image_info->magick,GetMagicName(
3025  magic_info),MagickPathExtent);
3026  magick_info=GetMagickInfo(image_info->magick,sans_exception);
3027  }
3028  if ((magick_info == (const MagickInfo *) NULL) ||
3029  (GetMagickEndianSupport(magick_info) == MagickFalse))
3030  image_info->endian=UndefinedEndian;
3031  sans_exception=DestroyExceptionInfo(sans_exception);
3032  return(MagickTrue);
3033  }
3034  magick_info=GetMagickInfo(image_info->magick,sans_exception);
3035  if ((magick_info == (const MagickInfo *) NULL) ||
3036  (GetMagickEndianSupport(magick_info) == MagickFalse))
3037  image_info->endian=UndefinedEndian;
3038  sans_exception=DestroyExceptionInfo(sans_exception);
3039  }
3040  return(MagickTrue);
3041 }
3042 
3043 /*
3044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3045 % %
3046 % %
3047 % %
3048 % S e t I m a g e I n f o B l o b %
3049 % %
3050 % %
3051 % %
3052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3053 %
3054 % SetImageInfoBlob() sets the image info blob member.
3055 %
3056 % The format of the SetImageInfoBlob method is:
3057 %
3058 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3059 % const size_t length)
3060 %
3061 % A description of each parameter follows:
3062 %
3063 % o image_info: the image info.
3064 %
3065 % o blob: the blob.
3066 %
3067 % o length: the blob length.
3068 %
3069 */
3070 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3071  const size_t length)
3072 {
3073  assert(image_info != (ImageInfo *) NULL);
3074  assert(image_info->signature == MagickCoreSignature);
3075  if (image_info->debug != MagickFalse)
3077  image_info->filename);
3078  image_info->blob=(void *) blob;
3079  image_info->length=length;
3080 }
3081 
3082 /*
3083 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3084 % %
3085 % %
3086 % %
3087 % S e t I m a g e I n f o C u s t o m S t r e a m %
3088 % %
3089 % %
3090 % %
3091 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3092 %
3093 % SetImageInfoCustomStream() sets the image info custom stream handlers.
3094 %
3095 % The format of the SetImageInfoCustomStream method is:
3096 %
3097 % void SetImageInfoCustomStream(ImageInfo *image_info,
3098 % CustomStreamInfo *custom_stream)
3099 %
3100 % A description of each parameter follows:
3101 %
3102 % o image_info: the image info.
3103 %
3104 % o custom_stream: your custom stream methods.
3105 %
3106 */
3108  CustomStreamInfo *custom_stream)
3109 {
3110  assert(image_info != (ImageInfo *) NULL);
3111  assert(image_info->signature == MagickCoreSignature);
3112  if (image_info->debug != MagickFalse)
3114  image_info->filename);
3115  image_info->custom_stream=(CustomStreamInfo *) custom_stream;
3116 }
3117 
3118 /*
3119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3120 % %
3121 % %
3122 % %
3123 % S e t I m a g e I n f o F i l e %
3124 % %
3125 % %
3126 % %
3127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3128 %
3129 % SetImageInfoFile() sets the image info file member.
3130 %
3131 % The format of the SetImageInfoFile method is:
3132 %
3133 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3134 %
3135 % A description of each parameter follows:
3136 %
3137 % o image_info: the image info.
3138 %
3139 % o file: the file.
3140 %
3141 */
3142 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3143 {
3144  assert(image_info != (ImageInfo *) NULL);
3145  assert(image_info->signature == MagickCoreSignature);
3146  if (image_info->debug != MagickFalse)
3148  image_info->filename);
3149  image_info->file=file;
3150 }
3151 
3152 /*
3153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3154 % %
3155 % %
3156 % %
3157 % S e t I m a g e M a s k %
3158 % %
3159 % %
3160 % %
3161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3162 %
3163 % SetImageMask() associates a mask with the image. The mask must be the same
3164 % dimensions as the image.
3165 %
3166 % The format of the SetImageMask method is:
3167 %
3168 % MagickBooleanType SetImageMask(Image *image,const PixelMask type,
3169 % const Image *mask,ExceptionInfo *exception)
3170 %
3171 % A description of each parameter follows:
3172 %
3173 % o image: the image.
3174 %
3175 % o type: the mask type, ReadPixelMask or WritePixelMask.
3176 %
3177 % o mask: the image mask.
3178 %
3179 % o exception: return any errors or warnings in this structure.
3180 %
3181 */
3183  const Image *mask,ExceptionInfo *exception)
3184 {
3185  CacheView
3186  *mask_view,
3187  *image_view;
3188 
3190  status;
3191 
3192  ssize_t
3193  y;
3194 
3195  /*
3196  Set image mask.
3197  */
3198  assert(image != (Image *) NULL);
3199  if (image->debug != MagickFalse)
3200  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3201  assert(image->signature == MagickCoreSignature);
3202  if (mask == (const Image *) NULL)
3203  {
3204  switch (type)
3205  {
3206  case ReadPixelMask:
3207  {
3209  break;
3210  }
3211  case WritePixelMask:
3212  {
3214  }
3215  default:
3216  {
3218  break;
3219  }
3220  }
3222  }
3223  switch (type)
3224  {
3225  case ReadPixelMask:
3226  {
3228  break;
3229  }
3230  case WritePixelMask:
3231  {
3233  break;
3234  }
3235  default:
3236  {
3238  break;
3239  }
3240  }
3242  return(MagickFalse);
3243  status=MagickTrue;
3245  mask_view=AcquireVirtualCacheView(mask,exception);
3247 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3248  #pragma omp parallel for schedule(static) shared(status) \
3249  magick_number_threads(mask,image,image->rows,1)
3250 #endif
3251  for (y=0; y < (ssize_t) image->rows; y++)
3252  {
3253  register const Quantum
3254  *magick_restrict p;
3255 
3256  register Quantum
3257  *magick_restrict q;
3258 
3259  register ssize_t
3260  x;
3261 
3262  if (status == MagickFalse)
3263  continue;
3264  p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3265  q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3266  if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3267  {
3268  status=MagickFalse;
3269  continue;
3270  }
3271  for (x=0; x < (ssize_t) image->columns; x++)
3272  {
3274  intensity;
3275 
3276  intensity=0.0;
3277  if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3278  intensity=GetPixelIntensity(mask,p);
3279  switch (type)
3280  {
3281  case ReadPixelMask:
3282  {
3283  SetPixelReadMask(image,ClampToQuantum(intensity),q);
3284  break;
3285  }
3286  case WritePixelMask:
3287  {
3288  SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3289  break;
3290  }
3291  default:
3292  {
3294  break;
3295  }
3296  }
3297  p+=GetPixelChannels(mask);
3298  q+=GetPixelChannels(image);
3299  }
3301  status=MagickFalse;
3302  }
3304  mask_view=DestroyCacheView(mask_view);
3305  image_view=DestroyCacheView(image_view);
3306  return(status);
3307 }
3308 
3309 /*
3310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3311 % %
3312 % %
3313 % %
3314 % S e t I m a g e R e g i o n M a s k %
3315 % %
3316 % %
3317 % %
3318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3319 %
3320 % SetImageRegionMask() associates a mask with the image as defined by the
3321 % specified region.
3322 %
3323 % The format of the SetImageRegionMask method is:
3324 %
3325 % MagickBooleanType SetImageRegionMask(Image *image,const PixelMask type,
3326 % const RectangleInfo *region,ExceptionInfo *exception)
3327 %
3328 % A description of each parameter follows:
3329 %
3330 % o image: the image.
3331 %
3332 % o type: the mask type, ReadPixelMask or WritePixelMask.
3333 %
3334 % o geometry: the mask region.
3335 %
3336 % o exception: return any errors or warnings in this structure.
3337 %
3338 */
3340  const PixelMask type,const RectangleInfo *region,ExceptionInfo *exception)
3341 {
3342  CacheView
3343  *image_view;
3344 
3346  status;
3347 
3348  ssize_t
3349  y;
3350 
3351  /*
3352  Set image mask as defined by the region.
3353  */
3354  assert(image != (Image *) NULL);
3355  if (image->debug != MagickFalse)
3356  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3357  assert(image->signature == MagickCoreSignature);
3358  if (region == (const RectangleInfo *) NULL)
3359  {
3360  switch (type)
3361  {
3362  case ReadPixelMask:
3363  {
3365  break;
3366  }
3367  case WritePixelMask:
3368  {
3370  break;
3371  }
3372  default:
3373  {
3375  break;
3376  }
3377  }
3379  }
3380  switch (type)
3381  {
3382  case ReadPixelMask:
3383  {
3385  break;
3386  }
3387  case WritePixelMask:
3388  {
3390  break;
3391  }
3392  default:
3393  {
3395  break;
3396  }
3397  }
3399  return(MagickFalse);
3400  status=MagickTrue;
3403 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3404  #pragma omp parallel for schedule(static) shared(status) \
3405  magick_number_threads(image,image,image->rows,1)
3406 #endif
3407  for (y=0; y < (ssize_t) image->rows; y++)
3408  {
3409  register Quantum
3410  *magick_restrict q;
3411 
3412  register ssize_t
3413  x;
3414 
3415  if (status == MagickFalse)
3416  continue;
3417  q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3418  if (q == (Quantum *) NULL)
3419  {
3420  status=MagickFalse;
3421  continue;
3422  }
3423  for (x=0; x < (ssize_t) image->columns; x++)
3424  {
3425  Quantum
3426  pixel;
3427 
3428  pixel=QuantumRange;
3429  if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3430  ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3431  pixel=(Quantum) 0;
3432  switch (type)
3433  {
3434  case ReadPixelMask:
3435  {
3436  SetPixelReadMask(image,pixel,q);
3437  break;
3438  }
3439  case WritePixelMask:
3440  {
3441  SetPixelWriteMask(image,pixel,q);
3442  break;
3443  }
3444  default:
3445  {
3446  SetPixelCompositeMask(image,pixel,q);
3447  break;
3448  }
3449  }
3450  q+=GetPixelChannels(image);
3451  }
3453  status=MagickFalse;
3454  }
3456  image_view=DestroyCacheView(image_view);
3457  return(status);
3458 }
3459 
3460 /*
3461 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3462 % %
3463 % %
3464 % %
3465 % 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 %
3466 % %
3467 % %
3468 % %
3469 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3470 %
3471 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3472 % image and returns the previous setting. A virtual pixel is any pixel access
3473 % that is outside the boundaries of the image cache.
3474 %
3475 % The format of the SetImageVirtualPixelMethod() method is:
3476 %
3477 % VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3478 % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3479 %
3480 % A description of each parameter follows:
3481 %
3482 % o image: the image.
3483 %
3484 % o virtual_pixel_method: choose the type of virtual pixel.
3485 %
3486 % o exception: return any errors or warnings in this structure.
3487 %
3488 */
3490  const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3491 {
3492  assert(image != (const Image *) NULL);
3493  assert(image->signature == MagickCoreSignature);
3494  if (image->debug != MagickFalse)
3496  return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3497 }
3498 
3499 /*
3500 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3501 % %
3502 % %
3503 % %
3504 % S m u s h I m a g e s %
3505 % %
3506 % %
3507 % %
3508 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3509 %
3510 % SmushImages() takes all images from the current image pointer to the end
3511 % of the image list and smushes them to each other top-to-bottom if the
3512 % stack parameter is true, otherwise left-to-right.
3513 %
3514 % The current gravity setting now effects how the image is justified in the
3515 % final image.
3516 %
3517 % The format of the SmushImages method is:
3518 %
3519 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3520 % ExceptionInfo *exception)
3521 %
3522 % A description of each parameter follows:
3523 %
3524 % o images: the image sequence.
3525 %
3526 % o stack: A value other than 0 stacks the images top-to-bottom.
3527 %
3528 % o offset: minimum distance in pixels between images.
3529 %
3530 % o exception: return any errors or warnings in this structure.
3531 %
3532 */
3533 
3534 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3535  const ssize_t offset,ExceptionInfo *exception)
3536 {
3537  CacheView
3538  *left_view,
3539  *right_view;
3540 
3541  const Image
3542  *left_image,
3543  *right_image;
3544 
3546  left_geometry,
3547  right_geometry;
3548 
3549  register const Quantum
3550  *p;
3551 
3552  register ssize_t
3553  i,
3554  y;
3555 
3556  size_t
3557  gap;
3558 
3559  ssize_t
3560  x;
3561 
3562  if (images->previous == (Image *) NULL)
3563  return(0);
3564  right_image=images;
3565  SetGeometry(smush_image,&right_geometry);
3566  GravityAdjustGeometry(right_image->columns,right_image->rows,
3567  right_image->gravity,&right_geometry);
3568  left_image=images->previous;
3569  SetGeometry(smush_image,&left_geometry);
3570  GravityAdjustGeometry(left_image->columns,left_image->rows,
3571  left_image->gravity,&left_geometry);
3572  gap=right_image->columns;
3573  left_view=AcquireVirtualCacheView(left_image,exception);
3574  right_view=AcquireVirtualCacheView(right_image,exception);
3575  for (y=0; y < (ssize_t) smush_image->rows; y++)
3576  {
3577  for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3578  {
3579  p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3580  if ((p == (const Quantum *) NULL) ||
3581  (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3582  ((left_image->columns-x-1) >= gap))
3583  break;
3584  }
3585  i=(ssize_t) left_image->columns-x-1;
3586  for (x=0; x < (ssize_t) right_image->columns; x++)
3587  {
3588  p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3589  exception);
3590  if ((p == (const Quantum *) NULL) ||
3591  (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3592  ((x+i) >= (ssize_t) gap))
3593  break;
3594  }
3595  if ((x+i) < (ssize_t) gap)
3596  gap=(size_t) (x+i);
3597  }
3598  right_view=DestroyCacheView(right_view);
3599  left_view=DestroyCacheView(left_view);
3600  if (y < (ssize_t) smush_image->rows)
3601  return(offset);
3602  return((ssize_t) gap-offset);
3603 }
3604 
3605 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3606  const ssize_t offset,ExceptionInfo *exception)
3607 {
3608  CacheView
3609  *bottom_view,
3610  *top_view;
3611 
3612  const Image
3613  *bottom_image,
3614  *top_image;
3615 
3617  bottom_geometry,
3618  top_geometry;
3619 
3620  register const Quantum
3621  *p;
3622 
3623  register ssize_t
3624  i,
3625  x;
3626 
3627  size_t
3628  gap;
3629 
3630  ssize_t
3631  y;
3632 
3633  if (images->previous == (Image *) NULL)
3634  return(0);
3635  bottom_image=images;
3636  SetGeometry(smush_image,&bottom_geometry);
3637  GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3638  bottom_image->gravity,&bottom_geometry);
3639  top_image=images->previous;
3640  SetGeometry(smush_image,&top_geometry);
3641  GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3642  &top_geometry);
3643  gap=bottom_image->rows;
3644  top_view=AcquireVirtualCacheView(top_image,exception);
3645  bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3646  for (x=0; x < (ssize_t) smush_image->columns; x++)
3647  {
3648  for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3649  {
3650  p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3651  if ((p == (const Quantum *) NULL) ||
3652  (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3653  ((top_image->rows-y-1) >= gap))
3654  break;
3655  }
3656  i=(ssize_t) top_image->rows-y-1;
3657  for (y=0; y < (ssize_t) bottom_image->rows; y++)
3658  {
3659  p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3660  exception);
3661  if ((p == (const Quantum *) NULL) ||
3662  (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3663  ((y+i) >= (ssize_t) gap))
3664  break;
3665  }
3666  if ((y+i) < (ssize_t) gap)
3667  gap=(size_t) (y+i);
3668  }
3669  bottom_view=DestroyCacheView(bottom_view);
3670  top_view=DestroyCacheView(top_view);
3671  if (x < (ssize_t) smush_image->columns)
3672  return(offset);
3673  return((ssize_t) gap-offset);
3674 }
3675 
3677  const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3678 {
3679 #define SmushImageTag "Smush/Image"
3680 
3681  const Image
3682  *image;
3683 
3684  Image
3685  *smush_image;
3686 
3688  proceed,
3689  status;
3690 
3692  n;
3693 
3694  PixelTrait
3695  alpha_trait;
3696 
3698  geometry;
3699 
3700  register const Image
3701  *next;
3702 
3703  size_t
3704  height,
3705  number_images,
3706  width;
3707 
3708  ssize_t
3709  x_offset,
3710  y_offset;
3711 
3712  /*
3713  Compute maximum area of smushed area.
3714  */
3715  assert(images != (Image *) NULL);
3716  assert(images->signature == MagickCoreSignature);
3717  if (images->debug != MagickFalse)
3718  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3719  assert(exception != (ExceptionInfo *) NULL);
3721  image=images;
3722  alpha_trait=image->alpha_trait;
3723  number_images=1;
3724  width=image->columns;
3725  height=image->rows;
3726  next=GetNextImageInList(image);
3727  for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3728  {
3729  if (next->alpha_trait != UndefinedPixelTrait)
3730  alpha_trait=BlendPixelTrait;
3731  number_images++;
3732  if (stack != MagickFalse)
3733  {
3734  if (next->columns > width)
3735  width=next->columns;
3736  height+=next->rows;
3737  if (next->previous != (Image *) NULL)
3738  height+=offset;
3739  continue;
3740  }
3741  width+=next->columns;
3742  if (next->previous != (Image *) NULL)
3743  width+=offset;
3744  if (next->rows > height)
3745  height=next->rows;
3746  }
3747  /*
3748  Smush images.
3749  */
3750  smush_image=CloneImage(image,width,height,MagickTrue,exception);
3751  if (smush_image == (Image *) NULL)
3752  return((Image *) NULL);
3754  {
3755  smush_image=DestroyImage(smush_image);
3756  return((Image *) NULL);
3757  }
3758  smush_image->alpha_trait=alpha_trait;
3759  (void) SetImageBackgroundColor(smush_image,exception);
3760  status=MagickTrue;
3761  x_offset=0;
3762  y_offset=0;
3763  for (n=0; n < (MagickOffsetType) number_images; n++)
3764  {
3765  SetGeometry(smush_image,&geometry);
3767  if (stack != MagickFalse)
3768  {
3769  x_offset-=geometry.x;
3770  y_offset-=SmushYGap(smush_image,image,offset,exception);
3771  }
3772  else
3773  {
3774  x_offset-=SmushXGap(smush_image,image,offset,exception);
3775  y_offset-=geometry.y;
3776  }
3777  status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3778  y_offset,exception);
3779  proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3780  if (proceed == MagickFalse)
3781  break;
3782  if (stack == MagickFalse)
3783  {
3784  x_offset+=(ssize_t) image->columns;
3785  y_offset=0;
3786  }
3787  else
3788  {
3789  x_offset=0;
3790  y_offset+=(ssize_t) image->rows;
3791  }
3793  }
3794  if (stack == MagickFalse)
3795  smush_image->columns=(size_t) x_offset;
3796  else
3797  smush_image->rows=(size_t) y_offset;
3798  if (status == MagickFalse)
3799  smush_image=DestroyImage(smush_image);
3800  return(smush_image);
3801 }
3802 
3803 /*
3804 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3805 % %
3806 % %
3807 % %
3808 % S t r i p I m a g e %
3809 % %
3810 % %
3811 % %
3812 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3813 %
3814 % StripImage() strips an image of all profiles and comments.
3815 %
3816 % The format of the StripImage method is:
3817 %
3818 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3819 %
3820 % A description of each parameter follows:
3821 %
3822 % o image: the image.
3823 %
3824 % o exception: return any errors or warnings in this structure.
3825 %
3826 */
3828 {
3830  status;
3831 
3832  assert(image != (Image *) NULL);
3833  if (image->debug != MagickFalse)
3834  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3835  (void) exception;
3837  (void) DeleteImageProperty(image,"comment");
3838  (void) DeleteImageProperty(image,"date:create");
3839  (void) DeleteImageProperty(image,"date:modify");
3840  status=SetImageArtifact(image,"png:exclude-chunk",
3841  "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3842  return(status);
3843 }
3844 
3845 /*
3846 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3847 % %
3848 % %
3849 % %
3850 + S y n c I m a g e %
3851 % %
3852 % %
3853 % %
3854 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3855 %
3856 % SyncImage() initializes the red, green, and blue intensities of each pixel
3857 % as defined by the colormap index.
3858 %
3859 % The format of the SyncImage method is:
3860 %
3861 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3862 %
3863 % A description of each parameter follows:
3864 %
3865 % o image: the image.
3866 %
3867 % o exception: return any errors or warnings in this structure.
3868 %
3869 */
3870 
3871 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3872  MagickBooleanType *range_exception)
3873 {
3874  if ((size_t) index < image->colors)
3875  return(index);
3876  *range_exception=MagickTrue;
3877  return((Quantum) 0);
3878 }
3879 
3881 {
3882  CacheView
3883  *image_view;
3884 
3886  range_exception,
3887  status,
3888  taint;
3889 
3890  ssize_t
3891  y;
3892 
3893  assert(image != (Image *) NULL);
3894  if (image->debug != MagickFalse)
3895  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3896  assert(image->signature == MagickCoreSignature);
3897  if (image->ping != MagickFalse)
3898  return(MagickTrue);
3900  return(MagickFalse);
3901  assert(image->colormap != (PixelInfo *) NULL);
3902  range_exception=MagickFalse;
3903  status=MagickTrue;
3904  taint=image->taint;
3906 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3907  #pragma omp parallel for schedule(static) shared(range_exception,status) \
3908  magick_number_threads(image,image,image->rows,1)
3909 #endif
3910  for (y=0; y < (ssize_t) image->rows; y++)
3911  {
3912  Quantum
3913  index;
3914 
3915  register Quantum
3916  *magick_restrict q;
3917 
3918  register ssize_t
3919  x;
3920 
3921  if (status == MagickFalse)
3922  continue;
3923  q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3924  if (q == (Quantum *) NULL)
3925  {
3926  status=MagickFalse;
3927  continue;
3928  }
3929  for (x=0; x < (ssize_t) image->columns; x++)
3930  {
3931  index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3932  SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
3933  q+=GetPixelChannels(image);
3934  }
3936  status=MagickFalse;
3937  }
3938  image_view=DestroyCacheView(image_view);
3939  image->taint=taint;
3940  if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3942  CorruptImageWarning,"InvalidColormapIndex","`%s'",image->filename);
3943  return(status);
3944 }
3945 
3946 /*
3947 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3948 % %
3949 % %
3950 % %
3951 % S y n c I m a g e S e t t i n g s %
3952 % %
3953 % %
3954 % %
3955 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3956 %
3957 % SyncImageSettings() syncs any image_info global options into per-image
3958 % attributes.
3959 %
3960 % Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
3961 % that operations and coders can find such settings. In IMv7 if a desired
3962 % per-image artifact is not set, then it will directly look for a global
3963 % option as a fallback, as such this copy is no longer needed, only the
3964 % link set up.
3965 %
3966 % The format of the SyncImageSettings method is:
3967 %
3968 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3969 % Image *image,ExceptionInfo *exception)
3970 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3971 % Image *image,ExceptionInfo *exception)
3972 %
3973 % A description of each parameter follows:
3974 %
3975 % o image_info: the image info.
3976 %
3977 % o image: the image.
3978 %
3979 % o exception: return any errors or warnings in this structure.
3980 %
3981 */
3982 
3984  Image *images,ExceptionInfo *exception)
3985 {
3986  Image
3987  *image;
3988 
3989  assert(image_info != (const ImageInfo *) NULL);
3990  assert(image_info->signature == MagickCoreSignature);
3991  assert(images != (Image *) NULL);
3992  assert(images->signature == MagickCoreSignature);
3993  if (images->debug != MagickFalse)
3994  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3995  image=images;
3996  for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3997  (void) SyncImageSettings(image_info,image,exception);
3998  (void) DeleteImageOption(image_info,"page");
3999  return(MagickTrue);
4000 }
4001 
4004 {
4005  const char
4006  *option;
4007 
4008  GeometryInfo
4009  geometry_info;
4010 
4012  flags;
4013 
4015  units;
4016 
4017  /*
4018  Sync image options.
4019  */
4020  assert(image_info != (const ImageInfo *) NULL);
4021  assert(image_info->signature == MagickCoreSignature);
4022  assert(image != (Image *) NULL);
4023  assert(image->signature == MagickCoreSignature);
4024  if (image->debug != MagickFalse)
4026  option=GetImageOption(image_info,"background");
4027  if (option != (const char *) NULL)
4029  exception);
4030  option=GetImageOption(image_info,"black-point-compensation");
4031  if (option != (const char *) NULL)
4034  option=GetImageOption(image_info,"blue-primary");
4035  if (option != (const char *) NULL)
4036  {
4037  flags=ParseGeometry(option,&geometry_info);
4038  image->chromaticity.blue_primary.x=geometry_info.rho;
4039  image->chromaticity.blue_primary.y=geometry_info.sigma;
4040  if ((flags & SigmaValue) == 0)
4042  }
4043  option=GetImageOption(image_info,"bordercolor");
4044  if (option != (const char *) NULL)
4046  exception);
4047  /* FUTURE: do not sync compose to per-image compose setting here */
4048  option=GetImageOption(image_info,"compose");
4049  if (option != (const char *) NULL)
4051  MagickFalse,option);
4052  /* -- */
4053  option=GetImageOption(image_info,"compress");
4054  if (option != (const char *) NULL)
4057  option=GetImageOption(image_info,"debug");
4058  if (option != (const char *) NULL)
4060  MagickFalse,option);
4061  option=GetImageOption(image_info,"density");
4062  if (option != (const char *) NULL)
4063  {
4064  flags=ParseGeometry(option,&geometry_info);
4065  image->resolution.x=geometry_info.rho;
4066  image->resolution.y=geometry_info.sigma;
4067  if ((flags & SigmaValue) == 0)
4069  }
4070  option=GetImageOption(image_info,"depth");
4071  if (option != (const char *) NULL)
4072  image->depth=StringToUnsignedLong(option);
4073  option=GetImageOption(image_info,"endian");
4074  if (option != (const char *) NULL)
4076  MagickFalse,option);
4077  option=GetImageOption(image_info,"filter");
4078  if (option != (const char *) NULL)
4080  MagickFalse,option);
4081  option=GetImageOption(image_info,"fuzz");
4082  if (option != (const char *) NULL)
4083  image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
4084  option=GetImageOption(image_info,"gravity");
4085  if (option != (const char *) NULL)
4087  MagickFalse,option);
4088  option=GetImageOption(image_info,"green-primary");
4089  if (option != (const char *) NULL)
4090  {
4091  flags=ParseGeometry(option,&geometry_info);
4092  image->chromaticity.green_primary.x=geometry_info.rho;
4093  image->chromaticity.green_primary.y=geometry_info.sigma;
4094  if ((flags & SigmaValue) == 0)
4096  }
4097  option=GetImageOption(image_info,"intent");
4098  if (option != (const char *) NULL)
4101  option=GetImageOption(image_info,"intensity");
4102  if (option != (const char *) NULL)
4105  option=GetImageOption(image_info,"interlace");
4106  if (option != (const char *) NULL)
4108  MagickFalse,option);
4109  option=GetImageOption(image_info,"interpolate");
4110  if (option != (const char *) NULL)
4113  option=GetImageOption(image_info,"loop");
4114  if (option != (const char *) NULL)
4116  option=GetImageOption(image_info,"mattecolor");
4117  if (option != (const char *) NULL)
4119  exception);
4120  option=GetImageOption(image_info,"orient");
4121  if (option != (const char *) NULL)
4124  option=GetImageOption(image_info,"page");
4125  if (option != (const char *) NULL)
4126  {
4127  char
4128  *geometry;
4129 
4130  geometry=GetPageGeometry(option);
4131  flags=ParseAbsoluteGeometry(geometry,&image->page);
4132  geometry=DestroyString(geometry);
4133  }
4134  option=GetImageOption(image_info,"quality");
4135  if (option != (const char *) NULL)
4137  option=GetImageOption(image_info,"red-primary");
4138  if (option != (const char *) NULL)
4139  {
4140  flags=ParseGeometry(option,&geometry_info);
4141  image->chromaticity.red_primary.x=geometry_info.rho;
4142  image->chromaticity.red_primary.y=geometry_info.sigma;
4143  if ((flags & SigmaValue) == 0)
4145  }
4146  if (image_info->quality != UndefinedCompressionQuality)
4147  image->quality=image_info->quality;
4148  option=GetImageOption(image_info,"scene");
4149  if (option != (const char *) NULL)
4150  image->scene=StringToUnsignedLong(option);
4151  option=GetImageOption(image_info,"taint");
4152  if (option != (const char *) NULL)
4154  MagickFalse,option);
4155  option=GetImageOption(image_info,"tile-offset");
4156  if (option != (const char *) NULL)
4157  {
4158  char
4159  *geometry;
4160 
4161  geometry=GetPageGeometry(option);
4162  flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4163  geometry=DestroyString(geometry);
4164  }
4165  option=GetImageOption(image_info,"transparent-color");
4166  if (option != (const char *) NULL)
4168  exception);
4169  option=GetImageOption(image_info,"type");
4170  if (option != (const char *) NULL)
4172  option);
4173  option=GetImageOption(image_info,"units");
4174  units=image_info->units;
4175  if (option != (const char *) NULL)
4177  MagickFalse,option);
4178  if (units != UndefinedResolution)
4179  {
4180  if (image->units != units)
4181  switch (image->units)
4182  {
4184  {
4185  if (units == PixelsPerCentimeterResolution)
4186  {
4187  image->resolution.x/=2.54;
4188  image->resolution.y/=2.54;
4189  }
4190  break;
4191  }
4193  {
4194  if (units == PixelsPerInchResolution)
4195  {
4196  image->resolution.x=(double) ((size_t) (100.0*2.54*
4197  image->resolution.x+0.5))/100.0;
4198  image->resolution.y=(double) ((size_t) (100.0*2.54*
4199  image->resolution.y+0.5))/100.0;
4200  }
4201  break;
4202  }
4203  default:
4204  break;
4205  }
4206  image->units=units;
4207  }
4208  option=GetImageOption(image_info,"virtual-pixel");
4209  if (option != (const char *) NULL)
4212  exception);
4213  option=GetImageOption(image_info,"white-point");
4214  if (option != (const char *) NULL)
4215  {
4216  flags=ParseGeometry(option,&geometry_info);
4217  image->chromaticity.white_point.x=geometry_info.rho;
4218  image->chromaticity.white_point.y=geometry_info.sigma;
4219  if ((flags & SigmaValue) == 0)
4221  }
4222  /*
4223  Pointer to allow the lookup of pre-image artifact will fallback to a global
4224  option setting/define. This saves a lot of duplication of global options
4225  into per-image artifacts, while ensuring only specifically set per-image
4226  artifacts are preserved when parenthesis ends.
4227  */
4228  if (image->image_info != (ImageInfo *) NULL)
4230  image->image_info=CloneImageInfo(image_info);
4231  return(MagickTrue);
4232 }
MagickExport Image * GetImageMask(const Image *image, const PixelMask type, ExceptionInfo *exception)
Definition: image.c:1434
size_t rows
Definition: image.h:172
#define magick_restrict
Definition: MagickCore.h:41
MagickExport FILE * GetImageInfoFile(const ImageInfo *image_info)
Definition: image.c:1404
MagickPrivate Cache DestroyPixelCache(Cache)
MagickExport MagickBooleanType GetMagickUseExtension(const MagickInfo *magick_info)
Definition: magick.c:971
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:3889
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
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:3880
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:2133
FilterType filter
Definition: image.h:219
MagickExport MagickBooleanType DeleteImageOption(ImageInfo *image_info, const char *option)
Definition: option.c:2227
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:2967
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:2046
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:4002
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:1181
MagickPrivate MagickBooleanType SyncImagePixelCache(Image *, ExceptionInfo *)
Definition: cache.c:5508
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:4738
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:2336
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:254
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:3070
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:2302
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:2263
EndianType
Definition: quantum.h:28
char * size
Definition: image.h:390
MagickExport void SetImageInfoFile(ImageInfo *image_info, FILE *file)
Definition: image.c:3142
Definition: image.h:151
void * cache
Definition: image.h:464
MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
Definition: image.c:1602
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:134
MagickExport MagickBooleanType SetImageMask(Image *image, const PixelMask type, const Image *mask, ExceptionInfo *exception)
Definition: image.c:3182
#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:3534
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:974
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:938
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:1902
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:177
MagickExport int LocaleNCompare(const char *p, const char *q, const size_t length)
Definition: locale.c:1542
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
MagickPrivate MagickBooleanType IsGlob(const char *) magick_attribute((__pure__))
Definition: token.c:592
MagickExport void DestroyImageProperties(Image *image)
Definition: property.c:314
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:2498
MagickBooleanType monochrome
Definition: image.h:432
MagickExport Quantum * QueueCacheViewAuthenticPixels(CacheView *cache_view, const ssize_t x, const ssize_t y, const size_t columns, const size_t rows, ExceptionInfo *exception)
Definition: cache-view.c:977
MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info, const unsigned int frames, ExceptionInfo *exception)
Definition: image.c:2702
MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image, const VirtualPixelMethod virtual_pixel_method, ExceptionInfo *exception)
Definition: image.c:3489
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:2414
size_t signature
Definition: image.h:354
size_t columns
Definition: image.h:172
MagickExport const MagickInfo * GetMagickInfo(const char *name, ExceptionInfo *exception)
Definition: magick.c:604
MagickExport Image * SmushImages(const Image *images, const MagickBooleanType stack, const ssize_t offset, ExceptionInfo *exception)
Definition: image.c:3676
MagickExport MagickBooleanType SetImageColor(Image *image, const PixelInfo *color, ExceptionInfo *exception)
Definition: image.c:2531
MagickExport Image * AcquireImage(const ImageInfo *image_info, ExceptionInfo *exception)
Definition: image.c:155
MagickExport MagickBooleanType OpenBlob(const ImageInfo *, Image *, const BlobMode, ExceptionInfo *)
MagickExport MagickBooleanType GetMagickAdjoin(const MagickInfo *magick_info)
Definition: magick.c:344
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:3871
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:2614
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:2169
MagickExport MagickBooleanType GetMagickEndianSupport(const MagickInfo *magick_info)
Definition: magick.c:569
MagickExport size_t InterpretImageFilename(const ImageInfo *image_info, Image *image, const char *format, int value, char *filename, ExceptionInfo *exception)
Definition: image.c:1646
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:2656
RenderingIntent
Definition: profile.h:30
double y
Definition: image.h:99
size_t quality
Definition: image.h:163
size_t colors
Definition: image.h:172
size_t depth
Definition: pixel.h:185
TimerInfo timer
Definition: image.h:300
MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info, Image *images, ExceptionInfo *exception)
Definition: image.c:3983
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:2240
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:1249
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:1939
MagickExport MagickBooleanType CloneImageOptions(ImageInfo *image_info, const ImageInfo *clone_info)
Definition: option.c:2130
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:1135
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:771
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:279
MagickExport const char * GetImageProperty(const Image *image, const char *property, ExceptionInfo *exception)
Definition: property.c:2229
MagickExport MagickBooleanType ModifyImage(Image **image, ExceptionInfo *exception)
Definition: image.c:1992
MagickPrivate VirtualPixelMethod SetPixelCacheVirtualMethod(Image *, const VirtualPixelMethod, ExceptionInfo *)
Definition: cache.c:5207
MagickExport MagickBooleanType IsBlobExempt(const Image *image)
Definition: blob.c:2810
MagickExport MagickBooleanType StripImage(Image *image, ExceptionInfo *exception)
Definition: image.c:3827
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:1342
MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image, ExceptionInfo *exception)
Definition: image.c:1803
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:3107
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:3605
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:3339
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:1602
MagickExport Image * DestroyImage(Image *image)
Definition: image.c:1178
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:1563
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:1311
#define QuantumRange
Definition: magick-type.h:83
MagickExport MagickBooleanType SetImageProgress(const Image *image, const char *tag, const MagickOffsetType offset, const MagickSizeType extent)
Definition: monitor.c:136
MagickBooleanType temporary
Definition: image.h:384
PixelChannelMap * channel_map
Definition: image.h:291