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