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 % http://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 AlphaColor[] = "#bdbdbd", /* gray */
109 BackgroundColor[] = "#ffffff", /* white */
110 BorderColor[] = "#dfdfdf", /* gray */
111 DefaultTileFrame[] = "15x15+3+3",
112 DefaultTileGeometry[] = "120x120+4+3>",
113 DefaultTileLabel[] = "%f\n%G\n%b",
114 ForegroundColor[] = "#000", /* black */
115 LoadImageTag[] = "Load/Image",
116 LoadImagesTag[] = "Load/Images",
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(AlphaColor,AllCompliance,&image->alpha_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->alpha_color=image_info->alpha_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 (void) SetImageBackgroundColor(append_image,exception);
536 append_view=AcquireAuthenticCacheView(append_image,exception);
537 for (n=0; n < (MagickOffsetType) number_images; n++)
545 SetGeometry(append_image,&geometry);
546 GravityAdjustGeometry(next->columns,next->rows,next->gravity,&geometry);
547 if (stack != MagickFalse)
548 x_offset-=geometry.x;
550 y_offset-=geometry.y;
551 image_view=AcquireVirtualCacheView(next,exception);
552 #if defined(MAGICKCORE_OPENMP_SUPPORT)
553 #pragma omp parallel for schedule(static,4) shared(status) \
554 magick_threads(next,next,next->rows,1)
556 for (y=0; y < (ssize_t) next->rows; y++)
564 register const Quantum
573 if (status == MagickFalse)
575 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
576 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
577 next->columns,1,exception);
578 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
583 GetPixelInfo(next,&pixel);
584 for (x=0; x < (ssize_t) next->columns; x++)
586 if (GetPixelWriteMask(next,p) == 0)
588 SetPixelBackgoundColor(append_image,q);
589 p+=GetPixelChannels(next);
590 q+=GetPixelChannels(append_image);
593 GetPixelInfoPixel(next,p,&pixel);
594 SetPixelViaPixelInfo(append_image,&pixel,q);
595 p+=GetPixelChannels(next);
596 q+=GetPixelChannels(append_image);
598 sync=SyncCacheViewAuthenticPixels(append_view,exception);
599 if (sync == MagickFalse)
602 image_view=DestroyCacheView(image_view);
603 if (stack == MagickFalse)
605 x_offset+=(ssize_t) next->columns;
611 y_offset+=(ssize_t) next->rows;
613 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
614 if (proceed == MagickFalse)
616 next=GetNextImageInList(next);
618 append_view=DestroyCacheView(append_view);
619 if (status == MagickFalse)
620 append_image=DestroyImage(append_image);
621 return(append_image);
625 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
629 % C a t c h I m a g e E x c e p t i o n %
633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
635 % CatchImageException() returns if no exceptions are found in the image
636 % sequence, otherwise it determines the most severe exception and reports
637 % it as a warning or error depending on the severity.
639 % The format of the CatchImageException method is:
641 % ExceptionType CatchImageException(Image *image)
643 % A description of each parameter follows:
645 % o image: An image sequence.
648 MagickExport ExceptionType CatchImageException(Image *image)
656 assert(image != (const Image *) NULL);
657 assert(image->signature == MagickCoreSignature);
658 if (image->debug != MagickFalse)
659 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
660 exception=AcquireExceptionInfo();
661 CatchException(exception);
662 severity=exception->severity;
663 exception=DestroyExceptionInfo(exception);
668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
672 % C l i p I m a g e P a t h %
676 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
678 % ClipImagePath() sets the image clip mask based any clipping path information
681 % The format of the ClipImagePath method is:
683 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
684 % const MagickBooleanType inside,ExceptionInfo *exception)
686 % A description of each parameter follows:
688 % o image: the image.
690 % o pathname: name of clipping path resource. If name is preceded by #, use
691 % clipping path numbered by name.
693 % o inside: if non-zero, later operations take effect inside clipping path.
694 % Otherwise later operations take effect outside clipping path.
696 % o exception: return any errors or warnings in this structure.
700 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
702 return(ClipImagePath(image,"#1",MagickTrue,exception));
705 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
706 const MagickBooleanType inside,ExceptionInfo *exception)
708 #define ClipImagePathTag "ClipPath/Image"
722 assert(image != (const Image *) NULL);
723 assert(image->signature == MagickCoreSignature);
724 if (image->debug != MagickFalse)
725 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
726 assert(pathname != NULL);
727 property=AcquireString(pathname);
728 (void) FormatLocaleString(property,MagickPathExtent,"8BIM:1999,2998:%s",
730 value=GetImageProperty(image,property,exception);
731 property=DestroyString(property);
732 if (value == (const char *) NULL)
734 ThrowFileException(exception,OptionError,"NoClipPathDefined",
738 image_info=AcquireImageInfo();
739 (void) CopyMagickString(image_info->filename,image->filename,
741 (void) ConcatenateMagickString(image_info->filename,pathname,
743 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
744 image_info=DestroyImageInfo(image_info);
745 if (clip_mask == (Image *) NULL)
747 if (clip_mask->storage_class == PseudoClass)
749 (void) SyncImage(clip_mask,exception);
750 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
753 if (inside == MagickFalse)
754 (void) NegateImage(clip_mask,MagickFalse,exception);
755 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
756 "8BIM:1999,2998:%s\nPS",pathname);
757 (void) SetImageMask(image,WritePixelMask,clip_mask,exception);
758 clip_mask=DestroyImage(clip_mask);
763 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
767 % C l o n e I m a g e %
771 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
773 % CloneImage() copies an image and returns the copy as a new image object.
775 % If the specified columns and rows is 0, an exact copy of the image is
776 % returned, otherwise the pixel data is undefined and must be initialized
777 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
778 % failure, a NULL image is returned and exception describes the reason for the
781 % The format of the CloneImage method is:
783 % Image *CloneImage(const Image *image,const size_t columns,
784 % const size_t rows,const MagickBooleanType orphan,
785 % ExceptionInfo *exception)
787 % A description of each parameter follows:
789 % o image: the image.
791 % o columns: the number of columns in the cloned image.
793 % o rows: the number of rows in the cloned image.
795 % o detach: With a value other than 0, the cloned image is detached from
796 % its parent I/O stream.
798 % o exception: return any errors or warnings in this structure.
801 MagickExport Image *CloneImage(const Image *image,const size_t columns,
802 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
816 assert(image != (const Image *) NULL);
817 assert(image->signature == MagickCoreSignature);
818 if (image->debug != MagickFalse)
819 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
820 assert(exception != (ExceptionInfo *) NULL);
821 assert(exception->signature == MagickCoreSignature);
822 if ((image->columns == 0) || (image->rows == 0))
824 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
825 "NegativeOrZeroImageSize","`%s'",image->filename);
826 return((Image *) NULL);
828 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
829 if (clone_image == (Image *) NULL)
830 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
831 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
832 clone_image->signature=MagickCoreSignature;
833 clone_image->storage_class=image->storage_class;
834 clone_image->number_channels=image->number_channels;
835 clone_image->number_meta_channels=image->number_meta_channels;
836 clone_image->metacontent_extent=image->metacontent_extent;
837 clone_image->colorspace=image->colorspace;
838 clone_image->read_mask=image->read_mask;
839 clone_image->write_mask=image->write_mask;
840 clone_image->alpha_trait=image->alpha_trait;
841 clone_image->columns=image->columns;
842 clone_image->rows=image->rows;
843 clone_image->dither=image->dither;
844 if (image->colormap != (PixelInfo *) NULL)
847 Allocate and copy the image colormap.
849 clone_image->colors=image->colors;
850 length=(size_t) image->colors;
851 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
852 sizeof(*clone_image->colormap));
853 if (clone_image->colormap == (PixelInfo *) NULL)
855 clone_image=DestroyImage(clone_image);
856 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
858 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
859 sizeof(*clone_image->colormap));
861 clone_image->image_info=CloneImageInfo(image->image_info);
862 (void) CloneImageProfiles(clone_image,image);
863 (void) CloneImageProperties(clone_image,image);
864 (void) CloneImageArtifacts(clone_image,image);
865 GetTimerInfo(&clone_image->timer);
866 if (image->ascii85 != (void *) NULL)
867 Ascii85Initialize(clone_image);
868 clone_image->magick_columns=image->magick_columns;
869 clone_image->magick_rows=image->magick_rows;
870 clone_image->type=image->type;
871 clone_image->channel_mask=image->channel_mask;
872 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
873 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
875 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
876 (void) CopyMagickString(clone_image->filename,image->filename,
878 clone_image->progress_monitor=image->progress_monitor;
879 clone_image->client_data=image->client_data;
880 clone_image->reference_count=1;
881 clone_image->next=image->next;
882 clone_image->previous=image->previous;
883 clone_image->list=NewImageList();
884 if (detach == MagickFalse)
885 clone_image->blob=ReferenceBlob(image->blob);
888 clone_image->next=NewImageList();
889 clone_image->previous=NewImageList();
890 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
892 clone_image->ping=image->ping;
893 clone_image->debug=IsEventLogging();
894 clone_image->semaphore=AcquireSemaphoreInfo();
895 if ((columns == 0) || (rows == 0))
897 if (image->montage != (char *) NULL)
898 (void) CloneString(&clone_image->montage,image->montage);
899 if (image->directory != (char *) NULL)
900 (void) CloneString(&clone_image->directory,image->directory);
901 clone_image->cache=ReferencePixelCache(image->cache);
905 if (image->columns != 0)
906 scale=(double) columns/(double) image->columns;
907 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
908 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
909 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
911 if (image->rows != 0)
912 scale=(double) rows/(double) image->rows;
913 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
914 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
915 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
916 clone_image->cache=ClonePixelCache(image->cache);
917 if (SetImageExtent(clone_image,columns,rows,exception) == MagickFalse)
918 clone_image=DestroyImage(clone_image);
923 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
927 % C l o n e I m a g e I n f o %
931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
933 % CloneImageInfo() makes a copy of the given image info structure. If
934 % NULL is specified, a new image info structure is created initialized to
937 % The format of the CloneImageInfo method is:
939 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
941 % A description of each parameter follows:
943 % o image_info: the image info.
946 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
951 clone_info=AcquireImageInfo();
952 if (image_info == (ImageInfo *) NULL)
954 clone_info->compression=image_info->compression;
955 clone_info->temporary=image_info->temporary;
956 clone_info->adjoin=image_info->adjoin;
957 clone_info->antialias=image_info->antialias;
958 clone_info->scene=image_info->scene;
959 clone_info->number_scenes=image_info->number_scenes;
960 clone_info->depth=image_info->depth;
961 (void) CloneString(&clone_info->size,image_info->size);
962 (void) CloneString(&clone_info->extract,image_info->extract);
963 (void) CloneString(&clone_info->scenes,image_info->scenes);
964 (void) CloneString(&clone_info->page,image_info->page);
965 clone_info->interlace=image_info->interlace;
966 clone_info->endian=image_info->endian;
967 clone_info->units=image_info->units;
968 clone_info->quality=image_info->quality;
969 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
970 (void) CloneString(&clone_info->server_name,image_info->server_name);
971 (void) CloneString(&clone_info->font,image_info->font);
972 (void) CloneString(&clone_info->texture,image_info->texture);
973 (void) CloneString(&clone_info->density,image_info->density);
974 clone_info->pointsize=image_info->pointsize;
975 clone_info->fuzz=image_info->fuzz;
976 clone_info->alpha_color=image_info->alpha_color;
977 clone_info->background_color=image_info->background_color;
978 clone_info->border_color=image_info->border_color;
979 clone_info->transparent_color=image_info->transparent_color;
980 clone_info->dither=image_info->dither;
981 clone_info->monochrome=image_info->monochrome;
982 clone_info->colorspace=image_info->colorspace;
983 clone_info->type=image_info->type;
984 clone_info->orientation=image_info->orientation;
985 clone_info->ping=image_info->ping;
986 clone_info->verbose=image_info->verbose;
987 clone_info->progress_monitor=image_info->progress_monitor;
988 clone_info->client_data=image_info->client_data;
989 clone_info->cache=image_info->cache;
990 if (image_info->cache != (void *) NULL)
991 clone_info->cache=ReferencePixelCache(image_info->cache);
992 if (image_info->profile != (void *) NULL)
993 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
994 image_info->profile);
995 SetImageInfoFile(clone_info,image_info->file);
996 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
997 clone_info->stream=image_info->stream;
998 (void) CopyMagickString(clone_info->magick,image_info->magick,
1000 (void) CopyMagickString(clone_info->unique,image_info->unique,
1002 (void) CopyMagickString(clone_info->filename,image_info->filename,
1004 clone_info->channel=image_info->channel;
1005 (void) CloneImageOptions(clone_info,image_info);
1006 clone_info->debug=IsEventLogging();
1007 clone_info->signature=image_info->signature;
1012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1016 % C o p y I m a g e P i x e l s %
1020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1022 % CopyImagePixels() copies pixels from the source image as defined by the
1023 % geometry the destination image at the specified offset.
1025 % The format of the CopyImagePixels method is:
1027 % MagickBooleanType CopyImagePixels(Image *image,const Image *source_image,
1028 % const RectangleInfo *geometry,const OffsetInfo *offset,
1029 % ExceptionInfo *exception);
1031 % A description of each parameter follows:
1033 % o image: the destination image.
1035 % o source_image: the source image.
1037 % o geometry: define the dimensions of the source pixel rectangle.
1039 % o offset: define the offset in the destination image.
1041 % o exception: return any errors or warnings in this structure.
1044 MagickExport MagickBooleanType CopyImagePixels(Image *image,
1045 const Image *source_image,const RectangleInfo *geometry,
1046 const OffsetInfo *offset,ExceptionInfo *exception)
1048 #define CopyImageTag "Copy/Image"
1063 assert(image != (Image *) NULL);
1064 if (image->debug != MagickFalse)
1065 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1066 assert(source_image != (Image *) NULL);
1067 assert(geometry != (RectangleInfo *) NULL);
1068 assert(offset != (OffsetInfo *) NULL);
1069 if ((offset->x < 0) || (offset->y < 0) ||
1070 ((ssize_t) (offset->x+geometry->width) > (ssize_t) image->columns) ||
1071 ((ssize_t) (offset->y+geometry->height) > (ssize_t) image->rows))
1072 ThrowBinaryException(OptionError,"GeometryDoesNotContainImage",
1074 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1075 return(MagickFalse);
1081 source_view=AcquireVirtualCacheView(source_image,exception);
1082 image_view=AcquireAuthenticCacheView(image,exception);
1083 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1084 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1085 magick_threads(image,source_image,geometry->height,1)
1087 for (y=0; y < (ssize_t) geometry->height; y++)
1092 register const Quantum
1101 if (status == MagickFalse)
1103 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1104 geometry->width,1,exception);
1105 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1106 geometry->width,1,exception);
1107 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1112 for (x=0; x < (ssize_t) geometry->width; x++)
1117 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1119 PixelChannel channel=GetPixelChannelChannel(image,i);
1120 PixelTrait traits=GetPixelChannelTraits(image,channel);
1121 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1122 if ((traits == UndefinedPixelTrait) ||
1123 ((traits & UpdatePixelTrait) == 0) ||
1124 (source_traits == UndefinedPixelTrait))
1126 SetPixelChannel(image,channel,p[i],q);
1128 p+=GetPixelChannels(source_image);
1129 q+=GetPixelChannels(image);
1131 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1132 if (sync == MagickFalse)
1134 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1139 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1140 #pragma omp critical (MagickCore_CopyImage)
1142 proceed=SetImageProgress(image,CopyImageTag,progress++,image->rows);
1143 if (proceed == MagickFalse)
1147 source_view=DestroyCacheView(source_view);
1148 image_view=DestroyCacheView(image_view);
1153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1157 % D e s t r o y I m a g e %
1161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1163 % DestroyImage() dereferences an image, deallocating memory associated with
1164 % the image if the reference count becomes zero.
1166 % The format of the DestroyImage method is:
1168 % Image *DestroyImage(Image *image)
1170 % A description of each parameter follows:
1172 % o image: the image.
1175 MagickExport Image *DestroyImage(Image *image)
1183 assert(image != (Image *) NULL);
1184 assert(image->signature == MagickCoreSignature);
1185 if (image->debug != MagickFalse)
1186 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1187 destroy=MagickFalse;
1188 LockSemaphoreInfo(image->semaphore);
1189 image->reference_count--;
1190 if (image->reference_count == 0)
1192 UnlockSemaphoreInfo(image->semaphore);
1193 if (destroy == MagickFalse)
1194 return((Image *) NULL);
1198 DestroyImagePixels(image);
1199 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1200 if (image->montage != (char *) NULL)
1201 image->montage=DestroyString(image->montage);
1202 if (image->directory != (char *) NULL)
1203 image->directory=DestroyString(image->directory);
1204 if (image->colormap != (PixelInfo *) NULL)
1205 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1206 if (image->geometry != (char *) NULL)
1207 image->geometry=DestroyString(image->geometry);
1208 DestroyImageProfiles(image);
1209 DestroyImageProperties(image);
1210 DestroyImageArtifacts(image);
1211 if (image->ascii85 != (Ascii85Info *) NULL)
1212 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1213 if (image->image_info != (ImageInfo *) NULL)
1214 image->image_info=DestroyImageInfo(image->image_info);
1216 if (image->semaphore != (SemaphoreInfo *) NULL)
1217 RelinquishSemaphoreInfo(&image->semaphore);
1218 image->signature=(~MagickCoreSignature);
1219 image=(Image *) RelinquishMagickMemory(image);
1224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1228 % D e s t r o y I m a g e I n f o %
1232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1234 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1237 % The format of the DestroyImageInfo method is:
1239 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1241 % A description of each parameter follows:
1243 % o image_info: the image info.
1246 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1248 assert(image_info != (ImageInfo *) NULL);
1249 assert(image_info->signature == MagickCoreSignature);
1250 if (image_info->debug != MagickFalse)
1251 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1252 image_info->filename);
1253 if (image_info->size != (char *) NULL)
1254 image_info->size=DestroyString(image_info->size);
1255 if (image_info->extract != (char *) NULL)
1256 image_info->extract=DestroyString(image_info->extract);
1257 if (image_info->scenes != (char *) NULL)
1258 image_info->scenes=DestroyString(image_info->scenes);
1259 if (image_info->page != (char *) NULL)
1260 image_info->page=DestroyString(image_info->page);
1261 if (image_info->sampling_factor != (char *) NULL)
1262 image_info->sampling_factor=DestroyString(
1263 image_info->sampling_factor);
1264 if (image_info->server_name != (char *) NULL)
1265 image_info->server_name=DestroyString(
1266 image_info->server_name);
1267 if (image_info->font != (char *) NULL)
1268 image_info->font=DestroyString(image_info->font);
1269 if (image_info->texture != (char *) NULL)
1270 image_info->texture=DestroyString(image_info->texture);
1271 if (image_info->density != (char *) NULL)
1272 image_info->density=DestroyString(image_info->density);
1273 if (image_info->cache != (void *) NULL)
1274 image_info->cache=DestroyPixelCache(image_info->cache);
1275 if (image_info->profile != (StringInfo *) NULL)
1276 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1277 image_info->profile);
1278 DestroyImageOptions(image_info);
1279 image_info->signature=(~MagickCoreSignature);
1280 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1289 + D i s a s s o c i a t e I m a g e S t r e a m %
1293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1295 % DisassociateImageStream() disassociates the image stream. It checks if the
1296 % blob of the specified image is referenced by other images. If the reference
1297 % count is higher then 1 a new blob is assigned to the specified image.
1299 % The format of the DisassociateImageStream method is:
1301 % void DisassociateImageStream(const Image *image)
1303 % A description of each parameter follows:
1305 % o image: the image.
1308 MagickExport void DisassociateImageStream(Image *image)
1310 assert(image != (Image *) NULL);
1311 assert(image->signature == MagickCoreSignature);
1312 if (image->debug != MagickFalse)
1313 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1314 DisassociateBlob(image);
1318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1322 % G e t I m a g e I n f o %
1326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1328 % GetImageInfo() initializes image_info to default values.
1330 % The format of the GetImageInfo method is:
1332 % void GetImageInfo(ImageInfo *image_info)
1334 % A description of each parameter follows:
1336 % o image_info: the image info.
1339 MagickExport void GetImageInfo(ImageInfo *image_info)
1348 File and image dimension members.
1350 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1351 assert(image_info != (ImageInfo *) NULL);
1352 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1353 image_info->adjoin=MagickTrue;
1354 image_info->interlace=NoInterlace;
1355 image_info->channel=DefaultChannels;
1356 image_info->quality=UndefinedCompressionQuality;
1357 image_info->antialias=MagickTrue;
1358 image_info->dither=MagickTrue;
1359 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1360 if (synchronize != (const char *) NULL)
1362 image_info->synchronize=IsStringTrue(synchronize);
1363 synchronize=DestroyString(synchronize);
1365 exception=AcquireExceptionInfo();
1366 (void) QueryColorCompliance(AlphaColor,AllCompliance,&image_info->alpha_color,
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(TransparentColor,AllCompliance,
1373 &image_info->transparent_color,exception);
1374 exception=DestroyExceptionInfo(exception);
1375 image_info->debug=IsEventLogging();
1376 image_info->signature=MagickCoreSignature;
1380 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1384 % G e t I m a g e I n f o F i l e %
1388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1390 % GetImageInfoFile() returns the image info file member.
1392 % The format of the GetImageInfoFile method is:
1394 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1396 % A description of each parameter follows:
1398 % o image_info: the image info.
1401 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1403 return(image_info->file);
1407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1411 % G e t I m a g e M a s k %
1415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1417 % GetImageMask() returns the mask associated with the image.
1419 % The format of the GetImageMask method is:
1421 % Image *GetImageMask(const Image *image,const PixelMask type,
1422 % ExceptionInfo *exception)
1424 % A description of each parameter follows:
1426 % o image: the image.
1428 % o type: the mask type, ReadPixelMask or WritePixelMask.
1431 MagickExport Image *GetImageMask(const Image *image,const PixelMask type,
1432 ExceptionInfo *exception)
1450 assert(image != (Image *) NULL);
1451 if (image->debug != MagickFalse)
1452 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1453 assert(image->signature == MagickCoreSignature);
1454 mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1455 if (mask_image == (Image *) NULL)
1456 return((Image *) NULL);
1458 mask_image->alpha_trait=UndefinedPixelTrait;
1459 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1460 mask_image->read_mask=MagickFalse;
1461 image_view=AcquireVirtualCacheView(image,exception);
1462 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1463 for (y=0; y < (ssize_t) image->rows; y++)
1465 register const Quantum
1474 if (status == MagickFalse)
1476 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1477 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1479 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1484 for (x=0; x < (ssize_t) image->columns; x++)
1488 case WritePixelMask:
1490 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1495 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1499 p+=GetPixelChannels(image);
1500 q+=GetPixelChannels(mask_image);
1502 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1505 mask_view=DestroyCacheView(mask_view);
1506 image_view=DestroyCacheView(image_view);
1507 if (status == MagickFalse)
1508 mask_image=DestroyImage(mask_image);
1513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1517 + G e t I m a g e R e f e r e n c e C o u n t %
1521 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1523 % GetImageReferenceCount() returns the image reference count.
1525 % The format of the GetReferenceCount method is:
1527 % ssize_t GetImageReferenceCount(Image *image)
1529 % A description of each parameter follows:
1531 % o image: the image.
1534 MagickExport ssize_t GetImageReferenceCount(Image *image)
1539 assert(image != (Image *) NULL);
1540 assert(image->signature == MagickCoreSignature);
1541 if (image->debug != MagickFalse)
1542 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1543 LockSemaphoreInfo(image->semaphore);
1544 reference_count=image->reference_count;
1545 UnlockSemaphoreInfo(image->semaphore);
1546 return(reference_count);
1550 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1554 % 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 %
1558 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1560 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1561 % image. A virtual pixel is any pixel access that is outside the boundaries
1562 % of the image cache.
1564 % The format of the GetImageVirtualPixelMethod() method is:
1566 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1568 % A description of each parameter follows:
1570 % o image: the image.
1573 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1575 assert(image != (Image *) NULL);
1576 assert(image->signature == MagickCoreSignature);
1577 if (image->debug != MagickFalse)
1578 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1579 return(GetPixelCacheVirtualMethod(image));
1583 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1587 % I n t e r p r e t I m a g e F i l e n a m e %
1591 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1593 % InterpretImageFilename() interprets embedded characters in an image filename.
1594 % The filename length is returned.
1596 % The format of the InterpretImageFilename method is:
1598 % size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1599 % const char *format,int value,char *filename,ExceptionInfo *exception)
1601 % A description of each parameter follows.
1603 % o image_info: the image info..
1605 % o image: the image.
1607 % o format: A filename describing the format to use to write the numeric
1608 % argument. Only the first numeric format identifier is replaced.
1610 % o value: Numeric value to substitute into format filename.
1612 % o filename: return the formatted filename in this character buffer.
1614 % o exception: return any errors or warnings in this structure.
1617 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1618 Image *image,const char *format,int value,char *filename,
1619 ExceptionInfo *exception)
1636 canonical=MagickFalse;
1638 (void) CopyMagickString(filename,format,MagickPathExtent);
1639 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1652 foo=(ssize_t) strtol(q,&q,10);
1664 (void) FormatLocaleString(filename+(p-format),(size_t)
1665 (MagickPathExtent-(p-format)),p,value);
1667 (void) ConcatenateMagickString(filename,q,MagickPathExtent);
1668 canonical=MagickTrue;
1677 pattern[MagickPathExtent];
1694 /* FUTURE: Compare update with code from InterpretImageProperties()
1695 Note that a 'filename:' property should not need depth recursion.
1697 if (strchr(p,']') == (char *) NULL)
1701 for (i=0; (i < (MagickPathExtent-1L)) && (*r != '\0'); i++)
1712 if (LocaleNCompare(pattern,"filename:",9) != 0)
1714 option=(const char *) NULL;
1715 if (image != (Image *) NULL)
1716 option=GetImageProperty(image,pattern,exception);
1717 if ((option == (const char *) NULL) && (image != (Image *) NULL))
1718 option=GetImageArtifact(image,pattern);
1719 if ((option == (const char *) NULL) &&
1720 (image_info != (ImageInfo *) NULL))
1721 option=GetImageOption(image_info,pattern);
1722 if (option == (const char *) NULL)
1727 (void) CopyMagickString(filename+(p-format-length),option,(size_t)
1728 (MagickPathExtent-(p-format-length)));
1729 length+=strlen(pattern)-1;
1731 (void) ConcatenateMagickString(filename,r+1,MagickPathExtent);
1732 canonical=MagickTrue;
1742 for (q=filename; *q != '\0'; q++)
1743 if ((*q == '%') && (*(q+1) == '%'))
1745 (void) CopyMagickString(q,q+1,(size_t) (MagickPathExtent-(q-filename)));
1746 canonical=MagickTrue;
1748 if (canonical == MagickFalse)
1749 (void) CopyMagickString(filename,format,MagickPathExtent);
1750 return(strlen(filename));
1754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1758 % I s H i g h D y n a m i c R a n g e I m a g e %
1762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1764 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1765 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1768 % The format of the IsHighDynamicRangeImage method is:
1770 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1771 % ExceptionInfo *exception)
1773 % A description of each parameter follows:
1775 % o image: the image.
1777 % o exception: return any errors or warnings in this structure.
1780 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1781 ExceptionInfo *exception)
1783 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1786 return(MagickFalse);
1797 assert(image != (Image *) NULL);
1798 assert(image->signature == MagickCoreSignature);
1799 if (image->debug != MagickFalse)
1800 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1802 image_view=AcquireVirtualCacheView(image,exception);
1803 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1804 #pragma omp parallel for schedule(static,4) shared(status) \
1805 magick_threads(image,image,image->rows,1)
1807 for (y=0; y < (ssize_t) image->rows; y++)
1809 register const Quantum
1815 if (status == MagickFalse)
1817 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1818 if (p == (const Quantum *) NULL)
1823 for (x=0; x < (ssize_t) image->columns; x++)
1828 if (GetPixelWriteMask(image,p) == 0)
1830 p+=GetPixelChannels(image);
1833 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1841 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1842 if (traits == UndefinedPixelTrait)
1844 pixel=(double) p[i];
1845 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1846 (pixel != (double) ((QuantumAny) pixel)))
1849 p+=GetPixelChannels(image);
1850 if (i < (ssize_t) GetPixelChannels(image))
1853 if (x < (ssize_t) image->columns)
1856 image_view=DestroyCacheView(image_view);
1857 return(status != MagickFalse ? MagickFalse : MagickTrue);
1862 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1866 % I s I m a g e O b j e c t %
1870 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1872 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1873 % set of image objects.
1875 % The format of the IsImageObject method is:
1877 % MagickBooleanType IsImageObject(const Image *image)
1879 % A description of each parameter follows:
1881 % o image: the image.
1884 MagickExport MagickBooleanType IsImageObject(const Image *image)
1886 register const Image
1889 assert(image != (Image *) NULL);
1890 if (image->debug != MagickFalse)
1891 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1892 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1893 if (p->signature != MagickCoreSignature)
1894 return(MagickFalse);
1899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1903 % I s T a i n t I m a g e %
1907 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1909 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1910 % since it was first constituted.
1912 % The format of the IsTaintImage method is:
1914 % MagickBooleanType IsTaintImage(const Image *image)
1916 % A description of each parameter follows:
1918 % o image: the image.
1921 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1924 magick[MagickPathExtent],
1925 filename[MagickPathExtent];
1927 register const Image
1930 assert(image != (Image *) NULL);
1931 if (image->debug != MagickFalse)
1932 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1933 assert(image->signature == MagickCoreSignature);
1934 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1935 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1936 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1938 if (p->taint != MagickFalse)
1940 if (LocaleCompare(p->magick,magick) != 0)
1942 if (LocaleCompare(p->filename,filename) != 0)
1945 return(MagickFalse);
1949 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1953 % M o d i f y I m a g e %
1957 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1959 % ModifyImage() ensures that there is only a single reference to the image
1960 % to be modified, updating the provided image pointer to point to a clone of
1961 % the original image if necessary.
1963 % The format of the ModifyImage method is:
1965 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1967 % A description of each parameter follows:
1969 % o image: the image.
1971 % o exception: return any errors or warnings in this structure.
1974 MagickExport MagickBooleanType ModifyImage(Image **image,
1975 ExceptionInfo *exception)
1980 assert(image != (Image **) NULL);
1981 assert(*image != (Image *) NULL);
1982 assert((*image)->signature == MagickCoreSignature);
1983 if ((*image)->debug != MagickFalse)
1984 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1985 if (GetImageReferenceCount(*image) <= 1)
1987 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1988 LockSemaphoreInfo((*image)->semaphore);
1989 (*image)->reference_count--;
1990 UnlockSemaphoreInfo((*image)->semaphore);
1996 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2000 % N e w M a g i c k I m a g e %
2004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2006 % NewMagickImage() creates a blank image canvas of the specified size and
2009 % The format of the NewMagickImage method is:
2011 % Image *NewMagickImage(const ImageInfo *image_info,const size_t width,
2012 % const size_t height,const PixelInfo *background,
2013 % ExceptionInfo *exception)
2015 % A description of each parameter follows:
2017 % o image: the image.
2019 % o width: the image width.
2021 % o height: the image height.
2023 % o background: the image color.
2025 % o exception: return any errors or warnings in this structure.
2028 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2029 const size_t width,const size_t height,const PixelInfo *background,
2030 ExceptionInfo *exception)
2044 assert(image_info != (const ImageInfo *) NULL);
2045 if (image_info->debug != MagickFalse)
2046 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2047 assert(image_info->signature == MagickCoreSignature);
2048 assert(background != (const PixelInfo *) NULL);
2049 image=AcquireImage(image_info,exception);
2050 image->columns=width;
2052 image->colorspace=background->colorspace;
2053 image->alpha_trait=background->alpha_trait;
2054 image->fuzz=background->fuzz;
2055 image->depth=background->depth;
2057 image_view=AcquireAuthenticCacheView(image,exception);
2058 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2059 #pragma omp parallel for schedule(static,4) shared(status) \
2060 magick_threads(image,image,image->rows,1)
2062 for (y=0; y < (ssize_t) image->rows; y++)
2070 if (status == MagickFalse)
2072 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2073 if (q == (Quantum *) NULL)
2078 for (x=0; x < (ssize_t) image->columns; x++)
2080 SetPixelViaPixelInfo(image,background,q);
2081 q+=GetPixelChannels(image);
2083 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2086 image_view=DestroyCacheView(image_view);
2087 if (status == MagickFalse)
2088 image=DestroyImage(image);
2093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2097 % R e f e r e n c e I m a g e %
2101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2103 % ReferenceImage() increments the reference count associated with an image
2104 % returning a pointer to the image.
2106 % The format of the ReferenceImage method is:
2108 % Image *ReferenceImage(Image *image)
2110 % A description of each parameter follows:
2112 % o image: the image.
2115 MagickExport Image *ReferenceImage(Image *image)
2117 assert(image != (Image *) NULL);
2118 if (image->debug != MagickFalse)
2119 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2120 assert(image->signature == MagickCoreSignature);
2121 LockSemaphoreInfo(image->semaphore);
2122 image->reference_count++;
2123 UnlockSemaphoreInfo(image->semaphore);
2128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2132 % R e s e t I m a g e P a g e %
2136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2138 % ResetImagePage() resets the image page canvas and position.
2140 % The format of the ResetImagePage method is:
2142 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2144 % A description of each parameter follows:
2146 % o image: the image.
2148 % o page: the relative page specification.
2151 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2159 assert(image != (Image *) NULL);
2160 assert(image->signature == MagickCoreSignature);
2161 if (image->debug != MagickFalse)
2162 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2163 flags=ParseAbsoluteGeometry(page,&geometry);
2164 if ((flags & WidthValue) != 0)
2166 if ((flags & HeightValue) == 0)
2167 geometry.height=geometry.width;
2168 image->page.width=geometry.width;
2169 image->page.height=geometry.height;
2171 if ((flags & AspectValue) != 0)
2173 if ((flags & XValue) != 0)
2174 image->page.x+=geometry.x;
2175 if ((flags & YValue) != 0)
2176 image->page.y+=geometry.y;
2180 if ((flags & XValue) != 0)
2182 image->page.x=geometry.x;
2183 if ((image->page.width == 0) && (geometry.x > 0))
2184 image->page.width=image->columns+geometry.x;
2186 if ((flags & YValue) != 0)
2188 image->page.y=geometry.y;
2189 if ((image->page.height == 0) && (geometry.y > 0))
2190 image->page.height=image->rows+geometry.y;
2197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2201 % S e t I m a g e B a c k g r o u n d C o l o r %
2205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2207 % SetImageBackgroundColor() initializes the image pixels to the image
2208 % background color. The background color is defined by the background_color
2209 % member of the image structure.
2211 % The format of the SetImage method is:
2213 % MagickBooleanType SetImageBackgroundColor(Image *image,
2214 % ExceptionInfo *exception)
2216 % A description of each parameter follows:
2218 % o image: the image.
2220 % o exception: return any errors or warnings in this structure.
2223 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2224 ExceptionInfo *exception)
2238 assert(image != (Image *) NULL);
2239 if (image->debug != MagickFalse)
2240 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2241 assert(image->signature == MagickCoreSignature);
2242 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2243 return(MagickFalse);
2244 if ((image->background_color.alpha != OpaqueAlpha) &&
2245 (image->alpha_trait == UndefinedPixelTrait))
2246 (void) SetImageAlphaChannel(image,OnAlphaChannel,exception);
2247 ConformPixelInfo(image,&image->background_color,&background,exception);
2249 Set image background color.
2252 image_view=AcquireAuthenticCacheView(image,exception);
2253 for (y=0; y < (ssize_t) image->rows; y++)
2261 if (status == MagickFalse)
2263 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2264 if (q == (Quantum *) NULL)
2269 for (x=0; x < (ssize_t) image->columns; x++)
2271 SetPixelViaPixelInfo(image,&background,q);
2272 q+=GetPixelChannels(image);
2274 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2277 image_view=DestroyCacheView(image_view);
2282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2286 % S e t I m a g e C h a n n e l M a s k %
2290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2292 % SetImageChannelMask() sets the image channel mask from the specified channel
2295 % The format of the SetImageChannelMask method is:
2297 % ChannelType SetImageChannelMask(Image *image,
2298 % const ChannelType channel_mask)
2300 % A description of each parameter follows:
2302 % o image: the image.
2304 % o channel_mask: the channel mask.
2307 MagickExport ChannelType SetImageChannelMask(Image *image,
2308 const ChannelType channel_mask)
2310 return(SetPixelChannelMask(image,channel_mask));
2314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2318 % S e t I m a g e C o l o r %
2322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2324 % SetImageColor() set the entire image canvas to the specified color.
2326 % The format of the SetImageColor method is:
2328 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2329 % ExeptionInfo *exception)
2331 % A description of each parameter follows:
2333 % o image: the image.
2335 % o background: the image color.
2337 % o exception: return any errors or warnings in this structure.
2340 MagickExport MagickBooleanType SetImageColor(Image *image,
2341 const PixelInfo *color,ExceptionInfo *exception)
2352 assert(image != (Image *) NULL);
2353 if (image->debug != MagickFalse)
2354 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2355 assert(image->signature == MagickCoreSignature);
2356 assert(color != (const PixelInfo *) NULL);
2357 image->colorspace=color->colorspace;
2358 image->alpha_trait=color->alpha_trait;
2359 image->fuzz=color->fuzz;
2360 image->depth=color->depth;
2362 image_view=AcquireAuthenticCacheView(image,exception);
2363 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2364 #pragma omp parallel for schedule(static,4) shared(status) \
2365 magick_threads(image,image,image->rows,1)
2367 for (y=0; y < (ssize_t) image->rows; y++)
2375 if (status == MagickFalse)
2377 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2378 if (q == (Quantum *) NULL)
2383 for (x=0; x < (ssize_t) image->columns; x++)
2385 SetPixelViaPixelInfo(image,color,q);
2386 q+=GetPixelChannels(image);
2388 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2391 image_view=DestroyCacheView(image_view);
2396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2400 % S e t I m a g e S t o r a g e C l a s s %
2404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2406 % SetImageStorageClass() sets the image class: DirectClass for true color
2407 % images or PseudoClass for colormapped images.
2409 % The format of the SetImageStorageClass method is:
2411 % MagickBooleanType SetImageStorageClass(Image *image,
2412 % const ClassType storage_class,ExceptionInfo *exception)
2414 % A description of each parameter follows:
2416 % o image: the image.
2418 % o storage_class: The image class.
2420 % o exception: return any errors or warnings in this structure.
2423 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2424 const ClassType storage_class,ExceptionInfo *exception)
2426 assert(image != (Image *) NULL);
2427 assert(image->signature == MagickCoreSignature);
2428 if (image->debug != MagickFalse)
2429 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2430 assert(exception != (ExceptionInfo *) NULL);
2431 assert(exception->signature == MagickCoreSignature);
2432 image->storage_class=storage_class;
2437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2441 % S e t I m a g e E x t e n t %
2445 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2447 % SetImageExtent() sets the image size (i.e. columns & rows).
2449 % The format of the SetImageExtent method is:
2451 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2452 % const size_t rows,ExceptionInfo *exception)
2454 % A description of each parameter follows:
2456 % o image: the image.
2458 % o columns: The image width in pixels.
2460 % o rows: The image height in pixels.
2462 % o exception: return any errors or warnings in this structure.
2465 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2466 const size_t rows,ExceptionInfo *exception)
2468 if ((columns == 0) || (rows == 0))
2469 ThrowBinaryException(ImageError,"NegativeOrZeroImageSize",image->filename);
2470 image->columns=columns;
2472 if (image->depth > (8*sizeof(MagickSizeType)))
2473 ThrowBinaryException(ImageError,"ImageDepthNotSupported",image->filename);
2474 return(SyncImagePixelCache(image,exception));
2478 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2482 + S e t I m a g e I n f o %
2486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2488 % SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
2489 % It is set to a type of image format based on the prefix or suffix of the
2490 % filename. For example, 'ps:image' returns PS indicating a Postscript image.
2491 % JPEG is returned for this filename: 'image.jpg'. The filename prefix has
2492 % precendence over the suffix. Use an optional index enclosed in brackets
2493 % after a file name to specify a desired scene of a multi-resolution image
2494 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2495 % indicates success.
2497 % The format of the SetImageInfo method is:
2499 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2500 % const unsigned int frames,ExceptionInfo *exception)
2502 % A description of each parameter follows:
2504 % o image_info: the image info.
2506 % o frames: the number of images you intend to write.
2508 % o exception: return any errors or warnings in this structure.
2511 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2512 const unsigned int frames,ExceptionInfo *exception)
2515 component[MagickPathExtent],
2516 magic[MagickPathExtent],
2541 Look for 'image.format' in filename.
2543 assert(image_info != (ImageInfo *) NULL);
2544 assert(image_info->signature == MagickCoreSignature);
2545 if (image_info->debug != MagickFalse)
2546 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2547 image_info->filename);
2549 GetPathComponent(image_info->filename,SubimagePath,component);
2550 if (*component != '\0')
2553 Look for scene specification (e.g. img0001.pcd[4]).
2555 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2557 if (IsGeometry(component) != MagickFalse)
2558 (void) CloneString(&image_info->extract,component);
2566 (void) CloneString(&image_info->scenes,component);
2567 image_info->scene=StringToUnsignedLong(image_info->scenes);
2568 image_info->number_scenes=image_info->scene;
2569 p=image_info->scenes;
2570 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2572 while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2574 first=(size_t) strtol(p,&q,10);
2576 while (isspace((int) ((unsigned char) *q)) != 0)
2579 last=(size_t) strtol(q+1,&q,10);
2582 if (first < image_info->scene)
2583 image_info->scene=first;
2584 if (last > image_info->number_scenes)
2585 image_info->number_scenes=last;
2588 image_info->number_scenes-=image_info->scene-1;
2592 if (*image_info->magick == '\0')
2593 GetPathComponent(image_info->filename,ExtensionPath,component);
2594 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2595 if (*component != '\0')
2596 if ((LocaleCompare(component,"gz") == 0) ||
2597 (LocaleCompare(component,"Z") == 0) ||
2598 (LocaleCompare(component,"svgz") == 0) ||
2599 (LocaleCompare(component,"wmz") == 0))
2602 path[MagickPathExtent];
2604 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2605 path[strlen(path)-strlen(component)-1]='\0';
2606 GetPathComponent(path,ExtensionPath,component);
2609 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2610 if (*component != '\0')
2611 if (LocaleCompare(component,"bz2") == 0)
2614 path[MagickPathExtent];
2616 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2617 path[strlen(path)-strlen(component)-1]='\0';
2618 GetPathComponent(path,ExtensionPath,component);
2621 image_info->affirm=MagickFalse;
2622 sans_exception=AcquireExceptionInfo();
2623 if (*component != '\0')
2632 *format_type_formats[] =
2654 User specified image format.
2656 (void) CopyMagickString(magic,component,MagickPathExtent);
2659 Look for explicit image formats.
2661 format_type=UndefinedFormatType;
2662 magick_info=GetMagickInfo(magic,sans_exception);
2663 if ((magick_info != (const MagickInfo *) NULL) &&
2664 (magick_info->format_type != UndefinedFormatType))
2665 format_type=magick_info->format_type;
2667 while ((format_type == UndefinedFormatType) &&
2668 (format_type_formats[i] != (char *) NULL))
2670 if ((*magic == *format_type_formats[i]) &&
2671 (LocaleCompare(magic,format_type_formats[i]) == 0))
2672 format_type=ExplicitFormatType;
2675 if (format_type == UndefinedFormatType)
2676 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2678 if (format_type == ExplicitFormatType)
2680 image_info->affirm=MagickTrue;
2681 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2683 if (LocaleCompare(magic,"RGB") == 0)
2684 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2687 Look for explicit 'format:image' in filename.
2690 GetPathComponent(image_info->filename,MagickPath,magic);
2693 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2694 magick_info=GetMagickInfo(magic,sans_exception);
2695 GetPathComponent(image_info->filename,CanonicalPath,component);
2696 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2704 User specified image format.
2707 magick_info=GetMagickInfo(magic,sans_exception);
2708 delegate_info=GetDelegateInfo(magic,"*",sans_exception);
2709 if (delegate_info == (const DelegateInfo *) NULL)
2710 delegate_info=GetDelegateInfo("*",magic,sans_exception);
2711 if (((magick_info != (const MagickInfo *) NULL) ||
2712 (delegate_info != (const DelegateInfo *) NULL)) &&
2713 (IsMagickConflict(magic) == MagickFalse))
2715 image_info->affirm=MagickTrue;
2716 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2717 GetPathComponent(image_info->filename,CanonicalPath,component);
2718 (void) CopyMagickString(image_info->filename,component,
2722 sans_exception=DestroyExceptionInfo(sans_exception);
2723 if ((magick_info == (const MagickInfo *) NULL) ||
2724 (GetMagickEndianSupport(magick_info) == MagickFalse))
2725 image_info->endian=UndefinedEndian;
2726 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2729 Test for multiple image support (e.g. image%02d.png).
2731 (void) InterpretImageFilename(image_info,(Image *) NULL,
2732 image_info->filename,(int) image_info->scene,component,exception);
2733 if ((LocaleCompare(component,image_info->filename) != 0) &&
2734 (strchr(component,'%') == (char *) NULL))
2735 image_info->adjoin=MagickFalse;
2737 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2740 Some image formats do not support multiple frames per file.
2742 magick_info=GetMagickInfo(magic,exception);
2743 if (magick_info != (const MagickInfo *) NULL)
2744 if (GetMagickAdjoin(magick_info) == MagickFalse)
2745 image_info->adjoin=MagickFalse;
2747 if (image_info->affirm != MagickFalse)
2758 Determine the image format from the first few bytes of the file.
2760 magick_size=GetMagicPatternExtent(exception);
2761 if (magick_size == 0)
2762 return(MagickFalse);
2763 image=AcquireImage(image_info,exception);
2764 (void) CopyMagickString(image->filename,image_info->filename,
2766 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2767 if (status == MagickFalse)
2769 image=DestroyImage(image);
2770 return(MagickFalse);
2772 if ((IsBlobSeekable(image) == MagickFalse) ||
2773 (IsBlobExempt(image) != MagickFalse))
2776 Copy standard input or pipe to temporary file.
2779 status=ImageToFile(image,component,exception);
2780 (void) CloseBlob(image);
2781 if (status == MagickFalse)
2783 image=DestroyImage(image);
2784 return(MagickFalse);
2786 SetImageInfoFile(image_info,(FILE *) NULL);
2787 (void) CopyMagickString(image->filename,component,MagickPathExtent);
2788 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2789 if (status == MagickFalse)
2791 image=DestroyImage(image);
2792 return(MagickFalse);
2794 (void) CopyMagickString(image_info->filename,component,
2796 image_info->temporary=MagickTrue;
2798 magick=(unsigned char *) AcquireMagickMemory(magick_size);
2799 if (magick == (unsigned char *) NULL)
2801 (void) CloseBlob(image);
2802 image=DestroyImage(image);
2803 return(MagickFalse);
2805 (void) ResetMagickMemory(magick,0,magick_size);
2806 count=ReadBlob(image,magick_size,magick);
2807 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
2808 (void) CloseBlob(image);
2809 image=DestroyImage(image);
2811 Check magic.xml configuration file.
2813 sans_exception=AcquireExceptionInfo();
2814 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
2815 magick=(unsigned char *) RelinquishMagickMemory(magick);
2816 if ((magic_info != (const MagicInfo *) NULL) &&
2817 (GetMagicName(magic_info) != (char *) NULL))
2820 Try to use magick_info that was determined earlier by the extension
2822 if ((magick_info != (const MagickInfo *) NULL) &&
2823 (GetMagickUseExtension(magick_info) != MagickFalse) &&
2824 (LocaleCompare(magick_info->module,GetMagicName(
2826 (void) CopyMagickString(image_info->magick,magick_info->name,
2830 (void) CopyMagickString(image_info->magick,GetMagicName(
2831 magic_info),MagickPathExtent);
2832 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2834 if ((magick_info == (const MagickInfo *) NULL) ||
2835 (GetMagickEndianSupport(magick_info) == MagickFalse))
2836 image_info->endian=UndefinedEndian;
2837 sans_exception=DestroyExceptionInfo(sans_exception);
2840 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2841 if ((magick_info == (const MagickInfo *) NULL) ||
2842 (GetMagickEndianSupport(magick_info) == MagickFalse))
2843 image_info->endian=UndefinedEndian;
2844 sans_exception=DestroyExceptionInfo(sans_exception);
2850 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2854 % S e t I m a g e I n f o B l o b %
2858 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2860 % SetImageInfoBlob() sets the image info blob member.
2862 % The format of the SetImageInfoBlob method is:
2864 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2865 % const size_t length)
2867 % A description of each parameter follows:
2869 % o image_info: the image info.
2873 % o length: the blob length.
2876 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2877 const size_t length)
2879 assert(image_info != (ImageInfo *) NULL);
2880 assert(image_info->signature == MagickCoreSignature);
2881 if (image_info->debug != MagickFalse)
2882 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2883 image_info->filename);
2884 image_info->blob=(void *) blob;
2885 image_info->length=length;
2889 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2893 % S e t I m a g e I n f o F i l e %
2897 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2899 % SetImageInfoFile() sets the image info file member.
2901 % The format of the SetImageInfoFile method is:
2903 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2905 % A description of each parameter follows:
2907 % o image_info: the image info.
2912 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2914 assert(image_info != (ImageInfo *) NULL);
2915 assert(image_info->signature == MagickCoreSignature);
2916 if (image_info->debug != MagickFalse)
2917 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2918 image_info->filename);
2919 image_info->file=file;
2923 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2927 % S e t I m a g e A l p h a %
2931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2933 % SetImageAlpha() sets the alpha levels of the image.
2935 % The format of the SetImageAlpha method is:
2937 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
2938 % ExceptionInfo *exception)
2940 % A description of each parameter follows:
2942 % o image: the image.
2944 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
2945 % fully transparent.
2948 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
2949 ExceptionInfo *exception)
2960 assert(image != (Image *) NULL);
2961 if (image->debug != MagickFalse)
2962 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2963 assert(image->signature == MagickCoreSignature);
2964 image->alpha_trait=BlendPixelTrait;
2966 image_view=AcquireAuthenticCacheView(image,exception);
2967 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2968 #pragma omp parallel for schedule(static,4) shared(status) \
2969 magick_threads(image,image,image->rows,1)
2971 for (y=0; y < (ssize_t) image->rows; y++)
2979 if (status == MagickFalse)
2981 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2982 if (q == (Quantum *) NULL)
2987 for (x=0; x < (ssize_t) image->columns; x++)
2989 if (GetPixelWriteMask(image,q) != 0)
2990 SetPixelAlpha(image,alpha,q);
2991 q+=GetPixelChannels(image);
2993 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2996 image_view=DestroyCacheView(image_view);
3001 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3005 % S e t I m a g e M a s k %
3009 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3011 % SetImageMask() associates a mask with the image. The mask must be the same
3012 % dimensions as the image.
3014 % The format of the SetImageMask method is:
3016 % MagickBooleanType SetImageMask(Image *image,const PixelMask type,
3017 % const Image *mask,ExceptionInfo *exception)
3019 % A description of each parameter follows:
3021 % o image: the image.
3023 % o type: the mask type, ReadPixelMask or WritePixelMask.
3025 % o mask: the image mask.
3027 % o exception: return any errors or warnings in this structure.
3030 MagickExport MagickBooleanType SetImageMask(Image *image,const PixelMask type,
3031 const Image *mask,ExceptionInfo *exception)
3046 assert(image != (Image *) NULL);
3047 if (image->debug != MagickFalse)
3048 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3049 assert(image->signature == MagickCoreSignature);
3050 if (mask == (const Image *) NULL)
3054 case WritePixelMask: image->write_mask=MagickFalse; break;
3055 default: image->read_mask=MagickFalse; break;
3057 return(SyncImagePixelCache(image,exception));
3061 case WritePixelMask: image->write_mask=MagickTrue; break;
3062 default: image->read_mask=MagickTrue; break;
3064 if (SyncImagePixelCache(image,exception) == MagickFalse)
3065 return(MagickFalse);
3067 mask_view=AcquireVirtualCacheView(mask,exception);
3068 image_view=AcquireAuthenticCacheView(image,exception);
3069 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3070 #pragma omp parallel for schedule(static,4) shared(status) \
3071 magick_threads(mask,image,1,1)
3073 for (y=0; y < (ssize_t) image->rows; y++)
3075 register const Quantum
3084 if (status == MagickFalse)
3086 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3087 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3088 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3093 for (x=0; x < (ssize_t) image->columns; x++)
3099 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3100 intensity=GetPixelIntensity(mask,p);
3103 case WritePixelMask:
3105 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3110 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3114 p+=GetPixelChannels(mask);
3115 q+=GetPixelChannels(image);
3117 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3120 mask_view=DestroyCacheView(mask_view);
3121 image_view=DestroyCacheView(image_view);
3126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3130 % S e t I m a g e R e g i o n M a s k %
3134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3136 % SetImageRegionMask() associates a mask with the image as defined by the
3139 % The format of the SetImageRegionMask method is:
3141 % MagickBooleanType SetImageRegionMask(Image *image,const PixelMask type,
3142 % const RectangleInfo *region,ExceptionInfo *exception)
3144 % A description of each parameter follows:
3146 % o image: the image.
3148 % o type: the mask type, ReadPixelMask or WritePixelMask.
3150 % o geometry: the mask region.
3152 % o exception: return any errors or warnings in this structure.
3155 MagickExport MagickBooleanType SetImageRegionMask(Image *image,
3156 const PixelMask type,const RectangleInfo *region,ExceptionInfo *exception)
3168 Set image mask as defined by the region.
3170 assert(image != (Image *) NULL);
3171 if (image->debug != MagickFalse)
3172 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3173 assert(image->signature == MagickCoreSignature);
3174 if (region == (const RectangleInfo *) NULL)
3178 case WritePixelMask: image->write_mask=MagickFalse; break;
3179 default: image->read_mask=MagickFalse; break;
3181 return(SyncImagePixelCache(image,exception));
3185 case WritePixelMask: image->write_mask=MagickTrue; break;
3186 default: image->read_mask=MagickTrue; break;
3188 if (SyncImagePixelCache(image,exception) == MagickFalse)
3189 return(MagickFalse);
3191 image_view=AcquireAuthenticCacheView(image,exception);
3192 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3193 #pragma omp parallel for schedule(static,4) shared(status) \
3194 magick_threads(image,image,1,1)
3196 for (y=0; y < (ssize_t) image->rows; y++)
3204 if (status == MagickFalse)
3206 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3207 if (q == (Quantum *) NULL)
3212 for (x=0; x < (ssize_t) image->columns; x++)
3218 if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3219 ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3223 case WritePixelMask:
3225 SetPixelWriteMask(image,pixel,q);
3230 SetPixelReadMask(image,pixel,q);
3234 q+=GetPixelChannels(image);
3236 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3239 image_view=DestroyCacheView(image_view);
3244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3248 % 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 %
3252 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3254 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3255 % image and returns the previous setting. A virtual pixel is any pixel access
3256 % that is outside the boundaries of the image cache.
3258 % The format of the SetImageVirtualPixelMethod() method is:
3260 % VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3261 % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3263 % A description of each parameter follows:
3265 % o image: the image.
3267 % o virtual_pixel_method: choose the type of virtual pixel.
3269 % o exception: return any errors or warnings in this structure.
3272 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3273 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3275 assert(image != (const Image *) NULL);
3276 assert(image->signature == MagickCoreSignature);
3277 if (image->debug != MagickFalse)
3278 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3279 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3287 % S m u s h I m a g e s %
3291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3293 % SmushImages() takes all images from the current image pointer to the end
3294 % of the image list and smushes them to each other top-to-bottom if the
3295 % stack parameter is true, otherwise left-to-right.
3297 % The current gravity setting now effects how the image is justified in the
3300 % The format of the SmushImages method is:
3302 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3303 % ExceptionInfo *exception)
3305 % A description of each parameter follows:
3307 % o images: the image sequence.
3309 % o stack: A value other than 0 stacks the images top-to-bottom.
3311 % o offset: minimum distance in pixels between images.
3313 % o exception: return any errors or warnings in this structure.
3317 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3318 const ssize_t offset,ExceptionInfo *exception)
3332 register const Quantum
3345 if (images->previous == (Image *) NULL)
3348 SetGeometry(smush_image,&right_geometry);
3349 GravityAdjustGeometry(right_image->columns,right_image->rows,
3350 right_image->gravity,&right_geometry);
3351 left_image=images->previous;
3352 SetGeometry(smush_image,&left_geometry);
3353 GravityAdjustGeometry(left_image->columns,left_image->rows,
3354 left_image->gravity,&left_geometry);
3355 gap=right_image->columns;
3356 left_view=AcquireVirtualCacheView(left_image,exception);
3357 right_view=AcquireVirtualCacheView(right_image,exception);
3358 for (y=0; y < (ssize_t) smush_image->rows; y++)
3360 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3362 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3363 if ((p == (const Quantum *) NULL) ||
3364 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3365 ((left_image->columns-x-1) >= gap))
3368 i=(ssize_t) left_image->columns-x-1;
3369 for (x=0; x < (ssize_t) right_image->columns; x++)
3371 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3373 if ((p == (const Quantum *) NULL) ||
3374 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3375 ((x+i) >= (ssize_t) gap))
3378 if ((x+i) < (ssize_t) gap)
3381 right_view=DestroyCacheView(right_view);
3382 left_view=DestroyCacheView(left_view);
3383 if (y < (ssize_t) smush_image->rows)
3385 return((ssize_t) gap-offset);
3388 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3389 const ssize_t offset,ExceptionInfo *exception)
3403 register const Quantum
3416 if (images->previous == (Image *) NULL)
3418 bottom_image=images;
3419 SetGeometry(smush_image,&bottom_geometry);
3420 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3421 bottom_image->gravity,&bottom_geometry);
3422 top_image=images->previous;
3423 SetGeometry(smush_image,&top_geometry);
3424 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3426 gap=bottom_image->rows;
3427 top_view=AcquireVirtualCacheView(top_image,exception);
3428 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3429 for (x=0; x < (ssize_t) smush_image->columns; x++)
3431 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3433 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3434 if ((p == (const Quantum *) NULL) ||
3435 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3436 ((top_image->rows-y-1) >= gap))
3439 i=(ssize_t) top_image->rows-y-1;
3440 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3442 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3444 if ((p == (const Quantum *) NULL) ||
3445 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3446 ((y+i) >= (ssize_t) gap))
3449 if ((y+i) < (ssize_t) gap)
3452 bottom_view=DestroyCacheView(bottom_view);
3453 top_view=DestroyCacheView(top_view);
3454 if (x < (ssize_t) smush_image->columns)
3456 return((ssize_t) gap-offset);
3459 MagickExport Image *SmushImages(const Image *images,
3460 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3462 #define SmushImageTag "Smush/Image"
3483 register const Image
3496 Compute maximum area of smushed area.
3498 assert(images != (Image *) NULL);
3499 assert(images->signature == MagickCoreSignature);
3500 if (images->debug != MagickFalse)
3501 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3502 assert(exception != (ExceptionInfo *) NULL);
3503 assert(exception->signature == MagickCoreSignature);
3505 alpha_trait=image->alpha_trait;
3507 width=image->columns;
3509 next=GetNextImageInList(image);
3510 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3512 if (next->alpha_trait != UndefinedPixelTrait)
3513 alpha_trait=BlendPixelTrait;
3515 if (stack != MagickFalse)
3517 if (next->columns > width)
3518 width=next->columns;
3520 if (next->previous != (Image *) NULL)
3524 width+=next->columns;
3525 if (next->previous != (Image *) NULL)
3527 if (next->rows > height)
3533 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3534 if (smush_image == (Image *) NULL)
3535 return((Image *) NULL);
3536 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3538 smush_image=DestroyImage(smush_image);
3539 return((Image *) NULL);
3541 smush_image->alpha_trait=alpha_trait;
3542 (void) SetImageBackgroundColor(smush_image,exception);
3546 for (n=0; n < (MagickOffsetType) number_images; n++)
3548 SetGeometry(smush_image,&geometry);
3549 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3550 if (stack != MagickFalse)
3552 x_offset-=geometry.x;
3553 y_offset-=SmushYGap(smush_image,image,offset,exception);
3557 x_offset-=SmushXGap(smush_image,image,offset,exception);
3558 y_offset-=geometry.y;
3560 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3561 y_offset,exception);
3562 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3563 if (proceed == MagickFalse)
3565 if (stack == MagickFalse)
3567 x_offset+=(ssize_t) image->columns;
3573 y_offset+=(ssize_t) image->rows;
3575 image=GetNextImageInList(image);
3577 if (stack == MagickFalse)
3578 smush_image->columns=(size_t) x_offset;
3580 smush_image->rows=(size_t) y_offset;
3581 if (status == MagickFalse)
3582 smush_image=DestroyImage(smush_image);
3583 return(smush_image);
3587 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3591 % S t r i p I m a g e %
3595 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3597 % StripImage() strips an image of all profiles and comments.
3599 % The format of the StripImage method is:
3601 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3603 % A description of each parameter follows:
3605 % o image: the image.
3607 % o exception: return any errors or warnings in this structure.
3610 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3615 assert(image != (Image *) NULL);
3616 if (image->debug != MagickFalse)
3617 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3619 DestroyImageProfiles(image);
3620 (void) DeleteImageProperty(image,"comment");
3621 (void) DeleteImageProperty(image,"date:create");
3622 (void) DeleteImageProperty(image,"date:modify");
3623 status=SetImageArtifact(image,"png:exclude-chunk",
3624 "bKGD,cHRM,EXIF,gAMA,iCCP,iTXt,sRGB,tEXt,zCCP,zTXt,date");
3629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3633 + S y n c I m a g e %
3637 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3639 % SyncImage() initializes the red, green, and blue intensities of each pixel
3640 % as defined by the colormap index.
3642 % The format of the SyncImage method is:
3644 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3646 % A description of each parameter follows:
3648 % o image: the image.
3650 % o exception: return any errors or warnings in this structure.
3654 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3655 MagickBooleanType *range_exception)
3657 if ((size_t) index < image->colors)
3659 *range_exception=MagickTrue;
3660 return((Quantum) 0);
3663 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3676 assert(image != (Image *) NULL);
3677 if (image->debug != MagickFalse)
3678 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3679 assert(image->signature == MagickCoreSignature);
3680 if (image->storage_class == DirectClass)
3681 return(MagickFalse);
3682 range_exception=MagickFalse;
3685 image_view=AcquireAuthenticCacheView(image,exception);
3686 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3687 #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
3688 magick_threads(image,image,image->rows,1)
3690 for (y=0; y < (ssize_t) image->rows; y++)
3701 if (status == MagickFalse)
3703 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3704 if (q == (Quantum *) NULL)
3709 for (x=0; x < (ssize_t) image->columns; x++)
3711 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3712 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
3713 q+=GetPixelChannels(image);
3715 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3718 image_view=DestroyCacheView(image_view);
3720 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3721 (void) ThrowMagickException(exception,GetMagickModule(),
3722 CorruptImageWarning,"InvalidColormapIndex","`%s'",image->filename);
3727 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3731 % S y n c I m a g e S e t t i n g s %
3735 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3737 % SyncImageSettings() syncs any image_info global options into per-image
3740 % Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
3741 % that operations and coders can find such settings. In IMv7 if a desired
3742 % per-image artifact is not set, then it will directly look for a global
3743 % option as a fallback, as such this copy is no longer needed, only the
3746 % The format of the SyncImageSettings method is:
3748 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3749 % Image *image,ExceptionInfo *exception)
3750 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3751 % Image *image,ExceptionInfo *exception)
3753 % A description of each parameter follows:
3755 % o image_info: the image info.
3757 % o image: the image.
3759 % o exception: return any errors or warnings in this structure.
3763 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3764 Image *images,ExceptionInfo *exception)
3769 assert(image_info != (const ImageInfo *) NULL);
3770 assert(image_info->signature == MagickCoreSignature);
3771 assert(images != (Image *) NULL);
3772 assert(images->signature == MagickCoreSignature);
3773 if (images->debug != MagickFalse)
3774 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3776 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3777 (void) SyncImageSettings(image_info,image,exception);
3778 (void) DeleteImageOption(image_info,"page");
3782 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3783 Image *image,ExceptionInfo *exception)
3800 assert(image_info != (const ImageInfo *) NULL);
3801 assert(image_info->signature == MagickCoreSignature);
3802 assert(image != (Image *) NULL);
3803 assert(image->signature == MagickCoreSignature);
3804 if (image->debug != MagickFalse)
3805 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3806 option=GetImageOption(image_info,"alpha-color");
3807 if (option != (const char *) NULL)
3808 (void) QueryColorCompliance(option,AllCompliance,&image->alpha_color,
3810 option=GetImageOption(image_info,"background");
3811 if (option != (const char *) NULL)
3812 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
3814 option=GetImageOption(image_info,"black-point-compensation");
3815 if (option != (const char *) NULL)
3816 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3817 MagickBooleanOptions,MagickFalse,option);
3818 option=GetImageOption(image_info,"blue-primary");
3819 if (option != (const char *) NULL)
3821 flags=ParseGeometry(option,&geometry_info);
3822 image->chromaticity.blue_primary.x=geometry_info.rho;
3823 image->chromaticity.blue_primary.y=geometry_info.sigma;
3824 if ((flags & SigmaValue) == 0)
3825 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3827 option=GetImageOption(image_info,"bordercolor");
3828 if (option != (const char *) NULL)
3829 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
3831 /* FUTURE: do not sync compose to per-image compose setting here */
3832 option=GetImageOption(image_info,"compose");
3833 if (option != (const char *) NULL)
3834 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3835 MagickFalse,option);
3837 option=GetImageOption(image_info,"compress");
3838 if (option != (const char *) NULL)
3839 image->compression=(CompressionType) ParseCommandOption(
3840 MagickCompressOptions,MagickFalse,option);
3841 option=GetImageOption(image_info,"debug");
3842 if (option != (const char *) NULL)
3843 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3844 MagickFalse,option);
3845 option=GetImageOption(image_info,"density");
3846 if (option != (const char *) NULL)
3848 flags=ParseGeometry(option,&geometry_info);
3849 image->resolution.x=geometry_info.rho;
3850 image->resolution.y=geometry_info.sigma;
3851 if ((flags & SigmaValue) == 0)
3852 image->resolution.y=image->resolution.x;
3854 option=GetImageOption(image_info,"depth");
3855 if (option != (const char *) NULL)
3856 image->depth=StringToUnsignedLong(option);
3857 option=GetImageOption(image_info,"endian");
3858 if (option != (const char *) NULL)
3859 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3860 MagickFalse,option);
3861 option=GetImageOption(image_info,"filter");
3862 if (option != (const char *) NULL)
3863 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
3864 MagickFalse,option);
3865 option=GetImageOption(image_info,"fuzz");
3866 if (option != (const char *) NULL)
3867 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3868 option=GetImageOption(image_info,"gravity");
3869 if (option != (const char *) NULL)
3870 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3871 MagickFalse,option);
3872 option=GetImageOption(image_info,"green-primary");
3873 if (option != (const char *) NULL)
3875 flags=ParseGeometry(option,&geometry_info);
3876 image->chromaticity.green_primary.x=geometry_info.rho;
3877 image->chromaticity.green_primary.y=geometry_info.sigma;
3878 if ((flags & SigmaValue) == 0)
3879 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3881 option=GetImageOption(image_info,"intent");
3882 if (option != (const char *) NULL)
3883 image->rendering_intent=(RenderingIntent) ParseCommandOption(
3884 MagickIntentOptions,MagickFalse,option);
3885 option=GetImageOption(image_info,"intensity");
3886 if (option != (const char *) NULL)
3887 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3888 MagickPixelIntensityOptions,MagickFalse,option);
3889 option=GetImageOption(image_info,"interlace");
3890 if (option != (const char *) NULL)
3891 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3892 MagickFalse,option);
3893 option=GetImageOption(image_info,"interpolate");
3894 if (option != (const char *) NULL)
3895 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
3896 MagickInterpolateOptions,MagickFalse,option);
3897 option=GetImageOption(image_info,"loop");
3898 if (option != (const char *) NULL)
3899 image->iterations=StringToUnsignedLong(option);
3900 option=GetImageOption(image_info,"orient");
3901 if (option != (const char *) NULL)
3902 image->orientation=(OrientationType) ParseCommandOption(
3903 MagickOrientationOptions,MagickFalse,option);
3904 option=GetImageOption(image_info,"page");
3905 if (option != (const char *) NULL)
3910 geometry=GetPageGeometry(option);
3911 flags=ParseAbsoluteGeometry(geometry,&image->page);
3912 geometry=DestroyString(geometry);
3914 option=GetImageOption(image_info,"quality");
3915 if (option != (const char *) NULL)
3916 image->quality=StringToUnsignedLong(option);
3917 option=GetImageOption(image_info,"red-primary");
3918 if (option != (const char *) NULL)
3920 flags=ParseGeometry(option,&geometry_info);
3921 image->chromaticity.red_primary.x=geometry_info.rho;
3922 image->chromaticity.red_primary.y=geometry_info.sigma;
3923 if ((flags & SigmaValue) == 0)
3924 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3926 if (image_info->quality != UndefinedCompressionQuality)
3927 image->quality=image_info->quality;
3928 option=GetImageOption(image_info,"scene");
3929 if (option != (const char *) NULL)
3930 image->scene=StringToUnsignedLong(option);
3931 option=GetImageOption(image_info,"taint");
3932 if (option != (const char *) NULL)
3933 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3934 MagickFalse,option);
3935 option=GetImageOption(image_info,"tile-offset");
3936 if (option != (const char *) NULL)
3941 geometry=GetPageGeometry(option);
3942 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3943 geometry=DestroyString(geometry);
3945 option=GetImageOption(image_info,"transparent-color");
3946 if (option != (const char *) NULL)
3947 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
3949 option=GetImageOption(image_info,"type");
3950 if (option != (const char *) NULL)
3951 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3953 option=GetImageOption(image_info,"units");
3954 units=image_info->units;
3955 if (option != (const char *) NULL)
3956 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
3957 MagickFalse,option);
3958 if (units != UndefinedResolution)
3960 if (image->units != units)
3961 switch (image->units)
3963 case PixelsPerInchResolution:
3965 if (units == PixelsPerCentimeterResolution)
3967 image->resolution.x/=2.54;
3968 image->resolution.y/=2.54;
3972 case PixelsPerCentimeterResolution:
3974 if (units == PixelsPerInchResolution)
3976 image->resolution.x=(double) ((size_t) (100.0*2.54*
3977 image->resolution.x+0.5))/100.0;
3978 image->resolution.y=(double) ((size_t) (100.0*2.54*
3979 image->resolution.y+0.5))/100.0;
3988 option=GetImageOption(image_info,"virtual-pixel");
3989 if (option != (const char *) NULL)
3990 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
3991 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
3993 option=GetImageOption(image_info,"white-point");
3994 if (option != (const char *) NULL)
3996 flags=ParseGeometry(option,&geometry_info);
3997 image->chromaticity.white_point.x=geometry_info.rho;
3998 image->chromaticity.white_point.y=geometry_info.sigma;
3999 if ((flags & SigmaValue) == 0)
4000 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4003 Pointer to allow the lookup of pre-image artifact will fallback to a global
4004 option setting/define. This saves a lot of duplication of global options
4005 into per-image artifacts, while ensuring only specifically set per-image
4006 artifacts are preserved when parenthesis ends.
4008 if (image->image_info != (ImageInfo *) NULL)
4009 image->image_info=DestroyImageInfo(image->image_info);
4010 image->image_info=CloneImageInfo(image_info);