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-2017 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/animate.h"
45 #include "MagickCore/artifact.h"
46 #include "MagickCore/attribute.h"
47 #include "MagickCore/blob.h"
48 #include "MagickCore/blob-private.h"
49 #include "MagickCore/cache.h"
50 #include "MagickCore/cache-private.h"
51 #include "MagickCore/cache-view.h"
52 #include "MagickCore/client.h"
53 #include "MagickCore/color.h"
54 #include "MagickCore/color-private.h"
55 #include "MagickCore/colormap.h"
56 #include "MagickCore/colorspace.h"
57 #include "MagickCore/colorspace-private.h"
58 #include "MagickCore/composite.h"
59 #include "MagickCore/composite-private.h"
60 #include "MagickCore/compress.h"
61 #include "MagickCore/constitute.h"
62 #include "MagickCore/delegate.h"
63 #include "MagickCore/display.h"
64 #include "MagickCore/draw.h"
65 #include "MagickCore/enhance.h"
66 #include "MagickCore/exception.h"
67 #include "MagickCore/exception-private.h"
68 #include "MagickCore/gem.h"
69 #include "MagickCore/geometry.h"
70 #include "MagickCore/histogram.h"
71 #include "MagickCore/image-private.h"
72 #include "MagickCore/list.h"
73 #include "MagickCore/magic.h"
74 #include "MagickCore/magick.h"
75 #include "MagickCore/magick-private.h"
76 #include "MagickCore/memory_.h"
77 #include "MagickCore/module.h"
78 #include "MagickCore/monitor.h"
79 #include "MagickCore/monitor-private.h"
80 #include "MagickCore/option.h"
81 #include "MagickCore/paint.h"
82 #include "MagickCore/pixel-accessor.h"
83 #include "MagickCore/profile.h"
84 #include "MagickCore/property.h"
85 #include "MagickCore/quantize.h"
86 #include "MagickCore/random_.h"
87 #include "MagickCore/resource_.h"
88 #include "MagickCore/segment.h"
89 #include "MagickCore/semaphore.h"
90 #include "MagickCore/signature-private.h"
91 #include "MagickCore/statistic.h"
92 #include "MagickCore/string_.h"
93 #include "MagickCore/string-private.h"
94 #include "MagickCore/thread-private.h"
95 #include "MagickCore/threshold.h"
96 #include "MagickCore/timer.h"
97 #include "MagickCore/token.h"
98 #include "MagickCore/utility.h"
99 #include "MagickCore/utility-private.h"
100 #include "MagickCore/version.h"
101 #include "MagickCore/xwindow-private.h"
104 Constant declaration.
107 AlphaColor[] = "#bdbdbd", /* gray */
108 BackgroundColor[] = "#ffffff", /* white */
109 BorderColor[] = "#dfdfdf", /* gray */
110 DefaultTileFrame[] = "15x15+3+3",
111 DefaultTileGeometry[] = "120x120+4+3>",
112 DefaultTileLabel[] = "%f\n%G\n%b",
113 ForegroundColor[] = "#000", /* black */
114 LoadImageTag[] = "Load/Image",
115 LoadImagesTag[] = "Load/Images",
116 PSDensityGeometry[] = "72.0x72.0",
117 PSPageGeometry[] = "612x792",
118 SaveImageTag[] = "Save/Image",
119 SaveImagesTag[] = "Save/Images",
120 TransparentColor[] = "#00000000"; /* transparent black */
123 DefaultResolution = 72.0;
126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 % A c q u i r e I m a g e %
134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 % AcquireImage() returns a pointer to an image structure initialized to
139 % The format of the AcquireImage method is:
141 % Image *AcquireImage(const ImageInfo *image_info,ExceptionInfo *exception)
143 % A description of each parameter follows:
145 % o image_info: Many of the image default values are set from this
146 % structure. For example, filename, compression, depth, background color,
149 % o exception: return any errors or warnings in this structure.
152 MagickExport Image *AcquireImage(const ImageInfo *image_info,
153 ExceptionInfo *exception)
165 Allocate image structure.
167 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
168 image=(Image *) AcquireMagickMemory(sizeof(*image));
169 if (image == (Image *) NULL)
170 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
171 (void) ResetMagickMemory(image,0,sizeof(*image));
173 Initialize Image structure.
175 (void) CopyMagickString(image->magick,"MIFF",MagickPathExtent);
176 image->storage_class=DirectClass;
177 image->depth=MAGICKCORE_QUANTUM_DEPTH;
178 image->colorspace=sRGBColorspace;
179 image->rendering_intent=PerceptualIntent;
180 image->gamma=1.000f/2.200f;
181 image->chromaticity.red_primary.x=0.6400f;
182 image->chromaticity.red_primary.y=0.3300f;
183 image->chromaticity.red_primary.z=0.0300f;
184 image->chromaticity.green_primary.x=0.3000f;
185 image->chromaticity.green_primary.y=0.6000f;
186 image->chromaticity.green_primary.z=0.1000f;
187 image->chromaticity.blue_primary.x=0.1500f;
188 image->chromaticity.blue_primary.y=0.0600f;
189 image->chromaticity.blue_primary.z=0.7900f;
190 image->chromaticity.white_point.x=0.3127f;
191 image->chromaticity.white_point.y=0.3290f;
192 image->chromaticity.white_point.z=0.3583f;
193 image->interlace=NoInterlace;
194 image->ticks_per_second=UndefinedTicksPerSecond;
195 image->compose=OverCompositeOp;
196 (void) QueryColorCompliance(AlphaColor,AllCompliance,&image->alpha_color,
198 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
199 &image->background_color,exception);
200 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
202 (void) QueryColorCompliance(TransparentColor,AllCompliance,
203 &image->transparent_color,exception);
204 GetTimerInfo(&image->timer);
205 image->cache=AcquirePixelCache(0);
206 image->channel_mask=DefaultChannels;
207 image->channel_map=AcquirePixelChannelMap();
208 image->blob=CloneBlobInfo((BlobInfo *) NULL);
209 image->timestamp=time((time_t *) NULL);
210 image->debug=IsEventLogging();
211 image->reference_count=1;
212 image->semaphore=AcquireSemaphoreInfo();
213 image->signature=MagickCoreSignature;
214 if (image_info == (ImageInfo *) NULL)
219 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
221 (void) CopyMagickString(image->filename,image_info->filename,
223 (void) CopyMagickString(image->magick_filename,image_info->filename,
225 (void) CopyMagickString(image->magick,image_info->magick,MagickPathExtent);
226 if (image_info->size != (char *) NULL)
228 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
229 image->columns=image->extract_info.width;
230 image->rows=image->extract_info.height;
231 image->offset=image->extract_info.x;
232 image->extract_info.x=0;
233 image->extract_info.y=0;
235 if (image_info->extract != (char *) NULL)
240 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
241 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
243 image->extract_info=geometry;
244 Swap(image->columns,image->extract_info.width);
245 Swap(image->rows,image->extract_info.height);
248 image->compression=image_info->compression;
249 image->quality=image_info->quality;
250 image->endian=image_info->endian;
251 image->interlace=image_info->interlace;
252 image->units=image_info->units;
253 if (image_info->density != (char *) NULL)
258 flags=ParseGeometry(image_info->density,&geometry_info);
259 image->resolution.x=geometry_info.rho;
260 image->resolution.y=geometry_info.sigma;
261 if ((flags & SigmaValue) == 0)
262 image->resolution.y=image->resolution.x;
264 if (image_info->page != (char *) NULL)
269 image->page=image->extract_info;
270 geometry=GetPageGeometry(image_info->page);
271 (void) ParseAbsoluteGeometry(geometry,&image->page);
272 geometry=DestroyString(geometry);
274 if (image_info->depth != 0)
275 image->depth=image_info->depth;
276 image->dither=image_info->dither;
277 image->alpha_color=image_info->alpha_color;
278 image->background_color=image_info->background_color;
279 image->border_color=image_info->border_color;
280 image->transparent_color=image_info->transparent_color;
281 image->ping=image_info->ping;
282 image->progress_monitor=image_info->progress_monitor;
283 image->client_data=image_info->client_data;
284 if (image_info->cache != (void *) NULL)
285 ClonePixelCacheMethods(image->cache,image_info->cache);
287 Set all global options that map to per-image settings.
289 (void) SyncImageSettings(image_info,image,exception);
291 Global options that are only set for new images.
293 option=GetImageOption(image_info,"delay");
294 if (option != (const char *) NULL)
299 flags=ParseGeometry(option,&geometry_info);
300 if ((flags & GreaterValue) != 0)
302 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
303 image->delay=(size_t) floor(geometry_info.rho+0.5);
306 if ((flags & LessValue) != 0)
308 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
309 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
312 image->delay=(size_t) floor(geometry_info.rho+0.5);
313 if ((flags & SigmaValue) != 0)
314 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
316 option=GetImageOption(image_info,"dispose");
317 if (option != (const char *) NULL)
318 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
324 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328 % A c q u i r e I m a g e I n f o %
332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334 % AcquireImageInfo() allocates the ImageInfo structure.
336 % The format of the AcquireImageInfo method is:
338 % ImageInfo *AcquireImageInfo(void)
341 MagickExport ImageInfo *AcquireImageInfo(void)
346 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
347 if (image_info == (ImageInfo *) NULL)
348 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
349 GetImageInfo(image_info);
354 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
358 % A c q u i r e N e x t I m a g e %
362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
364 % AcquireNextImage() initializes the next image in a sequence to
365 % default values. The next member of image points to the newly allocated
366 % image. If there is a memory shortage, next is assigned NULL.
368 % The format of the AcquireNextImage method is:
370 % void AcquireNextImage(const ImageInfo *image_info,Image *image,
371 % ExceptionInfo *exception)
373 % A description of each parameter follows:
375 % o image_info: Many of the image default values are set from this
376 % structure. For example, filename, compression, depth, background color,
379 % o image: the image.
381 % o exception: return any errors or warnings in this structure.
384 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image,
385 ExceptionInfo *exception)
388 Allocate image structure.
390 assert(image != (Image *) NULL);
391 assert(image->signature == MagickCoreSignature);
392 if (image->debug != MagickFalse)
393 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
394 image->next=AcquireImage(image_info,exception);
395 if (GetNextImageInList(image) == (Image *) NULL)
397 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
399 if (image_info != (ImageInfo *) NULL)
400 (void) CopyMagickString(GetNextImageInList(image)->filename,
401 image_info->filename,MagickPathExtent);
402 DestroyBlob(GetNextImageInList(image));
403 image->next->blob=ReferenceBlob(image->blob);
404 image->next->endian=image->endian;
405 image->next->scene=image->scene+1;
406 image->next->previous=image;
410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
414 % A p p e n d I m a g e s %
418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
420 % AppendImages() takes all images from the current image pointer to the end
421 % of the image list and appends them to each other top-to-bottom if the
422 % stack parameter is true, otherwise left-to-right.
424 % The current gravity setting effects how the image is justified in the
427 % The format of the AppendImages method is:
429 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
430 % ExceptionInfo *exception)
432 % A description of each parameter follows:
434 % o images: the image sequence.
436 % o stack: A value other than 0 stacks the images top-to-bottom.
438 % o exception: return any errors or warnings in this structure.
441 MagickExport Image *AppendImages(const Image *images,
442 const MagickBooleanType stack,ExceptionInfo *exception)
444 #define AppendImageTag "Append/Image"
453 homogeneous_colorspace,
480 Compute maximum area of appended area.
482 assert(images != (Image *) NULL);
483 assert(images->signature == MagickCoreSignature);
484 if (images->debug != MagickFalse)
485 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
486 assert(exception != (ExceptionInfo *) NULL);
487 assert(exception->signature == MagickCoreSignature);
488 alpha_trait=images->alpha_trait;
490 width=images->columns;
493 homogeneous_colorspace=MagickTrue;
494 next=GetNextImageInList(images);
495 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
497 if (next->depth > depth)
499 if (next->colorspace != images->colorspace)
500 homogeneous_colorspace=MagickFalse;
501 if (next->alpha_trait != UndefinedPixelTrait)
502 alpha_trait=BlendPixelTrait;
504 if (stack != MagickFalse)
506 if (next->columns > width)
511 width+=next->columns;
512 if (next->rows > height)
518 append_image=CloneImage(images,width,height,MagickTrue,exception);
519 if (append_image == (Image *) NULL)
520 return((Image *) NULL);
521 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
523 append_image=DestroyImage(append_image);
524 return((Image *) NULL);
526 if (homogeneous_colorspace == MagickFalse)
527 (void) SetImageColorspace(append_image,sRGBColorspace,exception);
528 append_image->depth=depth;
529 append_image->alpha_trait=alpha_trait;
530 (void) SetImageBackgroundColor(append_image,exception);
535 append_view=AcquireAuthenticCacheView(append_image,exception);
536 for (n=0; n < (MagickOffsetType) number_images; n++)
544 SetGeometry(append_image,&geometry);
545 GravityAdjustGeometry(next->columns,next->rows,next->gravity,&geometry);
546 if (stack != MagickFalse)
547 x_offset-=geometry.x;
549 y_offset-=geometry.y;
550 image_view=AcquireVirtualCacheView(next,exception);
551 #if defined(MAGICKCORE_OPENMP_SUPPORT)
552 #pragma omp parallel for schedule(static,4) shared(status) \
553 magick_threads(next,next,next->rows,1)
555 for (y=0; y < (ssize_t) next->rows; y++)
563 register const Quantum
572 if (status == MagickFalse)
574 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
575 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
576 next->columns,1,exception);
577 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
582 GetPixelInfo(next,&pixel);
583 for (x=0; x < (ssize_t) next->columns; x++)
585 if (GetPixelWriteMask(next,p) == 0)
587 SetPixelBackgoundColor(append_image,q);
588 p+=GetPixelChannels(next);
589 q+=GetPixelChannels(append_image);
592 GetPixelInfoPixel(next,p,&pixel);
593 SetPixelViaPixelInfo(append_image,&pixel,q);
594 p+=GetPixelChannels(next);
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) next->columns;
610 y_offset+=(ssize_t) next->rows;
612 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
613 if (proceed == MagickFalse)
615 next=GetNextImageInList(next);
617 append_view=DestroyCacheView(append_view);
618 if (status == MagickFalse)
619 append_image=DestroyImage(append_image);
620 return(append_image);
624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
628 % C a t c h I m a g e E x c e p t i o n %
632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
634 % CatchImageException() returns if no exceptions are found in the image
635 % sequence, otherwise it determines the most severe exception and reports
636 % it as a warning or error depending on the severity.
638 % The format of the CatchImageException method is:
640 % ExceptionType CatchImageException(Image *image)
642 % A description of each parameter follows:
644 % o image: An image sequence.
647 MagickExport ExceptionType CatchImageException(Image *image)
655 assert(image != (const Image *) NULL);
656 assert(image->signature == MagickCoreSignature);
657 if (image->debug != MagickFalse)
658 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
659 exception=AcquireExceptionInfo();
660 CatchException(exception);
661 severity=exception->severity;
662 exception=DestroyExceptionInfo(exception);
667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
671 % C l i p I m a g e P a t h %
675 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
677 % ClipImagePath() sets the image clip mask based any clipping path information
680 % The format of the ClipImagePath method is:
682 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
683 % const MagickBooleanType inside,ExceptionInfo *exception)
685 % A description of each parameter follows:
687 % o image: the image.
689 % o pathname: name of clipping path resource. If name is preceded by #, use
690 % clipping path numbered by name.
692 % o inside: if non-zero, later operations take effect inside clipping path.
693 % Otherwise later operations take effect outside clipping path.
695 % o exception: return any errors or warnings in this structure.
699 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
701 return(ClipImagePath(image,"#1",MagickTrue,exception));
704 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
705 const MagickBooleanType inside,ExceptionInfo *exception)
707 #define ClipImagePathTag "ClipPath/Image"
721 assert(image != (const Image *) NULL);
722 assert(image->signature == MagickCoreSignature);
723 if (image->debug != MagickFalse)
724 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
725 assert(pathname != NULL);
726 property=AcquireString(pathname);
727 (void) FormatLocaleString(property,MagickPathExtent,"8BIM:1999,2998:%s",
729 value=GetImageProperty(image,property,exception);
730 property=DestroyString(property);
731 if (value == (const char *) NULL)
733 ThrowFileException(exception,OptionError,"NoClipPathDefined",
737 image_info=AcquireImageInfo();
738 (void) CopyMagickString(image_info->filename,image->filename,
740 (void) ConcatenateMagickString(image_info->filename,pathname,
742 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
743 image_info=DestroyImageInfo(image_info);
744 if (clip_mask == (Image *) NULL)
746 if (clip_mask->storage_class == PseudoClass)
748 (void) SyncImage(clip_mask,exception);
749 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
752 if (inside == MagickFalse)
753 (void) NegateImage(clip_mask,MagickFalse,exception);
754 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
755 "8BIM:1999,2998:%s\nPS",pathname);
756 (void) SetImageMask(image,WritePixelMask,clip_mask,exception);
757 clip_mask=DestroyImage(clip_mask);
762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
766 % C l o n e I m a g e %
770 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
772 % CloneImage() copies an image and returns the copy as a new image object.
774 % If the specified columns and rows is 0, an exact copy of the image is
775 % returned, otherwise the pixel data is undefined and must be initialized
776 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
777 % failure, a NULL image is returned and exception describes the reason for the
780 % The format of the CloneImage method is:
782 % Image *CloneImage(const Image *image,const size_t columns,
783 % const size_t rows,const MagickBooleanType orphan,
784 % ExceptionInfo *exception)
786 % A description of each parameter follows:
788 % o image: the image.
790 % o columns: the number of columns in the cloned image.
792 % o rows: the number of rows in the cloned image.
794 % o detach: With a value other than 0, the cloned image is detached from
795 % its parent I/O stream.
797 % o exception: return any errors or warnings in this structure.
800 MagickExport Image *CloneImage(const Image *image,const size_t columns,
801 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
815 assert(image != (const Image *) NULL);
816 assert(image->signature == MagickCoreSignature);
817 if (image->debug != MagickFalse)
818 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
819 assert(exception != (ExceptionInfo *) NULL);
820 assert(exception->signature == MagickCoreSignature);
821 if ((image->columns == 0) || (image->rows == 0))
823 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
824 "NegativeOrZeroImageSize","`%s'",image->filename);
825 return((Image *) NULL);
827 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
828 if (clone_image == (Image *) NULL)
829 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
830 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
831 clone_image->signature=MagickCoreSignature;
832 clone_image->storage_class=image->storage_class;
833 clone_image->number_channels=image->number_channels;
834 clone_image->number_meta_channels=image->number_meta_channels;
835 clone_image->metacontent_extent=image->metacontent_extent;
836 clone_image->colorspace=image->colorspace;
837 clone_image->read_mask=image->read_mask;
838 clone_image->write_mask=image->write_mask;
839 clone_image->alpha_trait=image->alpha_trait;
840 clone_image->columns=image->columns;
841 clone_image->rows=image->rows;
842 clone_image->dither=image->dither;
843 if (image->colormap != (PixelInfo *) NULL)
846 Allocate and copy the image colormap.
848 clone_image->colors=image->colors;
849 length=(size_t) image->colors;
850 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
851 sizeof(*clone_image->colormap));
852 if (clone_image->colormap == (PixelInfo *) NULL)
854 clone_image=DestroyImage(clone_image);
855 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
857 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
858 sizeof(*clone_image->colormap));
860 clone_image->image_info=CloneImageInfo(image->image_info);
861 (void) CloneImageProfiles(clone_image,image);
862 (void) CloneImageProperties(clone_image,image);
863 (void) CloneImageArtifacts(clone_image,image);
864 GetTimerInfo(&clone_image->timer);
865 if (image->ascii85 != (void *) NULL)
866 Ascii85Initialize(clone_image);
867 clone_image->magick_columns=image->magick_columns;
868 clone_image->magick_rows=image->magick_rows;
869 clone_image->type=image->type;
870 clone_image->channel_mask=image->channel_mask;
871 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
872 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
874 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
875 (void) CopyMagickString(clone_image->filename,image->filename,
877 clone_image->progress_monitor=image->progress_monitor;
878 clone_image->client_data=image->client_data;
879 clone_image->reference_count=1;
880 clone_image->next=image->next;
881 clone_image->previous=image->previous;
882 clone_image->list=NewImageList();
883 if (detach == MagickFalse)
884 clone_image->blob=ReferenceBlob(image->blob);
887 clone_image->next=NewImageList();
888 clone_image->previous=NewImageList();
889 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
891 clone_image->ping=image->ping;
892 clone_image->debug=IsEventLogging();
893 clone_image->semaphore=AcquireSemaphoreInfo();
894 if ((columns == 0) || (rows == 0))
896 if (image->montage != (char *) NULL)
897 (void) CloneString(&clone_image->montage,image->montage);
898 if (image->directory != (char *) NULL)
899 (void) CloneString(&clone_image->directory,image->directory);
900 clone_image->cache=ReferencePixelCache(image->cache);
904 if (image->columns != 0)
905 scale=(double) columns/(double) image->columns;
906 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
907 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
908 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
910 if (image->rows != 0)
911 scale=(double) rows/(double) image->rows;
912 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
913 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
914 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
915 clone_image->cache=ClonePixelCache(image->cache);
916 if (SetImageExtent(clone_image,columns,rows,exception) == MagickFalse)
917 clone_image=DestroyImage(clone_image);
922 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
926 % C l o n e I m a g e I n f o %
930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
932 % CloneImageInfo() makes a copy of the given image info structure. If
933 % NULL is specified, a new image info structure is created initialized to
936 % The format of the CloneImageInfo method is:
938 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
940 % A description of each parameter follows:
942 % o image_info: the image info.
945 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
950 clone_info=AcquireImageInfo();
951 if (image_info == (ImageInfo *) NULL)
953 clone_info->compression=image_info->compression;
954 clone_info->temporary=image_info->temporary;
955 clone_info->adjoin=image_info->adjoin;
956 clone_info->antialias=image_info->antialias;
957 clone_info->scene=image_info->scene;
958 clone_info->number_scenes=image_info->number_scenes;
959 clone_info->depth=image_info->depth;
960 (void) CloneString(&clone_info->size,image_info->size);
961 (void) CloneString(&clone_info->extract,image_info->extract);
962 (void) CloneString(&clone_info->scenes,image_info->scenes);
963 (void) CloneString(&clone_info->page,image_info->page);
964 clone_info->interlace=image_info->interlace;
965 clone_info->endian=image_info->endian;
966 clone_info->units=image_info->units;
967 clone_info->quality=image_info->quality;
968 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
969 (void) CloneString(&clone_info->server_name,image_info->server_name);
970 (void) CloneString(&clone_info->font,image_info->font);
971 (void) CloneString(&clone_info->texture,image_info->texture);
972 (void) CloneString(&clone_info->density,image_info->density);
973 clone_info->pointsize=image_info->pointsize;
974 clone_info->fuzz=image_info->fuzz;
975 clone_info->alpha_color=image_info->alpha_color;
976 clone_info->background_color=image_info->background_color;
977 clone_info->border_color=image_info->border_color;
978 clone_info->transparent_color=image_info->transparent_color;
979 clone_info->dither=image_info->dither;
980 clone_info->monochrome=image_info->monochrome;
981 clone_info->colorspace=image_info->colorspace;
982 clone_info->type=image_info->type;
983 clone_info->orientation=image_info->orientation;
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->filename,image_info->filename,
1003 clone_info->channel=image_info->channel;
1004 (void) CloneImageOptions(clone_info,image_info);
1005 clone_info->debug=IsEventLogging();
1006 clone_info->signature=image_info->signature;
1011 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1015 % C o p y I m a g e P i x e l s %
1019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1021 % CopyImagePixels() copies pixels from the source image as defined by the
1022 % geometry the destination image at the specified offset.
1024 % The format of the CopyImagePixels method is:
1026 % MagickBooleanType CopyImagePixels(Image *image,const Image *source_image,
1027 % const RectangleInfo *geometry,const OffsetInfo *offset,
1028 % ExceptionInfo *exception);
1030 % A description of each parameter follows:
1032 % o image: the destination image.
1034 % o source_image: the source image.
1036 % o geometry: define the dimensions of the source pixel rectangle.
1038 % o offset: define the offset in the destination image.
1040 % o exception: return any errors or warnings in this structure.
1043 MagickExport MagickBooleanType CopyImagePixels(Image *image,
1044 const Image *source_image,const RectangleInfo *geometry,
1045 const OffsetInfo *offset,ExceptionInfo *exception)
1047 #define CopyImageTag "Copy/Image"
1062 assert(image != (Image *) NULL);
1063 if (image->debug != MagickFalse)
1064 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1065 assert(source_image != (Image *) NULL);
1066 assert(geometry != (RectangleInfo *) NULL);
1067 assert(offset != (OffsetInfo *) NULL);
1068 if ((offset->x < 0) || (offset->y < 0) ||
1069 ((ssize_t) (offset->x+geometry->width) > (ssize_t) image->columns) ||
1070 ((ssize_t) (offset->y+geometry->height) > (ssize_t) image->rows))
1071 ThrowBinaryException(OptionError,"GeometryDoesNotContainImage",
1073 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1074 return(MagickFalse);
1080 source_view=AcquireVirtualCacheView(source_image,exception);
1081 image_view=AcquireAuthenticCacheView(image,exception);
1082 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1083 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1084 magick_threads(image,source_image,geometry->height,1)
1086 for (y=0; y < (ssize_t) geometry->height; y++)
1091 register const Quantum
1100 if (status == MagickFalse)
1102 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1103 geometry->width,1,exception);
1104 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1105 geometry->width,1,exception);
1106 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1111 for (x=0; x < (ssize_t) geometry->width; x++)
1116 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1118 PixelChannel channel=GetPixelChannelChannel(image,i);
1119 PixelTrait traits=GetPixelChannelTraits(image,channel);
1120 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1121 if ((traits == UndefinedPixelTrait) ||
1122 ((traits & UpdatePixelTrait) == 0) ||
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 foo=(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 option=(const char *) NULL;
1714 if (image != (Image *) NULL)
1715 option=GetImageProperty(image,pattern,exception);
1716 if ((option == (const char *) NULL) && (image != (Image *) NULL))
1717 option=GetImageArtifact(image,pattern);
1718 if ((option == (const char *) NULL) &&
1719 (image_info != (ImageInfo *) NULL))
1720 option=GetImageOption(image_info,pattern);
1721 if (option == (const char *) NULL)
1726 (void) CopyMagickString(filename+(p-format-length),option,(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 (GetPixelWriteMask(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 ThrowBinaryException(ImageError,"NegativeOrZeroImageSize",image->filename);
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[] =
2644 User specified image format.
2646 (void) CopyMagickString(magic,component,MagickPathExtent);
2649 Look for explicit image formats.
2651 format_type=UndefinedFormatType;
2652 magick_info=GetMagickInfo(magic,sans_exception);
2653 if ((magick_info != (const MagickInfo *) NULL) &&
2654 (magick_info->format_type != UndefinedFormatType))
2655 format_type=magick_info->format_type;
2657 while ((format_type == UndefinedFormatType) &&
2658 (format_type_formats[i] != (char *) NULL))
2660 if ((*magic == *format_type_formats[i]) &&
2661 (LocaleCompare(magic,format_type_formats[i]) == 0))
2662 format_type=ExplicitFormatType;
2665 if (format_type == UndefinedFormatType)
2666 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2668 if (format_type == ExplicitFormatType)
2670 image_info->affirm=MagickTrue;
2671 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2673 if (LocaleCompare(magic,"RGB") == 0)
2674 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2677 Look for explicit 'format:image' in filename.
2680 GetPathComponent(image_info->filename,MagickPath,magic);
2683 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2684 magick_info=GetMagickInfo(magic,sans_exception);
2685 GetPathComponent(image_info->filename,CanonicalPath,component);
2686 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2694 User specified image format.
2697 magick_info=GetMagickInfo(magic,sans_exception);
2698 delegate_info=GetDelegateInfo(magic,"*",sans_exception);
2699 if (delegate_info == (const DelegateInfo *) NULL)
2700 delegate_info=GetDelegateInfo("*",magic,sans_exception);
2701 if (((magick_info != (const MagickInfo *) NULL) ||
2702 (delegate_info != (const DelegateInfo *) NULL)) &&
2703 (IsMagickConflict(magic) == MagickFalse))
2705 image_info->affirm=MagickTrue;
2706 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2707 GetPathComponent(image_info->filename,CanonicalPath,component);
2708 (void) CopyMagickString(image_info->filename,component,
2712 sans_exception=DestroyExceptionInfo(sans_exception);
2713 if ((magick_info == (const MagickInfo *) NULL) ||
2714 (GetMagickEndianSupport(magick_info) == MagickFalse))
2715 image_info->endian=UndefinedEndian;
2716 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2719 Test for multiple image support (e.g. image%02d.png).
2721 (void) InterpretImageFilename(image_info,(Image *) NULL,
2722 image_info->filename,(int) image_info->scene,component,exception);
2723 if ((LocaleCompare(component,image_info->filename) != 0) &&
2724 (strchr(component,'%') == (char *) NULL))
2725 image_info->adjoin=MagickFalse;
2727 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2730 Some image formats do not support multiple frames per file.
2732 magick_info=GetMagickInfo(magic,exception);
2733 if (magick_info != (const MagickInfo *) NULL)
2734 if (GetMagickAdjoin(magick_info) == MagickFalse)
2735 image_info->adjoin=MagickFalse;
2737 if (image_info->affirm != MagickFalse)
2748 Determine the image format from the first few bytes of the file.
2750 magick_size=GetMagicPatternExtent(exception);
2751 if (magick_size == 0)
2752 return(MagickFalse);
2753 image=AcquireImage(image_info,exception);
2754 (void) CopyMagickString(image->filename,image_info->filename,
2756 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2757 if (status == MagickFalse)
2759 image=DestroyImage(image);
2760 return(MagickFalse);
2762 if ((IsBlobSeekable(image) == MagickFalse) ||
2763 (IsBlobExempt(image) != MagickFalse))
2766 Copy standard input or pipe to temporary file.
2769 status=ImageToFile(image,component,exception);
2770 (void) CloseBlob(image);
2771 if (status == MagickFalse)
2773 image=DestroyImage(image);
2774 return(MagickFalse);
2776 SetImageInfoFile(image_info,(FILE *) NULL);
2777 (void) CopyMagickString(image->filename,component,MagickPathExtent);
2778 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2779 if (status == MagickFalse)
2781 image=DestroyImage(image);
2782 return(MagickFalse);
2784 (void) CopyMagickString(image_info->filename,component,
2786 image_info->temporary=MagickTrue;
2788 magick=(unsigned char *) AcquireMagickMemory(magick_size);
2789 if (magick == (unsigned char *) NULL)
2791 (void) CloseBlob(image);
2792 image=DestroyImage(image);
2793 return(MagickFalse);
2795 (void) ResetMagickMemory(magick,0,magick_size);
2796 count=ReadBlob(image,magick_size,magick);
2797 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
2798 (void) CloseBlob(image);
2799 image=DestroyImage(image);
2801 Check magic.xml configuration file.
2803 sans_exception=AcquireExceptionInfo();
2804 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
2805 magick=(unsigned char *) RelinquishMagickMemory(magick);
2806 if ((magic_info != (const MagicInfo *) NULL) &&
2807 (GetMagicName(magic_info) != (char *) NULL))
2810 Try to use magick_info that was determined earlier by the extension
2812 if ((magick_info != (const MagickInfo *) NULL) &&
2813 (GetMagickUseExtension(magick_info) != MagickFalse) &&
2814 (LocaleCompare(magick_info->module,GetMagicName(
2816 (void) CopyMagickString(image_info->magick,magick_info->name,
2820 (void) CopyMagickString(image_info->magick,GetMagicName(
2821 magic_info),MagickPathExtent);
2822 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2824 if ((magick_info == (const MagickInfo *) NULL) ||
2825 (GetMagickEndianSupport(magick_info) == MagickFalse))
2826 image_info->endian=UndefinedEndian;
2827 sans_exception=DestroyExceptionInfo(sans_exception);
2830 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2831 if ((magick_info == (const MagickInfo *) NULL) ||
2832 (GetMagickEndianSupport(magick_info) == MagickFalse))
2833 image_info->endian=UndefinedEndian;
2834 sans_exception=DestroyExceptionInfo(sans_exception);
2840 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2844 % S e t I m a g e I n f o B l o b %
2848 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2850 % SetImageInfoBlob() sets the image info blob member.
2852 % The format of the SetImageInfoBlob method is:
2854 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2855 % const size_t length)
2857 % A description of each parameter follows:
2859 % o image_info: the image info.
2863 % o length: the blob length.
2866 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2867 const size_t length)
2869 assert(image_info != (ImageInfo *) NULL);
2870 assert(image_info->signature == MagickCoreSignature);
2871 if (image_info->debug != MagickFalse)
2872 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2873 image_info->filename);
2874 image_info->blob=(void *) blob;
2875 image_info->length=length;
2879 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2883 % S e t I m a g e I n f o F i l e %
2887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2889 % SetImageInfoFile() sets the image info file member.
2891 % The format of the SetImageInfoFile method is:
2893 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2895 % A description of each parameter follows:
2897 % o image_info: the image info.
2902 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2904 assert(image_info != (ImageInfo *) NULL);
2905 assert(image_info->signature == MagickCoreSignature);
2906 if (image_info->debug != MagickFalse)
2907 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2908 image_info->filename);
2909 image_info->file=file;
2913 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2917 % S e t I m a g e A l p h a %
2921 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2923 % SetImageAlpha() sets the alpha levels of the image.
2925 % The format of the SetImageAlpha method is:
2927 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
2928 % ExceptionInfo *exception)
2930 % A description of each parameter follows:
2932 % o image: the image.
2934 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
2935 % fully transparent.
2938 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
2939 ExceptionInfo *exception)
2950 assert(image != (Image *) NULL);
2951 if (image->debug != MagickFalse)
2952 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2953 assert(image->signature == MagickCoreSignature);
2954 image->alpha_trait=BlendPixelTrait;
2956 image_view=AcquireAuthenticCacheView(image,exception);
2957 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2958 #pragma omp parallel for schedule(static,4) shared(status) \
2959 magick_threads(image,image,image->rows,1)
2961 for (y=0; y < (ssize_t) image->rows; y++)
2969 if (status == MagickFalse)
2971 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2972 if (q == (Quantum *) NULL)
2977 for (x=0; x < (ssize_t) image->columns; x++)
2979 if (GetPixelWriteMask(image,q) != 0)
2980 SetPixelAlpha(image,alpha,q);
2981 q+=GetPixelChannels(image);
2983 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2986 image_view=DestroyCacheView(image_view);
2991 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2995 % S e t I m a g e M a s k %
2999 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3001 % SetImageMask() associates a mask with the image. The mask must be the same
3002 % dimensions as the image.
3004 % The format of the SetImageMask method is:
3006 % MagickBooleanType SetImageMask(Image *image,const PixelMask type,
3007 % const Image *mask,ExceptionInfo *exception)
3009 % A description of each parameter follows:
3011 % o image: the image.
3013 % o type: the mask type, ReadPixelMask or WritePixelMask.
3015 % o mask: the image mask.
3017 % o exception: return any errors or warnings in this structure.
3020 MagickExport MagickBooleanType SetImageMask(Image *image,const PixelMask type,
3021 const Image *mask,ExceptionInfo *exception)
3036 assert(image != (Image *) NULL);
3037 if (image->debug != MagickFalse)
3038 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3039 assert(image->signature == MagickCoreSignature);
3040 if (mask == (const Image *) NULL)
3044 case WritePixelMask: image->write_mask=MagickFalse; break;
3045 default: image->read_mask=MagickFalse; break;
3047 return(SyncImagePixelCache(image,exception));
3051 case WritePixelMask: image->write_mask=MagickTrue; break;
3052 default: image->read_mask=MagickTrue; break;
3054 if (SyncImagePixelCache(image,exception) == MagickFalse)
3055 return(MagickFalse);
3057 mask_view=AcquireVirtualCacheView(mask,exception);
3058 image_view=AcquireAuthenticCacheView(image,exception);
3059 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3060 #pragma omp parallel for schedule(static,4) shared(status) \
3061 magick_threads(mask,image,1,1)
3063 for (y=0; y < (ssize_t) image->rows; y++)
3065 register const Quantum
3074 if (status == MagickFalse)
3076 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3077 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3078 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3083 for (x=0; x < (ssize_t) image->columns; x++)
3089 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3090 intensity=GetPixelIntensity(mask,p);
3093 case WritePixelMask:
3095 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3100 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3104 p+=GetPixelChannels(mask);
3105 q+=GetPixelChannels(image);
3107 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3110 mask_view=DestroyCacheView(mask_view);
3111 image_view=DestroyCacheView(image_view);
3116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3120 % S e t I m a g e R e g i o n M a s k %
3124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3126 % SetImageRegionMask() associates a mask with the image as defined by the
3129 % The format of the SetImageRegionMask method is:
3131 % MagickBooleanType SetImageRegionMask(Image *image,const PixelMask type,
3132 % const RectangleInfo *region,ExceptionInfo *exception)
3134 % A description of each parameter follows:
3136 % o image: the image.
3138 % o type: the mask type, ReadPixelMask or WritePixelMask.
3140 % o geometry: the mask region.
3142 % o exception: return any errors or warnings in this structure.
3145 MagickExport MagickBooleanType SetImageRegionMask(Image *image,
3146 const PixelMask type,const RectangleInfo *region,ExceptionInfo *exception)
3158 Set image mask as defined by the region.
3160 assert(image != (Image *) NULL);
3161 if (image->debug != MagickFalse)
3162 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3163 assert(image->signature == MagickCoreSignature);
3164 if (region == (const RectangleInfo *) NULL)
3168 case WritePixelMask: image->write_mask=MagickFalse; break;
3169 default: image->read_mask=MagickFalse; break;
3171 return(SyncImagePixelCache(image,exception));
3175 case WritePixelMask: image->write_mask=MagickTrue; break;
3176 default: image->read_mask=MagickTrue; break;
3178 if (SyncImagePixelCache(image,exception) == MagickFalse)
3179 return(MagickFalse);
3181 image_view=AcquireAuthenticCacheView(image,exception);
3182 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3183 #pragma omp parallel for schedule(static,4) shared(status) \
3184 magick_threads(image,image,1,1)
3186 for (y=0; y < (ssize_t) image->rows; y++)
3194 if (status == MagickFalse)
3196 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3197 if (q == (Quantum *) NULL)
3202 for (x=0; x < (ssize_t) image->columns; x++)
3208 if (((x >= region->x) && (x < (region->x+region->width))) &&
3209 ((y >= region->y) && (y < (region->y+region->height))))
3213 case WritePixelMask:
3215 SetPixelWriteMask(image,pixel,q);
3220 SetPixelReadMask(image,pixel,q);
3224 q+=GetPixelChannels(image);
3226 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3229 image_view=DestroyCacheView(image_view);
3234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3238 % 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 %
3242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3244 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3245 % image and returns the previous setting. A virtual pixel is any pixel access
3246 % that is outside the boundaries of the image cache.
3248 % The format of the SetImageVirtualPixelMethod() method is:
3250 % VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3251 % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3253 % A description of each parameter follows:
3255 % o image: the image.
3257 % o virtual_pixel_method: choose the type of virtual pixel.
3259 % o exception: return any errors or warnings in this structure.
3262 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3263 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3265 assert(image != (const Image *) NULL);
3266 assert(image->signature == MagickCoreSignature);
3267 if (image->debug != MagickFalse)
3268 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3269 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3277 % S m u s h I m a g e s %
3281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3283 % SmushImages() takes all images from the current image pointer to the end
3284 % of the image list and smushes them to each other top-to-bottom if the
3285 % stack parameter is true, otherwise left-to-right.
3287 % The current gravity setting now effects how the image is justified in the
3290 % The format of the SmushImages method is:
3292 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3293 % ExceptionInfo *exception)
3295 % A description of each parameter follows:
3297 % o images: the image sequence.
3299 % o stack: A value other than 0 stacks the images top-to-bottom.
3301 % o offset: minimum distance in pixels between images.
3303 % o exception: return any errors or warnings in this structure.
3307 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3308 const ssize_t offset,ExceptionInfo *exception)
3322 register const Quantum
3335 if (images->previous == (Image *) NULL)
3338 SetGeometry(smush_image,&right_geometry);
3339 GravityAdjustGeometry(right_image->columns,right_image->rows,
3340 right_image->gravity,&right_geometry);
3341 left_image=images->previous;
3342 SetGeometry(smush_image,&left_geometry);
3343 GravityAdjustGeometry(left_image->columns,left_image->rows,
3344 left_image->gravity,&left_geometry);
3345 gap=right_image->columns;
3346 left_view=AcquireVirtualCacheView(left_image,exception);
3347 right_view=AcquireVirtualCacheView(right_image,exception);
3348 for (y=0; y < (ssize_t) smush_image->rows; y++)
3350 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3352 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3353 if ((p == (const Quantum *) NULL) ||
3354 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3355 ((left_image->columns-x-1) >= gap))
3358 i=(ssize_t) left_image->columns-x-1;
3359 for (x=0; x < (ssize_t) right_image->columns; x++)
3361 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3363 if ((p == (const Quantum *) NULL) ||
3364 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3365 ((x+i) >= (ssize_t) gap))
3368 if ((x+i) < (ssize_t) gap)
3371 right_view=DestroyCacheView(right_view);
3372 left_view=DestroyCacheView(left_view);
3373 if (y < (ssize_t) smush_image->rows)
3375 return((ssize_t) gap-offset);
3378 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3379 const ssize_t offset,ExceptionInfo *exception)
3393 register const Quantum
3406 if (images->previous == (Image *) NULL)
3408 bottom_image=images;
3409 SetGeometry(smush_image,&bottom_geometry);
3410 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3411 bottom_image->gravity,&bottom_geometry);
3412 top_image=images->previous;
3413 SetGeometry(smush_image,&top_geometry);
3414 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3416 gap=bottom_image->rows;
3417 top_view=AcquireVirtualCacheView(top_image,exception);
3418 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3419 for (x=0; x < (ssize_t) smush_image->columns; x++)
3421 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3423 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3424 if ((p == (const Quantum *) NULL) ||
3425 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3426 ((top_image->rows-y-1) >= gap))
3429 i=(ssize_t) top_image->rows-y-1;
3430 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3432 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3434 if ((p == (const Quantum *) NULL) ||
3435 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3436 ((y+i) >= (ssize_t) gap))
3439 if ((y+i) < (ssize_t) gap)
3442 bottom_view=DestroyCacheView(bottom_view);
3443 top_view=DestroyCacheView(top_view);
3444 if (x < (ssize_t) smush_image->columns)
3446 return((ssize_t) gap-offset);
3449 MagickExport Image *SmushImages(const Image *images,
3450 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3452 #define SmushImageTag "Smush/Image"
3473 register const Image
3486 Compute maximum area of smushed area.
3488 assert(images != (Image *) NULL);
3489 assert(images->signature == MagickCoreSignature);
3490 if (images->debug != MagickFalse)
3491 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3492 assert(exception != (ExceptionInfo *) NULL);
3493 assert(exception->signature == MagickCoreSignature);
3495 alpha_trait=image->alpha_trait;
3497 width=image->columns;
3499 next=GetNextImageInList(image);
3500 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3502 if (next->alpha_trait != UndefinedPixelTrait)
3503 alpha_trait=BlendPixelTrait;
3505 if (stack != MagickFalse)
3507 if (next->columns > width)
3508 width=next->columns;
3510 if (next->previous != (Image *) NULL)
3514 width+=next->columns;
3515 if (next->previous != (Image *) NULL)
3517 if (next->rows > height)
3523 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3524 if (smush_image == (Image *) NULL)
3525 return((Image *) NULL);
3526 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3528 smush_image=DestroyImage(smush_image);
3529 return((Image *) NULL);
3531 smush_image->alpha_trait=alpha_trait;
3532 (void) SetImageBackgroundColor(smush_image,exception);
3536 for (n=0; n < (MagickOffsetType) number_images; n++)
3538 SetGeometry(smush_image,&geometry);
3539 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3540 if (stack != MagickFalse)
3542 x_offset-=geometry.x;
3543 y_offset-=SmushYGap(smush_image,image,offset,exception);
3547 x_offset-=SmushXGap(smush_image,image,offset,exception);
3548 y_offset-=geometry.y;
3550 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3551 y_offset,exception);
3552 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3553 if (proceed == MagickFalse)
3555 if (stack == MagickFalse)
3557 x_offset+=(ssize_t) image->columns;
3563 y_offset+=(ssize_t) image->rows;
3565 image=GetNextImageInList(image);
3567 if (stack == MagickFalse)
3568 smush_image->columns=(size_t) x_offset;
3570 smush_image->rows=(size_t) y_offset;
3571 if (status == MagickFalse)
3572 smush_image=DestroyImage(smush_image);
3573 return(smush_image);
3577 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3581 % S t r i p I m a g e %
3585 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3587 % StripImage() strips an image of all profiles and comments.
3589 % The format of the StripImage method is:
3591 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3593 % A description of each parameter follows:
3595 % o image: the image.
3597 % o exception: return any errors or warnings in this structure.
3600 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3605 assert(image != (Image *) NULL);
3606 if (image->debug != MagickFalse)
3607 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3609 DestroyImageProfiles(image);
3610 (void) DeleteImageProperty(image,"comment");
3611 (void) DeleteImageProperty(image,"date:create");
3612 (void) DeleteImageProperty(image,"date:modify");
3613 status=SetImageArtifact(image,"png:exclude-chunk",
3614 "bKGD,cHRM,EXIF,gAMA,iCCP,iTXt,sRGB,tEXt,zCCP,zTXt,date");
3619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3623 + S y n c I m a g e %
3627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3629 % SyncImage() initializes the red, green, and blue intensities of each pixel
3630 % as defined by the colormap index.
3632 % The format of the SyncImage method is:
3634 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3636 % A description of each parameter follows:
3638 % o image: the image.
3640 % o exception: return any errors or warnings in this structure.
3644 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3645 MagickBooleanType *range_exception)
3647 if ((size_t) index < image->colors)
3649 *range_exception=MagickTrue;
3650 return((Quantum) 0);
3653 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3666 assert(image != (Image *) NULL);
3667 if (image->debug != MagickFalse)
3668 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3669 assert(image->signature == MagickCoreSignature);
3670 if (image->storage_class == DirectClass)
3671 return(MagickFalse);
3672 range_exception=MagickFalse;
3675 image_view=AcquireAuthenticCacheView(image,exception);
3676 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3677 #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
3678 magick_threads(image,image,image->rows,1)
3680 for (y=0; y < (ssize_t) image->rows; y++)
3691 if (status == MagickFalse)
3693 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3694 if (q == (Quantum *) NULL)
3699 for (x=0; x < (ssize_t) image->columns; x++)
3701 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3702 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
3703 q+=GetPixelChannels(image);
3705 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3708 image_view=DestroyCacheView(image_view);
3710 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3711 (void) ThrowMagickException(exception,GetMagickModule(),
3712 CorruptImageWarning,"InvalidColormapIndex","`%s'",image->filename);
3717 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3721 % S y n c I m a g e S e t t i n g s %
3725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3727 % SyncImageSettings() syncs any image_info global options into per-image
3730 % Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
3731 % that operations and coders can find such settings. In IMv7 if a desired
3732 % per-image artifact is not set, then it will directly look for a global
3733 % option as a fallback, as such this copy is no longer needed, only the
3736 % The format of the SyncImageSettings method is:
3738 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3739 % Image *image,ExceptionInfo *exception)
3740 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3741 % Image *image,ExceptionInfo *exception)
3743 % A description of each parameter follows:
3745 % o image_info: the image info.
3747 % o image: the image.
3749 % o exception: return any errors or warnings in this structure.
3753 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3754 Image *images,ExceptionInfo *exception)
3759 assert(image_info != (const ImageInfo *) NULL);
3760 assert(image_info->signature == MagickCoreSignature);
3761 assert(images != (Image *) NULL);
3762 assert(images->signature == MagickCoreSignature);
3763 if (images->debug != MagickFalse)
3764 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3766 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3767 (void) SyncImageSettings(image_info,image,exception);
3768 (void) DeleteImageOption(image_info,"page");
3772 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3773 Image *image,ExceptionInfo *exception)
3790 assert(image_info != (const ImageInfo *) NULL);
3791 assert(image_info->signature == MagickCoreSignature);
3792 assert(image != (Image *) NULL);
3793 assert(image->signature == MagickCoreSignature);
3794 if (image->debug != MagickFalse)
3795 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3796 option=GetImageOption(image_info,"alpha-color");
3797 if (option != (const char *) NULL)
3798 (void) QueryColorCompliance(option,AllCompliance,&image->alpha_color,
3800 option=GetImageOption(image_info,"background");
3801 if (option != (const char *) NULL)
3802 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
3804 option=GetImageOption(image_info,"black-point-compensation");
3805 if (option != (const char *) NULL)
3806 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3807 MagickBooleanOptions,MagickFalse,option);
3808 option=GetImageOption(image_info,"blue-primary");
3809 if (option != (const char *) NULL)
3811 flags=ParseGeometry(option,&geometry_info);
3812 image->chromaticity.blue_primary.x=geometry_info.rho;
3813 image->chromaticity.blue_primary.y=geometry_info.sigma;
3814 if ((flags & SigmaValue) == 0)
3815 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3817 option=GetImageOption(image_info,"bordercolor");
3818 if (option != (const char *) NULL)
3819 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
3821 /* FUTURE: do not sync compose to per-image compose setting here */
3822 option=GetImageOption(image_info,"compose");
3823 if (option != (const char *) NULL)
3824 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3825 MagickFalse,option);
3827 option=GetImageOption(image_info,"compress");
3828 if (option != (const char *) NULL)
3829 image->compression=(CompressionType) ParseCommandOption(
3830 MagickCompressOptions,MagickFalse,option);
3831 option=GetImageOption(image_info,"debug");
3832 if (option != (const char *) NULL)
3833 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3834 MagickFalse,option);
3835 option=GetImageOption(image_info,"density");
3836 if (option != (const char *) NULL)
3838 flags=ParseGeometry(option,&geometry_info);
3839 image->resolution.x=geometry_info.rho;
3840 image->resolution.y=geometry_info.sigma;
3841 if ((flags & SigmaValue) == 0)
3842 image->resolution.y=image->resolution.x;
3844 option=GetImageOption(image_info,"depth");
3845 if (option != (const char *) NULL)
3846 image->depth=StringToUnsignedLong(option);
3847 option=GetImageOption(image_info,"endian");
3848 if (option != (const char *) NULL)
3849 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3850 MagickFalse,option);
3851 option=GetImageOption(image_info,"filter");
3852 if (option != (const char *) NULL)
3853 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
3854 MagickFalse,option);
3855 option=GetImageOption(image_info,"fuzz");
3856 if (option != (const char *) NULL)
3857 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3858 option=GetImageOption(image_info,"gravity");
3859 if (option != (const char *) NULL)
3860 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3861 MagickFalse,option);
3862 option=GetImageOption(image_info,"green-primary");
3863 if (option != (const char *) NULL)
3865 flags=ParseGeometry(option,&geometry_info);
3866 image->chromaticity.green_primary.x=geometry_info.rho;
3867 image->chromaticity.green_primary.y=geometry_info.sigma;
3868 if ((flags & SigmaValue) == 0)
3869 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3871 option=GetImageOption(image_info,"intent");
3872 if (option != (const char *) NULL)
3873 image->rendering_intent=(RenderingIntent) ParseCommandOption(
3874 MagickIntentOptions,MagickFalse,option);
3875 option=GetImageOption(image_info,"intensity");
3876 if (option != (const char *) NULL)
3877 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3878 MagickPixelIntensityOptions,MagickFalse,option);
3879 option=GetImageOption(image_info,"interlace");
3880 if (option != (const char *) NULL)
3881 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3882 MagickFalse,option);
3883 option=GetImageOption(image_info,"interpolate");
3884 if (option != (const char *) NULL)
3885 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
3886 MagickInterpolateOptions,MagickFalse,option);
3887 option=GetImageOption(image_info,"loop");
3888 if (option != (const char *) NULL)
3889 image->iterations=StringToUnsignedLong(option);
3890 option=GetImageOption(image_info,"orient");
3891 if (option != (const char *) NULL)
3892 image->orientation=(OrientationType) ParseCommandOption(
3893 MagickOrientationOptions,MagickFalse,option);
3894 option=GetImageOption(image_info,"page");
3895 if (option != (const char *) NULL)
3900 geometry=GetPageGeometry(option);
3901 flags=ParseAbsoluteGeometry(geometry,&image->page);
3902 geometry=DestroyString(geometry);
3904 option=GetImageOption(image_info,"quality");
3905 if (option != (const char *) NULL)
3906 image->quality=StringToUnsignedLong(option);
3907 option=GetImageOption(image_info,"red-primary");
3908 if (option != (const char *) NULL)
3910 flags=ParseGeometry(option,&geometry_info);
3911 image->chromaticity.red_primary.x=geometry_info.rho;
3912 image->chromaticity.red_primary.y=geometry_info.sigma;
3913 if ((flags & SigmaValue) == 0)
3914 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3916 if (image_info->quality != UndefinedCompressionQuality)
3917 image->quality=image_info->quality;
3918 option=GetImageOption(image_info,"scene");
3919 if (option != (const char *) NULL)
3920 image->scene=StringToUnsignedLong(option);
3921 option=GetImageOption(image_info,"taint");
3922 if (option != (const char *) NULL)
3923 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3924 MagickFalse,option);
3925 option=GetImageOption(image_info,"tile-offset");
3926 if (option != (const char *) NULL)
3931 geometry=GetPageGeometry(option);
3932 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3933 geometry=DestroyString(geometry);
3935 option=GetImageOption(image_info,"transparent-color");
3936 if (option != (const char *) NULL)
3937 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
3939 option=GetImageOption(image_info,"type");
3940 if (option != (const char *) NULL)
3941 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3943 option=GetImageOption(image_info,"units");
3944 units=image_info->units;
3945 if (option != (const char *) NULL)
3946 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
3947 MagickFalse,option);
3948 if (units != UndefinedResolution)
3950 if (image->units != units)
3951 switch (image->units)
3953 case PixelsPerInchResolution:
3955 if (units == PixelsPerCentimeterResolution)
3957 image->resolution.x/=2.54;
3958 image->resolution.y/=2.54;
3962 case PixelsPerCentimeterResolution:
3964 if (units == PixelsPerInchResolution)
3966 image->resolution.x=(double) ((size_t) (100.0*2.54*
3967 image->resolution.x+0.5))/100.0;
3968 image->resolution.y=(double) ((size_t) (100.0*2.54*
3969 image->resolution.y+0.5))/100.0;
3978 option=GetImageOption(image_info,"virtual-pixel");
3979 if (option != (const char *) NULL)
3980 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
3981 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
3983 option=GetImageOption(image_info,"white-point");
3984 if (option != (const char *) NULL)
3986 flags=ParseGeometry(option,&geometry_info);
3987 image->chromaticity.white_point.x=geometry_info.rho;
3988 image->chromaticity.white_point.y=geometry_info.sigma;
3989 if ((flags & SigmaValue) == 0)
3990 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
3993 Pointer to allow the lookup of pre-image artifact will fallback to a global
3994 option setting/define. This saves a lot of duplication of global options
3995 into per-image artifacts, while ensuring only specifically set per-image
3996 artifacts are preserved when parenthesis ends.
3998 if (image->image_info != (ImageInfo *) NULL)
3999 image->image_info=DestroyImageInfo(image->image_info);
4000 image->image_info=CloneImageInfo(image_info);