2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % IIIII M M AAA GGGG EEEEE %
8 % I M M M AAAAA G GG EEE %
10 % IIIII M M A A GGGG EEEEE %
13 % MagickCore Image Methods %
20 % Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/animate.h"
45 #include "MagickCore/artifact.h"
46 #include "MagickCore/attribute.h"
47 #include "MagickCore/blob.h"
48 #include "MagickCore/blob-private.h"
49 #include "MagickCore/cache.h"
50 #include "MagickCore/cache-private.h"
51 #include "MagickCore/cache-view.h"
52 #include "MagickCore/client.h"
53 #include "MagickCore/color.h"
54 #include "MagickCore/color-private.h"
55 #include "MagickCore/colormap.h"
56 #include "MagickCore/colorspace.h"
57 #include "MagickCore/colorspace-private.h"
58 #include "MagickCore/composite.h"
59 #include "MagickCore/composite-private.h"
60 #include "MagickCore/compress.h"
61 #include "MagickCore/constitute.h"
62 #include "MagickCore/display.h"
63 #include "MagickCore/draw.h"
64 #include "MagickCore/enhance.h"
65 #include "MagickCore/exception.h"
66 #include "MagickCore/exception-private.h"
67 #include "MagickCore/gem.h"
68 #include "MagickCore/geometry.h"
69 #include "MagickCore/histogram.h"
70 #include "MagickCore/image-private.h"
71 #include "MagickCore/list.h"
72 #include "MagickCore/magic.h"
73 #include "MagickCore/magick.h"
74 #include "MagickCore/magick-private.h"
75 #include "MagickCore/memory_.h"
76 #include "MagickCore/module.h"
77 #include "MagickCore/monitor.h"
78 #include "MagickCore/monitor-private.h"
79 #include "MagickCore/option.h"
80 #include "MagickCore/paint.h"
81 #include "MagickCore/pixel-accessor.h"
82 #include "MagickCore/profile.h"
83 #include "MagickCore/property.h"
84 #include "MagickCore/quantize.h"
85 #include "MagickCore/random_.h"
86 #include "MagickCore/resource_.h"
87 #include "MagickCore/segment.h"
88 #include "MagickCore/semaphore.h"
89 #include "MagickCore/signature-private.h"
90 #include "MagickCore/statistic.h"
91 #include "MagickCore/string_.h"
92 #include "MagickCore/string-private.h"
93 #include "MagickCore/thread-private.h"
94 #include "MagickCore/threshold.h"
95 #include "MagickCore/timer.h"
96 #include "MagickCore/token.h"
97 #include "MagickCore/utility.h"
98 #include "MagickCore/utility-private.h"
99 #include "MagickCore/version.h"
100 #include "MagickCore/xwindow-private.h"
103 Constant declaration.
106 AlphaColor[] = "#bdbdbd", /* gray */
107 BackgroundColor[] = "#ffffff", /* white */
108 BorderColor[] = "#dfdfdf", /* gray */
109 DefaultTileFrame[] = "15x15+3+3",
110 DefaultTileGeometry[] = "120x120+4+3>",
111 DefaultTileLabel[] = "%f\n%G\n%b",
112 ForegroundColor[] = "#000", /* black */
113 LoadImageTag[] = "Load/Image",
114 LoadImagesTag[] = "Load/Images",
115 PSDensityGeometry[] = "72.0x72.0",
116 PSPageGeometry[] = "612x792",
117 SaveImageTag[] = "Save/Image",
118 SaveImagesTag[] = "Save/Images",
119 TransparentColor[] = "#00000000"; /* transparent black */
122 DefaultResolution = 72.0;
125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 % A c q u i r e I m a g e %
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 % AcquireImage() returns a pointer to an image structure initialized to
138 % The format of the AcquireImage method is:
140 % Image *AcquireImage(const ImageInfo *image_info,ExceptionInfo *exception)
142 % A description of each parameter follows:
144 % o image_info: Many of the image default values are set from this
145 % structure. For example, filename, compression, depth, background color,
148 % o exception: return any errors or warnings in this structure.
151 MagickExport Image *AcquireImage(const ImageInfo *image_info,
152 ExceptionInfo *exception)
164 Allocate image structure.
166 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
167 image=(Image *) AcquireMagickMemory(sizeof(*image));
168 if (image == (Image *) NULL)
169 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
170 (void) ResetMagickMemory(image,0,sizeof(*image));
172 Initialize Image structure.
174 (void) CopyMagickString(image->magick,"MIFF",MagickPathExtent);
175 image->storage_class=DirectClass;
176 image->depth=MAGICKCORE_QUANTUM_DEPTH;
177 image->colorspace=sRGBColorspace;
178 image->rendering_intent=PerceptualIntent;
179 image->gamma=1.000f/2.200f;
180 image->chromaticity.red_primary.x=0.6400f;
181 image->chromaticity.red_primary.y=0.3300f;
182 image->chromaticity.red_primary.z=0.0300f;
183 image->chromaticity.green_primary.x=0.3000f;
184 image->chromaticity.green_primary.y=0.6000f;
185 image->chromaticity.green_primary.z=0.1000f;
186 image->chromaticity.blue_primary.x=0.1500f;
187 image->chromaticity.blue_primary.y=0.0600f;
188 image->chromaticity.blue_primary.z=0.7900f;
189 image->chromaticity.white_point.x=0.3127f;
190 image->chromaticity.white_point.y=0.3290f;
191 image->chromaticity.white_point.z=0.3583f;
192 image->interlace=NoInterlace;
193 image->ticks_per_second=UndefinedTicksPerSecond;
194 image->compose=OverCompositeOp;
195 (void) QueryColorCompliance(AlphaColor,AllCompliance,&image->alpha_color,
197 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
198 &image->background_color,exception);
199 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
201 (void) QueryColorCompliance(TransparentColor,AllCompliance,
202 &image->transparent_color,exception);
203 GetTimerInfo(&image->timer);
204 image->cache=AcquirePixelCache(0);
205 image->channel_mask=DefaultChannels;
206 image->channel_map=AcquirePixelChannelMap();
207 image->blob=CloneBlobInfo((BlobInfo *) NULL);
208 image->timestamp=time((time_t *) NULL);
209 image->debug=IsEventLogging();
210 image->reference_count=1;
211 image->semaphore=AcquireSemaphoreInfo();
212 image->signature=MagickCoreSignature;
213 if (image_info == (ImageInfo *) NULL)
218 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
220 (void) CopyMagickString(image->filename,image_info->filename,
222 (void) CopyMagickString(image->magick_filename,image_info->filename,
224 (void) CopyMagickString(image->magick,image_info->magick,MagickPathExtent);
225 if (image_info->size != (char *) NULL)
227 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
228 image->columns=image->extract_info.width;
229 image->rows=image->extract_info.height;
230 image->offset=image->extract_info.x;
231 image->extract_info.x=0;
232 image->extract_info.y=0;
234 if (image_info->extract != (char *) NULL)
239 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
240 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
242 image->extract_info=geometry;
243 Swap(image->columns,image->extract_info.width);
244 Swap(image->rows,image->extract_info.height);
247 image->compression=image_info->compression;
248 image->quality=image_info->quality;
249 image->endian=image_info->endian;
250 image->interlace=image_info->interlace;
251 image->units=image_info->units;
252 if (image_info->density != (char *) NULL)
257 flags=ParseGeometry(image_info->density,&geometry_info);
258 image->resolution.x=geometry_info.rho;
259 image->resolution.y=geometry_info.sigma;
260 if ((flags & SigmaValue) == 0)
261 image->resolution.y=image->resolution.x;
263 if (image_info->page != (char *) NULL)
268 image->page=image->extract_info;
269 geometry=GetPageGeometry(image_info->page);
270 (void) ParseAbsoluteGeometry(geometry,&image->page);
271 geometry=DestroyString(geometry);
273 if (image_info->depth != 0)
274 image->depth=image_info->depth;
275 image->dither=image_info->dither;
276 image->alpha_color=image_info->alpha_color;
277 image->background_color=image_info->background_color;
278 image->border_color=image_info->border_color;
279 image->transparent_color=image_info->transparent_color;
280 image->ping=image_info->ping;
281 image->progress_monitor=image_info->progress_monitor;
282 image->client_data=image_info->client_data;
283 if (image_info->cache != (void *) NULL)
284 ClonePixelCacheMethods(image->cache,image_info->cache);
286 Set all global options that map to per-image settings.
288 (void) SyncImageSettings(image_info,image,exception);
290 Global options that are only set for new images.
292 option=GetImageOption(image_info,"delay");
293 if (option != (const char *) NULL)
298 flags=ParseGeometry(option,&geometry_info);
299 if ((flags & GreaterValue) != 0)
301 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
302 image->delay=(size_t) floor(geometry_info.rho+0.5);
305 if ((flags & LessValue) != 0)
307 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
308 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
311 image->delay=(size_t) floor(geometry_info.rho+0.5);
312 if ((flags & SigmaValue) != 0)
313 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
315 option=GetImageOption(image_info,"dispose");
316 if (option != (const char *) NULL)
317 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
327 % A c q u i r e I m a g e I n f o %
331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
333 % AcquireImageInfo() allocates the ImageInfo structure.
335 % The format of the AcquireImageInfo method is:
337 % ImageInfo *AcquireImageInfo(void)
340 MagickExport ImageInfo *AcquireImageInfo(void)
345 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
346 if (image_info == (ImageInfo *) NULL)
347 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
348 GetImageInfo(image_info);
353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
357 % A c q u i r e N e x t I m a g e %
361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363 % AcquireNextImage() initializes the next image in a sequence to
364 % default values. The next member of image points to the newly allocated
365 % image. If there is a memory shortage, next is assigned NULL.
367 % The format of the AcquireNextImage method is:
369 % void AcquireNextImage(const ImageInfo *image_info,Image *image,
370 % ExceptionInfo *exception)
372 % A description of each parameter follows:
374 % o image_info: Many of the image default values are set from this
375 % structure. For example, filename, compression, depth, background color,
378 % o image: the image.
380 % o exception: return any errors or warnings in this structure.
383 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image,
384 ExceptionInfo *exception)
387 Allocate image structure.
389 assert(image != (Image *) NULL);
390 assert(image->signature == MagickCoreSignature);
391 if (image->debug != MagickFalse)
392 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
393 image->next=AcquireImage(image_info,exception);
394 if (GetNextImageInList(image) == (Image *) NULL)
396 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
398 if (image_info != (ImageInfo *) NULL)
399 (void) CopyMagickString(GetNextImageInList(image)->filename,
400 image_info->filename,MagickPathExtent);
401 DestroyBlob(GetNextImageInList(image));
402 image->next->blob=ReferenceBlob(image->blob);
403 image->next->endian=image->endian;
404 image->next->scene=image->scene+1;
405 image->next->previous=image;
409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
413 % A p p e n d I m a g e s %
417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
419 % AppendImages() takes all images from the current image pointer to the end
420 % of the image list and appends them to each other top-to-bottom if the
421 % stack parameter is true, otherwise left-to-right.
423 % The current gravity setting effects how the image is justified in the
426 % The format of the AppendImages method is:
428 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
429 % ExceptionInfo *exception)
431 % A description of each parameter follows:
433 % o images: the image sequence.
435 % o stack: A value other than 0 stacks the images top-to-bottom.
437 % o exception: return any errors or warnings in this structure.
440 MagickExport Image *AppendImages(const Image *images,
441 const MagickBooleanType stack,ExceptionInfo *exception)
443 #define AppendImageTag "Append/Image"
478 Compute maximum area of appended area.
480 assert(images != (Image *) NULL);
481 assert(images->signature == MagickCoreSignature);
482 if (images->debug != MagickFalse)
483 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
484 assert(exception != (ExceptionInfo *) NULL);
485 assert(exception->signature == MagickCoreSignature);
486 alpha_trait=images->alpha_trait;
488 width=images->columns;
491 next=GetNextImageInList(images);
492 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
494 if (next->depth > depth)
496 if (next->alpha_trait != UndefinedPixelTrait)
497 alpha_trait=BlendPixelTrait;
499 if (stack != MagickFalse)
501 if (next->columns > width)
506 width+=next->columns;
507 if (next->rows > height)
513 append_image=CloneImage(images,width,height,MagickTrue,exception);
514 if (append_image == (Image *) NULL)
515 return((Image *) NULL);
516 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
518 append_image=DestroyImage(append_image);
519 return((Image *) NULL);
521 append_image->depth=depth;
522 append_image->alpha_trait=alpha_trait;
523 (void) SetImageBackgroundColor(append_image,exception);
528 append_view=AcquireAuthenticCacheView(append_image,exception);
529 for (n=0; n < (MagickOffsetType) number_images; n++)
540 image=CloneImage(next,0,0,MagickTrue,exception);
541 if (image == (Image *) NULL)
543 (void) TransformImageColorspace(image,append_image->colorspace,exception);
544 SetGeometry(append_image,&geometry);
545 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
546 if (stack != MagickFalse)
547 x_offset-=geometry.x;
549 y_offset-=geometry.y;
550 image_view=AcquireVirtualCacheView(image,exception);
551 #if defined(MAGICKCORE_OPENMP_SUPPORT)
552 #pragma omp parallel for schedule(static,4) shared(status) \
553 magick_threads(image,image,image->rows,1)
555 for (y=0; y < (ssize_t) image->rows; y++)
563 register const Quantum
572 if (status == MagickFalse)
574 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
575 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
576 image->columns,1,exception);
577 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
582 GetPixelInfo(image,&pixel);
583 for (x=0; x < (ssize_t) image->columns; x++)
585 if (GetPixelReadMask(image,p) == 0)
587 SetPixelBackgoundColor(append_image,q);
588 p+=GetPixelChannels(image);
589 q+=GetPixelChannels(append_image);
592 GetPixelInfoPixel(image,p,&pixel);
593 SetPixelViaPixelInfo(append_image,&pixel,q);
594 p+=GetPixelChannels(image);
595 q+=GetPixelChannels(append_image);
597 sync=SyncCacheViewAuthenticPixels(append_view,exception);
598 if (sync == MagickFalse)
601 image_view=DestroyCacheView(image_view);
602 if (stack == MagickFalse)
604 x_offset+=(ssize_t) image->columns;
610 y_offset+=(ssize_t) image->rows;
612 image=DestroyImage(image);
613 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
614 if (proceed == MagickFalse)
616 next=GetNextImageInList(next);
618 append_view=DestroyCacheView(append_view);
619 if (status == MagickFalse)
620 append_image=DestroyImage(append_image);
621 return(append_image);
625 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
629 % C a t c h I m a g e E x c e p t i o n %
633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
635 % CatchImageException() returns if no exceptions are found in the image
636 % sequence, otherwise it determines the most severe exception and reports
637 % it as a warning or error depending on the severity.
639 % The format of the CatchImageException method is:
641 % ExceptionType CatchImageException(Image *image)
643 % A description of each parameter follows:
645 % o image: An image sequence.
648 MagickExport ExceptionType CatchImageException(Image *image)
656 assert(image != (const Image *) NULL);
657 assert(image->signature == MagickCoreSignature);
658 if (image->debug != MagickFalse)
659 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
660 exception=AcquireExceptionInfo();
661 CatchException(exception);
662 severity=exception->severity;
663 exception=DestroyExceptionInfo(exception);
668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
672 % C l i p I m a g e P a t h %
676 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
678 % ClipImagePath() sets the image clip mask based any clipping path information
681 % The format of the ClipImagePath method is:
683 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
684 % const MagickBooleanType inside,ExceptionInfo *exception)
686 % A description of each parameter follows:
688 % o image: the image.
690 % o pathname: name of clipping path resource. If name is preceded by #, use
691 % clipping path numbered by name.
693 % o inside: if non-zero, later operations take effect inside clipping path.
694 % Otherwise later operations take effect outside clipping path.
696 % o exception: return any errors or warnings in this structure.
700 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
702 return(ClipImagePath(image,"#1",MagickTrue,exception));
705 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
706 const MagickBooleanType inside,ExceptionInfo *exception)
708 #define ClipImagePathTag "ClipPath/Image"
722 assert(image != (const Image *) NULL);
723 assert(image->signature == MagickCoreSignature);
724 if (image->debug != MagickFalse)
725 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
726 assert(pathname != NULL);
727 property=AcquireString(pathname);
728 (void) FormatLocaleString(property,MagickPathExtent,"8BIM:1999,2998:%s",
730 value=GetImageProperty(image,property,exception);
731 property=DestroyString(property);
732 if (value == (const char *) NULL)
734 ThrowFileException(exception,OptionError,"NoClipPathDefined",
738 image_info=AcquireImageInfo();
739 (void) CopyMagickString(image_info->filename,image->filename,
741 (void) ConcatenateMagickString(image_info->filename,pathname,
743 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
744 image_info=DestroyImageInfo(image_info);
745 if (clip_mask == (Image *) NULL)
747 if (clip_mask->storage_class == PseudoClass)
749 (void) SyncImage(clip_mask,exception);
750 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
753 if (inside == MagickFalse)
754 (void) NegateImage(clip_mask,MagickFalse,exception);
755 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
756 "8BIM:1999,2998:%s\nPS",pathname);
757 (void) SetImageMask(image,ReadPixelMask,clip_mask,exception);
758 clip_mask=DestroyImage(clip_mask);
763 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
767 % C l o n e I m a g e %
771 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
773 % CloneImage() copies an image and returns the copy as a new image object.
775 % If the specified columns and rows is 0, an exact copy of the image is
776 % returned, otherwise the pixel data is undefined and must be initialized
777 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
778 % failure, a NULL image is returned and exception describes the reason for the
781 % The format of the CloneImage method is:
783 % Image *CloneImage(const Image *image,const size_t columns,
784 % const size_t rows,const MagickBooleanType orphan,
785 % ExceptionInfo *exception)
787 % A description of each parameter follows:
789 % o image: the image.
791 % o columns: the number of columns in the cloned image.
793 % o rows: the number of rows in the cloned image.
795 % o detach: With a value other than 0, the cloned image is detached from
796 % its parent I/O stream.
798 % o exception: return any errors or warnings in this structure.
801 MagickExport Image *CloneImage(const Image *image,const size_t columns,
802 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
816 assert(image != (const Image *) NULL);
817 assert(image->signature == MagickCoreSignature);
818 if (image->debug != MagickFalse)
819 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
820 assert(exception != (ExceptionInfo *) NULL);
821 assert(exception->signature == MagickCoreSignature);
822 if ((image->columns == 0) || (image->rows == 0))
824 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
825 "NegativeOrZeroImageSize","`%s'",image->filename);
826 return((Image *) NULL);
828 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
829 if (clone_image == (Image *) NULL)
830 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
831 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
832 clone_image->signature=MagickCoreSignature;
833 clone_image->storage_class=image->storage_class;
834 clone_image->number_channels=image->number_channels;
835 clone_image->number_meta_channels=image->number_meta_channels;
836 clone_image->metacontent_extent=image->metacontent_extent;
837 clone_image->colorspace=image->colorspace;
838 clone_image->read_mask=image->read_mask;
839 clone_image->write_mask=image->write_mask;
840 clone_image->alpha_trait=image->alpha_trait;
841 clone_image->columns=image->columns;
842 clone_image->rows=image->rows;
843 clone_image->dither=image->dither;
844 if (image->colormap != (PixelInfo *) NULL)
847 Allocate and copy the image colormap.
849 clone_image->colors=image->colors;
850 length=(size_t) image->colors;
851 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
852 sizeof(*clone_image->colormap));
853 if (clone_image->colormap == (PixelInfo *) NULL)
854 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
855 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
856 sizeof(*clone_image->colormap));
858 clone_image->image_info=CloneImageInfo(image->image_info);
859 (void) CloneImageProfiles(clone_image,image);
860 (void) CloneImageProperties(clone_image,image);
861 (void) CloneImageArtifacts(clone_image,image);
862 GetTimerInfo(&clone_image->timer);
863 if (image->ascii85 != (void *) NULL)
864 Ascii85Initialize(clone_image);
865 clone_image->magick_columns=image->magick_columns;
866 clone_image->magick_rows=image->magick_rows;
867 clone_image->type=image->type;
868 clone_image->channel_mask=image->channel_mask;
869 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
870 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
872 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
873 (void) CopyMagickString(clone_image->filename,image->filename,
875 clone_image->progress_monitor=image->progress_monitor;
876 clone_image->client_data=image->client_data;
877 clone_image->reference_count=1;
878 clone_image->next=image->next;
879 clone_image->previous=image->previous;
880 clone_image->list=NewImageList();
881 if (detach == MagickFalse)
882 clone_image->blob=ReferenceBlob(image->blob);
885 clone_image->next=NewImageList();
886 clone_image->previous=NewImageList();
887 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
889 clone_image->ping=image->ping;
890 clone_image->debug=IsEventLogging();
891 clone_image->semaphore=AcquireSemaphoreInfo();
892 if ((columns == 0) || (rows == 0))
894 if (image->montage != (char *) NULL)
895 (void) CloneString(&clone_image->montage,image->montage);
896 if (image->directory != (char *) NULL)
897 (void) CloneString(&clone_image->directory,image->directory);
898 clone_image->cache=ReferencePixelCache(image->cache);
902 if (image->columns != 0)
903 scale=(double) columns/(double) image->columns;
904 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
905 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
906 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
908 if (image->rows != 0)
909 scale=(double) rows/(double) image->rows;
910 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
911 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
912 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
913 clone_image->columns=columns;
914 clone_image->rows=rows;
915 clone_image->cache=ClonePixelCache(image->cache);
920 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
924 % C l o n e I m a g e I n f o %
928 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
930 % CloneImageInfo() makes a copy of the given image info structure. If
931 % NULL is specified, a new image info structure is created initialized to
934 % The format of the CloneImageInfo method is:
936 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
938 % A description of each parameter follows:
940 % o image_info: the image info.
943 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
948 clone_info=AcquireImageInfo();
949 if (image_info == (ImageInfo *) NULL)
951 clone_info->compression=image_info->compression;
952 clone_info->temporary=image_info->temporary;
953 clone_info->adjoin=image_info->adjoin;
954 clone_info->antialias=image_info->antialias;
955 clone_info->scene=image_info->scene;
956 clone_info->number_scenes=image_info->number_scenes;
957 clone_info->depth=image_info->depth;
958 (void) CloneString(&clone_info->size,image_info->size);
959 (void) CloneString(&clone_info->extract,image_info->extract);
960 (void) CloneString(&clone_info->scenes,image_info->scenes);
961 (void) CloneString(&clone_info->page,image_info->page);
962 clone_info->interlace=image_info->interlace;
963 clone_info->endian=image_info->endian;
964 clone_info->units=image_info->units;
965 clone_info->quality=image_info->quality;
966 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
967 (void) CloneString(&clone_info->server_name,image_info->server_name);
968 (void) CloneString(&clone_info->font,image_info->font);
969 (void) CloneString(&clone_info->texture,image_info->texture);
970 (void) CloneString(&clone_info->density,image_info->density);
971 clone_info->pointsize=image_info->pointsize;
972 clone_info->fuzz=image_info->fuzz;
973 clone_info->alpha_color=image_info->alpha_color;
974 clone_info->background_color=image_info->background_color;
975 clone_info->border_color=image_info->border_color;
976 clone_info->transparent_color=image_info->transparent_color;
977 clone_info->dither=image_info->dither;
978 clone_info->monochrome=image_info->monochrome;
979 clone_info->colorspace=image_info->colorspace;
980 clone_info->type=image_info->type;
981 clone_info->orientation=image_info->orientation;
982 clone_info->preview_type=image_info->preview_type;
983 clone_info->group=image_info->group;
984 clone_info->ping=image_info->ping;
985 clone_info->verbose=image_info->verbose;
986 clone_info->progress_monitor=image_info->progress_monitor;
987 clone_info->client_data=image_info->client_data;
988 clone_info->cache=image_info->cache;
989 if (image_info->cache != (void *) NULL)
990 clone_info->cache=ReferencePixelCache(image_info->cache);
991 if (image_info->profile != (void *) NULL)
992 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
993 image_info->profile);
994 SetImageInfoFile(clone_info,image_info->file);
995 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
996 clone_info->stream=image_info->stream;
997 (void) CopyMagickString(clone_info->magick,image_info->magick,
999 (void) CopyMagickString(clone_info->unique,image_info->unique,
1001 (void) CopyMagickString(clone_info->zero,image_info->zero,MagickPathExtent);
1002 (void) CopyMagickString(clone_info->filename,image_info->filename,
1004 clone_info->channel=image_info->channel;
1005 (void) CloneImageOptions(clone_info,image_info);
1006 clone_info->debug=IsEventLogging();
1007 clone_info->signature=image_info->signature;
1012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1016 % C o p y I m a g e P i x e l s %
1020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1022 % CopyImagePixels() copies pixels from the source image as defined by the
1023 % geometry the destination image at the specified offset.
1025 % The format of the CopyImagePixels method is:
1027 % MagickBooleanType CopyImagePixels(Image *image,const Image *source_image,
1028 % const RectangleInfo *geometry,const OffsetInfo *offset,
1029 % ExceptionInfo *exception);
1031 % A description of each parameter follows:
1033 % o image: the destination image.
1035 % o source_image: the source image.
1037 % o geometry: define the dimensions of the source pixel rectangle.
1039 % o offset: define the offset in the destination image.
1041 % o exception: return any errors or warnings in this structure.
1044 MagickExport MagickBooleanType CopyImagePixels(Image *image,
1045 const Image *source_image,const RectangleInfo *geometry,
1046 const OffsetInfo *offset,ExceptionInfo *exception)
1048 #define CopyImageTag "Copy/Image"
1063 assert(image != (Image *) NULL);
1064 if (image->debug != MagickFalse)
1065 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1066 assert(source_image != (Image *) NULL);
1067 assert(geometry != (RectangleInfo *) NULL);
1068 assert(offset != (OffsetInfo *) NULL);
1069 if ((offset->x < 0) || (offset->y < 0) ||
1070 ((ssize_t) (offset->x+geometry->width) > (ssize_t) image->columns) ||
1071 ((ssize_t) (offset->y+geometry->height) > (ssize_t) image->rows))
1072 ThrowBinaryException(OptionError,"GeometryDoesNotContainImage",
1074 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1075 return(MagickFalse);
1081 source_view=AcquireVirtualCacheView(source_image,exception);
1082 image_view=AcquireAuthenticCacheView(image,exception);
1083 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1084 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1085 magick_threads(image,source_image,geometry->height,1)
1087 for (y=0; y < (ssize_t) geometry->height; y++)
1092 register const Quantum
1101 if (status == MagickFalse)
1103 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1104 geometry->width,1,exception);
1105 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1106 geometry->width,1,exception);
1107 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1112 for (x=0; x < (ssize_t) geometry->width; x++)
1117 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1119 PixelChannel channel=GetPixelChannelChannel(image,i);
1120 PixelTrait traits=GetPixelChannelTraits(image,channel);
1121 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1122 if ((traits == UndefinedPixelTrait) ||
1123 (source_traits == UndefinedPixelTrait))
1125 SetPixelChannel(image,channel,p[i],q);
1127 p+=GetPixelChannels(source_image);
1128 q+=GetPixelChannels(image);
1130 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1131 if (sync == MagickFalse)
1133 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1138 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1139 #pragma omp critical (MagickCore_CopyImage)
1141 proceed=SetImageProgress(image,CopyImageTag,progress++,image->rows);
1142 if (proceed == MagickFalse)
1146 source_view=DestroyCacheView(source_view);
1147 image_view=DestroyCacheView(image_view);
1152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1156 % D e s t r o y I m a g e %
1160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1162 % DestroyImage() dereferences an image, deallocating memory associated with
1163 % the image if the reference count becomes zero.
1165 % The format of the DestroyImage method is:
1167 % Image *DestroyImage(Image *image)
1169 % A description of each parameter follows:
1171 % o image: the image.
1174 MagickExport Image *DestroyImage(Image *image)
1182 assert(image != (Image *) NULL);
1183 assert(image->signature == MagickCoreSignature);
1184 if (image->debug != MagickFalse)
1185 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1186 destroy=MagickFalse;
1187 LockSemaphoreInfo(image->semaphore);
1188 image->reference_count--;
1189 if (image->reference_count == 0)
1191 UnlockSemaphoreInfo(image->semaphore);
1192 if (destroy == MagickFalse)
1193 return((Image *) NULL);
1197 DestroyImagePixels(image);
1198 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1199 if (image->montage != (char *) NULL)
1200 image->montage=DestroyString(image->montage);
1201 if (image->directory != (char *) NULL)
1202 image->directory=DestroyString(image->directory);
1203 if (image->colormap != (PixelInfo *) NULL)
1204 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1205 if (image->geometry != (char *) NULL)
1206 image->geometry=DestroyString(image->geometry);
1207 DestroyImageProfiles(image);
1208 DestroyImageProperties(image);
1209 DestroyImageArtifacts(image);
1210 if (image->ascii85 != (Ascii85Info *) NULL)
1211 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1212 if (image->image_info != (ImageInfo *) NULL)
1213 image->image_info=DestroyImageInfo(image->image_info);
1215 if (image->semaphore != (SemaphoreInfo *) NULL)
1216 RelinquishSemaphoreInfo(&image->semaphore);
1217 image->signature=(~MagickCoreSignature);
1218 image=(Image *) RelinquishMagickMemory(image);
1223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1227 % D e s t r o y I m a g e I n f o %
1231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1233 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1236 % The format of the DestroyImageInfo method is:
1238 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1240 % A description of each parameter follows:
1242 % o image_info: the image info.
1245 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1247 assert(image_info != (ImageInfo *) NULL);
1248 assert(image_info->signature == MagickCoreSignature);
1249 if (image_info->debug != MagickFalse)
1250 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1251 image_info->filename);
1252 if (image_info->size != (char *) NULL)
1253 image_info->size=DestroyString(image_info->size);
1254 if (image_info->extract != (char *) NULL)
1255 image_info->extract=DestroyString(image_info->extract);
1256 if (image_info->scenes != (char *) NULL)
1257 image_info->scenes=DestroyString(image_info->scenes);
1258 if (image_info->page != (char *) NULL)
1259 image_info->page=DestroyString(image_info->page);
1260 if (image_info->sampling_factor != (char *) NULL)
1261 image_info->sampling_factor=DestroyString(
1262 image_info->sampling_factor);
1263 if (image_info->server_name != (char *) NULL)
1264 image_info->server_name=DestroyString(
1265 image_info->server_name);
1266 if (image_info->font != (char *) NULL)
1267 image_info->font=DestroyString(image_info->font);
1268 if (image_info->texture != (char *) NULL)
1269 image_info->texture=DestroyString(image_info->texture);
1270 if (image_info->density != (char *) NULL)
1271 image_info->density=DestroyString(image_info->density);
1272 if (image_info->cache != (void *) NULL)
1273 image_info->cache=DestroyPixelCache(image_info->cache);
1274 if (image_info->profile != (StringInfo *) NULL)
1275 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1276 image_info->profile);
1277 DestroyImageOptions(image_info);
1278 image_info->signature=(~MagickCoreSignature);
1279 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1284 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1288 + D i s a s s o c i a t e I m a g e S t r e a m %
1292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1294 % DisassociateImageStream() disassociates the image stream. It checks if the
1295 % blob of the specified image is referenced by other images. If the reference
1296 % count is higher then 1 a new blob is assigned to the specified image.
1298 % The format of the DisassociateImageStream method is:
1300 % void DisassociateImageStream(const Image *image)
1302 % A description of each parameter follows:
1304 % o image: the image.
1307 MagickExport void DisassociateImageStream(Image *image)
1309 assert(image != (Image *) NULL);
1310 assert(image->signature == MagickCoreSignature);
1311 if (image->debug != MagickFalse)
1312 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1313 DisassociateBlob(image);
1317 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1321 % G e t I m a g e I n f o %
1325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1327 % GetImageInfo() initializes image_info to default values.
1329 % The format of the GetImageInfo method is:
1331 % void GetImageInfo(ImageInfo *image_info)
1333 % A description of each parameter follows:
1335 % o image_info: the image info.
1338 MagickExport void GetImageInfo(ImageInfo *image_info)
1347 File and image dimension members.
1349 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1350 assert(image_info != (ImageInfo *) NULL);
1351 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1352 image_info->adjoin=MagickTrue;
1353 image_info->interlace=NoInterlace;
1354 image_info->channel=DefaultChannels;
1355 image_info->quality=UndefinedCompressionQuality;
1356 image_info->antialias=MagickTrue;
1357 image_info->dither=MagickTrue;
1358 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1359 if (synchronize != (const char *) NULL)
1361 image_info->synchronize=IsStringTrue(synchronize);
1362 synchronize=DestroyString(synchronize);
1364 exception=AcquireExceptionInfo();
1365 (void) QueryColorCompliance(AlphaColor,AllCompliance,&image_info->alpha_color,
1367 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1368 &image_info->background_color,exception);
1369 (void) QueryColorCompliance(BorderColor,AllCompliance,
1370 &image_info->border_color,exception);
1371 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1372 &image_info->transparent_color,exception);
1373 exception=DestroyExceptionInfo(exception);
1374 image_info->debug=IsEventLogging();
1375 image_info->signature=MagickCoreSignature;
1379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1383 % G e t I m a g e I n f o F i l e %
1387 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1389 % GetImageInfoFile() returns the image info file member.
1391 % The format of the GetImageInfoFile method is:
1393 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1395 % A description of each parameter follows:
1397 % o image_info: the image info.
1400 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1402 return(image_info->file);
1406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1410 % G e t I m a g e M a s k %
1414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1416 % GetImageMask() returns the mask associated with the image.
1418 % The format of the GetImageMask method is:
1420 % Image *GetImageMask(const Image *image,const PixelMask type,
1421 % ExceptionInfo *exception)
1423 % A description of each parameter follows:
1425 % o image: the image.
1427 % o type: the mask type, ReadPixelMask or WritePixelMask.
1430 MagickExport Image *GetImageMask(const Image *image,const PixelMask type,
1431 ExceptionInfo *exception)
1449 assert(image != (Image *) NULL);
1450 if (image->debug != MagickFalse)
1451 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1452 assert(image->signature == MagickCoreSignature);
1453 mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1454 if (mask_image == (Image *) NULL)
1455 return((Image *) NULL);
1457 mask_image->alpha_trait=UndefinedPixelTrait;
1458 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1459 mask_image->read_mask=MagickFalse;
1460 image_view=AcquireVirtualCacheView(image,exception);
1461 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1462 for (y=0; y < (ssize_t) image->rows; y++)
1464 register const Quantum
1473 if (status == MagickFalse)
1475 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1476 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1478 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1483 for (x=0; x < (ssize_t) image->columns; x++)
1487 case WritePixelMask:
1489 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1494 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1498 p+=GetPixelChannels(image);
1499 q+=GetPixelChannels(mask_image);
1501 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1504 mask_view=DestroyCacheView(mask_view);
1505 image_view=DestroyCacheView(image_view);
1506 if (status == MagickFalse)
1507 mask_image=DestroyImage(mask_image);
1512 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1516 + G e t I m a g e R e f e r e n c e C o u n t %
1520 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1522 % GetImageReferenceCount() returns the image reference count.
1524 % The format of the GetReferenceCount method is:
1526 % ssize_t GetImageReferenceCount(Image *image)
1528 % A description of each parameter follows:
1530 % o image: the image.
1533 MagickExport ssize_t GetImageReferenceCount(Image *image)
1538 assert(image != (Image *) NULL);
1539 assert(image->signature == MagickCoreSignature);
1540 if (image->debug != MagickFalse)
1541 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1542 LockSemaphoreInfo(image->semaphore);
1543 reference_count=image->reference_count;
1544 UnlockSemaphoreInfo(image->semaphore);
1545 return(reference_count);
1549 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1553 % 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 %
1557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1559 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1560 % image. A virtual pixel is any pixel access that is outside the boundaries
1561 % of the image cache.
1563 % The format of the GetImageVirtualPixelMethod() method is:
1565 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1567 % A description of each parameter follows:
1569 % o image: the image.
1572 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1574 assert(image != (Image *) NULL);
1575 assert(image->signature == MagickCoreSignature);
1576 if (image->debug != MagickFalse)
1577 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1578 return(GetPixelCacheVirtualMethod(image));
1582 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1586 % I n t e r p r e t I m a g e F i l e n a m e %
1590 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1592 % InterpretImageFilename() interprets embedded characters in an image filename.
1593 % The filename length is returned.
1595 % The format of the InterpretImageFilename method is:
1597 % size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1598 % const char *format,int value,char *filename,ExceptionInfo *exception)
1600 % A description of each parameter follows.
1602 % o image_info: the image info..
1604 % o image: the image.
1606 % o format: A filename describing the format to use to write the numeric
1607 % argument. Only the first numeric format identifier is replaced.
1609 % o value: Numeric value to substitute into format filename.
1611 % o filename: return the formatted filename in this character buffer.
1613 % o exception: return any errors or warnings in this structure.
1616 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1617 Image *image,const char *format,int value,char *filename,
1618 ExceptionInfo *exception)
1635 canonical=MagickFalse;
1637 (void) CopyMagickString(filename,format,MagickPathExtent);
1638 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1651 value=(ssize_t) strtol(q,&q,10);
1663 (void) FormatLocaleString(filename+(p-format),(size_t)
1664 (MagickPathExtent-(p-format)),p,value);
1666 (void) ConcatenateMagickString(filename,q,MagickPathExtent);
1667 canonical=MagickTrue;
1676 pattern[MagickPathExtent];
1693 /* FUTURE: Compare update with code from InterpretImageProperties()
1694 Note that a 'filename:' property should not need depth recursion.
1696 if (strchr(p,']') == (char *) NULL)
1700 for (i=0; (i < (MagickPathExtent-1L)) && (*r != '\0'); i++)
1711 if (LocaleNCompare(pattern,"filename:",9) != 0)
1713 value=(const char *) NULL;
1714 if (image != (Image *) NULL)
1715 value=GetImageProperty(image,pattern,exception);
1716 if ((value == (const char *) NULL) && (image != (Image *) NULL))
1717 value=GetImageArtifact(image,pattern);
1718 if ((value == (const char *) NULL) &&
1719 (image_info != (ImageInfo *) NULL))
1720 value=GetImageOption(image_info,pattern);
1721 if (value == (const char *) NULL)
1726 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1727 (MagickPathExtent-(p-format-length)));
1728 length+=strlen(pattern)-1;
1730 (void) ConcatenateMagickString(filename,r+1,MagickPathExtent);
1731 canonical=MagickTrue;
1741 for (q=filename; *q != '\0'; q++)
1742 if ((*q == '%') && (*(q+1) == '%'))
1744 (void) CopyMagickString(q,q+1,(size_t) (MagickPathExtent-(q-filename)));
1745 canonical=MagickTrue;
1747 if (canonical == MagickFalse)
1748 (void) CopyMagickString(filename,format,MagickPathExtent);
1749 return(strlen(filename));
1753 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1757 % I s H i g h D y n a m i c R a n g e I m a g e %
1761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1763 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1764 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1767 % The format of the IsHighDynamicRangeImage method is:
1769 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1770 % ExceptionInfo *exception)
1772 % A description of each parameter follows:
1774 % o image: the image.
1776 % o exception: return any errors or warnings in this structure.
1779 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1780 ExceptionInfo *exception)
1782 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1785 return(MagickFalse);
1796 assert(image != (Image *) NULL);
1797 assert(image->signature == MagickCoreSignature);
1798 if (image->debug != MagickFalse)
1799 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1801 image_view=AcquireVirtualCacheView(image,exception);
1802 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1803 #pragma omp parallel for schedule(static,4) shared(status) \
1804 magick_threads(image,image,image->rows,1)
1806 for (y=0; y < (ssize_t) image->rows; y++)
1808 register const Quantum
1814 if (status == MagickFalse)
1816 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1817 if (p == (const Quantum *) NULL)
1822 for (x=0; x < (ssize_t) image->columns; x++)
1827 if (GetPixelReadMask(image,p) == 0)
1829 p+=GetPixelChannels(image);
1832 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1840 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1841 if (traits == UndefinedPixelTrait)
1843 pixel=(double) p[i];
1844 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1845 (pixel != (double) ((QuantumAny) pixel)))
1848 p+=GetPixelChannels(image);
1849 if (i < (ssize_t) GetPixelChannels(image))
1852 if (x < (ssize_t) image->columns)
1855 image_view=DestroyCacheView(image_view);
1856 return(status != MagickFalse ? MagickFalse : MagickTrue);
1861 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1865 % I s I m a g e O b j e c t %
1869 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1871 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1872 % set of image objects.
1874 % The format of the IsImageObject method is:
1876 % MagickBooleanType IsImageObject(const Image *image)
1878 % A description of each parameter follows:
1880 % o image: the image.
1883 MagickExport MagickBooleanType IsImageObject(const Image *image)
1885 register const Image
1888 assert(image != (Image *) NULL);
1889 if (image->debug != MagickFalse)
1890 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1891 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1892 if (p->signature != MagickCoreSignature)
1893 return(MagickFalse);
1898 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1902 % I s T a i n t I m a g e %
1906 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1908 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1909 % since it was first constituted.
1911 % The format of the IsTaintImage method is:
1913 % MagickBooleanType IsTaintImage(const Image *image)
1915 % A description of each parameter follows:
1917 % o image: the image.
1920 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1923 magick[MagickPathExtent],
1924 filename[MagickPathExtent];
1926 register const Image
1929 assert(image != (Image *) NULL);
1930 if (image->debug != MagickFalse)
1931 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1932 assert(image->signature == MagickCoreSignature);
1933 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1934 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1935 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1937 if (p->taint != MagickFalse)
1939 if (LocaleCompare(p->magick,magick) != 0)
1941 if (LocaleCompare(p->filename,filename) != 0)
1944 return(MagickFalse);
1948 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1952 % M o d i f y I m a g e %
1956 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1958 % ModifyImage() ensures that there is only a single reference to the image
1959 % to be modified, updating the provided image pointer to point to a clone of
1960 % the original image if necessary.
1962 % The format of the ModifyImage method is:
1964 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1966 % A description of each parameter follows:
1968 % o image: the image.
1970 % o exception: return any errors or warnings in this structure.
1973 MagickExport MagickBooleanType ModifyImage(Image **image,
1974 ExceptionInfo *exception)
1979 assert(image != (Image **) NULL);
1980 assert(*image != (Image *) NULL);
1981 assert((*image)->signature == MagickCoreSignature);
1982 if ((*image)->debug != MagickFalse)
1983 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1984 if (GetImageReferenceCount(*image) <= 1)
1986 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1987 LockSemaphoreInfo((*image)->semaphore);
1988 (*image)->reference_count--;
1989 UnlockSemaphoreInfo((*image)->semaphore);
1995 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999 % N e w M a g i c k I m a g e %
2003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2005 % NewMagickImage() creates a blank image canvas of the specified size and
2008 % The format of the NewMagickImage method is:
2010 % Image *NewMagickImage(const ImageInfo *image_info,const size_t width,
2011 % const size_t height,const PixelInfo *background,
2012 % ExceptionInfo *exception)
2014 % A description of each parameter follows:
2016 % o image: the image.
2018 % o width: the image width.
2020 % o height: the image height.
2022 % o background: the image color.
2024 % o exception: return any errors or warnings in this structure.
2027 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2028 const size_t width,const size_t height,const PixelInfo *background,
2029 ExceptionInfo *exception)
2043 assert(image_info != (const ImageInfo *) NULL);
2044 if (image_info->debug != MagickFalse)
2045 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2046 assert(image_info->signature == MagickCoreSignature);
2047 assert(background != (const PixelInfo *) NULL);
2048 image=AcquireImage(image_info,exception);
2049 image->columns=width;
2051 image->colorspace=background->colorspace;
2052 image->alpha_trait=background->alpha_trait;
2053 image->fuzz=background->fuzz;
2054 image->depth=background->depth;
2056 image_view=AcquireAuthenticCacheView(image,exception);
2057 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2058 #pragma omp parallel for schedule(static,4) shared(status) \
2059 magick_threads(image,image,image->rows,1)
2061 for (y=0; y < (ssize_t) image->rows; y++)
2069 if (status == MagickFalse)
2071 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2072 if (q == (Quantum *) NULL)
2077 for (x=0; x < (ssize_t) image->columns; x++)
2079 SetPixelViaPixelInfo(image,background,q);
2080 q+=GetPixelChannels(image);
2082 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2085 image_view=DestroyCacheView(image_view);
2086 if (status == MagickFalse)
2087 image=DestroyImage(image);
2092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2096 % R e f e r e n c e I m a g e %
2100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2102 % ReferenceImage() increments the reference count associated with an image
2103 % returning a pointer to the image.
2105 % The format of the ReferenceImage method is:
2107 % Image *ReferenceImage(Image *image)
2109 % A description of each parameter follows:
2111 % o image: the image.
2114 MagickExport Image *ReferenceImage(Image *image)
2116 assert(image != (Image *) NULL);
2117 if (image->debug != MagickFalse)
2118 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2119 assert(image->signature == MagickCoreSignature);
2120 LockSemaphoreInfo(image->semaphore);
2121 image->reference_count++;
2122 UnlockSemaphoreInfo(image->semaphore);
2127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2131 % R e s e t I m a g e P a g e %
2135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2137 % ResetImagePage() resets the image page canvas and position.
2139 % The format of the ResetImagePage method is:
2141 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2143 % A description of each parameter follows:
2145 % o image: the image.
2147 % o page: the relative page specification.
2150 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2158 assert(image != (Image *) NULL);
2159 assert(image->signature == MagickCoreSignature);
2160 if (image->debug != MagickFalse)
2161 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2162 flags=ParseAbsoluteGeometry(page,&geometry);
2163 if ((flags & WidthValue) != 0)
2165 if ((flags & HeightValue) == 0)
2166 geometry.height=geometry.width;
2167 image->page.width=geometry.width;
2168 image->page.height=geometry.height;
2170 if ((flags & AspectValue) != 0)
2172 if ((flags & XValue) != 0)
2173 image->page.x+=geometry.x;
2174 if ((flags & YValue) != 0)
2175 image->page.y+=geometry.y;
2179 if ((flags & XValue) != 0)
2181 image->page.x=geometry.x;
2182 if ((image->page.width == 0) && (geometry.x > 0))
2183 image->page.width=image->columns+geometry.x;
2185 if ((flags & YValue) != 0)
2187 image->page.y=geometry.y;
2188 if ((image->page.height == 0) && (geometry.y > 0))
2189 image->page.height=image->rows+geometry.y;
2196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2200 % S e t I m a g e B a c k g r o u n d C o l o r %
2204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2206 % SetImageBackgroundColor() initializes the image pixels to the image
2207 % background color. The background color is defined by the background_color
2208 % member of the image structure.
2210 % The format of the SetImage method is:
2212 % MagickBooleanType SetImageBackgroundColor(Image *image,
2213 % ExceptionInfo *exception)
2215 % A description of each parameter follows:
2217 % o image: the image.
2219 % o exception: return any errors or warnings in this structure.
2222 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2223 ExceptionInfo *exception)
2237 assert(image != (Image *) NULL);
2238 if (image->debug != MagickFalse)
2239 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2240 assert(image->signature == MagickCoreSignature);
2241 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2242 return(MagickFalse);
2243 ConformPixelInfo(image,&image->background_color,&background,exception);
2245 Set image background color.
2248 image_view=AcquireAuthenticCacheView(image,exception);
2249 for (y=0; y < (ssize_t) image->rows; y++)
2257 if (status == MagickFalse)
2259 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2260 if (q == (Quantum *) NULL)
2265 for (x=0; x < (ssize_t) image->columns; x++)
2267 SetPixelViaPixelInfo(image,&background,q);
2268 q+=GetPixelChannels(image);
2270 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2273 image_view=DestroyCacheView(image_view);
2278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2282 % S e t I m a g e C h a n n e l M a s k %
2286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2288 % SetImageChannelMask() sets the image channel mask from the specified channel
2291 % The format of the SetImageChannelMask method is:
2293 % ChannelType SetImageChannelMask(Image *image,
2294 % const ChannelType channel_mask)
2296 % A description of each parameter follows:
2298 % o image: the image.
2300 % o channel_mask: the channel mask.
2303 MagickExport ChannelType SetImageChannelMask(Image *image,
2304 const ChannelType channel_mask)
2306 return(SetPixelChannelMask(image,channel_mask));
2310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2314 % S e t I m a g e C o l o r %
2318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2320 % SetImageColor() set the entire image canvas to the specified color.
2322 % The format of the SetImageColor method is:
2324 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2325 % ExeptionInfo *exception)
2327 % A description of each parameter follows:
2329 % o image: the image.
2331 % o background: the image color.
2333 % o exception: return any errors or warnings in this structure.
2336 MagickExport MagickBooleanType SetImageColor(Image *image,
2337 const PixelInfo *color,ExceptionInfo *exception)
2348 assert(image != (Image *) NULL);
2349 if (image->debug != MagickFalse)
2350 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2351 assert(image->signature == MagickCoreSignature);
2352 assert(color != (const PixelInfo *) NULL);
2353 image->colorspace=color->colorspace;
2354 image->alpha_trait=color->alpha_trait;
2355 image->fuzz=color->fuzz;
2356 image->depth=color->depth;
2358 image_view=AcquireAuthenticCacheView(image,exception);
2359 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2360 #pragma omp parallel for schedule(static,4) shared(status) \
2361 magick_threads(image,image,image->rows,1)
2363 for (y=0; y < (ssize_t) image->rows; y++)
2371 if (status == MagickFalse)
2373 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2374 if (q == (Quantum *) NULL)
2379 for (x=0; x < (ssize_t) image->columns; x++)
2381 SetPixelViaPixelInfo(image,color,q);
2382 q+=GetPixelChannels(image);
2384 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2387 image_view=DestroyCacheView(image_view);
2392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2396 % S e t I m a g e S t o r a g e C l a s s %
2400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2402 % SetImageStorageClass() sets the image class: DirectClass for true color
2403 % images or PseudoClass for colormapped images.
2405 % The format of the SetImageStorageClass method is:
2407 % MagickBooleanType SetImageStorageClass(Image *image,
2408 % const ClassType storage_class,ExceptionInfo *exception)
2410 % A description of each parameter follows:
2412 % o image: the image.
2414 % o storage_class: The image class.
2416 % o exception: return any errors or warnings in this structure.
2419 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2420 const ClassType storage_class,ExceptionInfo *exception)
2422 image->storage_class=storage_class;
2423 return(SyncImagePixelCache(image,exception));
2427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2431 % S e t I m a g e E x t e n t %
2435 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2437 % SetImageExtent() sets the image size (i.e. columns & rows).
2439 % The format of the SetImageExtent method is:
2441 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2442 % const size_t rows,ExceptionInfo *exception)
2444 % A description of each parameter follows:
2446 % o image: the image.
2448 % o columns: The image width in pixels.
2450 % o rows: The image height in pixels.
2452 % o exception: return any errors or warnings in this structure.
2455 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2456 const size_t rows,ExceptionInfo *exception)
2458 if ((columns == 0) || (rows == 0))
2459 return(MagickFalse);
2460 image->columns=columns;
2462 if (image->depth > (8*sizeof(MagickSizeType)))
2463 ThrowBinaryException(ImageError,"ImageDepthNotSupported",image->filename);
2464 return(SyncImagePixelCache(image,exception));
2468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2472 + S e t I m a g e I n f o %
2476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2478 % SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
2479 % It is set to a type of image format based on the prefix or suffix of the
2480 % filename. For example, 'ps:image' returns PS indicating a Postscript image.
2481 % JPEG is returned for this filename: 'image.jpg'. The filename prefix has
2482 % precendence over the suffix. Use an optional index enclosed in brackets
2483 % after a file name to specify a desired scene of a multi-resolution image
2484 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2485 % indicates success.
2487 % The format of the SetImageInfo method is:
2489 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2490 % const unsigned int frames,ExceptionInfo *exception)
2492 % A description of each parameter follows:
2494 % o image_info: the image info.
2496 % o frames: the number of images you intend to write.
2498 % o exception: return any errors or warnings in this structure.
2501 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2502 const unsigned int frames,ExceptionInfo *exception)
2505 component[MagickPathExtent],
2506 magic[MagickPathExtent],
2531 Look for 'image.format' in filename.
2533 assert(image_info != (ImageInfo *) NULL);
2534 assert(image_info->signature == MagickCoreSignature);
2535 if (image_info->debug != MagickFalse)
2536 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2537 image_info->filename);
2539 GetPathComponent(image_info->filename,SubimagePath,component);
2540 if (*component != '\0')
2543 Look for scene specification (e.g. img0001.pcd[4]).
2545 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2547 if (IsGeometry(component) != MagickFalse)
2548 (void) CloneString(&image_info->extract,component);
2556 (void) CloneString(&image_info->scenes,component);
2557 image_info->scene=StringToUnsignedLong(image_info->scenes);
2558 image_info->number_scenes=image_info->scene;
2559 p=image_info->scenes;
2560 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2562 while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2564 first=(size_t) strtol(p,&q,10);
2566 while (isspace((int) ((unsigned char) *q)) != 0)
2569 last=(size_t) strtol(q+1,&q,10);
2572 if (first < image_info->scene)
2573 image_info->scene=first;
2574 if (last > image_info->number_scenes)
2575 image_info->number_scenes=last;
2578 image_info->number_scenes-=image_info->scene-1;
2582 if (*image_info->magick == '\0')
2583 GetPathComponent(image_info->filename,ExtensionPath,component);
2584 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2585 if (*component != '\0')
2586 if ((LocaleCompare(component,"gz") == 0) ||
2587 (LocaleCompare(component,"Z") == 0) ||
2588 (LocaleCompare(component,"svgz") == 0) ||
2589 (LocaleCompare(component,"wmz") == 0))
2592 path[MagickPathExtent];
2594 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2595 path[strlen(path)-strlen(component)-1]='\0';
2596 GetPathComponent(path,ExtensionPath,component);
2599 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2600 if (*component != '\0')
2601 if (LocaleCompare(component,"bz2") == 0)
2604 path[MagickPathExtent];
2606 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
2607 path[strlen(path)-strlen(component)-1]='\0';
2608 GetPathComponent(path,ExtensionPath,component);
2611 image_info->affirm=MagickFalse;
2612 sans_exception=AcquireExceptionInfo();
2613 if (*component != '\0')
2622 *format_type_formats[] =
2645 User specified image format.
2647 (void) CopyMagickString(magic,component,MagickPathExtent);
2650 Look for explicit image formats.
2652 format_type=UndefinedFormatType;
2653 magick_info=GetMagickInfo(magic,sans_exception);
2654 if ((magick_info != (const MagickInfo *) NULL) &&
2655 (magick_info->format_type != UndefinedFormatType))
2656 format_type=magick_info->format_type;
2658 while ((format_type == UndefinedFormatType) &&
2659 (format_type_formats[i] != (char *) NULL))
2661 if ((*magic == *format_type_formats[i]) &&
2662 (LocaleCompare(magic,format_type_formats[i]) == 0))
2663 format_type=ExplicitFormatType;
2666 if (format_type == UndefinedFormatType)
2667 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2669 if (format_type == ExplicitFormatType)
2671 image_info->affirm=MagickTrue;
2672 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2674 if (LocaleCompare(magic,"RGB") == 0)
2675 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2678 Look for explicit 'format:image' in filename.
2681 GetPathComponent(image_info->filename,MagickPath,magic);
2683 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2687 User specified image format.
2690 if (IsMagickConflict(magic) == MagickFalse)
2692 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2693 if (LocaleCompare(magic,"EPHEMERAL") != 0)
2694 image_info->affirm=MagickTrue;
2696 image_info->temporary=MagickTrue;
2699 magick_info=GetMagickInfo(magic,sans_exception);
2700 sans_exception=DestroyExceptionInfo(sans_exception);
2701 if ((magick_info == (const MagickInfo *) NULL) ||
2702 (GetMagickEndianSupport(magick_info) == MagickFalse))
2703 image_info->endian=UndefinedEndian;
2704 GetPathComponent(image_info->filename,CanonicalPath,component);
2705 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2706 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2709 Test for multiple image support (e.g. image%02d.png).
2711 (void) InterpretImageFilename(image_info,(Image *) NULL,
2712 image_info->filename,(int) image_info->scene,component,exception);
2713 if ((LocaleCompare(component,image_info->filename) != 0) &&
2714 (strchr(component,'%') == (char *) NULL))
2715 image_info->adjoin=MagickFalse;
2717 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2720 Some image formats do not support multiple frames per file.
2722 magick_info=GetMagickInfo(magic,exception);
2723 if (magick_info != (const MagickInfo *) NULL)
2724 if (GetMagickAdjoin(magick_info) == MagickFalse)
2725 image_info->adjoin=MagickFalse;
2727 if (image_info->affirm != MagickFalse)
2738 Determine the image format from the first few bytes of the file.
2740 magick_size=GetMagicPatternExtent(exception);
2741 if (magick_size == 0)
2742 return(MagickFalse);
2743 image=AcquireImage(image_info,exception);
2744 (void) CopyMagickString(image->filename,image_info->filename,
2746 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2747 if (status == MagickFalse)
2749 image=DestroyImage(image);
2750 return(MagickFalse);
2752 if ((IsBlobSeekable(image) == MagickFalse) ||
2753 (IsBlobExempt(image) != MagickFalse))
2756 Copy standard input or pipe to temporary file.
2759 status=ImageToFile(image,component,exception);
2760 (void) CloseBlob(image);
2761 if (status == MagickFalse)
2763 image=DestroyImage(image);
2764 return(MagickFalse);
2766 SetImageInfoFile(image_info,(FILE *) NULL);
2767 (void) CopyMagickString(image->filename,component,MagickPathExtent);
2768 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2769 if (status == MagickFalse)
2771 image=DestroyImage(image);
2772 return(MagickFalse);
2774 (void) CopyMagickString(image_info->filename,component,
2776 image_info->temporary=MagickTrue;
2778 magick=(unsigned char *) AcquireMagickMemory(magick_size);
2779 if (magick == (unsigned char *) NULL)
2781 (void) CloseBlob(image);
2782 image=DestroyImage(image);
2783 return(MagickFalse);
2785 (void) ResetMagickMemory(magick,0,magick_size);
2786 count=ReadBlob(image,magick_size,magick);
2787 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
2788 (void) CloseBlob(image);
2789 image=DestroyImage(image);
2791 Check magic.xml configuration file.
2793 sans_exception=AcquireExceptionInfo();
2794 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
2795 magick=(unsigned char *) RelinquishMagickMemory(magick);
2796 if ((magic_info != (const MagicInfo *) NULL) &&
2797 (GetMagicName(magic_info) != (char *) NULL))
2800 Try to use magick_info that was determined earlier by the extension
2802 if ((magick_info != (const MagickInfo *) NULL) &&
2803 (GetMagickUseExtension(magick_info) != MagickFalse) &&
2804 (LocaleCompare(magick_info->module,GetMagicName(
2806 (void) CopyMagickString(image_info->magick,magick_info->name,
2810 (void) CopyMagickString(image_info->magick,GetMagicName(
2811 magic_info),MagickPathExtent);
2812 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2814 if ((magick_info == (const MagickInfo *) NULL) ||
2815 (GetMagickEndianSupport(magick_info) == MagickFalse))
2816 image_info->endian=UndefinedEndian;
2817 sans_exception=DestroyExceptionInfo(sans_exception);
2820 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2821 if ((magick_info == (const MagickInfo *) NULL) ||
2822 (GetMagickEndianSupport(magick_info) == MagickFalse))
2823 image_info->endian=UndefinedEndian;
2824 sans_exception=DestroyExceptionInfo(sans_exception);
2830 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2834 % S e t I m a g e I n f o B l o b %
2838 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2840 % SetImageInfoBlob() sets the image info blob member.
2842 % The format of the SetImageInfoBlob method is:
2844 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2845 % const size_t length)
2847 % A description of each parameter follows:
2849 % o image_info: the image info.
2853 % o length: the blob length.
2856 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2857 const size_t length)
2859 assert(image_info != (ImageInfo *) NULL);
2860 assert(image_info->signature == MagickCoreSignature);
2861 if (image_info->debug != MagickFalse)
2862 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2863 image_info->filename);
2864 image_info->blob=(void *) blob;
2865 image_info->length=length;
2869 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2873 % S e t I m a g e I n f o F i l e %
2877 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2879 % SetImageInfoFile() sets the image info file member.
2881 % The format of the SetImageInfoFile method is:
2883 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2885 % A description of each parameter follows:
2887 % o image_info: the image info.
2892 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2894 assert(image_info != (ImageInfo *) NULL);
2895 assert(image_info->signature == MagickCoreSignature);
2896 if (image_info->debug != MagickFalse)
2897 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2898 image_info->filename);
2899 image_info->file=file;
2903 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2907 % S e t I m a g e M a s k %
2911 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2913 % SetImageMask() associates a mask with the image. The mask must be the same
2914 % dimensions as the image.
2916 % The format of the SetImageMask method is:
2918 % MagickBooleanType SetImageMask(Image *image,const PixelMask type,
2919 % const Image *mask,ExceptionInfo *exception)
2921 % A description of each parameter follows:
2923 % o image: the image.
2925 % o type: the mask type, ReadPixelMask or WritePixelMask.
2927 % o mask: the image mask.
2929 % o exception: return any errors or warnings in this structure.
2932 MagickExport MagickBooleanType SetImageMask(Image *image,const PixelMask type,
2933 const Image *mask,ExceptionInfo *exception)
2948 assert(image != (Image *) NULL);
2949 if (image->debug != MagickFalse)
2950 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2951 assert(image->signature == MagickCoreSignature);
2952 if (mask == (const Image *) NULL)
2956 case WritePixelMask: image->write_mask=MagickFalse; break;
2957 default: image->read_mask=MagickFalse; break;
2959 return(SyncImagePixelCache(image,exception));
2963 case WritePixelMask: image->write_mask=MagickTrue; break;
2964 default: image->read_mask=MagickTrue; break;
2966 if (SyncImagePixelCache(image,exception) == MagickFalse)
2967 return(MagickFalse);
2969 mask_view=AcquireVirtualCacheView(mask,exception);
2970 image_view=AcquireAuthenticCacheView(image,exception);
2971 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2972 #pragma omp parallel for schedule(static,4) shared(status) \
2973 magick_threads(mask,image,1,1)
2975 for (y=0; y < (ssize_t) image->rows; y++)
2977 register const Quantum
2986 if (status == MagickFalse)
2988 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
2989 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2990 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2995 for (x=0; x < (ssize_t) image->columns; x++)
3000 intensity=GetPixelIntensity(mask,p);
3003 case WritePixelMask:
3005 SetPixelWriteMask(image,ClampToQuantum(QuantumRange-intensity),q);
3010 SetPixelReadMask(image,ClampToQuantum(QuantumRange-intensity),q);
3014 p+=GetPixelChannels(mask);
3015 q+=GetPixelChannels(image);
3017 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3020 mask_view=DestroyCacheView(mask_view);
3021 image_view=DestroyCacheView(image_view);
3026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3030 % S e t I m a g e A l p h a %
3034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3036 % SetImageAlpha() sets the alpha levels of the image.
3038 % The format of the SetImageAlpha method is:
3040 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3041 % ExceptionInfo *exception)
3043 % A description of each parameter follows:
3045 % o image: the image.
3047 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3048 % fully transparent.
3051 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3052 ExceptionInfo *exception)
3063 assert(image != (Image *) NULL);
3064 if (image->debug != MagickFalse)
3065 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3066 assert(image->signature == MagickCoreSignature);
3067 image->alpha_trait=BlendPixelTrait;
3069 image_view=AcquireAuthenticCacheView(image,exception);
3070 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3071 #pragma omp parallel for schedule(static,4) shared(status) \
3072 magick_threads(image,image,image->rows,1)
3074 for (y=0; y < (ssize_t) image->rows; y++)
3082 if (status == MagickFalse)
3084 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3085 if (q == (Quantum *) NULL)
3090 for (x=0; x < (ssize_t) image->columns; x++)
3092 if (GetPixelReadMask(image,q) != 0)
3093 SetPixelAlpha(image,alpha,q);
3094 q+=GetPixelChannels(image);
3096 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3099 image_view=DestroyCacheView(image_view);
3104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3108 % 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 %
3112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3114 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3115 % image and returns the previous setting. A virtual pixel is any pixel access
3116 % that is outside the boundaries of the image cache.
3118 % The format of the SetImageVirtualPixelMethod() method is:
3120 % VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3121 % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3123 % A description of each parameter follows:
3125 % o image: the image.
3127 % o virtual_pixel_method: choose the type of virtual pixel.
3129 % o exception: return any errors or warnings in this structure.
3132 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3133 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3135 assert(image != (const Image *) NULL);
3136 assert(image->signature == MagickCoreSignature);
3137 if (image->debug != MagickFalse)
3138 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3139 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3147 % S m u s h I m a g e s %
3151 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3153 % SmushImages() takes all images from the current image pointer to the end
3154 % of the image list and smushes them to each other top-to-bottom if the
3155 % stack parameter is true, otherwise left-to-right.
3157 % The current gravity setting now effects how the image is justified in the
3160 % The format of the SmushImages method is:
3162 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3163 % ExceptionInfo *exception)
3165 % A description of each parameter follows:
3167 % o images: the image sequence.
3169 % o stack: A value other than 0 stacks the images top-to-bottom.
3171 % o offset: minimum distance in pixels between images.
3173 % o exception: return any errors or warnings in this structure.
3177 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3178 const ssize_t offset,ExceptionInfo *exception)
3192 register const Quantum
3205 if (images->previous == (Image *) NULL)
3208 SetGeometry(smush_image,&right_geometry);
3209 GravityAdjustGeometry(right_image->columns,right_image->rows,
3210 right_image->gravity,&right_geometry);
3211 left_image=images->previous;
3212 SetGeometry(smush_image,&left_geometry);
3213 GravityAdjustGeometry(left_image->columns,left_image->rows,
3214 left_image->gravity,&left_geometry);
3215 gap=right_image->columns;
3216 left_view=AcquireVirtualCacheView(left_image,exception);
3217 right_view=AcquireVirtualCacheView(right_image,exception);
3218 for (y=0; y < (ssize_t) smush_image->rows; y++)
3220 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3222 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3223 if ((p == (const Quantum *) NULL) ||
3224 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3225 ((left_image->columns-x-1) >= gap))
3228 i=(ssize_t) left_image->columns-x-1;
3229 for (x=0; x < (ssize_t) right_image->columns; x++)
3231 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3233 if ((p == (const Quantum *) NULL) ||
3234 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3235 ((x+i) >= (ssize_t) gap))
3238 if ((x+i) < (ssize_t) gap)
3241 right_view=DestroyCacheView(right_view);
3242 left_view=DestroyCacheView(left_view);
3243 if (y < (ssize_t) smush_image->rows)
3245 return((ssize_t) gap-offset);
3248 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3249 const ssize_t offset,ExceptionInfo *exception)
3263 register const Quantum
3276 if (images->previous == (Image *) NULL)
3278 bottom_image=images;
3279 SetGeometry(smush_image,&bottom_geometry);
3280 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3281 bottom_image->gravity,&bottom_geometry);
3282 top_image=images->previous;
3283 SetGeometry(smush_image,&top_geometry);
3284 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3286 gap=bottom_image->rows;
3287 top_view=AcquireVirtualCacheView(top_image,exception);
3288 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3289 for (x=0; x < (ssize_t) smush_image->columns; x++)
3291 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3293 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3294 if ((p == (const Quantum *) NULL) ||
3295 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3296 ((top_image->rows-y-1) >= gap))
3299 i=(ssize_t) top_image->rows-y-1;
3300 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3302 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3304 if ((p == (const Quantum *) NULL) ||
3305 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3306 ((y+i) >= (ssize_t) gap))
3309 if ((y+i) < (ssize_t) gap)
3312 bottom_view=DestroyCacheView(bottom_view);
3313 top_view=DestroyCacheView(top_view);
3314 if (x < (ssize_t) smush_image->columns)
3316 return((ssize_t) gap-offset);
3319 MagickExport Image *SmushImages(const Image *images,
3320 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3322 #define SmushImageTag "Smush/Image"
3343 register const Image
3356 Compute maximum area of smushed area.
3358 assert(images != (Image *) NULL);
3359 assert(images->signature == MagickCoreSignature);
3360 if (images->debug != MagickFalse)
3361 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3362 assert(exception != (ExceptionInfo *) NULL);
3363 assert(exception->signature == MagickCoreSignature);
3365 alpha_trait=image->alpha_trait;
3367 width=image->columns;
3369 next=GetNextImageInList(image);
3370 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3372 if (next->alpha_trait != UndefinedPixelTrait)
3373 alpha_trait=BlendPixelTrait;
3375 if (stack != MagickFalse)
3377 if (next->columns > width)
3378 width=next->columns;
3380 if (next->previous != (Image *) NULL)
3384 width+=next->columns;
3385 if (next->previous != (Image *) NULL)
3387 if (next->rows > height)
3393 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3394 if (smush_image == (Image *) NULL)
3395 return((Image *) NULL);
3396 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3398 smush_image=DestroyImage(smush_image);
3399 return((Image *) NULL);
3401 smush_image->alpha_trait=alpha_trait;
3402 (void) SetImageBackgroundColor(smush_image,exception);
3406 for (n=0; n < (MagickOffsetType) number_images; n++)
3408 SetGeometry(smush_image,&geometry);
3409 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3410 if (stack != MagickFalse)
3412 x_offset-=geometry.x;
3413 y_offset-=SmushYGap(smush_image,image,offset,exception);
3417 x_offset-=SmushXGap(smush_image,image,offset,exception);
3418 y_offset-=geometry.y;
3420 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3421 y_offset,exception);
3422 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3423 if (proceed == MagickFalse)
3425 if (stack == MagickFalse)
3427 x_offset+=(ssize_t) image->columns;
3433 y_offset+=(ssize_t) image->rows;
3435 image=GetNextImageInList(image);
3437 if (stack == MagickFalse)
3438 smush_image->columns=(size_t) x_offset;
3440 smush_image->rows=(size_t) y_offset;
3441 if (status == MagickFalse)
3442 smush_image=DestroyImage(smush_image);
3443 return(smush_image);
3447 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3451 % S t r i p I m a g e %
3455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3457 % StripImage() strips an image of all profiles and comments.
3459 % The format of the StripImage method is:
3461 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3463 % A description of each parameter follows:
3465 % o image: the image.
3467 % o exception: return any errors or warnings in this structure.
3470 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3475 assert(image != (Image *) NULL);
3476 if (image->debug != MagickFalse)
3477 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3479 DestroyImageProfiles(image);
3480 (void) DeleteImageProperty(image,"comment");
3481 (void) DeleteImageProperty(image,"date:create");
3482 (void) DeleteImageProperty(image,"date:modify");
3483 status=SetImageArtifact(image,"png:exclude-chunk",
3484 "cHRM,EXIF,gAMA,iCCP,iTXt,sRGB,tEXt,zCCP,zTXt,date");
3489 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3493 + S y n c I m a g e %
3497 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3499 % SyncImage() initializes the red, green, and blue intensities of each pixel
3500 % as defined by the colormap index.
3502 % The format of the SyncImage method is:
3504 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3506 % A description of each parameter follows:
3508 % o image: the image.
3510 % o exception: return any errors or warnings in this structure.
3514 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3515 MagickBooleanType *range_exception)
3517 if ((size_t) index < image->colors)
3519 *range_exception=MagickTrue;
3520 return((Quantum) 0);
3523 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3536 assert(image != (Image *) NULL);
3537 if (image->debug != MagickFalse)
3538 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3539 assert(image->signature == MagickCoreSignature);
3540 if (image->storage_class == DirectClass)
3541 return(MagickFalse);
3542 range_exception=MagickFalse;
3545 image_view=AcquireAuthenticCacheView(image,exception);
3546 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3547 #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
3548 magick_threads(image,image,image->rows,1)
3550 for (y=0; y < (ssize_t) image->rows; y++)
3561 if (status == MagickFalse)
3563 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3564 if (q == (Quantum *) NULL)
3569 for (x=0; x < (ssize_t) image->columns; x++)
3571 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3572 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
3573 q+=GetPixelChannels(image);
3575 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3578 image_view=DestroyCacheView(image_view);
3580 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3581 (void) ThrowMagickException(exception,GetMagickModule(),
3582 CorruptImageWarning,"InvalidColormapIndex","`%s'",image->filename);
3587 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3591 % S y n c I m a g e S e t t i n g s %
3595 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3597 % SyncImageSettings() syncs any image_info global options into per-image
3600 % Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
3601 % that operations and coders can find such settings. In IMv7 if a desired
3602 % per-image artifact is not set, then it will directly look for a global
3603 % option as a fallback, as such this copy is no longer needed, only the
3606 % The format of the SyncImageSettings method is:
3608 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3609 % Image *image,ExceptionInfo *exception)
3610 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3611 % Image *image,ExceptionInfo *exception)
3613 % A description of each parameter follows:
3615 % o image_info: the image info.
3617 % o image: the image.
3619 % o exception: return any errors or warnings in this structure.
3623 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3624 Image *images,ExceptionInfo *exception)
3629 assert(image_info != (const ImageInfo *) NULL);
3630 assert(image_info->signature == MagickCoreSignature);
3631 assert(images != (Image *) NULL);
3632 assert(images->signature == MagickCoreSignature);
3633 if (images->debug != MagickFalse)
3634 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3636 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3637 (void) SyncImageSettings(image_info,image,exception);
3638 (void) DeleteImageOption(image_info,"page");
3642 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3643 Image *image,ExceptionInfo *exception)
3660 assert(image_info != (const ImageInfo *) NULL);
3661 assert(image_info->signature == MagickCoreSignature);
3662 assert(image != (Image *) NULL);
3663 assert(image->signature == MagickCoreSignature);
3664 if (image->debug != MagickFalse)
3665 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3666 option=GetImageOption(image_info,"alpha-color");
3667 if (option != (const char *) NULL)
3668 (void) QueryColorCompliance(option,AllCompliance,&image->alpha_color,
3670 option=GetImageOption(image_info,"background");
3671 if (option != (const char *) NULL)
3672 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
3674 option=GetImageOption(image_info,"black-point-compensation");
3675 if (option != (const char *) NULL)
3676 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3677 MagickBooleanOptions,MagickFalse,option);
3678 option=GetImageOption(image_info,"blue-primary");
3679 if (option != (const char *) NULL)
3681 flags=ParseGeometry(option,&geometry_info);
3682 image->chromaticity.blue_primary.x=geometry_info.rho;
3683 image->chromaticity.blue_primary.y=geometry_info.sigma;
3684 if ((flags & SigmaValue) == 0)
3685 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3687 option=GetImageOption(image_info,"bordercolor");
3688 if (option != (const char *) NULL)
3689 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
3691 /* FUTURE: do not sync compose to per-image compose setting here */
3692 option=GetImageOption(image_info,"compose");
3693 if (option != (const char *) NULL)
3694 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3695 MagickFalse,option);
3697 option=GetImageOption(image_info,"compress");
3698 if (option != (const char *) NULL)
3699 image->compression=(CompressionType) ParseCommandOption(
3700 MagickCompressOptions,MagickFalse,option);
3701 option=GetImageOption(image_info,"debug");
3702 if (option != (const char *) NULL)
3703 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3704 MagickFalse,option);
3705 option=GetImageOption(image_info,"density");
3706 if (option != (const char *) NULL)
3711 flags=ParseGeometry(option,&geometry_info);
3712 image->resolution.x=geometry_info.rho;
3713 image->resolution.y=geometry_info.sigma;
3714 if ((flags & SigmaValue) == 0)
3715 image->resolution.y=image->resolution.x;
3717 option=GetImageOption(image_info,"depth");
3718 if (option != (const char *) NULL)
3719 image->depth=StringToUnsignedLong(option);
3720 option=GetImageOption(image_info,"endian");
3721 if (option != (const char *) NULL)
3722 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3723 MagickFalse,option);
3724 option=GetImageOption(image_info,"filter");
3725 if (option != (const char *) NULL)
3726 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
3727 MagickFalse,option);
3728 option=GetImageOption(image_info,"fuzz");
3729 if (option != (const char *) NULL)
3730 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3731 option=GetImageOption(image_info,"gravity");
3732 if (option != (const char *) NULL)
3733 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3734 MagickFalse,option);
3735 option=GetImageOption(image_info,"green-primary");
3736 if (option != (const char *) NULL)
3738 flags=ParseGeometry(option,&geometry_info);
3739 image->chromaticity.green_primary.x=geometry_info.rho;
3740 image->chromaticity.green_primary.y=geometry_info.sigma;
3741 if ((flags & SigmaValue) == 0)
3742 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3744 option=GetImageOption(image_info,"intent");
3745 if (option != (const char *) NULL)
3746 image->rendering_intent=(RenderingIntent) ParseCommandOption(
3747 MagickIntentOptions,MagickFalse,option);
3748 option=GetImageOption(image_info,"intensity");
3749 if (option != (const char *) NULL)
3750 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3751 MagickPixelIntensityOptions,MagickFalse,option);
3752 option=GetImageOption(image_info,"interlace");
3753 if (option != (const char *) NULL)
3754 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3755 MagickFalse,option);
3756 option=GetImageOption(image_info,"interpolate");
3757 if (option != (const char *) NULL)
3758 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
3759 MagickInterpolateOptions,MagickFalse,option);
3760 option=GetImageOption(image_info,"loop");
3761 if (option != (const char *) NULL)
3762 image->iterations=StringToUnsignedLong(option);
3763 option=GetImageOption(image_info,"orient");
3764 if (option != (const char *) NULL)
3765 image->orientation=(OrientationType) ParseCommandOption(
3766 MagickOrientationOptions,MagickFalse,option);
3767 option=GetImageOption(image_info,"page");
3768 if (option != (const char *) NULL)
3773 geometry=GetPageGeometry(option);
3774 flags=ParseAbsoluteGeometry(geometry,&image->page);
3775 geometry=DestroyString(geometry);
3777 option=GetImageOption(image_info,"quality");
3778 if (option != (const char *) NULL)
3779 image->quality=StringToUnsignedLong(option);
3780 option=GetImageOption(image_info,"red-primary");
3781 if (option != (const char *) NULL)
3783 flags=ParseGeometry(option,&geometry_info);
3784 image->chromaticity.red_primary.x=geometry_info.rho;
3785 image->chromaticity.red_primary.y=geometry_info.sigma;
3786 if ((flags & SigmaValue) == 0)
3787 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3789 if (image_info->quality != UndefinedCompressionQuality)
3790 image->quality=image_info->quality;
3791 option=GetImageOption(image_info,"scene");
3792 if (option != (const char *) NULL)
3793 image->scene=StringToUnsignedLong(option);
3794 option=GetImageOption(image_info,"taint");
3795 if (option != (const char *) NULL)
3796 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3797 MagickFalse,option);
3798 option=GetImageOption(image_info,"tile-offset");
3799 if (option != (const char *) NULL)
3804 geometry=GetPageGeometry(option);
3805 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3806 geometry=DestroyString(geometry);
3808 option=GetImageOption(image_info,"transparent-color");
3809 if (option != (const char *) NULL)
3810 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
3812 option=GetImageOption(image_info,"type");
3813 if (option != (const char *) NULL)
3814 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3816 option=GetImageOption(image_info,"units");
3817 units=image_info->units;
3818 if (option != (const char *) NULL)
3819 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
3820 MagickFalse,option);
3821 if (units != UndefinedResolution)
3823 if (image->units != units)
3824 switch (image->units)
3826 case PixelsPerInchResolution:
3828 if (units == PixelsPerCentimeterResolution)
3830 image->resolution.x/=2.54;
3831 image->resolution.y/=2.54;
3835 case PixelsPerCentimeterResolution:
3837 if (units == PixelsPerInchResolution)
3839 image->resolution.x=(double) ((size_t) (100.0*2.54*
3840 image->resolution.x+0.5))/100.0;
3841 image->resolution.y=(double) ((size_t) (100.0*2.54*
3842 image->resolution.y+0.5))/100.0;
3851 option=GetImageOption(image_info,"virtual-pixel");
3852 if (option != (const char *) NULL)
3853 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
3854 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
3856 option=GetImageOption(image_info,"white-point");
3857 if (option != (const char *) NULL)
3859 flags=ParseGeometry(option,&geometry_info);
3860 image->chromaticity.white_point.x=geometry_info.rho;
3861 image->chromaticity.white_point.y=geometry_info.sigma;
3862 if ((flags & SigmaValue) == 0)
3863 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
3866 Pointer to allow the lookup of pre-image artifact will fallback to a global
3867 option setting/define. This saves a lot of duplication of global options
3868 into per-image artifacts, while ensuring only specifically set per-image
3869 artifacts are preserved when parenthesis ends.
3871 if (image->image_info != (ImageInfo *) NULL)
3872 image->image_info=DestroyImageInfo(image->image_info);
3873 image->image_info=CloneImageInfo(image_info);