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)
846 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
847 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
848 sizeof(*clone_image->colormap));
850 clone_image->image_info=CloneImageInfo(image->image_info);
851 (void) CloneImageProfiles(clone_image,image);
852 (void) CloneImageProperties(clone_image,image);
853 (void) CloneImageArtifacts(clone_image,image);
854 GetTimerInfo(&clone_image->timer);
855 if (image->ascii85 != (void *) NULL)
856 Ascii85Initialize(clone_image);
857 clone_image->magick_columns=image->magick_columns;
858 clone_image->magick_rows=image->magick_rows;
859 clone_image->type=image->type;
860 clone_image->channel_mask=image->channel_mask;
861 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
862 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
864 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
865 (void) CopyMagickString(clone_image->filename,image->filename,
867 clone_image->progress_monitor=image->progress_monitor;
868 clone_image->client_data=image->client_data;
869 clone_image->reference_count=1;
870 clone_image->next=image->next;
871 clone_image->previous=image->previous;
872 clone_image->list=NewImageList();
873 if (detach == MagickFalse)
874 clone_image->blob=ReferenceBlob(image->blob);
877 clone_image->next=NewImageList();
878 clone_image->previous=NewImageList();
879 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
881 clone_image->ping=image->ping;
882 clone_image->debug=IsEventLogging();
883 clone_image->semaphore=AcquireSemaphoreInfo();
884 if ((columns == 0) || (rows == 0))
886 if (image->montage != (char *) NULL)
887 (void) CloneString(&clone_image->montage,image->montage);
888 if (image->directory != (char *) NULL)
889 (void) CloneString(&clone_image->directory,image->directory);
890 clone_image->cache=ReferencePixelCache(image->cache);
894 if (image->columns != 0)
895 scale=(double) columns/(double) image->columns;
896 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
897 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
898 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
900 if (image->rows != 0)
901 scale=(double) rows/(double) image->rows;
902 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
903 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
904 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
905 clone_image->columns=columns;
906 clone_image->rows=rows;
907 clone_image->cache=ClonePixelCache(image->cache);
912 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
916 % C l o n e I m a g e I n f o %
920 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
922 % CloneImageInfo() makes a copy of the given image info structure. If
923 % NULL is specified, a new image info structure is created initialized to
926 % The format of the CloneImageInfo method is:
928 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
930 % A description of each parameter follows:
932 % o image_info: the image info.
935 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
940 clone_info=AcquireImageInfo();
941 if (image_info == (ImageInfo *) NULL)
943 clone_info->compression=image_info->compression;
944 clone_info->temporary=image_info->temporary;
945 clone_info->adjoin=image_info->adjoin;
946 clone_info->antialias=image_info->antialias;
947 clone_info->scene=image_info->scene;
948 clone_info->number_scenes=image_info->number_scenes;
949 clone_info->depth=image_info->depth;
950 (void) CloneString(&clone_info->size,image_info->size);
951 (void) CloneString(&clone_info->extract,image_info->extract);
952 (void) CloneString(&clone_info->scenes,image_info->scenes);
953 (void) CloneString(&clone_info->page,image_info->page);
954 clone_info->interlace=image_info->interlace;
955 clone_info->endian=image_info->endian;
956 clone_info->units=image_info->units;
957 clone_info->quality=image_info->quality;
958 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
959 (void) CloneString(&clone_info->server_name,image_info->server_name);
960 (void) CloneString(&clone_info->font,image_info->font);
961 (void) CloneString(&clone_info->texture,image_info->texture);
962 (void) CloneString(&clone_info->density,image_info->density);
963 clone_info->pointsize=image_info->pointsize;
964 clone_info->fuzz=image_info->fuzz;
965 clone_info->alpha_color=image_info->alpha_color;
966 clone_info->background_color=image_info->background_color;
967 clone_info->border_color=image_info->border_color;
968 clone_info->transparent_color=image_info->transparent_color;
969 clone_info->dither=image_info->dither;
970 clone_info->monochrome=image_info->monochrome;
971 clone_info->colorspace=image_info->colorspace;
972 clone_info->type=image_info->type;
973 clone_info->orientation=image_info->orientation;
974 clone_info->preview_type=image_info->preview_type;
975 clone_info->group=image_info->group;
976 clone_info->ping=image_info->ping;
977 clone_info->verbose=image_info->verbose;
978 clone_info->progress_monitor=image_info->progress_monitor;
979 clone_info->client_data=image_info->client_data;
980 clone_info->cache=image_info->cache;
981 if (image_info->cache != (void *) NULL)
982 clone_info->cache=ReferencePixelCache(image_info->cache);
983 if (image_info->profile != (void *) NULL)
984 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
985 image_info->profile);
986 SetImageInfoFile(clone_info,image_info->file);
987 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
988 clone_info->stream=image_info->stream;
989 (void) CopyMagickString(clone_info->magick,image_info->magick,
991 (void) CopyMagickString(clone_info->unique,image_info->unique,
993 (void) CopyMagickString(clone_info->filename,image_info->filename,
995 clone_info->channel=image_info->channel;
996 (void) CloneImageOptions(clone_info,image_info);
997 clone_info->debug=IsEventLogging();
998 clone_info->signature=image_info->signature;
1003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1007 % C o p y I m a g e P i x e l s %
1011 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1013 % CopyImagePixels() copies pixels from the source image as defined by the
1014 % geometry the destination image at the specified offset.
1016 % The format of the CopyImagePixels method is:
1018 % MagickBooleanType CopyImagePixels(Image *image,const Image *source_image,
1019 % const RectangleInfo *geometry,const OffsetInfo *offset,
1020 % ExceptionInfo *exception);
1022 % A description of each parameter follows:
1024 % o image: the destination image.
1026 % o source_image: the source image.
1028 % o geometry: define the dimensions of the source pixel rectangle.
1030 % o offset: define the offset in the destination image.
1032 % o exception: return any errors or warnings in this structure.
1035 MagickExport MagickBooleanType CopyImagePixels(Image *image,
1036 const Image *source_image,const RectangleInfo *geometry,
1037 const OffsetInfo *offset,ExceptionInfo *exception)
1039 #define CopyImageTag "Copy/Image"
1054 assert(image != (Image *) NULL);
1055 if (image->debug != MagickFalse)
1056 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1057 assert(source_image != (Image *) NULL);
1058 assert(geometry != (RectangleInfo *) NULL);
1059 assert(offset != (OffsetInfo *) NULL);
1060 if ((offset->x < 0) || (offset->y < 0) ||
1061 ((ssize_t) (offset->x+geometry->width) > (ssize_t) image->columns) ||
1062 ((ssize_t) (offset->y+geometry->height) > (ssize_t) image->rows))
1063 ThrowBinaryException(OptionError,"GeometryDoesNotContainImage",
1065 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1066 return(MagickFalse);
1072 source_view=AcquireVirtualCacheView(source_image,exception);
1073 image_view=AcquireAuthenticCacheView(image,exception);
1074 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1075 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1076 magick_threads(image,source_image,geometry->height,1)
1078 for (y=0; y < (ssize_t) geometry->height; y++)
1083 register const Quantum
1092 if (status == MagickFalse)
1094 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1095 geometry->width,1,exception);
1096 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1097 geometry->width,1,exception);
1098 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1103 for (x=0; x < (ssize_t) geometry->width; x++)
1108 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1110 PixelChannel channel=GetPixelChannelChannel(image,i);
1111 PixelTrait traits=GetPixelChannelTraits(image,channel);
1112 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1113 if ((traits == UndefinedPixelTrait) ||
1114 (source_traits == UndefinedPixelTrait))
1116 SetPixelChannel(image,channel,p[i],q);
1118 p+=GetPixelChannels(source_image);
1119 q+=GetPixelChannels(image);
1121 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1122 if (sync == MagickFalse)
1124 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1129 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1130 #pragma omp critical (MagickCore_CopyImage)
1132 proceed=SetImageProgress(image,CopyImageTag,progress++,image->rows);
1133 if (proceed == MagickFalse)
1137 source_view=DestroyCacheView(source_view);
1138 image_view=DestroyCacheView(image_view);
1143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1147 % D e s t r o y I m a g e %
1151 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1153 % DestroyImage() dereferences an image, deallocating memory associated with
1154 % the image if the reference count becomes zero.
1156 % The format of the DestroyImage method is:
1158 % Image *DestroyImage(Image *image)
1160 % A description of each parameter follows:
1162 % o image: the image.
1165 MagickExport Image *DestroyImage(Image *image)
1173 assert(image != (Image *) NULL);
1174 assert(image->signature == MagickCoreSignature);
1175 if (image->debug != MagickFalse)
1176 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1177 destroy=MagickFalse;
1178 LockSemaphoreInfo(image->semaphore);
1179 image->reference_count--;
1180 if (image->reference_count == 0)
1182 UnlockSemaphoreInfo(image->semaphore);
1183 if (destroy == MagickFalse)
1184 return((Image *) NULL);
1188 DestroyImagePixels(image);
1189 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1190 if (image->montage != (char *) NULL)
1191 image->montage=DestroyString(image->montage);
1192 if (image->directory != (char *) NULL)
1193 image->directory=DestroyString(image->directory);
1194 if (image->colormap != (PixelInfo *) NULL)
1195 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1196 if (image->geometry != (char *) NULL)
1197 image->geometry=DestroyString(image->geometry);
1198 DestroyImageProfiles(image);
1199 DestroyImageProperties(image);
1200 DestroyImageArtifacts(image);
1201 if (image->ascii85 != (Ascii85Info *) NULL)
1202 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1203 if (image->image_info != (ImageInfo *) NULL)
1204 image->image_info=DestroyImageInfo(image->image_info);
1206 if (image->semaphore != (SemaphoreInfo *) NULL)
1207 RelinquishSemaphoreInfo(&image->semaphore);
1208 image->signature=(~MagickCoreSignature);
1209 image=(Image *) RelinquishMagickMemory(image);
1214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1218 % D e s t r o y I m a g e I n f o %
1222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1224 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1227 % The format of the DestroyImageInfo method is:
1229 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1231 % A description of each parameter follows:
1233 % o image_info: the image info.
1236 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1238 assert(image_info != (ImageInfo *) NULL);
1239 assert(image_info->signature == MagickCoreSignature);
1240 if (image_info->debug != MagickFalse)
1241 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1242 image_info->filename);
1243 if (image_info->size != (char *) NULL)
1244 image_info->size=DestroyString(image_info->size);
1245 if (image_info->extract != (char *) NULL)
1246 image_info->extract=DestroyString(image_info->extract);
1247 if (image_info->scenes != (char *) NULL)
1248 image_info->scenes=DestroyString(image_info->scenes);
1249 if (image_info->page != (char *) NULL)
1250 image_info->page=DestroyString(image_info->page);
1251 if (image_info->sampling_factor != (char *) NULL)
1252 image_info->sampling_factor=DestroyString(
1253 image_info->sampling_factor);
1254 if (image_info->server_name != (char *) NULL)
1255 image_info->server_name=DestroyString(
1256 image_info->server_name);
1257 if (image_info->font != (char *) NULL)
1258 image_info->font=DestroyString(image_info->font);
1259 if (image_info->texture != (char *) NULL)
1260 image_info->texture=DestroyString(image_info->texture);
1261 if (image_info->density != (char *) NULL)
1262 image_info->density=DestroyString(image_info->density);
1263 if (image_info->cache != (void *) NULL)
1264 image_info->cache=DestroyPixelCache(image_info->cache);
1265 if (image_info->profile != (StringInfo *) NULL)
1266 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1267 image_info->profile);
1268 DestroyImageOptions(image_info);
1269 image_info->signature=(~MagickCoreSignature);
1270 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1279 + D i s a s s o c i a t e I m a g e S t r e a m %
1283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1285 % DisassociateImageStream() disassociates the image stream. It checks if the
1286 % blob of the specified image is referenced by other images. If the reference
1287 % count is higher then 1 a new blob is assigned to the specified image.
1289 % The format of the DisassociateImageStream method is:
1291 % void DisassociateImageStream(const Image *image)
1293 % A description of each parameter follows:
1295 % o image: the image.
1298 MagickExport void DisassociateImageStream(Image *image)
1300 assert(image != (Image *) NULL);
1301 assert(image->signature == MagickCoreSignature);
1302 if (image->debug != MagickFalse)
1303 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1304 DisassociateBlob(image);
1308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1312 % G e t I m a g e I n f o %
1316 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1318 % GetImageInfo() initializes image_info to default values.
1320 % The format of the GetImageInfo method is:
1322 % void GetImageInfo(ImageInfo *image_info)
1324 % A description of each parameter follows:
1326 % o image_info: the image info.
1329 MagickExport void GetImageInfo(ImageInfo *image_info)
1338 File and image dimension members.
1340 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1341 assert(image_info != (ImageInfo *) NULL);
1342 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1343 image_info->adjoin=MagickTrue;
1344 image_info->interlace=NoInterlace;
1345 image_info->channel=DefaultChannels;
1346 image_info->quality=UndefinedCompressionQuality;
1347 image_info->antialias=MagickTrue;
1348 image_info->dither=MagickTrue;
1349 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1350 if (synchronize != (const char *) NULL)
1352 image_info->synchronize=IsStringTrue(synchronize);
1353 synchronize=DestroyString(synchronize);
1355 exception=AcquireExceptionInfo();
1356 (void) QueryColorCompliance(AlphaColor,AllCompliance,&image_info->alpha_color,
1358 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1359 &image_info->background_color,exception);
1360 (void) QueryColorCompliance(BorderColor,AllCompliance,
1361 &image_info->border_color,exception);
1362 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1363 &image_info->transparent_color,exception);
1364 exception=DestroyExceptionInfo(exception);
1365 image_info->debug=IsEventLogging();
1366 image_info->signature=MagickCoreSignature;
1370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1374 % G e t I m a g e I n f o F i l e %
1378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1380 % GetImageInfoFile() returns the image info file member.
1382 % The format of the GetImageInfoFile method is:
1384 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1386 % A description of each parameter follows:
1388 % o image_info: the image info.
1391 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1393 return(image_info->file);
1397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1401 % G e t I m a g e M a s k %
1405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1407 % GetImageMask() returns the mask associated with the image.
1409 % The format of the GetImageMask method is:
1411 % Image *GetImageMask(const Image *image,const PixelMask type,
1412 % ExceptionInfo *exception)
1414 % A description of each parameter follows:
1416 % o image: the image.
1418 % o type: the mask type, ReadPixelMask or WritePixelMask.
1421 MagickExport Image *GetImageMask(const Image *image,const PixelMask type,
1422 ExceptionInfo *exception)
1440 assert(image != (Image *) NULL);
1441 if (image->debug != MagickFalse)
1442 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1443 assert(image->signature == MagickCoreSignature);
1444 mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1445 if (mask_image == (Image *) NULL)
1446 return((Image *) NULL);
1448 mask_image->alpha_trait=UndefinedPixelTrait;
1449 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1450 mask_image->read_mask=MagickFalse;
1451 image_view=AcquireVirtualCacheView(image,exception);
1452 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1453 for (y=0; y < (ssize_t) image->rows; y++)
1455 register const Quantum
1464 if (status == MagickFalse)
1466 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1467 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1469 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1474 for (x=0; x < (ssize_t) image->columns; x++)
1478 case WritePixelMask:
1480 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1485 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1489 p+=GetPixelChannels(image);
1490 q+=GetPixelChannels(mask_image);
1492 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1495 mask_view=DestroyCacheView(mask_view);
1496 image_view=DestroyCacheView(image_view);
1497 if (status == MagickFalse)
1498 mask_image=DestroyImage(mask_image);
1503 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1507 + G e t I m a g e R e f e r e n c e C o u n t %
1511 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1513 % GetImageReferenceCount() returns the image reference count.
1515 % The format of the GetReferenceCount method is:
1517 % ssize_t GetImageReferenceCount(Image *image)
1519 % A description of each parameter follows:
1521 % o image: the image.
1524 MagickExport ssize_t GetImageReferenceCount(Image *image)
1529 assert(image != (Image *) NULL);
1530 assert(image->signature == MagickCoreSignature);
1531 if (image->debug != MagickFalse)
1532 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1533 LockSemaphoreInfo(image->semaphore);
1534 reference_count=image->reference_count;
1535 UnlockSemaphoreInfo(image->semaphore);
1536 return(reference_count);
1540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1544 % 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 %
1548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1550 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1551 % image. A virtual pixel is any pixel access that is outside the boundaries
1552 % of the image cache.
1554 % The format of the GetImageVirtualPixelMethod() method is:
1556 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1558 % A description of each parameter follows:
1560 % o image: the image.
1563 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1565 assert(image != (Image *) NULL);
1566 assert(image->signature == MagickCoreSignature);
1567 if (image->debug != MagickFalse)
1568 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1569 return(GetPixelCacheVirtualMethod(image));
1573 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1577 % I n t e r p r e t I m a g e F i l e n a m e %
1581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1583 % InterpretImageFilename() interprets embedded characters in an image filename.
1584 % The filename length is returned.
1586 % The format of the InterpretImageFilename method is:
1588 % size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1589 % const char *format,int value,char *filename,ExceptionInfo *exception)
1591 % A description of each parameter follows.
1593 % o image_info: the image info..
1595 % o image: the image.
1597 % o format: A filename describing the format to use to write the numeric
1598 % argument. Only the first numeric format identifier is replaced.
1600 % o value: Numeric value to substitute into format filename.
1602 % o filename: return the formatted filename in this character buffer.
1604 % o exception: return any errors or warnings in this structure.
1607 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1608 Image *image,const char *format,int value,char *filename,
1609 ExceptionInfo *exception)
1626 canonical=MagickFalse;
1628 (void) CopyMagickString(filename,format,MagickPathExtent);
1629 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1642 foo=(ssize_t) strtol(q,&q,10);
1654 (void) FormatLocaleString(filename+(p-format),(size_t)
1655 (MagickPathExtent-(p-format)),p,value);
1657 (void) ConcatenateMagickString(filename,q,MagickPathExtent);
1658 canonical=MagickTrue;
1667 pattern[MagickPathExtent];
1684 /* FUTURE: Compare update with code from InterpretImageProperties()
1685 Note that a 'filename:' property should not need depth recursion.
1687 if (strchr(p,']') == (char *) NULL)
1691 for (i=0; (i < (MagickPathExtent-1L)) && (*r != '\0'); i++)
1702 if (LocaleNCompare(pattern,"filename:",9) != 0)
1704 option=(const char *) NULL;
1705 if (image != (Image *) NULL)
1706 option=GetImageProperty(image,pattern,exception);
1707 if ((option == (const char *) NULL) && (image != (Image *) NULL))
1708 option=GetImageArtifact(image,pattern);
1709 if ((option == (const char *) NULL) &&
1710 (image_info != (ImageInfo *) NULL))
1711 option=GetImageOption(image_info,pattern);
1712 if (option == (const char *) NULL)
1717 (void) CopyMagickString(filename+(p-format-length),option,(size_t)
1718 (MagickPathExtent-(p-format-length)));
1719 length+=strlen(pattern)-1;
1721 (void) ConcatenateMagickString(filename,r+1,MagickPathExtent);
1722 canonical=MagickTrue;
1732 for (q=filename; *q != '\0'; q++)
1733 if ((*q == '%') && (*(q+1) == '%'))
1735 (void) CopyMagickString(q,q+1,(size_t) (MagickPathExtent-(q-filename)));
1736 canonical=MagickTrue;
1738 if (canonical == MagickFalse)
1739 (void) CopyMagickString(filename,format,MagickPathExtent);
1740 return(strlen(filename));
1744 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1748 % I s H i g h D y n a m i c R a n g e I m a g e %
1752 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1754 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1755 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1758 % The format of the IsHighDynamicRangeImage method is:
1760 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1761 % ExceptionInfo *exception)
1763 % A description of each parameter follows:
1765 % o image: the image.
1767 % o exception: return any errors or warnings in this structure.
1770 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1771 ExceptionInfo *exception)
1773 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1776 return(MagickFalse);
1787 assert(image != (Image *) NULL);
1788 assert(image->signature == MagickCoreSignature);
1789 if (image->debug != MagickFalse)
1790 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1792 image_view=AcquireVirtualCacheView(image,exception);
1793 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1794 #pragma omp parallel for schedule(static,4) shared(status) \
1795 magick_threads(image,image,image->rows,1)
1797 for (y=0; y < (ssize_t) image->rows; y++)
1799 register const Quantum
1805 if (status == MagickFalse)
1807 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1808 if (p == (const Quantum *) NULL)
1813 for (x=0; x < (ssize_t) image->columns; x++)
1818 if (GetPixelReadMask(image,p) == 0)
1820 p+=GetPixelChannels(image);
1823 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1831 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1832 if (traits == UndefinedPixelTrait)
1834 pixel=(double) p[i];
1835 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1836 (pixel != (double) ((QuantumAny) pixel)))
1839 p+=GetPixelChannels(image);
1840 if (i < (ssize_t) GetPixelChannels(image))
1843 if (x < (ssize_t) image->columns)
1846 image_view=DestroyCacheView(image_view);
1847 return(status != MagickFalse ? MagickFalse : MagickTrue);
1852 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1856 % I s I m a g e O b j e c t %
1860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1862 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1863 % set of image objects.
1865 % The format of the IsImageObject method is:
1867 % MagickBooleanType IsImageObject(const Image *image)
1869 % A description of each parameter follows:
1871 % o image: the image.
1874 MagickExport MagickBooleanType IsImageObject(const Image *image)
1876 register const Image
1879 assert(image != (Image *) NULL);
1880 if (image->debug != MagickFalse)
1881 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1882 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1883 if (p->signature != MagickCoreSignature)
1884 return(MagickFalse);
1889 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1893 % I s T a i n t I m a g e %
1897 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1899 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1900 % since it was first constituted.
1902 % The format of the IsTaintImage method is:
1904 % MagickBooleanType IsTaintImage(const Image *image)
1906 % A description of each parameter follows:
1908 % o image: the image.
1911 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1914 magick[MagickPathExtent],
1915 filename[MagickPathExtent];
1917 register const Image
1920 assert(image != (Image *) NULL);
1921 if (image->debug != MagickFalse)
1922 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1923 assert(image->signature == MagickCoreSignature);
1924 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1925 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1926 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1928 if (p->taint != MagickFalse)
1930 if (LocaleCompare(p->magick,magick) != 0)
1932 if (LocaleCompare(p->filename,filename) != 0)
1935 return(MagickFalse);
1939 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1943 % M o d i f y I m a g e %
1947 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1949 % ModifyImage() ensures that there is only a single reference to the image
1950 % to be modified, updating the provided image pointer to point to a clone of
1951 % the original image if necessary.
1953 % The format of the ModifyImage method is:
1955 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1957 % A description of each parameter follows:
1959 % o image: the image.
1961 % o exception: return any errors or warnings in this structure.
1964 MagickExport MagickBooleanType ModifyImage(Image **image,
1965 ExceptionInfo *exception)
1970 assert(image != (Image **) NULL);
1971 assert(*image != (Image *) NULL);
1972 assert((*image)->signature == MagickCoreSignature);
1973 if ((*image)->debug != MagickFalse)
1974 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1975 if (GetImageReferenceCount(*image) <= 1)
1977 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1978 LockSemaphoreInfo((*image)->semaphore);
1979 (*image)->reference_count--;
1980 UnlockSemaphoreInfo((*image)->semaphore);
1986 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1990 % N e w M a g i c k I m a g e %
1994 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1996 % NewMagickImage() creates a blank image canvas of the specified size and
1999 % The format of the NewMagickImage method is:
2001 % Image *NewMagickImage(const ImageInfo *image_info,const size_t width,
2002 % const size_t height,const PixelInfo *background,
2003 % ExceptionInfo *exception)
2005 % A description of each parameter follows:
2007 % o image: the image.
2009 % o width: the image width.
2011 % o height: the image height.
2013 % o background: the image color.
2015 % o exception: return any errors or warnings in this structure.
2018 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2019 const size_t width,const size_t height,const PixelInfo *background,
2020 ExceptionInfo *exception)
2034 assert(image_info != (const ImageInfo *) NULL);
2035 if (image_info->debug != MagickFalse)
2036 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2037 assert(image_info->signature == MagickCoreSignature);
2038 assert(background != (const PixelInfo *) NULL);
2039 image=AcquireImage(image_info,exception);
2040 image->columns=width;
2042 image->colorspace=background->colorspace;
2043 image->alpha_trait=background->alpha_trait;
2044 image->fuzz=background->fuzz;
2045 image->depth=background->depth;
2047 image_view=AcquireAuthenticCacheView(image,exception);
2048 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2049 #pragma omp parallel for schedule(static,4) shared(status) \
2050 magick_threads(image,image,image->rows,1)
2052 for (y=0; y < (ssize_t) image->rows; y++)
2060 if (status == MagickFalse)
2062 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2063 if (q == (Quantum *) NULL)
2068 for (x=0; x < (ssize_t) image->columns; x++)
2070 SetPixelViaPixelInfo(image,background,q);
2071 q+=GetPixelChannels(image);
2073 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2076 image_view=DestroyCacheView(image_view);
2077 if (status == MagickFalse)
2078 image=DestroyImage(image);
2083 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2087 % R e f e r e n c e I m a g e %
2091 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2093 % ReferenceImage() increments the reference count associated with an image
2094 % returning a pointer to the image.
2096 % The format of the ReferenceImage method is:
2098 % Image *ReferenceImage(Image *image)
2100 % A description of each parameter follows:
2102 % o image: the image.
2105 MagickExport Image *ReferenceImage(Image *image)
2107 assert(image != (Image *) NULL);
2108 if (image->debug != MagickFalse)
2109 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2110 assert(image->signature == MagickCoreSignature);
2111 LockSemaphoreInfo(image->semaphore);
2112 image->reference_count++;
2113 UnlockSemaphoreInfo(image->semaphore);
2118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2122 % R e s e t I m a g e P a g e %
2126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2128 % ResetImagePage() resets the image page canvas and position.
2130 % The format of the ResetImagePage method is:
2132 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2134 % A description of each parameter follows:
2136 % o image: the image.
2138 % o page: the relative page specification.
2141 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2149 assert(image != (Image *) NULL);
2150 assert(image->signature == MagickCoreSignature);
2151 if (image->debug != MagickFalse)
2152 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2153 flags=ParseAbsoluteGeometry(page,&geometry);
2154 if ((flags & WidthValue) != 0)
2156 if ((flags & HeightValue) == 0)
2157 geometry.height=geometry.width;
2158 image->page.width=geometry.width;
2159 image->page.height=geometry.height;
2161 if ((flags & AspectValue) != 0)
2163 if ((flags & XValue) != 0)
2164 image->page.x+=geometry.x;
2165 if ((flags & YValue) != 0)
2166 image->page.y+=geometry.y;
2170 if ((flags & XValue) != 0)
2172 image->page.x=geometry.x;
2173 if ((image->page.width == 0) && (geometry.x > 0))
2174 image->page.width=image->columns+geometry.x;
2176 if ((flags & YValue) != 0)
2178 image->page.y=geometry.y;
2179 if ((image->page.height == 0) && (geometry.y > 0))
2180 image->page.height=image->rows+geometry.y;
2187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2191 % S e t I m a g e B a c k g r o u n d C o l o r %
2195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2197 % SetImageBackgroundColor() initializes the image pixels to the image
2198 % background color. The background color is defined by the background_color
2199 % member of the image structure.
2201 % The format of the SetImage method is:
2203 % MagickBooleanType SetImageBackgroundColor(Image *image,
2204 % ExceptionInfo *exception)
2206 % A description of each parameter follows:
2208 % o image: the image.
2210 % o exception: return any errors or warnings in this structure.
2213 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2214 ExceptionInfo *exception)
2228 assert(image != (Image *) NULL);
2229 if (image->debug != MagickFalse)
2230 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2231 assert(image->signature == MagickCoreSignature);
2232 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2233 return(MagickFalse);
2234 ConformPixelInfo(image,&image->background_color,&background,exception);
2236 Set image background color.
2239 image_view=AcquireAuthenticCacheView(image,exception);
2240 for (y=0; y < (ssize_t) image->rows; y++)
2248 if (status == MagickFalse)
2250 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2251 if (q == (Quantum *) NULL)
2256 for (x=0; x < (ssize_t) image->columns; x++)
2258 SetPixelViaPixelInfo(image,&background,q);
2259 q+=GetPixelChannels(image);
2261 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2264 image_view=DestroyCacheView(image_view);
2269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2273 % S e t I m a g e C h a n n e l M a s k %
2277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2279 % SetImageChannelMask() sets the image channel mask from the specified channel
2282 % The format of the SetImageChannelMask method is:
2284 % ChannelType SetImageChannelMask(Image *image,
2285 % const ChannelType channel_mask)
2287 % A description of each parameter follows:
2289 % o image: the image.
2291 % o channel_mask: the channel mask.
2294 MagickExport ChannelType SetImageChannelMask(Image *image,
2295 const ChannelType channel_mask)
2297 return(SetPixelChannelMask(image,channel_mask));
2301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2305 % S e t I m a g e C o l o r %
2309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2311 % SetImageColor() set the entire image canvas to the specified color.
2313 % The format of the SetImageColor method is:
2315 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2316 % ExeptionInfo *exception)
2318 % A description of each parameter follows:
2320 % o image: the image.
2322 % o background: the image color.
2324 % o exception: return any errors or warnings in this structure.
2327 MagickExport MagickBooleanType SetImageColor(Image *image,
2328 const PixelInfo *color,ExceptionInfo *exception)
2339 assert(image != (Image *) NULL);
2340 if (image->debug != MagickFalse)
2341 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2342 assert(image->signature == MagickCoreSignature);
2343 assert(color != (const PixelInfo *) NULL);
2344 image->colorspace=color->colorspace;
2345 image->alpha_trait=color->alpha_trait;
2346 image->fuzz=color->fuzz;
2347 image->depth=color->depth;
2349 image_view=AcquireAuthenticCacheView(image,exception);
2350 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2351 #pragma omp parallel for schedule(static,4) shared(status) \
2352 magick_threads(image,image,image->rows,1)
2354 for (y=0; y < (ssize_t) image->rows; y++)
2362 if (status == MagickFalse)
2364 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2365 if (q == (Quantum *) NULL)
2370 for (x=0; x < (ssize_t) image->columns; x++)
2372 SetPixelViaPixelInfo(image,color,q);
2373 q+=GetPixelChannels(image);
2375 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2378 image_view=DestroyCacheView(image_view);
2383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2387 % S e t I m a g e S t o r a g e C l a s s %
2391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2393 % SetImageStorageClass() sets the image class: DirectClass for true color
2394 % images or PseudoClass for colormapped images.
2396 % The format of the SetImageStorageClass method is:
2398 % MagickBooleanType SetImageStorageClass(Image *image,
2399 % const ClassType storage_class,ExceptionInfo *exception)
2401 % A description of each parameter follows:
2403 % o image: the image.
2405 % o storage_class: The image class.
2407 % o exception: return any errors or warnings in this structure.
2410 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2411 const ClassType storage_class,ExceptionInfo *exception)
2413 image->storage_class=storage_class;
2414 return(SyncImagePixelCache(image,exception));
2418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2422 % S e t I m a g e E x t e n t %
2426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2428 % SetImageExtent() sets the image size (i.e. columns & rows).
2430 % The format of the SetImageExtent method is:
2432 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2433 % const size_t rows,ExceptionInfo *exception)
2435 % A description of each parameter follows:
2437 % o image: the image.
2439 % o columns: The image width in pixels.
2441 % o rows: The image height in pixels.
2443 % o exception: return any errors or warnings in this structure.
2446 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2447 const size_t rows,ExceptionInfo *exception)
2449 if ((columns == 0) || (rows == 0))
2450 return(MagickFalse);
2451 image->columns=columns;
2453 if (image->depth > (8*sizeof(MagickSizeType)))
2454 ThrowBinaryException(ImageError,"ImageDepthNotSupported",image->filename);
2455 return(SyncImagePixelCache(image,exception));
2459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2463 + S e t I m a g e I n f o %
2467 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2469 % SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
2470 % It is set to a type of image format based on the prefix or suffix of the
2471 % filename. For example, 'ps:image' returns PS indicating a Postscript image.
2472 % JPEG is returned for this filename: 'image.jpg'. The filename prefix has
2473 % precendence over the suffix. Use an optional index enclosed in brackets
2474 % after a file name to specify a desired scene of a multi-resolution image
2475 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2476 % indicates success.
2478 % The format of the SetImageInfo method is:
2480 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2481 % const unsigned int frames,ExceptionInfo *exception)
2483 % A description of each parameter follows:
2485 % o image_info: the image info.
2487 % o frames: the number of images you intend to write.
2489 % o exception: return any errors or warnings in this structure.
2492 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2493 const unsigned int frames,ExceptionInfo *exception)
2496 component[MagickPathExtent],
2497 magic[MagickPathExtent],
2522 Look for 'image.format' in filename.
2524 assert(image_info != (ImageInfo *) NULL);
2525 assert(image_info->signature == MagickCoreSignature);
2526 if (image_info->debug != MagickFalse)
2527 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2528 image_info->filename);
2530 GetPathComponent(image_info->filename,SubimagePath,component);
2531 if (*component != '\0')
2534 Look for scene specification (e.g. img0001.pcd[4]).
2536 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2538 if (IsGeometry(component) != MagickFalse)
2539 (void) CloneString(&image_info->extract,component);
2547 (void) CloneString(&image_info->scenes,component);
2548 image_info->scene=StringToUnsignedLong(image_info->scenes);
2549 image_info->number_scenes=image_info->scene;
2550 p=image_info->scenes;
2551 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2553 while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2555 first=(size_t) strtol(p,&q,10);
2557 while (isspace((int) ((unsigned char) *q)) != 0)
2560 last=(size_t) strtol(q+1,&q,10);
2563 if (first < image_info->scene)
2564 image_info->scene=first;
2565 if (last > image_info->number_scenes)
2566 image_info->number_scenes=last;
2569 image_info->number_scenes-=image_info->scene-1;
2573 if (*image_info->magick == '\0')
2574 GetPathComponent(image_info->filename,ExtensionPath,component);
2575 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2576 if (*component != '\0')
2577 if ((LocaleCompare(component,"gz") == 0) ||
2578 (LocaleCompare(component,"Z") == 0) ||
2579 (LocaleCompare(component,"svgz") == 0) ||
2580 (LocaleCompare(component,"wmz") == 0))
2583 path[MagickPathExtent];
2585 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2586 path[strlen(path)-strlen(component)-1]='\0';
2587 GetPathComponent(path,ExtensionPath,component);
2590 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2591 if (*component != '\0')
2592 if (LocaleCompare(component,"bz2") == 0)
2595 path[MagickPathExtent];
2597 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2598 path[strlen(path)-strlen(component)-1]='\0';
2599 GetPathComponent(path,ExtensionPath,component);
2602 image_info->affirm=MagickFalse;
2603 sans_exception=AcquireExceptionInfo();
2604 if (*component != '\0')
2613 *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 if (LocaleCompare(magic,"EPHEMERAL") != 0)
2685 image_info->affirm=MagickTrue;
2687 image_info->temporary=MagickTrue;
2690 magick_info=GetMagickInfo(magic,sans_exception);
2691 sans_exception=DestroyExceptionInfo(sans_exception);
2692 if ((magick_info == (const MagickInfo *) NULL) ||
2693 (GetMagickEndianSupport(magick_info) == MagickFalse))
2694 image_info->endian=UndefinedEndian;
2695 GetPathComponent(image_info->filename,CanonicalPath,component);
2696 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2697 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2700 Test for multiple image support (e.g. image%02d.png).
2702 (void) InterpretImageFilename(image_info,(Image *) NULL,
2703 image_info->filename,(int) image_info->scene,component,exception);
2704 if ((LocaleCompare(component,image_info->filename) != 0) &&
2705 (strchr(component,'%') == (char *) NULL))
2706 image_info->adjoin=MagickFalse;
2708 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2711 Some image formats do not support multiple frames per file.
2713 magick_info=GetMagickInfo(magic,exception);
2714 if (magick_info != (const MagickInfo *) NULL)
2715 if (GetMagickAdjoin(magick_info) == MagickFalse)
2716 image_info->adjoin=MagickFalse;
2718 if (image_info->affirm != MagickFalse)
2729 Determine the image format from the first few bytes of the file.
2731 magick_size=GetMagicPatternExtent(exception);
2732 if (magick_size == 0)
2733 return(MagickFalse);
2734 image=AcquireImage(image_info,exception);
2735 (void) CopyMagickString(image->filename,image_info->filename,
2737 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2738 if (status == MagickFalse)
2740 image=DestroyImage(image);
2741 return(MagickFalse);
2743 if ((IsBlobSeekable(image) == MagickFalse) ||
2744 (IsBlobExempt(image) != MagickFalse))
2747 Copy standard input or pipe to temporary file.
2750 status=ImageToFile(image,component,exception);
2751 (void) CloseBlob(image);
2752 if (status == MagickFalse)
2754 image=DestroyImage(image);
2755 return(MagickFalse);
2757 SetImageInfoFile(image_info,(FILE *) NULL);
2758 (void) CopyMagickString(image->filename,component,MagickPathExtent);
2759 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2760 if (status == MagickFalse)
2762 image=DestroyImage(image);
2763 return(MagickFalse);
2765 (void) CopyMagickString(image_info->filename,component,
2767 image_info->temporary=MagickTrue;
2769 magick=(unsigned char *) AcquireMagickMemory(magick_size);
2770 if (magick == (unsigned char *) NULL)
2772 (void) CloseBlob(image);
2773 image=DestroyImage(image);
2774 return(MagickFalse);
2776 (void) ResetMagickMemory(magick,0,magick_size);
2777 count=ReadBlob(image,magick_size,magick);
2778 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
2779 (void) CloseBlob(image);
2780 image=DestroyImage(image);
2782 Check magic.xml configuration file.
2784 sans_exception=AcquireExceptionInfo();
2785 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
2786 magick=(unsigned char *) RelinquishMagickMemory(magick);
2787 if ((magic_info != (const MagicInfo *) NULL) &&
2788 (GetMagicName(magic_info) != (char *) NULL))
2791 Try to use magick_info that was determined earlier by the extension
2793 if ((magick_info != (const MagickInfo *) NULL) &&
2794 (GetMagickUseExtension(magick_info) != MagickFalse) &&
2795 (LocaleCompare(magick_info->module,GetMagicName(
2797 (void) CopyMagickString(image_info->magick,magick_info->name,
2801 (void) CopyMagickString(image_info->magick,GetMagicName(
2802 magic_info),MagickPathExtent);
2803 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2805 if ((magick_info == (const MagickInfo *) NULL) ||
2806 (GetMagickEndianSupport(magick_info) == MagickFalse))
2807 image_info->endian=UndefinedEndian;
2808 sans_exception=DestroyExceptionInfo(sans_exception);
2811 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2812 if ((magick_info == (const MagickInfo *) NULL) ||
2813 (GetMagickEndianSupport(magick_info) == MagickFalse))
2814 image_info->endian=UndefinedEndian;
2815 sans_exception=DestroyExceptionInfo(sans_exception);
2821 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2825 % S e t I m a g e I n f o B l o b %
2829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2831 % SetImageInfoBlob() sets the image info blob member.
2833 % The format of the SetImageInfoBlob method is:
2835 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2836 % const size_t length)
2838 % A description of each parameter follows:
2840 % o image_info: the image info.
2844 % o length: the blob length.
2847 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2848 const size_t length)
2850 assert(image_info != (ImageInfo *) NULL);
2851 assert(image_info->signature == MagickCoreSignature);
2852 if (image_info->debug != MagickFalse)
2853 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2854 image_info->filename);
2855 image_info->blob=(void *) blob;
2856 image_info->length=length;
2860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2864 % S e t I m a g e I n f o F i l e %
2868 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2870 % SetImageInfoFile() sets the image info file member.
2872 % The format of the SetImageInfoFile method is:
2874 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2876 % A description of each parameter follows:
2878 % o image_info: the image info.
2883 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2885 assert(image_info != (ImageInfo *) NULL);
2886 assert(image_info->signature == MagickCoreSignature);
2887 if (image_info->debug != MagickFalse)
2888 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2889 image_info->filename);
2890 image_info->file=file;
2894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2898 % S e t I m a g e M a s k %
2902 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2904 % SetImageMask() associates a mask with the image. The mask must be the same
2905 % dimensions as the image.
2907 % The format of the SetImageMask method is:
2909 % MagickBooleanType SetImageMask(Image *image,const PixelMask type,
2910 % const Image *mask,ExceptionInfo *exception)
2912 % A description of each parameter follows:
2914 % o image: the image.
2916 % o type: the mask type, ReadPixelMask or WritePixelMask.
2918 % o mask: the image mask.
2920 % o exception: return any errors or warnings in this structure.
2923 MagickExport MagickBooleanType SetImageMask(Image *image,const PixelMask type,
2924 const Image *mask,ExceptionInfo *exception)
2939 assert(image != (Image *) NULL);
2940 if (image->debug != MagickFalse)
2941 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2942 assert(image->signature == MagickCoreSignature);
2943 if (mask == (const Image *) NULL)
2947 case WritePixelMask: image->write_mask=MagickFalse; break;
2948 default: image->read_mask=MagickFalse; break;
2950 return(SyncImagePixelCache(image,exception));
2954 case WritePixelMask: image->write_mask=MagickTrue; break;
2955 default: image->read_mask=MagickTrue; break;
2957 if (SyncImagePixelCache(image,exception) == MagickFalse)
2958 return(MagickFalse);
2960 mask_view=AcquireVirtualCacheView(mask,exception);
2961 image_view=AcquireAuthenticCacheView(image,exception);
2962 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2963 #pragma omp parallel for schedule(static,4) shared(status) \
2964 magick_threads(mask,image,1,1)
2966 for (y=0; y < (ssize_t) image->rows; y++)
2968 register const Quantum
2977 if (status == MagickFalse)
2979 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
2980 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2981 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2986 for (x=0; x < (ssize_t) image->columns; x++)
2991 intensity=GetPixelIntensity(mask,p);
2994 case WritePixelMask:
2996 SetPixelWriteMask(image,ClampToQuantum(QuantumRange-intensity),q);
3001 SetPixelReadMask(image,ClampToQuantum(QuantumRange-intensity),q);
3005 p+=GetPixelChannels(mask);
3006 q+=GetPixelChannels(image);
3008 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3011 mask_view=DestroyCacheView(mask_view);
3012 image_view=DestroyCacheView(image_view);
3017 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3021 % S e t I m a g e A l p h a %
3025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3027 % SetImageAlpha() sets the alpha levels of the image.
3029 % The format of the SetImageAlpha method is:
3031 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3032 % ExceptionInfo *exception)
3034 % A description of each parameter follows:
3036 % o image: the image.
3038 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3039 % fully transparent.
3042 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3043 ExceptionInfo *exception)
3054 assert(image != (Image *) NULL);
3055 if (image->debug != MagickFalse)
3056 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3057 assert(image->signature == MagickCoreSignature);
3058 image->alpha_trait=BlendPixelTrait;
3060 image_view=AcquireAuthenticCacheView(image,exception);
3061 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3062 #pragma omp parallel for schedule(static,4) shared(status) \
3063 magick_threads(image,image,image->rows,1)
3065 for (y=0; y < (ssize_t) image->rows; y++)
3073 if (status == MagickFalse)
3075 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3076 if (q == (Quantum *) NULL)
3081 for (x=0; x < (ssize_t) image->columns; x++)
3083 if (GetPixelReadMask(image,q) != 0)
3084 SetPixelAlpha(image,alpha,q);
3085 q+=GetPixelChannels(image);
3087 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3090 image_view=DestroyCacheView(image_view);
3095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3099 % 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 %
3103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3105 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3106 % image and returns the previous setting. A virtual pixel is any pixel access
3107 % that is outside the boundaries of the image cache.
3109 % The format of the SetImageVirtualPixelMethod() method is:
3111 % VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3112 % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3114 % A description of each parameter follows:
3116 % o image: the image.
3118 % o virtual_pixel_method: choose the type of virtual pixel.
3120 % o exception: return any errors or warnings in this structure.
3123 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3124 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3126 assert(image != (const Image *) NULL);
3127 assert(image->signature == MagickCoreSignature);
3128 if (image->debug != MagickFalse)
3129 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3130 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3138 % S m u s h I m a g e s %
3142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3144 % SmushImages() takes all images from the current image pointer to the end
3145 % of the image list and smushes them to each other top-to-bottom if the
3146 % stack parameter is true, otherwise left-to-right.
3148 % The current gravity setting now effects how the image is justified in the
3151 % The format of the SmushImages method is:
3153 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3154 % ExceptionInfo *exception)
3156 % A description of each parameter follows:
3158 % o images: the image sequence.
3160 % o stack: A value other than 0 stacks the images top-to-bottom.
3162 % o offset: minimum distance in pixels between images.
3164 % o exception: return any errors or warnings in this structure.
3168 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3169 const ssize_t offset,ExceptionInfo *exception)
3183 register const Quantum
3196 if (images->previous == (Image *) NULL)
3199 SetGeometry(smush_image,&right_geometry);
3200 GravityAdjustGeometry(right_image->columns,right_image->rows,
3201 right_image->gravity,&right_geometry);
3202 left_image=images->previous;
3203 SetGeometry(smush_image,&left_geometry);
3204 GravityAdjustGeometry(left_image->columns,left_image->rows,
3205 left_image->gravity,&left_geometry);
3206 gap=right_image->columns;
3207 left_view=AcquireVirtualCacheView(left_image,exception);
3208 right_view=AcquireVirtualCacheView(right_image,exception);
3209 for (y=0; y < (ssize_t) smush_image->rows; y++)
3211 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3213 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3214 if ((p == (const Quantum *) NULL) ||
3215 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3216 ((left_image->columns-x-1) >= gap))
3219 i=(ssize_t) left_image->columns-x-1;
3220 for (x=0; x < (ssize_t) right_image->columns; x++)
3222 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3224 if ((p == (const Quantum *) NULL) ||
3225 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3226 ((x+i) >= (ssize_t) gap))
3229 if ((x+i) < (ssize_t) gap)
3232 right_view=DestroyCacheView(right_view);
3233 left_view=DestroyCacheView(left_view);
3234 if (y < (ssize_t) smush_image->rows)
3236 return((ssize_t) gap-offset);
3239 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3240 const ssize_t offset,ExceptionInfo *exception)
3254 register const Quantum
3267 if (images->previous == (Image *) NULL)
3269 bottom_image=images;
3270 SetGeometry(smush_image,&bottom_geometry);
3271 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3272 bottom_image->gravity,&bottom_geometry);
3273 top_image=images->previous;
3274 SetGeometry(smush_image,&top_geometry);
3275 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3277 gap=bottom_image->rows;
3278 top_view=AcquireVirtualCacheView(top_image,exception);
3279 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3280 for (x=0; x < (ssize_t) smush_image->columns; x++)
3282 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3284 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3285 if ((p == (const Quantum *) NULL) ||
3286 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3287 ((top_image->rows-y-1) >= gap))
3290 i=(ssize_t) top_image->rows-y-1;
3291 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3293 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3295 if ((p == (const Quantum *) NULL) ||
3296 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3297 ((y+i) >= (ssize_t) gap))
3300 if ((y+i) < (ssize_t) gap)
3303 bottom_view=DestroyCacheView(bottom_view);
3304 top_view=DestroyCacheView(top_view);
3305 if (x < (ssize_t) smush_image->columns)
3307 return((ssize_t) gap-offset);
3310 MagickExport Image *SmushImages(const Image *images,
3311 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3313 #define SmushImageTag "Smush/Image"
3334 register const Image
3347 Compute maximum area of smushed area.
3349 assert(images != (Image *) NULL);
3350 assert(images->signature == MagickCoreSignature);
3351 if (images->debug != MagickFalse)
3352 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3353 assert(exception != (ExceptionInfo *) NULL);
3354 assert(exception->signature == MagickCoreSignature);
3356 alpha_trait=image->alpha_trait;
3358 width=image->columns;
3360 next=GetNextImageInList(image);
3361 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3363 if (next->alpha_trait != UndefinedPixelTrait)
3364 alpha_trait=BlendPixelTrait;
3366 if (stack != MagickFalse)
3368 if (next->columns > width)
3369 width=next->columns;
3371 if (next->previous != (Image *) NULL)
3375 width+=next->columns;
3376 if (next->previous != (Image *) NULL)
3378 if (next->rows > height)
3384 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3385 if (smush_image == (Image *) NULL)
3386 return((Image *) NULL);
3387 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3389 smush_image=DestroyImage(smush_image);
3390 return((Image *) NULL);
3392 smush_image->alpha_trait=alpha_trait;
3393 (void) SetImageBackgroundColor(smush_image,exception);
3397 for (n=0; n < (MagickOffsetType) number_images; n++)
3399 SetGeometry(smush_image,&geometry);
3400 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3401 if (stack != MagickFalse)
3403 x_offset-=geometry.x;
3404 y_offset-=SmushYGap(smush_image,image,offset,exception);
3408 x_offset-=SmushXGap(smush_image,image,offset,exception);
3409 y_offset-=geometry.y;
3411 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3412 y_offset,exception);
3413 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3414 if (proceed == MagickFalse)
3416 if (stack == MagickFalse)
3418 x_offset+=(ssize_t) image->columns;
3424 y_offset+=(ssize_t) image->rows;
3426 image=GetNextImageInList(image);
3428 if (stack == MagickFalse)
3429 smush_image->columns=(size_t) x_offset;
3431 smush_image->rows=(size_t) y_offset;
3432 if (status == MagickFalse)
3433 smush_image=DestroyImage(smush_image);
3434 return(smush_image);
3438 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3442 % S t r i p I m a g e %
3446 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3448 % StripImage() strips an image of all profiles and comments.
3450 % The format of the StripImage method is:
3452 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3454 % A description of each parameter follows:
3456 % o image: the image.
3458 % o exception: return any errors or warnings in this structure.
3461 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3466 assert(image != (Image *) NULL);
3467 if (image->debug != MagickFalse)
3468 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3470 DestroyImageProfiles(image);
3471 (void) DeleteImageProperty(image,"comment");
3472 (void) DeleteImageProperty(image,"date:create");
3473 (void) DeleteImageProperty(image,"date:modify");
3474 status=SetImageArtifact(image,"png:exclude-chunk",
3475 "cHRM,EXIF,gAMA,iCCP,iTXt,sRGB,tEXt,zCCP,zTXt,date");
3480 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3484 + S y n c I m a g e %
3488 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3490 % SyncImage() initializes the red, green, and blue intensities of each pixel
3491 % as defined by the colormap index.
3493 % The format of the SyncImage method is:
3495 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3497 % A description of each parameter follows:
3499 % o image: the image.
3501 % o exception: return any errors or warnings in this structure.
3505 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3506 MagickBooleanType *range_exception)
3508 if ((size_t) index < image->colors)
3510 *range_exception=MagickTrue;
3511 return((Quantum) 0);
3514 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3527 assert(image != (Image *) NULL);
3528 if (image->debug != MagickFalse)
3529 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3530 assert(image->signature == MagickCoreSignature);
3531 if (image->storage_class == DirectClass)
3532 return(MagickFalse);
3533 range_exception=MagickFalse;
3536 image_view=AcquireAuthenticCacheView(image,exception);
3537 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3538 #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
3539 magick_threads(image,image,image->rows,1)
3541 for (y=0; y < (ssize_t) image->rows; y++)
3552 if (status == MagickFalse)
3554 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3555 if (q == (Quantum *) NULL)
3560 for (x=0; x < (ssize_t) image->columns; x++)
3562 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3563 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
3564 q+=GetPixelChannels(image);
3566 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3569 image_view=DestroyCacheView(image_view);
3571 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3572 (void) ThrowMagickException(exception,GetMagickModule(),
3573 CorruptImageWarning,"InvalidColormapIndex","`%s'",image->filename);
3578 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3582 % S y n c I m a g e S e t t i n g s %
3586 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3588 % SyncImageSettings() syncs any image_info global options into per-image
3591 % Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
3592 % that operations and coders can find such settings. In IMv7 if a desired
3593 % per-image artifact is not set, then it will directly look for a global
3594 % option as a fallback, as such this copy is no longer needed, only the
3597 % The format of the SyncImageSettings method is:
3599 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3600 % Image *image,ExceptionInfo *exception)
3601 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3602 % Image *image,ExceptionInfo *exception)
3604 % A description of each parameter follows:
3606 % o image_info: the image info.
3608 % o image: the image.
3610 % o exception: return any errors or warnings in this structure.
3614 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3615 Image *images,ExceptionInfo *exception)
3620 assert(image_info != (const ImageInfo *) NULL);
3621 assert(image_info->signature == MagickCoreSignature);
3622 assert(images != (Image *) NULL);
3623 assert(images->signature == MagickCoreSignature);
3624 if (images->debug != MagickFalse)
3625 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3627 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3628 (void) SyncImageSettings(image_info,image,exception);
3629 (void) DeleteImageOption(image_info,"page");
3633 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3634 Image *image,ExceptionInfo *exception)
3651 assert(image_info != (const ImageInfo *) NULL);
3652 assert(image_info->signature == MagickCoreSignature);
3653 assert(image != (Image *) NULL);
3654 assert(image->signature == MagickCoreSignature);
3655 if (image->debug != MagickFalse)
3656 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3657 option=GetImageOption(image_info,"alpha-color");
3658 if (option != (const char *) NULL)
3659 (void) QueryColorCompliance(option,AllCompliance,&image->alpha_color,
3661 option=GetImageOption(image_info,"background");
3662 if (option != (const char *) NULL)
3663 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
3665 option=GetImageOption(image_info,"black-point-compensation");
3666 if (option != (const char *) NULL)
3667 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3668 MagickBooleanOptions,MagickFalse,option);
3669 option=GetImageOption(image_info,"blue-primary");
3670 if (option != (const char *) NULL)
3672 flags=ParseGeometry(option,&geometry_info);
3673 image->chromaticity.blue_primary.x=geometry_info.rho;
3674 image->chromaticity.blue_primary.y=geometry_info.sigma;
3675 if ((flags & SigmaValue) == 0)
3676 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3678 option=GetImageOption(image_info,"bordercolor");
3679 if (option != (const char *) NULL)
3680 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
3682 /* FUTURE: do not sync compose to per-image compose setting here */
3683 option=GetImageOption(image_info,"compose");
3684 if (option != (const char *) NULL)
3685 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3686 MagickFalse,option);
3688 option=GetImageOption(image_info,"compress");
3689 if (option != (const char *) NULL)
3690 image->compression=(CompressionType) ParseCommandOption(
3691 MagickCompressOptions,MagickFalse,option);
3692 option=GetImageOption(image_info,"debug");
3693 if (option != (const char *) NULL)
3694 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3695 MagickFalse,option);
3696 option=GetImageOption(image_info,"density");
3697 if (option != (const char *) NULL)
3702 flags=ParseGeometry(option,&geometry_info);
3703 image->resolution.x=geometry_info.rho;
3704 image->resolution.y=geometry_info.sigma;
3705 if ((flags & SigmaValue) == 0)
3706 image->resolution.y=image->resolution.x;
3708 option=GetImageOption(image_info,"depth");
3709 if (option != (const char *) NULL)
3710 image->depth=StringToUnsignedLong(option);
3711 option=GetImageOption(image_info,"endian");
3712 if (option != (const char *) NULL)
3713 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3714 MagickFalse,option);
3715 option=GetImageOption(image_info,"filter");
3716 if (option != (const char *) NULL)
3717 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
3718 MagickFalse,option);
3719 option=GetImageOption(image_info,"fuzz");
3720 if (option != (const char *) NULL)
3721 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3722 option=GetImageOption(image_info,"gravity");
3723 if (option != (const char *) NULL)
3724 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3725 MagickFalse,option);
3726 option=GetImageOption(image_info,"green-primary");
3727 if (option != (const char *) NULL)
3729 flags=ParseGeometry(option,&geometry_info);
3730 image->chromaticity.green_primary.x=geometry_info.rho;
3731 image->chromaticity.green_primary.y=geometry_info.sigma;
3732 if ((flags & SigmaValue) == 0)
3733 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3735 option=GetImageOption(image_info,"intent");
3736 if (option != (const char *) NULL)
3737 image->rendering_intent=(RenderingIntent) ParseCommandOption(
3738 MagickIntentOptions,MagickFalse,option);
3739 option=GetImageOption(image_info,"intensity");
3740 if (option != (const char *) NULL)
3741 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3742 MagickPixelIntensityOptions,MagickFalse,option);
3743 option=GetImageOption(image_info,"interlace");
3744 if (option != (const char *) NULL)
3745 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3746 MagickFalse,option);
3747 option=GetImageOption(image_info,"interpolate");
3748 if (option != (const char *) NULL)
3749 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
3750 MagickInterpolateOptions,MagickFalse,option);
3751 option=GetImageOption(image_info,"loop");
3752 if (option != (const char *) NULL)
3753 image->iterations=StringToUnsignedLong(option);
3754 option=GetImageOption(image_info,"orient");
3755 if (option != (const char *) NULL)
3756 image->orientation=(OrientationType) ParseCommandOption(
3757 MagickOrientationOptions,MagickFalse,option);
3758 option=GetImageOption(image_info,"page");
3759 if (option != (const char *) NULL)
3764 geometry=GetPageGeometry(option);
3765 flags=ParseAbsoluteGeometry(geometry,&image->page);
3766 geometry=DestroyString(geometry);
3768 option=GetImageOption(image_info,"quality");
3769 if (option != (const char *) NULL)
3770 image->quality=StringToUnsignedLong(option);
3771 option=GetImageOption(image_info,"red-primary");
3772 if (option != (const char *) NULL)
3774 flags=ParseGeometry(option,&geometry_info);
3775 image->chromaticity.red_primary.x=geometry_info.rho;
3776 image->chromaticity.red_primary.y=geometry_info.sigma;
3777 if ((flags & SigmaValue) == 0)
3778 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3780 if (image_info->quality != UndefinedCompressionQuality)
3781 image->quality=image_info->quality;
3782 option=GetImageOption(image_info,"scene");
3783 if (option != (const char *) NULL)
3784 image->scene=StringToUnsignedLong(option);
3785 option=GetImageOption(image_info,"taint");
3786 if (option != (const char *) NULL)
3787 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3788 MagickFalse,option);
3789 option=GetImageOption(image_info,"tile-offset");
3790 if (option != (const char *) NULL)
3795 geometry=GetPageGeometry(option);
3796 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3797 geometry=DestroyString(geometry);
3799 option=GetImageOption(image_info,"transparent-color");
3800 if (option != (const char *) NULL)
3801 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
3803 option=GetImageOption(image_info,"type");
3804 if (option != (const char *) NULL)
3805 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3807 option=GetImageOption(image_info,"units");
3808 units=image_info->units;
3809 if (option != (const char *) NULL)
3810 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
3811 MagickFalse,option);
3812 if (units != UndefinedResolution)
3814 if (image->units != units)
3815 switch (image->units)
3817 case PixelsPerInchResolution:
3819 if (units == PixelsPerCentimeterResolution)
3821 image->resolution.x/=2.54;
3822 image->resolution.y/=2.54;
3826 case PixelsPerCentimeterResolution:
3828 if (units == PixelsPerInchResolution)
3830 image->resolution.x=(double) ((size_t) (100.0*2.54*
3831 image->resolution.x+0.5))/100.0;
3832 image->resolution.y=(double) ((size_t) (100.0*2.54*
3833 image->resolution.y+0.5))/100.0;
3842 option=GetImageOption(image_info,"virtual-pixel");
3843 if (option != (const char *) NULL)
3844 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
3845 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
3847 option=GetImageOption(image_info,"white-point");
3848 if (option != (const char *) NULL)
3850 flags=ParseGeometry(option,&geometry_info);
3851 image->chromaticity.white_point.x=geometry_info.rho;
3852 image->chromaticity.white_point.y=geometry_info.sigma;
3853 if ((flags & SigmaValue) == 0)
3854 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
3857 Pointer to allow the lookup of pre-image artifact will fallback to a global
3858 option setting/define. This saves a lot of duplication of global options
3859 into per-image artifacts, while ensuring only specifically set per-image
3860 artifacts are preserved when parenthesis ends.
3862 if (image->image_info != (ImageInfo *) NULL)
3863 image->image_info=DestroyImageInfo(image->image_info);
3864 image->image_info=CloneImageInfo(image_info);