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-2012 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/animate.h"
45 #include "MagickCore/artifact.h"
46 #include "MagickCore/attribute.h"
47 #include "MagickCore/blob.h"
48 #include "MagickCore/blob-private.h"
49 #include "MagickCore/cache.h"
50 #include "MagickCore/cache-private.h"
51 #include "MagickCore/cache-view.h"
52 #include "MagickCore/client.h"
53 #include "MagickCore/color.h"
54 #include "MagickCore/color-private.h"
55 #include "MagickCore/colormap.h"
56 #include "MagickCore/colorspace.h"
57 #include "MagickCore/colorspace-private.h"
58 #include "MagickCore/composite.h"
59 #include "MagickCore/composite-private.h"
60 #include "MagickCore/compress.h"
61 #include "MagickCore/constitute.h"
62 #include "MagickCore/display.h"
63 #include "MagickCore/draw.h"
64 #include "MagickCore/enhance.h"
65 #include "MagickCore/exception.h"
66 #include "MagickCore/exception-private.h"
67 #include "MagickCore/gem.h"
68 #include "MagickCore/geometry.h"
69 #include "MagickCore/histogram.h"
70 #include "MagickCore/image-private.h"
71 #include "MagickCore/list.h"
72 #include "MagickCore/magic.h"
73 #include "MagickCore/magick.h"
74 #include "MagickCore/magick-private.h"
75 #include "MagickCore/memory_.h"
76 #include "MagickCore/module.h"
77 #include "MagickCore/monitor.h"
78 #include "MagickCore/monitor-private.h"
79 #include "MagickCore/option.h"
80 #include "MagickCore/paint.h"
81 #include "MagickCore/pixel-accessor.h"
82 #include "MagickCore/profile.h"
83 #include "MagickCore/property.h"
84 #include "MagickCore/quantize.h"
85 #include "MagickCore/random_.h"
86 #include "MagickCore/segment.h"
87 #include "MagickCore/semaphore.h"
88 #include "MagickCore/signature-private.h"
89 #include "MagickCore/statistic.h"
90 #include "MagickCore/string_.h"
91 #include "MagickCore/string-private.h"
92 #include "MagickCore/thread-private.h"
93 #include "MagickCore/threshold.h"
94 #include "MagickCore/timer.h"
95 #include "MagickCore/token.h"
96 #include "MagickCore/utility.h"
97 #include "MagickCore/utility-private.h"
98 #include "MagickCore/version.h"
99 #include "MagickCore/xwindow-private.h"
102 Constant declaration.
105 BackgroundColor[] = "#ffffff", /* white */
106 BorderColor[] = "#dfdfdf", /* gray */
107 DefaultTileFrame[] = "15x15+3+3",
108 DefaultTileGeometry[] = "120x120+4+3>",
109 DefaultTileLabel[] = "%f\n%G\n%b",
110 ForegroundColor[] = "#000", /* black */
111 LoadImageTag[] = "Load/Image",
112 LoadImagesTag[] = "Load/Images",
113 MatteColor[] = "#bdbdbd", /* gray */
114 PSDensityGeometry[] = "72.0x72.0",
115 PSPageGeometry[] = "612x792",
116 SaveImageTag[] = "Save/Image",
117 SaveImagesTag[] = "Save/Images",
118 TransparentColor[] = "#00000000"; /* transparent black */
121 DefaultResolution = 72.0;
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 % A c q u i r e I m a g e %
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 % AcquireImage() returns a pointer to an image structure initialized to
137 % The format of the AcquireImage method is:
139 % Image *AcquireImage(const ImageInfo *image_info,ExceptionInfo *exception)
141 % A description of each parameter follows:
143 % o image_info: Many of the image default values are set from this
144 % structure. For example, filename, compression, depth, background color,
147 % o exception: return any errors or warnings in this structure.
150 MagickExport Image *AcquireImage(const ImageInfo *image_info,
151 ExceptionInfo *exception)
163 Allocate image structure.
165 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
166 image=(Image *) AcquireMagickMemory(sizeof(*image));
167 if (image == (Image *) NULL)
168 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
169 (void) ResetMagickMemory(image,0,sizeof(*image));
171 Initialize Image structure.
173 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
174 image->storage_class=DirectClass;
175 image->depth=MAGICKCORE_QUANTUM_DEPTH;
176 image->colorspace=sRGBColorspace;
177 image->rendering_intent=RelativeIntent;
178 image->gamma=0.45455;
179 image->chromaticity.red_primary.x=0.6400;
180 image->chromaticity.red_primary.y=0.3300;
181 image->chromaticity.green_primary.x=0.3000;
182 image->chromaticity.green_primary.y=0.6000;
183 image->chromaticity.blue_primary.x=0.1500;
184 image->chromaticity.blue_primary.y=0.0600;
185 image->chromaticity.white_point.x=0.3127;
186 image->chromaticity.white_point.y=0.3290;
187 image->interlace=NoInterlace;
188 image->ticks_per_second=UndefinedTicksPerSecond;
189 image->compose=OverCompositeOp;
190 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
191 &image->background_color,exception);
192 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
194 (void) QueryColorCompliance(MatteColor,AllCompliance,&image->matte_color,
196 (void) QueryColorCompliance(TransparentColor,AllCompliance,
197 &image->transparent_color,exception);
198 image->resolution.x=DefaultResolution;
199 image->resolution.y=DefaultResolution;
200 image->units=PixelsPerInchResolution;
201 GetTimerInfo(&image->timer);
202 image->cache=AcquirePixelCache(0);
203 image->channel_mask=DefaultChannels;
204 image->channel_map=AcquirePixelChannelMap();
205 image->blob=CloneBlobInfo((BlobInfo *) NULL);
206 image->debug=IsEventLogging();
207 image->reference_count=1;
208 image->semaphore=AllocateSemaphoreInfo();
209 image->signature=MagickSignature;
210 if (image_info == (ImageInfo *) NULL)
215 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
217 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
218 (void) CopyMagickString(image->magick_filename,image_info->filename,
220 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
221 if (image_info->size != (char *) NULL)
223 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
224 image->columns=image->extract_info.width;
225 image->rows=image->extract_info.height;
226 image->offset=image->extract_info.x;
227 image->extract_info.x=0;
228 image->extract_info.y=0;
230 if (image_info->extract != (char *) NULL)
235 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
236 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
238 image->extract_info=geometry;
239 Swap(image->columns,image->extract_info.width);
240 Swap(image->rows,image->extract_info.height);
243 image->compression=image_info->compression;
244 image->quality=image_info->quality;
245 image->endian=image_info->endian;
246 image->interlace=image_info->interlace;
247 image->units=image_info->units;
248 if (image_info->density != (char *) NULL)
253 flags=ParseGeometry(image_info->density,&geometry_info);
254 image->resolution.x=geometry_info.rho;
255 image->resolution.y=geometry_info.sigma;
256 if ((flags & SigmaValue) == 0)
257 image->resolution.y=image->resolution.x;
259 if (image_info->page != (char *) NULL)
264 image->page=image->extract_info;
265 geometry=GetPageGeometry(image_info->page);
266 (void) ParseAbsoluteGeometry(geometry,&image->page);
267 geometry=DestroyString(geometry);
269 if (image_info->depth != 0)
270 image->depth=image_info->depth;
271 image->dither=image_info->dither;
272 image->background_color=image_info->background_color;
273 image->border_color=image_info->border_color;
274 image->matte_color=image_info->matte_color;
275 image->transparent_color=image_info->transparent_color;
276 image->ping=image_info->ping;
277 image->progress_monitor=image_info->progress_monitor;
278 image->client_data=image_info->client_data;
279 if (image_info->cache != (void *) NULL)
280 ClonePixelCacheMethods(image->cache,image_info->cache);
281 (void) SyncImageSettings(image_info,image,exception);
282 option=GetImageOption(image_info,"delay");
283 if (option != (const char *) NULL)
288 flags=ParseGeometry(option,&geometry_info);
289 if ((flags & GreaterValue) != 0)
291 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
292 image->delay=(size_t) floor(geometry_info.rho+0.5);
295 if ((flags & LessValue) != 0)
297 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
298 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
301 image->delay=(size_t) floor(geometry_info.rho+0.5);
302 if ((flags & SigmaValue) != 0)
303 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
305 option=GetImageOption(image_info,"dispose");
306 if (option != (const char *) NULL)
307 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
317 % A c q u i r e I m a g e I n f o %
321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323 % AcquireImageInfo() allocates the ImageInfo structure.
325 % The format of the AcquireImageInfo method is:
327 % ImageInfo *AcquireImageInfo(void)
330 MagickExport ImageInfo *AcquireImageInfo(void)
335 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
336 if (image_info == (ImageInfo *) NULL)
337 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
338 GetImageInfo(image_info);
343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347 % A c q u i r e N e x t I m a g e %
351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353 % AcquireNextImage() initializes the next image in a sequence to
354 % default values. The next member of image points to the newly allocated
355 % image. If there is a memory shortage, next is assigned NULL.
357 % The format of the AcquireNextImage method is:
359 % void AcquireNextImage(const ImageInfo *image_info,Image *image,
360 % ExceptionInfo *exception)
362 % A description of each parameter follows:
364 % o image_info: Many of the image default values are set from this
365 % structure. For example, filename, compression, depth, background color,
368 % o image: the image.
370 % o exception: return any errors or warnings in this structure.
373 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image,
374 ExceptionInfo *exception)
377 Allocate image structure.
379 assert(image != (Image *) NULL);
380 assert(image->signature == MagickSignature);
381 if (image->debug != MagickFalse)
382 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
383 image->next=AcquireImage(image_info,exception);
384 if (GetNextImageInList(image) == (Image *) NULL)
386 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
388 if (image_info != (ImageInfo *) NULL)
389 (void) CopyMagickString(GetNextImageInList(image)->filename,
390 image_info->filename,MaxTextExtent);
391 DestroyBlob(GetNextImageInList(image));
392 image->next->blob=ReferenceBlob(image->blob);
393 image->next->endian=image->endian;
394 image->next->scene=image->scene+1;
395 image->next->previous=image;
399 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
403 % A p p e n d I m a g e s %
407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409 % AppendImages() takes all images from the current image pointer to the end
410 % of the image list and appends them to each other top-to-bottom if the
411 % stack parameter is true, otherwise left-to-right.
413 % The current gravity setting effects how the image is justified in the
416 % The format of the AppendImages method is:
418 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
419 % ExceptionInfo *exception)
421 % A description of each parameter follows:
423 % o images: the image sequence.
425 % o stack: A value other than 0 stacks the images top-to-bottom.
427 % o exception: return any errors or warnings in this structure.
430 MagickExport Image *AppendImages(const Image *images,
431 const MagickBooleanType stack,ExceptionInfo *exception)
433 #define AppendImageTag "Append/Image"
466 Compute maximum area of appended area.
468 assert(images != (Image *) NULL);
469 assert(images->signature == MagickSignature);
470 if (images->debug != MagickFalse)
471 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
472 assert(exception != (ExceptionInfo *) NULL);
473 assert(exception->signature == MagickSignature);
476 width=images->columns;
478 next=GetNextImageInList(images);
479 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
481 if (next->matte != MagickFalse)
484 if (stack != MagickFalse)
486 if (next->columns > width)
491 width+=next->columns;
492 if (next->rows > height)
498 append_image=CloneImage(images,width,height,MagickTrue,exception);
499 if (append_image == (Image *) NULL)
500 return((Image *) NULL);
501 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
503 append_image=DestroyImage(append_image);
504 return((Image *) NULL);
506 append_image->matte=matte;
507 (void) SetImageBackgroundColor(append_image,exception);
512 append_view=AcquireCacheView(append_image);
513 for (n=0; n < (MagickOffsetType) number_images; n++)
521 image=CloneImage(next,0,0,MagickTrue,exception);
522 if (image == (Image *) NULL)
524 (void) TransformImageColorspace(image,append_image->colorspace,exception);
525 SetGeometry(append_image,&geometry);
526 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
527 if (stack != MagickFalse)
528 x_offset-=geometry.x;
530 y_offset-=geometry.y;
531 image_view=AcquireCacheView(image);
532 #if defined(MAGICKCORE_OPENMP_SUPPORT)
533 #pragma omp parallel for schedule(static) shared(status)
535 for (y=0; y < (ssize_t) image->rows; y++)
543 register const Quantum
552 if (status == MagickFalse)
554 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
555 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
556 image->columns,1,exception);
557 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
562 GetPixelInfo(image,&pixel);
563 for (x=0; x < (ssize_t) image->columns; x++)
565 if (GetPixelMask(image,p) != 0)
567 p+=GetPixelChannels(image);
568 q+=GetPixelChannels(append_image);
571 GetPixelInfoPixel(image,p,&pixel);
572 SetPixelInfoPixel(append_image,&pixel,q);
573 p+=GetPixelChannels(image);
574 q+=GetPixelChannels(append_image);
576 sync=SyncCacheViewAuthenticPixels(append_view,exception);
577 if (sync == MagickFalse)
580 image_view=DestroyCacheView(image_view);
581 if (stack == MagickFalse)
583 x_offset+=(ssize_t) image->columns;
589 y_offset+=(ssize_t) image->rows;
591 image=DestroyImage(image);
592 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
593 if (proceed == MagickFalse)
595 next=GetNextImageInList(next);
597 append_view=DestroyCacheView(append_view);
598 if (status == MagickFalse)
599 append_image=DestroyImage(append_image);
600 return(append_image);
604 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608 % C a t c h I m a g e E x c e p t i o n %
612 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
614 % CatchImageException() returns if no exceptions are found in the image
615 % sequence, otherwise it determines the most severe exception and reports
616 % it as a warning or error depending on the severity.
618 % The format of the CatchImageException method is:
620 % ExceptionType CatchImageException(Image *image)
622 % A description of each parameter follows:
624 % o image: An image sequence.
627 MagickExport ExceptionType CatchImageException(Image *image)
635 assert(image != (const Image *) NULL);
636 assert(image->signature == MagickSignature);
637 if (image->debug != MagickFalse)
638 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
639 exception=AcquireExceptionInfo();
640 CatchException(exception);
641 severity=exception->severity;
642 exception=DestroyExceptionInfo(exception);
647 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
651 % C l i p I m a g e P a t h %
655 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
657 % ClipImagePath() sets the image clip mask based any clipping path information
660 % The format of the ClipImagePath method is:
662 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
663 % const MagickBooleanType inside,ExceptionInfo *exception)
665 % A description of each parameter follows:
667 % o image: the image.
669 % o pathname: name of clipping path resource. If name is preceded by #, use
670 % clipping path numbered by name.
672 % o inside: if non-zero, later operations take effect inside clipping path.
673 % Otherwise later operations take effect outside clipping path.
675 % o exception: return any errors or warnings in this structure.
679 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
681 return(ClipImagePath(image,"#1",MagickTrue,exception));
684 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
685 const MagickBooleanType inside,ExceptionInfo *exception)
687 #define ClipImagePathTag "ClipPath/Image"
701 assert(image != (const Image *) NULL);
702 assert(image->signature == MagickSignature);
703 if (image->debug != MagickFalse)
704 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
705 assert(pathname != NULL);
706 property=AcquireString(pathname);
707 (void) FormatLocaleString(property,MaxTextExtent,"8BIM:1999,2998:%s",
709 value=GetImageProperty(image,property,exception);
710 property=DestroyString(property);
711 if (value == (const char *) NULL)
713 ThrowFileException(exception,OptionError,"NoClipPathDefined",
717 image_info=AcquireImageInfo();
718 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
719 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
720 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
721 image_info=DestroyImageInfo(image_info);
722 if (clip_mask == (Image *) NULL)
724 if (clip_mask->storage_class == PseudoClass)
726 (void) SyncImage(clip_mask,exception);
727 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
730 if (inside == MagickFalse)
731 (void) NegateImage(clip_mask,MagickFalse,exception);
732 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
733 "8BIM:1999,2998:%s\nPS",pathname);
734 (void) SetImageMask(image,clip_mask,exception);
735 clip_mask=DestroyImage(clip_mask);
740 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
744 % C l o n e I m a g e %
748 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
750 % CloneImage() copies an image and returns the copy as a new image object.
752 % If the specified columns and rows is 0, an exact copy of the image is
753 % returned, otherwise the pixel data is undefined and must be initialized
754 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
755 % failure, a NULL image is returned and exception describes the reason for the
758 % The format of the CloneImage method is:
760 % Image *CloneImage(const Image *image,const size_t columns,
761 % const size_t rows,const MagickBooleanType orphan,
762 % ExceptionInfo *exception)
764 % A description of each parameter follows:
766 % o image: the image.
768 % o columns: the number of columns in the cloned image.
770 % o rows: the number of rows in the cloned image.
772 % o detach: With a value other than 0, the cloned image is detached from
773 % its parent I/O stream.
775 % o exception: return any errors or warnings in this structure.
778 MagickExport Image *CloneImage(const Image *image,const size_t columns,
779 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
793 assert(image != (const Image *) NULL);
794 assert(image->signature == MagickSignature);
795 if (image->debug != MagickFalse)
796 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
797 assert(exception != (ExceptionInfo *) NULL);
798 assert(exception->signature == MagickSignature);
799 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
800 if (clone_image == (Image *) NULL)
801 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
802 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
803 clone_image->signature=MagickSignature;
804 clone_image->storage_class=image->storage_class;
805 clone_image->number_channels=image->number_channels;
806 clone_image->number_meta_channels=image->number_meta_channels;
807 clone_image->metacontent_extent=image->metacontent_extent;
808 clone_image->colorspace=image->colorspace;
809 clone_image->mask=image->mask;
810 clone_image->matte=image->matte;
811 clone_image->columns=image->columns;
812 clone_image->rows=image->rows;
813 clone_image->dither=image->dither;
814 if (image->colormap != (PixelInfo *) NULL)
817 Allocate and copy the image colormap.
819 clone_image->colors=image->colors;
820 length=(size_t) image->colors;
821 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
822 sizeof(*clone_image->colormap));
823 if (clone_image->colormap == (PixelInfo *) NULL)
824 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
825 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
826 sizeof(*clone_image->colormap));
828 (void) CloneImageProfiles(clone_image,image);
829 (void) CloneImageProperties(clone_image,image);
830 (void) CloneImageArtifacts(clone_image,image);
831 GetTimerInfo(&clone_image->timer);
832 if (image->ascii85 != (void *) NULL)
833 Ascii85Initialize(clone_image);
834 clone_image->magick_columns=image->magick_columns;
835 clone_image->magick_rows=image->magick_rows;
836 clone_image->type=image->type;
837 clone_image->channel_mask=image->channel_mask;
838 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
839 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
841 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
842 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
843 clone_image->progress_monitor=image->progress_monitor;
844 clone_image->client_data=image->client_data;
845 clone_image->reference_count=1;
846 clone_image->next=image->next;
847 clone_image->previous=image->previous;
848 clone_image->list=NewImageList();
849 if (detach == MagickFalse)
850 clone_image->blob=ReferenceBlob(image->blob);
853 clone_image->next=NewImageList();
854 clone_image->previous=NewImageList();
855 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
857 clone_image->ping=image->ping;
858 clone_image->debug=IsEventLogging();
859 clone_image->semaphore=AllocateSemaphoreInfo();
860 if ((columns == 0) && (rows == 0))
862 if (image->montage != (char *) NULL)
863 (void) CloneString(&clone_image->montage,image->montage);
864 if (image->directory != (char *) NULL)
865 (void) CloneString(&clone_image->directory,image->directory);
866 clone_image->cache=ReferencePixelCache(image->cache);
869 scale=(MagickRealType) columns/(MagickRealType) image->columns;
870 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
871 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
872 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
873 scale=(MagickRealType) rows/(MagickRealType) image->rows;
874 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
875 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
876 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
877 clone_image->columns=columns;
878 clone_image->rows=rows;
879 clone_image->cache=ClonePixelCache(image->cache);
884 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
888 % C l o n e I m a g e I n f o %
892 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
894 % CloneImageInfo() makes a copy of the given image info structure. If
895 % NULL is specified, a new image info structure is created initialized to
898 % The format of the CloneImageInfo method is:
900 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
902 % A description of each parameter follows:
904 % o image_info: the image info.
907 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
912 clone_info=AcquireImageInfo();
913 if (image_info == (ImageInfo *) NULL)
915 clone_info->compression=image_info->compression;
916 clone_info->temporary=image_info->temporary;
917 clone_info->adjoin=image_info->adjoin;
918 clone_info->antialias=image_info->antialias;
919 clone_info->scene=image_info->scene;
920 clone_info->number_scenes=image_info->number_scenes;
921 clone_info->depth=image_info->depth;
922 (void) CloneString(&clone_info->size,image_info->size);
923 (void) CloneString(&clone_info->extract,image_info->extract);
924 (void) CloneString(&clone_info->scenes,image_info->scenes);
925 (void) CloneString(&clone_info->page,image_info->page);
926 clone_info->interlace=image_info->interlace;
927 clone_info->endian=image_info->endian;
928 clone_info->units=image_info->units;
929 clone_info->quality=image_info->quality;
930 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
931 (void) CloneString(&clone_info->server_name,image_info->server_name);
932 (void) CloneString(&clone_info->font,image_info->font);
933 (void) CloneString(&clone_info->texture,image_info->texture);
934 (void) CloneString(&clone_info->density,image_info->density);
935 clone_info->pointsize=image_info->pointsize;
936 clone_info->fuzz=image_info->fuzz;
937 clone_info->background_color=image_info->background_color;
938 clone_info->border_color=image_info->border_color;
939 clone_info->matte_color=image_info->matte_color;
940 clone_info->transparent_color=image_info->transparent_color;
941 clone_info->dither=image_info->dither;
942 clone_info->monochrome=image_info->monochrome;
943 clone_info->colorspace=image_info->colorspace;
944 clone_info->type=image_info->type;
945 clone_info->orientation=image_info->orientation;
946 clone_info->preview_type=image_info->preview_type;
947 clone_info->group=image_info->group;
948 clone_info->ping=image_info->ping;
949 clone_info->verbose=image_info->verbose;
950 (void) CloneString(&clone_info->view,image_info->view);
951 clone_info->progress_monitor=image_info->progress_monitor;
952 clone_info->client_data=image_info->client_data;
953 clone_info->cache=image_info->cache;
954 if (image_info->cache != (void *) NULL)
955 clone_info->cache=ReferencePixelCache(image_info->cache);
956 if (image_info->profile != (void *) NULL)
957 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
958 image_info->profile);
959 SetImageInfoFile(clone_info,image_info->file);
960 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
961 clone_info->stream=image_info->stream;
962 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
963 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
964 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
965 (void) CopyMagickString(clone_info->filename,image_info->filename,
967 clone_info->channel=image_info->channel;
968 (void) CloneImageOptions(clone_info,image_info);
969 clone_info->debug=IsEventLogging();
970 clone_info->signature=image_info->signature;
975 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
979 % D e s t r o y I m a g e %
983 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
985 % DestroyImage() dereferences an image, deallocating memory associated with
986 % the image if the reference count becomes zero.
988 % The format of the DestroyImage method is:
990 % Image *DestroyImage(Image *image)
992 % A description of each parameter follows:
994 % o image: the image.
997 MagickExport Image *DestroyImage(Image *image)
1005 assert(image != (Image *) NULL);
1006 assert(image->signature == MagickSignature);
1007 if (image->debug != MagickFalse)
1008 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1009 destroy=MagickFalse;
1010 LockSemaphoreInfo(image->semaphore);
1011 image->reference_count--;
1012 if (image->reference_count == 0)
1014 UnlockSemaphoreInfo(image->semaphore);
1015 if (destroy == MagickFalse)
1016 return((Image *) NULL);
1020 DestroyImagePixels(image);
1021 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1022 if (image->montage != (char *) NULL)
1023 image->montage=DestroyString(image->montage);
1024 if (image->directory != (char *) NULL)
1025 image->directory=DestroyString(image->directory);
1026 if (image->colormap != (PixelInfo *) NULL)
1027 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1028 if (image->geometry != (char *) NULL)
1029 image->geometry=DestroyString(image->geometry);
1030 DestroyImageProfiles(image);
1031 DestroyImageProperties(image);
1032 DestroyImageArtifacts(image);
1033 if (image->ascii85 != (Ascii85Info*) NULL)
1034 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1036 if (image->semaphore != (SemaphoreInfo *) NULL)
1037 DestroySemaphoreInfo(&image->semaphore);
1038 image->signature=(~MagickSignature);
1039 image=(Image *) RelinquishMagickMemory(image);
1044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1048 % D e s t r o y I m a g e I n f o %
1052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1054 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1057 % The format of the DestroyImageInfo method is:
1059 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1061 % A description of each parameter follows:
1063 % o image_info: the image info.
1066 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1068 assert(image_info != (ImageInfo *) NULL);
1069 assert(image_info->signature == MagickSignature);
1070 if (image_info->debug != MagickFalse)
1071 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1072 image_info->filename);
1073 if (image_info->size != (char *) NULL)
1074 image_info->size=DestroyString(image_info->size);
1075 if (image_info->extract != (char *) NULL)
1076 image_info->extract=DestroyString(image_info->extract);
1077 if (image_info->scenes != (char *) NULL)
1078 image_info->scenes=DestroyString(image_info->scenes);
1079 if (image_info->page != (char *) NULL)
1080 image_info->page=DestroyString(image_info->page);
1081 if (image_info->sampling_factor != (char *) NULL)
1082 image_info->sampling_factor=DestroyString(
1083 image_info->sampling_factor);
1084 if (image_info->server_name != (char *) NULL)
1085 image_info->server_name=DestroyString(
1086 image_info->server_name);
1087 if (image_info->font != (char *) NULL)
1088 image_info->font=DestroyString(image_info->font);
1089 if (image_info->texture != (char *) NULL)
1090 image_info->texture=DestroyString(image_info->texture);
1091 if (image_info->density != (char *) NULL)
1092 image_info->density=DestroyString(image_info->density);
1093 if (image_info->view != (char *) NULL)
1094 image_info->view=DestroyString(image_info->view);
1095 if (image_info->cache != (void *) NULL)
1096 image_info->cache=DestroyPixelCache(image_info->cache);
1097 if (image_info->profile != (StringInfo *) NULL)
1098 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1099 image_info->profile);
1100 DestroyImageOptions(image_info);
1101 image_info->signature=(~MagickSignature);
1102 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1111 + D i s a s s o c i a t e I m a g e S t r e a m %
1115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1117 % DisassociateImageStream() disassociates the image stream.
1119 % The format of the DisassociateImageStream method is:
1121 % MagickBooleanType DisassociateImageStream(const Image *image)
1123 % A description of each parameter follows:
1125 % o image: the image.
1128 MagickExport void DisassociateImageStream(Image *image)
1130 assert(image != (const Image *) NULL);
1131 assert(image->signature == MagickSignature);
1132 if (image->debug != MagickFalse)
1133 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1134 (void) DetachBlob(image->blob);
1138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1142 % G e t I m a g e A l p h a C h a n n e l %
1146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1148 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1149 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
1152 % The format of the GetImageAlphaChannel method is:
1154 % MagickBooleanType GetImageAlphaChannel(const Image *image)
1156 % A description of each parameter follows:
1158 % o image: the image.
1161 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1163 assert(image != (const Image *) NULL);
1164 if (image->debug != MagickFalse)
1165 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1166 assert(image->signature == MagickSignature);
1167 return(image->matte);
1171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1175 % G e t I m a g e I n f o %
1179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1181 % GetImageInfo() initializes image_info to default values.
1183 % The format of the GetImageInfo method is:
1185 % void GetImageInfo(ImageInfo *image_info)
1187 % A description of each parameter follows:
1189 % o image_info: the image info.
1192 MagickExport void GetImageInfo(ImageInfo *image_info)
1198 File and image dimension members.
1200 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1201 assert(image_info != (ImageInfo *) NULL);
1202 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1203 image_info->adjoin=MagickTrue;
1204 image_info->interlace=NoInterlace;
1205 image_info->channel=DefaultChannels;
1206 image_info->quality=UndefinedCompressionQuality;
1207 image_info->antialias=MagickTrue;
1208 image_info->dither=MagickTrue;
1209 image_info->synchronize=IsStringTrue(GetEnvironmentValue(
1210 "MAGICK_SYNCHRONIZE"));
1211 exception=AcquireExceptionInfo();
1212 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1213 &image_info->background_color,exception);
1214 (void) QueryColorCompliance(BorderColor,AllCompliance,
1215 &image_info->border_color,exception);
1216 (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
1218 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1219 &image_info->transparent_color,exception);
1220 exception=DestroyExceptionInfo(exception);
1221 image_info->debug=IsEventLogging();
1222 image_info->signature=MagickSignature;
1226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1230 % G e t I m a g e I n f o F i l e %
1234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1236 % GetImageInfoFile() returns the image info file member.
1238 % The format of the GetImageInfoFile method is:
1240 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1242 % A description of each parameter follows:
1244 % o image_info: the image info.
1247 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1249 return(image_info->file);
1253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1257 % G e t I m a g e M a s k %
1261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1263 % GetImageMask() returns the mask associated with the image.
1265 % The format of the GetImageMask method is:
1267 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1269 % A description of each parameter follows:
1271 % o image: the image.
1274 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1292 assert(image != (Image *) NULL);
1293 if (image->debug != MagickFalse)
1294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1295 assert(image->signature == MagickSignature);
1296 mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1297 if (mask_image == (Image *) NULL)
1298 return((Image *) NULL);
1300 mask_image->colorspace=GRAYColorspace;
1301 mask_image->mask=MagickFalse;
1302 image_view=AcquireCacheView(image);
1303 mask_view=AcquireCacheView(mask_image);
1304 for (y=0; y < (ssize_t) image->rows; y++)
1306 register const Quantum
1315 if (status == MagickFalse)
1317 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1318 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1320 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1325 for (x=0; x < (ssize_t) image->columns; x++)
1327 SetPixelGray(mask_image,GetPixelMask(image,p),q);
1328 p+=GetPixelChannels(image);
1329 q+=GetPixelChannels(mask_image);
1331 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1334 mask_view=DestroyCacheView(mask_view);
1335 image_view=DestroyCacheView(image_view);
1340 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1344 + G e t I m a g e R e f e r e n c e C o u n t %
1348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1350 % GetImageReferenceCount() returns the image reference count.
1352 % The format of the GetReferenceCount method is:
1354 % ssize_t GetImageReferenceCount(Image *image)
1356 % A description of each parameter follows:
1358 % o image: the image.
1361 MagickExport ssize_t GetImageReferenceCount(Image *image)
1366 assert(image != (Image *) NULL);
1367 assert(image->signature == MagickSignature);
1368 if (image->debug != MagickFalse)
1369 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1370 LockSemaphoreInfo(image->semaphore);
1371 reference_count=image->reference_count;
1372 UnlockSemaphoreInfo(image->semaphore);
1373 return(reference_count);
1377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1381 % 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 %
1385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1387 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1388 % image. A virtual pixel is any pixel access that is outside the boundaries
1389 % of the image cache.
1391 % The format of the GetImageVirtualPixelMethod() method is:
1393 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1395 % A description of each parameter follows:
1397 % o image: the image.
1400 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1402 assert(image != (Image *) NULL);
1403 assert(image->signature == MagickSignature);
1404 if (image->debug != MagickFalse)
1405 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1406 return(GetPixelCacheVirtualMethod(image));
1410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1414 % I n t e r p r e t I m a g e F i l e n a m e %
1418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1420 % InterpretImageFilename() interprets embedded characters in an image filename.
1421 % The filename length is returned.
1423 % The format of the InterpretImageFilename method is:
1425 % size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1426 % const char *format,int value,char *filename,ExceptionInfo *exception)
1428 % A description of each parameter follows.
1430 % o image_info: the image info..
1432 % o image: the image.
1434 % o format: A filename describing the format to use to write the numeric
1435 % argument. Only the first numeric format identifier is replaced.
1437 % o value: Numeric value to substitute into format filename.
1439 % o filename: return the formatted filename in this character buffer.
1441 % o exception: return any errors or warnings in this structure.
1444 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1445 Image *image,const char *format,int value,char *filename,
1446 ExceptionInfo *exception)
1463 canonical=MagickFalse;
1465 (void) CopyMagickString(filename,format,MaxTextExtent);
1466 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1479 value=(ssize_t) strtol(q,&q,10);
1491 (void) FormatLocaleString(filename+(p-format),(size_t) (MaxTextExtent-
1492 (p-format)),p,value);
1494 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1495 canonical=MagickTrue;
1504 pattern[MaxTextExtent];
1521 if (strchr(p,']') == (char *) NULL)
1525 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1536 if (LocaleNCompare(pattern,"filename:",9) != 0)
1538 value=(const char *) NULL;
1539 if ((image_info != (const ImageInfo *) NULL) &&
1540 (image != (const Image *) NULL))
1541 value=GetMagickProperty(image_info,image,pattern,exception);
1543 if (image != (Image *) NULL)
1544 value=GetImageProperty(image,pattern,exception);
1546 if (image_info != (ImageInfo *) NULL)
1547 value=GetImageOption(image_info,pattern);
1548 if (value == (const char *) NULL)
1553 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1554 (MaxTextExtent-(p-format-length)));
1555 length+=strlen(pattern)-1;
1557 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1558 canonical=MagickTrue;
1568 for (q=filename; *q != '\0'; q++)
1569 if ((*q == '%') && (*(q+1) == '%'))
1571 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1572 canonical=MagickTrue;
1574 if (canonical == MagickFalse)
1575 (void) CopyMagickString(filename,format,MaxTextExtent);
1576 return(strlen(filename));
1580 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1584 % I s H i g h D y n a m i c R a n g e I m a g e %
1588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1590 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1591 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1594 % The format of the IsHighDynamicRangeImage method is:
1596 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1597 % ExceptionInfo *exception)
1599 % A description of each parameter follows:
1601 % o image: the image.
1603 % o exception: return any errors or warnings in this structure.
1606 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1607 ExceptionInfo *exception)
1609 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1612 return(MagickFalse);
1623 assert(image != (Image *) NULL);
1624 assert(image->signature == MagickSignature);
1625 if (image->debug != MagickFalse)
1626 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1628 image_view=AcquireCacheView(image);
1629 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1630 #pragma omp parallel for schedule(static,4) shared(status)
1632 for (y=0; y < (ssize_t) image->rows; y++)
1634 register const Quantum
1640 if (status == MagickFalse)
1642 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1643 if (p == (const Quantum *) NULL)
1648 for (x=0; x < (ssize_t) image->columns; x++)
1656 if (GetPixelMask(image,p) != 0)
1658 p+=GetPixelChannels(image);
1661 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1666 traits=GetPixelChannelMapTraits(image,i);
1667 if (traits == UndefinedPixelTrait)
1669 pixel=(MagickRealType) p[i];
1670 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1671 (pixel != (QuantumAny) pixel))
1674 p+=GetPixelChannels(image);
1675 if (i < (ssize_t) GetPixelChannels(image))
1678 if (x < (ssize_t) image->columns)
1681 image_view=DestroyCacheView(image_view);
1682 return(status != MagickFalse ? MagickFalse : MagickTrue);
1687 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1691 % I s I m a g e O b j e c t %
1695 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1697 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1698 % set of image objects.
1700 % The format of the IsImageObject method is:
1702 % MagickBooleanType IsImageObject(const Image *image)
1704 % A description of each parameter follows:
1706 % o image: the image.
1709 MagickExport MagickBooleanType IsImageObject(const Image *image)
1711 register const Image
1714 assert(image != (Image *) NULL);
1715 if (image->debug != MagickFalse)
1716 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1717 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1718 if (p->signature != MagickSignature)
1719 return(MagickFalse);
1724 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1728 % I s T a i n t I m a g e %
1732 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1734 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1735 % since it was first constituted.
1737 % The format of the IsTaintImage method is:
1739 % MagickBooleanType IsTaintImage(const Image *image)
1741 % A description of each parameter follows:
1743 % o image: the image.
1746 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1749 magick[MaxTextExtent],
1750 filename[MaxTextExtent];
1752 register const Image
1755 assert(image != (Image *) NULL);
1756 if (image->debug != MagickFalse)
1757 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1758 assert(image->signature == MagickSignature);
1759 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
1760 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1761 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1763 if (p->taint != MagickFalse)
1765 if (LocaleCompare(p->magick,magick) != 0)
1767 if (LocaleCompare(p->filename,filename) != 0)
1770 return(MagickFalse);
1774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1778 % M o d i f y I m a g e %
1782 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1784 % ModifyImage() ensures that there is only a single reference to the image
1785 % to be modified, updating the provided image pointer to point to a clone of
1786 % the original image if necessary.
1788 % The format of the ModifyImage method is:
1790 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1792 % A description of each parameter follows:
1794 % o image: the image.
1796 % o exception: return any errors or warnings in this structure.
1799 MagickExport MagickBooleanType ModifyImage(Image **image,
1800 ExceptionInfo *exception)
1805 assert(image != (Image **) NULL);
1806 assert(*image != (Image *) NULL);
1807 assert((*image)->signature == MagickSignature);
1808 if ((*image)->debug != MagickFalse)
1809 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1810 if (GetImageReferenceCount(*image) <= 1)
1812 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1813 LockSemaphoreInfo((*image)->semaphore);
1814 (*image)->reference_count--;
1815 UnlockSemaphoreInfo((*image)->semaphore);
1821 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1825 % N e w M a g i c k I m a g e %
1829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1831 % NewMagickImage() creates a blank image canvas of the specified size and
1834 % The format of the NewMagickImage method is:
1836 % Image *NewMagickImage(const ImageInfo *image_info,
1837 % const size_t width,const size_t height,const PixelInfo *background,
1838 % ExceptionInfo *exception)
1840 % A description of each parameter follows:
1842 % o image: the image.
1844 % o width: the image width.
1846 % o height: the image height.
1848 % o background: the image color.
1850 % o exception: return any errors or warnings in this structure.
1853 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
1854 const size_t width,const size_t height,const PixelInfo *background,
1855 ExceptionInfo *exception)
1869 assert(image_info != (const ImageInfo *) NULL);
1870 if (image_info->debug != MagickFalse)
1871 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1872 assert(image_info->signature == MagickSignature);
1873 assert(background != (const PixelInfo *) NULL);
1874 image=AcquireImage(image_info,exception);
1875 image->columns=width;
1877 image->colorspace=background->colorspace;
1878 image->matte=background->matte;
1879 image->fuzz=background->fuzz;
1880 image->depth=background->depth;
1882 image_view=AcquireCacheView(image);
1883 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1884 #pragma omp parallel for schedule(static,4) shared(status)
1886 for (y=0; y < (ssize_t) image->rows; y++)
1894 if (status == MagickFalse)
1896 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
1897 if (q == (Quantum *) NULL)
1902 for (x=0; x < (ssize_t) image->columns; x++)
1904 SetPixelInfoPixel(image,background,q);
1905 q+=GetPixelChannels(image);
1907 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1910 image_view=DestroyCacheView(image_view);
1911 if (status == MagickFalse)
1912 image=DestroyImage(image);
1917 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1921 % R e f e r e n c e I m a g e %
1925 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1927 % ReferenceImage() increments the reference count associated with an image
1928 % returning a pointer to the image.
1930 % The format of the ReferenceImage method is:
1932 % Image *ReferenceImage(Image *image)
1934 % A description of each parameter follows:
1936 % o image: the image.
1939 MagickExport Image *ReferenceImage(Image *image)
1941 assert(image != (Image *) NULL);
1942 if (image->debug != MagickFalse)
1943 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1944 assert(image->signature == MagickSignature);
1945 LockSemaphoreInfo(image->semaphore);
1946 image->reference_count++;
1947 UnlockSemaphoreInfo(image->semaphore);
1952 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1956 % R e s e t I m a g e P a g e %
1960 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1962 % ResetImagePage() resets the image page canvas and position.
1964 % The format of the ResetImagePage method is:
1966 % MagickBooleanType ResetImagePage(Image *image,const char *page)
1968 % A description of each parameter follows:
1970 % o image: the image.
1972 % o page: the relative page specification.
1975 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
1983 assert(image != (Image *) NULL);
1984 assert(image->signature == MagickSignature);
1985 if (image->debug != MagickFalse)
1986 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1987 flags=ParseAbsoluteGeometry(page,&geometry);
1988 if ((flags & WidthValue) != 0)
1990 if ((flags & HeightValue) == 0)
1991 geometry.height=geometry.width;
1992 image->page.width=geometry.width;
1993 image->page.height=geometry.height;
1995 if ((flags & AspectValue) != 0)
1997 if ((flags & XValue) != 0)
1998 image->page.x+=geometry.x;
1999 if ((flags & YValue) != 0)
2000 image->page.y+=geometry.y;
2004 if ((flags & XValue) != 0)
2006 image->page.x=geometry.x;
2007 if ((image->page.width == 0) && (geometry.x > 0))
2008 image->page.width=image->columns+geometry.x;
2010 if ((flags & YValue) != 0)
2012 image->page.y=geometry.y;
2013 if ((image->page.height == 0) && (geometry.y > 0))
2014 image->page.height=image->rows+geometry.y;
2021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2025 % S e t I m a g e A l p h a C h a n n e l %
2029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2031 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2034 % The format of the SetImageAlphaChannel method is:
2036 % MagickBooleanType SetImageAlphaChannel(Image *image,
2037 % const AlphaChannelType alpha_type,ExceptionInfo *exception)
2039 % A description of each parameter follows:
2041 % o image: the image.
2043 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
2044 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2045 % OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
2046 % TransparentAlphaChannel.
2048 % o exception: return any errors or warnings in this structure.
2052 static inline void FlattenPixelInfo(const Image *image,const PixelInfo *p,
2053 const MagickRealType alpha,const Quantum *q,const MagickRealType beta,
2065 Compose pixel p over pixel q with the given alpha.
2067 Sa=QuantumScale*alpha;
2068 Da=QuantumScale*beta,
2069 gamma=Sa*(-Da)+Sa+Da;
2070 gamma=1.0/(gamma <= MagickEpsilon ? 1.0 : gamma);
2071 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2079 channel=GetPixelChannelMapChannel(image,i);
2080 traits=GetPixelChannelMapTraits(image,channel);
2081 if (traits == UndefinedPixelTrait)
2085 case RedPixelChannel:
2087 composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
2088 beta,(MagickRealType) p->red,alpha));
2091 case GreenPixelChannel:
2093 composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
2094 beta,(MagickRealType) p->green,alpha));
2097 case BluePixelChannel:
2099 composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
2100 beta,(MagickRealType) p->blue,alpha));
2103 case BlackPixelChannel:
2105 composite[i]=ClampToQuantum(gamma*MagickOver_((MagickRealType) q[i],
2106 beta,(MagickRealType) p->black,alpha));
2109 case AlphaPixelChannel:
2111 composite[i]=ClampToQuantum(QuantumRange*(Sa*(-Da)+Sa+Da));
2120 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2121 const AlphaChannelType alpha_type,ExceptionInfo *exception)
2126 assert(image != (Image *) NULL);
2127 if (image->debug != MagickFalse)
2128 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2129 assert(image->signature == MagickSignature);
2133 case ActivateAlphaChannel:
2135 image->matte=MagickTrue;
2138 case BackgroundAlphaChannel:
2147 Set transparent pixels to background color.
2149 if (image->matte == MagickFalse)
2151 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2153 image_view=AcquireCacheView(image);
2154 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2155 #pragma omp parallel for schedule(static,4) shared(status)
2157 for (y=0; y < (ssize_t) image->rows; y++)
2165 if (status == MagickFalse)
2167 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2169 if (q == (Quantum *) NULL)
2174 for (x=0; x < (ssize_t) image->columns; x++)
2176 if (GetPixelAlpha(image,q) == TransparentAlpha)
2177 SetPixelInfoPixel(image,&image->background_color,q);
2178 q+=GetPixelChannels(image);
2180 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2183 image_view=DestroyCacheView(image_view);
2186 case CopyAlphaChannel:
2187 case ShapeAlphaChannel:
2190 Copy pixel intensity to the alpha channel.
2192 status=CompositeImage(image,image,IntensityCompositeOp,MagickTrue,0,0,
2194 if (alpha_type == ShapeAlphaChannel)
2195 (void) LevelImageColors(image,&image->background_color,
2196 &image->background_color,MagickTrue,exception);
2199 case DeactivateAlphaChannel:
2201 image->matte=MagickFalse;
2204 case ExtractAlphaChannel:
2206 status=CompositeImage(image,image,AlphaCompositeOp,MagickTrue,0,0,
2208 image->matte=MagickFalse;
2211 case OpaqueAlphaChannel:
2213 status=SetImageAlpha(image,OpaqueAlpha,exception);
2216 case RemoveAlphaChannel:
2225 Remove transparency.
2227 if (image->matte == MagickFalse)
2229 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2231 image_view=AcquireCacheView(image);
2232 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2233 #pragma omp parallel for schedule(static,4) shared(status)
2235 for (y=0; y < (ssize_t) image->rows; y++)
2243 if (status == MagickFalse)
2245 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2247 if (q == (Quantum *) NULL)
2252 for (x=0; x < (ssize_t) image->columns; x++)
2254 FlattenPixelInfo(image,&image->background_color,
2255 image->background_color.alpha,q,(MagickRealType)
2256 GetPixelAlpha(image,q),q);
2257 q+=GetPixelChannels(image);
2259 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2262 image_view=DestroyCacheView(image_view);
2263 image->matte=image->background_color.matte;
2266 case SetAlphaChannel:
2268 if (image->matte == MagickFalse)
2269 status=SetImageAlpha(image,OpaqueAlpha,exception);
2272 case TransparentAlphaChannel:
2274 status=SetImageAlpha(image,TransparentAlpha,exception);
2277 case UndefinedAlphaChannel:
2280 if (status == MagickFalse)
2282 return(SyncImagePixelCache(image,exception));
2286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2290 % S e t I m a g e B a c k g r o u n d C o l o r %
2294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2296 % SetImageBackgroundColor() initializes the image pixels to the image
2297 % background color. The background color is defined by the background_color
2298 % member of the image structure.
2300 % The format of the SetImage method is:
2302 % MagickBooleanType SetImageBackgroundColor(Image *image,
2303 % ExceptionInfo *exception)
2305 % A description of each parameter follows:
2307 % o image: the image.
2309 % o exception: return any errors or warnings in this structure.
2312 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2313 ExceptionInfo *exception)
2324 assert(image != (Image *) NULL);
2325 if (image->debug != MagickFalse)
2326 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2327 assert(image->signature == MagickSignature);
2328 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2329 return(MagickFalse);
2330 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
2331 (IsPixelInfoGray(&image->background_color) == MagickFalse))
2332 (void) TransformImageColorspace(image,sRGBColorspace,exception);
2333 if ((image->background_color.matte != MagickFalse) &&
2334 (image->matte == MagickFalse))
2335 (void) SetImageAlpha(image,OpaqueAlpha,exception);
2337 Set image background color.
2340 image_view=AcquireCacheView(image);
2341 for (y=0; y < (ssize_t) image->rows; y++)
2349 if (status == MagickFalse)
2351 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2352 if (q == (Quantum *) NULL)
2357 for (x=0; x < (ssize_t) image->columns; x++)
2359 SetPixelInfoPixel(image,&image->background_color,q);
2360 q+=GetPixelChannels(image);
2362 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2365 image_view=DestroyCacheView(image_view);
2370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2374 % S e t I m a g e C o l o r %
2378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2380 % SetImageColor() set the entire image canvas to the specified color.
2382 % The format of the SetImageColor method is:
2384 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2385 % ExeptionInfo *exception)
2387 % A description of each parameter follows:
2389 % o image: the image.
2391 % o background: the image color.
2393 % o exception: return any errors or warnings in this structure.
2396 MagickExport MagickBooleanType SetImageColor(Image *image,
2397 const PixelInfo *color,ExceptionInfo *exception)
2408 assert(image != (Image *) NULL);
2409 if (image->debug != MagickFalse)
2410 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2411 assert(image->signature == MagickSignature);
2412 assert(color != (const PixelInfo *) NULL);
2413 image->colorspace=color->colorspace;
2414 image->matte=color->matte;
2415 image->fuzz=color->fuzz;
2416 image->depth=color->depth;
2418 image_view=AcquireCacheView(image);
2419 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2420 #pragma omp parallel for schedule(static,4) shared(status)
2422 for (y=0; y < (ssize_t) image->rows; y++)
2430 if (status == MagickFalse)
2432 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2433 if (q == (Quantum *) NULL)
2438 for (x=0; x < (ssize_t) image->columns; x++)
2440 SetPixelInfoPixel(image,color,q);
2441 q+=GetPixelChannels(image);
2443 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2446 image_view=DestroyCacheView(image_view);
2451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2455 % S e t I m a g e S t o r a g e C l a s s %
2459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2461 % SetImageStorageClass() sets the image class: DirectClass for true color
2462 % images or PseudoClass for colormapped images.
2464 % The format of the SetImageStorageClass method is:
2466 % MagickBooleanType SetImageStorageClass(Image *image,
2467 % const ClassType storage_class,ExceptionInfo *exception)
2469 % A description of each parameter follows:
2471 % o image: the image.
2473 % o storage_class: The image class.
2475 % o exception: return any errors or warnings in this structure.
2478 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2479 const ClassType storage_class,ExceptionInfo *exception)
2481 image->storage_class=storage_class;
2482 return(SyncImagePixelCache(image,exception));
2486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2490 % S e t I m a g e E x t e n t %
2494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2496 % SetImageExtent() sets the image size (i.e. columns & rows).
2498 % The format of the SetImageExtent method is:
2500 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2501 % const size_t rows,ExceptionInfo *exception)
2503 % A description of each parameter follows:
2505 % o image: the image.
2507 % o columns: The image width in pixels.
2509 % o rows: The image height in pixels.
2511 % o exception: return any errors or warnings in this structure.
2514 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2515 const size_t rows,ExceptionInfo *exception)
2517 if ((columns == 0) || (rows == 0))
2518 return(MagickFalse);
2519 image->columns=columns;
2521 return(SyncImagePixelCache(image,exception));
2525 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2529 + S e t I m a g e I n f o %
2533 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2535 % SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2536 % It is set to a type of image format based on the prefix or suffix of the
2537 % filename. For example, `ps:image' returns PS indicating a Postscript image.
2538 % JPEG is returned for this filename: `image.jpg'. The filename prefix has
2539 % precendence over the suffix. Use an optional index enclosed in brackets
2540 % after a file name to specify a desired scene of a multi-resolution image
2541 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2542 % indicates success.
2544 % The format of the SetImageInfo method is:
2546 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2547 % const unsigned int frames,ExceptionInfo *exception)
2549 % A description of each parameter follows:
2551 % o image_info: the image info.
2553 % o frames: the number of images you intend to write.
2555 % o exception: return any errors or warnings in this structure.
2558 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2559 const unsigned int frames,ExceptionInfo *exception)
2562 extension[MaxTextExtent],
2563 filename[MaxTextExtent],
2564 magic[MaxTextExtent],
2566 subimage[MaxTextExtent];
2590 magick[2*MaxTextExtent];
2593 Look for 'image.format' in filename.
2595 assert(image_info != (ImageInfo *) NULL);
2596 assert(image_info->signature == MagickSignature);
2597 if (image_info->debug != MagickFalse)
2598 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2599 image_info->filename);
2603 GetPathComponent(image_info->filename,SubimagePath,subimage);
2604 if (*subimage != '\0')
2607 Look for scene specification (e.g. img0001.pcd[4]).
2609 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
2611 if (IsGeometry(subimage) != MagickFalse)
2612 (void) CloneString(&image_info->extract,subimage);
2620 (void) CloneString(&image_info->scenes,subimage);
2621 image_info->scene=StringToUnsignedLong(image_info->scenes);
2622 image_info->number_scenes=image_info->scene;
2623 p=image_info->scenes;
2624 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2626 while ((isspace((int) ((unsigned char) *p)) != 0) ||
2629 first=(size_t) strtol(p,&q,10);
2631 while (isspace((int) ((unsigned char) *q)) != 0)
2634 last=(size_t) strtol(q+1,&q,10);
2637 if (first < image_info->scene)
2638 image_info->scene=first;
2639 if (last > image_info->number_scenes)
2640 image_info->number_scenes=last;
2643 image_info->number_scenes-=image_info->scene-1;
2648 GetPathComponent(image_info->filename,ExtensionPath,extension);
2649 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2650 if (*extension != '\0')
2651 if ((LocaleCompare(extension,"gz") == 0) ||
2652 (LocaleCompare(extension,"Z") == 0) ||
2653 (LocaleCompare(extension,"svgz") == 0) ||
2654 (LocaleCompare(extension,"wmz") == 0))
2657 path[MaxTextExtent];
2659 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
2660 path[strlen(path)-strlen(extension)-1]='\0';
2661 GetPathComponent(path,ExtensionPath,extension);
2664 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2665 if (*extension != '\0')
2666 if (LocaleCompare(extension,"bz2") == 0)
2669 path[MaxTextExtent];
2671 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
2672 path[strlen(path)-strlen(extension)-1]='\0';
2673 GetPathComponent(path,ExtensionPath,extension);
2676 image_info->affirm=MagickFalse;
2677 sans_exception=AcquireExceptionInfo();
2678 if (*extension != '\0')
2687 *format_type_formats[] =
2710 User specified image format.
2712 (void) CopyMagickString(magic,extension,MaxTextExtent);
2715 Look for explicit image formats.
2717 format_type=UndefinedFormatType;
2719 while ((format_type == UndefinedFormatType) &&
2720 (format_type_formats[i] != (char *) NULL))
2722 if ((*magic == *format_type_formats[i]) &&
2723 (LocaleCompare(magic,format_type_formats[i]) == 0))
2724 format_type=ExplicitFormatType;
2727 magick_info=GetMagickInfo(magic,sans_exception);
2728 if ((magick_info != (const MagickInfo *) NULL) &&
2729 (magick_info->format_type != UndefinedFormatType))
2730 format_type=magick_info->format_type;
2731 if (format_type == UndefinedFormatType)
2732 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2734 if (format_type == ExplicitFormatType)
2736 image_info->affirm=MagickTrue;
2737 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2739 if (LocaleCompare(magic,"RGB") == 0)
2740 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2743 Look for explicit 'format:image' in filename.
2746 GetPathComponent(image_info->filename,MagickPath,magic);
2748 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
2752 User specified image format.
2755 if (IsMagickConflict(magic) == MagickFalse)
2757 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2758 if (LocaleCompare(magic,"EPHEMERAL") != 0)
2759 image_info->affirm=MagickTrue;
2761 image_info->temporary=MagickTrue;
2764 magick_info=GetMagickInfo(magic,sans_exception);
2765 sans_exception=DestroyExceptionInfo(sans_exception);
2766 if ((magick_info == (const MagickInfo *) NULL) ||
2767 (GetMagickEndianSupport(magick_info) == MagickFalse))
2768 image_info->endian=UndefinedEndian;
2769 GetPathComponent(image_info->filename,CanonicalPath,filename);
2770 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
2771 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2774 Test for multiple image support (e.g. image%02d.png).
2776 (void) InterpretImageFilename(image_info,(Image *) NULL,
2777 image_info->filename,(int) image_info->scene,filename,exception);
2778 if ((LocaleCompare(filename,image_info->filename) != 0) &&
2779 (strchr(filename,'%') == (char *) NULL))
2780 image_info->adjoin=MagickFalse;
2782 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2785 Some image formats do not support multiple frames per file.
2787 magick_info=GetMagickInfo(magic,exception);
2788 if (magick_info != (const MagickInfo *) NULL)
2789 if (GetMagickAdjoin(magick_info) == MagickFalse)
2790 image_info->adjoin=MagickFalse;
2792 if (image_info->affirm != MagickFalse)
2797 Determine the image format from the first few bytes of the file.
2799 image=AcquireImage(image_info,exception);
2800 (void) CopyMagickString(image->filename,image_info->filename,
2802 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2803 if (status == MagickFalse)
2805 image=DestroyImage(image);
2806 return(MagickFalse);
2808 if ((IsBlobSeekable(image) == MagickFalse) ||
2809 (IsBlobExempt(image) != MagickFalse))
2812 Copy standard input or pipe to temporary file.
2815 status=ImageToFile(image,filename,exception);
2816 (void) CloseBlob(image);
2817 if (status == MagickFalse)
2819 image=DestroyImage(image);
2820 return(MagickFalse);
2822 SetImageInfoFile(image_info,(FILE *) NULL);
2823 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
2824 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2825 if (status == MagickFalse)
2827 image=DestroyImage(image);
2828 return(MagickFalse);
2830 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
2831 image_info->temporary=MagickTrue;
2833 (void) ResetMagickMemory(magick,0,sizeof(magick));
2834 count=ReadBlob(image,2*MaxTextExtent,magick);
2835 (void) CloseBlob(image);
2836 image=DestroyImage(image);
2838 Check magic.xml configuration file.
2840 sans_exception=AcquireExceptionInfo();
2841 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
2842 if ((magic_info != (const MagicInfo *) NULL) &&
2843 (GetMagicName(magic_info) != (char *) NULL))
2845 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
2847 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2848 if ((magick_info == (const MagickInfo *) NULL) ||
2849 (GetMagickEndianSupport(magick_info) == MagickFalse))
2850 image_info->endian=UndefinedEndian;
2851 sans_exception=DestroyExceptionInfo(sans_exception);
2854 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2855 if ((magick_info == (const MagickInfo *) NULL) ||
2856 (GetMagickEndianSupport(magick_info) == MagickFalse))
2857 image_info->endian=UndefinedEndian;
2858 sans_exception=DestroyExceptionInfo(sans_exception);
2864 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2868 % S e t I m a g e I n f o B l o b %
2872 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2874 % SetImageInfoBlob() sets the image info blob member.
2876 % The format of the SetImageInfoBlob method is:
2878 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2879 % const size_t length)
2881 % A description of each parameter follows:
2883 % o image_info: the image info.
2887 % o length: the blob length.
2890 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2891 const size_t length)
2893 assert(image_info != (ImageInfo *) NULL);
2894 assert(image_info->signature == MagickSignature);
2895 if (image_info->debug != MagickFalse)
2896 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2897 image_info->filename);
2898 image_info->blob=(void *) blob;
2899 image_info->length=length;
2903 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2907 % S e t I m a g e I n f o F i l e %
2911 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2913 % SetImageInfoFile() sets the image info file member.
2915 % The format of the SetImageInfoFile method is:
2917 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2919 % A description of each parameter follows:
2921 % o image_info: the image info.
2926 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2928 assert(image_info != (ImageInfo *) NULL);
2929 assert(image_info->signature == MagickSignature);
2930 if (image_info->debug != MagickFalse)
2931 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2932 image_info->filename);
2933 image_info->file=file;
2937 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2941 % S e t I m a g e M a s k %
2945 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2947 % SetImageMask() associates a mask with the image. The mask must be the same
2948 % dimensions as the image.
2950 % The format of the SetImageMask method is:
2952 % MagickBooleanType SetImageMask(Image *image,const Image *mask,
2953 % ExceptionInfo *exception)
2955 % A description of each parameter follows:
2957 % o image: the image.
2959 % o mask: the image mask.
2961 % o exception: return any errors or warnings in this structure.
2964 MagickExport MagickBooleanType SetImageMask(Image *image,const Image *mask,
2965 ExceptionInfo *exception)
2980 assert(image != (Image *) NULL);
2981 if (image->debug != MagickFalse)
2982 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2983 assert(image->signature == MagickSignature);
2984 if (mask == (const Image *) NULL)
2986 image->mask=MagickFalse;
2990 image->mask=MagickTrue;
2991 image_view=AcquireCacheView(image);
2992 mask_view=AcquireCacheView(mask);
2993 for (y=0; y < (ssize_t) image->rows; y++)
2995 register const Quantum
3004 if (status == MagickFalse)
3006 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3007 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3008 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3013 for (x=0; x < (ssize_t) image->columns; x++)
3015 SetPixelMask(image,GetPixelGray(mask,p),q);
3016 p+=GetPixelChannels(mask);
3017 q+=GetPixelChannels(image);
3019 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3022 mask_view=DestroyCacheView(mask_view);
3023 image_view=DestroyCacheView(image_view);
3028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3032 % S e t I m a g e A l p h a %
3036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3038 % SetImageAlpha() sets the alpha levels of the image.
3040 % The format of the SetImageAlpha method is:
3042 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3043 % ExceptionInfo *exception)
3045 % A description of each parameter follows:
3047 % o image: the image.
3049 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3050 % fully transparent.
3053 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3054 ExceptionInfo *exception)
3065 assert(image != (Image *) NULL);
3066 if (image->debug != MagickFalse)
3067 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3068 assert(image->signature == MagickSignature);
3069 image->matte=MagickTrue;
3071 image_view=AcquireCacheView(image);
3072 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3073 #pragma omp parallel for schedule(static,4) shared(status)
3075 for (y=0; y < (ssize_t) image->rows; y++)
3083 if (status == MagickFalse)
3085 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3086 if (q == (Quantum *) NULL)
3091 for (x=0; x < (ssize_t) image->columns; x++)
3093 SetPixelAlpha(image,alpha,q);
3094 q+=GetPixelChannels(image);
3096 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3099 image_view=DestroyCacheView(image_view);
3104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3108 % S e t I m a g e T y p e %
3112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3114 % SetImageType() sets the type of image. Choose from these types:
3116 % Bilevel Grayscale GrayscaleMatte
3117 % Palette PaletteMatte TrueColor
3118 % TrueColorMatte ColorSeparation ColorSeparationMatte
3121 % The format of the SetImageType method is:
3123 % MagickBooleanType SetImageType(Image *image,const ImageType type,
3124 % ExceptionInfo *exception)
3126 % A description of each parameter follows:
3128 % o image: the image.
3130 % o type: Image type.
3132 % o exception: return any errors or warnings in this structure.
3135 MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type,
3136 ExceptionInfo *exception)
3150 assert(image != (Image *) NULL);
3151 if (image->debug != MagickFalse)
3152 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3153 assert(image->signature == MagickSignature);
3155 image_info=AcquireImageInfo();
3156 image_info->dither=image->dither;
3157 artifact=GetImageArtifact(image,"dither");
3158 if (artifact != (const char *) NULL)
3159 (void) SetImageOption(image_info,"dither",artifact);
3164 if (IsImageMonochrome(image,exception) == MagickFalse)
3166 quantize_info=AcquireQuantizeInfo(image_info);
3167 quantize_info->number_colors=2;
3168 quantize_info->colorspace=GRAYColorspace;
3169 status=QuantizeImage(quantize_info,image,exception);
3170 quantize_info=DestroyQuantizeInfo(quantize_info);
3172 image->matte=MagickFalse;
3177 if (IsImageGray(image,exception) == MagickFalse)
3178 status=TransformImageColorspace(image,GRAYColorspace,exception);
3179 image->matte=MagickFalse;
3182 case GrayscaleMatteType:
3184 if (IsImageGray(image,exception) == MagickFalse)
3185 status=TransformImageColorspace(image,GRAYColorspace,exception);
3186 if (image->matte == MagickFalse)
3187 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3192 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3193 status=TransformImageColorspace(image,sRGBColorspace,exception);
3194 if ((image->storage_class == DirectClass) || (image->colors > 256))
3196 quantize_info=AcquireQuantizeInfo(image_info);
3197 quantize_info->number_colors=256;
3198 status=QuantizeImage(quantize_info,image,exception);
3199 quantize_info=DestroyQuantizeInfo(quantize_info);
3201 image->matte=MagickFalse;
3204 case PaletteBilevelMatteType:
3209 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3210 status=TransformImageColorspace(image,sRGBColorspace,exception);
3211 if (image->matte == MagickFalse)
3212 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3213 channel_mask=SetPixelChannelMask(image,AlphaChannel);
3214 (void) BilevelImage(image,(double) QuantumRange/2.0,exception);
3215 (void) SetPixelChannelMask(image,channel_mask);
3216 quantize_info=AcquireQuantizeInfo(image_info);
3217 status=QuantizeImage(quantize_info,image,exception);
3218 quantize_info=DestroyQuantizeInfo(quantize_info);
3221 case PaletteMatteType:
3223 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3224 status=TransformImageColorspace(image,sRGBColorspace,exception);
3225 if (image->matte == MagickFalse)
3226 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3227 quantize_info=AcquireQuantizeInfo(image_info);
3228 quantize_info->colorspace=TransparentColorspace;
3229 status=QuantizeImage(quantize_info,image,exception);
3230 quantize_info=DestroyQuantizeInfo(quantize_info);
3235 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3236 status=TransformImageColorspace(image,sRGBColorspace,exception);
3237 if (image->storage_class != DirectClass)
3238 status=SetImageStorageClass(image,DirectClass,exception);
3239 image->matte=MagickFalse;
3242 case TrueColorMatteType:
3244 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3245 status=TransformImageColorspace(image,sRGBColorspace,exception);
3246 if (image->storage_class != DirectClass)
3247 status=SetImageStorageClass(image,DirectClass,exception);
3248 if (image->matte == MagickFalse)
3249 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3252 case ColorSeparationType:
3254 if (image->colorspace != CMYKColorspace)
3256 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3257 status=TransformImageColorspace(image,sRGBColorspace,exception);
3258 status=TransformImageColorspace(image,CMYKColorspace,exception);
3260 if (image->storage_class != DirectClass)
3261 status=SetImageStorageClass(image,DirectClass,exception);
3262 image->matte=MagickFalse;
3265 case ColorSeparationMatteType:
3267 if (image->colorspace != CMYKColorspace)
3269 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3270 status=TransformImageColorspace(image,sRGBColorspace,exception);
3271 status=TransformImageColorspace(image,CMYKColorspace,exception);
3273 if (image->storage_class != DirectClass)
3274 status=SetImageStorageClass(image,DirectClass,exception);
3275 if (image->matte == MagickFalse)
3276 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3284 image_info=DestroyImageInfo(image_info);
3289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3293 % 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 %
3297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3299 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3300 % image and returns the previous setting. A virtual pixel is any pixel access
3301 % that is outside the boundaries of the image cache.
3303 % The format of the SetImageVirtualPixelMethod() method is:
3305 % VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3306 % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3308 % A description of each parameter follows:
3310 % o image: the image.
3312 % o virtual_pixel_method: choose the type of virtual pixel.
3314 % o exception: return any errors or warnings in this structure.
3317 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3318 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3320 assert(image != (const Image *) NULL);
3321 assert(image->signature == MagickSignature);
3322 if (image->debug != MagickFalse)
3323 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3324 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3332 % S m u s h I m a g e s %
3336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3338 % SmushImages() takes all images from the current image pointer to the end
3339 % of the image list and smushes them to each other top-to-bottom if the
3340 % stack parameter is true, otherwise left-to-right.
3342 % The current gravity setting now effects how the image is justified in the
3345 % The format of the SmushImages method is:
3347 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3348 % ExceptionInfo *exception)
3350 % A description of each parameter follows:
3352 % o images: the image sequence.
3354 % o stack: A value other than 0 stacks the images top-to-bottom.
3356 % o offset: minimum distance in pixels between images.
3358 % o exception: return any errors or warnings in this structure.
3362 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3363 const ssize_t offset,ExceptionInfo *exception)
3377 register const Quantum
3390 if (images->previous == (Image *) NULL)
3393 SetGeometry(smush_image,&right_geometry);
3394 GravityAdjustGeometry(right_image->columns,right_image->rows,
3395 right_image->gravity,&right_geometry);
3396 left_image=images->previous;
3397 SetGeometry(smush_image,&left_geometry);
3398 GravityAdjustGeometry(left_image->columns,left_image->rows,
3399 left_image->gravity,&left_geometry);
3400 gap=right_image->columns;
3401 left_view=AcquireCacheView(left_image);
3402 right_view=AcquireCacheView(right_image);
3403 for (y=0; y < (ssize_t) smush_image->rows; y++)
3405 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3407 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3408 if ((p == (const Quantum *) NULL) ||
3409 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3410 ((left_image->columns-x-1) >= gap))
3413 i=(ssize_t) left_image->columns-x-1;
3414 for (x=0; x < (ssize_t) right_image->columns; x++)
3416 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3418 if ((p == (const Quantum *) NULL) ||
3419 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3420 ((x+i) >= (ssize_t) gap))
3423 if ((x+i) < (ssize_t) gap)
3426 right_view=DestroyCacheView(right_view);
3427 left_view=DestroyCacheView(left_view);
3428 if (y < (ssize_t) smush_image->rows)
3430 return((ssize_t) gap-offset);
3433 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3434 const ssize_t offset,ExceptionInfo *exception)
3448 register const Quantum
3461 if (images->previous == (Image *) NULL)
3463 bottom_image=images;
3464 SetGeometry(smush_image,&bottom_geometry);
3465 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3466 bottom_image->gravity,&bottom_geometry);
3467 top_image=images->previous;
3468 SetGeometry(smush_image,&top_geometry);
3469 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3471 gap=bottom_image->rows;
3472 top_view=AcquireCacheView(top_image);
3473 bottom_view=AcquireCacheView(bottom_image);
3474 for (x=0; x < (ssize_t) smush_image->columns; x++)
3476 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3478 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3479 if ((p == (const Quantum *) NULL) ||
3480 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3481 ((top_image->rows-y-1) >= gap))
3484 i=(ssize_t) top_image->rows-y-1;
3485 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3487 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3489 if ((p == (const Quantum *) NULL) ||
3490 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3491 ((y+i) >= (ssize_t) gap))
3494 if ((y+i) < (ssize_t) gap)
3497 bottom_view=DestroyCacheView(bottom_view);
3498 top_view=DestroyCacheView(top_view);
3499 if (x < (ssize_t) smush_image->columns)
3501 return((ssize_t) gap-offset);
3504 MagickExport Image *SmushImages(const Image *images,
3505 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3507 #define SmushImageTag "Smush/Image"
3529 register const Image
3542 Compute maximum area of smushed area.
3544 assert(images != (Image *) NULL);
3545 assert(images->signature == MagickSignature);
3546 if (images->debug != MagickFalse)
3547 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3548 assert(exception != (ExceptionInfo *) NULL);
3549 assert(exception->signature == MagickSignature);
3553 width=image->columns;
3555 next=GetNextImageInList(image);
3556 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3558 if (next->matte != MagickFalse)
3561 if (stack != MagickFalse)
3563 if (next->columns > width)
3564 width=next->columns;
3566 if (next->previous != (Image *) NULL)
3570 width+=next->columns;
3571 if (next->previous != (Image *) NULL)
3573 if (next->rows > height)
3579 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3580 if (smush_image == (Image *) NULL)
3581 return((Image *) NULL);
3582 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3584 smush_image=DestroyImage(smush_image);
3585 return((Image *) NULL);
3587 smush_image->matte=matte;
3588 (void) SetImageBackgroundColor(smush_image,exception);
3592 smush_view=AcquireCacheView(smush_image);
3593 for (n=0; n < (MagickOffsetType) number_images; n++)
3595 SetGeometry(smush_image,&geometry);
3596 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3597 if (stack != MagickFalse)
3599 x_offset-=geometry.x;
3600 y_offset-=SmushYGap(smush_image,image,offset,exception);
3604 x_offset-=SmushXGap(smush_image,image,offset,exception);
3605 y_offset-=geometry.y;
3607 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3608 y_offset,exception);
3609 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3610 if (proceed == MagickFalse)
3612 if (stack == MagickFalse)
3614 x_offset+=(ssize_t) image->columns;
3620 y_offset+=(ssize_t) image->rows;
3622 image=GetNextImageInList(image);
3624 if (stack == MagickFalse)
3625 smush_image->columns=(size_t) x_offset;
3627 smush_image->rows=(size_t) y_offset;
3628 smush_view=DestroyCacheView(smush_view);
3629 if (status == MagickFalse)
3630 smush_image=DestroyImage(smush_image);
3631 return(smush_image);
3635 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3639 % S t r i p I m a g e %
3643 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3645 % StripImage() strips an image of all profiles and comments.
3647 % The format of the StripImage method is:
3649 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3651 % A description of each parameter follows:
3653 % o image: the image.
3655 % o exception: return any errors or warnings in this structure.
3658 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3663 assert(image != (Image *) NULL);
3664 if (image->debug != MagickFalse)
3665 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3667 DestroyImageProfiles(image);
3668 (void) DeleteImageProperty(image,"comment");
3669 (void) DeleteImageProperty(image,"date:create");
3670 (void) DeleteImageProperty(image,"date:modify");
3671 status=SetImageArtifact(image,"png:include-chunk","none,trns,gama");
3676 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3680 + S y n c I m a g e %
3684 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3686 % SyncImage() initializes the red, green, and blue intensities of each pixel
3687 % as defined by the colormap index.
3689 % The format of the SyncImage method is:
3691 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3693 % A description of each parameter follows:
3695 % o image: the image.
3697 % o exception: return any errors or warnings in this structure.
3701 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3702 MagickBooleanType *range_exception)
3704 if ((size_t) index < image->colors)
3706 *range_exception=MagickTrue;
3710 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3722 assert(image != (Image *) NULL);
3723 if (image->debug != MagickFalse)
3724 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3725 assert(image->signature == MagickSignature);
3726 if (image->storage_class == DirectClass)
3727 return(MagickFalse);
3728 range_exception=MagickFalse;
3730 image_view=AcquireCacheView(image);
3731 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3732 #pragma omp parallel for schedule(static,4) shared(range_exception,status)
3734 for (y=0; y < (ssize_t) image->rows; y++)
3745 if (status == MagickFalse)
3747 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3748 if (q == (Quantum *) NULL)
3753 for (x=0; x < (ssize_t) image->columns; x++)
3755 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3756 SetPixelInfoPixel(image,image->colormap+(ssize_t) index,q);
3757 q+=GetPixelChannels(image);
3759 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3762 image_view=DestroyCacheView(image_view);
3763 if (range_exception != MagickFalse)
3764 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
3765 "InvalidColormapIndex","`%s'",image->filename);
3770 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3774 % S y n c I m a g e S e t t i n g s %
3778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3780 % SyncImageSettings() syncs the image_info options into per-image attributes.
3782 % The format of the SyncImageSettings method is:
3784 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3785 % Image *image,ExceptionInfo *exception)
3786 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3787 % Image *image,ExceptionInfo *exception)
3789 % A description of each parameter follows:
3791 % o image_info: the image info.
3793 % o image: the image.
3795 % o exception: return any errors or warnings in this structure.
3799 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3800 Image *images,ExceptionInfo *exception)
3805 assert(image_info != (const ImageInfo *) NULL);
3806 assert(image_info->signature == MagickSignature);
3807 assert(images != (Image *) NULL);
3808 assert(images->signature == MagickSignature);
3809 if (images->debug != MagickFalse)
3810 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3812 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3813 (void) SyncImageSettings(image_info,image,exception);
3814 (void) DeleteImageOption(image_info,"page");
3818 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3819 Image *image,ExceptionInfo *exception)
3822 property[MaxTextExtent];
3840 assert(image_info != (const ImageInfo *) NULL);
3841 assert(image_info->signature == MagickSignature);
3842 assert(image != (Image *) NULL);
3843 assert(image->signature == MagickSignature);
3844 if (image->debug != MagickFalse)
3845 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3846 option=GetImageOption(image_info,"background");
3847 if (option != (const char *) NULL)
3848 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
3850 option=GetImageOption(image_info,"black-point-compensation");
3851 if (option != (const char *) NULL)
3852 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3853 MagickBooleanOptions,MagickFalse,option);
3854 option=GetImageOption(image_info,"blue-primary");
3855 if (option != (const char *) NULL)
3857 flags=ParseGeometry(option,&geometry_info);
3858 image->chromaticity.blue_primary.x=geometry_info.rho;
3859 image->chromaticity.blue_primary.y=geometry_info.sigma;
3860 if ((flags & SigmaValue) == 0)
3861 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3863 option=GetImageOption(image_info,"bordercolor");
3864 if (option != (const char *) NULL)
3865 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
3867 option=GetImageOption(image_info,"channel");
3868 if (option != (const char *) NULL)
3869 (void) SetPixelChannelMapMask(image,(ChannelType)
3870 ParseChannelOption(option));
3871 /* FUTURE: do not sync compose to per-image compose setting here */
3872 option=GetImageOption(image_info,"compose");
3873 if (option != (const char *) NULL)
3874 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3875 MagickFalse,option);
3877 option=GetImageOption(image_info,"compress");
3878 if (option != (const char *) NULL)
3879 image->compression=(CompressionType) ParseCommandOption(
3880 MagickCompressOptions,MagickFalse,option);
3881 option=GetImageOption(image_info,"debug");
3882 if (option != (const char *) NULL)
3883 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3884 MagickFalse,option);
3885 option=GetImageOption(image_info,"density");
3886 if (option != (const char *) NULL)
3891 flags=ParseGeometry(option,&geometry_info);
3892 image->resolution.x=geometry_info.rho;
3893 image->resolution.y=geometry_info.sigma;
3894 if ((flags & SigmaValue) == 0)
3895 image->resolution.y=image->resolution.x;
3897 option=GetImageOption(image_info,"depth");
3898 if (option != (const char *) NULL)
3899 image->depth=StringToUnsignedLong(option);
3900 option=GetImageOption(image_info,"endian");
3901 if (option != (const char *) NULL)
3902 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3903 MagickFalse,option);
3904 option=GetImageOption(image_info,"filter");
3905 if (option != (const char *) NULL)
3906 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
3907 MagickFalse,option);
3908 option=GetImageOption(image_info,"fuzz");
3909 if (option != (const char *) NULL)
3910 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3911 option=GetImageOption(image_info,"gravity");
3912 if (option != (const char *) NULL)
3913 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3914 MagickFalse,option);
3915 option=GetImageOption(image_info,"green-primary");
3916 if (option != (const char *) NULL)
3918 flags=ParseGeometry(option,&geometry_info);
3919 image->chromaticity.green_primary.x=geometry_info.rho;
3920 image->chromaticity.green_primary.y=geometry_info.sigma;
3921 if ((flags & SigmaValue) == 0)
3922 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3924 option=GetImageOption(image_info,"intent");
3925 if (option != (const char *) NULL)
3926 image->rendering_intent=(RenderingIntent) ParseCommandOption(
3927 MagickIntentOptions,MagickFalse,option);
3928 option=GetImageOption(image_info,"interlace");
3929 if (option != (const char *) NULL)
3930 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3931 MagickFalse,option);
3932 option=GetImageOption(image_info,"interpolate");
3933 if (option != (const char *) NULL)
3934 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
3935 MagickInterpolateOptions,MagickFalse,option);
3936 option=GetImageOption(image_info,"loop");
3937 if (option != (const char *) NULL)
3938 image->iterations=StringToUnsignedLong(option);
3939 option=GetImageOption(image_info,"mattecolor");
3940 if (option != (const char *) NULL)
3941 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
3943 option=GetImageOption(image_info,"orient");
3944 if (option != (const char *) NULL)
3945 image->orientation=(OrientationType) ParseCommandOption(
3946 MagickOrientationOptions,MagickFalse,option);
3947 option=GetImageOption(image_info,"page");
3948 if (option != (const char *) NULL)
3953 geometry=GetPageGeometry(option);
3954 flags=ParseAbsoluteGeometry(geometry,&image->page);
3955 geometry=DestroyString(geometry);
3957 option=GetImageOption(image_info,"quality");
3958 if (option != (const char *) NULL)
3959 image->quality=StringToUnsignedLong(option);
3960 option=GetImageOption(image_info,"red-primary");
3961 if (option != (const char *) NULL)
3963 flags=ParseGeometry(option,&geometry_info);
3964 image->chromaticity.red_primary.x=geometry_info.rho;
3965 image->chromaticity.red_primary.y=geometry_info.sigma;
3966 if ((flags & SigmaValue) == 0)
3967 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3969 if (image_info->quality != UndefinedCompressionQuality)
3970 image->quality=image_info->quality;
3971 option=GetImageOption(image_info,"scene");
3972 if (option != (const char *) NULL)
3973 image->scene=StringToUnsignedLong(option);
3974 option=GetImageOption(image_info,"taint");
3975 if (option != (const char *) NULL)
3976 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3977 MagickFalse,option);
3978 option=GetImageOption(image_info,"tile-offset");
3979 if (option != (const char *) NULL)
3984 geometry=GetPageGeometry(option);
3985 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3986 geometry=DestroyString(geometry);
3988 option=GetImageOption(image_info,"transparent-color");
3989 if (option != (const char *) NULL)
3990 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
3992 option=GetImageOption(image_info,"type");
3993 if (option != (const char *) NULL)
3994 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3996 option=GetImageOption(image_info,"units");
3997 units=image_info->units;
3998 if (option != (const char *) NULL)
3999 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4000 MagickFalse,option);
4001 if (units != UndefinedResolution)
4003 if (image->units != units)
4004 switch (image->units)
4006 case PixelsPerInchResolution:
4008 if (units == PixelsPerCentimeterResolution)
4010 image->resolution.x/=2.54;
4011 image->resolution.y/=2.54;
4015 case PixelsPerCentimeterResolution:
4017 if (units == PixelsPerInchResolution)
4019 image->resolution.x=(double) ((size_t) (100.0*2.54*
4020 image->resolution.x+0.5))/100.0;
4021 image->resolution.y=(double) ((size_t) (100.0*2.54*
4022 image->resolution.y+0.5))/100.0;
4031 option=GetImageOption(image_info,"virtual-pixel");
4032 if (option != (const char *) NULL)
4033 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4034 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4036 option=GetImageOption(image_info,"white-point");
4037 if (option != (const char *) NULL)
4039 flags=ParseGeometry(option,&geometry_info);
4040 image->chromaticity.white_point.x=geometry_info.rho;
4041 image->chromaticity.white_point.y=geometry_info.sigma;
4042 if ((flags & SigmaValue) == 0)
4043 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4045 ResetImageOptionIterator(image_info);
4046 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4048 value=GetImageOption(image_info,option);
4049 if (value != (const char *) NULL)
4051 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4052 (void) SetImageArtifact(image,property,value);
4054 option=GetNextImageOption(image_info);