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