2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % IIIII M M AAA GGGG EEEEE %
8 % I M M M AAAAA G GG EEE %
10 % IIIII M M A A GGGG EEEEE %
13 % MagickCore Image Methods %
20 % Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % https://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/animate.h"
45 #include "MagickCore/artifact.h"
46 #include "MagickCore/attribute.h"
47 #include "MagickCore/blob.h"
48 #include "MagickCore/blob-private.h"
49 #include "MagickCore/cache.h"
50 #include "MagickCore/cache-private.h"
51 #include "MagickCore/cache-view.h"
52 #include "MagickCore/channel.h"
53 #include "MagickCore/client.h"
54 #include "MagickCore/color.h"
55 #include "MagickCore/color-private.h"
56 #include "MagickCore/colormap.h"
57 #include "MagickCore/colorspace.h"
58 #include "MagickCore/colorspace-private.h"
59 #include "MagickCore/composite.h"
60 #include "MagickCore/composite-private.h"
61 #include "MagickCore/compress.h"
62 #include "MagickCore/constitute.h"
63 #include "MagickCore/delegate.h"
64 #include "MagickCore/display.h"
65 #include "MagickCore/draw.h"
66 #include "MagickCore/enhance.h"
67 #include "MagickCore/exception.h"
68 #include "MagickCore/exception-private.h"
69 #include "MagickCore/gem.h"
70 #include "MagickCore/geometry.h"
71 #include "MagickCore/histogram.h"
72 #include "MagickCore/image-private.h"
73 #include "MagickCore/list.h"
74 #include "MagickCore/magic.h"
75 #include "MagickCore/magick.h"
76 #include "MagickCore/magick-private.h"
77 #include "MagickCore/memory_.h"
78 #include "MagickCore/module.h"
79 #include "MagickCore/monitor.h"
80 #include "MagickCore/monitor-private.h"
81 #include "MagickCore/option.h"
82 #include "MagickCore/paint.h"
83 #include "MagickCore/pixel-accessor.h"
84 #include "MagickCore/profile.h"
85 #include "MagickCore/property.h"
86 #include "MagickCore/quantize.h"
87 #include "MagickCore/random_.h"
88 #include "MagickCore/resource_.h"
89 #include "MagickCore/segment.h"
90 #include "MagickCore/semaphore.h"
91 #include "MagickCore/signature-private.h"
92 #include "MagickCore/statistic.h"
93 #include "MagickCore/string_.h"
94 #include "MagickCore/string-private.h"
95 #include "MagickCore/thread-private.h"
96 #include "MagickCore/threshold.h"
97 #include "MagickCore/timer.h"
98 #include "MagickCore/token.h"
99 #include "MagickCore/utility.h"
100 #include "MagickCore/utility-private.h"
101 #include "MagickCore/version.h"
102 #include "MagickCore/xwindow-private.h"
105 Constant declaration.
108 BackgroundColor[] = "#ffffff", /* white */
109 BorderColor[] = "#dfdfdf", /* gray */
110 DefaultTileFrame[] = "15x15+3+3",
111 DefaultTileGeometry[] = "120x120+4+3>",
112 DefaultTileLabel[] = "%f\n%G\n%b",
113 ForegroundColor[] = "#000", /* black */
114 LoadImageTag[] = "Load/Image",
115 LoadImagesTag[] = "Load/Images",
116 MatteColor[] = "#bdbdbd", /* gray */
117 PSDensityGeometry[] = "72.0x72.0",
118 PSPageGeometry[] = "612x792",
119 SaveImageTag[] = "Save/Image",
120 SaveImagesTag[] = "Save/Images",
121 TransparentColor[] = "#00000000"; /* transparent black */
124 DefaultResolution = 72.0;
127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 % A c q u i r e I m a g e %
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 % AcquireImage() returns a pointer to an image structure initialized to
140 % The format of the AcquireImage method is:
142 % Image *AcquireImage(const ImageInfo *image_info,ExceptionInfo *exception)
144 % A description of each parameter follows:
146 % o image_info: Many of the image default values are set from this
147 % structure. For example, filename, compression, depth, background color,
150 % o exception: return any errors or warnings in this structure.
153 MagickExport Image *AcquireImage(const ImageInfo *image_info,
154 ExceptionInfo *exception)
166 Allocate image structure.
168 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
169 image=(Image *) AcquireMagickMemory(sizeof(*image));
170 if (image == (Image *) NULL)
171 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
172 (void) ResetMagickMemory(image,0,sizeof(*image));
174 Initialize Image structure.
176 (void) CopyMagickString(image->magick,"MIFF",MagickPathExtent);
177 image->storage_class=DirectClass;
178 image->depth=MAGICKCORE_QUANTUM_DEPTH;
179 image->colorspace=sRGBColorspace;
180 image->rendering_intent=PerceptualIntent;
181 image->gamma=1.000f/2.200f;
182 image->chromaticity.red_primary.x=0.6400f;
183 image->chromaticity.red_primary.y=0.3300f;
184 image->chromaticity.red_primary.z=0.0300f;
185 image->chromaticity.green_primary.x=0.3000f;
186 image->chromaticity.green_primary.y=0.6000f;
187 image->chromaticity.green_primary.z=0.1000f;
188 image->chromaticity.blue_primary.x=0.1500f;
189 image->chromaticity.blue_primary.y=0.0600f;
190 image->chromaticity.blue_primary.z=0.7900f;
191 image->chromaticity.white_point.x=0.3127f;
192 image->chromaticity.white_point.y=0.3290f;
193 image->chromaticity.white_point.z=0.3583f;
194 image->interlace=NoInterlace;
195 image->ticks_per_second=UndefinedTicksPerSecond;
196 image->compose=OverCompositeOp;
197 (void) QueryColorCompliance(MatteColor,AllCompliance,&image->matte_color,
199 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
200 &image->background_color,exception);
201 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
203 (void) QueryColorCompliance(TransparentColor,AllCompliance,
204 &image->transparent_color,exception);
205 GetTimerInfo(&image->timer);
206 image->cache=AcquirePixelCache(0);
207 image->channel_mask=DefaultChannels;
208 image->channel_map=AcquirePixelChannelMap();
209 image->blob=CloneBlobInfo((BlobInfo *) NULL);
210 image->timestamp=time((time_t *) NULL);
211 image->debug=IsEventLogging();
212 image->reference_count=1;
213 image->semaphore=AcquireSemaphoreInfo();
214 image->signature=MagickCoreSignature;
215 if (image_info == (ImageInfo *) NULL)
220 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
222 (void) CopyMagickString(image->filename,image_info->filename,
224 (void) CopyMagickString(image->magick_filename,image_info->filename,
226 (void) CopyMagickString(image->magick,image_info->magick,MagickPathExtent);
227 if (image_info->size != (char *) NULL)
229 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
230 image->columns=image->extract_info.width;
231 image->rows=image->extract_info.height;
232 image->offset=image->extract_info.x;
233 image->extract_info.x=0;
234 image->extract_info.y=0;
236 if (image_info->extract != (char *) NULL)
241 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
242 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
244 image->extract_info=geometry;
245 Swap(image->columns,image->extract_info.width);
246 Swap(image->rows,image->extract_info.height);
249 image->compression=image_info->compression;
250 image->quality=image_info->quality;
251 image->endian=image_info->endian;
252 image->interlace=image_info->interlace;
253 image->units=image_info->units;
254 if (image_info->density != (char *) NULL)
259 flags=ParseGeometry(image_info->density,&geometry_info);
260 image->resolution.x=geometry_info.rho;
261 image->resolution.y=geometry_info.sigma;
262 if ((flags & SigmaValue) == 0)
263 image->resolution.y=image->resolution.x;
265 if (image_info->page != (char *) NULL)
270 image->page=image->extract_info;
271 geometry=GetPageGeometry(image_info->page);
272 (void) ParseAbsoluteGeometry(geometry,&image->page);
273 geometry=DestroyString(geometry);
275 if (image_info->depth != 0)
276 image->depth=image_info->depth;
277 image->dither=image_info->dither;
278 image->matte_color=image_info->matte_color;
279 image->background_color=image_info->background_color;
280 image->border_color=image_info->border_color;
281 image->transparent_color=image_info->transparent_color;
282 image->ping=image_info->ping;
283 image->progress_monitor=image_info->progress_monitor;
284 image->client_data=image_info->client_data;
285 if (image_info->cache != (void *) NULL)
286 ClonePixelCacheMethods(image->cache,image_info->cache);
288 Set all global options that map to per-image settings.
290 (void) SyncImageSettings(image_info,image,exception);
292 Global options that are only set for new images.
294 option=GetImageOption(image_info,"delay");
295 if (option != (const char *) NULL)
300 flags=ParseGeometry(option,&geometry_info);
301 if ((flags & GreaterValue) != 0)
303 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
304 image->delay=(size_t) floor(geometry_info.rho+0.5);
307 if ((flags & LessValue) != 0)
309 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
310 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
313 image->delay=(size_t) floor(geometry_info.rho+0.5);
314 if ((flags & SigmaValue) != 0)
315 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
317 option=GetImageOption(image_info,"dispose");
318 if (option != (const char *) NULL)
319 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329 % A c q u i r e I m a g e I n f o %
333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335 % AcquireImageInfo() allocates the ImageInfo structure.
337 % The format of the AcquireImageInfo method is:
339 % ImageInfo *AcquireImageInfo(void)
342 MagickExport ImageInfo *AcquireImageInfo(void)
347 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
348 if (image_info == (ImageInfo *) NULL)
349 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
350 GetImageInfo(image_info);
355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
359 % A c q u i r e N e x t I m a g e %
363 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
365 % AcquireNextImage() initializes the next image in a sequence to
366 % default values. The next member of image points to the newly allocated
367 % image. If there is a memory shortage, next is assigned NULL.
369 % The format of the AcquireNextImage method is:
371 % void AcquireNextImage(const ImageInfo *image_info,Image *image,
372 % ExceptionInfo *exception)
374 % A description of each parameter follows:
376 % o image_info: Many of the image default values are set from this
377 % structure. For example, filename, compression, depth, background color,
380 % o image: the image.
382 % o exception: return any errors or warnings in this structure.
385 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image,
386 ExceptionInfo *exception)
389 Allocate image structure.
391 assert(image != (Image *) NULL);
392 assert(image->signature == MagickCoreSignature);
393 if (image->debug != MagickFalse)
394 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
395 image->next=AcquireImage(image_info,exception);
396 if (GetNextImageInList(image) == (Image *) NULL)
398 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
400 if (image_info != (ImageInfo *) NULL)
401 (void) CopyMagickString(GetNextImageInList(image)->filename,
402 image_info->filename,MagickPathExtent);
403 DestroyBlob(GetNextImageInList(image));
404 image->next->blob=ReferenceBlob(image->blob);
405 image->next->endian=image->endian;
406 image->next->scene=image->scene+1;
407 image->next->previous=image;
411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
415 % A p p e n d I m a g e s %
419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421 % AppendImages() takes all images from the current image pointer to the end
422 % of the image list and appends them to each other top-to-bottom if the
423 % stack parameter is true, otherwise left-to-right.
425 % The current gravity setting effects how the image is justified in the
428 % The format of the AppendImages method is:
430 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
431 % ExceptionInfo *exception)
433 % A description of each parameter follows:
435 % o images: the image sequence.
437 % o stack: A value other than 0 stacks the images top-to-bottom.
439 % o exception: return any errors or warnings in this structure.
442 MagickExport Image *AppendImages(const Image *images,
443 const MagickBooleanType stack,ExceptionInfo *exception)
445 #define AppendImageTag "Append/Image"
454 homogeneous_colorspace,
481 Compute maximum area of appended area.
483 assert(images != (Image *) NULL);
484 assert(images->signature == MagickCoreSignature);
485 if (images->debug != MagickFalse)
486 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
487 assert(exception != (ExceptionInfo *) NULL);
488 assert(exception->signature == MagickCoreSignature);
489 alpha_trait=images->alpha_trait;
491 width=images->columns;
494 homogeneous_colorspace=MagickTrue;
495 next=GetNextImageInList(images);
496 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
498 if (next->depth > depth)
500 if (next->colorspace != images->colorspace)
501 homogeneous_colorspace=MagickFalse;
502 if (next->alpha_trait != UndefinedPixelTrait)
503 alpha_trait=BlendPixelTrait;
505 if (stack != MagickFalse)
507 if (next->columns > width)
512 width+=next->columns;
513 if (next->rows > height)
519 append_image=CloneImage(images,width,height,MagickTrue,exception);
520 if (append_image == (Image *) NULL)
521 return((Image *) NULL);
522 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
524 append_image=DestroyImage(append_image);
525 return((Image *) NULL);
527 if (homogeneous_colorspace == MagickFalse)
528 (void) SetImageColorspace(append_image,sRGBColorspace,exception);
529 append_image->depth=depth;
530 append_image->alpha_trait=alpha_trait;
531 append_image->page=images->page;
532 (void) SetImageBackgroundColor(append_image,exception);
537 append_view=AcquireAuthenticCacheView(append_image,exception);
538 for (n=0; n < (MagickOffsetType) number_images; n++)
546 SetGeometry(append_image,&geometry);
547 GravityAdjustGeometry(next->columns,next->rows,next->gravity,&geometry);
548 if (stack != MagickFalse)
549 x_offset-=geometry.x;
551 y_offset-=geometry.y;
552 image_view=AcquireVirtualCacheView(next,exception);
553 #if defined(MAGICKCORE_OPENMP_SUPPORT)
554 #pragma omp parallel for schedule(static,4) shared(status) \
555 magick_chunk_threads(next,next,next->rows,1)
557 for (y=0; y < (ssize_t) next->rows; y++)
565 register const Quantum
574 if (status == MagickFalse)
576 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
577 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
578 next->columns,1,exception);
579 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
584 GetPixelInfo(next,&pixel);
585 for (x=0; x < (ssize_t) next->columns; x++)
587 if (GetPixelWriteMask(next,p) <= (QuantumRange/2))
589 SetPixelBackgoundColor(append_image,q);
590 p+=GetPixelChannels(next);
591 q+=GetPixelChannels(append_image);
594 GetPixelInfoPixel(next,p,&pixel);
595 SetPixelViaPixelInfo(append_image,&pixel,q);
596 p+=GetPixelChannels(next);
597 q+=GetPixelChannels(append_image);
599 sync=SyncCacheViewAuthenticPixels(append_view,exception);
600 if (sync == MagickFalse)
603 image_view=DestroyCacheView(image_view);
604 if (stack == MagickFalse)
606 x_offset+=(ssize_t) next->columns;
612 y_offset+=(ssize_t) next->rows;
614 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
615 if (proceed == MagickFalse)
617 next=GetNextImageInList(next);
619 append_view=DestroyCacheView(append_view);
620 if (status == MagickFalse)
621 append_image=DestroyImage(append_image);
622 return(append_image);
626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
630 % C a t c h I m a g e E x c e p t i o n %
634 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
636 % CatchImageException() returns if no exceptions are found in the image
637 % sequence, otherwise it determines the most severe exception and reports
638 % it as a warning or error depending on the severity.
640 % The format of the CatchImageException method is:
642 % ExceptionType CatchImageException(Image *image)
644 % A description of each parameter follows:
646 % o image: An image sequence.
649 MagickExport ExceptionType CatchImageException(Image *image)
657 assert(image != (const Image *) NULL);
658 assert(image->signature == MagickCoreSignature);
659 if (image->debug != MagickFalse)
660 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
661 exception=AcquireExceptionInfo();
662 CatchException(exception);
663 severity=exception->severity;
664 exception=DestroyExceptionInfo(exception);
669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
673 % C l i p I m a g e P a t h %
677 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
679 % ClipImagePath() sets the image clip mask based any clipping path information
682 % The format of the ClipImagePath method is:
684 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
685 % const MagickBooleanType inside,ExceptionInfo *exception)
687 % A description of each parameter follows:
689 % o image: the image.
691 % o pathname: name of clipping path resource. If name is preceded by #, use
692 % clipping path numbered by name.
694 % o inside: if non-zero, later operations take effect inside clipping path.
695 % Otherwise later operations take effect outside clipping path.
697 % o exception: return any errors or warnings in this structure.
701 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
703 return(ClipImagePath(image,"#1",MagickTrue,exception));
706 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
707 const MagickBooleanType inside,ExceptionInfo *exception)
709 #define ClipImagePathTag "ClipPath/Image"
723 assert(image != (const Image *) NULL);
724 assert(image->signature == MagickCoreSignature);
725 if (image->debug != MagickFalse)
726 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
727 assert(pathname != NULL);
728 property=AcquireString(pathname);
729 (void) FormatLocaleString(property,MagickPathExtent,"8BIM:1999,2998:%s",
731 value=GetImageProperty(image,property,exception);
732 property=DestroyString(property);
733 if (value == (const char *) NULL)
735 ThrowFileException(exception,OptionError,"NoClipPathDefined",
739 image_info=AcquireImageInfo();
740 (void) CopyMagickString(image_info->filename,image->filename,
742 (void) ConcatenateMagickString(image_info->filename,pathname,
744 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
745 image_info=DestroyImageInfo(image_info);
746 if (clip_mask == (Image *) NULL)
748 if (clip_mask->storage_class == PseudoClass)
750 (void) SyncImage(clip_mask,exception);
751 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
754 if (inside != MagickFalse)
755 (void) NegateImage(clip_mask,MagickFalse,exception);
756 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
757 "8BIM:1999,2998:%s\nPS",pathname);
758 (void) SetImageMask(image,WritePixelMask,clip_mask,exception);
759 clip_mask=DestroyImage(clip_mask);
764 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
768 % C l o n e I m a g e %
772 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
774 % CloneImage() copies an image and returns the copy as a new image object.
776 % If the specified columns and rows is 0, an exact copy of the image is
777 % returned, otherwise the pixel data is undefined and must be initialized
778 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
779 % failure, a NULL image is returned and exception describes the reason for the
782 % The format of the CloneImage method is:
784 % Image *CloneImage(const Image *image,const size_t columns,
785 % const size_t rows,const MagickBooleanType orphan,
786 % ExceptionInfo *exception)
788 % A description of each parameter follows:
790 % o image: the image.
792 % o columns: the number of columns in the cloned image.
794 % o rows: the number of rows in the cloned image.
796 % o detach: With a value other than 0, the cloned image is detached from
797 % its parent I/O stream.
799 % o exception: return any errors or warnings in this structure.
802 MagickExport Image *CloneImage(const Image *image,const size_t columns,
803 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
817 assert(image != (const Image *) NULL);
818 assert(image->signature == MagickCoreSignature);
819 if (image->debug != MagickFalse)
820 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
821 assert(exception != (ExceptionInfo *) NULL);
822 assert(exception->signature == MagickCoreSignature);
823 if ((image->columns == 0) || (image->rows == 0))
825 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
826 "NegativeOrZeroImageSize","`%s'",image->filename);
827 return((Image *) NULL);
829 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
830 if (clone_image == (Image *) NULL)
831 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
832 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
833 clone_image->signature=MagickCoreSignature;
834 clone_image->storage_class=image->storage_class;
835 clone_image->number_channels=image->number_channels;
836 clone_image->number_meta_channels=image->number_meta_channels;
837 clone_image->metacontent_extent=image->metacontent_extent;
838 clone_image->colorspace=image->colorspace;
839 clone_image->read_mask=image->read_mask;
840 clone_image->write_mask=image->write_mask;
841 clone_image->alpha_trait=image->alpha_trait;
842 clone_image->columns=image->columns;
843 clone_image->rows=image->rows;
844 clone_image->dither=image->dither;
845 clone_image->image_info=CloneImageInfo(image->image_info);
846 (void) CloneImageProfiles(clone_image,image);
847 (void) CloneImageProperties(clone_image,image);
848 (void) CloneImageArtifacts(clone_image,image);
849 GetTimerInfo(&clone_image->timer);
850 if (image->ascii85 != (void *) NULL)
851 Ascii85Initialize(clone_image);
852 clone_image->magick_columns=image->magick_columns;
853 clone_image->magick_rows=image->magick_rows;
854 clone_image->type=image->type;
855 clone_image->channel_mask=image->channel_mask;
856 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
857 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
859 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
860 (void) CopyMagickString(clone_image->filename,image->filename,
862 clone_image->progress_monitor=image->progress_monitor;
863 clone_image->client_data=image->client_data;
864 clone_image->reference_count=1;
865 clone_image->next=image->next;
866 clone_image->previous=image->previous;
867 clone_image->list=NewImageList();
868 if (detach == MagickFalse)
869 clone_image->blob=ReferenceBlob(image->blob);
872 clone_image->next=NewImageList();
873 clone_image->previous=NewImageList();
874 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
876 clone_image->ping=image->ping;
877 clone_image->debug=IsEventLogging();
878 clone_image->semaphore=AcquireSemaphoreInfo();
879 if (image->colormap != (PixelInfo *) NULL)
882 Allocate and copy the image colormap.
884 clone_image->colors=image->colors;
885 length=(size_t) image->colors;
886 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length+1,
887 sizeof(*clone_image->colormap));
888 if (clone_image->colormap == (PixelInfo *) NULL)
890 clone_image=DestroyImage(clone_image);
891 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
893 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
894 sizeof(*clone_image->colormap));
896 if ((columns == 0) || (rows == 0))
898 if (image->montage != (char *) NULL)
899 (void) CloneString(&clone_image->montage,image->montage);
900 if (image->directory != (char *) NULL)
901 (void) CloneString(&clone_image->directory,image->directory);
902 clone_image->cache=ReferencePixelCache(image->cache);
906 if (image->columns != 0)
907 scale=(double) columns/(double) image->columns;
908 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
909 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
910 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
912 if (image->rows != 0)
913 scale=(double) rows/(double) image->rows;
914 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
915 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
916 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
917 clone_image->cache=ClonePixelCache(image->cache);
918 if (SetImageExtent(clone_image,columns,rows,exception) == MagickFalse)
919 clone_image=DestroyImage(clone_image);
924 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
928 % C l o n e I m a g e I n f o %
932 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
934 % CloneImageInfo() makes a copy of the given image info structure. If
935 % NULL is specified, a new image info structure is created initialized to
938 % The format of the CloneImageInfo method is:
940 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
942 % A description of each parameter follows:
944 % o image_info: the image info.
947 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
952 clone_info=AcquireImageInfo();
953 if (image_info == (ImageInfo *) NULL)
955 clone_info->compression=image_info->compression;
956 clone_info->temporary=image_info->temporary;
957 clone_info->adjoin=image_info->adjoin;
958 clone_info->antialias=image_info->antialias;
959 clone_info->scene=image_info->scene;
960 clone_info->number_scenes=image_info->number_scenes;
961 clone_info->depth=image_info->depth;
962 (void) CloneString(&clone_info->size,image_info->size);
963 (void) CloneString(&clone_info->extract,image_info->extract);
964 (void) CloneString(&clone_info->scenes,image_info->scenes);
965 (void) CloneString(&clone_info->page,image_info->page);
966 clone_info->interlace=image_info->interlace;
967 clone_info->endian=image_info->endian;
968 clone_info->units=image_info->units;
969 clone_info->quality=image_info->quality;
970 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
971 (void) CloneString(&clone_info->server_name,image_info->server_name);
972 (void) CloneString(&clone_info->font,image_info->font);
973 (void) CloneString(&clone_info->texture,image_info->texture);
974 (void) CloneString(&clone_info->density,image_info->density);
975 clone_info->pointsize=image_info->pointsize;
976 clone_info->fuzz=image_info->fuzz;
977 clone_info->matte_color=image_info->matte_color;
978 clone_info->background_color=image_info->background_color;
979 clone_info->border_color=image_info->border_color;
980 clone_info->transparent_color=image_info->transparent_color;
981 clone_info->dither=image_info->dither;
982 clone_info->monochrome=image_info->monochrome;
983 clone_info->colorspace=image_info->colorspace;
984 clone_info->type=image_info->type;
985 clone_info->orientation=image_info->orientation;
986 clone_info->ping=image_info->ping;
987 clone_info->verbose=image_info->verbose;
988 clone_info->progress_monitor=image_info->progress_monitor;
989 clone_info->client_data=image_info->client_data;
990 clone_info->cache=image_info->cache;
991 if (image_info->cache != (void *) NULL)
992 clone_info->cache=ReferencePixelCache(image_info->cache);
993 if (image_info->profile != (void *) NULL)
994 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
995 image_info->profile);
996 SetImageInfoFile(clone_info,image_info->file);
997 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
998 clone_info->stream=image_info->stream;
999 clone_info->custom_stream=image_info->custom_stream;
1000 (void) CopyMagickString(clone_info->magick,image_info->magick,
1002 (void) CopyMagickString(clone_info->unique,image_info->unique,
1004 (void) CopyMagickString(clone_info->filename,image_info->filename,
1006 clone_info->channel=image_info->channel;
1007 (void) CloneImageOptions(clone_info,image_info);
1008 clone_info->debug=IsEventLogging();
1009 clone_info->signature=image_info->signature;
1014 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1018 % C o p y I m a g e P i x e l s %
1022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1024 % CopyImagePixels() copies pixels from the source image as defined by the
1025 % geometry the destination image at the specified offset.
1027 % The format of the CopyImagePixels method is:
1029 % MagickBooleanType CopyImagePixels(Image *image,const Image *source_image,
1030 % const RectangleInfo *geometry,const OffsetInfo *offset,
1031 % ExceptionInfo *exception);
1033 % A description of each parameter follows:
1035 % o image: the destination image.
1037 % o source_image: the source image.
1039 % o geometry: define the dimensions of the source pixel rectangle.
1041 % o offset: define the offset in the destination image.
1043 % o exception: return any errors or warnings in this structure.
1046 MagickExport MagickBooleanType CopyImagePixels(Image *image,
1047 const Image *source_image,const RectangleInfo *geometry,
1048 const OffsetInfo *offset,ExceptionInfo *exception)
1050 #define CopyImageTag "Copy/Image"
1065 assert(image != (Image *) NULL);
1066 if (image->debug != MagickFalse)
1067 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1068 assert(source_image != (Image *) NULL);
1069 assert(geometry != (RectangleInfo *) NULL);
1070 assert(offset != (OffsetInfo *) NULL);
1071 if ((offset->x < 0) || (offset->y < 0) ||
1072 ((ssize_t) (offset->x+geometry->width) > (ssize_t) image->columns) ||
1073 ((ssize_t) (offset->y+geometry->height) > (ssize_t) image->rows))
1074 ThrowBinaryException(OptionError,"GeometryDoesNotContainImage",
1076 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1077 return(MagickFalse);
1083 source_view=AcquireVirtualCacheView(source_image,exception);
1084 image_view=AcquireAuthenticCacheView(image,exception);
1085 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1086 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1087 magick_chunk_threads(image,source_image,geometry->height,1)
1089 for (y=0; y < (ssize_t) geometry->height; y++)
1094 register const Quantum
1103 if (status == MagickFalse)
1105 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1106 geometry->width,1,exception);
1107 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1108 geometry->width,1,exception);
1109 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1114 for (x=0; x < (ssize_t) geometry->width; x++)
1119 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1121 PixelChannel channel = GetPixelChannelChannel(image,i);
1122 PixelTrait traits = GetPixelChannelTraits(image,channel);
1123 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1124 if ((traits == UndefinedPixelTrait) ||
1125 ((traits & UpdatePixelTrait) == 0) ||
1126 (source_traits == UndefinedPixelTrait))
1128 SetPixelChannel(image,channel,p[i],q);
1130 p+=GetPixelChannels(source_image);
1131 q+=GetPixelChannels(image);
1133 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1134 if (sync == MagickFalse)
1136 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1141 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1142 #pragma omp critical (MagickCore_CopyImage)
1144 proceed=SetImageProgress(image,CopyImageTag,progress++,image->rows);
1145 if (proceed == MagickFalse)
1149 source_view=DestroyCacheView(source_view);
1150 image_view=DestroyCacheView(image_view);
1155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1159 % D e s t r o y I m a g e %
1163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1165 % DestroyImage() dereferences an image, deallocating memory associated with
1166 % the image if the reference count becomes zero.
1168 % The format of the DestroyImage method is:
1170 % Image *DestroyImage(Image *image)
1172 % A description of each parameter follows:
1174 % o image: the image.
1177 MagickExport Image *DestroyImage(Image *image)
1185 assert(image != (Image *) NULL);
1186 assert(image->signature == MagickCoreSignature);
1187 if (image->debug != MagickFalse)
1188 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1189 destroy=MagickFalse;
1190 LockSemaphoreInfo(image->semaphore);
1191 image->reference_count--;
1192 if (image->reference_count == 0)
1194 UnlockSemaphoreInfo(image->semaphore);
1195 if (destroy == MagickFalse)
1196 return((Image *) NULL);
1200 DestroyImagePixels(image);
1201 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1202 if (image->montage != (char *) NULL)
1203 image->montage=DestroyString(image->montage);
1204 if (image->directory != (char *) NULL)
1205 image->directory=DestroyString(image->directory);
1206 if (image->colormap != (PixelInfo *) NULL)
1207 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1208 if (image->geometry != (char *) NULL)
1209 image->geometry=DestroyString(image->geometry);
1210 DestroyImageProfiles(image);
1211 DestroyImageProperties(image);
1212 DestroyImageArtifacts(image);
1213 if (image->ascii85 != (Ascii85Info *) NULL)
1214 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1215 if (image->image_info != (ImageInfo *) NULL)
1216 image->image_info=DestroyImageInfo(image->image_info);
1218 if (image->semaphore != (SemaphoreInfo *) NULL)
1219 RelinquishSemaphoreInfo(&image->semaphore);
1220 image->signature=(~MagickCoreSignature);
1221 image=(Image *) RelinquishMagickMemory(image);
1226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1230 % D e s t r o y I m a g e I n f o %
1234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1236 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1239 % The format of the DestroyImageInfo method is:
1241 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1243 % A description of each parameter follows:
1245 % o image_info: the image info.
1248 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1250 assert(image_info != (ImageInfo *) NULL);
1251 assert(image_info->signature == MagickCoreSignature);
1252 if (image_info->debug != MagickFalse)
1253 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1254 image_info->filename);
1255 if (image_info->size != (char *) NULL)
1256 image_info->size=DestroyString(image_info->size);
1257 if (image_info->extract != (char *) NULL)
1258 image_info->extract=DestroyString(image_info->extract);
1259 if (image_info->scenes != (char *) NULL)
1260 image_info->scenes=DestroyString(image_info->scenes);
1261 if (image_info->page != (char *) NULL)
1262 image_info->page=DestroyString(image_info->page);
1263 if (image_info->sampling_factor != (char *) NULL)
1264 image_info->sampling_factor=DestroyString(
1265 image_info->sampling_factor);
1266 if (image_info->server_name != (char *) NULL)
1267 image_info->server_name=DestroyString(
1268 image_info->server_name);
1269 if (image_info->font != (char *) NULL)
1270 image_info->font=DestroyString(image_info->font);
1271 if (image_info->texture != (char *) NULL)
1272 image_info->texture=DestroyString(image_info->texture);
1273 if (image_info->density != (char *) NULL)
1274 image_info->density=DestroyString(image_info->density);
1275 if (image_info->cache != (void *) NULL)
1276 image_info->cache=DestroyPixelCache(image_info->cache);
1277 if (image_info->profile != (StringInfo *) NULL)
1278 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1279 image_info->profile);
1280 DestroyImageOptions(image_info);
1281 image_info->signature=(~MagickCoreSignature);
1282 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1291 + D i s a s s o c i a t e I m a g e S t r e a m %
1295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1297 % DisassociateImageStream() disassociates the image stream. It checks if the
1298 % blob of the specified image is referenced by other images. If the reference
1299 % count is higher then 1 a new blob is assigned to the specified image.
1301 % The format of the DisassociateImageStream method is:
1303 % void DisassociateImageStream(const Image *image)
1305 % A description of each parameter follows:
1307 % o image: the image.
1310 MagickExport void DisassociateImageStream(Image *image)
1312 assert(image != (Image *) NULL);
1313 assert(image->signature == MagickCoreSignature);
1314 if (image->debug != MagickFalse)
1315 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1316 DisassociateBlob(image);
1320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1324 % G e t I m a g e I n f o %
1328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1330 % GetImageInfo() initializes image_info to default values.
1332 % The format of the GetImageInfo method is:
1334 % void GetImageInfo(ImageInfo *image_info)
1336 % A description of each parameter follows:
1338 % o image_info: the image info.
1341 MagickExport void GetImageInfo(ImageInfo *image_info)
1350 File and image dimension members.
1352 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1353 assert(image_info != (ImageInfo *) NULL);
1354 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1355 image_info->adjoin=MagickTrue;
1356 image_info->interlace=NoInterlace;
1357 image_info->channel=DefaultChannels;
1358 image_info->quality=UndefinedCompressionQuality;
1359 image_info->antialias=MagickTrue;
1360 image_info->dither=MagickTrue;
1361 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1362 if (synchronize != (const char *) NULL)
1364 image_info->synchronize=IsStringTrue(synchronize);
1365 synchronize=DestroyString(synchronize);
1367 exception=AcquireExceptionInfo();
1368 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1369 &image_info->background_color,exception);
1370 (void) QueryColorCompliance(BorderColor,AllCompliance,
1371 &image_info->border_color,exception);
1372 (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
1374 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1375 &image_info->transparent_color,exception);
1376 exception=DestroyExceptionInfo(exception);
1377 image_info->debug=IsEventLogging();
1378 image_info->signature=MagickCoreSignature;
1382 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1386 % G e t I m a g e I n f o F i l e %
1390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1392 % GetImageInfoFile() returns the image info file member.
1394 % The format of the GetImageInfoFile method is:
1396 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1398 % A description of each parameter follows:
1400 % o image_info: the image info.
1403 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1405 return(image_info->file);
1409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1413 % G e t I m a g e M a s k %
1417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1419 % GetImageMask() returns the mask associated with the image.
1421 % The format of the GetImageMask method is:
1423 % Image *GetImageMask(const Image *image,const PixelMask type,
1424 % ExceptionInfo *exception)
1426 % A description of each parameter follows:
1428 % o image: the image.
1430 % o type: the mask type, ReadPixelMask or WritePixelMask.
1433 MagickExport Image *GetImageMask(const Image *image,const PixelMask type,
1434 ExceptionInfo *exception)
1452 assert(image != (Image *) NULL);
1453 if (image->debug != MagickFalse)
1454 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1455 assert(image->signature == MagickCoreSignature);
1456 mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1457 if (mask_image == (Image *) NULL)
1458 return((Image *) NULL);
1460 mask_image->alpha_trait=UndefinedPixelTrait;
1461 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1462 mask_image->read_mask=MagickFalse;
1463 image_view=AcquireVirtualCacheView(image,exception);
1464 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1465 for (y=0; y < (ssize_t) image->rows; y++)
1467 register const Quantum
1476 if (status == MagickFalse)
1478 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1479 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1481 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1486 for (x=0; x < (ssize_t) image->columns; x++)
1490 case WritePixelMask:
1492 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1497 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1501 p+=GetPixelChannels(image);
1502 q+=GetPixelChannels(mask_image);
1504 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1507 mask_view=DestroyCacheView(mask_view);
1508 image_view=DestroyCacheView(image_view);
1509 if (status == MagickFalse)
1510 mask_image=DestroyImage(mask_image);
1515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1519 + G e t I m a g e R e f e r e n c e C o u n t %
1523 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1525 % GetImageReferenceCount() returns the image reference count.
1527 % The format of the GetReferenceCount method is:
1529 % ssize_t GetImageReferenceCount(Image *image)
1531 % A description of each parameter follows:
1533 % o image: the image.
1536 MagickExport ssize_t GetImageReferenceCount(Image *image)
1541 assert(image != (Image *) NULL);
1542 assert(image->signature == MagickCoreSignature);
1543 if (image->debug != MagickFalse)
1544 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1545 LockSemaphoreInfo(image->semaphore);
1546 reference_count=image->reference_count;
1547 UnlockSemaphoreInfo(image->semaphore);
1548 return(reference_count);
1552 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1556 % 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 %
1560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1562 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1563 % image. A virtual pixel is any pixel access that is outside the boundaries
1564 % of the image cache.
1566 % The format of the GetImageVirtualPixelMethod() method is:
1568 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1570 % A description of each parameter follows:
1572 % o image: the image.
1575 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1577 assert(image != (Image *) NULL);
1578 assert(image->signature == MagickCoreSignature);
1579 if (image->debug != MagickFalse)
1580 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1581 return(GetPixelCacheVirtualMethod(image));
1585 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1589 % I n t e r p r e t I m a g e F i l e n a m e %
1593 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1595 % InterpretImageFilename() interprets embedded characters in an image filename.
1596 % The filename length is returned.
1598 % The format of the InterpretImageFilename method is:
1600 % size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1601 % const char *format,int value,char *filename,ExceptionInfo *exception)
1603 % A description of each parameter follows.
1605 % o image_info: the image info..
1607 % o image: the image.
1609 % o format: A filename describing the format to use to write the numeric
1610 % argument. Only the first numeric format identifier is replaced.
1612 % o value: Numeric value to substitute into format filename.
1614 % o filename: return the formatted filename in this character buffer.
1616 % o exception: return any errors or warnings in this structure.
1619 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1620 Image *image,const char *format,int value,char *filename,
1621 ExceptionInfo *exception)
1638 canonical=MagickFalse;
1640 (void) CopyMagickString(filename,format,MagickPathExtent);
1641 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1654 foo=(ssize_t) strtol(q,&q,10);
1666 (void) FormatLocaleString(filename+(p-format),(size_t)
1667 (MagickPathExtent-(p-format)),p,value);
1669 (void) ConcatenateMagickString(filename,q,MagickPathExtent);
1670 canonical=MagickTrue;
1679 pattern[MagickPathExtent];
1696 /* FUTURE: Compare update with code from InterpretImageProperties()
1697 Note that a 'filename:' property should not need depth recursion.
1699 if (strchr(p,']') == (char *) NULL)
1703 for (i=0; (i < (MagickPathExtent-1L)) && (*r != '\0'); i++)
1714 if (LocaleNCompare(pattern,"filename:",9) != 0)
1716 option=(const char *) NULL;
1717 if (image != (Image *) NULL)
1718 option=GetImageProperty(image,pattern,exception);
1719 if ((option == (const char *) NULL) && (image != (Image *) NULL))
1720 option=GetImageArtifact(image,pattern);
1721 if ((option == (const char *) NULL) &&
1722 (image_info != (ImageInfo *) NULL))
1723 option=GetImageOption(image_info,pattern);
1724 if (option == (const char *) NULL)
1729 (void) CopyMagickString(filename+(p-format-length),option,(size_t)
1730 (MagickPathExtent-(p-format-length)));
1731 length+=strlen(pattern)-1;
1733 (void) ConcatenateMagickString(filename,r+1,MagickPathExtent);
1734 canonical=MagickTrue;
1744 for (q=filename; *q != '\0'; q++)
1745 if ((*q == '%') && (*(q+1) == '%'))
1747 (void) CopyMagickString(q,q+1,(size_t) (MagickPathExtent-(q-filename)));
1748 canonical=MagickTrue;
1750 if (canonical == MagickFalse)
1751 (void) CopyMagickString(filename,format,MagickPathExtent);
1752 return(strlen(filename));
1756 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1760 % I s H i g h D y n a m i c R a n g e I m a g e %
1764 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1766 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1767 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1770 % The format of the IsHighDynamicRangeImage method is:
1772 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1773 % ExceptionInfo *exception)
1775 % A description of each parameter follows:
1777 % o image: the image.
1779 % o exception: return any errors or warnings in this structure.
1782 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1783 ExceptionInfo *exception)
1785 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1788 return(MagickFalse);
1799 assert(image != (Image *) NULL);
1800 assert(image->signature == MagickCoreSignature);
1801 if (image->debug != MagickFalse)
1802 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1804 image_view=AcquireVirtualCacheView(image,exception);
1805 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1806 #pragma omp parallel for schedule(static,4) shared(status) \
1807 magick_chunk_threads(image,image,image->rows,1)
1809 for (y=0; y < (ssize_t) image->rows; y++)
1811 register const Quantum
1817 if (status == MagickFalse)
1819 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1820 if (p == (const Quantum *) NULL)
1825 for (x=0; x < (ssize_t) image->columns; x++)
1830 if (GetPixelWriteMask(image,p) <= (QuantumRange/2))
1832 p+=GetPixelChannels(image);
1835 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1843 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1844 if (traits == UndefinedPixelTrait)
1846 pixel=(double) p[i];
1847 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1848 (pixel != (double) ((QuantumAny) pixel)))
1851 p+=GetPixelChannels(image);
1852 if (i < (ssize_t) GetPixelChannels(image))
1855 if (x < (ssize_t) image->columns)
1858 image_view=DestroyCacheView(image_view);
1859 return(status != MagickFalse ? MagickFalse : MagickTrue);
1864 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1868 % I s I m a g e O b j e c t %
1872 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1874 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1875 % set of image objects.
1877 % The format of the IsImageObject method is:
1879 % MagickBooleanType IsImageObject(const Image *image)
1881 % A description of each parameter follows:
1883 % o image: the image.
1886 MagickExport MagickBooleanType IsImageObject(const Image *image)
1888 register const Image
1891 assert(image != (Image *) NULL);
1892 if (image->debug != MagickFalse)
1893 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1894 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1895 if (p->signature != MagickCoreSignature)
1896 return(MagickFalse);
1901 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1905 % I s T a i n t I m a g e %
1909 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1911 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1912 % since it was first constituted.
1914 % The format of the IsTaintImage method is:
1916 % MagickBooleanType IsTaintImage(const Image *image)
1918 % A description of each parameter follows:
1920 % o image: the image.
1923 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1926 magick[MagickPathExtent],
1927 filename[MagickPathExtent];
1929 register const Image
1932 assert(image != (Image *) NULL);
1933 if (image->debug != MagickFalse)
1934 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1935 assert(image->signature == MagickCoreSignature);
1936 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1937 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1938 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1940 if (p->taint != MagickFalse)
1942 if (LocaleCompare(p->magick,magick) != 0)
1944 if (LocaleCompare(p->filename,filename) != 0)
1947 return(MagickFalse);
1951 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1955 % M o d i f y I m a g e %
1959 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1961 % ModifyImage() ensures that there is only a single reference to the image
1962 % to be modified, updating the provided image pointer to point to a clone of
1963 % the original image if necessary.
1965 % The format of the ModifyImage method is:
1967 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1969 % A description of each parameter follows:
1971 % o image: the image.
1973 % o exception: return any errors or warnings in this structure.
1976 MagickExport MagickBooleanType ModifyImage(Image **image,
1977 ExceptionInfo *exception)
1982 assert(image != (Image **) NULL);
1983 assert(*image != (Image *) NULL);
1984 assert((*image)->signature == MagickCoreSignature);
1985 if ((*image)->debug != MagickFalse)
1986 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1987 if (GetImageReferenceCount(*image) <= 1)
1989 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1990 LockSemaphoreInfo((*image)->semaphore);
1991 (*image)->reference_count--;
1992 UnlockSemaphoreInfo((*image)->semaphore);
1998 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2002 % N e w M a g i c k I m a g e %
2006 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2008 % NewMagickImage() creates a blank image canvas of the specified size and
2011 % The format of the NewMagickImage method is:
2013 % Image *NewMagickImage(const ImageInfo *image_info,const size_t width,
2014 % const size_t height,const PixelInfo *background,
2015 % ExceptionInfo *exception)
2017 % A description of each parameter follows:
2019 % o image: the image.
2021 % o width: the image width.
2023 % o height: the image height.
2025 % o background: the image color.
2027 % o exception: return any errors or warnings in this structure.
2030 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2031 const size_t width,const size_t height,const PixelInfo *background,
2032 ExceptionInfo *exception)
2046 assert(image_info != (const ImageInfo *) NULL);
2047 if (image_info->debug != MagickFalse)
2048 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2049 assert(image_info->signature == MagickCoreSignature);
2050 assert(background != (const PixelInfo *) NULL);
2051 image=AcquireImage(image_info,exception);
2052 image->columns=width;
2054 image->colorspace=background->colorspace;
2055 image->alpha_trait=background->alpha_trait;
2056 image->fuzz=background->fuzz;
2057 image->depth=background->depth;
2059 image_view=AcquireAuthenticCacheView(image,exception);
2060 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2061 #pragma omp parallel for schedule(static,4) shared(status) \
2062 magick_chunk_threads(image,image,image->rows,1)
2064 for (y=0; y < (ssize_t) image->rows; y++)
2072 if (status == MagickFalse)
2074 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2075 if (q == (Quantum *) NULL)
2080 for (x=0; x < (ssize_t) image->columns; x++)
2082 SetPixelViaPixelInfo(image,background,q);
2083 q+=GetPixelChannels(image);
2085 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2088 image_view=DestroyCacheView(image_view);
2089 if (status == MagickFalse)
2090 image=DestroyImage(image);
2095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2099 % R e f e r e n c e I m a g e %
2103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2105 % ReferenceImage() increments the reference count associated with an image
2106 % returning a pointer to the image.
2108 % The format of the ReferenceImage method is:
2110 % Image *ReferenceImage(Image *image)
2112 % A description of each parameter follows:
2114 % o image: the image.
2117 MagickExport Image *ReferenceImage(Image *image)
2119 assert(image != (Image *) NULL);
2120 if (image->debug != MagickFalse)
2121 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2122 assert(image->signature == MagickCoreSignature);
2123 LockSemaphoreInfo(image->semaphore);
2124 image->reference_count++;
2125 UnlockSemaphoreInfo(image->semaphore);
2130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2134 % R e s e t I m a g e P a g e %
2138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2140 % ResetImagePage() resets the image page canvas and position.
2142 % The format of the ResetImagePage method is:
2144 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2146 % A description of each parameter follows:
2148 % o image: the image.
2150 % o page: the relative page specification.
2153 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2161 assert(image != (Image *) NULL);
2162 assert(image->signature == MagickCoreSignature);
2163 if (image->debug != MagickFalse)
2164 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2165 flags=ParseAbsoluteGeometry(page,&geometry);
2166 if ((flags & WidthValue) != 0)
2168 if ((flags & HeightValue) == 0)
2169 geometry.height=geometry.width;
2170 image->page.width=geometry.width;
2171 image->page.height=geometry.height;
2173 if ((flags & AspectValue) != 0)
2175 if ((flags & XValue) != 0)
2176 image->page.x+=geometry.x;
2177 if ((flags & YValue) != 0)
2178 image->page.y+=geometry.y;
2182 if ((flags & XValue) != 0)
2184 image->page.x=geometry.x;
2185 if ((image->page.width == 0) && (geometry.x > 0))
2186 image->page.width=image->columns+geometry.x;
2188 if ((flags & YValue) != 0)
2190 image->page.y=geometry.y;
2191 if ((image->page.height == 0) && (geometry.y > 0))
2192 image->page.height=image->rows+geometry.y;
2199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2203 % S e t I m a g e A l p h a %
2207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2209 % SetImageAlpha() sets the alpha levels of the image.
2211 % The format of the SetImageAlpha method is:
2213 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
2214 % ExceptionInfo *exception)
2216 % A description of each parameter follows:
2218 % o image: the image.
2220 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
2221 % fully transparent.
2224 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
2225 ExceptionInfo *exception)
2236 assert(image != (Image *) NULL);
2237 if (image->debug != MagickFalse)
2238 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2239 assert(image->signature == MagickCoreSignature);
2240 image->alpha_trait=BlendPixelTrait;
2242 image_view=AcquireAuthenticCacheView(image,exception);
2243 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2244 #pragma omp parallel for schedule(static,4) shared(status) \
2245 magick_chunk_threads(image,image,image->rows,1)
2247 for (y=0; y < (ssize_t) image->rows; y++)
2255 if (status == MagickFalse)
2257 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2258 if (q == (Quantum *) NULL)
2263 for (x=0; x < (ssize_t) image->columns; x++)
2265 if (GetPixelWriteMask(image,q) > (QuantumRange/2))
2266 SetPixelAlpha(image,alpha,q);
2267 q+=GetPixelChannels(image);
2269 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2272 image_view=DestroyCacheView(image_view);
2277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2281 % S e t I m a g e B a c k g r o u n d C o l o r %
2285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2287 % SetImageBackgroundColor() initializes the image pixels to the image
2288 % background color. The background color is defined by the background_color
2289 % member of the image structure.
2291 % The format of the SetImage method is:
2293 % MagickBooleanType SetImageBackgroundColor(Image *image,
2294 % ExceptionInfo *exception)
2296 % A description of each parameter follows:
2298 % o image: the image.
2300 % o exception: return any errors or warnings in this structure.
2303 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2304 ExceptionInfo *exception)
2318 assert(image != (Image *) NULL);
2319 if (image->debug != MagickFalse)
2320 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2321 assert(image->signature == MagickCoreSignature);
2322 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2323 return(MagickFalse);
2324 if ((image->background_color.alpha != OpaqueAlpha) &&
2325 (image->alpha_trait == UndefinedPixelTrait))
2326 (void) SetImageAlphaChannel(image,OnAlphaChannel,exception);
2327 ConformPixelInfo(image,&image->background_color,&background,exception);
2329 Set image background color.
2332 image_view=AcquireAuthenticCacheView(image,exception);
2333 for (y=0; y < (ssize_t) image->rows; y++)
2341 if (status == MagickFalse)
2343 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2344 if (q == (Quantum *) NULL)
2349 for (x=0; x < (ssize_t) image->columns; x++)
2351 SetPixelViaPixelInfo(image,&background,q);
2352 q+=GetPixelChannels(image);
2354 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2357 image_view=DestroyCacheView(image_view);
2362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2366 % S e t I m a g e C h a n n e l M a s k %
2370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2372 % SetImageChannelMask() sets the image channel mask from the specified channel
2375 % The format of the SetImageChannelMask method is:
2377 % ChannelType SetImageChannelMask(Image *image,
2378 % const ChannelType channel_mask)
2380 % A description of each parameter follows:
2382 % o image: the image.
2384 % o channel_mask: the channel mask.
2387 MagickExport ChannelType SetImageChannelMask(Image *image,
2388 const ChannelType channel_mask)
2390 return(SetPixelChannelMask(image,channel_mask));
2394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2398 % S e t I m a g e C o l o r %
2402 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2404 % SetImageColor() set the entire image canvas to the specified color.
2406 % The format of the SetImageColor method is:
2408 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2409 % ExeptionInfo *exception)
2411 % A description of each parameter follows:
2413 % o image: the image.
2415 % o background: the image color.
2417 % o exception: return any errors or warnings in this structure.
2420 MagickExport MagickBooleanType SetImageColor(Image *image,
2421 const PixelInfo *color,ExceptionInfo *exception)
2432 assert(image != (Image *) NULL);
2433 if (image->debug != MagickFalse)
2434 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2435 assert(image->signature == MagickCoreSignature);
2436 assert(color != (const PixelInfo *) NULL);
2437 image->colorspace=color->colorspace;
2438 image->alpha_trait=color->alpha_trait;
2439 image->fuzz=color->fuzz;
2440 image->depth=color->depth;
2442 image_view=AcquireAuthenticCacheView(image,exception);
2443 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2444 #pragma omp parallel for schedule(static,4) shared(status) \
2445 magick_chunk_threads(image,image,image->rows,1)
2447 for (y=0; y < (ssize_t) image->rows; y++)
2455 if (status == MagickFalse)
2457 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2458 if (q == (Quantum *) NULL)
2463 for (x=0; x < (ssize_t) image->columns; x++)
2465 SetPixelViaPixelInfo(image,color,q);
2466 q+=GetPixelChannels(image);
2468 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2471 image_view=DestroyCacheView(image_view);
2476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2480 % S e t I m a g e S t o r a g e C l a s s %
2484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2486 % SetImageStorageClass() sets the image class: DirectClass for true color
2487 % images or PseudoClass for colormapped images.
2489 % The format of the SetImageStorageClass method is:
2491 % MagickBooleanType SetImageStorageClass(Image *image,
2492 % const ClassType storage_class,ExceptionInfo *exception)
2494 % A description of each parameter follows:
2496 % o image: the image.
2498 % o storage_class: The image class.
2500 % o exception: return any errors or warnings in this structure.
2503 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2504 const ClassType storage_class,ExceptionInfo *exception)
2506 assert(image != (Image *) NULL);
2507 assert(image->signature == MagickCoreSignature);
2508 if (image->debug != MagickFalse)
2509 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2510 assert(exception != (ExceptionInfo *) NULL);
2511 assert(exception->signature == MagickCoreSignature);
2512 image->storage_class=storage_class;
2513 return(SyncImagePixelCache(image,exception));
2517 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2521 % S e t I m a g e E x t e n t %
2525 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2527 % SetImageExtent() sets the image size (i.e. columns & rows).
2529 % The format of the SetImageExtent method is:
2531 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2532 % const size_t rows,ExceptionInfo *exception)
2534 % A description of each parameter follows:
2536 % o image: the image.
2538 % o columns: The image width in pixels.
2540 % o rows: The image height in pixels.
2542 % o exception: return any errors or warnings in this structure.
2545 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2546 const size_t rows,ExceptionInfo *exception)
2548 if ((columns == 0) || (rows == 0))
2549 ThrowBinaryException(ImageError,"NegativeOrZeroImageSize",image->filename);
2550 image->columns=columns;
2552 if (image->depth > (8*sizeof(MagickSizeType)))
2553 ThrowBinaryException(ImageError,"ImageDepthNotSupported",image->filename);
2554 return(SyncImagePixelCache(image,exception));
2558 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2562 + S e t I m a g e I n f o %
2566 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2568 % SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
2569 % It is set to a type of image format based on the prefix or suffix of the
2570 % filename. For example, 'ps:image' returns PS indicating a Postscript image.
2571 % JPEG is returned for this filename: 'image.jpg'. The filename prefix has
2572 % precendence over the suffix. Use an optional index enclosed in brackets
2573 % after a file name to specify a desired scene of a multi-resolution image
2574 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2575 % indicates success.
2577 % The format of the SetImageInfo method is:
2579 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2580 % const unsigned int frames,ExceptionInfo *exception)
2582 % A description of each parameter follows:
2584 % o image_info: the image info.
2586 % o frames: the number of images you intend to write.
2588 % o exception: return any errors or warnings in this structure.
2591 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2592 const unsigned int frames,ExceptionInfo *exception)
2595 component[MagickPathExtent],
2596 magic[MagickPathExtent],
2621 Look for 'image.format' in filename.
2623 assert(image_info != (ImageInfo *) NULL);
2624 assert(image_info->signature == MagickCoreSignature);
2625 if (image_info->debug != MagickFalse)
2626 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2627 image_info->filename);
2629 GetPathComponent(image_info->filename,SubimagePath,component);
2630 if (*component != '\0')
2633 Look for scene specification (e.g. img0001.pcd[4]).
2635 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2637 if (IsGeometry(component) != MagickFalse)
2638 (void) CloneString(&image_info->extract,component);
2646 (void) CloneString(&image_info->scenes,component);
2647 image_info->scene=StringToUnsignedLong(image_info->scenes);
2648 image_info->number_scenes=image_info->scene;
2649 p=image_info->scenes;
2650 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2652 while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2654 first=(size_t) strtol(p,&q,10);
2656 while (isspace((int) ((unsigned char) *q)) != 0)
2659 last=(size_t) strtol(q+1,&q,10);
2662 if (first < image_info->scene)
2663 image_info->scene=first;
2664 if (last > image_info->number_scenes)
2665 image_info->number_scenes=last;
2668 image_info->number_scenes-=image_info->scene-1;
2672 if (*image_info->magick == '\0')
2673 GetPathComponent(image_info->filename,ExtensionPath,component);
2674 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2675 if (*component != '\0')
2676 if ((LocaleCompare(component,"gz") == 0) ||
2677 (LocaleCompare(component,"Z") == 0) ||
2678 (LocaleCompare(component,"svgz") == 0) ||
2679 (LocaleCompare(component,"wmz") == 0))
2682 path[MagickPathExtent];
2684 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2685 path[strlen(path)-strlen(component)-1]='\0';
2686 GetPathComponent(path,ExtensionPath,component);
2689 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2690 if (*component != '\0')
2691 if (LocaleCompare(component,"bz2") == 0)
2694 path[MagickPathExtent];
2696 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2697 path[strlen(path)-strlen(component)-1]='\0';
2698 GetPathComponent(path,ExtensionPath,component);
2701 image_info->affirm=MagickFalse;
2702 sans_exception=AcquireExceptionInfo();
2703 if (*component != '\0')
2712 *format_type_formats[] =
2734 User specified image format.
2736 (void) CopyMagickString(magic,component,MagickPathExtent);
2739 Look for explicit image formats.
2741 format_type=UndefinedFormatType;
2742 magick_info=GetMagickInfo(magic,sans_exception);
2743 if ((magick_info != (const MagickInfo *) NULL) &&
2744 (magick_info->format_type != UndefinedFormatType))
2745 format_type=magick_info->format_type;
2747 while ((format_type == UndefinedFormatType) &&
2748 (format_type_formats[i] != (char *) NULL))
2750 if ((*magic == *format_type_formats[i]) &&
2751 (LocaleCompare(magic,format_type_formats[i]) == 0))
2752 format_type=ExplicitFormatType;
2755 if (format_type == UndefinedFormatType)
2756 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2758 if (format_type == ExplicitFormatType)
2760 image_info->affirm=MagickTrue;
2761 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2763 if (LocaleCompare(magic,"RGB") == 0)
2764 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2767 Look for explicit 'format:image' in filename.
2770 GetPathComponent(image_info->filename,MagickPath,magic);
2773 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2774 magick_info=GetMagickInfo(magic,sans_exception);
2775 GetPathComponent(image_info->filename,CanonicalPath,component);
2776 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2784 User specified image format.
2787 magick_info=GetMagickInfo(magic,sans_exception);
2788 delegate_info=GetDelegateInfo(magic,"*",sans_exception);
2789 if (delegate_info == (const DelegateInfo *) NULL)
2790 delegate_info=GetDelegateInfo("*",magic,sans_exception);
2791 if (((magick_info != (const MagickInfo *) NULL) ||
2792 (delegate_info != (const DelegateInfo *) NULL)) &&
2793 (IsMagickConflict(magic) == MagickFalse))
2795 image_info->affirm=MagickTrue;
2796 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2797 GetPathComponent(image_info->filename,CanonicalPath,component);
2798 (void) CopyMagickString(image_info->filename,component,
2802 sans_exception=DestroyExceptionInfo(sans_exception);
2803 if ((magick_info == (const MagickInfo *) NULL) ||
2804 (GetMagickEndianSupport(magick_info) == MagickFalse))
2805 image_info->endian=UndefinedEndian;
2806 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2809 Test for multiple image support (e.g. image%02d.png).
2811 (void) InterpretImageFilename(image_info,(Image *) NULL,
2812 image_info->filename,(int) image_info->scene,component,exception);
2813 if ((LocaleCompare(component,image_info->filename) != 0) &&
2814 (strchr(component,'%') == (char *) NULL))
2815 image_info->adjoin=MagickFalse;
2817 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2820 Some image formats do not support multiple frames per file.
2822 magick_info=GetMagickInfo(magic,exception);
2823 if (magick_info != (const MagickInfo *) NULL)
2824 if (GetMagickAdjoin(magick_info) == MagickFalse)
2825 image_info->adjoin=MagickFalse;
2827 if (image_info->affirm != MagickFalse)
2838 Determine the image format from the first few bytes of the file.
2840 magick_size=GetMagicPatternExtent(exception);
2841 if (magick_size == 0)
2842 return(MagickFalse);
2843 image=AcquireImage(image_info,exception);
2844 (void) CopyMagickString(image->filename,image_info->filename,
2846 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2847 if (status == MagickFalse)
2849 image=DestroyImage(image);
2850 return(MagickFalse);
2852 if ((IsBlobSeekable(image) == MagickFalse) ||
2853 (IsBlobExempt(image) != MagickFalse))
2856 Copy standard input or pipe to temporary file.
2859 status=ImageToFile(image,component,exception);
2860 (void) CloseBlob(image);
2861 if (status == MagickFalse)
2863 image=DestroyImage(image);
2864 return(MagickFalse);
2866 SetImageInfoFile(image_info,(FILE *) NULL);
2867 (void) CopyMagickString(image->filename,component,MagickPathExtent);
2868 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2869 if (status == MagickFalse)
2871 image=DestroyImage(image);
2872 return(MagickFalse);
2874 (void) CopyMagickString(image_info->filename,component,
2876 image_info->temporary=MagickTrue;
2878 magick=(unsigned char *) AcquireMagickMemory(magick_size);
2879 if (magick == (unsigned char *) NULL)
2881 (void) CloseBlob(image);
2882 image=DestroyImage(image);
2883 return(MagickFalse);
2885 (void) ResetMagickMemory(magick,0,magick_size);
2886 count=ReadBlob(image,magick_size,magick);
2887 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
2888 (void) CloseBlob(image);
2889 image=DestroyImage(image);
2891 Check magic.xml configuration file.
2893 sans_exception=AcquireExceptionInfo();
2894 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
2895 magick=(unsigned char *) RelinquishMagickMemory(magick);
2896 if ((magic_info != (const MagicInfo *) NULL) &&
2897 (GetMagicName(magic_info) != (char *) NULL))
2900 Try to use magick_info that was determined earlier by the extension
2902 if ((magick_info != (const MagickInfo *) NULL) &&
2903 (GetMagickUseExtension(magick_info) != MagickFalse) &&
2904 (LocaleCompare(magick_info->module,GetMagicName(
2906 (void) CopyMagickString(image_info->magick,magick_info->name,
2910 (void) CopyMagickString(image_info->magick,GetMagicName(
2911 magic_info),MagickPathExtent);
2912 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2914 if ((magick_info == (const MagickInfo *) NULL) ||
2915 (GetMagickEndianSupport(magick_info) == MagickFalse))
2916 image_info->endian=UndefinedEndian;
2917 sans_exception=DestroyExceptionInfo(sans_exception);
2920 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2921 if ((magick_info == (const MagickInfo *) NULL) ||
2922 (GetMagickEndianSupport(magick_info) == MagickFalse))
2923 image_info->endian=UndefinedEndian;
2924 sans_exception=DestroyExceptionInfo(sans_exception);
2930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2934 % S e t I m a g e I n f o B l o b %
2938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2940 % SetImageInfoBlob() sets the image info blob member.
2942 % The format of the SetImageInfoBlob method is:
2944 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2945 % const size_t length)
2947 % A description of each parameter follows:
2949 % o image_info: the image info.
2953 % o length: the blob length.
2956 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2957 const size_t length)
2959 assert(image_info != (ImageInfo *) NULL);
2960 assert(image_info->signature == MagickCoreSignature);
2961 if (image_info->debug != MagickFalse)
2962 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2963 image_info->filename);
2964 image_info->blob=(void *) blob;
2965 image_info->length=length;
2969 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2973 % S e t I m a g e I n f o C u s t o m S t r e a m %
2977 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2979 % SetImageInfoCustomStream() sets the image info custom stream handlers.
2981 % The format of the SetImageInfoCustomStream method is:
2983 % void SetImageInfoCustomStream(ImageInfo *image_info,
2984 % CustomStreamInfo *custom_stream)
2986 % A description of each parameter follows:
2988 % o image_info: the image info.
2990 % o custom_stream: your custom stream methods.
2993 MagickExport void SetImageInfoCustomStream(ImageInfo *image_info,
2994 CustomStreamInfo *custom_stream)
2996 assert(image_info != (ImageInfo *) NULL);
2997 assert(image_info->signature == MagickCoreSignature);
2998 if (image_info->debug != MagickFalse)
2999 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3000 image_info->filename);
3001 image_info->custom_stream=(CustomStreamInfo *) custom_stream;
3005 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3009 % S e t I m a g e I n f o F i l e %
3013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3015 % SetImageInfoFile() sets the image info file member.
3017 % The format of the SetImageInfoFile method is:
3019 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3021 % A description of each parameter follows:
3023 % o image_info: the image info.
3028 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3030 assert(image_info != (ImageInfo *) NULL);
3031 assert(image_info->signature == MagickCoreSignature);
3032 if (image_info->debug != MagickFalse)
3033 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3034 image_info->filename);
3035 image_info->file=file;
3039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3043 % S e t I m a g e M a s k %
3047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3049 % SetImageMask() associates a mask with the image. The mask must be the same
3050 % dimensions as the image.
3052 % The format of the SetImageMask method is:
3054 % MagickBooleanType SetImageMask(Image *image,const PixelMask type,
3055 % const Image *mask,ExceptionInfo *exception)
3057 % A description of each parameter follows:
3059 % o image: the image.
3061 % o type: the mask type, ReadPixelMask or WritePixelMask.
3063 % o mask: the image mask.
3065 % o exception: return any errors or warnings in this structure.
3068 MagickExport MagickBooleanType SetImageMask(Image *image,const PixelMask type,
3069 const Image *mask,ExceptionInfo *exception)
3084 assert(image != (Image *) NULL);
3085 if (image->debug != MagickFalse)
3086 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3087 assert(image->signature == MagickCoreSignature);
3088 if (mask == (const Image *) NULL)
3092 case WritePixelMask: image->write_mask=MagickFalse; break;
3093 default: image->read_mask=MagickFalse; break;
3095 return(SyncImagePixelCache(image,exception));
3099 case WritePixelMask: image->write_mask=MagickTrue; break;
3100 default: image->read_mask=MagickTrue; break;
3102 if (SyncImagePixelCache(image,exception) == MagickFalse)
3103 return(MagickFalse);
3105 mask_view=AcquireVirtualCacheView(mask,exception);
3106 image_view=AcquireAuthenticCacheView(image,exception);
3107 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3108 #pragma omp parallel for schedule(static,4) shared(status) \
3109 magick_chunk_threads(mask,image,1,1)
3111 for (y=0; y < (ssize_t) image->rows; y++)
3113 register const Quantum
3122 if (status == MagickFalse)
3124 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3125 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3126 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3131 for (x=0; x < (ssize_t) image->columns; x++)
3137 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3138 intensity=GetPixelIntensity(mask,p);
3141 case WritePixelMask:
3143 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3148 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3152 p+=GetPixelChannels(mask);
3153 q+=GetPixelChannels(image);
3155 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3158 mask_view=DestroyCacheView(mask_view);
3159 image_view=DestroyCacheView(image_view);
3164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3168 % S e t I m a g e R e g i o n M a s k %
3172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3174 % SetImageRegionMask() associates a mask with the image as defined by the
3177 % The format of the SetImageRegionMask method is:
3179 % MagickBooleanType SetImageRegionMask(Image *image,const PixelMask type,
3180 % const RectangleInfo *region,ExceptionInfo *exception)
3182 % A description of each parameter follows:
3184 % o image: the image.
3186 % o type: the mask type, ReadPixelMask or WritePixelMask.
3188 % o geometry: the mask region.
3190 % o exception: return any errors or warnings in this structure.
3193 MagickExport MagickBooleanType SetImageRegionMask(Image *image,
3194 const PixelMask type,const RectangleInfo *region,ExceptionInfo *exception)
3206 Set image mask as defined by the region.
3208 assert(image != (Image *) NULL);
3209 if (image->debug != MagickFalse)
3210 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3211 assert(image->signature == MagickCoreSignature);
3212 if (region == (const RectangleInfo *) NULL)
3216 case WritePixelMask: image->write_mask=MagickFalse; break;
3217 default: image->read_mask=MagickFalse; break;
3219 return(SyncImagePixelCache(image,exception));
3223 case WritePixelMask: image->write_mask=MagickTrue; break;
3224 default: image->read_mask=MagickTrue; break;
3226 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
3227 return(MagickFalse);
3229 image_view=AcquireAuthenticCacheView(image,exception);
3230 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3231 #pragma omp parallel for schedule(static,4) shared(status) \
3232 magick_number_threads(image,image,2)
3234 for (y=0; y < (ssize_t) image->rows; y++)
3242 if (status == MagickFalse)
3244 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3245 if (q == (Quantum *) NULL)
3250 for (x=0; x < (ssize_t) image->columns; x++)
3256 if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3257 ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3261 case WritePixelMask:
3263 SetPixelWriteMask(image,pixel,q);
3268 SetPixelReadMask(image,pixel,q);
3272 q+=GetPixelChannels(image);
3274 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3277 image_view=DestroyCacheView(image_view);
3282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3286 % 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 %
3290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3292 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3293 % image and returns the previous setting. A virtual pixel is any pixel access
3294 % that is outside the boundaries of the image cache.
3296 % The format of the SetImageVirtualPixelMethod() method is:
3298 % VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3299 % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3301 % A description of each parameter follows:
3303 % o image: the image.
3305 % o virtual_pixel_method: choose the type of virtual pixel.
3307 % o exception: return any errors or warnings in this structure.
3310 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3311 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3313 assert(image != (const Image *) NULL);
3314 assert(image->signature == MagickCoreSignature);
3315 if (image->debug != MagickFalse)
3316 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3317 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3325 % S m u s h I m a g e s %
3329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3331 % SmushImages() takes all images from the current image pointer to the end
3332 % of the image list and smushes them to each other top-to-bottom if the
3333 % stack parameter is true, otherwise left-to-right.
3335 % The current gravity setting now effects how the image is justified in the
3338 % The format of the SmushImages method is:
3340 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3341 % ExceptionInfo *exception)
3343 % A description of each parameter follows:
3345 % o images: the image sequence.
3347 % o stack: A value other than 0 stacks the images top-to-bottom.
3349 % o offset: minimum distance in pixels between images.
3351 % o exception: return any errors or warnings in this structure.
3355 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3356 const ssize_t offset,ExceptionInfo *exception)
3370 register const Quantum
3383 if (images->previous == (Image *) NULL)
3386 SetGeometry(smush_image,&right_geometry);
3387 GravityAdjustGeometry(right_image->columns,right_image->rows,
3388 right_image->gravity,&right_geometry);
3389 left_image=images->previous;
3390 SetGeometry(smush_image,&left_geometry);
3391 GravityAdjustGeometry(left_image->columns,left_image->rows,
3392 left_image->gravity,&left_geometry);
3393 gap=right_image->columns;
3394 left_view=AcquireVirtualCacheView(left_image,exception);
3395 right_view=AcquireVirtualCacheView(right_image,exception);
3396 for (y=0; y < (ssize_t) smush_image->rows; y++)
3398 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3400 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3401 if ((p == (const Quantum *) NULL) ||
3402 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3403 ((left_image->columns-x-1) >= gap))
3406 i=(ssize_t) left_image->columns-x-1;
3407 for (x=0; x < (ssize_t) right_image->columns; x++)
3409 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3411 if ((p == (const Quantum *) NULL) ||
3412 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3413 ((x+i) >= (ssize_t) gap))
3416 if ((x+i) < (ssize_t) gap)
3419 right_view=DestroyCacheView(right_view);
3420 left_view=DestroyCacheView(left_view);
3421 if (y < (ssize_t) smush_image->rows)
3423 return((ssize_t) gap-offset);
3426 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3427 const ssize_t offset,ExceptionInfo *exception)
3441 register const Quantum
3454 if (images->previous == (Image *) NULL)
3456 bottom_image=images;
3457 SetGeometry(smush_image,&bottom_geometry);
3458 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3459 bottom_image->gravity,&bottom_geometry);
3460 top_image=images->previous;
3461 SetGeometry(smush_image,&top_geometry);
3462 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3464 gap=bottom_image->rows;
3465 top_view=AcquireVirtualCacheView(top_image,exception);
3466 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3467 for (x=0; x < (ssize_t) smush_image->columns; x++)
3469 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3471 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3472 if ((p == (const Quantum *) NULL) ||
3473 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3474 ((top_image->rows-y-1) >= gap))
3477 i=(ssize_t) top_image->rows-y-1;
3478 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3480 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3482 if ((p == (const Quantum *) NULL) ||
3483 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3484 ((y+i) >= (ssize_t) gap))
3487 if ((y+i) < (ssize_t) gap)
3490 bottom_view=DestroyCacheView(bottom_view);
3491 top_view=DestroyCacheView(top_view);
3492 if (x < (ssize_t) smush_image->columns)
3494 return((ssize_t) gap-offset);
3497 MagickExport Image *SmushImages(const Image *images,
3498 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3500 #define SmushImageTag "Smush/Image"
3521 register const Image
3534 Compute maximum area of smushed area.
3536 assert(images != (Image *) NULL);
3537 assert(images->signature == MagickCoreSignature);
3538 if (images->debug != MagickFalse)
3539 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3540 assert(exception != (ExceptionInfo *) NULL);
3541 assert(exception->signature == MagickCoreSignature);
3543 alpha_trait=image->alpha_trait;
3545 width=image->columns;
3547 next=GetNextImageInList(image);
3548 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3550 if (next->alpha_trait != UndefinedPixelTrait)
3551 alpha_trait=BlendPixelTrait;
3553 if (stack != MagickFalse)
3555 if (next->columns > width)
3556 width=next->columns;
3558 if (next->previous != (Image *) NULL)
3562 width+=next->columns;
3563 if (next->previous != (Image *) NULL)
3565 if (next->rows > height)
3571 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3572 if (smush_image == (Image *) NULL)
3573 return((Image *) NULL);
3574 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3576 smush_image=DestroyImage(smush_image);
3577 return((Image *) NULL);
3579 smush_image->alpha_trait=alpha_trait;
3580 (void) SetImageBackgroundColor(smush_image,exception);
3584 for (n=0; n < (MagickOffsetType) number_images; n++)
3586 SetGeometry(smush_image,&geometry);
3587 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3588 if (stack != MagickFalse)
3590 x_offset-=geometry.x;
3591 y_offset-=SmushYGap(smush_image,image,offset,exception);
3595 x_offset-=SmushXGap(smush_image,image,offset,exception);
3596 y_offset-=geometry.y;
3598 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3599 y_offset,exception);
3600 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3601 if (proceed == MagickFalse)
3603 if (stack == MagickFalse)
3605 x_offset+=(ssize_t) image->columns;
3611 y_offset+=(ssize_t) image->rows;
3613 image=GetNextImageInList(image);
3615 if (stack == MagickFalse)
3616 smush_image->columns=(size_t) x_offset;
3618 smush_image->rows=(size_t) y_offset;
3619 if (status == MagickFalse)
3620 smush_image=DestroyImage(smush_image);
3621 return(smush_image);
3625 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3629 % S t r i p I m a g e %
3633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3635 % StripImage() strips an image of all profiles and comments.
3637 % The format of the StripImage method is:
3639 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3641 % A description of each parameter follows:
3643 % o image: the image.
3645 % o exception: return any errors or warnings in this structure.
3648 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3653 assert(image != (Image *) NULL);
3654 if (image->debug != MagickFalse)
3655 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3657 DestroyImageProfiles(image);
3658 (void) DeleteImageProperty(image,"comment");
3659 (void) DeleteImageProperty(image,"date:create");
3660 (void) DeleteImageProperty(image,"date:modify");
3661 status=SetImageArtifact(image,"png:exclude-chunk",
3662 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3671 + S y n c I m a g e %
3675 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3677 % SyncImage() initializes the red, green, and blue intensities of each pixel
3678 % as defined by the colormap index.
3680 % The format of the SyncImage method is:
3682 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3684 % A description of each parameter follows:
3686 % o image: the image.
3688 % o exception: return any errors or warnings in this structure.
3692 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3693 MagickBooleanType *range_exception)
3695 if ((size_t) index < image->colors)
3697 *range_exception=MagickTrue;
3698 return((Quantum) 0);
3701 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3714 assert(image != (Image *) NULL);
3715 if (image->debug != MagickFalse)
3716 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3717 assert(image->signature == MagickCoreSignature);
3718 if (image->ping != MagickFalse)
3720 if (image->storage_class != PseudoClass)
3721 return(MagickFalse);
3722 assert(image->colormap != (PixelInfo *) NULL);
3723 range_exception=MagickFalse;
3726 image_view=AcquireAuthenticCacheView(image,exception);
3727 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3728 #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
3729 magick_chunk_threads(image,image,image->rows,1)
3731 for (y=0; y < (ssize_t) image->rows; y++)
3742 if (status == MagickFalse)
3744 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3745 if (q == (Quantum *) NULL)
3750 for (x=0; x < (ssize_t) image->columns; x++)
3752 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3753 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
3754 q+=GetPixelChannels(image);
3756 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3759 image_view=DestroyCacheView(image_view);
3761 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3762 (void) ThrowMagickException(exception,GetMagickModule(),
3763 CorruptImageWarning,"InvalidColormapIndex","`%s'",image->filename);
3768 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3772 % S y n c I m a g e S e t t i n g s %
3776 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3778 % SyncImageSettings() syncs any image_info global options into per-image
3781 % Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
3782 % that operations and coders can find such settings. In IMv7 if a desired
3783 % per-image artifact is not set, then it will directly look for a global
3784 % option as a fallback, as such this copy is no longer needed, only the
3787 % The format of the SyncImageSettings method is:
3789 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3790 % Image *image,ExceptionInfo *exception)
3791 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3792 % Image *image,ExceptionInfo *exception)
3794 % A description of each parameter follows:
3796 % o image_info: the image info.
3798 % o image: the image.
3800 % o exception: return any errors or warnings in this structure.
3804 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3805 Image *images,ExceptionInfo *exception)
3810 assert(image_info != (const ImageInfo *) NULL);
3811 assert(image_info->signature == MagickCoreSignature);
3812 assert(images != (Image *) NULL);
3813 assert(images->signature == MagickCoreSignature);
3814 if (images->debug != MagickFalse)
3815 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3817 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3818 (void) SyncImageSettings(image_info,image,exception);
3819 (void) DeleteImageOption(image_info,"page");
3823 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3824 Image *image,ExceptionInfo *exception)
3841 assert(image_info != (const ImageInfo *) NULL);
3842 assert(image_info->signature == MagickCoreSignature);
3843 assert(image != (Image *) NULL);
3844 assert(image->signature == MagickCoreSignature);
3845 if (image->debug != MagickFalse)
3846 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3847 option=GetImageOption(image_info,"background");
3848 if (option != (const char *) NULL)
3849 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
3851 option=GetImageOption(image_info,"black-point-compensation");
3852 if (option != (const char *) NULL)
3853 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3854 MagickBooleanOptions,MagickFalse,option);
3855 option=GetImageOption(image_info,"blue-primary");
3856 if (option != (const char *) NULL)
3858 flags=ParseGeometry(option,&geometry_info);
3859 image->chromaticity.blue_primary.x=geometry_info.rho;
3860 image->chromaticity.blue_primary.y=geometry_info.sigma;
3861 if ((flags & SigmaValue) == 0)
3862 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3864 option=GetImageOption(image_info,"bordercolor");
3865 if (option != (const char *) NULL)
3866 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
3868 /* FUTURE: do not sync compose to per-image compose setting here */
3869 option=GetImageOption(image_info,"compose");
3870 if (option != (const char *) NULL)
3871 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3872 MagickFalse,option);
3874 option=GetImageOption(image_info,"compress");
3875 if (option != (const char *) NULL)
3876 image->compression=(CompressionType) ParseCommandOption(
3877 MagickCompressOptions,MagickFalse,option);
3878 option=GetImageOption(image_info,"debug");
3879 if (option != (const char *) NULL)
3880 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3881 MagickFalse,option);
3882 option=GetImageOption(image_info,"density");
3883 if (option != (const char *) NULL)
3885 flags=ParseGeometry(option,&geometry_info);
3886 image->resolution.x=geometry_info.rho;
3887 image->resolution.y=geometry_info.sigma;
3888 if ((flags & SigmaValue) == 0)
3889 image->resolution.y=image->resolution.x;
3891 option=GetImageOption(image_info,"depth");
3892 if (option != (const char *) NULL)
3893 image->depth=StringToUnsignedLong(option);
3894 option=GetImageOption(image_info,"endian");
3895 if (option != (const char *) NULL)
3896 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3897 MagickFalse,option);
3898 option=GetImageOption(image_info,"filter");
3899 if (option != (const char *) NULL)
3900 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
3901 MagickFalse,option);
3902 option=GetImageOption(image_info,"fuzz");
3903 if (option != (const char *) NULL)
3904 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3905 option=GetImageOption(image_info,"gravity");
3906 if (option != (const char *) NULL)
3907 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3908 MagickFalse,option);
3909 option=GetImageOption(image_info,"green-primary");
3910 if (option != (const char *) NULL)
3912 flags=ParseGeometry(option,&geometry_info);
3913 image->chromaticity.green_primary.x=geometry_info.rho;
3914 image->chromaticity.green_primary.y=geometry_info.sigma;
3915 if ((flags & SigmaValue) == 0)
3916 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3918 option=GetImageOption(image_info,"intent");
3919 if (option != (const char *) NULL)
3920 image->rendering_intent=(RenderingIntent) ParseCommandOption(
3921 MagickIntentOptions,MagickFalse,option);
3922 option=GetImageOption(image_info,"intensity");
3923 if (option != (const char *) NULL)
3924 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3925 MagickPixelIntensityOptions,MagickFalse,option);
3926 option=GetImageOption(image_info,"interlace");
3927 if (option != (const char *) NULL)
3928 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3929 MagickFalse,option);
3930 option=GetImageOption(image_info,"interpolate");
3931 if (option != (const char *) NULL)
3932 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
3933 MagickInterpolateOptions,MagickFalse,option);
3934 option=GetImageOption(image_info,"loop");
3935 if (option != (const char *) NULL)
3936 image->iterations=StringToUnsignedLong(option);
3937 option=GetImageOption(image_info,"mattecolor");
3938 if (option != (const char *) NULL)
3939 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
3941 option=GetImageOption(image_info,"orient");
3942 if (option != (const char *) NULL)
3943 image->orientation=(OrientationType) ParseCommandOption(
3944 MagickOrientationOptions,MagickFalse,option);
3945 option=GetImageOption(image_info,"page");
3946 if (option != (const char *) NULL)
3951 geometry=GetPageGeometry(option);
3952 flags=ParseAbsoluteGeometry(geometry,&image->page);
3953 geometry=DestroyString(geometry);
3955 option=GetImageOption(image_info,"quality");
3956 if (option != (const char *) NULL)
3957 image->quality=StringToUnsignedLong(option);
3958 option=GetImageOption(image_info,"red-primary");
3959 if (option != (const char *) NULL)
3961 flags=ParseGeometry(option,&geometry_info);
3962 image->chromaticity.red_primary.x=geometry_info.rho;
3963 image->chromaticity.red_primary.y=geometry_info.sigma;
3964 if ((flags & SigmaValue) == 0)
3965 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3967 if (image_info->quality != UndefinedCompressionQuality)
3968 image->quality=image_info->quality;
3969 option=GetImageOption(image_info,"scene");
3970 if (option != (const char *) NULL)
3971 image->scene=StringToUnsignedLong(option);
3972 option=GetImageOption(image_info,"taint");
3973 if (option != (const char *) NULL)
3974 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3975 MagickFalse,option);
3976 option=GetImageOption(image_info,"tile-offset");
3977 if (option != (const char *) NULL)
3982 geometry=GetPageGeometry(option);
3983 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3984 geometry=DestroyString(geometry);
3986 option=GetImageOption(image_info,"transparent-color");
3987 if (option != (const char *) NULL)
3988 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
3990 option=GetImageOption(image_info,"type");
3991 if (option != (const char *) NULL)
3992 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3994 option=GetImageOption(image_info,"units");
3995 units=image_info->units;
3996 if (option != (const char *) NULL)
3997 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
3998 MagickFalse,option);
3999 if (units != UndefinedResolution)
4001 if (image->units != units)
4002 switch (image->units)
4004 case PixelsPerInchResolution:
4006 if (units == PixelsPerCentimeterResolution)
4008 image->resolution.x/=2.54;
4009 image->resolution.y/=2.54;
4013 case PixelsPerCentimeterResolution:
4015 if (units == PixelsPerInchResolution)
4017 image->resolution.x=(double) ((size_t) (100.0*2.54*
4018 image->resolution.x+0.5))/100.0;
4019 image->resolution.y=(double) ((size_t) (100.0*2.54*
4020 image->resolution.y+0.5))/100.0;
4029 option=GetImageOption(image_info,"virtual-pixel");
4030 if (option != (const char *) NULL)
4031 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4032 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4034 option=GetImageOption(image_info,"white-point");
4035 if (option != (const char *) NULL)
4037 flags=ParseGeometry(option,&geometry_info);
4038 image->chromaticity.white_point.x=geometry_info.rho;
4039 image->chromaticity.white_point.y=geometry_info.sigma;
4040 if ((flags & SigmaValue) == 0)
4041 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4044 Pointer to allow the lookup of pre-image artifact will fallback to a global
4045 option setting/define. This saves a lot of duplication of global options
4046 into per-image artifacts, while ensuring only specifically set per-image
4047 artifacts are preserved when parenthesis ends.
4049 if (image->image_info != (ImageInfo *) NULL)
4050 image->image_info=DestroyImageInfo(image->image_info);
4051 image->image_info=CloneImageInfo(image_info);