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-2016 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/client.h"
53 #include "MagickCore/color.h"
54 #include "MagickCore/color-private.h"
55 #include "MagickCore/colormap.h"
56 #include "MagickCore/colorspace.h"
57 #include "MagickCore/colorspace-private.h"
58 #include "MagickCore/composite.h"
59 #include "MagickCore/composite-private.h"
60 #include "MagickCore/compress.h"
61 #include "MagickCore/constitute.h"
62 #include "MagickCore/delegate.h"
63 #include "MagickCore/display.h"
64 #include "MagickCore/draw.h"
65 #include "MagickCore/enhance.h"
66 #include "MagickCore/exception.h"
67 #include "MagickCore/exception-private.h"
68 #include "MagickCore/gem.h"
69 #include "MagickCore/geometry.h"
70 #include "MagickCore/histogram.h"
71 #include "MagickCore/image-private.h"
72 #include "MagickCore/list.h"
73 #include "MagickCore/magic.h"
74 #include "MagickCore/magick.h"
75 #include "MagickCore/magick-private.h"
76 #include "MagickCore/memory_.h"
77 #include "MagickCore/module.h"
78 #include "MagickCore/monitor.h"
79 #include "MagickCore/monitor-private.h"
80 #include "MagickCore/option.h"
81 #include "MagickCore/paint.h"
82 #include "MagickCore/pixel-accessor.h"
83 #include "MagickCore/profile.h"
84 #include "MagickCore/property.h"
85 #include "MagickCore/quantize.h"
86 #include "MagickCore/random_.h"
87 #include "MagickCore/resource_.h"
88 #include "MagickCore/segment.h"
89 #include "MagickCore/semaphore.h"
90 #include "MagickCore/signature-private.h"
91 #include "MagickCore/statistic.h"
92 #include "MagickCore/string_.h"
93 #include "MagickCore/string-private.h"
94 #include "MagickCore/thread-private.h"
95 #include "MagickCore/threshold.h"
96 #include "MagickCore/timer.h"
97 #include "MagickCore/token.h"
98 #include "MagickCore/utility.h"
99 #include "MagickCore/utility-private.h"
100 #include "MagickCore/version.h"
101 #include "MagickCore/xwindow-private.h"
104 Constant declaration.
107 AlphaColor[] = "#bdbdbd", /* gray */
108 BackgroundColor[] = "#ffffff", /* white */
109 BorderColor[] = "#dfdfdf", /* gray */
110 DefaultTileFrame[] = "15x15+3+3",
111 DefaultTileGeometry[] = "120x120+4+3>",
112 DefaultTileLabel[] = "%f\n%G\n%b",
113 ForegroundColor[] = "#000", /* black */
114 LoadImageTag[] = "Load/Image",
115 LoadImagesTag[] = "Load/Images",
116 PSDensityGeometry[] = "72.0x72.0",
117 PSPageGeometry[] = "612x792",
118 SaveImageTag[] = "Save/Image",
119 SaveImagesTag[] = "Save/Images",
120 TransparentColor[] = "#00000000"; /* transparent black */
123 DefaultResolution = 72.0;
126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 % A c q u i r e I m a g e %
134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 % AcquireImage() returns a pointer to an image structure initialized to
139 % The format of the AcquireImage method is:
141 % Image *AcquireImage(const ImageInfo *image_info,ExceptionInfo *exception)
143 % A description of each parameter follows:
145 % o image_info: Many of the image default values are set from this
146 % structure. For example, filename, compression, depth, background color,
149 % o exception: return any errors or warnings in this structure.
152 MagickExport Image *AcquireImage(const ImageInfo *image_info,
153 ExceptionInfo *exception)
165 Allocate image structure.
167 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
168 image=(Image *) AcquireMagickMemory(sizeof(*image));
169 if (image == (Image *) NULL)
170 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
171 (void) ResetMagickMemory(image,0,sizeof(*image));
173 Initialize Image structure.
175 (void) CopyMagickString(image->magick,"MIFF",MagickPathExtent);
176 image->storage_class=DirectClass;
177 image->depth=MAGICKCORE_QUANTUM_DEPTH;
178 image->colorspace=sRGBColorspace;
179 image->rendering_intent=PerceptualIntent;
180 image->gamma=1.000f/2.200f;
181 image->chromaticity.red_primary.x=0.6400f;
182 image->chromaticity.red_primary.y=0.3300f;
183 image->chromaticity.red_primary.z=0.0300f;
184 image->chromaticity.green_primary.x=0.3000f;
185 image->chromaticity.green_primary.y=0.6000f;
186 image->chromaticity.green_primary.z=0.1000f;
187 image->chromaticity.blue_primary.x=0.1500f;
188 image->chromaticity.blue_primary.y=0.0600f;
189 image->chromaticity.blue_primary.z=0.7900f;
190 image->chromaticity.white_point.x=0.3127f;
191 image->chromaticity.white_point.y=0.3290f;
192 image->chromaticity.white_point.z=0.3583f;
193 image->interlace=NoInterlace;
194 image->ticks_per_second=UndefinedTicksPerSecond;
195 image->compose=OverCompositeOp;
196 (void) QueryColorCompliance(AlphaColor,AllCompliance,&image->alpha_color,
198 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
199 &image->background_color,exception);
200 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
202 (void) QueryColorCompliance(TransparentColor,AllCompliance,
203 &image->transparent_color,exception);
204 GetTimerInfo(&image->timer);
205 image->cache=AcquirePixelCache(0);
206 image->channel_mask=DefaultChannels;
207 image->channel_map=AcquirePixelChannelMap();
208 image->blob=CloneBlobInfo((BlobInfo *) NULL);
209 image->timestamp=time((time_t *) NULL);
210 image->debug=IsEventLogging();
211 image->reference_count=1;
212 image->semaphore=AcquireSemaphoreInfo();
213 image->signature=MagickCoreSignature;
214 if (image_info == (ImageInfo *) NULL)
219 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
221 (void) CopyMagickString(image->filename,image_info->filename,
223 (void) CopyMagickString(image->magick_filename,image_info->filename,
225 (void) CopyMagickString(image->magick,image_info->magick,MagickPathExtent);
226 if (image_info->size != (char *) NULL)
228 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
229 image->columns=image->extract_info.width;
230 image->rows=image->extract_info.height;
231 image->offset=image->extract_info.x;
232 image->extract_info.x=0;
233 image->extract_info.y=0;
235 if (image_info->extract != (char *) NULL)
240 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
241 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
243 image->extract_info=geometry;
244 Swap(image->columns,image->extract_info.width);
245 Swap(image->rows,image->extract_info.height);
248 image->compression=image_info->compression;
249 image->quality=image_info->quality;
250 image->endian=image_info->endian;
251 image->interlace=image_info->interlace;
252 image->units=image_info->units;
253 if (image_info->density != (char *) NULL)
258 flags=ParseGeometry(image_info->density,&geometry_info);
259 image->resolution.x=geometry_info.rho;
260 image->resolution.y=geometry_info.sigma;
261 if ((flags & SigmaValue) == 0)
262 image->resolution.y=image->resolution.x;
264 if (image_info->page != (char *) NULL)
269 image->page=image->extract_info;
270 geometry=GetPageGeometry(image_info->page);
271 (void) ParseAbsoluteGeometry(geometry,&image->page);
272 geometry=DestroyString(geometry);
274 if (image_info->depth != 0)
275 image->depth=image_info->depth;
276 image->dither=image_info->dither;
277 image->alpha_color=image_info->alpha_color;
278 image->background_color=image_info->background_color;
279 image->border_color=image_info->border_color;
280 image->transparent_color=image_info->transparent_color;
281 image->ping=image_info->ping;
282 image->progress_monitor=image_info->progress_monitor;
283 image->client_data=image_info->client_data;
284 if (image_info->cache != (void *) NULL)
285 ClonePixelCacheMethods(image->cache,image_info->cache);
287 Set all global options that map to per-image settings.
289 (void) SyncImageSettings(image_info,image,exception);
291 Global options that are only set for new images.
293 option=GetImageOption(image_info,"delay");
294 if (option != (const char *) NULL)
299 flags=ParseGeometry(option,&geometry_info);
300 if ((flags & GreaterValue) != 0)
302 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
303 image->delay=(size_t) floor(geometry_info.rho+0.5);
306 if ((flags & LessValue) != 0)
308 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
309 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
312 image->delay=(size_t) floor(geometry_info.rho+0.5);
313 if ((flags & SigmaValue) != 0)
314 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
316 option=GetImageOption(image_info,"dispose");
317 if (option != (const char *) NULL)
318 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
324 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328 % A c q u i r e I m a g e I n f o %
332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334 % AcquireImageInfo() allocates the ImageInfo structure.
336 % The format of the AcquireImageInfo method is:
338 % ImageInfo *AcquireImageInfo(void)
341 MagickExport ImageInfo *AcquireImageInfo(void)
346 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
347 if (image_info == (ImageInfo *) NULL)
348 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
349 GetImageInfo(image_info);
354 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
358 % A c q u i r e N e x t I m a g e %
362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
364 % AcquireNextImage() initializes the next image in a sequence to
365 % default values. The next member of image points to the newly allocated
366 % image. If there is a memory shortage, next is assigned NULL.
368 % The format of the AcquireNextImage method is:
370 % void AcquireNextImage(const ImageInfo *image_info,Image *image,
371 % ExceptionInfo *exception)
373 % A description of each parameter follows:
375 % o image_info: Many of the image default values are set from this
376 % structure. For example, filename, compression, depth, background color,
379 % o image: the image.
381 % o exception: return any errors or warnings in this structure.
384 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image,
385 ExceptionInfo *exception)
388 Allocate image structure.
390 assert(image != (Image *) NULL);
391 assert(image->signature == MagickCoreSignature);
392 if (image->debug != MagickFalse)
393 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
394 image->next=AcquireImage(image_info,exception);
395 if (GetNextImageInList(image) == (Image *) NULL)
397 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
399 if (image_info != (ImageInfo *) NULL)
400 (void) CopyMagickString(GetNextImageInList(image)->filename,
401 image_info->filename,MagickPathExtent);
402 DestroyBlob(GetNextImageInList(image));
403 image->next->blob=ReferenceBlob(image->blob);
404 image->next->endian=image->endian;
405 image->next->scene=image->scene+1;
406 image->next->previous=image;
410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
414 % A p p e n d I m a g e s %
418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
420 % AppendImages() takes all images from the current image pointer to the end
421 % of the image list and appends them to each other top-to-bottom if the
422 % stack parameter is true, otherwise left-to-right.
424 % The current gravity setting effects how the image is justified in the
427 % The format of the AppendImages method is:
429 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
430 % ExceptionInfo *exception)
432 % A description of each parameter follows:
434 % o images: the image sequence.
436 % o stack: A value other than 0 stacks the images top-to-bottom.
438 % o exception: return any errors or warnings in this structure.
441 MagickExport Image *AppendImages(const Image *images,
442 const MagickBooleanType stack,ExceptionInfo *exception)
444 #define AppendImageTag "Append/Image"
479 Compute maximum area of appended area.
481 assert(images != (Image *) NULL);
482 assert(images->signature == MagickCoreSignature);
483 if (images->debug != MagickFalse)
484 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
485 assert(exception != (ExceptionInfo *) NULL);
486 assert(exception->signature == MagickCoreSignature);
487 alpha_trait=images->alpha_trait;
489 width=images->columns;
492 next=GetNextImageInList(images);
493 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
495 if (next->depth > depth)
497 if (next->alpha_trait != UndefinedPixelTrait)
498 alpha_trait=BlendPixelTrait;
500 if (stack != MagickFalse)
502 if (next->columns > width)
507 width+=next->columns;
508 if (next->rows > height)
514 append_image=CloneImage(images,width,height,MagickTrue,exception);
515 if (append_image == (Image *) NULL)
516 return((Image *) NULL);
517 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
519 append_image=DestroyImage(append_image);
520 return((Image *) NULL);
522 append_image->depth=depth;
523 append_image->alpha_trait=alpha_trait;
524 (void) SetImageBackgroundColor(append_image,exception);
529 append_view=AcquireAuthenticCacheView(append_image,exception);
530 for (n=0; n < (MagickOffsetType) number_images; n++)
538 SetGeometry(append_image,&geometry);
539 GravityAdjustGeometry(next->columns,next->rows,next->gravity,&geometry);
540 if (stack != MagickFalse)
541 x_offset-=geometry.x;
543 y_offset-=geometry.y;
544 image_view=AcquireVirtualCacheView(next,exception);
545 #if defined(MAGICKCORE_OPENMP_SUPPORT)
546 #pragma omp parallel for schedule(static,4) shared(status) \
547 magick_threads(next,next,next->rows,1)
549 for (y=0; y < (ssize_t) next->rows; y++)
557 register const Quantum
566 if (status == MagickFalse)
568 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
569 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
570 next->columns,1,exception);
571 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
576 GetPixelInfo(next,&pixel);
577 for (x=0; x < (ssize_t) next->columns; x++)
579 if (GetPixelReadMask(next,p) == 0)
581 SetPixelBackgoundColor(append_image,q);
582 p+=GetPixelChannels(next);
583 q+=GetPixelChannels(append_image);
586 GetPixelInfoPixel(next,p,&pixel);
587 SetPixelViaPixelInfo(append_image,&pixel,q);
588 p+=GetPixelChannels(next);
589 q+=GetPixelChannels(append_image);
591 sync=SyncCacheViewAuthenticPixels(append_view,exception);
592 if (sync == MagickFalse)
595 image_view=DestroyCacheView(image_view);
596 if (stack == MagickFalse)
598 x_offset+=(ssize_t) next->columns;
604 y_offset+=(ssize_t) next->rows;
606 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
607 if (proceed == MagickFalse)
609 next=GetNextImageInList(next);
611 append_view=DestroyCacheView(append_view);
612 if (status == MagickFalse)
613 append_image=DestroyImage(append_image);
614 return(append_image);
618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
622 % C a t c h I m a g e E x c e p t i o n %
626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
628 % CatchImageException() returns if no exceptions are found in the image
629 % sequence, otherwise it determines the most severe exception and reports
630 % it as a warning or error depending on the severity.
632 % The format of the CatchImageException method is:
634 % ExceptionType CatchImageException(Image *image)
636 % A description of each parameter follows:
638 % o image: An image sequence.
641 MagickExport ExceptionType CatchImageException(Image *image)
649 assert(image != (const Image *) NULL);
650 assert(image->signature == MagickCoreSignature);
651 if (image->debug != MagickFalse)
652 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
653 exception=AcquireExceptionInfo();
654 CatchException(exception);
655 severity=exception->severity;
656 exception=DestroyExceptionInfo(exception);
661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
665 % C l i p I m a g e P a t h %
669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
671 % ClipImagePath() sets the image clip mask based any clipping path information
674 % The format of the ClipImagePath method is:
676 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
677 % const MagickBooleanType inside,ExceptionInfo *exception)
679 % A description of each parameter follows:
681 % o image: the image.
683 % o pathname: name of clipping path resource. If name is preceded by #, use
684 % clipping path numbered by name.
686 % o inside: if non-zero, later operations take effect inside clipping path.
687 % Otherwise later operations take effect outside clipping path.
689 % o exception: return any errors or warnings in this structure.
693 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
695 return(ClipImagePath(image,"#1",MagickTrue,exception));
698 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
699 const MagickBooleanType inside,ExceptionInfo *exception)
701 #define ClipImagePathTag "ClipPath/Image"
715 assert(image != (const Image *) NULL);
716 assert(image->signature == MagickCoreSignature);
717 if (image->debug != MagickFalse)
718 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
719 assert(pathname != NULL);
720 property=AcquireString(pathname);
721 (void) FormatLocaleString(property,MagickPathExtent,"8BIM:1999,2998:%s",
723 value=GetImageProperty(image,property,exception);
724 property=DestroyString(property);
725 if (value == (const char *) NULL)
727 ThrowFileException(exception,OptionError,"NoClipPathDefined",
731 image_info=AcquireImageInfo();
732 (void) CopyMagickString(image_info->filename,image->filename,
734 (void) ConcatenateMagickString(image_info->filename,pathname,
736 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
737 image_info=DestroyImageInfo(image_info);
738 if (clip_mask == (Image *) NULL)
740 if (clip_mask->storage_class == PseudoClass)
742 (void) SyncImage(clip_mask,exception);
743 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
746 if (inside == MagickFalse)
747 (void) NegateImage(clip_mask,MagickFalse,exception);
748 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
749 "8BIM:1999,2998:%s\nPS",pathname);
750 (void) SetImageMask(image,ReadPixelMask,clip_mask,exception);
751 clip_mask=DestroyImage(clip_mask);
756 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
760 % C l o n e I m a g e %
764 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
766 % CloneImage() copies an image and returns the copy as a new image object.
768 % If the specified columns and rows is 0, an exact copy of the image is
769 % returned, otherwise the pixel data is undefined and must be initialized
770 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
771 % failure, a NULL image is returned and exception describes the reason for the
774 % The format of the CloneImage method is:
776 % Image *CloneImage(const Image *image,const size_t columns,
777 % const size_t rows,const MagickBooleanType orphan,
778 % ExceptionInfo *exception)
780 % A description of each parameter follows:
782 % o image: the image.
784 % o columns: the number of columns in the cloned image.
786 % o rows: the number of rows in the cloned image.
788 % o detach: With a value other than 0, the cloned image is detached from
789 % its parent I/O stream.
791 % o exception: return any errors or warnings in this structure.
794 MagickExport Image *CloneImage(const Image *image,const size_t columns,
795 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
809 assert(image != (const Image *) NULL);
810 assert(image->signature == MagickCoreSignature);
811 if (image->debug != MagickFalse)
812 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
813 assert(exception != (ExceptionInfo *) NULL);
814 assert(exception->signature == MagickCoreSignature);
815 if ((image->columns == 0) || (image->rows == 0))
817 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
818 "NegativeOrZeroImageSize","`%s'",image->filename);
819 return((Image *) NULL);
821 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
822 if (clone_image == (Image *) NULL)
823 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
824 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
825 clone_image->signature=MagickCoreSignature;
826 clone_image->storage_class=image->storage_class;
827 clone_image->number_channels=image->number_channels;
828 clone_image->number_meta_channels=image->number_meta_channels;
829 clone_image->metacontent_extent=image->metacontent_extent;
830 clone_image->colorspace=image->colorspace;
831 clone_image->read_mask=image->read_mask;
832 clone_image->write_mask=image->write_mask;
833 clone_image->alpha_trait=image->alpha_trait;
834 clone_image->columns=image->columns;
835 clone_image->rows=image->rows;
836 clone_image->dither=image->dither;
837 if (image->colormap != (PixelInfo *) NULL)
840 Allocate and copy the image colormap.
842 clone_image->colors=image->colors;
843 length=(size_t) image->colors;
844 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
845 sizeof(*clone_image->colormap));
846 if (clone_image->colormap == (PixelInfo *) NULL)
848 clone_image=DestroyImage(clone_image);
849 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
851 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
852 sizeof(*clone_image->colormap));
854 clone_image->image_info=CloneImageInfo(image->image_info);
855 (void) CloneImageProfiles(clone_image,image);
856 (void) CloneImageProperties(clone_image,image);
857 (void) CloneImageArtifacts(clone_image,image);
858 GetTimerInfo(&clone_image->timer);
859 if (image->ascii85 != (void *) NULL)
860 Ascii85Initialize(clone_image);
861 clone_image->magick_columns=image->magick_columns;
862 clone_image->magick_rows=image->magick_rows;
863 clone_image->type=image->type;
864 clone_image->channel_mask=image->channel_mask;
865 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
866 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
868 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
869 (void) CopyMagickString(clone_image->filename,image->filename,
871 clone_image->progress_monitor=image->progress_monitor;
872 clone_image->client_data=image->client_data;
873 clone_image->reference_count=1;
874 clone_image->next=image->next;
875 clone_image->previous=image->previous;
876 clone_image->list=NewImageList();
877 if (detach == MagickFalse)
878 clone_image->blob=ReferenceBlob(image->blob);
881 clone_image->next=NewImageList();
882 clone_image->previous=NewImageList();
883 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
885 clone_image->ping=image->ping;
886 clone_image->debug=IsEventLogging();
887 clone_image->semaphore=AcquireSemaphoreInfo();
888 if ((columns == 0) || (rows == 0))
890 if (image->montage != (char *) NULL)
891 (void) CloneString(&clone_image->montage,image->montage);
892 if (image->directory != (char *) NULL)
893 (void) CloneString(&clone_image->directory,image->directory);
894 clone_image->cache=ReferencePixelCache(image->cache);
898 if (image->columns != 0)
899 scale=(double) columns/(double) image->columns;
900 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
901 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
902 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
904 if (image->rows != 0)
905 scale=(double) rows/(double) image->rows;
906 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
907 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
908 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
909 clone_image->cache=ClonePixelCache(image->cache);
910 if (SetImageExtent(clone_image,columns,rows,exception) == MagickFalse)
911 clone_image=DestroyImage(clone_image);
916 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
920 % C l o n e I m a g e I n f o %
924 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
926 % CloneImageInfo() makes a copy of the given image info structure. If
927 % NULL is specified, a new image info structure is created initialized to
930 % The format of the CloneImageInfo method is:
932 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
934 % A description of each parameter follows:
936 % o image_info: the image info.
939 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
944 clone_info=AcquireImageInfo();
945 if (image_info == (ImageInfo *) NULL)
947 clone_info->compression=image_info->compression;
948 clone_info->temporary=image_info->temporary;
949 clone_info->adjoin=image_info->adjoin;
950 clone_info->antialias=image_info->antialias;
951 clone_info->scene=image_info->scene;
952 clone_info->number_scenes=image_info->number_scenes;
953 clone_info->depth=image_info->depth;
954 (void) CloneString(&clone_info->size,image_info->size);
955 (void) CloneString(&clone_info->extract,image_info->extract);
956 (void) CloneString(&clone_info->scenes,image_info->scenes);
957 (void) CloneString(&clone_info->page,image_info->page);
958 clone_info->interlace=image_info->interlace;
959 clone_info->endian=image_info->endian;
960 clone_info->units=image_info->units;
961 clone_info->quality=image_info->quality;
962 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
963 (void) CloneString(&clone_info->server_name,image_info->server_name);
964 (void) CloneString(&clone_info->font,image_info->font);
965 (void) CloneString(&clone_info->texture,image_info->texture);
966 (void) CloneString(&clone_info->density,image_info->density);
967 clone_info->pointsize=image_info->pointsize;
968 clone_info->fuzz=image_info->fuzz;
969 clone_info->alpha_color=image_info->alpha_color;
970 clone_info->background_color=image_info->background_color;
971 clone_info->border_color=image_info->border_color;
972 clone_info->transparent_color=image_info->transparent_color;
973 clone_info->dither=image_info->dither;
974 clone_info->monochrome=image_info->monochrome;
975 clone_info->colorspace=image_info->colorspace;
976 clone_info->type=image_info->type;
977 clone_info->orientation=image_info->orientation;
978 clone_info->ping=image_info->ping;
979 clone_info->verbose=image_info->verbose;
980 clone_info->progress_monitor=image_info->progress_monitor;
981 clone_info->client_data=image_info->client_data;
982 clone_info->cache=image_info->cache;
983 if (image_info->cache != (void *) NULL)
984 clone_info->cache=ReferencePixelCache(image_info->cache);
985 if (image_info->profile != (void *) NULL)
986 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
987 image_info->profile);
988 SetImageInfoFile(clone_info,image_info->file);
989 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
990 clone_info->stream=image_info->stream;
991 (void) CopyMagickString(clone_info->magick,image_info->magick,
993 (void) CopyMagickString(clone_info->unique,image_info->unique,
995 (void) CopyMagickString(clone_info->filename,image_info->filename,
997 clone_info->channel=image_info->channel;
998 (void) CloneImageOptions(clone_info,image_info);
999 clone_info->debug=IsEventLogging();
1000 clone_info->signature=image_info->signature;
1005 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1009 % C o p y I m a g e P i x e l s %
1013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1015 % CopyImagePixels() copies pixels from the source image as defined by the
1016 % geometry the destination image at the specified offset.
1018 % The format of the CopyImagePixels method is:
1020 % MagickBooleanType CopyImagePixels(Image *image,const Image *source_image,
1021 % const RectangleInfo *geometry,const OffsetInfo *offset,
1022 % ExceptionInfo *exception);
1024 % A description of each parameter follows:
1026 % o image: the destination image.
1028 % o source_image: the source image.
1030 % o geometry: define the dimensions of the source pixel rectangle.
1032 % o offset: define the offset in the destination image.
1034 % o exception: return any errors or warnings in this structure.
1037 MagickExport MagickBooleanType CopyImagePixels(Image *image,
1038 const Image *source_image,const RectangleInfo *geometry,
1039 const OffsetInfo *offset,ExceptionInfo *exception)
1041 #define CopyImageTag "Copy/Image"
1056 assert(image != (Image *) NULL);
1057 if (image->debug != MagickFalse)
1058 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1059 assert(source_image != (Image *) NULL);
1060 assert(geometry != (RectangleInfo *) NULL);
1061 assert(offset != (OffsetInfo *) NULL);
1062 if ((offset->x < 0) || (offset->y < 0) ||
1063 ((ssize_t) (offset->x+geometry->width) > (ssize_t) image->columns) ||
1064 ((ssize_t) (offset->y+geometry->height) > (ssize_t) image->rows))
1065 ThrowBinaryException(OptionError,"GeometryDoesNotContainImage",
1067 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1068 return(MagickFalse);
1074 source_view=AcquireVirtualCacheView(source_image,exception);
1075 image_view=AcquireAuthenticCacheView(image,exception);
1076 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1077 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1078 magick_threads(image,source_image,geometry->height,1)
1080 for (y=0; y < (ssize_t) geometry->height; y++)
1085 register const Quantum
1094 if (status == MagickFalse)
1096 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1097 geometry->width,1,exception);
1098 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1099 geometry->width,1,exception);
1100 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1105 for (x=0; x < (ssize_t) geometry->width; x++)
1110 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1112 PixelChannel channel=GetPixelChannelChannel(image,i);
1113 PixelTrait traits=GetPixelChannelTraits(image,channel);
1114 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1115 if ((traits == UndefinedPixelTrait) ||
1116 ((traits & UpdatePixelTrait) == 0) ||
1117 (source_traits == UndefinedPixelTrait))
1119 SetPixelChannel(image,channel,p[i],q);
1121 p+=GetPixelChannels(source_image);
1122 q+=GetPixelChannels(image);
1124 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1125 if (sync == MagickFalse)
1127 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1132 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1133 #pragma omp critical (MagickCore_CopyImage)
1135 proceed=SetImageProgress(image,CopyImageTag,progress++,image->rows);
1136 if (proceed == MagickFalse)
1140 source_view=DestroyCacheView(source_view);
1141 image_view=DestroyCacheView(image_view);
1146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1150 % D e s t r o y I m a g e %
1154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1156 % DestroyImage() dereferences an image, deallocating memory associated with
1157 % the image if the reference count becomes zero.
1159 % The format of the DestroyImage method is:
1161 % Image *DestroyImage(Image *image)
1163 % A description of each parameter follows:
1165 % o image: the image.
1168 MagickExport Image *DestroyImage(Image *image)
1176 assert(image != (Image *) NULL);
1177 assert(image->signature == MagickCoreSignature);
1178 if (image->debug != MagickFalse)
1179 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1180 destroy=MagickFalse;
1181 LockSemaphoreInfo(image->semaphore);
1182 image->reference_count--;
1183 if (image->reference_count == 0)
1185 UnlockSemaphoreInfo(image->semaphore);
1186 if (destroy == MagickFalse)
1187 return((Image *) NULL);
1191 DestroyImagePixels(image);
1192 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1193 if (image->montage != (char *) NULL)
1194 image->montage=DestroyString(image->montage);
1195 if (image->directory != (char *) NULL)
1196 image->directory=DestroyString(image->directory);
1197 if (image->colormap != (PixelInfo *) NULL)
1198 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1199 if (image->geometry != (char *) NULL)
1200 image->geometry=DestroyString(image->geometry);
1201 DestroyImageProfiles(image);
1202 DestroyImageProperties(image);
1203 DestroyImageArtifacts(image);
1204 if (image->ascii85 != (Ascii85Info *) NULL)
1205 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1206 if (image->image_info != (ImageInfo *) NULL)
1207 image->image_info=DestroyImageInfo(image->image_info);
1209 if (image->semaphore != (SemaphoreInfo *) NULL)
1210 RelinquishSemaphoreInfo(&image->semaphore);
1211 image->signature=(~MagickCoreSignature);
1212 image=(Image *) RelinquishMagickMemory(image);
1217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1221 % D e s t r o y I m a g e I n f o %
1225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1227 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1230 % The format of the DestroyImageInfo method is:
1232 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1234 % A description of each parameter follows:
1236 % o image_info: the image info.
1239 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1241 assert(image_info != (ImageInfo *) NULL);
1242 assert(image_info->signature == MagickCoreSignature);
1243 if (image_info->debug != MagickFalse)
1244 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1245 image_info->filename);
1246 if (image_info->size != (char *) NULL)
1247 image_info->size=DestroyString(image_info->size);
1248 if (image_info->extract != (char *) NULL)
1249 image_info->extract=DestroyString(image_info->extract);
1250 if (image_info->scenes != (char *) NULL)
1251 image_info->scenes=DestroyString(image_info->scenes);
1252 if (image_info->page != (char *) NULL)
1253 image_info->page=DestroyString(image_info->page);
1254 if (image_info->sampling_factor != (char *) NULL)
1255 image_info->sampling_factor=DestroyString(
1256 image_info->sampling_factor);
1257 if (image_info->server_name != (char *) NULL)
1258 image_info->server_name=DestroyString(
1259 image_info->server_name);
1260 if (image_info->font != (char *) NULL)
1261 image_info->font=DestroyString(image_info->font);
1262 if (image_info->texture != (char *) NULL)
1263 image_info->texture=DestroyString(image_info->texture);
1264 if (image_info->density != (char *) NULL)
1265 image_info->density=DestroyString(image_info->density);
1266 if (image_info->cache != (void *) NULL)
1267 image_info->cache=DestroyPixelCache(image_info->cache);
1268 if (image_info->profile != (StringInfo *) NULL)
1269 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1270 image_info->profile);
1271 DestroyImageOptions(image_info);
1272 image_info->signature=(~MagickCoreSignature);
1273 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1282 + D i s a s s o c i a t e I m a g e S t r e a m %
1286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1288 % DisassociateImageStream() disassociates the image stream. It checks if the
1289 % blob of the specified image is referenced by other images. If the reference
1290 % count is higher then 1 a new blob is assigned to the specified image.
1292 % The format of the DisassociateImageStream method is:
1294 % void DisassociateImageStream(const Image *image)
1296 % A description of each parameter follows:
1298 % o image: the image.
1301 MagickExport void DisassociateImageStream(Image *image)
1303 assert(image != (Image *) NULL);
1304 assert(image->signature == MagickCoreSignature);
1305 if (image->debug != MagickFalse)
1306 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1307 DisassociateBlob(image);
1311 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1315 % G e t I m a g e I n f o %
1319 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1321 % GetImageInfo() initializes image_info to default values.
1323 % The format of the GetImageInfo method is:
1325 % void GetImageInfo(ImageInfo *image_info)
1327 % A description of each parameter follows:
1329 % o image_info: the image info.
1332 MagickExport void GetImageInfo(ImageInfo *image_info)
1341 File and image dimension members.
1343 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1344 assert(image_info != (ImageInfo *) NULL);
1345 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1346 image_info->adjoin=MagickTrue;
1347 image_info->interlace=NoInterlace;
1348 image_info->channel=DefaultChannels;
1349 image_info->quality=UndefinedCompressionQuality;
1350 image_info->antialias=MagickTrue;
1351 image_info->dither=MagickTrue;
1352 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1353 if (synchronize != (const char *) NULL)
1355 image_info->synchronize=IsStringTrue(synchronize);
1356 synchronize=DestroyString(synchronize);
1358 exception=AcquireExceptionInfo();
1359 (void) QueryColorCompliance(AlphaColor,AllCompliance,&image_info->alpha_color,
1361 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1362 &image_info->background_color,exception);
1363 (void) QueryColorCompliance(BorderColor,AllCompliance,
1364 &image_info->border_color,exception);
1365 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1366 &image_info->transparent_color,exception);
1367 exception=DestroyExceptionInfo(exception);
1368 image_info->debug=IsEventLogging();
1369 image_info->signature=MagickCoreSignature;
1373 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1377 % G e t I m a g e I n f o F i l e %
1381 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1383 % GetImageInfoFile() returns the image info file member.
1385 % The format of the GetImageInfoFile method is:
1387 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1389 % A description of each parameter follows:
1391 % o image_info: the image info.
1394 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1396 return(image_info->file);
1400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1404 % G e t I m a g e M a s k %
1408 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1410 % GetImageMask() returns the mask associated with the image.
1412 % The format of the GetImageMask method is:
1414 % Image *GetImageMask(const Image *image,const PixelMask type,
1415 % ExceptionInfo *exception)
1417 % A description of each parameter follows:
1419 % o image: the image.
1421 % o type: the mask type, ReadPixelMask or WritePixelMask.
1424 MagickExport Image *GetImageMask(const Image *image,const PixelMask type,
1425 ExceptionInfo *exception)
1443 assert(image != (Image *) NULL);
1444 if (image->debug != MagickFalse)
1445 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1446 assert(image->signature == MagickCoreSignature);
1447 mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1448 if (mask_image == (Image *) NULL)
1449 return((Image *) NULL);
1451 mask_image->alpha_trait=UndefinedPixelTrait;
1452 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1453 mask_image->read_mask=MagickFalse;
1454 image_view=AcquireVirtualCacheView(image,exception);
1455 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1456 for (y=0; y < (ssize_t) image->rows; y++)
1458 register const Quantum
1467 if (status == MagickFalse)
1469 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1470 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1472 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1477 for (x=0; x < (ssize_t) image->columns; x++)
1481 case WritePixelMask:
1483 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1488 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1492 p+=GetPixelChannels(image);
1493 q+=GetPixelChannels(mask_image);
1495 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1498 mask_view=DestroyCacheView(mask_view);
1499 image_view=DestroyCacheView(image_view);
1500 if (status == MagickFalse)
1501 mask_image=DestroyImage(mask_image);
1506 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1510 + G e t I m a g e R e f e r e n c e C o u n t %
1514 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1516 % GetImageReferenceCount() returns the image reference count.
1518 % The format of the GetReferenceCount method is:
1520 % ssize_t GetImageReferenceCount(Image *image)
1522 % A description of each parameter follows:
1524 % o image: the image.
1527 MagickExport ssize_t GetImageReferenceCount(Image *image)
1532 assert(image != (Image *) NULL);
1533 assert(image->signature == MagickCoreSignature);
1534 if (image->debug != MagickFalse)
1535 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1536 LockSemaphoreInfo(image->semaphore);
1537 reference_count=image->reference_count;
1538 UnlockSemaphoreInfo(image->semaphore);
1539 return(reference_count);
1543 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1547 % 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 %
1551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1553 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1554 % image. A virtual pixel is any pixel access that is outside the boundaries
1555 % of the image cache.
1557 % The format of the GetImageVirtualPixelMethod() method is:
1559 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1561 % A description of each parameter follows:
1563 % o image: the image.
1566 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1568 assert(image != (Image *) NULL);
1569 assert(image->signature == MagickCoreSignature);
1570 if (image->debug != MagickFalse)
1571 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1572 return(GetPixelCacheVirtualMethod(image));
1576 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1580 % I n t e r p r e t I m a g e F i l e n a m e %
1584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1586 % InterpretImageFilename() interprets embedded characters in an image filename.
1587 % The filename length is returned.
1589 % The format of the InterpretImageFilename method is:
1591 % size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1592 % const char *format,int value,char *filename,ExceptionInfo *exception)
1594 % A description of each parameter follows.
1596 % o image_info: the image info..
1598 % o image: the image.
1600 % o format: A filename describing the format to use to write the numeric
1601 % argument. Only the first numeric format identifier is replaced.
1603 % o value: Numeric value to substitute into format filename.
1605 % o filename: return the formatted filename in this character buffer.
1607 % o exception: return any errors or warnings in this structure.
1610 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1611 Image *image,const char *format,int value,char *filename,
1612 ExceptionInfo *exception)
1629 canonical=MagickFalse;
1631 (void) CopyMagickString(filename,format,MagickPathExtent);
1632 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1645 foo=(ssize_t) strtol(q,&q,10);
1657 (void) FormatLocaleString(filename+(p-format),(size_t)
1658 (MagickPathExtent-(p-format)),p,value);
1660 (void) ConcatenateMagickString(filename,q,MagickPathExtent);
1661 canonical=MagickTrue;
1670 pattern[MagickPathExtent];
1687 /* FUTURE: Compare update with code from InterpretImageProperties()
1688 Note that a 'filename:' property should not need depth recursion.
1690 if (strchr(p,']') == (char *) NULL)
1694 for (i=0; (i < (MagickPathExtent-1L)) && (*r != '\0'); i++)
1705 if (LocaleNCompare(pattern,"filename:",9) != 0)
1707 option=(const char *) NULL;
1708 if (image != (Image *) NULL)
1709 option=GetImageProperty(image,pattern,exception);
1710 if ((option == (const char *) NULL) && (image != (Image *) NULL))
1711 option=GetImageArtifact(image,pattern);
1712 if ((option == (const char *) NULL) &&
1713 (image_info != (ImageInfo *) NULL))
1714 option=GetImageOption(image_info,pattern);
1715 if (option == (const char *) NULL)
1720 (void) CopyMagickString(filename+(p-format-length),option,(size_t)
1721 (MagickPathExtent-(p-format-length)));
1722 length+=strlen(pattern)-1;
1724 (void) ConcatenateMagickString(filename,r+1,MagickPathExtent);
1725 canonical=MagickTrue;
1735 for (q=filename; *q != '\0'; q++)
1736 if ((*q == '%') && (*(q+1) == '%'))
1738 (void) CopyMagickString(q,q+1,(size_t) (MagickPathExtent-(q-filename)));
1739 canonical=MagickTrue;
1741 if (canonical == MagickFalse)
1742 (void) CopyMagickString(filename,format,MagickPathExtent);
1743 return(strlen(filename));
1747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1751 % I s H i g h D y n a m i c R a n g e I m a g e %
1755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1757 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1758 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1761 % The format of the IsHighDynamicRangeImage method is:
1763 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1764 % ExceptionInfo *exception)
1766 % A description of each parameter follows:
1768 % o image: the image.
1770 % o exception: return any errors or warnings in this structure.
1773 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1774 ExceptionInfo *exception)
1776 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1779 return(MagickFalse);
1790 assert(image != (Image *) NULL);
1791 assert(image->signature == MagickCoreSignature);
1792 if (image->debug != MagickFalse)
1793 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1795 image_view=AcquireVirtualCacheView(image,exception);
1796 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1797 #pragma omp parallel for schedule(static,4) shared(status) \
1798 magick_threads(image,image,image->rows,1)
1800 for (y=0; y < (ssize_t) image->rows; y++)
1802 register const Quantum
1808 if (status == MagickFalse)
1810 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1811 if (p == (const Quantum *) NULL)
1816 for (x=0; x < (ssize_t) image->columns; x++)
1821 if (GetPixelReadMask(image,p) == 0)
1823 p+=GetPixelChannels(image);
1826 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1834 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1835 if (traits == UndefinedPixelTrait)
1837 pixel=(double) p[i];
1838 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1839 (pixel != (double) ((QuantumAny) pixel)))
1842 p+=GetPixelChannels(image);
1843 if (i < (ssize_t) GetPixelChannels(image))
1846 if (x < (ssize_t) image->columns)
1849 image_view=DestroyCacheView(image_view);
1850 return(status != MagickFalse ? MagickFalse : MagickTrue);
1855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1859 % I s I m a g e O b j e c t %
1863 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1865 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1866 % set of image objects.
1868 % The format of the IsImageObject method is:
1870 % MagickBooleanType IsImageObject(const Image *image)
1872 % A description of each parameter follows:
1874 % o image: the image.
1877 MagickExport MagickBooleanType IsImageObject(const Image *image)
1879 register const Image
1882 assert(image != (Image *) NULL);
1883 if (image->debug != MagickFalse)
1884 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1885 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1886 if (p->signature != MagickCoreSignature)
1887 return(MagickFalse);
1892 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1896 % I s T a i n t I m a g e %
1900 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1902 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1903 % since it was first constituted.
1905 % The format of the IsTaintImage method is:
1907 % MagickBooleanType IsTaintImage(const Image *image)
1909 % A description of each parameter follows:
1911 % o image: the image.
1914 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1917 magick[MagickPathExtent],
1918 filename[MagickPathExtent];
1920 register const Image
1923 assert(image != (Image *) NULL);
1924 if (image->debug != MagickFalse)
1925 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1926 assert(image->signature == MagickCoreSignature);
1927 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1928 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1929 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1931 if (p->taint != MagickFalse)
1933 if (LocaleCompare(p->magick,magick) != 0)
1935 if (LocaleCompare(p->filename,filename) != 0)
1938 return(MagickFalse);
1942 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1946 % M o d i f y I m a g e %
1950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1952 % ModifyImage() ensures that there is only a single reference to the image
1953 % to be modified, updating the provided image pointer to point to a clone of
1954 % the original image if necessary.
1956 % The format of the ModifyImage method is:
1958 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1960 % A description of each parameter follows:
1962 % o image: the image.
1964 % o exception: return any errors or warnings in this structure.
1967 MagickExport MagickBooleanType ModifyImage(Image **image,
1968 ExceptionInfo *exception)
1973 assert(image != (Image **) NULL);
1974 assert(*image != (Image *) NULL);
1975 assert((*image)->signature == MagickCoreSignature);
1976 if ((*image)->debug != MagickFalse)
1977 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1978 if (GetImageReferenceCount(*image) <= 1)
1980 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1981 LockSemaphoreInfo((*image)->semaphore);
1982 (*image)->reference_count--;
1983 UnlockSemaphoreInfo((*image)->semaphore);
1989 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1993 % N e w M a g i c k I m a g e %
1997 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999 % NewMagickImage() creates a blank image canvas of the specified size and
2002 % The format of the NewMagickImage method is:
2004 % Image *NewMagickImage(const ImageInfo *image_info,const size_t width,
2005 % const size_t height,const PixelInfo *background,
2006 % ExceptionInfo *exception)
2008 % A description of each parameter follows:
2010 % o image: the image.
2012 % o width: the image width.
2014 % o height: the image height.
2016 % o background: the image color.
2018 % o exception: return any errors or warnings in this structure.
2021 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2022 const size_t width,const size_t height,const PixelInfo *background,
2023 ExceptionInfo *exception)
2037 assert(image_info != (const ImageInfo *) NULL);
2038 if (image_info->debug != MagickFalse)
2039 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2040 assert(image_info->signature == MagickCoreSignature);
2041 assert(background != (const PixelInfo *) NULL);
2042 image=AcquireImage(image_info,exception);
2043 image->columns=width;
2045 image->colorspace=background->colorspace;
2046 image->alpha_trait=background->alpha_trait;
2047 image->fuzz=background->fuzz;
2048 image->depth=background->depth;
2050 image_view=AcquireAuthenticCacheView(image,exception);
2051 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2052 #pragma omp parallel for schedule(static,4) shared(status) \
2053 magick_threads(image,image,image->rows,1)
2055 for (y=0; y < (ssize_t) image->rows; y++)
2063 if (status == MagickFalse)
2065 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2066 if (q == (Quantum *) NULL)
2071 for (x=0; x < (ssize_t) image->columns; x++)
2073 SetPixelViaPixelInfo(image,background,q);
2074 q+=GetPixelChannels(image);
2076 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2079 image_view=DestroyCacheView(image_view);
2080 if (status == MagickFalse)
2081 image=DestroyImage(image);
2086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2090 % R e f e r e n c e I m a g e %
2094 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2096 % ReferenceImage() increments the reference count associated with an image
2097 % returning a pointer to the image.
2099 % The format of the ReferenceImage method is:
2101 % Image *ReferenceImage(Image *image)
2103 % A description of each parameter follows:
2105 % o image: the image.
2108 MagickExport Image *ReferenceImage(Image *image)
2110 assert(image != (Image *) NULL);
2111 if (image->debug != MagickFalse)
2112 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2113 assert(image->signature == MagickCoreSignature);
2114 LockSemaphoreInfo(image->semaphore);
2115 image->reference_count++;
2116 UnlockSemaphoreInfo(image->semaphore);
2121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2125 % R e s e t I m a g e P a g e %
2129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2131 % ResetImagePage() resets the image page canvas and position.
2133 % The format of the ResetImagePage method is:
2135 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2137 % A description of each parameter follows:
2139 % o image: the image.
2141 % o page: the relative page specification.
2144 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2152 assert(image != (Image *) NULL);
2153 assert(image->signature == MagickCoreSignature);
2154 if (image->debug != MagickFalse)
2155 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2156 flags=ParseAbsoluteGeometry(page,&geometry);
2157 if ((flags & WidthValue) != 0)
2159 if ((flags & HeightValue) == 0)
2160 geometry.height=geometry.width;
2161 image->page.width=geometry.width;
2162 image->page.height=geometry.height;
2164 if ((flags & AspectValue) != 0)
2166 if ((flags & XValue) != 0)
2167 image->page.x+=geometry.x;
2168 if ((flags & YValue) != 0)
2169 image->page.y+=geometry.y;
2173 if ((flags & XValue) != 0)
2175 image->page.x=geometry.x;
2176 if ((image->page.width == 0) && (geometry.x > 0))
2177 image->page.width=image->columns+geometry.x;
2179 if ((flags & YValue) != 0)
2181 image->page.y=geometry.y;
2182 if ((image->page.height == 0) && (geometry.y > 0))
2183 image->page.height=image->rows+geometry.y;
2190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2194 % S e t I m a g e B a c k g r o u n d C o l o r %
2198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2200 % SetImageBackgroundColor() initializes the image pixels to the image
2201 % background color. The background color is defined by the background_color
2202 % member of the image structure.
2204 % The format of the SetImage method is:
2206 % MagickBooleanType SetImageBackgroundColor(Image *image,
2207 % ExceptionInfo *exception)
2209 % A description of each parameter follows:
2211 % o image: the image.
2213 % o exception: return any errors or warnings in this structure.
2216 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2217 ExceptionInfo *exception)
2231 assert(image != (Image *) NULL);
2232 if (image->debug != MagickFalse)
2233 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2234 assert(image->signature == MagickCoreSignature);
2235 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2236 return(MagickFalse);
2237 ConformPixelInfo(image,&image->background_color,&background,exception);
2239 Set image background color.
2242 image_view=AcquireAuthenticCacheView(image,exception);
2243 for (y=0; y < (ssize_t) image->rows; y++)
2251 if (status == MagickFalse)
2253 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2254 if (q == (Quantum *) NULL)
2259 for (x=0; x < (ssize_t) image->columns; x++)
2261 SetPixelViaPixelInfo(image,&background,q);
2262 q+=GetPixelChannels(image);
2264 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2267 image_view=DestroyCacheView(image_view);
2272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2276 % S e t I m a g e C h a n n e l M a s k %
2280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2282 % SetImageChannelMask() sets the image channel mask from the specified channel
2285 % The format of the SetImageChannelMask method is:
2287 % ChannelType SetImageChannelMask(Image *image,
2288 % const ChannelType channel_mask)
2290 % A description of each parameter follows:
2292 % o image: the image.
2294 % o channel_mask: the channel mask.
2297 MagickExport ChannelType SetImageChannelMask(Image *image,
2298 const ChannelType channel_mask)
2300 return(SetPixelChannelMask(image,channel_mask));
2304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2308 % S e t I m a g e C o l o r %
2312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2314 % SetImageColor() set the entire image canvas to the specified color.
2316 % The format of the SetImageColor method is:
2318 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2319 % ExeptionInfo *exception)
2321 % A description of each parameter follows:
2323 % o image: the image.
2325 % o background: the image color.
2327 % o exception: return any errors or warnings in this structure.
2330 MagickExport MagickBooleanType SetImageColor(Image *image,
2331 const PixelInfo *color,ExceptionInfo *exception)
2342 assert(image != (Image *) NULL);
2343 if (image->debug != MagickFalse)
2344 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2345 assert(image->signature == MagickCoreSignature);
2346 assert(color != (const PixelInfo *) NULL);
2347 image->colorspace=color->colorspace;
2348 image->alpha_trait=color->alpha_trait;
2349 image->fuzz=color->fuzz;
2350 image->depth=color->depth;
2352 image_view=AcquireAuthenticCacheView(image,exception);
2353 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2354 #pragma omp parallel for schedule(static,4) shared(status) \
2355 magick_threads(image,image,image->rows,1)
2357 for (y=0; y < (ssize_t) image->rows; y++)
2365 if (status == MagickFalse)
2367 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2368 if (q == (Quantum *) NULL)
2373 for (x=0; x < (ssize_t) image->columns; x++)
2375 SetPixelViaPixelInfo(image,color,q);
2376 q+=GetPixelChannels(image);
2378 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2381 image_view=DestroyCacheView(image_view);
2386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2390 % S e t I m a g e S t o r a g e C l a s s %
2394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2396 % SetImageStorageClass() sets the image class: DirectClass for true color
2397 % images or PseudoClass for colormapped images.
2399 % The format of the SetImageStorageClass method is:
2401 % MagickBooleanType SetImageStorageClass(Image *image,
2402 % const ClassType storage_class,ExceptionInfo *exception)
2404 % A description of each parameter follows:
2406 % o image: the image.
2408 % o storage_class: The image class.
2410 % o exception: return any errors or warnings in this structure.
2413 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2414 const ClassType storage_class,ExceptionInfo *exception)
2416 image->storage_class=storage_class;
2417 return(SyncImagePixelCache(image,exception));
2421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2425 % S e t I m a g e E x t e n t %
2429 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2431 % SetImageExtent() sets the image size (i.e. columns & rows).
2433 % The format of the SetImageExtent method is:
2435 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2436 % const size_t rows,ExceptionInfo *exception)
2438 % A description of each parameter follows:
2440 % o image: the image.
2442 % o columns: The image width in pixels.
2444 % o rows: The image height in pixels.
2446 % o exception: return any errors or warnings in this structure.
2449 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2450 const size_t rows,ExceptionInfo *exception)
2452 if ((columns == 0) || (rows == 0))
2453 ThrowBinaryException(ImageError,"NegativeOrZeroImageSize",image->filename);
2454 image->columns=columns;
2456 if (image->depth > (8*sizeof(MagickSizeType)))
2457 ThrowBinaryException(ImageError,"ImageDepthNotSupported",image->filename);
2458 return(SyncImagePixelCache(image,exception));
2462 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2466 + S e t I m a g e I n f o %
2470 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2472 % SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
2473 % It is set to a type of image format based on the prefix or suffix of the
2474 % filename. For example, 'ps:image' returns PS indicating a Postscript image.
2475 % JPEG is returned for this filename: 'image.jpg'. The filename prefix has
2476 % precendence over the suffix. Use an optional index enclosed in brackets
2477 % after a file name to specify a desired scene of a multi-resolution image
2478 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2479 % indicates success.
2481 % The format of the SetImageInfo method is:
2483 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2484 % const unsigned int frames,ExceptionInfo *exception)
2486 % A description of each parameter follows:
2488 % o image_info: the image info.
2490 % o frames: the number of images you intend to write.
2492 % o exception: return any errors or warnings in this structure.
2495 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2496 const unsigned int frames,ExceptionInfo *exception)
2499 component[MagickPathExtent],
2500 magic[MagickPathExtent],
2525 Look for 'image.format' in filename.
2527 assert(image_info != (ImageInfo *) NULL);
2528 assert(image_info->signature == MagickCoreSignature);
2529 if (image_info->debug != MagickFalse)
2530 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2531 image_info->filename);
2533 GetPathComponent(image_info->filename,SubimagePath,component);
2534 if (*component != '\0')
2537 Look for scene specification (e.g. img0001.pcd[4]).
2539 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2541 if (IsGeometry(component) != MagickFalse)
2542 (void) CloneString(&image_info->extract,component);
2550 (void) CloneString(&image_info->scenes,component);
2551 image_info->scene=StringToUnsignedLong(image_info->scenes);
2552 image_info->number_scenes=image_info->scene;
2553 p=image_info->scenes;
2554 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2556 while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2558 first=(size_t) strtol(p,&q,10);
2560 while (isspace((int) ((unsigned char) *q)) != 0)
2563 last=(size_t) strtol(q+1,&q,10);
2566 if (first < image_info->scene)
2567 image_info->scene=first;
2568 if (last > image_info->number_scenes)
2569 image_info->number_scenes=last;
2572 image_info->number_scenes-=image_info->scene-1;
2576 if (*image_info->magick == '\0')
2577 GetPathComponent(image_info->filename,ExtensionPath,component);
2578 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2579 if (*component != '\0')
2580 if ((LocaleCompare(component,"gz") == 0) ||
2581 (LocaleCompare(component,"Z") == 0) ||
2582 (LocaleCompare(component,"svgz") == 0) ||
2583 (LocaleCompare(component,"wmz") == 0))
2586 path[MagickPathExtent];
2588 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2589 path[strlen(path)-strlen(component)-1]='\0';
2590 GetPathComponent(path,ExtensionPath,component);
2593 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2594 if (*component != '\0')
2595 if (LocaleCompare(component,"bz2") == 0)
2598 path[MagickPathExtent];
2600 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2601 path[strlen(path)-strlen(component)-1]='\0';
2602 GetPathComponent(path,ExtensionPath,component);
2605 image_info->affirm=MagickFalse;
2606 sans_exception=AcquireExceptionInfo();
2607 if (*component != '\0')
2616 *format_type_formats[] =
2638 User specified image format.
2640 (void) CopyMagickString(magic,component,MagickPathExtent);
2643 Look for explicit image formats.
2645 format_type=UndefinedFormatType;
2646 magick_info=GetMagickInfo(magic,sans_exception);
2647 if ((magick_info != (const MagickInfo *) NULL) &&
2648 (magick_info->format_type != UndefinedFormatType))
2649 format_type=magick_info->format_type;
2651 while ((format_type == UndefinedFormatType) &&
2652 (format_type_formats[i] != (char *) NULL))
2654 if ((*magic == *format_type_formats[i]) &&
2655 (LocaleCompare(magic,format_type_formats[i]) == 0))
2656 format_type=ExplicitFormatType;
2659 if (format_type == UndefinedFormatType)
2660 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2662 if (format_type == ExplicitFormatType)
2664 image_info->affirm=MagickTrue;
2665 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2667 if (LocaleCompare(magic,"RGB") == 0)
2668 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2671 Look for explicit 'format:image' in filename.
2674 GetPathComponent(image_info->filename,MagickPath,magic);
2677 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2678 magick_info=GetMagickInfo(magic,sans_exception);
2679 GetPathComponent(image_info->filename,CanonicalPath,component);
2680 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2688 User specified image format.
2691 magick_info=GetMagickInfo(magic,sans_exception);
2692 delegate_info=GetDelegateInfo(magic,"*",sans_exception);
2693 if (delegate_info == (const DelegateInfo *) NULL)
2694 delegate_info=GetDelegateInfo("*",magic,sans_exception);
2695 if (((magick_info != (const MagickInfo *) NULL) ||
2696 (delegate_info != (const DelegateInfo *) NULL)) &&
2697 (IsMagickConflict(magic) == MagickFalse))
2699 image_info->affirm=MagickTrue;
2700 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2701 GetPathComponent(image_info->filename,CanonicalPath,component);
2702 (void) CopyMagickString(image_info->filename,component,
2706 sans_exception=DestroyExceptionInfo(sans_exception);
2707 if ((magick_info == (const MagickInfo *) NULL) ||
2708 (GetMagickEndianSupport(magick_info) == MagickFalse))
2709 image_info->endian=UndefinedEndian;
2710 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2713 Test for multiple image support (e.g. image%02d.png).
2715 (void) InterpretImageFilename(image_info,(Image *) NULL,
2716 image_info->filename,(int) image_info->scene,component,exception);
2717 if ((LocaleCompare(component,image_info->filename) != 0) &&
2718 (strchr(component,'%') == (char *) NULL))
2719 image_info->adjoin=MagickFalse;
2721 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2724 Some image formats do not support multiple frames per file.
2726 magick_info=GetMagickInfo(magic,exception);
2727 if (magick_info != (const MagickInfo *) NULL)
2728 if (GetMagickAdjoin(magick_info) == MagickFalse)
2729 image_info->adjoin=MagickFalse;
2731 if (image_info->affirm != MagickFalse)
2742 Determine the image format from the first few bytes of the file.
2744 magick_size=GetMagicPatternExtent(exception);
2745 if (magick_size == 0)
2746 return(MagickFalse);
2747 image=AcquireImage(image_info,exception);
2748 (void) CopyMagickString(image->filename,image_info->filename,
2750 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2751 if (status == MagickFalse)
2753 image=DestroyImage(image);
2754 return(MagickFalse);
2756 if ((IsBlobSeekable(image) == MagickFalse) ||
2757 (IsBlobExempt(image) != MagickFalse))
2760 Copy standard input or pipe to temporary file.
2763 status=ImageToFile(image,component,exception);
2764 (void) CloseBlob(image);
2765 if (status == MagickFalse)
2767 image=DestroyImage(image);
2768 return(MagickFalse);
2770 SetImageInfoFile(image_info,(FILE *) NULL);
2771 (void) CopyMagickString(image->filename,component,MagickPathExtent);
2772 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2773 if (status == MagickFalse)
2775 image=DestroyImage(image);
2776 return(MagickFalse);
2778 (void) CopyMagickString(image_info->filename,component,
2780 image_info->temporary=MagickTrue;
2782 magick=(unsigned char *) AcquireMagickMemory(magick_size);
2783 if (magick == (unsigned char *) NULL)
2785 (void) CloseBlob(image);
2786 image=DestroyImage(image);
2787 return(MagickFalse);
2789 (void) ResetMagickMemory(magick,0,magick_size);
2790 count=ReadBlob(image,magick_size,magick);
2791 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
2792 (void) CloseBlob(image);
2793 image=DestroyImage(image);
2795 Check magic.xml configuration file.
2797 sans_exception=AcquireExceptionInfo();
2798 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
2799 magick=(unsigned char *) RelinquishMagickMemory(magick);
2800 if ((magic_info != (const MagicInfo *) NULL) &&
2801 (GetMagicName(magic_info) != (char *) NULL))
2804 Try to use magick_info that was determined earlier by the extension
2806 if ((magick_info != (const MagickInfo *) NULL) &&
2807 (GetMagickUseExtension(magick_info) != MagickFalse) &&
2808 (LocaleCompare(magick_info->module,GetMagicName(
2810 (void) CopyMagickString(image_info->magick,magick_info->name,
2814 (void) CopyMagickString(image_info->magick,GetMagicName(
2815 magic_info),MagickPathExtent);
2816 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2818 if ((magick_info == (const MagickInfo *) NULL) ||
2819 (GetMagickEndianSupport(magick_info) == MagickFalse))
2820 image_info->endian=UndefinedEndian;
2821 sans_exception=DestroyExceptionInfo(sans_exception);
2824 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2825 if ((magick_info == (const MagickInfo *) NULL) ||
2826 (GetMagickEndianSupport(magick_info) == MagickFalse))
2827 image_info->endian=UndefinedEndian;
2828 sans_exception=DestroyExceptionInfo(sans_exception);
2834 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2838 % S e t I m a g e I n f o B l o b %
2842 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2844 % SetImageInfoBlob() sets the image info blob member.
2846 % The format of the SetImageInfoBlob method is:
2848 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2849 % const size_t length)
2851 % A description of each parameter follows:
2853 % o image_info: the image info.
2857 % o length: the blob length.
2860 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2861 const size_t length)
2863 assert(image_info != (ImageInfo *) NULL);
2864 assert(image_info->signature == MagickCoreSignature);
2865 if (image_info->debug != MagickFalse)
2866 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2867 image_info->filename);
2868 image_info->blob=(void *) blob;
2869 image_info->length=length;
2873 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2877 % S e t I m a g e I n f o F i l e %
2881 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2883 % SetImageInfoFile() sets the image info file member.
2885 % The format of the SetImageInfoFile method is:
2887 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2889 % A description of each parameter follows:
2891 % o image_info: the image info.
2896 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2898 assert(image_info != (ImageInfo *) NULL);
2899 assert(image_info->signature == MagickCoreSignature);
2900 if (image_info->debug != MagickFalse)
2901 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2902 image_info->filename);
2903 image_info->file=file;
2907 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2911 % S e t I m a g e A l p h a %
2915 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2917 % SetImageAlpha() sets the alpha levels of the image.
2919 % The format of the SetImageAlpha method is:
2921 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
2922 % ExceptionInfo *exception)
2924 % A description of each parameter follows:
2926 % o image: the image.
2928 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
2929 % fully transparent.
2932 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
2933 ExceptionInfo *exception)
2944 assert(image != (Image *) NULL);
2945 if (image->debug != MagickFalse)
2946 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2947 assert(image->signature == MagickCoreSignature);
2948 image->alpha_trait=BlendPixelTrait;
2950 image_view=AcquireAuthenticCacheView(image,exception);
2951 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2952 #pragma omp parallel for schedule(static,4) shared(status) \
2953 magick_threads(image,image,image->rows,1)
2955 for (y=0; y < (ssize_t) image->rows; y++)
2963 if (status == MagickFalse)
2965 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2966 if (q == (Quantum *) NULL)
2971 for (x=0; x < (ssize_t) image->columns; x++)
2973 if (GetPixelReadMask(image,q) != 0)
2974 SetPixelAlpha(image,alpha,q);
2975 q+=GetPixelChannels(image);
2977 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2980 image_view=DestroyCacheView(image_view);
2985 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2989 % S e t I m a g e M a s k %
2993 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2995 % SetImageMask() associates a mask with the image. The mask must be the same
2996 % dimensions as the image.
2998 % The format of the SetImageMask method is:
3000 % MagickBooleanType SetImageMask(Image *image,const PixelMask type,
3001 % const Image *mask,ExceptionInfo *exception)
3003 % A description of each parameter follows:
3005 % o image: the image.
3007 % o type: the mask type, ReadPixelMask or WritePixelMask.
3009 % o mask: the image mask.
3011 % o exception: return any errors or warnings in this structure.
3014 MagickExport MagickBooleanType SetImageMask(Image *image,const PixelMask type,
3015 const Image *mask,ExceptionInfo *exception)
3030 assert(image != (Image *) NULL);
3031 if (image->debug != MagickFalse)
3032 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3033 assert(image->signature == MagickCoreSignature);
3034 if (mask == (const Image *) NULL)
3038 case WritePixelMask: image->write_mask=MagickFalse; break;
3039 default: image->read_mask=MagickFalse; break;
3041 return(SyncImagePixelCache(image,exception));
3045 case WritePixelMask: image->write_mask=MagickTrue; break;
3046 default: image->read_mask=MagickTrue; break;
3048 if (SyncImagePixelCache(image,exception) == MagickFalse)
3049 return(MagickFalse);
3051 mask_view=AcquireVirtualCacheView(mask,exception);
3052 image_view=AcquireAuthenticCacheView(image,exception);
3053 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3054 #pragma omp parallel for schedule(static,4) shared(status) \
3055 magick_threads(mask,image,1,1)
3057 for (y=0; y < (ssize_t) image->rows; y++)
3059 register const Quantum
3068 if (status == MagickFalse)
3070 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3071 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3072 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3077 for (x=0; x < (ssize_t) image->columns; x++)
3082 intensity=GetPixelIntensity(mask,p);
3085 case WritePixelMask:
3087 SetPixelWriteMask(image,ClampToQuantum(QuantumRange-intensity),q);
3092 SetPixelReadMask(image,ClampToQuantum(QuantumRange-intensity),q);
3096 p+=GetPixelChannels(mask);
3097 q+=GetPixelChannels(image);
3099 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3102 mask_view=DestroyCacheView(mask_view);
3103 image_view=DestroyCacheView(image_view);
3108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3112 % S e t I m a g e R e g i o n M a s k %
3116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3118 % SetImageRegionMask() associates a mask as defined by a region with the
3121 % The format of the SetImageRegionMask method is:
3123 % MagickBooleanType SetImageRegionMask(Image *image,const PixelMask type,
3124 % const RectangleInfo *region,ExceptionInfo *exception)
3126 % A description of each parameter follows:
3128 % o image: the image.
3130 % o type: the mask type, ReadPixelMask or WritePixelMask.
3132 % o geometry: the mask region.
3134 % o exception: return any errors or warnings in this structure.
3137 MagickExport MagickBooleanType SetImageRegionMask(Image *image,
3138 const PixelMask type,const RectangleInfo *region,ExceptionInfo *exception)
3150 Set image mask as defined by the region.
3152 assert(image != (Image *) NULL);
3153 if (image->debug != MagickFalse)
3154 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3155 assert(image->signature == MagickCoreSignature);
3156 if (region == (const RectangleInfo *) NULL)
3160 case WritePixelMask: image->write_mask=MagickFalse; break;
3161 default: image->read_mask=MagickFalse; break;
3163 return(SyncImagePixelCache(image,exception));
3167 case WritePixelMask: image->write_mask=MagickTrue; break;
3168 default: image->read_mask=MagickTrue; break;
3170 if (SyncImagePixelCache(image,exception) == MagickFalse)
3171 return(MagickFalse);
3173 image_view=AcquireAuthenticCacheView(image,exception);
3174 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3175 #pragma omp parallel for schedule(static,4) shared(status) \
3176 magick_threads(image,image,1,1)
3178 for (y=0; y < (ssize_t) image->rows; y++)
3186 if (status == MagickFalse)
3188 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3189 if (q == (Quantum *) NULL)
3194 for (x=0; x < (ssize_t) image->columns; x++)
3200 if (((x >= region->x) && (x < (region->x+region->width))) &&
3201 ((y >= region->y) && (y < (region->y+region->height))))
3205 case WritePixelMask:
3207 SetPixelWriteMask(image,pixel,q);
3212 SetPixelReadMask(image,pixel,q);
3216 q+=GetPixelChannels(image);
3218 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3221 image_view=DestroyCacheView(image_view);
3226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3230 % 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 %
3234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3236 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3237 % image and returns the previous setting. A virtual pixel is any pixel access
3238 % that is outside the boundaries of the image cache.
3240 % The format of the SetImageVirtualPixelMethod() method is:
3242 % VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3243 % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3245 % A description of each parameter follows:
3247 % o image: the image.
3249 % o virtual_pixel_method: choose the type of virtual pixel.
3251 % o exception: return any errors or warnings in this structure.
3254 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3255 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3257 assert(image != (const Image *) NULL);
3258 assert(image->signature == MagickCoreSignature);
3259 if (image->debug != MagickFalse)
3260 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3261 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3269 % S m u s h I m a g e s %
3273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3275 % SmushImages() takes all images from the current image pointer to the end
3276 % of the image list and smushes them to each other top-to-bottom if the
3277 % stack parameter is true, otherwise left-to-right.
3279 % The current gravity setting now effects how the image is justified in the
3282 % The format of the SmushImages method is:
3284 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3285 % ExceptionInfo *exception)
3287 % A description of each parameter follows:
3289 % o images: the image sequence.
3291 % o stack: A value other than 0 stacks the images top-to-bottom.
3293 % o offset: minimum distance in pixels between images.
3295 % o exception: return any errors or warnings in this structure.
3299 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3300 const ssize_t offset,ExceptionInfo *exception)
3314 register const Quantum
3327 if (images->previous == (Image *) NULL)
3330 SetGeometry(smush_image,&right_geometry);
3331 GravityAdjustGeometry(right_image->columns,right_image->rows,
3332 right_image->gravity,&right_geometry);
3333 left_image=images->previous;
3334 SetGeometry(smush_image,&left_geometry);
3335 GravityAdjustGeometry(left_image->columns,left_image->rows,
3336 left_image->gravity,&left_geometry);
3337 gap=right_image->columns;
3338 left_view=AcquireVirtualCacheView(left_image,exception);
3339 right_view=AcquireVirtualCacheView(right_image,exception);
3340 for (y=0; y < (ssize_t) smush_image->rows; y++)
3342 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3344 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3345 if ((p == (const Quantum *) NULL) ||
3346 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3347 ((left_image->columns-x-1) >= gap))
3350 i=(ssize_t) left_image->columns-x-1;
3351 for (x=0; x < (ssize_t) right_image->columns; x++)
3353 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3355 if ((p == (const Quantum *) NULL) ||
3356 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3357 ((x+i) >= (ssize_t) gap))
3360 if ((x+i) < (ssize_t) gap)
3363 right_view=DestroyCacheView(right_view);
3364 left_view=DestroyCacheView(left_view);
3365 if (y < (ssize_t) smush_image->rows)
3367 return((ssize_t) gap-offset);
3370 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3371 const ssize_t offset,ExceptionInfo *exception)
3385 register const Quantum
3398 if (images->previous == (Image *) NULL)
3400 bottom_image=images;
3401 SetGeometry(smush_image,&bottom_geometry);
3402 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3403 bottom_image->gravity,&bottom_geometry);
3404 top_image=images->previous;
3405 SetGeometry(smush_image,&top_geometry);
3406 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3408 gap=bottom_image->rows;
3409 top_view=AcquireVirtualCacheView(top_image,exception);
3410 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3411 for (x=0; x < (ssize_t) smush_image->columns; x++)
3413 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3415 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3416 if ((p == (const Quantum *) NULL) ||
3417 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3418 ((top_image->rows-y-1) >= gap))
3421 i=(ssize_t) top_image->rows-y-1;
3422 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3424 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3426 if ((p == (const Quantum *) NULL) ||
3427 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3428 ((y+i) >= (ssize_t) gap))
3431 if ((y+i) < (ssize_t) gap)
3434 bottom_view=DestroyCacheView(bottom_view);
3435 top_view=DestroyCacheView(top_view);
3436 if (x < (ssize_t) smush_image->columns)
3438 return((ssize_t) gap-offset);
3441 MagickExport Image *SmushImages(const Image *images,
3442 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3444 #define SmushImageTag "Smush/Image"
3465 register const Image
3478 Compute maximum area of smushed area.
3480 assert(images != (Image *) NULL);
3481 assert(images->signature == MagickCoreSignature);
3482 if (images->debug != MagickFalse)
3483 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3484 assert(exception != (ExceptionInfo *) NULL);
3485 assert(exception->signature == MagickCoreSignature);
3487 alpha_trait=image->alpha_trait;
3489 width=image->columns;
3491 next=GetNextImageInList(image);
3492 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3494 if (next->alpha_trait != UndefinedPixelTrait)
3495 alpha_trait=BlendPixelTrait;
3497 if (stack != MagickFalse)
3499 if (next->columns > width)
3500 width=next->columns;
3502 if (next->previous != (Image *) NULL)
3506 width+=next->columns;
3507 if (next->previous != (Image *) NULL)
3509 if (next->rows > height)
3515 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3516 if (smush_image == (Image *) NULL)
3517 return((Image *) NULL);
3518 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3520 smush_image=DestroyImage(smush_image);
3521 return((Image *) NULL);
3523 smush_image->alpha_trait=alpha_trait;
3524 (void) SetImageBackgroundColor(smush_image,exception);
3528 for (n=0; n < (MagickOffsetType) number_images; n++)
3530 SetGeometry(smush_image,&geometry);
3531 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3532 if (stack != MagickFalse)
3534 x_offset-=geometry.x;
3535 y_offset-=SmushYGap(smush_image,image,offset,exception);
3539 x_offset-=SmushXGap(smush_image,image,offset,exception);
3540 y_offset-=geometry.y;
3542 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3543 y_offset,exception);
3544 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3545 if (proceed == MagickFalse)
3547 if (stack == MagickFalse)
3549 x_offset+=(ssize_t) image->columns;
3555 y_offset+=(ssize_t) image->rows;
3557 image=GetNextImageInList(image);
3559 if (stack == MagickFalse)
3560 smush_image->columns=(size_t) x_offset;
3562 smush_image->rows=(size_t) y_offset;
3563 if (status == MagickFalse)
3564 smush_image=DestroyImage(smush_image);
3565 return(smush_image);
3569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3573 % S t r i p I m a g e %
3577 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3579 % StripImage() strips an image of all profiles and comments.
3581 % The format of the StripImage method is:
3583 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3585 % A description of each parameter follows:
3587 % o image: the image.
3589 % o exception: return any errors or warnings in this structure.
3592 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3597 assert(image != (Image *) NULL);
3598 if (image->debug != MagickFalse)
3599 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3601 DestroyImageProfiles(image);
3602 (void) DeleteImageProperty(image,"comment");
3603 (void) DeleteImageProperty(image,"date:create");
3604 (void) DeleteImageProperty(image,"date:modify");
3605 status=SetImageArtifact(image,"png:exclude-chunk",
3606 "bKGD,cHRM,EXIF,gAMA,iCCP,iTXt,sRGB,tEXt,zCCP,zTXt,date");
3611 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3615 + S y n c I m a g e %
3619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3621 % SyncImage() initializes the red, green, and blue intensities of each pixel
3622 % as defined by the colormap index.
3624 % The format of the SyncImage method is:
3626 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3628 % A description of each parameter follows:
3630 % o image: the image.
3632 % o exception: return any errors or warnings in this structure.
3636 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3637 MagickBooleanType *range_exception)
3639 if ((size_t) index < image->colors)
3641 *range_exception=MagickTrue;
3642 return((Quantum) 0);
3645 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3658 assert(image != (Image *) NULL);
3659 if (image->debug != MagickFalse)
3660 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3661 assert(image->signature == MagickCoreSignature);
3662 if (image->storage_class == DirectClass)
3663 return(MagickFalse);
3664 range_exception=MagickFalse;
3667 image_view=AcquireAuthenticCacheView(image,exception);
3668 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3669 #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
3670 magick_threads(image,image,image->rows,1)
3672 for (y=0; y < (ssize_t) image->rows; y++)
3683 if (status == MagickFalse)
3685 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3686 if (q == (Quantum *) NULL)
3691 for (x=0; x < (ssize_t) image->columns; x++)
3693 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3694 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
3695 q+=GetPixelChannels(image);
3697 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3700 image_view=DestroyCacheView(image_view);
3702 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3703 (void) ThrowMagickException(exception,GetMagickModule(),
3704 CorruptImageWarning,"InvalidColormapIndex","`%s'",image->filename);
3709 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3713 % S y n c I m a g e S e t t i n g s %
3717 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3719 % SyncImageSettings() syncs any image_info global options into per-image
3722 % Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
3723 % that operations and coders can find such settings. In IMv7 if a desired
3724 % per-image artifact is not set, then it will directly look for a global
3725 % option as a fallback, as such this copy is no longer needed, only the
3728 % The format of the SyncImageSettings method is:
3730 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3731 % Image *image,ExceptionInfo *exception)
3732 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3733 % Image *image,ExceptionInfo *exception)
3735 % A description of each parameter follows:
3737 % o image_info: the image info.
3739 % o image: the image.
3741 % o exception: return any errors or warnings in this structure.
3745 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3746 Image *images,ExceptionInfo *exception)
3751 assert(image_info != (const ImageInfo *) NULL);
3752 assert(image_info->signature == MagickCoreSignature);
3753 assert(images != (Image *) NULL);
3754 assert(images->signature == MagickCoreSignature);
3755 if (images->debug != MagickFalse)
3756 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3758 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3759 (void) SyncImageSettings(image_info,image,exception);
3760 (void) DeleteImageOption(image_info,"page");
3764 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3765 Image *image,ExceptionInfo *exception)
3782 assert(image_info != (const ImageInfo *) NULL);
3783 assert(image_info->signature == MagickCoreSignature);
3784 assert(image != (Image *) NULL);
3785 assert(image->signature == MagickCoreSignature);
3786 if (image->debug != MagickFalse)
3787 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3788 option=GetImageOption(image_info,"alpha-color");
3789 if (option != (const char *) NULL)
3790 (void) QueryColorCompliance(option,AllCompliance,&image->alpha_color,
3792 option=GetImageOption(image_info,"background");
3793 if (option != (const char *) NULL)
3794 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
3796 option=GetImageOption(image_info,"black-point-compensation");
3797 if (option != (const char *) NULL)
3798 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3799 MagickBooleanOptions,MagickFalse,option);
3800 option=GetImageOption(image_info,"blue-primary");
3801 if (option != (const char *) NULL)
3803 flags=ParseGeometry(option,&geometry_info);
3804 image->chromaticity.blue_primary.x=geometry_info.rho;
3805 image->chromaticity.blue_primary.y=geometry_info.sigma;
3806 if ((flags & SigmaValue) == 0)
3807 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3809 option=GetImageOption(image_info,"bordercolor");
3810 if (option != (const char *) NULL)
3811 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
3813 /* FUTURE: do not sync compose to per-image compose setting here */
3814 option=GetImageOption(image_info,"compose");
3815 if (option != (const char *) NULL)
3816 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3817 MagickFalse,option);
3819 option=GetImageOption(image_info,"compress");
3820 if (option != (const char *) NULL)
3821 image->compression=(CompressionType) ParseCommandOption(
3822 MagickCompressOptions,MagickFalse,option);
3823 option=GetImageOption(image_info,"debug");
3824 if (option != (const char *) NULL)
3825 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3826 MagickFalse,option);
3827 option=GetImageOption(image_info,"density");
3828 if (option != (const char *) NULL)
3833 flags=ParseGeometry(option,&geometry_info);
3834 image->resolution.x=geometry_info.rho;
3835 image->resolution.y=geometry_info.sigma;
3836 if ((flags & SigmaValue) == 0)
3837 image->resolution.y=image->resolution.x;
3839 option=GetImageOption(image_info,"depth");
3840 if (option != (const char *) NULL)
3841 image->depth=StringToUnsignedLong(option);
3842 option=GetImageOption(image_info,"endian");
3843 if (option != (const char *) NULL)
3844 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3845 MagickFalse,option);
3846 option=GetImageOption(image_info,"filter");
3847 if (option != (const char *) NULL)
3848 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
3849 MagickFalse,option);
3850 option=GetImageOption(image_info,"fuzz");
3851 if (option != (const char *) NULL)
3852 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3853 option=GetImageOption(image_info,"gravity");
3854 if (option != (const char *) NULL)
3855 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3856 MagickFalse,option);
3857 option=GetImageOption(image_info,"green-primary");
3858 if (option != (const char *) NULL)
3860 flags=ParseGeometry(option,&geometry_info);
3861 image->chromaticity.green_primary.x=geometry_info.rho;
3862 image->chromaticity.green_primary.y=geometry_info.sigma;
3863 if ((flags & SigmaValue) == 0)
3864 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3866 option=GetImageOption(image_info,"intent");
3867 if (option != (const char *) NULL)
3868 image->rendering_intent=(RenderingIntent) ParseCommandOption(
3869 MagickIntentOptions,MagickFalse,option);
3870 option=GetImageOption(image_info,"intensity");
3871 if (option != (const char *) NULL)
3872 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3873 MagickPixelIntensityOptions,MagickFalse,option);
3874 option=GetImageOption(image_info,"interlace");
3875 if (option != (const char *) NULL)
3876 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3877 MagickFalse,option);
3878 option=GetImageOption(image_info,"interpolate");
3879 if (option != (const char *) NULL)
3880 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
3881 MagickInterpolateOptions,MagickFalse,option);
3882 option=GetImageOption(image_info,"loop");
3883 if (option != (const char *) NULL)
3884 image->iterations=StringToUnsignedLong(option);
3885 option=GetImageOption(image_info,"orient");
3886 if (option != (const char *) NULL)
3887 image->orientation=(OrientationType) ParseCommandOption(
3888 MagickOrientationOptions,MagickFalse,option);
3889 option=GetImageOption(image_info,"page");
3890 if (option != (const char *) NULL)
3895 geometry=GetPageGeometry(option);
3896 flags=ParseAbsoluteGeometry(geometry,&image->page);
3897 geometry=DestroyString(geometry);
3899 option=GetImageOption(image_info,"quality");
3900 if (option != (const char *) NULL)
3901 image->quality=StringToUnsignedLong(option);
3902 option=GetImageOption(image_info,"red-primary");
3903 if (option != (const char *) NULL)
3905 flags=ParseGeometry(option,&geometry_info);
3906 image->chromaticity.red_primary.x=geometry_info.rho;
3907 image->chromaticity.red_primary.y=geometry_info.sigma;
3908 if ((flags & SigmaValue) == 0)
3909 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3911 if (image_info->quality != UndefinedCompressionQuality)
3912 image->quality=image_info->quality;
3913 option=GetImageOption(image_info,"scene");
3914 if (option != (const char *) NULL)
3915 image->scene=StringToUnsignedLong(option);
3916 option=GetImageOption(image_info,"taint");
3917 if (option != (const char *) NULL)
3918 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3919 MagickFalse,option);
3920 option=GetImageOption(image_info,"tile-offset");
3921 if (option != (const char *) NULL)
3926 geometry=GetPageGeometry(option);
3927 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3928 geometry=DestroyString(geometry);
3930 option=GetImageOption(image_info,"transparent-color");
3931 if (option != (const char *) NULL)
3932 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
3934 option=GetImageOption(image_info,"type");
3935 if (option != (const char *) NULL)
3936 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3938 option=GetImageOption(image_info,"units");
3939 units=image_info->units;
3940 if (option != (const char *) NULL)
3941 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
3942 MagickFalse,option);
3943 if (units != UndefinedResolution)
3945 if (image->units != units)
3946 switch (image->units)
3948 case PixelsPerInchResolution:
3950 if (units == PixelsPerCentimeterResolution)
3952 image->resolution.x/=2.54;
3953 image->resolution.y/=2.54;
3957 case PixelsPerCentimeterResolution:
3959 if (units == PixelsPerInchResolution)
3961 image->resolution.x=(double) ((size_t) (100.0*2.54*
3962 image->resolution.x+0.5))/100.0;
3963 image->resolution.y=(double) ((size_t) (100.0*2.54*
3964 image->resolution.y+0.5))/100.0;
3973 option=GetImageOption(image_info,"virtual-pixel");
3974 if (option != (const char *) NULL)
3975 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
3976 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
3978 option=GetImageOption(image_info,"white-point");
3979 if (option != (const char *) NULL)
3981 flags=ParseGeometry(option,&geometry_info);
3982 image->chromaticity.white_point.x=geometry_info.rho;
3983 image->chromaticity.white_point.y=geometry_info.sigma;
3984 if ((flags & SigmaValue) == 0)
3985 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
3988 Pointer to allow the lookup of pre-image artifact will fallback to a global
3989 option setting/define. This saves a lot of duplication of global options
3990 into per-image artifacts, while ensuring only specifically set per-image
3991 artifacts are preserved when parenthesis ends.
3993 if (image->image_info != (ImageInfo *) NULL)
3994 image->image_info=DestroyImageInfo(image->image_info);
3995 image->image_info=CloneImageInfo(image_info);