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-2015 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 BackgroundColor[] = "#ffffff", /* white */
107 BorderColor[] = "#dfdfdf", /* gray */
108 DefaultTileFrame[] = "15x15+3+3",
109 DefaultTileGeometry[] = "120x120+4+3>",
110 DefaultTileLabel[] = "%f\n%G\n%b",
111 ForegroundColor[] = "#000", /* black */
112 LoadImageTag[] = "Load/Image",
113 LoadImagesTag[] = "Load/Images",
114 MatteColor[] = "#bdbdbd", /* gray */
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(BackgroundColor,AllCompliance,
196 &image->background_color,exception);
197 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
199 (void) QueryColorCompliance(MatteColor,AllCompliance,&image->matte_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->background_color=image_info->background_color;
277 image->border_color=image_info->border_color;
278 image->matte_color=image_info->matte_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"
477 Compute maximum area of appended area.
479 assert(images != (Image *) NULL);
480 assert(images->signature == MagickCoreSignature);
481 if (images->debug != MagickFalse)
482 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
483 assert(exception != (ExceptionInfo *) NULL);
484 assert(exception->signature == MagickCoreSignature);
485 alpha_trait=images->alpha_trait;
487 width=images->columns;
489 next=GetNextImageInList(images);
490 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
492 if (next->alpha_trait != UndefinedPixelTrait)
493 alpha_trait=BlendPixelTrait;
495 if (stack != MagickFalse)
497 if (next->columns > width)
502 width+=next->columns;
503 if (next->rows > height)
509 append_image=CloneImage(images,width,height,MagickTrue,exception);
510 if (append_image == (Image *) NULL)
511 return((Image *) NULL);
512 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
514 append_image=DestroyImage(append_image);
515 return((Image *) NULL);
517 append_image->alpha_trait=alpha_trait;
518 (void) SetImageBackgroundColor(append_image,exception);
523 append_view=AcquireAuthenticCacheView(append_image,exception);
524 for (n=0; n < (MagickOffsetType) number_images; n++)
535 image=CloneImage(next,0,0,MagickTrue,exception);
536 if (image == (Image *) NULL)
538 (void) TransformImageColorspace(image,append_image->colorspace,exception);
539 SetGeometry(append_image,&geometry);
540 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
541 if (stack != MagickFalse)
542 x_offset-=geometry.x;
544 y_offset-=geometry.y;
545 image_view=AcquireVirtualCacheView(image,exception);
546 #if defined(MAGICKCORE_OPENMP_SUPPORT)
547 #pragma omp parallel for schedule(static,4) shared(status) \
548 magick_threads(image,image,image->rows,1)
550 for (y=0; y < (ssize_t) image->rows; y++)
558 register const Quantum
567 if (status == MagickFalse)
569 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
570 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
571 image->columns,1,exception);
572 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
577 GetPixelInfo(image,&pixel);
578 for (x=0; x < (ssize_t) image->columns; x++)
580 if (GetPixelReadMask(image,p) == 0)
582 SetPixelBackgoundColor(append_image,q);
583 p+=GetPixelChannels(image);
584 q+=GetPixelChannels(append_image);
587 GetPixelInfoPixel(image,p,&pixel);
588 SetPixelViaPixelInfo(append_image,&pixel,q);
589 p+=GetPixelChannels(image);
590 q+=GetPixelChannels(append_image);
592 sync=SyncCacheViewAuthenticPixels(append_view,exception);
593 if (sync == MagickFalse)
596 image_view=DestroyCacheView(image_view);
597 if (stack == MagickFalse)
599 x_offset+=(ssize_t) image->columns;
605 y_offset+=(ssize_t) image->rows;
607 image=DestroyImage(image);
608 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
609 if (proceed == MagickFalse)
611 next=GetNextImageInList(next);
613 append_view=DestroyCacheView(append_view);
614 if (status == MagickFalse)
615 append_image=DestroyImage(append_image);
616 return(append_image);
620 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
624 % C a t c h I m a g e E x c e p t i o n %
628 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
630 % CatchImageException() returns if no exceptions are found in the image
631 % sequence, otherwise it determines the most severe exception and reports
632 % it as a warning or error depending on the severity.
634 % The format of the CatchImageException method is:
636 % ExceptionType CatchImageException(Image *image)
638 % A description of each parameter follows:
640 % o image: An image sequence.
643 MagickExport ExceptionType CatchImageException(Image *image)
651 assert(image != (const Image *) NULL);
652 assert(image->signature == MagickCoreSignature);
653 if (image->debug != MagickFalse)
654 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
655 exception=AcquireExceptionInfo();
656 CatchException(exception);
657 severity=exception->severity;
658 exception=DestroyExceptionInfo(exception);
663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
667 % C l i p I m a g e P a t h %
671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
673 % ClipImagePath() sets the image clip mask based any clipping path information
676 % The format of the ClipImagePath method is:
678 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
679 % const MagickBooleanType inside,ExceptionInfo *exception)
681 % A description of each parameter follows:
683 % o image: the image.
685 % o pathname: name of clipping path resource. If name is preceded by #, use
686 % clipping path numbered by name.
688 % o inside: if non-zero, later operations take effect inside clipping path.
689 % Otherwise later operations take effect outside clipping path.
691 % o exception: return any errors or warnings in this structure.
695 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
697 return(ClipImagePath(image,"#1",MagickTrue,exception));
700 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
701 const MagickBooleanType inside,ExceptionInfo *exception)
703 #define ClipImagePathTag "ClipPath/Image"
717 assert(image != (const Image *) NULL);
718 assert(image->signature == MagickCoreSignature);
719 if (image->debug != MagickFalse)
720 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
721 assert(pathname != NULL);
722 property=AcquireString(pathname);
723 (void) FormatLocaleString(property,MagickPathExtent,"8BIM:1999,2998:%s",
725 value=GetImageProperty(image,property,exception);
726 property=DestroyString(property);
727 if (value == (const char *) NULL)
729 ThrowFileException(exception,OptionError,"NoClipPathDefined",
733 image_info=AcquireImageInfo();
734 (void) CopyMagickString(image_info->filename,image->filename,
736 (void) ConcatenateMagickString(image_info->filename,pathname,
738 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
739 image_info=DestroyImageInfo(image_info);
740 if (clip_mask == (Image *) NULL)
742 if (clip_mask->storage_class == PseudoClass)
744 (void) SyncImage(clip_mask,exception);
745 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
748 if (inside == MagickFalse)
749 (void) NegateImage(clip_mask,MagickFalse,exception);
750 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
751 "8BIM:1999,2998:%s\nPS",pathname);
752 (void) SetImageMask(image,ReadPixelMask,clip_mask,exception);
753 clip_mask=DestroyImage(clip_mask);
758 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
762 % C l o n e I m a g e %
766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
768 % CloneImage() copies an image and returns the copy as a new image object.
770 % If the specified columns and rows is 0, an exact copy of the image is
771 % returned, otherwise the pixel data is undefined and must be initialized
772 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
773 % failure, a NULL image is returned and exception describes the reason for the
776 % The format of the CloneImage method is:
778 % Image *CloneImage(const Image *image,const size_t columns,
779 % const size_t rows,const MagickBooleanType orphan,
780 % ExceptionInfo *exception)
782 % A description of each parameter follows:
784 % o image: the image.
786 % o columns: the number of columns in the cloned image.
788 % o rows: the number of rows in the cloned image.
790 % o detach: With a value other than 0, the cloned image is detached from
791 % its parent I/O stream.
793 % o exception: return any errors or warnings in this structure.
796 MagickExport Image *CloneImage(const Image *image,const size_t columns,
797 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
811 assert(image != (const Image *) NULL);
812 assert(image->signature == MagickCoreSignature);
813 if (image->debug != MagickFalse)
814 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
815 assert(exception != (ExceptionInfo *) NULL);
816 assert(exception->signature == MagickCoreSignature);
817 if ((image->columns == 0) || (image->rows == 0))
819 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
820 "NegativeOrZeroImageSize","`%s'",image->filename);
821 return((Image *) NULL);
823 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
824 if (clone_image == (Image *) NULL)
825 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
826 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
827 clone_image->signature=MagickCoreSignature;
828 clone_image->storage_class=image->storage_class;
829 clone_image->number_channels=image->number_channels;
830 clone_image->number_meta_channels=image->number_meta_channels;
831 clone_image->metacontent_extent=image->metacontent_extent;
832 clone_image->colorspace=image->colorspace;
833 clone_image->read_mask=image->read_mask;
834 clone_image->write_mask=image->write_mask;
835 clone_image->alpha_trait=image->alpha_trait;
836 clone_image->columns=image->columns;
837 clone_image->rows=image->rows;
838 clone_image->dither=image->dither;
839 if (image->colormap != (PixelInfo *) NULL)
842 Allocate and copy the image colormap.
844 clone_image->colors=image->colors;
845 length=(size_t) image->colors;
846 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
847 sizeof(*clone_image->colormap));
848 if (clone_image->colormap == (PixelInfo *) NULL)
849 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
850 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
851 sizeof(*clone_image->colormap));
853 clone_image->image_info=CloneImageInfo(image->image_info);
854 (void) CloneImageProfiles(clone_image,image);
855 (void) CloneImageProperties(clone_image,image);
856 (void) CloneImageArtifacts(clone_image,image);
857 GetTimerInfo(&clone_image->timer);
858 if (image->ascii85 != (void *) NULL)
859 Ascii85Initialize(clone_image);
860 clone_image->magick_columns=image->magick_columns;
861 clone_image->magick_rows=image->magick_rows;
862 clone_image->type=image->type;
863 clone_image->channel_mask=image->channel_mask;
864 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
865 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
867 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
868 (void) CopyMagickString(clone_image->filename,image->filename,
870 clone_image->progress_monitor=image->progress_monitor;
871 clone_image->client_data=image->client_data;
872 clone_image->reference_count=1;
873 clone_image->next=image->next;
874 clone_image->previous=image->previous;
875 clone_image->list=NewImageList();
876 if (detach == MagickFalse)
877 clone_image->blob=ReferenceBlob(image->blob);
880 clone_image->next=NewImageList();
881 clone_image->previous=NewImageList();
882 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
884 clone_image->ping=image->ping;
885 clone_image->debug=IsEventLogging();
886 clone_image->semaphore=AcquireSemaphoreInfo();
887 if ((columns == 0) || (rows == 0))
889 if (image->montage != (char *) NULL)
890 (void) CloneString(&clone_image->montage,image->montage);
891 if (image->directory != (char *) NULL)
892 (void) CloneString(&clone_image->directory,image->directory);
893 clone_image->cache=ReferencePixelCache(image->cache);
897 if (image->columns != 0)
898 scale=(double) columns/(double) image->columns;
899 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
900 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
901 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
903 if (image->rows != 0)
904 scale=(double) rows/(double) image->rows;
905 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
906 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
907 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
908 clone_image->columns=columns;
909 clone_image->rows=rows;
910 clone_image->cache=ClonePixelCache(image->cache);
915 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
919 % C l o n e I m a g e I n f o %
923 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
925 % CloneImageInfo() makes a copy of the given image info structure. If
926 % NULL is specified, a new image info structure is created initialized to
929 % The format of the CloneImageInfo method is:
931 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
933 % A description of each parameter follows:
935 % o image_info: the image info.
938 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
943 clone_info=AcquireImageInfo();
944 if (image_info == (ImageInfo *) NULL)
946 clone_info->compression=image_info->compression;
947 clone_info->temporary=image_info->temporary;
948 clone_info->adjoin=image_info->adjoin;
949 clone_info->antialias=image_info->antialias;
950 clone_info->scene=image_info->scene;
951 clone_info->number_scenes=image_info->number_scenes;
952 clone_info->depth=image_info->depth;
953 (void) CloneString(&clone_info->size,image_info->size);
954 (void) CloneString(&clone_info->extract,image_info->extract);
955 (void) CloneString(&clone_info->scenes,image_info->scenes);
956 (void) CloneString(&clone_info->page,image_info->page);
957 clone_info->interlace=image_info->interlace;
958 clone_info->endian=image_info->endian;
959 clone_info->units=image_info->units;
960 clone_info->quality=image_info->quality;
961 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
962 (void) CloneString(&clone_info->server_name,image_info->server_name);
963 (void) CloneString(&clone_info->font,image_info->font);
964 (void) CloneString(&clone_info->texture,image_info->texture);
965 (void) CloneString(&clone_info->density,image_info->density);
966 clone_info->pointsize=image_info->pointsize;
967 clone_info->fuzz=image_info->fuzz;
968 clone_info->background_color=image_info->background_color;
969 clone_info->border_color=image_info->border_color;
970 clone_info->matte_color=image_info->matte_color;
971 clone_info->transparent_color=image_info->transparent_color;
972 clone_info->dither=image_info->dither;
973 clone_info->monochrome=image_info->monochrome;
974 clone_info->colorspace=image_info->colorspace;
975 clone_info->type=image_info->type;
976 clone_info->orientation=image_info->orientation;
977 clone_info->preview_type=image_info->preview_type;
978 clone_info->group=image_info->group;
979 clone_info->ping=image_info->ping;
980 clone_info->verbose=image_info->verbose;
981 (void) CloneString(&clone_info->view,image_info->view);
982 clone_info->progress_monitor=image_info->progress_monitor;
983 clone_info->client_data=image_info->client_data;
984 clone_info->cache=image_info->cache;
985 if (image_info->cache != (void *) NULL)
986 clone_info->cache=ReferencePixelCache(image_info->cache);
987 if (image_info->profile != (void *) NULL)
988 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
989 image_info->profile);
990 SetImageInfoFile(clone_info,image_info->file);
991 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
992 clone_info->stream=image_info->stream;
993 (void) CopyMagickString(clone_info->magick,image_info->magick,
995 (void) CopyMagickString(clone_info->unique,image_info->unique,
997 (void) CopyMagickString(clone_info->zero,image_info->zero,MagickPathExtent);
998 (void) CopyMagickString(clone_info->filename,image_info->filename,
1000 clone_info->channel=image_info->channel;
1001 (void) CloneImageOptions(clone_info,image_info);
1002 clone_info->debug=IsEventLogging();
1003 clone_info->signature=image_info->signature;
1008 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1012 % C o p y I m a g e P i x e l s %
1016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1018 % CopyImagePixels() copies pixels from the source image as defined by the
1019 % geometry the destination image at the specified offset.
1021 % The format of the CopyImagePixels method is:
1023 % MagickBooleanType CopyImagePixels(Image *image,const Image *source_image,
1024 % const RectangleInfo *geometry,const OffsetInfo *offset,
1025 % ExceptionInfo *exception);
1027 % A description of each parameter follows:
1029 % o image: the destination image.
1031 % o source_image: the source image.
1033 % o geometry: define the dimensions of the source pixel rectangle.
1035 % o offset: define the offset in the destination image.
1037 % o exception: return any errors or warnings in this structure.
1040 MagickExport MagickBooleanType CopyImagePixels(Image *image,
1041 const Image *source_image,const RectangleInfo *geometry,
1042 const OffsetInfo *offset,ExceptionInfo *exception)
1044 #define CopyImageTag "Copy/Image"
1059 assert(image != (Image *) NULL);
1060 if (image->debug != MagickFalse)
1061 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1062 assert(source_image != (Image *) NULL);
1063 assert(geometry != (RectangleInfo *) NULL);
1064 assert(offset != (OffsetInfo *) NULL);
1065 if ((offset->x < 0) || (offset->y < 0) ||
1066 ((ssize_t) (offset->x+geometry->width) > (ssize_t) image->columns) ||
1067 ((ssize_t) (offset->y+geometry->height) > (ssize_t) image->rows))
1068 ThrowBinaryException(OptionError,"GeometryDoesNotContainImage",
1070 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1071 return(MagickFalse);
1077 source_view=AcquireVirtualCacheView(source_image,exception);
1078 image_view=AcquireAuthenticCacheView(image,exception);
1079 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1080 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1081 magick_threads(image,source_image,geometry->height,1)
1083 for (y=0; y < (ssize_t) geometry->height; y++)
1088 register const Quantum
1097 if (status == MagickFalse)
1099 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1100 geometry->width,1,exception);
1101 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1102 geometry->width,1,exception);
1103 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1108 for (x=0; x < (ssize_t) geometry->width; x++)
1113 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1115 PixelChannel channel=GetPixelChannelChannel(image,i);
1116 PixelTrait traits=GetPixelChannelTraits(image,channel);
1117 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1118 if ((traits == UndefinedPixelTrait) ||
1119 (source_traits == UndefinedPixelTrait))
1121 SetPixelChannel(image,channel,p[i],q);
1123 p+=GetPixelChannels(source_image);
1124 q+=GetPixelChannels(image);
1126 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1127 if (sync == MagickFalse)
1129 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1134 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1135 #pragma omp critical (MagickCore_CopyImage)
1137 proceed=SetImageProgress(image,CopyImageTag,progress++,image->rows);
1138 if (proceed == MagickFalse)
1142 source_view=DestroyCacheView(source_view);
1143 image_view=DestroyCacheView(image_view);
1148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1152 % D e s t r o y I m a g e %
1156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1158 % DestroyImage() dereferences an image, deallocating memory associated with
1159 % the image if the reference count becomes zero.
1161 % The format of the DestroyImage method is:
1163 % Image *DestroyImage(Image *image)
1165 % A description of each parameter follows:
1167 % o image: the image.
1170 MagickExport Image *DestroyImage(Image *image)
1178 assert(image != (Image *) NULL);
1179 assert(image->signature == MagickCoreSignature);
1180 if (image->debug != MagickFalse)
1181 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1182 destroy=MagickFalse;
1183 LockSemaphoreInfo(image->semaphore);
1184 image->reference_count--;
1185 if (image->reference_count == 0)
1187 UnlockSemaphoreInfo(image->semaphore);
1188 if (destroy == MagickFalse)
1189 return((Image *) NULL);
1193 DestroyImagePixels(image);
1194 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1195 if (image->montage != (char *) NULL)
1196 image->montage=DestroyString(image->montage);
1197 if (image->directory != (char *) NULL)
1198 image->directory=DestroyString(image->directory);
1199 if (image->colormap != (PixelInfo *) NULL)
1200 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1201 if (image->geometry != (char *) NULL)
1202 image->geometry=DestroyString(image->geometry);
1203 DestroyImageProfiles(image);
1204 DestroyImageProperties(image);
1205 DestroyImageArtifacts(image);
1206 if (image->ascii85 != (Ascii85Info *) NULL)
1207 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1208 if (image->image_info != (ImageInfo *) NULL)
1209 image->image_info=DestroyImageInfo(image->image_info);
1211 if (image->semaphore != (SemaphoreInfo *) NULL)
1212 RelinquishSemaphoreInfo(&image->semaphore);
1213 image->signature=(~MagickCoreSignature);
1214 image=(Image *) RelinquishMagickMemory(image);
1219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1223 % D e s t r o y I m a g e I n f o %
1227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1229 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1232 % The format of the DestroyImageInfo method is:
1234 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1236 % A description of each parameter follows:
1238 % o image_info: the image info.
1241 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1243 assert(image_info != (ImageInfo *) NULL);
1244 assert(image_info->signature == MagickCoreSignature);
1245 if (image_info->debug != MagickFalse)
1246 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1247 image_info->filename);
1248 if (image_info->size != (char *) NULL)
1249 image_info->size=DestroyString(image_info->size);
1250 if (image_info->extract != (char *) NULL)
1251 image_info->extract=DestroyString(image_info->extract);
1252 if (image_info->scenes != (char *) NULL)
1253 image_info->scenes=DestroyString(image_info->scenes);
1254 if (image_info->page != (char *) NULL)
1255 image_info->page=DestroyString(image_info->page);
1256 if (image_info->sampling_factor != (char *) NULL)
1257 image_info->sampling_factor=DestroyString(
1258 image_info->sampling_factor);
1259 if (image_info->server_name != (char *) NULL)
1260 image_info->server_name=DestroyString(
1261 image_info->server_name);
1262 if (image_info->font != (char *) NULL)
1263 image_info->font=DestroyString(image_info->font);
1264 if (image_info->texture != (char *) NULL)
1265 image_info->texture=DestroyString(image_info->texture);
1266 if (image_info->density != (char *) NULL)
1267 image_info->density=DestroyString(image_info->density);
1268 if (image_info->view != (char *) NULL)
1269 image_info->view=DestroyString(image_info->view);
1270 if (image_info->cache != (void *) NULL)
1271 image_info->cache=DestroyPixelCache(image_info->cache);
1272 if (image_info->profile != (StringInfo *) NULL)
1273 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1274 image_info->profile);
1275 DestroyImageOptions(image_info);
1276 image_info->signature=(~MagickCoreSignature);
1277 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1286 + D i s a s s o c i a t e I m a g e S t r e a m %
1290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1292 % DisassociateImageStream() disassociates the image stream. It checks if the
1293 % blob of the specified image is referenced by other images. If the reference
1294 % count is higher then 1 a new blob is assigned to the specified image.
1296 % The format of the DisassociateImageStream method is:
1298 % void DisassociateImageStream(const Image *image)
1300 % A description of each parameter follows:
1302 % o image: the image.
1305 MagickExport void DisassociateImageStream(Image *image)
1307 assert(image != (Image *) NULL);
1308 assert(image->signature == MagickCoreSignature);
1309 if (image->debug != MagickFalse)
1310 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1311 DisassociateBlob(image);
1315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1319 % G e t I m a g e I n f o %
1323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1325 % GetImageInfo() initializes image_info to default values.
1327 % The format of the GetImageInfo method is:
1329 % void GetImageInfo(ImageInfo *image_info)
1331 % A description of each parameter follows:
1333 % o image_info: the image info.
1336 MagickExport void GetImageInfo(ImageInfo *image_info)
1345 File and image dimension members.
1347 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1348 assert(image_info != (ImageInfo *) NULL);
1349 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1350 image_info->adjoin=MagickTrue;
1351 image_info->interlace=NoInterlace;
1352 image_info->channel=DefaultChannels;
1353 image_info->quality=UndefinedCompressionQuality;
1354 image_info->antialias=MagickTrue;
1355 image_info->dither=MagickTrue;
1356 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1357 if (synchronize != (const char *) NULL)
1359 image_info->synchronize=IsStringTrue(synchronize);
1360 synchronize=DestroyString(synchronize);
1362 exception=AcquireExceptionInfo();
1363 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1364 &image_info->background_color,exception);
1365 (void) QueryColorCompliance(BorderColor,AllCompliance,
1366 &image_info->border_color,exception);
1367 (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
1369 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1370 &image_info->transparent_color,exception);
1371 exception=DestroyExceptionInfo(exception);
1372 image_info->debug=IsEventLogging();
1373 image_info->signature=MagickCoreSignature;
1377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1381 % G e t I m a g e I n f o F i l e %
1385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1387 % GetImageInfoFile() returns the image info file member.
1389 % The format of the GetImageInfoFile method is:
1391 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1393 % A description of each parameter follows:
1395 % o image_info: the image info.
1398 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1400 return(image_info->file);
1404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1408 % G e t I m a g e M a s k %
1412 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1414 % GetImageMask() returns the mask associated with the image.
1416 % The format of the GetImageMask method is:
1418 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1420 % A description of each parameter follows:
1422 % o image: the image.
1425 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1443 assert(image != (Image *) NULL);
1444 if (image->debug != MagickFalse)
1445 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1446 assert(image->signature == MagickCoreSignature);
1447 mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1448 if (mask_image == (Image *) NULL)
1449 return((Image *) NULL);
1451 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1452 mask_image->read_mask=MagickFalse;
1453 mask_image->alpha_trait=UndefinedPixelTrait;
1454 image_view=AcquireVirtualCacheView(image,exception);
1455 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1456 for (y=0; y < (ssize_t) image->rows; y++)
1458 register const Quantum
1467 if (status == MagickFalse)
1469 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1470 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1472 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1477 for (x=0; x < (ssize_t) image->columns; x++)
1479 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1480 p+=GetPixelChannels(image);
1481 q+=GetPixelChannels(mask_image);
1483 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1486 mask_view=DestroyCacheView(mask_view);
1487 image_view=DestroyCacheView(image_view);
1488 if (status == MagickFalse)
1489 mask_image=DestroyImage(mask_image);
1494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1498 + G e t I m a g e R e f e r e n c e C o u n t %
1502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1504 % GetImageReferenceCount() returns the image reference count.
1506 % The format of the GetReferenceCount method is:
1508 % ssize_t GetImageReferenceCount(Image *image)
1510 % A description of each parameter follows:
1512 % o image: the image.
1515 MagickExport ssize_t GetImageReferenceCount(Image *image)
1520 assert(image != (Image *) NULL);
1521 assert(image->signature == MagickCoreSignature);
1522 if (image->debug != MagickFalse)
1523 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1524 LockSemaphoreInfo(image->semaphore);
1525 reference_count=image->reference_count;
1526 UnlockSemaphoreInfo(image->semaphore);
1527 return(reference_count);
1531 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1535 % 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 %
1539 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1541 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1542 % image. A virtual pixel is any pixel access that is outside the boundaries
1543 % of the image cache.
1545 % The format of the GetImageVirtualPixelMethod() method is:
1547 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1549 % A description of each parameter follows:
1551 % o image: the image.
1554 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1556 assert(image != (Image *) NULL);
1557 assert(image->signature == MagickCoreSignature);
1558 if (image->debug != MagickFalse)
1559 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1560 return(GetPixelCacheVirtualMethod(image));
1564 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1568 % I n t e r p r e t I m a g e F i l e n a m e %
1572 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1574 % InterpretImageFilename() interprets embedded characters in an image filename.
1575 % The filename length is returned.
1577 % The format of the InterpretImageFilename method is:
1579 % size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1580 % const char *format,int value,char *filename,ExceptionInfo *exception)
1582 % A description of each parameter follows.
1584 % o image_info: the image info..
1586 % o image: the image.
1588 % o format: A filename describing the format to use to write the numeric
1589 % argument. Only the first numeric format identifier is replaced.
1591 % o value: Numeric value to substitute into format filename.
1593 % o filename: return the formatted filename in this character buffer.
1595 % o exception: return any errors or warnings in this structure.
1598 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1599 Image *image,const char *format,int value,char *filename,
1600 ExceptionInfo *exception)
1617 canonical=MagickFalse;
1619 (void) CopyMagickString(filename,format,MagickPathExtent);
1620 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1633 value=(ssize_t) strtol(q,&q,10);
1645 (void) FormatLocaleString(filename+(p-format),(size_t)
1646 (MagickPathExtent-(p-format)),p,value);
1648 (void) ConcatenateMagickString(filename,q,MagickPathExtent);
1649 canonical=MagickTrue;
1658 pattern[MagickPathExtent];
1675 /* FUTURE: Compare update with code from InterpretImageProperties()
1676 Note that a 'filename:' property should not need depth recursion.
1678 if (strchr(p,']') == (char *) NULL)
1682 for (i=0; (i < (MagickPathExtent-1L)) && (*r != '\0'); i++)
1693 if (LocaleNCompare(pattern,"filename:",9) != 0)
1695 value=(const char *) NULL;
1696 if (image != (Image *) NULL)
1697 value=GetImageProperty(image,pattern,exception);
1698 if ((value == (const char *) NULL) && (image != (Image *) NULL))
1699 value=GetImageArtifact(image,pattern);
1700 if ((value == (const char *) NULL) &&
1701 (image_info != (ImageInfo *) NULL))
1702 value=GetImageOption(image_info,pattern);
1703 if (value == (const char *) NULL)
1708 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1709 (MagickPathExtent-(p-format-length)));
1710 length+=strlen(pattern)-1;
1712 (void) ConcatenateMagickString(filename,r+1,MagickPathExtent);
1713 canonical=MagickTrue;
1723 for (q=filename; *q != '\0'; q++)
1724 if ((*q == '%') && (*(q+1) == '%'))
1726 (void) CopyMagickString(q,q+1,(size_t) (MagickPathExtent-(q-filename)));
1727 canonical=MagickTrue;
1729 if (canonical == MagickFalse)
1730 (void) CopyMagickString(filename,format,MagickPathExtent);
1731 return(strlen(filename));
1735 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1739 % I s H i g h D y n a m i c R a n g e I m a g e %
1743 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1745 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1746 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1749 % The format of the IsHighDynamicRangeImage method is:
1751 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1752 % ExceptionInfo *exception)
1754 % A description of each parameter follows:
1756 % o image: the image.
1758 % o exception: return any errors or warnings in this structure.
1761 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1762 ExceptionInfo *exception)
1764 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1767 return(MagickFalse);
1778 assert(image != (Image *) NULL);
1779 assert(image->signature == MagickCoreSignature);
1780 if (image->debug != MagickFalse)
1781 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1783 image_view=AcquireVirtualCacheView(image,exception);
1784 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1785 #pragma omp parallel for schedule(static,4) shared(status) \
1786 magick_threads(image,image,image->rows,1)
1788 for (y=0; y < (ssize_t) image->rows; y++)
1790 register const Quantum
1796 if (status == MagickFalse)
1798 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1799 if (p == (const Quantum *) NULL)
1804 for (x=0; x < (ssize_t) image->columns; x++)
1809 if (GetPixelReadMask(image,p) == 0)
1811 p+=GetPixelChannels(image);
1814 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1822 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1823 if (traits == UndefinedPixelTrait)
1825 pixel=(double) p[i];
1826 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1827 (pixel != (double) ((QuantumAny) pixel)))
1830 p+=GetPixelChannels(image);
1831 if (i < (ssize_t) GetPixelChannels(image))
1834 if (x < (ssize_t) image->columns)
1837 image_view=DestroyCacheView(image_view);
1838 return(status != MagickFalse ? MagickFalse : MagickTrue);
1843 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1847 % I s I m a g e O b j e c t %
1851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1853 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1854 % set of image objects.
1856 % The format of the IsImageObject method is:
1858 % MagickBooleanType IsImageObject(const Image *image)
1860 % A description of each parameter follows:
1862 % o image: the image.
1865 MagickExport MagickBooleanType IsImageObject(const Image *image)
1867 register const Image
1870 assert(image != (Image *) NULL);
1871 if (image->debug != MagickFalse)
1872 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1873 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1874 if (p->signature != MagickCoreSignature)
1875 return(MagickFalse);
1880 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1884 % I s T a i n t I m a g e %
1888 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1890 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1891 % since it was first constituted.
1893 % The format of the IsTaintImage method is:
1895 % MagickBooleanType IsTaintImage(const Image *image)
1897 % A description of each parameter follows:
1899 % o image: the image.
1902 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1905 magick[MagickPathExtent],
1906 filename[MagickPathExtent];
1908 register const Image
1911 assert(image != (Image *) NULL);
1912 if (image->debug != MagickFalse)
1913 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1914 assert(image->signature == MagickCoreSignature);
1915 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1916 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1917 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1919 if (p->taint != MagickFalse)
1921 if (LocaleCompare(p->magick,magick) != 0)
1923 if (LocaleCompare(p->filename,filename) != 0)
1926 return(MagickFalse);
1930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1934 % M o d i f y I m a g e %
1938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1940 % ModifyImage() ensures that there is only a single reference to the image
1941 % to be modified, updating the provided image pointer to point to a clone of
1942 % the original image if necessary.
1944 % The format of the ModifyImage method is:
1946 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1948 % A description of each parameter follows:
1950 % o image: the image.
1952 % o exception: return any errors or warnings in this structure.
1955 MagickExport MagickBooleanType ModifyImage(Image **image,
1956 ExceptionInfo *exception)
1961 assert(image != (Image **) NULL);
1962 assert(*image != (Image *) NULL);
1963 assert((*image)->signature == MagickCoreSignature);
1964 if ((*image)->debug != MagickFalse)
1965 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1966 if (GetImageReferenceCount(*image) <= 1)
1968 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1969 LockSemaphoreInfo((*image)->semaphore);
1970 (*image)->reference_count--;
1971 UnlockSemaphoreInfo((*image)->semaphore);
1977 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1981 % N e w M a g i c k I m a g e %
1985 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1987 % NewMagickImage() creates a blank image canvas of the specified size and
1990 % The format of the NewMagickImage method is:
1992 % Image *NewMagickImage(const ImageInfo *image_info,const size_t width,
1993 % const size_t height,const PixelInfo *background,
1994 % ExceptionInfo *exception)
1996 % A description of each parameter follows:
1998 % o image: the image.
2000 % o width: the image width.
2002 % o height: the image height.
2004 % o background: the image color.
2006 % o exception: return any errors or warnings in this structure.
2009 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2010 const size_t width,const size_t height,const PixelInfo *background,
2011 ExceptionInfo *exception)
2025 assert(image_info != (const ImageInfo *) NULL);
2026 if (image_info->debug != MagickFalse)
2027 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2028 assert(image_info->signature == MagickCoreSignature);
2029 assert(background != (const PixelInfo *) NULL);
2030 image=AcquireImage(image_info,exception);
2031 image->columns=width;
2033 image->colorspace=background->colorspace;
2034 image->alpha_trait=background->alpha_trait;
2035 image->fuzz=background->fuzz;
2036 image->depth=background->depth;
2038 image_view=AcquireAuthenticCacheView(image,exception);
2039 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2040 #pragma omp parallel for schedule(static,4) shared(status) \
2041 magick_threads(image,image,image->rows,1)
2043 for (y=0; y < (ssize_t) image->rows; y++)
2051 if (status == MagickFalse)
2053 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2054 if (q == (Quantum *) NULL)
2059 for (x=0; x < (ssize_t) image->columns; x++)
2061 SetPixelViaPixelInfo(image,background,q);
2062 q+=GetPixelChannels(image);
2064 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2067 image_view=DestroyCacheView(image_view);
2068 if (status == MagickFalse)
2069 image=DestroyImage(image);
2074 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2078 % R e f e r e n c e I m a g e %
2082 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2084 % ReferenceImage() increments the reference count associated with an image
2085 % returning a pointer to the image.
2087 % The format of the ReferenceImage method is:
2089 % Image *ReferenceImage(Image *image)
2091 % A description of each parameter follows:
2093 % o image: the image.
2096 MagickExport Image *ReferenceImage(Image *image)
2098 assert(image != (Image *) NULL);
2099 if (image->debug != MagickFalse)
2100 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2101 assert(image->signature == MagickCoreSignature);
2102 LockSemaphoreInfo(image->semaphore);
2103 image->reference_count++;
2104 UnlockSemaphoreInfo(image->semaphore);
2109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2113 % R e s e t I m a g e P a g e %
2117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2119 % ResetImagePage() resets the image page canvas and position.
2121 % The format of the ResetImagePage method is:
2123 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2125 % A description of each parameter follows:
2127 % o image: the image.
2129 % o page: the relative page specification.
2132 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2140 assert(image != (Image *) NULL);
2141 assert(image->signature == MagickCoreSignature);
2142 if (image->debug != MagickFalse)
2143 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2144 flags=ParseAbsoluteGeometry(page,&geometry);
2145 if ((flags & WidthValue) != 0)
2147 if ((flags & HeightValue) == 0)
2148 geometry.height=geometry.width;
2149 image->page.width=geometry.width;
2150 image->page.height=geometry.height;
2152 if ((flags & AspectValue) != 0)
2154 if ((flags & XValue) != 0)
2155 image->page.x+=geometry.x;
2156 if ((flags & YValue) != 0)
2157 image->page.y+=geometry.y;
2161 if ((flags & XValue) != 0)
2163 image->page.x=geometry.x;
2164 if ((image->page.width == 0) && (geometry.x > 0))
2165 image->page.width=image->columns+geometry.x;
2167 if ((flags & YValue) != 0)
2169 image->page.y=geometry.y;
2170 if ((image->page.height == 0) && (geometry.y > 0))
2171 image->page.height=image->rows+geometry.y;
2178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2182 % S e t I m a g e B a c k g r o u n d C o l o r %
2186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2188 % SetImageBackgroundColor() initializes the image pixels to the image
2189 % background color. The background color is defined by the background_color
2190 % member of the image structure.
2192 % The format of the SetImage method is:
2194 % MagickBooleanType SetImageBackgroundColor(Image *image,
2195 % ExceptionInfo *exception)
2197 % A description of each parameter follows:
2199 % o image: the image.
2201 % o exception: return any errors or warnings in this structure.
2204 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2205 ExceptionInfo *exception)
2219 assert(image != (Image *) NULL);
2220 if (image->debug != MagickFalse)
2221 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2222 assert(image->signature == MagickCoreSignature);
2223 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2224 return(MagickFalse);
2225 ConformPixelInfo(image,&image->background_color,&background,exception);
2227 Set image background color.
2230 image_view=AcquireAuthenticCacheView(image,exception);
2231 for (y=0; y < (ssize_t) image->rows; y++)
2239 if (status == MagickFalse)
2241 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2242 if (q == (Quantum *) NULL)
2247 for (x=0; x < (ssize_t) image->columns; x++)
2249 SetPixelViaPixelInfo(image,&background,q);
2250 q+=GetPixelChannels(image);
2252 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2255 image_view=DestroyCacheView(image_view);
2260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2264 % S e t I m a g e C h a n n e l M a s k %
2268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2270 % SetImageChannelMask() sets the image channel mask from the specified channel
2273 % The format of the SetImageChannelMask method is:
2275 % ChannelType SetImageChannelMask(Image *image,
2276 % const ChannelType channel_mask)
2278 % A description of each parameter follows:
2280 % o image: the image.
2282 % o channel_mask: the channel mask.
2285 MagickExport ChannelType SetImageChannelMask(Image *image,
2286 const ChannelType channel_mask)
2288 return(SetPixelChannelMask(image,channel_mask));
2292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2296 % S e t I m a g e C o l o r %
2300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2302 % SetImageColor() set the entire image canvas to the specified color.
2304 % The format of the SetImageColor method is:
2306 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2307 % ExeptionInfo *exception)
2309 % A description of each parameter follows:
2311 % o image: the image.
2313 % o background: the image color.
2315 % o exception: return any errors or warnings in this structure.
2318 MagickExport MagickBooleanType SetImageColor(Image *image,
2319 const PixelInfo *color,ExceptionInfo *exception)
2330 assert(image != (Image *) NULL);
2331 if (image->debug != MagickFalse)
2332 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2333 assert(image->signature == MagickCoreSignature);
2334 assert(color != (const PixelInfo *) NULL);
2335 image->colorspace=color->colorspace;
2336 image->alpha_trait=color->alpha_trait;
2337 image->fuzz=color->fuzz;
2338 image->depth=color->depth;
2340 image_view=AcquireAuthenticCacheView(image,exception);
2341 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2342 #pragma omp parallel for schedule(static,4) shared(status) \
2343 magick_threads(image,image,image->rows,1)
2345 for (y=0; y < (ssize_t) image->rows; y++)
2353 if (status == MagickFalse)
2355 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2356 if (q == (Quantum *) NULL)
2361 for (x=0; x < (ssize_t) image->columns; x++)
2363 SetPixelViaPixelInfo(image,color,q);
2364 q+=GetPixelChannels(image);
2366 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2369 image_view=DestroyCacheView(image_view);
2374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2378 % S e t I m a g e S t o r a g e C l a s s %
2382 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2384 % SetImageStorageClass() sets the image class: DirectClass for true color
2385 % images or PseudoClass for colormapped images.
2387 % The format of the SetImageStorageClass method is:
2389 % MagickBooleanType SetImageStorageClass(Image *image,
2390 % const ClassType storage_class,ExceptionInfo *exception)
2392 % A description of each parameter follows:
2394 % o image: the image.
2396 % o storage_class: The image class.
2398 % o exception: return any errors or warnings in this structure.
2401 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2402 const ClassType storage_class,ExceptionInfo *exception)
2404 image->storage_class=storage_class;
2405 return(SyncImagePixelCache(image,exception));
2409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2413 % S e t I m a g e E x t e n t %
2417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2419 % SetImageExtent() sets the image size (i.e. columns & rows).
2421 % The format of the SetImageExtent method is:
2423 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2424 % const size_t rows,ExceptionInfo *exception)
2426 % A description of each parameter follows:
2428 % o image: the image.
2430 % o columns: The image width in pixels.
2432 % o rows: The image height in pixels.
2434 % o exception: return any errors or warnings in this structure.
2437 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2438 const size_t rows,ExceptionInfo *exception)
2440 if ((columns == 0) || (rows == 0))
2441 return(MagickFalse);
2442 image->columns=columns;
2444 if (image->depth > (8*sizeof(MagickSizeType)))
2445 ThrowBinaryException(ImageError,"ImageDepthNotSupported",image->filename);
2446 return(SyncImagePixelCache(image,exception));
2450 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2454 + S e t I m a g e I n f o %
2458 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2460 % SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
2461 % It is set to a type of image format based on the prefix or suffix of the
2462 % filename. For example, 'ps:image' returns PS indicating a Postscript image.
2463 % JPEG is returned for this filename: 'image.jpg'. The filename prefix has
2464 % precendence over the suffix. Use an optional index enclosed in brackets
2465 % after a file name to specify a desired scene of a multi-resolution image
2466 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2467 % indicates success.
2469 % The format of the SetImageInfo method is:
2471 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2472 % const unsigned int frames,ExceptionInfo *exception)
2474 % A description of each parameter follows:
2476 % o image_info: the image info.
2478 % o frames: the number of images you intend to write.
2480 % o exception: return any errors or warnings in this structure.
2483 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2484 const unsigned int frames,ExceptionInfo *exception)
2487 component[MagickPathExtent],
2488 magic[MagickPathExtent],
2513 Look for 'image.format' in filename.
2515 assert(image_info != (ImageInfo *) NULL);
2516 assert(image_info->signature == MagickCoreSignature);
2517 if (image_info->debug != MagickFalse)
2518 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2519 image_info->filename);
2521 GetPathComponent(image_info->filename,SubimagePath,component);
2522 if (*component != '\0')
2525 Look for scene specification (e.g. img0001.pcd[4]).
2527 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2529 if (IsGeometry(component) != MagickFalse)
2530 (void) CloneString(&image_info->extract,component);
2538 (void) CloneString(&image_info->scenes,component);
2539 image_info->scene=StringToUnsignedLong(image_info->scenes);
2540 image_info->number_scenes=image_info->scene;
2541 p=image_info->scenes;
2542 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2544 while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2546 first=(size_t) strtol(p,&q,10);
2548 while (isspace((int) ((unsigned char) *q)) != 0)
2551 last=(size_t) strtol(q+1,&q,10);
2554 if (first < image_info->scene)
2555 image_info->scene=first;
2556 if (last > image_info->number_scenes)
2557 image_info->number_scenes=last;
2560 image_info->number_scenes-=image_info->scene-1;
2564 if (*image_info->magick == '\0')
2565 GetPathComponent(image_info->filename,ExtensionPath,component);
2566 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2567 if (*component != '\0')
2568 if ((LocaleCompare(component,"gz") == 0) ||
2569 (LocaleCompare(component,"Z") == 0) ||
2570 (LocaleCompare(component,"svgz") == 0) ||
2571 (LocaleCompare(component,"wmz") == 0))
2574 path[MagickPathExtent];
2576 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2577 path[strlen(path)-strlen(component)-1]='\0';
2578 GetPathComponent(path,ExtensionPath,component);
2581 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2582 if (*component != '\0')
2583 if (LocaleCompare(component,"bz2") == 0)
2586 path[MagickPathExtent];
2588 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2589 path[strlen(path)-strlen(component)-1]='\0';
2590 GetPathComponent(path,ExtensionPath,component);
2593 image_info->affirm=MagickFalse;
2594 sans_exception=AcquireExceptionInfo();
2595 if (*component != '\0')
2604 *format_type_formats[] =
2627 User specified image format.
2629 (void) CopyMagickString(magic,component,MagickPathExtent);
2632 Look for explicit image formats.
2634 format_type=UndefinedFormatType;
2635 magick_info=GetMagickInfo(magic,sans_exception);
2636 if ((magick_info != (const MagickInfo *) NULL) &&
2637 (magick_info->format_type != UndefinedFormatType))
2638 format_type=magick_info->format_type;
2640 while ((format_type == UndefinedFormatType) &&
2641 (format_type_formats[i] != (char *) NULL))
2643 if ((*magic == *format_type_formats[i]) &&
2644 (LocaleCompare(magic,format_type_formats[i]) == 0))
2645 format_type=ExplicitFormatType;
2648 if (format_type == UndefinedFormatType)
2649 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2651 if (format_type == ExplicitFormatType)
2653 image_info->affirm=MagickTrue;
2654 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2656 if (LocaleCompare(magic,"RGB") == 0)
2657 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2660 Look for explicit 'format:image' in filename.
2663 GetPathComponent(image_info->filename,MagickPath,magic);
2665 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2669 User specified image format.
2672 if (IsMagickConflict(magic) == MagickFalse)
2674 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2675 if (LocaleCompare(magic,"EPHEMERAL") != 0)
2676 image_info->affirm=MagickTrue;
2678 image_info->temporary=MagickTrue;
2681 magick_info=GetMagickInfo(magic,sans_exception);
2682 sans_exception=DestroyExceptionInfo(sans_exception);
2683 if ((magick_info == (const MagickInfo *) NULL) ||
2684 (GetMagickEndianSupport(magick_info) == MagickFalse))
2685 image_info->endian=UndefinedEndian;
2686 GetPathComponent(image_info->filename,CanonicalPath,component);
2687 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2688 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2691 Test for multiple image support (e.g. image%02d.png).
2693 (void) InterpretImageFilename(image_info,(Image *) NULL,
2694 image_info->filename,(int) image_info->scene,component,exception);
2695 if ((LocaleCompare(component,image_info->filename) != 0) &&
2696 (strchr(component,'%') == (char *) NULL))
2697 image_info->adjoin=MagickFalse;
2699 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2702 Some image formats do not support multiple frames per file.
2704 magick_info=GetMagickInfo(magic,exception);
2705 if (magick_info != (const MagickInfo *) NULL)
2706 if (GetMagickAdjoin(magick_info) == MagickFalse)
2707 image_info->adjoin=MagickFalse;
2709 if (image_info->affirm != MagickFalse)
2720 Determine the image format from the first few bytes of the file.
2722 magick_size=GetMagicPatternExtent(exception);
2723 if (magick_size == 0)
2724 return(MagickFalse);
2725 image=AcquireImage(image_info,exception);
2726 (void) CopyMagickString(image->filename,image_info->filename,
2728 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2729 if (status == MagickFalse)
2731 image=DestroyImage(image);
2732 return(MagickFalse);
2734 if ((IsBlobSeekable(image) == MagickFalse) ||
2735 (IsBlobExempt(image) != MagickFalse))
2738 Copy standard input or pipe to temporary file.
2741 status=ImageToFile(image,component,exception);
2742 (void) CloseBlob(image);
2743 if (status == MagickFalse)
2745 image=DestroyImage(image);
2746 return(MagickFalse);
2748 SetImageInfoFile(image_info,(FILE *) NULL);
2749 (void) CopyMagickString(image->filename,component,MagickPathExtent);
2750 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2751 if (status == MagickFalse)
2753 image=DestroyImage(image);
2754 return(MagickFalse);
2756 (void) CopyMagickString(image_info->filename,component,
2758 image_info->temporary=MagickTrue;
2760 magick=(unsigned char *) AcquireMagickMemory(magick_size);
2761 if (magick == (unsigned char *) NULL)
2763 (void) CloseBlob(image);
2764 image=DestroyImage(image);
2765 return(MagickFalse);
2767 (void) ResetMagickMemory(magick,0,magick_size);
2768 count=ReadBlob(image,magick_size,magick);
2769 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
2770 (void) CloseBlob(image);
2771 image=DestroyImage(image);
2773 Check magic.xml configuration file.
2775 sans_exception=AcquireExceptionInfo();
2776 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
2777 magick=(unsigned char *) RelinquishMagickMemory(magick);
2778 if ((magic_info != (const MagicInfo *) NULL) &&
2779 (GetMagicName(magic_info) != (char *) NULL))
2782 Try to use magick_info that was determined earlier by the extension
2784 if ((magick_info != (const MagickInfo *) NULL) &&
2785 (GetMagickUseExtension(magick_info) != MagickFalse) &&
2786 (LocaleCompare(magick_info->module,GetMagicName(
2788 (void) CopyMagickString(image_info->magick,magick_info->name,
2792 (void) CopyMagickString(image_info->magick,GetMagicName(
2793 magic_info),MagickPathExtent);
2794 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2796 if ((magick_info == (const MagickInfo *) NULL) ||
2797 (GetMagickEndianSupport(magick_info) == MagickFalse))
2798 image_info->endian=UndefinedEndian;
2799 sans_exception=DestroyExceptionInfo(sans_exception);
2802 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2803 if ((magick_info == (const MagickInfo *) NULL) ||
2804 (GetMagickEndianSupport(magick_info) == MagickFalse))
2805 image_info->endian=UndefinedEndian;
2806 sans_exception=DestroyExceptionInfo(sans_exception);
2812 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2816 % S e t I m a g e I n f o B l o b %
2820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2822 % SetImageInfoBlob() sets the image info blob member.
2824 % The format of the SetImageInfoBlob method is:
2826 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2827 % const size_t length)
2829 % A description of each parameter follows:
2831 % o image_info: the image info.
2835 % o length: the blob length.
2838 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2839 const size_t length)
2841 assert(image_info != (ImageInfo *) NULL);
2842 assert(image_info->signature == MagickCoreSignature);
2843 if (image_info->debug != MagickFalse)
2844 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2845 image_info->filename);
2846 image_info->blob=(void *) blob;
2847 image_info->length=length;
2851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2855 % S e t I m a g e I n f o F i l e %
2859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2861 % SetImageInfoFile() sets the image info file member.
2863 % The format of the SetImageInfoFile method is:
2865 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2867 % A description of each parameter follows:
2869 % o image_info: the image info.
2874 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2876 assert(image_info != (ImageInfo *) NULL);
2877 assert(image_info->signature == MagickCoreSignature);
2878 if (image_info->debug != MagickFalse)
2879 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2880 image_info->filename);
2881 image_info->file=file;
2885 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2889 % S e t I m a g e M a s k %
2893 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2895 % SetImageMask() associates a mask with the image. The mask must be the same
2896 % dimensions as the image.
2898 % The format of the SetImageMask method is:
2900 % MagickBooleanType SetImageMask(Image *image,const PixelMask type,
2901 % const Image *mask,ExceptionInfo *exception)
2903 % A description of each parameter follows:
2905 % o image: the image.
2907 % o type: the mask type, ReadPixelMask or WritePixelMask.
2909 % o mask: the image mask.
2911 % o exception: return any errors or warnings in this structure.
2914 MagickExport MagickBooleanType SetImageMask(Image *image,const PixelMask type,
2915 const Image *mask,ExceptionInfo *exception)
2930 assert(image != (Image *) NULL);
2931 if (image->debug != MagickFalse)
2932 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2933 assert(image->signature == MagickCoreSignature);
2934 if (mask == (const Image *) NULL)
2938 case WritePixelMask: image->write_mask=MagickFalse; break;
2939 default: image->read_mask=MagickFalse; break;
2941 return(SyncImagePixelCache(image,exception));
2945 case WritePixelMask: image->write_mask=MagickTrue; break;
2946 default: image->read_mask=MagickTrue; break;
2948 if (SyncImagePixelCache(image,exception) == MagickFalse)
2949 return(MagickFalse);
2951 mask_view=AcquireVirtualCacheView(mask,exception);
2952 image_view=AcquireAuthenticCacheView(image,exception);
2953 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2954 #pragma omp parallel for schedule(static,4) shared(status) \
2955 magick_threads(mask,image,1,1)
2957 for (y=0; y < (ssize_t) image->rows; y++)
2959 register const Quantum
2968 if (status == MagickFalse)
2970 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
2971 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2972 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2977 for (x=0; x < (ssize_t) image->columns; x++)
2981 case WritePixelMask:
2983 SetPixelWriteMask(image,ClampToQuantum(GetPixelIntensity(mask,p)),q);
2988 SetPixelReadMask(image,ClampToQuantum(GetPixelIntensity(mask,p)),q);
2992 p+=GetPixelChannels(mask);
2993 q+=GetPixelChannels(image);
2995 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2998 mask_view=DestroyCacheView(mask_view);
2999 image_view=DestroyCacheView(image_view);
3004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3008 % S e t I m a g e A l p h a %
3012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3014 % SetImageAlpha() sets the alpha levels of the image.
3016 % The format of the SetImageAlpha method is:
3018 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3019 % ExceptionInfo *exception)
3021 % A description of each parameter follows:
3023 % o image: the image.
3025 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3026 % fully transparent.
3029 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3030 ExceptionInfo *exception)
3041 assert(image != (Image *) NULL);
3042 if (image->debug != MagickFalse)
3043 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3044 assert(image->signature == MagickCoreSignature);
3045 image->alpha_trait=BlendPixelTrait;
3047 image_view=AcquireAuthenticCacheView(image,exception);
3048 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3049 #pragma omp parallel for schedule(static,4) shared(status) \
3050 magick_threads(image,image,image->rows,1)
3052 for (y=0; y < (ssize_t) image->rows; y++)
3060 if (status == MagickFalse)
3062 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3063 if (q == (Quantum *) NULL)
3068 for (x=0; x < (ssize_t) image->columns; x++)
3070 if (GetPixelReadMask(image,q) != 0)
3071 SetPixelAlpha(image,alpha,q);
3072 q+=GetPixelChannels(image);
3074 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3077 image_view=DestroyCacheView(image_view);
3082 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3086 % 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 %
3090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3092 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3093 % image and returns the previous setting. A virtual pixel is any pixel access
3094 % that is outside the boundaries of the image cache.
3096 % The format of the SetImageVirtualPixelMethod() method is:
3098 % VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3099 % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3101 % A description of each parameter follows:
3103 % o image: the image.
3105 % o virtual_pixel_method: choose the type of virtual pixel.
3107 % o exception: return any errors or warnings in this structure.
3110 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3111 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3113 assert(image != (const Image *) NULL);
3114 assert(image->signature == MagickCoreSignature);
3115 if (image->debug != MagickFalse)
3116 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3117 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3125 % S m u s h I m a g e s %
3129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3131 % SmushImages() takes all images from the current image pointer to the end
3132 % of the image list and smushes them to each other top-to-bottom if the
3133 % stack parameter is true, otherwise left-to-right.
3135 % The current gravity setting now effects how the image is justified in the
3138 % The format of the SmushImages method is:
3140 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3141 % ExceptionInfo *exception)
3143 % A description of each parameter follows:
3145 % o images: the image sequence.
3147 % o stack: A value other than 0 stacks the images top-to-bottom.
3149 % o offset: minimum distance in pixels between images.
3151 % o exception: return any errors or warnings in this structure.
3155 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3156 const ssize_t offset,ExceptionInfo *exception)
3170 register const Quantum
3183 if (images->previous == (Image *) NULL)
3186 SetGeometry(smush_image,&right_geometry);
3187 GravityAdjustGeometry(right_image->columns,right_image->rows,
3188 right_image->gravity,&right_geometry);
3189 left_image=images->previous;
3190 SetGeometry(smush_image,&left_geometry);
3191 GravityAdjustGeometry(left_image->columns,left_image->rows,
3192 left_image->gravity,&left_geometry);
3193 gap=right_image->columns;
3194 left_view=AcquireVirtualCacheView(left_image,exception);
3195 right_view=AcquireVirtualCacheView(right_image,exception);
3196 for (y=0; y < (ssize_t) smush_image->rows; y++)
3198 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3200 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3201 if ((p == (const Quantum *) NULL) ||
3202 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3203 ((left_image->columns-x-1) >= gap))
3206 i=(ssize_t) left_image->columns-x-1;
3207 for (x=0; x < (ssize_t) right_image->columns; x++)
3209 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3211 if ((p == (const Quantum *) NULL) ||
3212 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3213 ((x+i) >= (ssize_t) gap))
3216 if ((x+i) < (ssize_t) gap)
3219 right_view=DestroyCacheView(right_view);
3220 left_view=DestroyCacheView(left_view);
3221 if (y < (ssize_t) smush_image->rows)
3223 return((ssize_t) gap-offset);
3226 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3227 const ssize_t offset,ExceptionInfo *exception)
3241 register const Quantum
3254 if (images->previous == (Image *) NULL)
3256 bottom_image=images;
3257 SetGeometry(smush_image,&bottom_geometry);
3258 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3259 bottom_image->gravity,&bottom_geometry);
3260 top_image=images->previous;
3261 SetGeometry(smush_image,&top_geometry);
3262 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3264 gap=bottom_image->rows;
3265 top_view=AcquireVirtualCacheView(top_image,exception);
3266 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3267 for (x=0; x < (ssize_t) smush_image->columns; x++)
3269 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3271 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3272 if ((p == (const Quantum *) NULL) ||
3273 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3274 ((top_image->rows-y-1) >= gap))
3277 i=(ssize_t) top_image->rows-y-1;
3278 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3280 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3282 if ((p == (const Quantum *) NULL) ||
3283 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3284 ((y+i) >= (ssize_t) gap))
3287 if ((y+i) < (ssize_t) gap)
3290 bottom_view=DestroyCacheView(bottom_view);
3291 top_view=DestroyCacheView(top_view);
3292 if (x < (ssize_t) smush_image->columns)
3294 return((ssize_t) gap-offset);
3297 MagickExport Image *SmushImages(const Image *images,
3298 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3300 #define SmushImageTag "Smush/Image"
3321 register const Image
3334 Compute maximum area of smushed area.
3336 assert(images != (Image *) NULL);
3337 assert(images->signature == MagickCoreSignature);
3338 if (images->debug != MagickFalse)
3339 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3340 assert(exception != (ExceptionInfo *) NULL);
3341 assert(exception->signature == MagickCoreSignature);
3343 alpha_trait=image->alpha_trait;
3345 width=image->columns;
3347 next=GetNextImageInList(image);
3348 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3350 if (next->alpha_trait != UndefinedPixelTrait)
3351 alpha_trait=BlendPixelTrait;
3353 if (stack != MagickFalse)
3355 if (next->columns > width)
3356 width=next->columns;
3358 if (next->previous != (Image *) NULL)
3362 width+=next->columns;
3363 if (next->previous != (Image *) NULL)
3365 if (next->rows > height)
3371 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3372 if (smush_image == (Image *) NULL)
3373 return((Image *) NULL);
3374 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3376 smush_image=DestroyImage(smush_image);
3377 return((Image *) NULL);
3379 smush_image->alpha_trait=alpha_trait;
3380 (void) SetImageBackgroundColor(smush_image,exception);
3384 for (n=0; n < (MagickOffsetType) number_images; n++)
3386 SetGeometry(smush_image,&geometry);
3387 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3388 if (stack != MagickFalse)
3390 x_offset-=geometry.x;
3391 y_offset-=SmushYGap(smush_image,image,offset,exception);
3395 x_offset-=SmushXGap(smush_image,image,offset,exception);
3396 y_offset-=geometry.y;
3398 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3399 y_offset,exception);
3400 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3401 if (proceed == MagickFalse)
3403 if (stack == MagickFalse)
3405 x_offset+=(ssize_t) image->columns;
3411 y_offset+=(ssize_t) image->rows;
3413 image=GetNextImageInList(image);
3415 if (stack == MagickFalse)
3416 smush_image->columns=(size_t) x_offset;
3418 smush_image->rows=(size_t) y_offset;
3419 if (status == MagickFalse)
3420 smush_image=DestroyImage(smush_image);
3421 return(smush_image);
3425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3429 % S t r i p I m a g e %
3433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3435 % StripImage() strips an image of all profiles and comments.
3437 % The format of the StripImage method is:
3439 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3441 % A description of each parameter follows:
3443 % o image: the image.
3445 % o exception: return any errors or warnings in this structure.
3448 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3453 assert(image != (Image *) NULL);
3454 if (image->debug != MagickFalse)
3455 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3457 DestroyImageProfiles(image);
3458 (void) DeleteImageProperty(image,"comment");
3459 (void) DeleteImageProperty(image,"date:create");
3460 (void) DeleteImageProperty(image,"date:modify");
3461 status=SetImageArtifact(image,"png:exclude-chunk",
3462 "EXIF,iCCP,iTXt,sRGB,tEXt,zCCP,zTXt,date");
3467 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3471 + S y n c I m a g e %
3475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3477 % SyncImage() initializes the red, green, and blue intensities of each pixel
3478 % as defined by the colormap index.
3480 % The format of the SyncImage method is:
3482 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3484 % A description of each parameter follows:
3486 % o image: the image.
3488 % o exception: return any errors or warnings in this structure.
3492 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3493 MagickBooleanType *range_exception)
3495 if ((size_t) index < image->colors)
3497 *range_exception=MagickTrue;
3498 return((Quantum) 0);
3501 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3514 assert(image != (Image *) NULL);
3515 if (image->debug != MagickFalse)
3516 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3517 assert(image->signature == MagickCoreSignature);
3518 if (image->storage_class == DirectClass)
3519 return(MagickFalse);
3520 range_exception=MagickFalse;
3523 image_view=AcquireAuthenticCacheView(image,exception);
3524 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3525 #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
3526 magick_threads(image,image,image->rows,1)
3528 for (y=0; y < (ssize_t) image->rows; y++)
3539 if (status == MagickFalse)
3541 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3542 if (q == (Quantum *) NULL)
3547 for (x=0; x < (ssize_t) image->columns; x++)
3549 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3550 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
3551 q+=GetPixelChannels(image);
3553 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3556 image_view=DestroyCacheView(image_view);
3558 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3559 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
3560 "InvalidColormapIndex","`%s'",image->filename);
3565 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3569 % S y n c I m a g e S e t t i n g s %
3573 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3575 % SyncImageSettings() syncs any image_info global options into per-image
3578 % Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
3579 % that operations and coders can find such settings. In IMv7 if a desired
3580 % per-image artifact is not set, then it will directly look for a global
3581 % option as a fallback, as such this copy is no longer needed, only the
3584 % The format of the SyncImageSettings method is:
3586 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3587 % Image *image,ExceptionInfo *exception)
3588 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3589 % Image *image,ExceptionInfo *exception)
3591 % A description of each parameter follows:
3593 % o image_info: the image info.
3595 % o image: the image.
3597 % o exception: return any errors or warnings in this structure.
3601 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3602 Image *images,ExceptionInfo *exception)
3607 assert(image_info != (const ImageInfo *) NULL);
3608 assert(image_info->signature == MagickCoreSignature);
3609 assert(images != (Image *) NULL);
3610 assert(images->signature == MagickCoreSignature);
3611 if (images->debug != MagickFalse)
3612 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3614 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3615 (void) SyncImageSettings(image_info,image,exception);
3616 (void) DeleteImageOption(image_info,"page");
3620 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3621 Image *image,ExceptionInfo *exception)
3638 assert(image_info != (const ImageInfo *) NULL);
3639 assert(image_info->signature == MagickCoreSignature);
3640 assert(image != (Image *) NULL);
3641 assert(image->signature == MagickCoreSignature);
3642 if (image->debug != MagickFalse)
3643 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3644 option=GetImageOption(image_info,"background");
3645 if (option != (const char *) NULL)
3646 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
3648 option=GetImageOption(image_info,"black-point-compensation");
3649 if (option != (const char *) NULL)
3650 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3651 MagickBooleanOptions,MagickFalse,option);
3652 option=GetImageOption(image_info,"blue-primary");
3653 if (option != (const char *) NULL)
3655 flags=ParseGeometry(option,&geometry_info);
3656 image->chromaticity.blue_primary.x=geometry_info.rho;
3657 image->chromaticity.blue_primary.y=geometry_info.sigma;
3658 if ((flags & SigmaValue) == 0)
3659 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3661 option=GetImageOption(image_info,"bordercolor");
3662 if (option != (const char *) NULL)
3663 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
3665 /* FUTURE: do not sync compose to per-image compose setting here */
3666 option=GetImageOption(image_info,"compose");
3667 if (option != (const char *) NULL)
3668 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3669 MagickFalse,option);
3671 option=GetImageOption(image_info,"compress");
3672 if (option != (const char *) NULL)
3673 image->compression=(CompressionType) ParseCommandOption(
3674 MagickCompressOptions,MagickFalse,option);
3675 option=GetImageOption(image_info,"debug");
3676 if (option != (const char *) NULL)
3677 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3678 MagickFalse,option);
3679 option=GetImageOption(image_info,"density");
3680 if (option != (const char *) NULL)
3685 flags=ParseGeometry(option,&geometry_info);
3686 image->resolution.x=geometry_info.rho;
3687 image->resolution.y=geometry_info.sigma;
3688 if ((flags & SigmaValue) == 0)
3689 image->resolution.y=image->resolution.x;
3691 option=GetImageOption(image_info,"depth");
3692 if (option != (const char *) NULL)
3693 image->depth=StringToUnsignedLong(option);
3694 option=GetImageOption(image_info,"endian");
3695 if (option != (const char *) NULL)
3696 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3697 MagickFalse,option);
3698 option=GetImageOption(image_info,"filter");
3699 if (option != (const char *) NULL)
3700 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
3701 MagickFalse,option);
3702 option=GetImageOption(image_info,"fuzz");
3703 if (option != (const char *) NULL)
3704 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3705 option=GetImageOption(image_info,"gravity");
3706 if (option != (const char *) NULL)
3707 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3708 MagickFalse,option);
3709 option=GetImageOption(image_info,"green-primary");
3710 if (option != (const char *) NULL)
3712 flags=ParseGeometry(option,&geometry_info);
3713 image->chromaticity.green_primary.x=geometry_info.rho;
3714 image->chromaticity.green_primary.y=geometry_info.sigma;
3715 if ((flags & SigmaValue) == 0)
3716 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3718 option=GetImageOption(image_info,"intent");
3719 if (option != (const char *) NULL)
3720 image->rendering_intent=(RenderingIntent) ParseCommandOption(
3721 MagickIntentOptions,MagickFalse,option);
3722 option=GetImageOption(image_info,"intensity");
3723 if (option != (const char *) NULL)
3724 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3725 MagickPixelIntensityOptions,MagickFalse,option);
3726 option=GetImageOption(image_info,"interlace");
3727 if (option != (const char *) NULL)
3728 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3729 MagickFalse,option);
3730 option=GetImageOption(image_info,"interpolate");
3731 if (option != (const char *) NULL)
3732 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
3733 MagickInterpolateOptions,MagickFalse,option);
3734 option=GetImageOption(image_info,"loop");
3735 if (option != (const char *) NULL)
3736 image->iterations=StringToUnsignedLong(option);
3737 option=GetImageOption(image_info,"mattecolor");
3738 if (option != (const char *) NULL)
3739 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
3741 option=GetImageOption(image_info,"orient");
3742 if (option != (const char *) NULL)
3743 image->orientation=(OrientationType) ParseCommandOption(
3744 MagickOrientationOptions,MagickFalse,option);
3745 option=GetImageOption(image_info,"page");
3746 if (option != (const char *) NULL)
3751 geometry=GetPageGeometry(option);
3752 flags=ParseAbsoluteGeometry(geometry,&image->page);
3753 geometry=DestroyString(geometry);
3755 option=GetImageOption(image_info,"quality");
3756 if (option != (const char *) NULL)
3757 image->quality=StringToUnsignedLong(option);
3758 option=GetImageOption(image_info,"red-primary");
3759 if (option != (const char *) NULL)
3761 flags=ParseGeometry(option,&geometry_info);
3762 image->chromaticity.red_primary.x=geometry_info.rho;
3763 image->chromaticity.red_primary.y=geometry_info.sigma;
3764 if ((flags & SigmaValue) == 0)
3765 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3767 if (image_info->quality != UndefinedCompressionQuality)
3768 image->quality=image_info->quality;
3769 option=GetImageOption(image_info,"scene");
3770 if (option != (const char *) NULL)
3771 image->scene=StringToUnsignedLong(option);
3772 option=GetImageOption(image_info,"taint");
3773 if (option != (const char *) NULL)
3774 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3775 MagickFalse,option);
3776 option=GetImageOption(image_info,"tile-offset");
3777 if (option != (const char *) NULL)
3782 geometry=GetPageGeometry(option);
3783 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3784 geometry=DestroyString(geometry);
3786 option=GetImageOption(image_info,"transparent-color");
3787 if (option != (const char *) NULL)
3788 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
3790 option=GetImageOption(image_info,"type");
3791 if (option != (const char *) NULL)
3792 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3794 option=GetImageOption(image_info,"units");
3795 units=image_info->units;
3796 if (option != (const char *) NULL)
3797 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
3798 MagickFalse,option);
3799 if (units != UndefinedResolution)
3801 if (image->units != units)
3802 switch (image->units)
3804 case PixelsPerInchResolution:
3806 if (units == PixelsPerCentimeterResolution)
3808 image->resolution.x/=2.54;
3809 image->resolution.y/=2.54;
3813 case PixelsPerCentimeterResolution:
3815 if (units == PixelsPerInchResolution)
3817 image->resolution.x=(double) ((size_t) (100.0*2.54*
3818 image->resolution.x+0.5))/100.0;
3819 image->resolution.y=(double) ((size_t) (100.0*2.54*
3820 image->resolution.y+0.5))/100.0;
3829 option=GetImageOption(image_info,"virtual-pixel");
3830 if (option != (const char *) NULL)
3831 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
3832 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
3834 option=GetImageOption(image_info,"white-point");
3835 if (option != (const char *) NULL)
3837 flags=ParseGeometry(option,&geometry_info);
3838 image->chromaticity.white_point.x=geometry_info.rho;
3839 image->chromaticity.white_point.y=geometry_info.sigma;
3840 if ((flags & SigmaValue) == 0)
3841 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
3844 Pointer to allow the lookup of pre-image artifact will fallback to a global
3845 option setting/define. This saves a lot of duplication of global options
3846 into per-image artifacts, while ensuring only specifically set per-image
3847 artifacts are preserved when parenthesis ends.
3849 if (image->image_info != (ImageInfo *) NULL)
3850 image->image_info=DestroyImageInfo(image->image_info);
3851 image->image_info=CloneImageInfo(image_info);