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/display.h"
63 #include "MagickCore/draw.h"
64 #include "MagickCore/enhance.h"
65 #include "MagickCore/exception.h"
66 #include "MagickCore/exception-private.h"
67 #include "MagickCore/gem.h"
68 #include "MagickCore/geometry.h"
69 #include "MagickCore/histogram.h"
70 #include "MagickCore/image-private.h"
71 #include "MagickCore/list.h"
72 #include "MagickCore/magic.h"
73 #include "MagickCore/magick.h"
74 #include "MagickCore/magick-private.h"
75 #include "MagickCore/memory_.h"
76 #include "MagickCore/module.h"
77 #include "MagickCore/monitor.h"
78 #include "MagickCore/monitor-private.h"
79 #include "MagickCore/option.h"
80 #include "MagickCore/paint.h"
81 #include "MagickCore/pixel-accessor.h"
82 #include "MagickCore/profile.h"
83 #include "MagickCore/property.h"
84 #include "MagickCore/quantize.h"
85 #include "MagickCore/random_.h"
86 #include "MagickCore/resource_.h"
87 #include "MagickCore/segment.h"
88 #include "MagickCore/semaphore.h"
89 #include "MagickCore/signature-private.h"
90 #include "MagickCore/statistic.h"
91 #include "MagickCore/string_.h"
92 #include "MagickCore/string-private.h"
93 #include "MagickCore/thread-private.h"
94 #include "MagickCore/threshold.h"
95 #include "MagickCore/timer.h"
96 #include "MagickCore/token.h"
97 #include "MagickCore/utility.h"
98 #include "MagickCore/utility-private.h"
99 #include "MagickCore/version.h"
100 #include "MagickCore/xwindow-private.h"
103 Constant declaration.
106 AlphaColor[] = "#bdbdbd", /* gray */
107 BackgroundColor[] = "#ffffff", /* white */
108 BorderColor[] = "#dfdfdf", /* gray */
109 DefaultTileFrame[] = "15x15+3+3",
110 DefaultTileGeometry[] = "120x120+4+3>",
111 DefaultTileLabel[] = "%f\n%G\n%b",
112 ForegroundColor[] = "#000", /* black */
113 LoadImageTag[] = "Load/Image",
114 LoadImagesTag[] = "Load/Images",
115 PSDensityGeometry[] = "72.0x72.0",
116 PSPageGeometry[] = "612x792",
117 SaveImageTag[] = "Save/Image",
118 SaveImagesTag[] = "Save/Images",
119 TransparentColor[] = "#00000000"; /* transparent black */
122 DefaultResolution = 72.0;
125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 % A c q u i r e I m a g e %
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 % AcquireImage() returns a pointer to an image structure initialized to
138 % The format of the AcquireImage method is:
140 % Image *AcquireImage(const ImageInfo *image_info,ExceptionInfo *exception)
142 % A description of each parameter follows:
144 % o image_info: Many of the image default values are set from this
145 % structure. For example, filename, compression, depth, background color,
148 % o exception: return any errors or warnings in this structure.
151 MagickExport Image *AcquireImage(const ImageInfo *image_info,
152 ExceptionInfo *exception)
164 Allocate image structure.
166 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
167 image=(Image *) AcquireMagickMemory(sizeof(*image));
168 if (image == (Image *) NULL)
169 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
170 (void) ResetMagickMemory(image,0,sizeof(*image));
172 Initialize Image structure.
174 (void) CopyMagickString(image->magick,"MIFF",MagickPathExtent);
175 image->storage_class=DirectClass;
176 image->depth=MAGICKCORE_QUANTUM_DEPTH;
177 image->colorspace=sRGBColorspace;
178 image->rendering_intent=PerceptualIntent;
179 image->gamma=1.000f/2.200f;
180 image->chromaticity.red_primary.x=0.6400f;
181 image->chromaticity.red_primary.y=0.3300f;
182 image->chromaticity.red_primary.z=0.0300f;
183 image->chromaticity.green_primary.x=0.3000f;
184 image->chromaticity.green_primary.y=0.6000f;
185 image->chromaticity.green_primary.z=0.1000f;
186 image->chromaticity.blue_primary.x=0.1500f;
187 image->chromaticity.blue_primary.y=0.0600f;
188 image->chromaticity.blue_primary.z=0.7900f;
189 image->chromaticity.white_point.x=0.3127f;
190 image->chromaticity.white_point.y=0.3290f;
191 image->chromaticity.white_point.z=0.3583f;
192 image->interlace=NoInterlace;
193 image->ticks_per_second=UndefinedTicksPerSecond;
194 image->compose=OverCompositeOp;
195 (void) QueryColorCompliance(AlphaColor,AllCompliance,&image->alpha_color,
197 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
198 &image->background_color,exception);
199 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
201 (void) QueryColorCompliance(TransparentColor,AllCompliance,
202 &image->transparent_color,exception);
203 GetTimerInfo(&image->timer);
204 image->cache=AcquirePixelCache(0);
205 image->channel_mask=DefaultChannels;
206 image->channel_map=AcquirePixelChannelMap();
207 image->blob=CloneBlobInfo((BlobInfo *) NULL);
208 image->timestamp=time((time_t *) NULL);
209 image->debug=IsEventLogging();
210 image->reference_count=1;
211 image->semaphore=AcquireSemaphoreInfo();
212 image->signature=MagickCoreSignature;
213 if (image_info == (ImageInfo *) NULL)
218 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
220 (void) CopyMagickString(image->filename,image_info->filename,
222 (void) CopyMagickString(image->magick_filename,image_info->filename,
224 (void) CopyMagickString(image->magick,image_info->magick,MagickPathExtent);
225 if (image_info->size != (char *) NULL)
227 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
228 image->columns=image->extract_info.width;
229 image->rows=image->extract_info.height;
230 image->offset=image->extract_info.x;
231 image->extract_info.x=0;
232 image->extract_info.y=0;
234 if (image_info->extract != (char *) NULL)
239 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
240 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
242 image->extract_info=geometry;
243 Swap(image->columns,image->extract_info.width);
244 Swap(image->rows,image->extract_info.height);
247 image->compression=image_info->compression;
248 image->quality=image_info->quality;
249 image->endian=image_info->endian;
250 image->interlace=image_info->interlace;
251 image->units=image_info->units;
252 if (image_info->density != (char *) NULL)
257 flags=ParseGeometry(image_info->density,&geometry_info);
258 image->resolution.x=geometry_info.rho;
259 image->resolution.y=geometry_info.sigma;
260 if ((flags & SigmaValue) == 0)
261 image->resolution.y=image->resolution.x;
263 if (image_info->page != (char *) NULL)
268 image->page=image->extract_info;
269 geometry=GetPageGeometry(image_info->page);
270 (void) ParseAbsoluteGeometry(geometry,&image->page);
271 geometry=DestroyString(geometry);
273 if (image_info->depth != 0)
274 image->depth=image_info->depth;
275 image->dither=image_info->dither;
276 image->alpha_color=image_info->alpha_color;
277 image->background_color=image_info->background_color;
278 image->border_color=image_info->border_color;
279 image->transparent_color=image_info->transparent_color;
280 image->ping=image_info->ping;
281 image->progress_monitor=image_info->progress_monitor;
282 image->client_data=image_info->client_data;
283 if (image_info->cache != (void *) NULL)
284 ClonePixelCacheMethods(image->cache,image_info->cache);
286 Set all global options that map to per-image settings.
288 (void) SyncImageSettings(image_info,image,exception);
290 Global options that are only set for new images.
292 option=GetImageOption(image_info,"delay");
293 if (option != (const char *) NULL)
298 flags=ParseGeometry(option,&geometry_info);
299 if ((flags & GreaterValue) != 0)
301 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
302 image->delay=(size_t) floor(geometry_info.rho+0.5);
305 if ((flags & LessValue) != 0)
307 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
308 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
311 image->delay=(size_t) floor(geometry_info.rho+0.5);
312 if ((flags & SigmaValue) != 0)
313 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
315 option=GetImageOption(image_info,"dispose");
316 if (option != (const char *) NULL)
317 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
327 % A c q u i r e I m a g e I n f o %
331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
333 % AcquireImageInfo() allocates the ImageInfo structure.
335 % The format of the AcquireImageInfo method is:
337 % ImageInfo *AcquireImageInfo(void)
340 MagickExport ImageInfo *AcquireImageInfo(void)
345 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
346 if (image_info == (ImageInfo *) NULL)
347 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
348 GetImageInfo(image_info);
353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
357 % A c q u i r e N e x t I m a g e %
361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363 % AcquireNextImage() initializes the next image in a sequence to
364 % default values. The next member of image points to the newly allocated
365 % image. If there is a memory shortage, next is assigned NULL.
367 % The format of the AcquireNextImage method is:
369 % void AcquireNextImage(const ImageInfo *image_info,Image *image,
370 % ExceptionInfo *exception)
372 % A description of each parameter follows:
374 % o image_info: Many of the image default values are set from this
375 % structure. For example, filename, compression, depth, background color,
378 % o image: the image.
380 % o exception: return any errors or warnings in this structure.
383 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image,
384 ExceptionInfo *exception)
387 Allocate image structure.
389 assert(image != (Image *) NULL);
390 assert(image->signature == MagickCoreSignature);
391 if (image->debug != MagickFalse)
392 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
393 image->next=AcquireImage(image_info,exception);
394 if (GetNextImageInList(image) == (Image *) NULL)
396 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
398 if (image_info != (ImageInfo *) NULL)
399 (void) CopyMagickString(GetNextImageInList(image)->filename,
400 image_info->filename,MagickPathExtent);
401 DestroyBlob(GetNextImageInList(image));
402 image->next->blob=ReferenceBlob(image->blob);
403 image->next->endian=image->endian;
404 image->next->scene=image->scene+1;
405 image->next->previous=image;
409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
413 % A p p e n d I m a g e s %
417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
419 % AppendImages() takes all images from the current image pointer to the end
420 % of the image list and appends them to each other top-to-bottom if the
421 % stack parameter is true, otherwise left-to-right.
423 % The current gravity setting effects how the image is justified in the
426 % The format of the AppendImages method is:
428 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
429 % ExceptionInfo *exception)
431 % A description of each parameter follows:
433 % o images: the image sequence.
435 % o stack: A value other than 0 stacks the images top-to-bottom.
437 % o exception: return any errors or warnings in this structure.
440 MagickExport Image *AppendImages(const Image *images,
441 const MagickBooleanType stack,ExceptionInfo *exception)
443 #define AppendImageTag "Append/Image"
478 Compute maximum area of appended area.
480 assert(images != (Image *) NULL);
481 assert(images->signature == MagickCoreSignature);
482 if (images->debug != MagickFalse)
483 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
484 assert(exception != (ExceptionInfo *) NULL);
485 assert(exception->signature == MagickCoreSignature);
486 alpha_trait=images->alpha_trait;
488 width=images->columns;
491 next=GetNextImageInList(images);
492 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
494 if (next->depth > depth)
496 if (next->alpha_trait != UndefinedPixelTrait)
497 alpha_trait=BlendPixelTrait;
499 if (stack != MagickFalse)
501 if (next->columns > width)
506 width+=next->columns;
507 if (next->rows > height)
513 append_image=CloneImage(images,width,height,MagickTrue,exception);
514 if (append_image == (Image *) NULL)
515 return((Image *) NULL);
516 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
518 append_image=DestroyImage(append_image);
519 return((Image *) NULL);
521 append_image->depth=depth;
522 append_image->alpha_trait=alpha_trait;
523 (void) SetImageBackgroundColor(append_image,exception);
528 append_view=AcquireAuthenticCacheView(append_image,exception);
529 for (n=0; n < (MagickOffsetType) number_images; n++)
537 SetGeometry(append_image,&geometry);
538 GravityAdjustGeometry(next->columns,next->rows,next->gravity,&geometry);
539 if (stack != MagickFalse)
540 x_offset-=geometry.x;
542 y_offset-=geometry.y;
543 image_view=AcquireVirtualCacheView(next,exception);
544 #if defined(MAGICKCORE_OPENMP_SUPPORT)
545 #pragma omp parallel for schedule(static,4) shared(status) \
546 magick_threads(next,next,next->rows,1)
548 for (y=0; y < (ssize_t) next->rows; y++)
556 register const Quantum
565 if (status == MagickFalse)
567 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
568 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
569 next->columns,1,exception);
570 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
575 GetPixelInfo(next,&pixel);
576 for (x=0; x < (ssize_t) next->columns; x++)
578 if (GetPixelReadMask(next,p) == 0)
580 SetPixelBackgoundColor(append_image,q);
581 p+=GetPixelChannels(next);
582 q+=GetPixelChannels(append_image);
585 GetPixelInfoPixel(next,p,&pixel);
586 SetPixelViaPixelInfo(append_image,&pixel,q);
587 p+=GetPixelChannels(next);
588 q+=GetPixelChannels(append_image);
590 sync=SyncCacheViewAuthenticPixels(append_view,exception);
591 if (sync == MagickFalse)
594 image_view=DestroyCacheView(image_view);
595 if (stack == MagickFalse)
597 x_offset+=(ssize_t) next->columns;
603 y_offset+=(ssize_t) next->rows;
605 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
606 if (proceed == MagickFalse)
608 next=GetNextImageInList(next);
610 append_view=DestroyCacheView(append_view);
611 if (status == MagickFalse)
612 append_image=DestroyImage(append_image);
613 return(append_image);
617 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
621 % C a t c h I m a g e E x c e p t i o n %
625 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
627 % CatchImageException() returns if no exceptions are found in the image
628 % sequence, otherwise it determines the most severe exception and reports
629 % it as a warning or error depending on the severity.
631 % The format of the CatchImageException method is:
633 % ExceptionType CatchImageException(Image *image)
635 % A description of each parameter follows:
637 % o image: An image sequence.
640 MagickExport ExceptionType CatchImageException(Image *image)
648 assert(image != (const Image *) NULL);
649 assert(image->signature == MagickCoreSignature);
650 if (image->debug != MagickFalse)
651 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
652 exception=AcquireExceptionInfo();
653 CatchException(exception);
654 severity=exception->severity;
655 exception=DestroyExceptionInfo(exception);
660 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664 % C l i p I m a g e P a t h %
668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
670 % ClipImagePath() sets the image clip mask based any clipping path information
673 % The format of the ClipImagePath method is:
675 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
676 % const MagickBooleanType inside,ExceptionInfo *exception)
678 % A description of each parameter follows:
680 % o image: the image.
682 % o pathname: name of clipping path resource. If name is preceded by #, use
683 % clipping path numbered by name.
685 % o inside: if non-zero, later operations take effect inside clipping path.
686 % Otherwise later operations take effect outside clipping path.
688 % o exception: return any errors or warnings in this structure.
692 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
694 return(ClipImagePath(image,"#1",MagickTrue,exception));
697 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
698 const MagickBooleanType inside,ExceptionInfo *exception)
700 #define ClipImagePathTag "ClipPath/Image"
714 assert(image != (const Image *) NULL);
715 assert(image->signature == MagickCoreSignature);
716 if (image->debug != MagickFalse)
717 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
718 assert(pathname != NULL);
719 property=AcquireString(pathname);
720 (void) FormatLocaleString(property,MagickPathExtent,"8BIM:1999,2998:%s",
722 value=GetImageProperty(image,property,exception);
723 property=DestroyString(property);
724 if (value == (const char *) NULL)
726 ThrowFileException(exception,OptionError,"NoClipPathDefined",
730 image_info=AcquireImageInfo();
731 (void) CopyMagickString(image_info->filename,image->filename,
733 (void) ConcatenateMagickString(image_info->filename,pathname,
735 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
736 image_info=DestroyImageInfo(image_info);
737 if (clip_mask == (Image *) NULL)
739 if (clip_mask->storage_class == PseudoClass)
741 (void) SyncImage(clip_mask,exception);
742 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
745 if (inside == MagickFalse)
746 (void) NegateImage(clip_mask,MagickFalse,exception);
747 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
748 "8BIM:1999,2998:%s\nPS",pathname);
749 (void) SetImageMask(image,ReadPixelMask,clip_mask,exception);
750 clip_mask=DestroyImage(clip_mask);
755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
759 % C l o n e I m a g e %
763 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
765 % CloneImage() copies an image and returns the copy as a new image object.
767 % If the specified columns and rows is 0, an exact copy of the image is
768 % returned, otherwise the pixel data is undefined and must be initialized
769 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
770 % failure, a NULL image is returned and exception describes the reason for the
773 % The format of the CloneImage method is:
775 % Image *CloneImage(const Image *image,const size_t columns,
776 % const size_t rows,const MagickBooleanType orphan,
777 % ExceptionInfo *exception)
779 % A description of each parameter follows:
781 % o image: the image.
783 % o columns: the number of columns in the cloned image.
785 % o rows: the number of rows in the cloned image.
787 % o detach: With a value other than 0, the cloned image is detached from
788 % its parent I/O stream.
790 % o exception: return any errors or warnings in this structure.
793 MagickExport Image *CloneImage(const Image *image,const size_t columns,
794 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
808 assert(image != (const Image *) NULL);
809 assert(image->signature == MagickCoreSignature);
810 if (image->debug != MagickFalse)
811 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
812 assert(exception != (ExceptionInfo *) NULL);
813 assert(exception->signature == MagickCoreSignature);
814 if ((image->columns == 0) || (image->rows == 0))
816 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
817 "NegativeOrZeroImageSize","`%s'",image->filename);
818 return((Image *) NULL);
820 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
821 if (clone_image == (Image *) NULL)
822 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
823 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
824 clone_image->signature=MagickCoreSignature;
825 clone_image->storage_class=image->storage_class;
826 clone_image->number_channels=image->number_channels;
827 clone_image->number_meta_channels=image->number_meta_channels;
828 clone_image->metacontent_extent=image->metacontent_extent;
829 clone_image->colorspace=image->colorspace;
830 clone_image->read_mask=image->read_mask;
831 clone_image->write_mask=image->write_mask;
832 clone_image->alpha_trait=image->alpha_trait;
833 clone_image->columns=image->columns;
834 clone_image->rows=image->rows;
835 clone_image->dither=image->dither;
836 if (image->colormap != (PixelInfo *) NULL)
839 Allocate and copy the image colormap.
841 clone_image->colors=image->colors;
842 length=(size_t) image->colors;
843 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
844 sizeof(*clone_image->colormap));
845 if (clone_image->colormap == (PixelInfo *) NULL)
847 clone_image=DestroyImage(clone_image);
848 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
850 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
851 sizeof(*clone_image->colormap));
853 clone_image->image_info=CloneImageInfo(image->image_info);
854 (void) CloneImageProfiles(clone_image,image);
855 (void) CloneImageProperties(clone_image,image);
856 (void) CloneImageArtifacts(clone_image,image);
857 GetTimerInfo(&clone_image->timer);
858 if (image->ascii85 != (void *) NULL)
859 Ascii85Initialize(clone_image);
860 clone_image->magick_columns=image->magick_columns;
861 clone_image->magick_rows=image->magick_rows;
862 clone_image->type=image->type;
863 clone_image->channel_mask=image->channel_mask;
864 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
865 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
867 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
868 (void) CopyMagickString(clone_image->filename,image->filename,
870 clone_image->progress_monitor=image->progress_monitor;
871 clone_image->client_data=image->client_data;
872 clone_image->reference_count=1;
873 clone_image->next=image->next;
874 clone_image->previous=image->previous;
875 clone_image->list=NewImageList();
876 if (detach == MagickFalse)
877 clone_image->blob=ReferenceBlob(image->blob);
880 clone_image->next=NewImageList();
881 clone_image->previous=NewImageList();
882 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
884 clone_image->ping=image->ping;
885 clone_image->debug=IsEventLogging();
886 clone_image->semaphore=AcquireSemaphoreInfo();
887 if ((columns == 0) || (rows == 0))
889 if (image->montage != (char *) NULL)
890 (void) CloneString(&clone_image->montage,image->montage);
891 if (image->directory != (char *) NULL)
892 (void) CloneString(&clone_image->directory,image->directory);
893 clone_image->cache=ReferencePixelCache(image->cache);
897 if (image->columns != 0)
898 scale=(double) columns/(double) image->columns;
899 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
900 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
901 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
903 if (image->rows != 0)
904 scale=(double) rows/(double) image->rows;
905 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
906 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
907 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
908 clone_image->columns=columns;
909 clone_image->rows=rows;
910 clone_image->cache=ClonePixelCache(image->cache);
915 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
919 % C l o n e I m a g e I n f o %
923 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
925 % CloneImageInfo() makes a copy of the given image info structure. If
926 % NULL is specified, a new image info structure is created initialized to
929 % The format of the CloneImageInfo method is:
931 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
933 % A description of each parameter follows:
935 % o image_info: the image info.
938 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
943 clone_info=AcquireImageInfo();
944 if (image_info == (ImageInfo *) NULL)
946 clone_info->compression=image_info->compression;
947 clone_info->temporary=image_info->temporary;
948 clone_info->adjoin=image_info->adjoin;
949 clone_info->antialias=image_info->antialias;
950 clone_info->scene=image_info->scene;
951 clone_info->number_scenes=image_info->number_scenes;
952 clone_info->depth=image_info->depth;
953 (void) CloneString(&clone_info->size,image_info->size);
954 (void) CloneString(&clone_info->extract,image_info->extract);
955 (void) CloneString(&clone_info->scenes,image_info->scenes);
956 (void) CloneString(&clone_info->page,image_info->page);
957 clone_info->interlace=image_info->interlace;
958 clone_info->endian=image_info->endian;
959 clone_info->units=image_info->units;
960 clone_info->quality=image_info->quality;
961 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
962 (void) CloneString(&clone_info->server_name,image_info->server_name);
963 (void) CloneString(&clone_info->font,image_info->font);
964 (void) CloneString(&clone_info->texture,image_info->texture);
965 (void) CloneString(&clone_info->density,image_info->density);
966 clone_info->pointsize=image_info->pointsize;
967 clone_info->fuzz=image_info->fuzz;
968 clone_info->alpha_color=image_info->alpha_color;
969 clone_info->background_color=image_info->background_color;
970 clone_info->border_color=image_info->border_color;
971 clone_info->transparent_color=image_info->transparent_color;
972 clone_info->dither=image_info->dither;
973 clone_info->monochrome=image_info->monochrome;
974 clone_info->colorspace=image_info->colorspace;
975 clone_info->type=image_info->type;
976 clone_info->orientation=image_info->orientation;
977 clone_info->ping=image_info->ping;
978 clone_info->verbose=image_info->verbose;
979 clone_info->progress_monitor=image_info->progress_monitor;
980 clone_info->client_data=image_info->client_data;
981 clone_info->cache=image_info->cache;
982 if (image_info->cache != (void *) NULL)
983 clone_info->cache=ReferencePixelCache(image_info->cache);
984 if (image_info->profile != (void *) NULL)
985 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
986 image_info->profile);
987 SetImageInfoFile(clone_info,image_info->file);
988 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
989 clone_info->stream=image_info->stream;
990 (void) CopyMagickString(clone_info->magick,image_info->magick,
992 (void) CopyMagickString(clone_info->unique,image_info->unique,
994 (void) CopyMagickString(clone_info->filename,image_info->filename,
996 clone_info->channel=image_info->channel;
997 (void) CloneImageOptions(clone_info,image_info);
998 clone_info->debug=IsEventLogging();
999 clone_info->signature=image_info->signature;
1004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1008 % C o p y I m a g e P i x e l s %
1012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1014 % CopyImagePixels() copies pixels from the source image as defined by the
1015 % geometry the destination image at the specified offset.
1017 % The format of the CopyImagePixels method is:
1019 % MagickBooleanType CopyImagePixels(Image *image,const Image *source_image,
1020 % const RectangleInfo *geometry,const OffsetInfo *offset,
1021 % ExceptionInfo *exception);
1023 % A description of each parameter follows:
1025 % o image: the destination image.
1027 % o source_image: the source image.
1029 % o geometry: define the dimensions of the source pixel rectangle.
1031 % o offset: define the offset in the destination image.
1033 % o exception: return any errors or warnings in this structure.
1036 MagickExport MagickBooleanType CopyImagePixels(Image *image,
1037 const Image *source_image,const RectangleInfo *geometry,
1038 const OffsetInfo *offset,ExceptionInfo *exception)
1040 #define CopyImageTag "Copy/Image"
1055 assert(image != (Image *) NULL);
1056 if (image->debug != MagickFalse)
1057 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1058 assert(source_image != (Image *) NULL);
1059 assert(geometry != (RectangleInfo *) NULL);
1060 assert(offset != (OffsetInfo *) NULL);
1061 if ((offset->x < 0) || (offset->y < 0) ||
1062 ((ssize_t) (offset->x+geometry->width) > (ssize_t) image->columns) ||
1063 ((ssize_t) (offset->y+geometry->height) > (ssize_t) image->rows))
1064 ThrowBinaryException(OptionError,"GeometryDoesNotContainImage",
1066 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1067 return(MagickFalse);
1073 source_view=AcquireVirtualCacheView(source_image,exception);
1074 image_view=AcquireAuthenticCacheView(image,exception);
1075 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1076 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1077 magick_threads(image,source_image,geometry->height,1)
1079 for (y=0; y < (ssize_t) geometry->height; y++)
1084 register const Quantum
1093 if (status == MagickFalse)
1095 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1096 geometry->width,1,exception);
1097 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1098 geometry->width,1,exception);
1099 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1104 for (x=0; x < (ssize_t) geometry->width; x++)
1109 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1111 PixelChannel channel=GetPixelChannelChannel(image,i);
1112 PixelTrait traits=GetPixelChannelTraits(image,channel);
1113 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1114 if ((traits == UndefinedPixelTrait) ||
1115 (source_traits == UndefinedPixelTrait))
1117 SetPixelChannel(image,channel,p[i],q);
1119 p+=GetPixelChannels(source_image);
1120 q+=GetPixelChannels(image);
1122 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1123 if (sync == MagickFalse)
1125 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1130 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1131 #pragma omp critical (MagickCore_CopyImage)
1133 proceed=SetImageProgress(image,CopyImageTag,progress++,image->rows);
1134 if (proceed == MagickFalse)
1138 source_view=DestroyCacheView(source_view);
1139 image_view=DestroyCacheView(image_view);
1144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1148 % D e s t r o y I m a g e %
1152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1154 % DestroyImage() dereferences an image, deallocating memory associated with
1155 % the image if the reference count becomes zero.
1157 % The format of the DestroyImage method is:
1159 % Image *DestroyImage(Image *image)
1161 % A description of each parameter follows:
1163 % o image: the image.
1166 MagickExport Image *DestroyImage(Image *image)
1174 assert(image != (Image *) NULL);
1175 assert(image->signature == MagickCoreSignature);
1176 if (image->debug != MagickFalse)
1177 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1178 destroy=MagickFalse;
1179 LockSemaphoreInfo(image->semaphore);
1180 image->reference_count--;
1181 if (image->reference_count == 0)
1183 UnlockSemaphoreInfo(image->semaphore);
1184 if (destroy == MagickFalse)
1185 return((Image *) NULL);
1189 DestroyImagePixels(image);
1190 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1191 if (image->montage != (char *) NULL)
1192 image->montage=DestroyString(image->montage);
1193 if (image->directory != (char *) NULL)
1194 image->directory=DestroyString(image->directory);
1195 if (image->colormap != (PixelInfo *) NULL)
1196 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1197 if (image->geometry != (char *) NULL)
1198 image->geometry=DestroyString(image->geometry);
1199 DestroyImageProfiles(image);
1200 DestroyImageProperties(image);
1201 DestroyImageArtifacts(image);
1202 if (image->ascii85 != (Ascii85Info *) NULL)
1203 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1204 if (image->image_info != (ImageInfo *) NULL)
1205 image->image_info=DestroyImageInfo(image->image_info);
1207 if (image->semaphore != (SemaphoreInfo *) NULL)
1208 RelinquishSemaphoreInfo(&image->semaphore);
1209 image->signature=(~MagickCoreSignature);
1210 image=(Image *) RelinquishMagickMemory(image);
1215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1219 % D e s t r o y I m a g e I n f o %
1223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1225 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1228 % The format of the DestroyImageInfo method is:
1230 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1232 % A description of each parameter follows:
1234 % o image_info: the image info.
1237 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1239 assert(image_info != (ImageInfo *) NULL);
1240 assert(image_info->signature == MagickCoreSignature);
1241 if (image_info->debug != MagickFalse)
1242 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1243 image_info->filename);
1244 if (image_info->size != (char *) NULL)
1245 image_info->size=DestroyString(image_info->size);
1246 if (image_info->extract != (char *) NULL)
1247 image_info->extract=DestroyString(image_info->extract);
1248 if (image_info->scenes != (char *) NULL)
1249 image_info->scenes=DestroyString(image_info->scenes);
1250 if (image_info->page != (char *) NULL)
1251 image_info->page=DestroyString(image_info->page);
1252 if (image_info->sampling_factor != (char *) NULL)
1253 image_info->sampling_factor=DestroyString(
1254 image_info->sampling_factor);
1255 if (image_info->server_name != (char *) NULL)
1256 image_info->server_name=DestroyString(
1257 image_info->server_name);
1258 if (image_info->font != (char *) NULL)
1259 image_info->font=DestroyString(image_info->font);
1260 if (image_info->texture != (char *) NULL)
1261 image_info->texture=DestroyString(image_info->texture);
1262 if (image_info->density != (char *) NULL)
1263 image_info->density=DestroyString(image_info->density);
1264 if (image_info->cache != (void *) NULL)
1265 image_info->cache=DestroyPixelCache(image_info->cache);
1266 if (image_info->profile != (StringInfo *) NULL)
1267 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1268 image_info->profile);
1269 DestroyImageOptions(image_info);
1270 image_info->signature=(~MagickCoreSignature);
1271 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1280 + D i s a s s o c i a t e I m a g e S t r e a m %
1284 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1286 % DisassociateImageStream() disassociates the image stream. It checks if the
1287 % blob of the specified image is referenced by other images. If the reference
1288 % count is higher then 1 a new blob is assigned to the specified image.
1290 % The format of the DisassociateImageStream method is:
1292 % void DisassociateImageStream(const Image *image)
1294 % A description of each parameter follows:
1296 % o image: the image.
1299 MagickExport void DisassociateImageStream(Image *image)
1301 assert(image != (Image *) NULL);
1302 assert(image->signature == MagickCoreSignature);
1303 if (image->debug != MagickFalse)
1304 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1305 DisassociateBlob(image);
1309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1313 % G e t I m a g e I n f o %
1317 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1319 % GetImageInfo() initializes image_info to default values.
1321 % The format of the GetImageInfo method is:
1323 % void GetImageInfo(ImageInfo *image_info)
1325 % A description of each parameter follows:
1327 % o image_info: the image info.
1330 MagickExport void GetImageInfo(ImageInfo *image_info)
1339 File and image dimension members.
1341 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1342 assert(image_info != (ImageInfo *) NULL);
1343 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1344 image_info->adjoin=MagickTrue;
1345 image_info->interlace=NoInterlace;
1346 image_info->channel=DefaultChannels;
1347 image_info->quality=UndefinedCompressionQuality;
1348 image_info->antialias=MagickTrue;
1349 image_info->dither=MagickTrue;
1350 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1351 if (synchronize != (const char *) NULL)
1353 image_info->synchronize=IsStringTrue(synchronize);
1354 synchronize=DestroyString(synchronize);
1356 exception=AcquireExceptionInfo();
1357 (void) QueryColorCompliance(AlphaColor,AllCompliance,&image_info->alpha_color,
1359 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1360 &image_info->background_color,exception);
1361 (void) QueryColorCompliance(BorderColor,AllCompliance,
1362 &image_info->border_color,exception);
1363 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1364 &image_info->transparent_color,exception);
1365 exception=DestroyExceptionInfo(exception);
1366 image_info->debug=IsEventLogging();
1367 image_info->signature=MagickCoreSignature;
1371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1375 % G e t I m a g e I n f o F i l e %
1379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1381 % GetImageInfoFile() returns the image info file member.
1383 % The format of the GetImageInfoFile method is:
1385 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1387 % A description of each parameter follows:
1389 % o image_info: the image info.
1392 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1394 return(image_info->file);
1398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1402 % G e t I m a g e M a s k %
1406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1408 % GetImageMask() returns the mask associated with the image.
1410 % The format of the GetImageMask method is:
1412 % Image *GetImageMask(const Image *image,const PixelMask type,
1413 % ExceptionInfo *exception)
1415 % A description of each parameter follows:
1417 % o image: the image.
1419 % o type: the mask type, ReadPixelMask or WritePixelMask.
1422 MagickExport Image *GetImageMask(const Image *image,const PixelMask type,
1423 ExceptionInfo *exception)
1441 assert(image != (Image *) NULL);
1442 if (image->debug != MagickFalse)
1443 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1444 assert(image->signature == MagickCoreSignature);
1445 mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1446 if (mask_image == (Image *) NULL)
1447 return((Image *) NULL);
1449 mask_image->alpha_trait=UndefinedPixelTrait;
1450 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1451 mask_image->read_mask=MagickFalse;
1452 image_view=AcquireVirtualCacheView(image,exception);
1453 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1454 for (y=0; y < (ssize_t) image->rows; y++)
1456 register const Quantum
1465 if (status == MagickFalse)
1467 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1468 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1470 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1475 for (x=0; x < (ssize_t) image->columns; x++)
1479 case WritePixelMask:
1481 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1486 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1490 p+=GetPixelChannels(image);
1491 q+=GetPixelChannels(mask_image);
1493 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1496 mask_view=DestroyCacheView(mask_view);
1497 image_view=DestroyCacheView(image_view);
1498 if (status == MagickFalse)
1499 mask_image=DestroyImage(mask_image);
1504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1508 + G e t I m a g e R e f e r e n c e C o u n t %
1512 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1514 % GetImageReferenceCount() returns the image reference count.
1516 % The format of the GetReferenceCount method is:
1518 % ssize_t GetImageReferenceCount(Image *image)
1520 % A description of each parameter follows:
1522 % o image: the image.
1525 MagickExport ssize_t GetImageReferenceCount(Image *image)
1530 assert(image != (Image *) NULL);
1531 assert(image->signature == MagickCoreSignature);
1532 if (image->debug != MagickFalse)
1533 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1534 LockSemaphoreInfo(image->semaphore);
1535 reference_count=image->reference_count;
1536 UnlockSemaphoreInfo(image->semaphore);
1537 return(reference_count);
1541 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1545 % 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 %
1549 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1551 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1552 % image. A virtual pixel is any pixel access that is outside the boundaries
1553 % of the image cache.
1555 % The format of the GetImageVirtualPixelMethod() method is:
1557 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1559 % A description of each parameter follows:
1561 % o image: the image.
1564 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1566 assert(image != (Image *) NULL);
1567 assert(image->signature == MagickCoreSignature);
1568 if (image->debug != MagickFalse)
1569 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1570 return(GetPixelCacheVirtualMethod(image));
1574 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1578 % I n t e r p r e t I m a g e F i l e n a m e %
1582 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1584 % InterpretImageFilename() interprets embedded characters in an image filename.
1585 % The filename length is returned.
1587 % The format of the InterpretImageFilename method is:
1589 % size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1590 % const char *format,int value,char *filename,ExceptionInfo *exception)
1592 % A description of each parameter follows.
1594 % o image_info: the image info..
1596 % o image: the image.
1598 % o format: A filename describing the format to use to write the numeric
1599 % argument. Only the first numeric format identifier is replaced.
1601 % o value: Numeric value to substitute into format filename.
1603 % o filename: return the formatted filename in this character buffer.
1605 % o exception: return any errors or warnings in this structure.
1608 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1609 Image *image,const char *format,int value,char *filename,
1610 ExceptionInfo *exception)
1627 canonical=MagickFalse;
1629 (void) CopyMagickString(filename,format,MagickPathExtent);
1630 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1643 foo=(ssize_t) strtol(q,&q,10);
1655 (void) FormatLocaleString(filename+(p-format),(size_t)
1656 (MagickPathExtent-(p-format)),p,value);
1658 (void) ConcatenateMagickString(filename,q,MagickPathExtent);
1659 canonical=MagickTrue;
1668 pattern[MagickPathExtent];
1685 /* FUTURE: Compare update with code from InterpretImageProperties()
1686 Note that a 'filename:' property should not need depth recursion.
1688 if (strchr(p,']') == (char *) NULL)
1692 for (i=0; (i < (MagickPathExtent-1L)) && (*r != '\0'); i++)
1703 if (LocaleNCompare(pattern,"filename:",9) != 0)
1705 option=(const char *) NULL;
1706 if (image != (Image *) NULL)
1707 option=GetImageProperty(image,pattern,exception);
1708 if ((option == (const char *) NULL) && (image != (Image *) NULL))
1709 option=GetImageArtifact(image,pattern);
1710 if ((option == (const char *) NULL) &&
1711 (image_info != (ImageInfo *) NULL))
1712 option=GetImageOption(image_info,pattern);
1713 if (option == (const char *) NULL)
1718 (void) CopyMagickString(filename+(p-format-length),option,(size_t)
1719 (MagickPathExtent-(p-format-length)));
1720 length+=strlen(pattern)-1;
1722 (void) ConcatenateMagickString(filename,r+1,MagickPathExtent);
1723 canonical=MagickTrue;
1733 for (q=filename; *q != '\0'; q++)
1734 if ((*q == '%') && (*(q+1) == '%'))
1736 (void) CopyMagickString(q,q+1,(size_t) (MagickPathExtent-(q-filename)));
1737 canonical=MagickTrue;
1739 if (canonical == MagickFalse)
1740 (void) CopyMagickString(filename,format,MagickPathExtent);
1741 return(strlen(filename));
1745 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1749 % I s H i g h D y n a m i c R a n g e I m a g e %
1753 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1755 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1756 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1759 % The format of the IsHighDynamicRangeImage method is:
1761 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1762 % ExceptionInfo *exception)
1764 % A description of each parameter follows:
1766 % o image: the image.
1768 % o exception: return any errors or warnings in this structure.
1771 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1772 ExceptionInfo *exception)
1774 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1777 return(MagickFalse);
1788 assert(image != (Image *) NULL);
1789 assert(image->signature == MagickCoreSignature);
1790 if (image->debug != MagickFalse)
1791 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1793 image_view=AcquireVirtualCacheView(image,exception);
1794 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1795 #pragma omp parallel for schedule(static,4) shared(status) \
1796 magick_threads(image,image,image->rows,1)
1798 for (y=0; y < (ssize_t) image->rows; y++)
1800 register const Quantum
1806 if (status == MagickFalse)
1808 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1809 if (p == (const Quantum *) NULL)
1814 for (x=0; x < (ssize_t) image->columns; x++)
1819 if (GetPixelReadMask(image,p) == 0)
1821 p+=GetPixelChannels(image);
1824 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1832 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1833 if (traits == UndefinedPixelTrait)
1835 pixel=(double) p[i];
1836 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1837 (pixel != (double) ((QuantumAny) pixel)))
1840 p+=GetPixelChannels(image);
1841 if (i < (ssize_t) GetPixelChannels(image))
1844 if (x < (ssize_t) image->columns)
1847 image_view=DestroyCacheView(image_view);
1848 return(status != MagickFalse ? MagickFalse : MagickTrue);
1853 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1857 % I s I m a g e O b j e c t %
1861 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1863 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1864 % set of image objects.
1866 % The format of the IsImageObject method is:
1868 % MagickBooleanType IsImageObject(const Image *image)
1870 % A description of each parameter follows:
1872 % o image: the image.
1875 MagickExport MagickBooleanType IsImageObject(const Image *image)
1877 register const Image
1880 assert(image != (Image *) NULL);
1881 if (image->debug != MagickFalse)
1882 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1883 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1884 if (p->signature != MagickCoreSignature)
1885 return(MagickFalse);
1890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1894 % I s T a i n t I m a g e %
1898 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1900 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1901 % since it was first constituted.
1903 % The format of the IsTaintImage method is:
1905 % MagickBooleanType IsTaintImage(const Image *image)
1907 % A description of each parameter follows:
1909 % o image: the image.
1912 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1915 magick[MagickPathExtent],
1916 filename[MagickPathExtent];
1918 register const Image
1921 assert(image != (Image *) NULL);
1922 if (image->debug != MagickFalse)
1923 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1924 assert(image->signature == MagickCoreSignature);
1925 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1926 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1927 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1929 if (p->taint != MagickFalse)
1931 if (LocaleCompare(p->magick,magick) != 0)
1933 if (LocaleCompare(p->filename,filename) != 0)
1936 return(MagickFalse);
1940 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1944 % M o d i f y I m a g e %
1948 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1950 % ModifyImage() ensures that there is only a single reference to the image
1951 % to be modified, updating the provided image pointer to point to a clone of
1952 % the original image if necessary.
1954 % The format of the ModifyImage method is:
1956 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1958 % A description of each parameter follows:
1960 % o image: the image.
1962 % o exception: return any errors or warnings in this structure.
1965 MagickExport MagickBooleanType ModifyImage(Image **image,
1966 ExceptionInfo *exception)
1971 assert(image != (Image **) NULL);
1972 assert(*image != (Image *) NULL);
1973 assert((*image)->signature == MagickCoreSignature);
1974 if ((*image)->debug != MagickFalse)
1975 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1976 if (GetImageReferenceCount(*image) <= 1)
1978 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1979 LockSemaphoreInfo((*image)->semaphore);
1980 (*image)->reference_count--;
1981 UnlockSemaphoreInfo((*image)->semaphore);
1987 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1991 % N e w M a g i c k I m a g e %
1995 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1997 % NewMagickImage() creates a blank image canvas of the specified size and
2000 % The format of the NewMagickImage method is:
2002 % Image *NewMagickImage(const ImageInfo *image_info,const size_t width,
2003 % const size_t height,const PixelInfo *background,
2004 % ExceptionInfo *exception)
2006 % A description of each parameter follows:
2008 % o image: the image.
2010 % o width: the image width.
2012 % o height: the image height.
2014 % o background: the image color.
2016 % o exception: return any errors or warnings in this structure.
2019 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2020 const size_t width,const size_t height,const PixelInfo *background,
2021 ExceptionInfo *exception)
2035 assert(image_info != (const ImageInfo *) NULL);
2036 if (image_info->debug != MagickFalse)
2037 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2038 assert(image_info->signature == MagickCoreSignature);
2039 assert(background != (const PixelInfo *) NULL);
2040 image=AcquireImage(image_info,exception);
2041 image->columns=width;
2043 image->colorspace=background->colorspace;
2044 image->alpha_trait=background->alpha_trait;
2045 image->fuzz=background->fuzz;
2046 image->depth=background->depth;
2048 image_view=AcquireAuthenticCacheView(image,exception);
2049 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2050 #pragma omp parallel for schedule(static,4) shared(status) \
2051 magick_threads(image,image,image->rows,1)
2053 for (y=0; y < (ssize_t) image->rows; y++)
2061 if (status == MagickFalse)
2063 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2064 if (q == (Quantum *) NULL)
2069 for (x=0; x < (ssize_t) image->columns; x++)
2071 SetPixelViaPixelInfo(image,background,q);
2072 q+=GetPixelChannels(image);
2074 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2077 image_view=DestroyCacheView(image_view);
2078 if (status == MagickFalse)
2079 image=DestroyImage(image);
2084 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2088 % R e f e r e n c e I m a g e %
2092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2094 % ReferenceImage() increments the reference count associated with an image
2095 % returning a pointer to the image.
2097 % The format of the ReferenceImage method is:
2099 % Image *ReferenceImage(Image *image)
2101 % A description of each parameter follows:
2103 % o image: the image.
2106 MagickExport Image *ReferenceImage(Image *image)
2108 assert(image != (Image *) NULL);
2109 if (image->debug != MagickFalse)
2110 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2111 assert(image->signature == MagickCoreSignature);
2112 LockSemaphoreInfo(image->semaphore);
2113 image->reference_count++;
2114 UnlockSemaphoreInfo(image->semaphore);
2119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2123 % R e s e t I m a g e P a g e %
2127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2129 % ResetImagePage() resets the image page canvas and position.
2131 % The format of the ResetImagePage method is:
2133 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2135 % A description of each parameter follows:
2137 % o image: the image.
2139 % o page: the relative page specification.
2142 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2150 assert(image != (Image *) NULL);
2151 assert(image->signature == MagickCoreSignature);
2152 if (image->debug != MagickFalse)
2153 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2154 flags=ParseAbsoluteGeometry(page,&geometry);
2155 if ((flags & WidthValue) != 0)
2157 if ((flags & HeightValue) == 0)
2158 geometry.height=geometry.width;
2159 image->page.width=geometry.width;
2160 image->page.height=geometry.height;
2162 if ((flags & AspectValue) != 0)
2164 if ((flags & XValue) != 0)
2165 image->page.x+=geometry.x;
2166 if ((flags & YValue) != 0)
2167 image->page.y+=geometry.y;
2171 if ((flags & XValue) != 0)
2173 image->page.x=geometry.x;
2174 if ((image->page.width == 0) && (geometry.x > 0))
2175 image->page.width=image->columns+geometry.x;
2177 if ((flags & YValue) != 0)
2179 image->page.y=geometry.y;
2180 if ((image->page.height == 0) && (geometry.y > 0))
2181 image->page.height=image->rows+geometry.y;
2188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2192 % S e t I m a g e B a c k g r o u n d C o l o r %
2196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2198 % SetImageBackgroundColor() initializes the image pixels to the image
2199 % background color. The background color is defined by the background_color
2200 % member of the image structure.
2202 % The format of the SetImage method is:
2204 % MagickBooleanType SetImageBackgroundColor(Image *image,
2205 % ExceptionInfo *exception)
2207 % A description of each parameter follows:
2209 % o image: the image.
2211 % o exception: return any errors or warnings in this structure.
2214 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2215 ExceptionInfo *exception)
2229 assert(image != (Image *) NULL);
2230 if (image->debug != MagickFalse)
2231 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2232 assert(image->signature == MagickCoreSignature);
2233 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2234 return(MagickFalse);
2235 ConformPixelInfo(image,&image->background_color,&background,exception);
2237 Set image background color.
2240 image_view=AcquireAuthenticCacheView(image,exception);
2241 for (y=0; y < (ssize_t) image->rows; y++)
2249 if (status == MagickFalse)
2251 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2252 if (q == (Quantum *) NULL)
2257 for (x=0; x < (ssize_t) image->columns; x++)
2259 SetPixelViaPixelInfo(image,&background,q);
2260 q+=GetPixelChannels(image);
2262 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2265 image_view=DestroyCacheView(image_view);
2270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2274 % S e t I m a g e C h a n n e l M a s k %
2278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2280 % SetImageChannelMask() sets the image channel mask from the specified channel
2283 % The format of the SetImageChannelMask method is:
2285 % ChannelType SetImageChannelMask(Image *image,
2286 % const ChannelType channel_mask)
2288 % A description of each parameter follows:
2290 % o image: the image.
2292 % o channel_mask: the channel mask.
2295 MagickExport ChannelType SetImageChannelMask(Image *image,
2296 const ChannelType channel_mask)
2298 return(SetPixelChannelMask(image,channel_mask));
2302 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2306 % S e t I m a g e C o l o r %
2310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2312 % SetImageColor() set the entire image canvas to the specified color.
2314 % The format of the SetImageColor method is:
2316 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2317 % ExeptionInfo *exception)
2319 % A description of each parameter follows:
2321 % o image: the image.
2323 % o background: the image color.
2325 % o exception: return any errors or warnings in this structure.
2328 MagickExport MagickBooleanType SetImageColor(Image *image,
2329 const PixelInfo *color,ExceptionInfo *exception)
2340 assert(image != (Image *) NULL);
2341 if (image->debug != MagickFalse)
2342 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2343 assert(image->signature == MagickCoreSignature);
2344 assert(color != (const PixelInfo *) NULL);
2345 image->colorspace=color->colorspace;
2346 image->alpha_trait=color->alpha_trait;
2347 image->fuzz=color->fuzz;
2348 image->depth=color->depth;
2350 image_view=AcquireAuthenticCacheView(image,exception);
2351 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2352 #pragma omp parallel for schedule(static,4) shared(status) \
2353 magick_threads(image,image,image->rows,1)
2355 for (y=0; y < (ssize_t) image->rows; y++)
2363 if (status == MagickFalse)
2365 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2366 if (q == (Quantum *) NULL)
2371 for (x=0; x < (ssize_t) image->columns; x++)
2373 SetPixelViaPixelInfo(image,color,q);
2374 q+=GetPixelChannels(image);
2376 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2379 image_view=DestroyCacheView(image_view);
2384 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2388 % S e t I m a g e S t o r a g e C l a s s %
2392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2394 % SetImageStorageClass() sets the image class: DirectClass for true color
2395 % images or PseudoClass for colormapped images.
2397 % The format of the SetImageStorageClass method is:
2399 % MagickBooleanType SetImageStorageClass(Image *image,
2400 % const ClassType storage_class,ExceptionInfo *exception)
2402 % A description of each parameter follows:
2404 % o image: the image.
2406 % o storage_class: The image class.
2408 % o exception: return any errors or warnings in this structure.
2411 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2412 const ClassType storage_class,ExceptionInfo *exception)
2414 image->storage_class=storage_class;
2415 return(SyncImagePixelCache(image,exception));
2419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2423 % S e t I m a g e E x t e n t %
2427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2429 % SetImageExtent() sets the image size (i.e. columns & rows).
2431 % The format of the SetImageExtent method is:
2433 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2434 % const size_t rows,ExceptionInfo *exception)
2436 % A description of each parameter follows:
2438 % o image: the image.
2440 % o columns: The image width in pixels.
2442 % o rows: The image height in pixels.
2444 % o exception: return any errors or warnings in this structure.
2447 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2448 const size_t rows,ExceptionInfo *exception)
2450 if ((columns == 0) || (rows == 0))
2451 return(MagickFalse);
2452 image->columns=columns;
2454 if (image->depth > (8*sizeof(MagickSizeType)))
2455 ThrowBinaryException(ImageError,"ImageDepthNotSupported",image->filename);
2456 return(SyncImagePixelCache(image,exception));
2460 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2464 + S e t I m a g e I n f o %
2468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2470 % SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
2471 % It is set to a type of image format based on the prefix or suffix of the
2472 % filename. For example, 'ps:image' returns PS indicating a Postscript image.
2473 % JPEG is returned for this filename: 'image.jpg'. The filename prefix has
2474 % precendence over the suffix. Use an optional index enclosed in brackets
2475 % after a file name to specify a desired scene of a multi-resolution image
2476 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2477 % indicates success.
2479 % The format of the SetImageInfo method is:
2481 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2482 % const unsigned int frames,ExceptionInfo *exception)
2484 % A description of each parameter follows:
2486 % o image_info: the image info.
2488 % o frames: the number of images you intend to write.
2490 % o exception: return any errors or warnings in this structure.
2493 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2494 const unsigned int frames,ExceptionInfo *exception)
2497 component[MagickPathExtent],
2498 magic[MagickPathExtent],
2523 Look for 'image.format' in filename.
2525 assert(image_info != (ImageInfo *) NULL);
2526 assert(image_info->signature == MagickCoreSignature);
2527 if (image_info->debug != MagickFalse)
2528 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2529 image_info->filename);
2531 GetPathComponent(image_info->filename,SubimagePath,component);
2532 if (*component != '\0')
2535 Look for scene specification (e.g. img0001.pcd[4]).
2537 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2539 if (IsGeometry(component) != MagickFalse)
2540 (void) CloneString(&image_info->extract,component);
2548 (void) CloneString(&image_info->scenes,component);
2549 image_info->scene=StringToUnsignedLong(image_info->scenes);
2550 image_info->number_scenes=image_info->scene;
2551 p=image_info->scenes;
2552 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2554 while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2556 first=(size_t) strtol(p,&q,10);
2558 while (isspace((int) ((unsigned char) *q)) != 0)
2561 last=(size_t) strtol(q+1,&q,10);
2564 if (first < image_info->scene)
2565 image_info->scene=first;
2566 if (last > image_info->number_scenes)
2567 image_info->number_scenes=last;
2570 image_info->number_scenes-=image_info->scene-1;
2574 if (*image_info->magick == '\0')
2575 GetPathComponent(image_info->filename,ExtensionPath,component);
2576 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2577 if (*component != '\0')
2578 if ((LocaleCompare(component,"gz") == 0) ||
2579 (LocaleCompare(component,"Z") == 0) ||
2580 (LocaleCompare(component,"svgz") == 0) ||
2581 (LocaleCompare(component,"wmz") == 0))
2584 path[MagickPathExtent];
2586 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2587 path[strlen(path)-strlen(component)-1]='\0';
2588 GetPathComponent(path,ExtensionPath,component);
2591 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2592 if (*component != '\0')
2593 if (LocaleCompare(component,"bz2") == 0)
2596 path[MagickPathExtent];
2598 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2599 path[strlen(path)-strlen(component)-1]='\0';
2600 GetPathComponent(path,ExtensionPath,component);
2603 image_info->affirm=MagickFalse;
2604 sans_exception=AcquireExceptionInfo();
2605 if (*component != '\0')
2614 *format_type_formats[] =
2636 User specified image format.
2638 (void) CopyMagickString(magic,component,MagickPathExtent);
2641 Look for explicit image formats.
2643 format_type=UndefinedFormatType;
2644 magick_info=GetMagickInfo(magic,sans_exception);
2645 if ((magick_info != (const MagickInfo *) NULL) &&
2646 (magick_info->format_type != UndefinedFormatType))
2647 format_type=magick_info->format_type;
2649 while ((format_type == UndefinedFormatType) &&
2650 (format_type_formats[i] != (char *) NULL))
2652 if ((*magic == *format_type_formats[i]) &&
2653 (LocaleCompare(magic,format_type_formats[i]) == 0))
2654 format_type=ExplicitFormatType;
2657 if (format_type == UndefinedFormatType)
2658 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2660 if (format_type == ExplicitFormatType)
2662 image_info->affirm=MagickTrue;
2663 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2665 if (LocaleCompare(magic,"RGB") == 0)
2666 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2669 Look for explicit 'format:image' in filename.
2672 GetPathComponent(image_info->filename,MagickPath,magic);
2674 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2678 User specified image format.
2681 if (IsMagickConflict(magic) == MagickFalse)
2683 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2684 image_info->affirm=MagickTrue;
2687 magick_info=GetMagickInfo(magic,sans_exception);
2688 sans_exception=DestroyExceptionInfo(sans_exception);
2689 if ((magick_info == (const MagickInfo *) NULL) ||
2690 (GetMagickEndianSupport(magick_info) == MagickFalse))
2691 image_info->endian=UndefinedEndian;
2692 GetPathComponent(image_info->filename,CanonicalPath,component);
2693 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2694 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2697 Test for multiple image support (e.g. image%02d.png).
2699 (void) InterpretImageFilename(image_info,(Image *) NULL,
2700 image_info->filename,(int) image_info->scene,component,exception);
2701 if ((LocaleCompare(component,image_info->filename) != 0) &&
2702 (strchr(component,'%') == (char *) NULL))
2703 image_info->adjoin=MagickFalse;
2705 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2708 Some image formats do not support multiple frames per file.
2710 magick_info=GetMagickInfo(magic,exception);
2711 if (magick_info != (const MagickInfo *) NULL)
2712 if (GetMagickAdjoin(magick_info) == MagickFalse)
2713 image_info->adjoin=MagickFalse;
2715 if (image_info->affirm != MagickFalse)
2726 Determine the image format from the first few bytes of the file.
2728 magick_size=GetMagicPatternExtent(exception);
2729 if (magick_size == 0)
2730 return(MagickFalse);
2731 image=AcquireImage(image_info,exception);
2732 (void) CopyMagickString(image->filename,image_info->filename,
2734 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2735 if (status == MagickFalse)
2737 image=DestroyImage(image);
2738 return(MagickFalse);
2740 if ((IsBlobSeekable(image) == MagickFalse) ||
2741 (IsBlobExempt(image) != MagickFalse))
2744 Copy standard input or pipe to temporary file.
2747 status=ImageToFile(image,component,exception);
2748 (void) CloseBlob(image);
2749 if (status == MagickFalse)
2751 image=DestroyImage(image);
2752 return(MagickFalse);
2754 SetImageInfoFile(image_info,(FILE *) NULL);
2755 (void) CopyMagickString(image->filename,component,MagickPathExtent);
2756 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2757 if (status == MagickFalse)
2759 image=DestroyImage(image);
2760 return(MagickFalse);
2762 (void) CopyMagickString(image_info->filename,component,
2764 image_info->temporary=MagickTrue;
2766 magick=(unsigned char *) AcquireMagickMemory(magick_size);
2767 if (magick == (unsigned char *) NULL)
2769 (void) CloseBlob(image);
2770 image=DestroyImage(image);
2771 return(MagickFalse);
2773 (void) ResetMagickMemory(magick,0,magick_size);
2774 count=ReadBlob(image,magick_size,magick);
2775 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
2776 (void) CloseBlob(image);
2777 image=DestroyImage(image);
2779 Check magic.xml configuration file.
2781 sans_exception=AcquireExceptionInfo();
2782 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
2783 magick=(unsigned char *) RelinquishMagickMemory(magick);
2784 if ((magic_info != (const MagicInfo *) NULL) &&
2785 (GetMagicName(magic_info) != (char *) NULL))
2788 Try to use magick_info that was determined earlier by the extension
2790 if ((magick_info != (const MagickInfo *) NULL) &&
2791 (GetMagickUseExtension(magick_info) != MagickFalse) &&
2792 (LocaleCompare(magick_info->module,GetMagicName(
2794 (void) CopyMagickString(image_info->magick,magick_info->name,
2798 (void) CopyMagickString(image_info->magick,GetMagicName(
2799 magic_info),MagickPathExtent);
2800 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2802 if ((magick_info == (const MagickInfo *) NULL) ||
2803 (GetMagickEndianSupport(magick_info) == MagickFalse))
2804 image_info->endian=UndefinedEndian;
2805 sans_exception=DestroyExceptionInfo(sans_exception);
2808 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2809 if ((magick_info == (const MagickInfo *) NULL) ||
2810 (GetMagickEndianSupport(magick_info) == MagickFalse))
2811 image_info->endian=UndefinedEndian;
2812 sans_exception=DestroyExceptionInfo(sans_exception);
2818 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2822 % S e t I m a g e I n f o B l o b %
2826 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2828 % SetImageInfoBlob() sets the image info blob member.
2830 % The format of the SetImageInfoBlob method is:
2832 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2833 % const size_t length)
2835 % A description of each parameter follows:
2837 % o image_info: the image info.
2841 % o length: the blob length.
2844 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2845 const size_t length)
2847 assert(image_info != (ImageInfo *) NULL);
2848 assert(image_info->signature == MagickCoreSignature);
2849 if (image_info->debug != MagickFalse)
2850 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2851 image_info->filename);
2852 image_info->blob=(void *) blob;
2853 image_info->length=length;
2857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2861 % S e t I m a g e I n f o F i l e %
2865 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2867 % SetImageInfoFile() sets the image info file member.
2869 % The format of the SetImageInfoFile method is:
2871 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2873 % A description of each parameter follows:
2875 % o image_info: the image info.
2880 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2882 assert(image_info != (ImageInfo *) NULL);
2883 assert(image_info->signature == MagickCoreSignature);
2884 if (image_info->debug != MagickFalse)
2885 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2886 image_info->filename);
2887 image_info->file=file;
2891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2895 % S e t I m a g e M a s k %
2899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2901 % SetImageMask() associates a mask with the image. The mask must be the same
2902 % dimensions as the image.
2904 % The format of the SetImageMask method is:
2906 % MagickBooleanType SetImageMask(Image *image,const PixelMask type,
2907 % const Image *mask,ExceptionInfo *exception)
2909 % A description of each parameter follows:
2911 % o image: the image.
2913 % o type: the mask type, ReadPixelMask or WritePixelMask.
2915 % o mask: the image mask.
2917 % o exception: return any errors or warnings in this structure.
2920 MagickExport MagickBooleanType SetImageMask(Image *image,const PixelMask type,
2921 const Image *mask,ExceptionInfo *exception)
2936 assert(image != (Image *) NULL);
2937 if (image->debug != MagickFalse)
2938 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2939 assert(image->signature == MagickCoreSignature);
2940 if (mask == (const Image *) NULL)
2944 case WritePixelMask: image->write_mask=MagickFalse; break;
2945 default: image->read_mask=MagickFalse; break;
2947 return(SyncImagePixelCache(image,exception));
2951 case WritePixelMask: image->write_mask=MagickTrue; break;
2952 default: image->read_mask=MagickTrue; break;
2954 if (SyncImagePixelCache(image,exception) == MagickFalse)
2955 return(MagickFalse);
2957 mask_view=AcquireVirtualCacheView(mask,exception);
2958 image_view=AcquireAuthenticCacheView(image,exception);
2959 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2960 #pragma omp parallel for schedule(static,4) shared(status) \
2961 magick_threads(mask,image,1,1)
2963 for (y=0; y < (ssize_t) image->rows; y++)
2965 register const Quantum
2974 if (status == MagickFalse)
2976 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
2977 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2978 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2983 for (x=0; x < (ssize_t) image->columns; x++)
2988 intensity=GetPixelIntensity(mask,p);
2991 case WritePixelMask:
2993 SetPixelWriteMask(image,ClampToQuantum(QuantumRange-intensity),q);
2998 SetPixelReadMask(image,ClampToQuantum(QuantumRange-intensity),q);
3002 p+=GetPixelChannels(mask);
3003 q+=GetPixelChannels(image);
3005 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3008 mask_view=DestroyCacheView(mask_view);
3009 image_view=DestroyCacheView(image_view);
3014 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3018 % S e t I m a g e A l p h a %
3022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3024 % SetImageAlpha() sets the alpha levels of the image.
3026 % The format of the SetImageAlpha method is:
3028 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3029 % ExceptionInfo *exception)
3031 % A description of each parameter follows:
3033 % o image: the image.
3035 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3036 % fully transparent.
3039 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3040 ExceptionInfo *exception)
3051 assert(image != (Image *) NULL);
3052 if (image->debug != MagickFalse)
3053 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3054 assert(image->signature == MagickCoreSignature);
3055 image->alpha_trait=BlendPixelTrait;
3057 image_view=AcquireAuthenticCacheView(image,exception);
3058 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3059 #pragma omp parallel for schedule(static,4) shared(status) \
3060 magick_threads(image,image,image->rows,1)
3062 for (y=0; y < (ssize_t) image->rows; y++)
3070 if (status == MagickFalse)
3072 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3073 if (q == (Quantum *) NULL)
3078 for (x=0; x < (ssize_t) image->columns; x++)
3080 if (GetPixelReadMask(image,q) != 0)
3081 SetPixelAlpha(image,alpha,q);
3082 q+=GetPixelChannels(image);
3084 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3087 image_view=DestroyCacheView(image_view);
3092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3096 % 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 %
3100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3102 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3103 % image and returns the previous setting. A virtual pixel is any pixel access
3104 % that is outside the boundaries of the image cache.
3106 % The format of the SetImageVirtualPixelMethod() method is:
3108 % VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3109 % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3111 % A description of each parameter follows:
3113 % o image: the image.
3115 % o virtual_pixel_method: choose the type of virtual pixel.
3117 % o exception: return any errors or warnings in this structure.
3120 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3121 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3123 assert(image != (const Image *) NULL);
3124 assert(image->signature == MagickCoreSignature);
3125 if (image->debug != MagickFalse)
3126 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3127 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3135 % S m u s h I m a g e s %
3139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3141 % SmushImages() takes all images from the current image pointer to the end
3142 % of the image list and smushes them to each other top-to-bottom if the
3143 % stack parameter is true, otherwise left-to-right.
3145 % The current gravity setting now effects how the image is justified in the
3148 % The format of the SmushImages method is:
3150 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3151 % ExceptionInfo *exception)
3153 % A description of each parameter follows:
3155 % o images: the image sequence.
3157 % o stack: A value other than 0 stacks the images top-to-bottom.
3159 % o offset: minimum distance in pixels between images.
3161 % o exception: return any errors or warnings in this structure.
3165 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3166 const ssize_t offset,ExceptionInfo *exception)
3180 register const Quantum
3193 if (images->previous == (Image *) NULL)
3196 SetGeometry(smush_image,&right_geometry);
3197 GravityAdjustGeometry(right_image->columns,right_image->rows,
3198 right_image->gravity,&right_geometry);
3199 left_image=images->previous;
3200 SetGeometry(smush_image,&left_geometry);
3201 GravityAdjustGeometry(left_image->columns,left_image->rows,
3202 left_image->gravity,&left_geometry);
3203 gap=right_image->columns;
3204 left_view=AcquireVirtualCacheView(left_image,exception);
3205 right_view=AcquireVirtualCacheView(right_image,exception);
3206 for (y=0; y < (ssize_t) smush_image->rows; y++)
3208 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3210 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3211 if ((p == (const Quantum *) NULL) ||
3212 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3213 ((left_image->columns-x-1) >= gap))
3216 i=(ssize_t) left_image->columns-x-1;
3217 for (x=0; x < (ssize_t) right_image->columns; x++)
3219 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3221 if ((p == (const Quantum *) NULL) ||
3222 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3223 ((x+i) >= (ssize_t) gap))
3226 if ((x+i) < (ssize_t) gap)
3229 right_view=DestroyCacheView(right_view);
3230 left_view=DestroyCacheView(left_view);
3231 if (y < (ssize_t) smush_image->rows)
3233 return((ssize_t) gap-offset);
3236 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3237 const ssize_t offset,ExceptionInfo *exception)
3251 register const Quantum
3264 if (images->previous == (Image *) NULL)
3266 bottom_image=images;
3267 SetGeometry(smush_image,&bottom_geometry);
3268 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3269 bottom_image->gravity,&bottom_geometry);
3270 top_image=images->previous;
3271 SetGeometry(smush_image,&top_geometry);
3272 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3274 gap=bottom_image->rows;
3275 top_view=AcquireVirtualCacheView(top_image,exception);
3276 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3277 for (x=0; x < (ssize_t) smush_image->columns; x++)
3279 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3281 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3282 if ((p == (const Quantum *) NULL) ||
3283 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3284 ((top_image->rows-y-1) >= gap))
3287 i=(ssize_t) top_image->rows-y-1;
3288 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3290 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3292 if ((p == (const Quantum *) NULL) ||
3293 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3294 ((y+i) >= (ssize_t) gap))
3297 if ((y+i) < (ssize_t) gap)
3300 bottom_view=DestroyCacheView(bottom_view);
3301 top_view=DestroyCacheView(top_view);
3302 if (x < (ssize_t) smush_image->columns)
3304 return((ssize_t) gap-offset);
3307 MagickExport Image *SmushImages(const Image *images,
3308 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3310 #define SmushImageTag "Smush/Image"
3331 register const Image
3344 Compute maximum area of smushed area.
3346 assert(images != (Image *) NULL);
3347 assert(images->signature == MagickCoreSignature);
3348 if (images->debug != MagickFalse)
3349 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3350 assert(exception != (ExceptionInfo *) NULL);
3351 assert(exception->signature == MagickCoreSignature);
3353 alpha_trait=image->alpha_trait;
3355 width=image->columns;
3357 next=GetNextImageInList(image);
3358 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3360 if (next->alpha_trait != UndefinedPixelTrait)
3361 alpha_trait=BlendPixelTrait;
3363 if (stack != MagickFalse)
3365 if (next->columns > width)
3366 width=next->columns;
3368 if (next->previous != (Image *) NULL)
3372 width+=next->columns;
3373 if (next->previous != (Image *) NULL)
3375 if (next->rows > height)
3381 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3382 if (smush_image == (Image *) NULL)
3383 return((Image *) NULL);
3384 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3386 smush_image=DestroyImage(smush_image);
3387 return((Image *) NULL);
3389 smush_image->alpha_trait=alpha_trait;
3390 (void) SetImageBackgroundColor(smush_image,exception);
3394 for (n=0; n < (MagickOffsetType) number_images; n++)
3396 SetGeometry(smush_image,&geometry);
3397 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3398 if (stack != MagickFalse)
3400 x_offset-=geometry.x;
3401 y_offset-=SmushYGap(smush_image,image,offset,exception);
3405 x_offset-=SmushXGap(smush_image,image,offset,exception);
3406 y_offset-=geometry.y;
3408 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3409 y_offset,exception);
3410 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3411 if (proceed == MagickFalse)
3413 if (stack == MagickFalse)
3415 x_offset+=(ssize_t) image->columns;
3421 y_offset+=(ssize_t) image->rows;
3423 image=GetNextImageInList(image);
3425 if (stack == MagickFalse)
3426 smush_image->columns=(size_t) x_offset;
3428 smush_image->rows=(size_t) y_offset;
3429 if (status == MagickFalse)
3430 smush_image=DestroyImage(smush_image);
3431 return(smush_image);
3435 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3439 % S t r i p I m a g e %
3443 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3445 % StripImage() strips an image of all profiles and comments.
3447 % The format of the StripImage method is:
3449 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3451 % A description of each parameter follows:
3453 % o image: the image.
3455 % o exception: return any errors or warnings in this structure.
3458 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3463 assert(image != (Image *) NULL);
3464 if (image->debug != MagickFalse)
3465 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3467 DestroyImageProfiles(image);
3468 (void) DeleteImageProperty(image,"comment");
3469 (void) DeleteImageProperty(image,"date:create");
3470 (void) DeleteImageProperty(image,"date:modify");
3471 status=SetImageArtifact(image,"png:exclude-chunk",
3472 "bKGD,cHRM,EXIF,gAMA,iCCP,iTXt,sRGB,tEXt,zCCP,zTXt,date");
3477 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3481 + S y n c I m a g e %
3485 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3487 % SyncImage() initializes the red, green, and blue intensities of each pixel
3488 % as defined by the colormap index.
3490 % The format of the SyncImage method is:
3492 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3494 % A description of each parameter follows:
3496 % o image: the image.
3498 % o exception: return any errors or warnings in this structure.
3502 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3503 MagickBooleanType *range_exception)
3505 if ((size_t) index < image->colors)
3507 *range_exception=MagickTrue;
3508 return((Quantum) 0);
3511 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3524 assert(image != (Image *) NULL);
3525 if (image->debug != MagickFalse)
3526 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3527 assert(image->signature == MagickCoreSignature);
3528 if (image->storage_class == DirectClass)
3529 return(MagickFalse);
3530 range_exception=MagickFalse;
3533 image_view=AcquireAuthenticCacheView(image,exception);
3534 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3535 #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
3536 magick_threads(image,image,image->rows,1)
3538 for (y=0; y < (ssize_t) image->rows; y++)
3549 if (status == MagickFalse)
3551 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3552 if (q == (Quantum *) NULL)
3557 for (x=0; x < (ssize_t) image->columns; x++)
3559 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3560 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
3561 q+=GetPixelChannels(image);
3563 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3566 image_view=DestroyCacheView(image_view);
3568 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3569 (void) ThrowMagickException(exception,GetMagickModule(),
3570 CorruptImageWarning,"InvalidColormapIndex","`%s'",image->filename);
3575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3579 % S y n c I m a g e S e t t i n g s %
3583 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3585 % SyncImageSettings() syncs any image_info global options into per-image
3588 % Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
3589 % that operations and coders can find such settings. In IMv7 if a desired
3590 % per-image artifact is not set, then it will directly look for a global
3591 % option as a fallback, as such this copy is no longer needed, only the
3594 % The format of the SyncImageSettings method is:
3596 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3597 % Image *image,ExceptionInfo *exception)
3598 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3599 % Image *image,ExceptionInfo *exception)
3601 % A description of each parameter follows:
3603 % o image_info: the image info.
3605 % o image: the image.
3607 % o exception: return any errors or warnings in this structure.
3611 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3612 Image *images,ExceptionInfo *exception)
3617 assert(image_info != (const ImageInfo *) NULL);
3618 assert(image_info->signature == MagickCoreSignature);
3619 assert(images != (Image *) NULL);
3620 assert(images->signature == MagickCoreSignature);
3621 if (images->debug != MagickFalse)
3622 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3624 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3625 (void) SyncImageSettings(image_info,image,exception);
3626 (void) DeleteImageOption(image_info,"page");
3630 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3631 Image *image,ExceptionInfo *exception)
3648 assert(image_info != (const ImageInfo *) NULL);
3649 assert(image_info->signature == MagickCoreSignature);
3650 assert(image != (Image *) NULL);
3651 assert(image->signature == MagickCoreSignature);
3652 if (image->debug != MagickFalse)
3653 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3654 option=GetImageOption(image_info,"alpha-color");
3655 if (option != (const char *) NULL)
3656 (void) QueryColorCompliance(option,AllCompliance,&image->alpha_color,
3658 option=GetImageOption(image_info,"background");
3659 if (option != (const char *) NULL)
3660 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
3662 option=GetImageOption(image_info,"black-point-compensation");
3663 if (option != (const char *) NULL)
3664 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3665 MagickBooleanOptions,MagickFalse,option);
3666 option=GetImageOption(image_info,"blue-primary");
3667 if (option != (const char *) NULL)
3669 flags=ParseGeometry(option,&geometry_info);
3670 image->chromaticity.blue_primary.x=geometry_info.rho;
3671 image->chromaticity.blue_primary.y=geometry_info.sigma;
3672 if ((flags & SigmaValue) == 0)
3673 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3675 option=GetImageOption(image_info,"bordercolor");
3676 if (option != (const char *) NULL)
3677 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
3679 /* FUTURE: do not sync compose to per-image compose setting here */
3680 option=GetImageOption(image_info,"compose");
3681 if (option != (const char *) NULL)
3682 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3683 MagickFalse,option);
3685 option=GetImageOption(image_info,"compress");
3686 if (option != (const char *) NULL)
3687 image->compression=(CompressionType) ParseCommandOption(
3688 MagickCompressOptions,MagickFalse,option);
3689 option=GetImageOption(image_info,"debug");
3690 if (option != (const char *) NULL)
3691 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3692 MagickFalse,option);
3693 option=GetImageOption(image_info,"density");
3694 if (option != (const char *) NULL)
3699 flags=ParseGeometry(option,&geometry_info);
3700 image->resolution.x=geometry_info.rho;
3701 image->resolution.y=geometry_info.sigma;
3702 if ((flags & SigmaValue) == 0)
3703 image->resolution.y=image->resolution.x;
3705 option=GetImageOption(image_info,"depth");
3706 if (option != (const char *) NULL)
3707 image->depth=StringToUnsignedLong(option);
3708 option=GetImageOption(image_info,"endian");
3709 if (option != (const char *) NULL)
3710 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3711 MagickFalse,option);
3712 option=GetImageOption(image_info,"filter");
3713 if (option != (const char *) NULL)
3714 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
3715 MagickFalse,option);
3716 option=GetImageOption(image_info,"fuzz");
3717 if (option != (const char *) NULL)
3718 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3719 option=GetImageOption(image_info,"gravity");
3720 if (option != (const char *) NULL)
3721 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3722 MagickFalse,option);
3723 option=GetImageOption(image_info,"green-primary");
3724 if (option != (const char *) NULL)
3726 flags=ParseGeometry(option,&geometry_info);
3727 image->chromaticity.green_primary.x=geometry_info.rho;
3728 image->chromaticity.green_primary.y=geometry_info.sigma;
3729 if ((flags & SigmaValue) == 0)
3730 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3732 option=GetImageOption(image_info,"intent");
3733 if (option != (const char *) NULL)
3734 image->rendering_intent=(RenderingIntent) ParseCommandOption(
3735 MagickIntentOptions,MagickFalse,option);
3736 option=GetImageOption(image_info,"intensity");
3737 if (option != (const char *) NULL)
3738 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3739 MagickPixelIntensityOptions,MagickFalse,option);
3740 option=GetImageOption(image_info,"interlace");
3741 if (option != (const char *) NULL)
3742 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3743 MagickFalse,option);
3744 option=GetImageOption(image_info,"interpolate");
3745 if (option != (const char *) NULL)
3746 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
3747 MagickInterpolateOptions,MagickFalse,option);
3748 option=GetImageOption(image_info,"loop");
3749 if (option != (const char *) NULL)
3750 image->iterations=StringToUnsignedLong(option);
3751 option=GetImageOption(image_info,"orient");
3752 if (option != (const char *) NULL)
3753 image->orientation=(OrientationType) ParseCommandOption(
3754 MagickOrientationOptions,MagickFalse,option);
3755 option=GetImageOption(image_info,"page");
3756 if (option != (const char *) NULL)
3761 geometry=GetPageGeometry(option);
3762 flags=ParseAbsoluteGeometry(geometry,&image->page);
3763 geometry=DestroyString(geometry);
3765 option=GetImageOption(image_info,"quality");
3766 if (option != (const char *) NULL)
3767 image->quality=StringToUnsignedLong(option);
3768 option=GetImageOption(image_info,"red-primary");
3769 if (option != (const char *) NULL)
3771 flags=ParseGeometry(option,&geometry_info);
3772 image->chromaticity.red_primary.x=geometry_info.rho;
3773 image->chromaticity.red_primary.y=geometry_info.sigma;
3774 if ((flags & SigmaValue) == 0)
3775 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3777 if (image_info->quality != UndefinedCompressionQuality)
3778 image->quality=image_info->quality;
3779 option=GetImageOption(image_info,"scene");
3780 if (option != (const char *) NULL)
3781 image->scene=StringToUnsignedLong(option);
3782 option=GetImageOption(image_info,"taint");
3783 if (option != (const char *) NULL)
3784 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3785 MagickFalse,option);
3786 option=GetImageOption(image_info,"tile-offset");
3787 if (option != (const char *) NULL)
3792 geometry=GetPageGeometry(option);
3793 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3794 geometry=DestroyString(geometry);
3796 option=GetImageOption(image_info,"transparent-color");
3797 if (option != (const char *) NULL)
3798 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
3800 option=GetImageOption(image_info,"type");
3801 if (option != (const char *) NULL)
3802 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3804 option=GetImageOption(image_info,"units");
3805 units=image_info->units;
3806 if (option != (const char *) NULL)
3807 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
3808 MagickFalse,option);
3809 if (units != UndefinedResolution)
3811 if (image->units != units)
3812 switch (image->units)
3814 case PixelsPerInchResolution:
3816 if (units == PixelsPerCentimeterResolution)
3818 image->resolution.x/=2.54;
3819 image->resolution.y/=2.54;
3823 case PixelsPerCentimeterResolution:
3825 if (units == PixelsPerInchResolution)
3827 image->resolution.x=(double) ((size_t) (100.0*2.54*
3828 image->resolution.x+0.5))/100.0;
3829 image->resolution.y=(double) ((size_t) (100.0*2.54*
3830 image->resolution.y+0.5))/100.0;
3839 option=GetImageOption(image_info,"virtual-pixel");
3840 if (option != (const char *) NULL)
3841 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
3842 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
3844 option=GetImageOption(image_info,"white-point");
3845 if (option != (const char *) NULL)
3847 flags=ParseGeometry(option,&geometry_info);
3848 image->chromaticity.white_point.x=geometry_info.rho;
3849 image->chromaticity.white_point.y=geometry_info.sigma;
3850 if ((flags & SigmaValue) == 0)
3851 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
3854 Pointer to allow the lookup of pre-image artifact will fallback to a global
3855 option setting/define. This saves a lot of duplication of global options
3856 into per-image artifacts, while ensuring only specifically set per-image
3857 artifacts are preserved when parenthesis ends.
3859 if (image->image_info != (ImageInfo *) NULL)
3860 image->image_info=DestroyImageInfo(image->image_info);
3861 image->image_info=CloneImageInfo(image_info);