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-2013 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/animate.h"
45 #include "MagickCore/artifact.h"
46 #include "MagickCore/attribute.h"
47 #include "MagickCore/blob.h"
48 #include "MagickCore/blob-private.h"
49 #include "MagickCore/cache.h"
50 #include "MagickCore/cache-private.h"
51 #include "MagickCore/cache-view.h"
52 #include "MagickCore/client.h"
53 #include "MagickCore/color.h"
54 #include "MagickCore/color-private.h"
55 #include "MagickCore/colormap.h"
56 #include "MagickCore/colorspace.h"
57 #include "MagickCore/colorspace-private.h"
58 #include "MagickCore/composite.h"
59 #include "MagickCore/composite-private.h"
60 #include "MagickCore/compress.h"
61 #include "MagickCore/constitute.h"
62 #include "MagickCore/display.h"
63 #include "MagickCore/draw.h"
64 #include "MagickCore/enhance.h"
65 #include "MagickCore/exception.h"
66 #include "MagickCore/exception-private.h"
67 #include "MagickCore/gem.h"
68 #include "MagickCore/geometry.h"
69 #include "MagickCore/histogram.h"
70 #include "MagickCore/image-private.h"
71 #include "MagickCore/list.h"
72 #include "MagickCore/magic.h"
73 #include "MagickCore/magick.h"
74 #include "MagickCore/magick-private.h"
75 #include "MagickCore/memory_.h"
76 #include "MagickCore/module.h"
77 #include "MagickCore/monitor.h"
78 #include "MagickCore/monitor-private.h"
79 #include "MagickCore/option.h"
80 #include "MagickCore/paint.h"
81 #include "MagickCore/pixel-accessor.h"
82 #include "MagickCore/profile.h"
83 #include "MagickCore/property.h"
84 #include "MagickCore/quantize.h"
85 #include "MagickCore/random_.h"
86 #include "MagickCore/resource_.h"
87 #include "MagickCore/segment.h"
88 #include "MagickCore/semaphore.h"
89 #include "MagickCore/signature-private.h"
90 #include "MagickCore/statistic.h"
91 #include "MagickCore/string_.h"
92 #include "MagickCore/string-private.h"
93 #include "MagickCore/thread-private.h"
94 #include "MagickCore/threshold.h"
95 #include "MagickCore/timer.h"
96 #include "MagickCore/token.h"
97 #include "MagickCore/utility.h"
98 #include "MagickCore/utility-private.h"
99 #include "MagickCore/version.h"
100 #include "MagickCore/xwindow-private.h"
103 Constant declaration.
106 BackgroundColor[] = "#ffffff", /* white */
107 BorderColor[] = "#dfdfdf", /* gray */
108 DefaultTileFrame[] = "15x15+3+3",
109 DefaultTileGeometry[] = "120x120+4+3>",
110 DefaultTileLabel[] = "%f\n%G\n%b",
111 ForegroundColor[] = "#000", /* black */
112 LoadImageTag[] = "Load/Image",
113 LoadImagesTag[] = "Load/Images",
114 MatteColor[] = "#bdbdbd", /* gray */
115 PSDensityGeometry[] = "72.0x72.0",
116 PSPageGeometry[] = "612x792",
117 SaveImageTag[] = "Save/Image",
118 SaveImagesTag[] = "Save/Images",
119 TransparentColor[] = "#00000000"; /* transparent black */
122 DefaultResolution = 72.0;
125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 % A c q u i r e I m a g e %
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 % AcquireImage() returns a pointer to an image structure initialized to
138 % The format of the AcquireImage method is:
140 % Image *AcquireImage(const ImageInfo *image_info,ExceptionInfo *exception)
142 % A description of each parameter follows:
144 % o image_info: Many of the image default values are set from this
145 % structure. For example, filename, compression, depth, background color,
148 % o exception: return any errors or warnings in this structure.
151 MagickExport Image *AcquireImage(const ImageInfo *image_info,
152 ExceptionInfo *exception)
164 Allocate image structure.
166 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
167 image=(Image *) AcquireMagickMemory(sizeof(*image));
168 if (image == (Image *) NULL)
169 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
170 (void) ResetMagickMemory(image,0,sizeof(*image));
172 Initialize Image structure.
174 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
175 image->storage_class=DirectClass;
176 image->depth=MAGICKCORE_QUANTUM_DEPTH;
177 image->colorspace=sRGBColorspace;
178 image->rendering_intent=PerceptualIntent;
179 image->gamma=1.000f/2.200f;
180 image->chromaticity.red_primary.x=0.6400f;
181 image->chromaticity.red_primary.y=0.3300f;
182 image->chromaticity.red_primary.z=0.0300f;
183 image->chromaticity.green_primary.x=0.3000f;
184 image->chromaticity.green_primary.y=0.6000f;
185 image->chromaticity.green_primary.z=0.1000f;
186 image->chromaticity.blue_primary.x=0.1500f;
187 image->chromaticity.blue_primary.y=0.0600f;
188 image->chromaticity.blue_primary.z=0.7900f;
189 image->chromaticity.white_point.x=0.3127f;
190 image->chromaticity.white_point.y=0.3290f;
191 image->chromaticity.white_point.z=0.3583f;
192 image->interlace=NoInterlace;
193 image->ticks_per_second=UndefinedTicksPerSecond;
194 image->compose=OverCompositeOp;
195 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
196 &image->background_color,exception);
197 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
199 (void) QueryColorCompliance(MatteColor,AllCompliance,&image->matte_color,
201 (void) QueryColorCompliance(TransparentColor,AllCompliance,
202 &image->transparent_color,exception);
203 GetTimerInfo(&image->timer);
204 image->cache=AcquirePixelCache(0);
205 image->channel_mask=DefaultChannels;
206 image->channel_map=AcquirePixelChannelMap();
207 image->blob=CloneBlobInfo((BlobInfo *) NULL);
208 image->timestamp=time((time_t *) NULL);
209 image->debug=IsEventLogging();
210 image->reference_count=1;
211 image->semaphore=AllocateSemaphoreInfo();
212 image->signature=MagickSignature;
213 if (image_info == (ImageInfo *) NULL)
218 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
220 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
221 (void) CopyMagickString(image->magick_filename,image_info->filename,
223 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
224 if (image_info->size != (char *) NULL)
226 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
227 image->columns=image->extract_info.width;
228 image->rows=image->extract_info.height;
229 image->offset=image->extract_info.x;
230 image->extract_info.x=0;
231 image->extract_info.y=0;
233 if (image_info->extract != (char *) NULL)
238 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
239 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
241 image->extract_info=geometry;
242 Swap(image->columns,image->extract_info.width);
243 Swap(image->rows,image->extract_info.height);
246 image->compression=image_info->compression;
247 image->quality=image_info->quality;
248 image->endian=image_info->endian;
249 image->interlace=image_info->interlace;
250 image->units=image_info->units;
251 if (image_info->density != (char *) NULL)
256 flags=ParseGeometry(image_info->density,&geometry_info);
257 image->resolution.x=geometry_info.rho;
258 image->resolution.y=geometry_info.sigma;
259 if ((flags & SigmaValue) == 0)
260 image->resolution.y=image->resolution.x;
262 if (image_info->page != (char *) NULL)
267 image->page=image->extract_info;
268 geometry=GetPageGeometry(image_info->page);
269 (void) ParseAbsoluteGeometry(geometry,&image->page);
270 geometry=DestroyString(geometry);
272 if (image_info->depth != 0)
273 image->depth=image_info->depth;
274 image->dither=image_info->dither;
275 image->background_color=image_info->background_color;
276 image->border_color=image_info->border_color;
277 image->matte_color=image_info->matte_color;
278 image->transparent_color=image_info->transparent_color;
279 image->ping=image_info->ping;
280 image->progress_monitor=image_info->progress_monitor;
281 image->client_data=image_info->client_data;
282 if (image_info->cache != (void *) NULL)
283 ClonePixelCacheMethods(image->cache,image_info->cache);
285 Set all global options that map to per-image settings.
287 (void) SyncImageSettings(image_info,image,exception);
289 Global options that are only set for new images.
291 image->image_info=(ImageInfo *) NULL;
292 option=GetImageOption(image_info,"delay");
293 if (option != (const char *) NULL)
298 flags=ParseGeometry(option,&geometry_info);
299 if ((flags & GreaterValue) != 0)
301 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
302 image->delay=(size_t) floor(geometry_info.rho+0.5);
305 if ((flags & LessValue) != 0)
307 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
308 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
311 image->delay=(size_t) floor(geometry_info.rho+0.5);
312 if ((flags & SigmaValue) != 0)
313 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
315 option=GetImageOption(image_info,"dispose");
316 if (option != (const char *) NULL)
317 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
327 % A c q u i r e I m a g e I n f o %
331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
333 % AcquireImageInfo() allocates the ImageInfo structure.
335 % The format of the AcquireImageInfo method is:
337 % ImageInfo *AcquireImageInfo(void)
340 MagickExport ImageInfo *AcquireImageInfo(void)
345 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
346 if (image_info == (ImageInfo *) NULL)
347 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
348 GetImageInfo(image_info);
353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
357 % A c q u i r e N e x t I m a g e %
361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363 % AcquireNextImage() initializes the next image in a sequence to
364 % default values. The next member of image points to the newly allocated
365 % image. If there is a memory shortage, next is assigned NULL.
367 % The format of the AcquireNextImage method is:
369 % void AcquireNextImage(const ImageInfo *image_info,Image *image,
370 % ExceptionInfo *exception)
372 % A description of each parameter follows:
374 % o image_info: Many of the image default values are set from this
375 % structure. For example, filename, compression, depth, background color,
378 % o image: the image.
380 % o exception: return any errors or warnings in this structure.
383 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image,
384 ExceptionInfo *exception)
387 Allocate image structure.
389 assert(image != (Image *) NULL);
390 assert(image->signature == MagickSignature);
391 if (image->debug != MagickFalse)
392 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
393 image->next=AcquireImage(image_info,exception);
394 if (GetNextImageInList(image) == (Image *) NULL)
396 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
398 if (image_info != (ImageInfo *) NULL)
399 (void) CopyMagickString(GetNextImageInList(image)->filename,
400 image_info->filename,MaxTextExtent);
401 DestroyBlob(GetNextImageInList(image));
402 image->next->blob=ReferenceBlob(image->blob);
403 image->next->endian=image->endian;
404 image->next->scene=image->scene+1;
405 image->next->previous=image;
409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
413 % A p p e n d I m a g e s %
417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
419 % AppendImages() takes all images from the current image pointer to the end
420 % of the image list and appends them to each other top-to-bottom if the
421 % stack parameter is true, otherwise left-to-right.
423 % The current gravity setting effects how the image is justified in the
426 % The format of the AppendImages method is:
428 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
429 % ExceptionInfo *exception)
431 % A description of each parameter follows:
433 % o images: the image sequence.
435 % o stack: A value other than 0 stacks the images top-to-bottom.
437 % o exception: return any errors or warnings in this structure.
440 MagickExport Image *AppendImages(const Image *images,
441 const MagickBooleanType stack,ExceptionInfo *exception)
443 #define AppendImageTag "Append/Image"
477 Compute maximum area of appended area.
479 assert(images != (Image *) NULL);
480 assert(images->signature == MagickSignature);
481 if (images->debug != MagickFalse)
482 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
483 assert(exception != (ExceptionInfo *) NULL);
484 assert(exception->signature == MagickSignature);
485 alpha_trait=images->alpha_trait;
487 width=images->columns;
489 next=GetNextImageInList(images);
490 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
492 if (next->alpha_trait == BlendPixelTrait)
493 alpha_trait=BlendPixelTrait;
495 if (stack != MagickFalse)
497 if (next->columns > width)
502 width+=next->columns;
503 if (next->rows > height)
509 append_image=CloneImage(images,width,height,MagickTrue,exception);
510 if (append_image == (Image *) NULL)
511 return((Image *) NULL);
512 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
514 append_image=DestroyImage(append_image);
515 return((Image *) NULL);
517 append_image->alpha_trait=alpha_trait;
518 (void) SetImageBackgroundColor(append_image,exception);
523 append_view=AcquireAuthenticCacheView(append_image,exception);
524 for (n=0; n < (MagickOffsetType) number_images; n++)
535 image=CloneImage(next,0,0,MagickTrue,exception);
536 if (image == (Image *) NULL)
538 (void) TransformImageColorspace(image,append_image->colorspace,exception);
539 SetGeometry(append_image,&geometry);
540 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
541 if (stack != MagickFalse)
542 x_offset-=geometry.x;
544 y_offset-=geometry.y;
545 image_view=AcquireVirtualCacheView(image,exception);
546 #if defined(MAGICKCORE_OPENMP_SUPPORT)
547 #pragma omp parallel for schedule(static,4) shared(status) \
548 magick_threads(image,image,image->rows,1)
550 for (y=0; y < (ssize_t) image->rows; y++)
558 register const Quantum
567 if (status == MagickFalse)
569 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
570 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
571 image->columns,1,exception);
572 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
577 GetPixelInfo(image,&pixel);
578 for (x=0; x < (ssize_t) image->columns; x++)
580 if (GetPixelMask(image,p) == 0)
582 p+=GetPixelChannels(image);
583 q+=GetPixelChannels(append_image);
586 GetPixelInfoPixel(image,p,&pixel);
587 SetPixelInfoPixel(append_image,&pixel,q);
588 p+=GetPixelChannels(image);
589 q+=GetPixelChannels(append_image);
591 sync=SyncCacheViewAuthenticPixels(append_view,exception);
592 if (sync == MagickFalse)
595 image_view=DestroyCacheView(image_view);
596 if (stack == MagickFalse)
598 x_offset+=(ssize_t) image->columns;
604 y_offset+=(ssize_t) image->rows;
606 image=DestroyImage(image);
607 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
608 if (proceed == MagickFalse)
610 next=GetNextImageInList(next);
612 append_view=DestroyCacheView(append_view);
613 if (status == MagickFalse)
614 append_image=DestroyImage(append_image);
615 return(append_image);
619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
623 % C a t c h I m a g e E x c e p t i o n %
627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
629 % CatchImageException() returns if no exceptions are found in the image
630 % sequence, otherwise it determines the most severe exception and reports
631 % it as a warning or error depending on the severity.
633 % The format of the CatchImageException method is:
635 % ExceptionType CatchImageException(Image *image)
637 % A description of each parameter follows:
639 % o image: An image sequence.
642 MagickExport ExceptionType CatchImageException(Image *image)
650 assert(image != (const Image *) NULL);
651 assert(image->signature == MagickSignature);
652 if (image->debug != MagickFalse)
653 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
654 exception=AcquireExceptionInfo();
655 CatchException(exception);
656 severity=exception->severity;
657 exception=DestroyExceptionInfo(exception);
662 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
666 % C l i p I m a g e P a t h %
670 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
672 % ClipImagePath() sets the image clip mask based any clipping path information
675 % The format of the ClipImagePath method is:
677 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
678 % const MagickBooleanType inside,ExceptionInfo *exception)
680 % A description of each parameter follows:
682 % o image: the image.
684 % o pathname: name of clipping path resource. If name is preceded by #, use
685 % clipping path numbered by name.
687 % o inside: if non-zero, later operations take effect inside clipping path.
688 % Otherwise later operations take effect outside clipping path.
690 % o exception: return any errors or warnings in this structure.
694 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
696 return(ClipImagePath(image,"#1",MagickTrue,exception));
699 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
700 const MagickBooleanType inside,ExceptionInfo *exception)
702 #define ClipImagePathTag "ClipPath/Image"
716 assert(image != (const Image *) NULL);
717 assert(image->signature == MagickSignature);
718 if (image->debug != MagickFalse)
719 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
720 assert(pathname != NULL);
721 property=AcquireString(pathname);
722 (void) FormatLocaleString(property,MaxTextExtent,"8BIM:1999,2998:%s",
724 value=GetImageProperty(image,property,exception);
725 property=DestroyString(property);
726 if (value == (const char *) NULL)
728 ThrowFileException(exception,OptionError,"NoClipPathDefined",
732 image_info=AcquireImageInfo();
733 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
734 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
735 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
736 image_info=DestroyImageInfo(image_info);
737 if (clip_mask == (Image *) NULL)
739 if (clip_mask->storage_class == PseudoClass)
741 (void) SyncImage(clip_mask,exception);
742 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
745 if (inside == MagickFalse)
746 (void) NegateImage(clip_mask,MagickFalse,exception);
747 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
748 "8BIM:1999,2998:%s\nPS",pathname);
749 (void) SetImageMask(image,clip_mask,exception);
750 clip_mask=DestroyImage(clip_mask);
755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
759 % C l o n e I m a g e %
763 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
765 % CloneImage() copies an image and returns the copy as a new image object.
767 % If the specified columns and rows is 0, an exact copy of the image is
768 % returned, otherwise the pixel data is undefined and must be initialized
769 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
770 % failure, a NULL image is returned and exception describes the reason for the
773 % The format of the CloneImage method is:
775 % Image *CloneImage(const Image *image,const size_t columns,
776 % const size_t rows,const MagickBooleanType orphan,
777 % ExceptionInfo *exception)
779 % A description of each parameter follows:
781 % o image: the image.
783 % o columns: the number of columns in the cloned image.
785 % o rows: the number of rows in the cloned image.
787 % o detach: With a value other than 0, the cloned image is detached from
788 % its parent I/O stream.
790 % o exception: return any errors or warnings in this structure.
793 MagickExport Image *CloneImage(const Image *image,const size_t columns,
794 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
808 assert(image != (const Image *) NULL);
809 assert(image->signature == MagickSignature);
810 if (image->debug != MagickFalse)
811 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
812 assert(exception != (ExceptionInfo *) NULL);
813 assert(exception->signature == MagickSignature);
814 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
815 if (clone_image == (Image *) NULL)
816 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
817 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
818 clone_image->signature=MagickSignature;
819 clone_image->storage_class=image->storage_class;
820 clone_image->number_channels=image->number_channels;
821 clone_image->number_meta_channels=image->number_meta_channels;
822 clone_image->metacontent_extent=image->metacontent_extent;
823 clone_image->colorspace=image->colorspace;
824 clone_image->mask=image->mask;
825 clone_image->alpha_trait=image->alpha_trait;
826 clone_image->columns=image->columns;
827 clone_image->rows=image->rows;
828 clone_image->dither=image->dither;
829 if (image->colormap != (PixelInfo *) NULL)
832 Allocate and copy the image colormap.
834 clone_image->colors=image->colors;
835 length=(size_t) image->colors;
836 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
837 sizeof(*clone_image->colormap));
838 if (clone_image->colormap == (PixelInfo *) NULL)
839 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
840 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
841 sizeof(*clone_image->colormap));
843 (void) CloneImageProfiles(clone_image,image);
844 (void) CloneImageProperties(clone_image,image);
845 (void) CloneImageArtifacts(clone_image,image);
846 GetTimerInfo(&clone_image->timer);
847 if (image->ascii85 != (void *) NULL)
848 Ascii85Initialize(clone_image);
849 clone_image->magick_columns=image->magick_columns;
850 clone_image->magick_rows=image->magick_rows;
851 clone_image->type=image->type;
852 clone_image->channel_mask=image->channel_mask;
853 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
854 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
856 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
857 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
858 clone_image->progress_monitor=image->progress_monitor;
859 clone_image->client_data=image->client_data;
860 clone_image->reference_count=1;
861 clone_image->next=image->next;
862 clone_image->previous=image->previous;
863 clone_image->list=NewImageList();
864 if (detach == MagickFalse)
865 clone_image->blob=ReferenceBlob(image->blob);
868 clone_image->next=NewImageList();
869 clone_image->previous=NewImageList();
870 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
872 clone_image->ping=image->ping;
873 clone_image->debug=IsEventLogging();
874 clone_image->semaphore=AllocateSemaphoreInfo();
875 if ((columns == 0) && (rows == 0))
877 if (image->montage != (char *) NULL)
878 (void) CloneString(&clone_image->montage,image->montage);
879 if (image->directory != (char *) NULL)
880 (void) CloneString(&clone_image->directory,image->directory);
881 clone_image->cache=ReferencePixelCache(image->cache);
884 scale=(double) columns/(double) image->columns;
885 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
886 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
887 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
888 scale=(double) rows/(double) image->rows;
889 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
890 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
891 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
892 clone_image->columns=columns;
893 clone_image->rows=rows;
894 clone_image->cache=ClonePixelCache(image->cache);
899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
903 % C l o n e I m a g e I n f o %
907 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
909 % CloneImageInfo() makes a copy of the given image info structure. If
910 % NULL is specified, a new image info structure is created initialized to
913 % The format of the CloneImageInfo method is:
915 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
917 % A description of each parameter follows:
919 % o image_info: the image info.
922 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
927 clone_info=AcquireImageInfo();
928 if (image_info == (ImageInfo *) NULL)
930 clone_info->compression=image_info->compression;
931 clone_info->temporary=image_info->temporary;
932 clone_info->adjoin=image_info->adjoin;
933 clone_info->antialias=image_info->antialias;
934 clone_info->scene=image_info->scene;
935 clone_info->number_scenes=image_info->number_scenes;
936 clone_info->depth=image_info->depth;
937 (void) CloneString(&clone_info->size,image_info->size);
938 (void) CloneString(&clone_info->extract,image_info->extract);
939 (void) CloneString(&clone_info->scenes,image_info->scenes);
940 (void) CloneString(&clone_info->page,image_info->page);
941 clone_info->interlace=image_info->interlace;
942 clone_info->endian=image_info->endian;
943 clone_info->units=image_info->units;
944 clone_info->quality=image_info->quality;
945 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
946 (void) CloneString(&clone_info->server_name,image_info->server_name);
947 (void) CloneString(&clone_info->font,image_info->font);
948 (void) CloneString(&clone_info->texture,image_info->texture);
949 (void) CloneString(&clone_info->density,image_info->density);
950 clone_info->pointsize=image_info->pointsize;
951 clone_info->fuzz=image_info->fuzz;
952 clone_info->background_color=image_info->background_color;
953 clone_info->border_color=image_info->border_color;
954 clone_info->matte_color=image_info->matte_color;
955 clone_info->transparent_color=image_info->transparent_color;
956 clone_info->dither=image_info->dither;
957 clone_info->monochrome=image_info->monochrome;
958 clone_info->colorspace=image_info->colorspace;
959 clone_info->type=image_info->type;
960 clone_info->orientation=image_info->orientation;
961 clone_info->preview_type=image_info->preview_type;
962 clone_info->group=image_info->group;
963 clone_info->ping=image_info->ping;
964 clone_info->verbose=image_info->verbose;
965 (void) CloneString(&clone_info->view,image_info->view);
966 clone_info->progress_monitor=image_info->progress_monitor;
967 clone_info->client_data=image_info->client_data;
968 clone_info->cache=image_info->cache;
969 if (image_info->cache != (void *) NULL)
970 clone_info->cache=ReferencePixelCache(image_info->cache);
971 if (image_info->profile != (void *) NULL)
972 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
973 image_info->profile);
974 SetImageInfoFile(clone_info,image_info->file);
975 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
976 clone_info->stream=image_info->stream;
977 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
978 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
979 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
980 (void) CopyMagickString(clone_info->filename,image_info->filename,
982 clone_info->channel=image_info->channel;
983 (void) CloneImageOptions(clone_info,image_info);
984 clone_info->debug=IsEventLogging();
985 clone_info->signature=image_info->signature;
990 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
994 % D e s t r o y I m a g e %
998 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1000 % DestroyImage() dereferences an image, deallocating memory associated with
1001 % the image if the reference count becomes zero.
1003 % The format of the DestroyImage method is:
1005 % Image *DestroyImage(Image *image)
1007 % A description of each parameter follows:
1009 % o image: the image.
1012 MagickExport Image *DestroyImage(Image *image)
1020 assert(image != (Image *) NULL);
1021 assert(image->signature == MagickSignature);
1022 if (image->debug != MagickFalse)
1023 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1024 destroy=MagickFalse;
1025 LockSemaphoreInfo(image->semaphore);
1026 image->reference_count--;
1027 if (image->reference_count == 0)
1029 UnlockSemaphoreInfo(image->semaphore);
1030 if (destroy == MagickFalse)
1031 return((Image *) NULL);
1035 DestroyImagePixels(image);
1036 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1037 if (image->montage != (char *) NULL)
1038 image->montage=DestroyString(image->montage);
1039 if (image->directory != (char *) NULL)
1040 image->directory=DestroyString(image->directory);
1041 if (image->colormap != (PixelInfo *) NULL)
1042 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1043 if (image->geometry != (char *) NULL)
1044 image->geometry=DestroyString(image->geometry);
1045 DestroyImageProfiles(image);
1046 DestroyImageProperties(image);
1047 DestroyImageArtifacts(image);
1048 if (image->ascii85 != (Ascii85Info*) NULL)
1049 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1051 if (image->semaphore != (SemaphoreInfo *) NULL)
1052 DestroySemaphoreInfo(&image->semaphore);
1053 image->signature=(~MagickSignature);
1054 image=(Image *) RelinquishMagickMemory(image);
1059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1063 % D e s t r o y I m a g e I n f o %
1067 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1069 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1072 % The format of the DestroyImageInfo method is:
1074 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1076 % A description of each parameter follows:
1078 % o image_info: the image info.
1081 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1083 assert(image_info != (ImageInfo *) NULL);
1084 assert(image_info->signature == MagickSignature);
1085 if (image_info->debug != MagickFalse)
1086 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1087 image_info->filename);
1088 if (image_info->size != (char *) NULL)
1089 image_info->size=DestroyString(image_info->size);
1090 if (image_info->extract != (char *) NULL)
1091 image_info->extract=DestroyString(image_info->extract);
1092 if (image_info->scenes != (char *) NULL)
1093 image_info->scenes=DestroyString(image_info->scenes);
1094 if (image_info->page != (char *) NULL)
1095 image_info->page=DestroyString(image_info->page);
1096 if (image_info->sampling_factor != (char *) NULL)
1097 image_info->sampling_factor=DestroyString(
1098 image_info->sampling_factor);
1099 if (image_info->server_name != (char *) NULL)
1100 image_info->server_name=DestroyString(
1101 image_info->server_name);
1102 if (image_info->font != (char *) NULL)
1103 image_info->font=DestroyString(image_info->font);
1104 if (image_info->texture != (char *) NULL)
1105 image_info->texture=DestroyString(image_info->texture);
1106 if (image_info->density != (char *) NULL)
1107 image_info->density=DestroyString(image_info->density);
1108 if (image_info->view != (char *) NULL)
1109 image_info->view=DestroyString(image_info->view);
1110 if (image_info->cache != (void *) NULL)
1111 image_info->cache=DestroyPixelCache(image_info->cache);
1112 if (image_info->profile != (StringInfo *) NULL)
1113 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1114 image_info->profile);
1115 DestroyImageOptions(image_info);
1116 image_info->signature=(~MagickSignature);
1117 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1126 + D i s a s s o c i a t e I m a g e S t r e a m %
1130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1132 % DisassociateImageStream() disassociates the image stream.
1134 % The format of the DisassociateImageStream method is:
1136 % MagickBooleanType DisassociateImageStream(const Image *image)
1138 % A description of each parameter follows:
1140 % o image: the image.
1143 MagickExport void DisassociateImageStream(Image *image)
1145 assert(image != (const Image *) NULL);
1146 assert(image->signature == MagickSignature);
1147 if (image->debug != MagickFalse)
1148 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1149 (void) DetachBlob(image->blob);
1153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1157 % G e t I m a g e A l p h a C h a n n e l %
1161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1163 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1164 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
1167 % The format of the GetImageAlphaChannel method is:
1169 % MagickBooleanType GetImageAlphaChannel(const Image *image)
1171 % A description of each parameter follows:
1173 % o image: the image.
1176 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1178 assert(image != (const Image *) NULL);
1179 if (image->debug != MagickFalse)
1180 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1181 assert(image->signature == MagickSignature);
1182 return(image->alpha_trait == BlendPixelTrait ? MagickTrue : MagickFalse);
1186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1190 % G e t I m a g e I n f o %
1194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1196 % GetImageInfo() initializes image_info to default values.
1198 % The format of the GetImageInfo method is:
1200 % void GetImageInfo(ImageInfo *image_info)
1202 % A description of each parameter follows:
1204 % o image_info: the image info.
1207 MagickExport void GetImageInfo(ImageInfo *image_info)
1216 File and image dimension members.
1218 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1219 assert(image_info != (ImageInfo *) NULL);
1220 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1221 image_info->adjoin=MagickTrue;
1222 image_info->interlace=NoInterlace;
1223 image_info->channel=DefaultChannels;
1224 image_info->quality=UndefinedCompressionQuality;
1225 image_info->antialias=MagickTrue;
1226 image_info->dither=MagickTrue;
1227 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1228 if (synchronize != (const char *) NULL)
1230 image_info->synchronize=IsStringTrue(synchronize);
1231 synchronize=DestroyString(synchronize);
1233 exception=AcquireExceptionInfo();
1234 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1235 &image_info->background_color,exception);
1236 (void) QueryColorCompliance(BorderColor,AllCompliance,
1237 &image_info->border_color,exception);
1238 (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
1240 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1241 &image_info->transparent_color,exception);
1242 exception=DestroyExceptionInfo(exception);
1243 image_info->debug=IsEventLogging();
1244 image_info->signature=MagickSignature;
1248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1252 % G e t I m a g e I n f o F i l e %
1256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1258 % GetImageInfoFile() returns the image info file member.
1260 % The format of the GetImageInfoFile method is:
1262 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1264 % A description of each parameter follows:
1266 % o image_info: the image info.
1269 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1271 return(image_info->file);
1275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1279 % G e t I m a g e M a s k %
1283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1285 % GetImageMask() returns the mask associated with the image.
1287 % The format of the GetImageMask method is:
1289 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1291 % A description of each parameter follows:
1293 % o image: the image.
1296 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1314 assert(image != (Image *) NULL);
1315 if (image->debug != MagickFalse)
1316 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1317 assert(image->signature == MagickSignature);
1318 mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1319 if (mask_image == (Image *) NULL)
1320 return((Image *) NULL);
1322 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1323 mask_image->mask=MagickFalse;
1324 image_view=AcquireVirtualCacheView(image,exception);
1325 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1326 for (y=0; y < (ssize_t) image->rows; y++)
1328 register const Quantum
1337 if (status == MagickFalse)
1339 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1340 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1342 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1347 for (x=0; x < (ssize_t) image->columns; x++)
1349 SetPixelGray(mask_image,GetPixelMask(image,p),q);
1350 p+=GetPixelChannels(image);
1351 q+=GetPixelChannels(mask_image);
1353 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1356 mask_view=DestroyCacheView(mask_view);
1357 image_view=DestroyCacheView(image_view);
1358 if (status == MagickFalse)
1359 mask_image=DestroyImage(mask_image);
1364 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1368 + G e t I m a g e R e f e r e n c e C o u n t %
1372 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1374 % GetImageReferenceCount() returns the image reference count.
1376 % The format of the GetReferenceCount method is:
1378 % ssize_t GetImageReferenceCount(Image *image)
1380 % A description of each parameter follows:
1382 % o image: the image.
1385 MagickExport ssize_t GetImageReferenceCount(Image *image)
1390 assert(image != (Image *) NULL);
1391 assert(image->signature == MagickSignature);
1392 if (image->debug != MagickFalse)
1393 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1394 LockSemaphoreInfo(image->semaphore);
1395 reference_count=image->reference_count;
1396 UnlockSemaphoreInfo(image->semaphore);
1397 return(reference_count);
1401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1405 % 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 %
1409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1411 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1412 % image. A virtual pixel is any pixel access that is outside the boundaries
1413 % of the image cache.
1415 % The format of the GetImageVirtualPixelMethod() method is:
1417 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1419 % A description of each parameter follows:
1421 % o image: the image.
1424 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1426 assert(image != (Image *) NULL);
1427 assert(image->signature == MagickSignature);
1428 if (image->debug != MagickFalse)
1429 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1430 return(GetPixelCacheVirtualMethod(image));
1434 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1438 % I n t e r p r e t I m a g e F i l e n a m e %
1442 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1444 % InterpretImageFilename() interprets embedded characters in an image filename.
1445 % The filename length is returned.
1447 % The format of the InterpretImageFilename method is:
1449 % size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1450 % const char *format,int value,char *filename,ExceptionInfo *exception)
1452 % A description of each parameter follows.
1454 % o image_info: the image info..
1456 % o image: the image.
1458 % o format: A filename describing the format to use to write the numeric
1459 % argument. Only the first numeric format identifier is replaced.
1461 % o value: Numeric value to substitute into format filename.
1463 % o filename: return the formatted filename in this character buffer.
1465 % o exception: return any errors or warnings in this structure.
1468 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1469 Image *image,const char *format,int value,char *filename,
1470 ExceptionInfo *exception)
1487 canonical=MagickFalse;
1489 (void) CopyMagickString(filename,format,MaxTextExtent);
1490 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1503 value=(ssize_t) strtol(q,&q,10);
1515 (void) FormatLocaleString(filename+(p-format),(size_t) (MaxTextExtent-
1516 (p-format)),p,value);
1518 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1519 canonical=MagickTrue;
1528 pattern[MaxTextExtent];
1545 /* FUTURE: Compare update with code from InterpretImageProperties()
1546 Note that a 'filename:' property should not need depth recursion.
1548 if (strchr(p,']') == (char *) NULL)
1552 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1563 if (LocaleNCompare(pattern,"filename:",9) != 0)
1565 value=(const char *) NULL;
1567 // FUTURE: remove this code. -- Anthony 29 Arpil 2012
1568 // Removed as GetMagickProperty() will will never match a "filename:"
1569 // string as this is not a 'known' image property.
1571 if ((image_info != (const ImageInfo *) NULL) &&
1572 (image != (const Image *) NULL))
1573 value=GetMagickProperty(image_info,image,pattern,exception);
1576 if (image != (Image *) NULL)
1577 value=GetImageProperty(image,pattern,exception);
1578 if ((value == (const char *) NULL) && (image != (Image *) NULL))
1579 value=GetImageArtifact(image,pattern);
1580 if ((value == (const char *) NULL) &&
1581 (image_info != (ImageInfo *) NULL))
1582 value=GetImageOption(image_info,pattern);
1583 if (value == (const char *) NULL)
1588 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1589 (MaxTextExtent-(p-format-length)));
1590 length+=strlen(pattern)-1;
1592 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1593 canonical=MagickTrue;
1603 for (q=filename; *q != '\0'; q++)
1604 if ((*q == '%') && (*(q+1) == '%'))
1606 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1607 canonical=MagickTrue;
1609 if (canonical == MagickFalse)
1610 (void) CopyMagickString(filename,format,MaxTextExtent);
1611 return(strlen(filename));
1615 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1619 % I s H i g h D y n a m i c R a n g e I m a g e %
1623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1625 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1626 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1629 % The format of the IsHighDynamicRangeImage method is:
1631 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1632 % ExceptionInfo *exception)
1634 % A description of each parameter follows:
1636 % o image: the image.
1638 % o exception: return any errors or warnings in this structure.
1641 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1642 ExceptionInfo *exception)
1644 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1647 return(MagickFalse);
1658 assert(image != (Image *) NULL);
1659 assert(image->signature == MagickSignature);
1660 if (image->debug != MagickFalse)
1661 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1663 image_view=AcquireVirtualCacheView(image,exception);
1664 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1665 #pragma omp parallel for schedule(static,4) shared(status) \
1666 magick_threads(image,image,image->rows,1)
1668 for (y=0; y < (ssize_t) image->rows; y++)
1670 register const Quantum
1676 if (status == MagickFalse)
1678 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1679 if (p == (const Quantum *) NULL)
1684 for (x=0; x < (ssize_t) image->columns; x++)
1689 if (GetPixelMask(image,p) == 0)
1691 p+=GetPixelChannels(image);
1694 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1702 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1703 if (traits == UndefinedPixelTrait)
1705 pixel=(double) p[i];
1706 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1707 (pixel != (QuantumAny) pixel))
1710 p+=GetPixelChannels(image);
1711 if (i < (ssize_t) GetPixelChannels(image))
1714 if (x < (ssize_t) image->columns)
1717 image_view=DestroyCacheView(image_view);
1718 return(status != MagickFalse ? MagickFalse : MagickTrue);
1723 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1727 % I s I m a g e O b j e c t %
1731 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1733 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1734 % set of image objects.
1736 % The format of the IsImageObject method is:
1738 % MagickBooleanType IsImageObject(const Image *image)
1740 % A description of each parameter follows:
1742 % o image: the image.
1745 MagickExport MagickBooleanType IsImageObject(const Image *image)
1747 register const Image
1750 assert(image != (Image *) NULL);
1751 if (image->debug != MagickFalse)
1752 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1753 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1754 if (p->signature != MagickSignature)
1755 return(MagickFalse);
1760 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1764 % I s T a i n t I m a g e %
1768 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1770 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1771 % since it was first constituted.
1773 % The format of the IsTaintImage method is:
1775 % MagickBooleanType IsTaintImage(const Image *image)
1777 % A description of each parameter follows:
1779 % o image: the image.
1782 MagickExport MagickBooleanType IsTaintImage(const Image *image)
1785 magick[MaxTextExtent],
1786 filename[MaxTextExtent];
1788 register const Image
1791 assert(image != (Image *) NULL);
1792 if (image->debug != MagickFalse)
1793 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1794 assert(image->signature == MagickSignature);
1795 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
1796 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1797 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1799 if (p->taint != MagickFalse)
1801 if (LocaleCompare(p->magick,magick) != 0)
1803 if (LocaleCompare(p->filename,filename) != 0)
1806 return(MagickFalse);
1810 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1814 % M o d i f y I m a g e %
1818 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1820 % ModifyImage() ensures that there is only a single reference to the image
1821 % to be modified, updating the provided image pointer to point to a clone of
1822 % the original image if necessary.
1824 % The format of the ModifyImage method is:
1826 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1828 % A description of each parameter follows:
1830 % o image: the image.
1832 % o exception: return any errors or warnings in this structure.
1835 MagickExport MagickBooleanType ModifyImage(Image **image,
1836 ExceptionInfo *exception)
1841 assert(image != (Image **) NULL);
1842 assert(*image != (Image *) NULL);
1843 assert((*image)->signature == MagickSignature);
1844 if ((*image)->debug != MagickFalse)
1845 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1846 if (GetImageReferenceCount(*image) <= 1)
1848 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
1849 LockSemaphoreInfo((*image)->semaphore);
1850 (*image)->reference_count--;
1851 UnlockSemaphoreInfo((*image)->semaphore);
1857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1861 % N e w M a g i c k I m a g e %
1865 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1867 % NewMagickImage() creates a blank image canvas of the specified size and
1870 % The format of the NewMagickImage method is:
1872 % Image *NewMagickImage(const ImageInfo *image_info,
1873 % const size_t width,const size_t height,const PixelInfo *background,
1874 % ExceptionInfo *exception)
1876 % A description of each parameter follows:
1878 % o image: the image.
1880 % o width: the image width.
1882 % o height: the image height.
1884 % o background: the image color.
1886 % o exception: return any errors or warnings in this structure.
1889 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
1890 const size_t width,const size_t height,const PixelInfo *background,
1891 ExceptionInfo *exception)
1905 assert(image_info != (const ImageInfo *) NULL);
1906 if (image_info->debug != MagickFalse)
1907 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1908 assert(image_info->signature == MagickSignature);
1909 assert(background != (const PixelInfo *) NULL);
1910 image=AcquireImage(image_info,exception);
1911 image->columns=width;
1913 image->colorspace=background->colorspace;
1914 image->alpha_trait=background->alpha_trait;
1915 image->fuzz=background->fuzz;
1916 image->depth=background->depth;
1918 image_view=AcquireAuthenticCacheView(image,exception);
1919 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1920 #pragma omp parallel for schedule(static,4) shared(status) \
1921 magick_threads(image,image,image->rows,1)
1923 for (y=0; y < (ssize_t) image->rows; y++)
1931 if (status == MagickFalse)
1933 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
1934 if (q == (Quantum *) NULL)
1939 for (x=0; x < (ssize_t) image->columns; x++)
1941 SetPixelInfoPixel(image,background,q);
1942 q+=GetPixelChannels(image);
1944 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1947 image_view=DestroyCacheView(image_view);
1948 if (status == MagickFalse)
1949 image=DestroyImage(image);
1954 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1958 % R e f e r e n c e I m a g e %
1962 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1964 % ReferenceImage() increments the reference count associated with an image
1965 % returning a pointer to the image.
1967 % The format of the ReferenceImage method is:
1969 % Image *ReferenceImage(Image *image)
1971 % A description of each parameter follows:
1973 % o image: the image.
1976 MagickExport Image *ReferenceImage(Image *image)
1978 assert(image != (Image *) NULL);
1979 if (image->debug != MagickFalse)
1980 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1981 assert(image->signature == MagickSignature);
1982 LockSemaphoreInfo(image->semaphore);
1983 image->reference_count++;
1984 UnlockSemaphoreInfo(image->semaphore);
1989 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1993 % R e s e t I m a g e P a g e %
1997 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999 % ResetImagePage() resets the image page canvas and position.
2001 % The format of the ResetImagePage method is:
2003 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2005 % A description of each parameter follows:
2007 % o image: the image.
2009 % o page: the relative page specification.
2012 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2020 assert(image != (Image *) NULL);
2021 assert(image->signature == MagickSignature);
2022 if (image->debug != MagickFalse)
2023 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2024 flags=ParseAbsoluteGeometry(page,&geometry);
2025 if ((flags & WidthValue) != 0)
2027 if ((flags & HeightValue) == 0)
2028 geometry.height=geometry.width;
2029 image->page.width=geometry.width;
2030 image->page.height=geometry.height;
2032 if ((flags & AspectValue) != 0)
2034 if ((flags & XValue) != 0)
2035 image->page.x+=geometry.x;
2036 if ((flags & YValue) != 0)
2037 image->page.y+=geometry.y;
2041 if ((flags & XValue) != 0)
2043 image->page.x=geometry.x;
2044 if ((image->page.width == 0) && (geometry.x > 0))
2045 image->page.width=image->columns+geometry.x;
2047 if ((flags & YValue) != 0)
2049 image->page.y=geometry.y;
2050 if ((image->page.height == 0) && (geometry.y > 0))
2051 image->page.height=image->rows+geometry.y;
2058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2062 % S e t I m a g e A l p h a C h a n n e l %
2066 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2068 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2071 % The format of the SetImageAlphaChannel method is:
2073 % MagickBooleanType SetImageAlphaChannel(Image *image,
2074 % const AlphaChannelOption alpha_type,ExceptionInfo *exception)
2076 % A description of each parameter follows:
2078 % o image: the image.
2080 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
2081 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2082 % OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
2083 % TransparentAlphaChannel.
2085 % o exception: return any errors or warnings in this structure.
2089 static inline void FlattenPixelInfo(const Image *image,const PixelInfo *p,
2090 const double alpha,const Quantum *q,const double beta,
2102 Compose pixel p over pixel q with the given alpha.
2104 Sa=QuantumScale*alpha;
2105 Da=QuantumScale*beta,
2106 gamma=Sa*(-Da)+Sa+Da;
2107 gamma=PerceptibleReciprocal(gamma);
2108 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2110 PixelChannel channel=GetPixelChannelChannel(image,i);
2111 PixelTrait traits=GetPixelChannelTraits(image,channel);
2112 if (traits == UndefinedPixelTrait)
2116 case RedPixelChannel:
2118 composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
2119 (double) p->red,alpha));
2122 case GreenPixelChannel:
2124 composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
2125 (double) p->green,alpha));
2128 case BluePixelChannel:
2130 composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
2131 (double) p->blue,alpha));
2134 case BlackPixelChannel:
2136 composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
2137 (double) p->black,alpha));
2140 case AlphaPixelChannel:
2142 composite[i]=ClampToQuantum(QuantumRange*(Sa*(-Da)+Sa+Da));
2151 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2152 const AlphaChannelOption alpha_type,ExceptionInfo *exception)
2157 assert(image != (Image *) NULL);
2158 if (image->debug != MagickFalse)
2159 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2160 assert(image->signature == MagickSignature);
2164 case ActivateAlphaChannel:
2166 image->alpha_trait=BlendPixelTrait;
2169 case BackgroundAlphaChannel:
2178 Set transparent pixels to background color.
2180 if (image->alpha_trait != BlendPixelTrait)
2182 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2184 image_view=AcquireAuthenticCacheView(image,exception);
2185 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2186 #pragma omp parallel for schedule(static,4) shared(status) \
2187 magick_threads(image,image,image->rows,1)
2189 for (y=0; y < (ssize_t) image->rows; y++)
2197 if (status == MagickFalse)
2199 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2201 if (q == (Quantum *) NULL)
2206 for (x=0; x < (ssize_t) image->columns; x++)
2208 if (GetPixelAlpha(image,q) == TransparentAlpha)
2210 SetPixelInfoPixel(image,&image->background_color,q);
2211 SetPixelChannel(image,AlphaPixelChannel,TransparentAlpha,q);
2213 q+=GetPixelChannels(image);
2215 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2218 image_view=DestroyCacheView(image_view);
2221 case CopyAlphaChannel:
2222 case ShapeAlphaChannel:
2225 Copy pixel intensity to the alpha channel.
2227 status=CompositeImage(image,image,IntensityCompositeOp,MagickTrue,0,0,
2229 if (alpha_type == ShapeAlphaChannel)
2230 (void) LevelImageColors(image,&image->background_color,
2231 &image->background_color,MagickTrue,exception);
2234 case DeactivateAlphaChannel:
2236 image->alpha_trait=CopyPixelTrait;
2239 case ExtractAlphaChannel:
2241 status=CompositeImage(image,image,AlphaCompositeOp,MagickTrue,0,0,
2243 image->alpha_trait=CopyPixelTrait;
2246 case OpaqueAlphaChannel:
2248 status=SetImageAlpha(image,OpaqueAlpha,exception);
2251 case RemoveAlphaChannel:
2260 Remove transparency.
2262 if (image->alpha_trait != BlendPixelTrait)
2264 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2266 image_view=AcquireAuthenticCacheView(image,exception);
2267 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2268 #pragma omp parallel for schedule(static,4) shared(status) \
2269 magick_threads(image,image,image->rows,1)
2271 for (y=0; y < (ssize_t) image->rows; y++)
2279 if (status == MagickFalse)
2281 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2283 if (q == (Quantum *) NULL)
2288 for (x=0; x < (ssize_t) image->columns; x++)
2290 FlattenPixelInfo(image,&image->background_color,
2291 image->background_color.alpha,q,(double)
2292 GetPixelAlpha(image,q),q);
2293 q+=GetPixelChannels(image);
2295 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2298 image_view=DestroyCacheView(image_view);
2299 image->alpha_trait=image->background_color.alpha_trait;
2302 case SetAlphaChannel:
2304 if (image->alpha_trait != BlendPixelTrait)
2305 status=SetImageAlpha(image,OpaqueAlpha,exception);
2308 case TransparentAlphaChannel:
2310 status=SetImageAlpha(image,TransparentAlpha,exception);
2313 case UndefinedAlphaChannel:
2316 if (status == MagickFalse)
2318 return(SyncImagePixelCache(image,exception));
2322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2326 % S e t I m a g e B a c k g r o u n d C o l o r %
2330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2332 % SetImageBackgroundColor() initializes the image pixels to the image
2333 % background color. The background color is defined by the background_color
2334 % member of the image structure.
2336 % The format of the SetImage method is:
2338 % MagickBooleanType SetImageBackgroundColor(Image *image,
2339 % ExceptionInfo *exception)
2341 % A description of each parameter follows:
2343 % o image: the image.
2345 % o exception: return any errors or warnings in this structure.
2348 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2349 ExceptionInfo *exception)
2360 assert(image != (Image *) NULL);
2361 if (image->debug != MagickFalse)
2362 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2363 assert(image->signature == MagickSignature);
2364 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2365 return(MagickFalse);
2366 if ((IsPixelInfoGray(&image->background_color) == MagickFalse) &&
2367 (IsGrayColorspace(image->colorspace) != MagickFalse))
2368 (void) TransformImageColorspace(image,sRGBColorspace,exception);
2369 if ((image->background_color.alpha_trait == BlendPixelTrait) &&
2370 (image->alpha_trait != BlendPixelTrait))
2371 (void) SetImageAlpha(image,OpaqueAlpha,exception);
2373 Set image background color.
2376 image_view=AcquireAuthenticCacheView(image,exception);
2377 for (y=0; y < (ssize_t) image->rows; y++)
2385 if (status == MagickFalse)
2387 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2388 if (q == (Quantum *) NULL)
2393 for (x=0; x < (ssize_t) image->columns; x++)
2395 SetPixelInfoPixel(image,&image->background_color,q);
2396 q+=GetPixelChannels(image);
2398 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2401 image_view=DestroyCacheView(image_view);
2406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2410 % S e t I m a g e C h a n n e l M a s k %
2414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2416 % SetImageChannelMask() sets the image channel mask from the specified channel
2419 % The format of the SetImageChannelMask method is:
2421 % ChannelType SetImageChannelMask(Image *image,
2422 % const ChannelType channel_mask)
2424 % A description of each parameter follows:
2426 % o image: the image.
2428 % o channel_mask: the channel mask.
2431 MagickExport ChannelType SetImageChannelMask(Image *image,
2432 const ChannelType channel_mask)
2437 mask=image->channel_mask;
2438 image->channel_mask=channel_mask;
2439 SetPixelChannelMask(image,channel_mask);
2444 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2448 % S e t I m a g e C o l o r %
2452 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2454 % SetImageColor() set the entire image canvas to the specified color.
2456 % The format of the SetImageColor method is:
2458 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2459 % ExeptionInfo *exception)
2461 % A description of each parameter follows:
2463 % o image: the image.
2465 % o background: the image color.
2467 % o exception: return any errors or warnings in this structure.
2470 MagickExport MagickBooleanType SetImageColor(Image *image,
2471 const PixelInfo *color,ExceptionInfo *exception)
2482 assert(image != (Image *) NULL);
2483 if (image->debug != MagickFalse)
2484 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2485 assert(image->signature == MagickSignature);
2486 assert(color != (const PixelInfo *) NULL);
2487 image->colorspace=color->colorspace;
2488 image->alpha_trait=color->alpha_trait;
2489 image->fuzz=color->fuzz;
2490 image->depth=color->depth;
2492 image_view=AcquireAuthenticCacheView(image,exception);
2493 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2494 #pragma omp parallel for schedule(static,4) shared(status) \
2495 magick_threads(image,image,image->rows,1)
2497 for (y=0; y < (ssize_t) image->rows; y++)
2505 if (status == MagickFalse)
2507 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2508 if (q == (Quantum *) NULL)
2513 for (x=0; x < (ssize_t) image->columns; x++)
2515 SetPixelInfoPixel(image,color,q);
2516 q+=GetPixelChannels(image);
2518 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2521 image_view=DestroyCacheView(image_view);
2526 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2530 % S e t I m a g e S t o r a g e C l a s s %
2534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2536 % SetImageStorageClass() sets the image class: DirectClass for true color
2537 % images or PseudoClass for colormapped images.
2539 % The format of the SetImageStorageClass method is:
2541 % MagickBooleanType SetImageStorageClass(Image *image,
2542 % const ClassType storage_class,ExceptionInfo *exception)
2544 % A description of each parameter follows:
2546 % o image: the image.
2548 % o storage_class: The image class.
2550 % o exception: return any errors or warnings in this structure.
2553 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2554 const ClassType storage_class,ExceptionInfo *exception)
2556 image->storage_class=storage_class;
2557 return(SyncImagePixelCache(image,exception));
2561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2565 % S e t I m a g e E x t e n t %
2569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2571 % SetImageExtent() sets the image size (i.e. columns & rows).
2573 % The format of the SetImageExtent method is:
2575 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2576 % const size_t rows,ExceptionInfo *exception)
2578 % A description of each parameter follows:
2580 % o image: the image.
2582 % o columns: The image width in pixels.
2584 % o rows: The image height in pixels.
2586 % o exception: return any errors or warnings in this structure.
2589 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2590 const size_t rows,ExceptionInfo *exception)
2592 if ((columns == 0) || (rows == 0))
2593 return(MagickFalse);
2594 image->columns=columns;
2596 return(SyncImagePixelCache(image,exception));
2600 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2604 + S e t I m a g e I n f o %
2608 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2610 % SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
2611 % It is set to a type of image format based on the prefix or suffix of the
2612 % filename. For example, 'ps:image' returns PS indicating a Postscript image.
2613 % JPEG is returned for this filename: 'image.jpg'. The filename prefix has
2614 % precendence over the suffix. Use an optional index enclosed in brackets
2615 % after a file name to specify a desired scene of a multi-resolution image
2616 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2617 % indicates success.
2619 % The format of the SetImageInfo method is:
2621 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
2622 % const unsigned int frames,ExceptionInfo *exception)
2624 % A description of each parameter follows:
2626 % o image_info: the image info.
2628 % o frames: the number of images you intend to write.
2630 % o exception: return any errors or warnings in this structure.
2633 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2634 const unsigned int frames,ExceptionInfo *exception)
2637 extension[MaxTextExtent],
2638 filename[MaxTextExtent],
2639 magic[MaxTextExtent],
2641 subimage[MaxTextExtent];
2665 magick[2*MaxTextExtent];
2668 Look for 'image.format' in filename.
2670 assert(image_info != (ImageInfo *) NULL);
2671 assert(image_info->signature == MagickSignature);
2672 if (image_info->debug != MagickFalse)
2673 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2674 image_info->filename);
2678 GetPathComponent(image_info->filename,SubimagePath,subimage);
2679 if (*subimage != '\0')
2682 Look for scene specification (e.g. img0001.pcd[4]).
2684 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
2686 if (IsGeometry(subimage) != MagickFalse)
2687 (void) CloneString(&image_info->extract,subimage);
2695 (void) CloneString(&image_info->scenes,subimage);
2696 image_info->scene=StringToUnsignedLong(image_info->scenes);
2697 image_info->number_scenes=image_info->scene;
2698 p=image_info->scenes;
2699 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2701 while ((isspace((int) ((unsigned char) *p)) != 0) ||
2704 first=(size_t) strtol(p,&q,10);
2706 while (isspace((int) ((unsigned char) *q)) != 0)
2709 last=(size_t) strtol(q+1,&q,10);
2712 if (first < image_info->scene)
2713 image_info->scene=first;
2714 if (last > image_info->number_scenes)
2715 image_info->number_scenes=last;
2718 image_info->number_scenes-=image_info->scene-1;
2723 GetPathComponent(image_info->filename,ExtensionPath,extension);
2724 #if defined(MAGICKCORE_ZLIB_DELEGATE)
2725 if (*extension != '\0')
2726 if ((LocaleCompare(extension,"gz") == 0) ||
2727 (LocaleCompare(extension,"Z") == 0) ||
2728 (LocaleCompare(extension,"svgz") == 0) ||
2729 (LocaleCompare(extension,"wmz") == 0))
2732 path[MaxTextExtent];
2734 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
2735 path[strlen(path)-strlen(extension)-1]='\0';
2736 GetPathComponent(path,ExtensionPath,extension);
2739 #if defined(MAGICKCORE_BZLIB_DELEGATE)
2740 if (*extension != '\0')
2741 if (LocaleCompare(extension,"bz2") == 0)
2744 path[MaxTextExtent];
2746 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
2747 path[strlen(path)-strlen(extension)-1]='\0';
2748 GetPathComponent(path,ExtensionPath,extension);
2751 image_info->affirm=MagickFalse;
2752 sans_exception=AcquireExceptionInfo();
2753 if (*extension != '\0')
2762 *format_type_formats[] =
2785 User specified image format.
2787 (void) CopyMagickString(magic,extension,MaxTextExtent);
2790 Look for explicit image formats.
2792 format_type=UndefinedFormatType;
2794 while ((format_type == UndefinedFormatType) &&
2795 (format_type_formats[i] != (char *) NULL))
2797 if ((*magic == *format_type_formats[i]) &&
2798 (LocaleCompare(magic,format_type_formats[i]) == 0))
2799 format_type=ExplicitFormatType;
2802 magick_info=GetMagickInfo(magic,sans_exception);
2803 if ((magick_info != (const MagickInfo *) NULL) &&
2804 (magick_info->format_type != UndefinedFormatType))
2805 format_type=magick_info->format_type;
2806 if (format_type == UndefinedFormatType)
2807 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2809 if (format_type == ExplicitFormatType)
2811 image_info->affirm=MagickTrue;
2812 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2814 if (LocaleCompare(magic,"RGB") == 0)
2815 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2818 Look for explicit 'format:image' in filename.
2821 GetPathComponent(image_info->filename,MagickPath,magic);
2823 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
2827 User specified image format.
2830 if (IsMagickConflict(magic) == MagickFalse)
2832 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2833 if (LocaleCompare(magic,"EPHEMERAL") != 0)
2834 image_info->affirm=MagickTrue;
2836 image_info->temporary=MagickTrue;
2839 magick_info=GetMagickInfo(magic,sans_exception);
2840 sans_exception=DestroyExceptionInfo(sans_exception);
2841 if ((magick_info == (const MagickInfo *) NULL) ||
2842 (GetMagickEndianSupport(magick_info) == MagickFalse))
2843 image_info->endian=UndefinedEndian;
2844 GetPathComponent(image_info->filename,CanonicalPath,filename);
2845 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
2846 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2849 Test for multiple image support (e.g. image%02d.png).
2851 (void) InterpretImageFilename(image_info,(Image *) NULL,
2852 image_info->filename,(int) image_info->scene,filename,exception);
2853 if ((LocaleCompare(filename,image_info->filename) != 0) &&
2854 (strchr(filename,'%') == (char *) NULL))
2855 image_info->adjoin=MagickFalse;
2857 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2860 Some image formats do not support multiple frames per file.
2862 magick_info=GetMagickInfo(magic,exception);
2863 if (magick_info != (const MagickInfo *) NULL)
2864 if (GetMagickAdjoin(magick_info) == MagickFalse)
2865 image_info->adjoin=MagickFalse;
2867 if (image_info->affirm != MagickFalse)
2872 Determine the image format from the first few bytes of the file.
2874 image=AcquireImage(image_info,exception);
2875 (void) CopyMagickString(image->filename,image_info->filename,
2877 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2878 if (status == MagickFalse)
2880 image=DestroyImage(image);
2881 return(MagickFalse);
2883 if ((IsBlobSeekable(image) == MagickFalse) ||
2884 (IsBlobExempt(image) != MagickFalse))
2887 Copy standard input or pipe to temporary file.
2890 status=ImageToFile(image,filename,exception);
2891 (void) CloseBlob(image);
2892 if (status == MagickFalse)
2894 image=DestroyImage(image);
2895 return(MagickFalse);
2897 SetImageInfoFile(image_info,(FILE *) NULL);
2898 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
2899 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2900 if (status == MagickFalse)
2902 image=DestroyImage(image);
2903 return(MagickFalse);
2905 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
2906 image_info->temporary=MagickTrue;
2908 (void) ResetMagickMemory(magick,0,sizeof(magick));
2909 count=ReadBlob(image,2*MaxTextExtent,magick);
2910 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
2911 (void) CloseBlob(image);
2912 image=DestroyImage(image);
2914 Check magic.xml configuration file.
2916 sans_exception=AcquireExceptionInfo();
2917 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
2918 if ((magic_info != (const MagicInfo *) NULL) &&
2919 (GetMagicName(magic_info) != (char *) NULL))
2921 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
2923 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2924 if ((magick_info == (const MagickInfo *) NULL) ||
2925 (GetMagickEndianSupport(magick_info) == MagickFalse))
2926 image_info->endian=UndefinedEndian;
2927 sans_exception=DestroyExceptionInfo(sans_exception);
2930 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2931 if ((magick_info == (const MagickInfo *) NULL) ||
2932 (GetMagickEndianSupport(magick_info) == MagickFalse))
2933 image_info->endian=UndefinedEndian;
2934 sans_exception=DestroyExceptionInfo(sans_exception);
2940 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2944 % S e t I m a g e I n f o B l o b %
2948 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2950 % SetImageInfoBlob() sets the image info blob member.
2952 % The format of the SetImageInfoBlob method is:
2954 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2955 % const size_t length)
2957 % A description of each parameter follows:
2959 % o image_info: the image info.
2963 % o length: the blob length.
2966 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2967 const size_t length)
2969 assert(image_info != (ImageInfo *) NULL);
2970 assert(image_info->signature == MagickSignature);
2971 if (image_info->debug != MagickFalse)
2972 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2973 image_info->filename);
2974 image_info->blob=(void *) blob;
2975 image_info->length=length;
2979 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2983 % S e t I m a g e I n f o F i l e %
2987 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2989 % SetImageInfoFile() sets the image info file member.
2991 % The format of the SetImageInfoFile method is:
2993 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2995 % A description of each parameter follows:
2997 % o image_info: the image info.
3002 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3004 assert(image_info != (ImageInfo *) NULL);
3005 assert(image_info->signature == MagickSignature);
3006 if (image_info->debug != MagickFalse)
3007 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3008 image_info->filename);
3009 image_info->file=file;
3013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3017 % S e t I m a g e M a s k %
3021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3023 % SetImageMask() associates a mask with the image. The mask must be the same
3024 % dimensions as the image.
3026 % The format of the SetImageMask method is:
3028 % MagickBooleanType SetImageMask(Image *image,const Image *mask,
3029 % ExceptionInfo *exception)
3031 % A description of each parameter follows:
3033 % o image: the image.
3035 % o mask: the image mask.
3037 % o exception: return any errors or warnings in this structure.
3040 MagickExport MagickBooleanType SetImageMask(Image *image,const Image *mask,
3041 ExceptionInfo *exception)
3056 assert(image != (Image *) NULL);
3057 if (image->debug != MagickFalse)
3058 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3059 assert(image->signature == MagickSignature);
3060 if (mask == (const Image *) NULL)
3062 image->mask=MagickFalse;
3063 return(SyncImagePixelCache(image,exception));
3065 image->mask=MagickTrue;
3066 if (SyncImagePixelCache(image,exception) == MagickFalse)
3067 return(MagickFalse);
3069 mask_view=AcquireVirtualCacheView(mask,exception);
3070 image_view=AcquireAuthenticCacheView(image,exception);
3071 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3072 #pragma omp parallel for schedule(static,4) shared(status) \
3073 magick_threads(mask,image,1,1)
3075 for (y=0; y < (ssize_t) image->rows; y++)
3077 register const Quantum
3086 if (status == MagickFalse)
3088 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3089 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3090 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3095 for (x=0; x < (ssize_t) image->columns; x++)
3097 SetPixelMask(image,ClampToQuantum(GetPixelIntensity(mask,p)),q);
3098 p+=GetPixelChannels(mask);
3099 q+=GetPixelChannels(image);
3101 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3104 mask_view=DestroyCacheView(mask_view);
3105 image_view=DestroyCacheView(image_view);
3110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3114 % S e t I m a g e A l p h a %
3118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3120 % SetImageAlpha() sets the alpha levels of the image.
3122 % The format of the SetImageAlpha method is:
3124 % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3125 % ExceptionInfo *exception)
3127 % A description of each parameter follows:
3129 % o image: the image.
3131 % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3132 % fully transparent.
3135 MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3136 ExceptionInfo *exception)
3147 assert(image != (Image *) NULL);
3148 if (image->debug != MagickFalse)
3149 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3150 assert(image->signature == MagickSignature);
3151 image->alpha_trait=BlendPixelTrait;
3153 image_view=AcquireAuthenticCacheView(image,exception);
3154 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3155 #pragma omp parallel for schedule(static,4) shared(status) \
3156 magick_threads(image,image,image->rows,1)
3158 for (y=0; y < (ssize_t) image->rows; y++)
3166 if (status == MagickFalse)
3168 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3169 if (q == (Quantum *) NULL)
3174 for (x=0; x < (ssize_t) image->columns; x++)
3176 SetPixelAlpha(image,alpha,q);
3177 q+=GetPixelChannels(image);
3179 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3182 image_view=DestroyCacheView(image_view);
3187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3191 % 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 %
3195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3197 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3198 % image and returns the previous setting. A virtual pixel is any pixel access
3199 % that is outside the boundaries of the image cache.
3201 % The format of the SetImageVirtualPixelMethod() method is:
3203 % VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3204 % const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3206 % A description of each parameter follows:
3208 % o image: the image.
3210 % o virtual_pixel_method: choose the type of virtual pixel.
3212 % o exception: return any errors or warnings in this structure.
3215 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3216 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3218 assert(image != (const Image *) NULL);
3219 assert(image->signature == MagickSignature);
3220 if (image->debug != MagickFalse)
3221 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3222 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3230 % S m u s h I m a g e s %
3234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3236 % SmushImages() takes all images from the current image pointer to the end
3237 % of the image list and smushes them to each other top-to-bottom if the
3238 % stack parameter is true, otherwise left-to-right.
3240 % The current gravity setting now effects how the image is justified in the
3243 % The format of the SmushImages method is:
3245 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3246 % ExceptionInfo *exception)
3248 % A description of each parameter follows:
3250 % o images: the image sequence.
3252 % o stack: A value other than 0 stacks the images top-to-bottom.
3254 % o offset: minimum distance in pixels between images.
3256 % o exception: return any errors or warnings in this structure.
3260 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3261 const ssize_t offset,ExceptionInfo *exception)
3275 register const Quantum
3288 if (images->previous == (Image *) NULL)
3291 SetGeometry(smush_image,&right_geometry);
3292 GravityAdjustGeometry(right_image->columns,right_image->rows,
3293 right_image->gravity,&right_geometry);
3294 left_image=images->previous;
3295 SetGeometry(smush_image,&left_geometry);
3296 GravityAdjustGeometry(left_image->columns,left_image->rows,
3297 left_image->gravity,&left_geometry);
3298 gap=right_image->columns;
3299 left_view=AcquireVirtualCacheView(left_image,exception);
3300 right_view=AcquireVirtualCacheView(right_image,exception);
3301 for (y=0; y < (ssize_t) smush_image->rows; y++)
3303 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3305 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3306 if ((p == (const Quantum *) NULL) ||
3307 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3308 ((left_image->columns-x-1) >= gap))
3311 i=(ssize_t) left_image->columns-x-1;
3312 for (x=0; x < (ssize_t) right_image->columns; x++)
3314 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3316 if ((p == (const Quantum *) NULL) ||
3317 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3318 ((x+i) >= (ssize_t) gap))
3321 if ((x+i) < (ssize_t) gap)
3324 right_view=DestroyCacheView(right_view);
3325 left_view=DestroyCacheView(left_view);
3326 if (y < (ssize_t) smush_image->rows)
3328 return((ssize_t) gap-offset);
3331 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3332 const ssize_t offset,ExceptionInfo *exception)
3346 register const Quantum
3359 if (images->previous == (Image *) NULL)
3361 bottom_image=images;
3362 SetGeometry(smush_image,&bottom_geometry);
3363 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3364 bottom_image->gravity,&bottom_geometry);
3365 top_image=images->previous;
3366 SetGeometry(smush_image,&top_geometry);
3367 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3369 gap=bottom_image->rows;
3370 top_view=AcquireVirtualCacheView(top_image,exception);
3371 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3372 for (x=0; x < (ssize_t) smush_image->columns; x++)
3374 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3376 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3377 if ((p == (const Quantum *) NULL) ||
3378 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3379 ((top_image->rows-y-1) >= gap))
3382 i=(ssize_t) top_image->rows-y-1;
3383 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3385 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3387 if ((p == (const Quantum *) NULL) ||
3388 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3389 ((y+i) >= (ssize_t) gap))
3392 if ((y+i) < (ssize_t) gap)
3395 bottom_view=DestroyCacheView(bottom_view);
3396 top_view=DestroyCacheView(top_view);
3397 if (x < (ssize_t) smush_image->columns)
3399 return((ssize_t) gap-offset);
3402 MagickExport Image *SmushImages(const Image *images,
3403 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3405 #define SmushImageTag "Smush/Image"
3426 register const Image
3439 Compute maximum area of smushed area.
3441 assert(images != (Image *) NULL);
3442 assert(images->signature == MagickSignature);
3443 if (images->debug != MagickFalse)
3444 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3445 assert(exception != (ExceptionInfo *) NULL);
3446 assert(exception->signature == MagickSignature);
3448 alpha_trait=image->alpha_trait;
3450 width=image->columns;
3452 next=GetNextImageInList(image);
3453 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3455 if (next->alpha_trait == BlendPixelTrait)
3456 alpha_trait=BlendPixelTrait;
3458 if (stack != MagickFalse)
3460 if (next->columns > width)
3461 width=next->columns;
3463 if (next->previous != (Image *) NULL)
3467 width+=next->columns;
3468 if (next->previous != (Image *) NULL)
3470 if (next->rows > height)
3476 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3477 if (smush_image == (Image *) NULL)
3478 return((Image *) NULL);
3479 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3481 smush_image=DestroyImage(smush_image);
3482 return((Image *) NULL);
3484 smush_image->alpha_trait=alpha_trait;
3485 (void) SetImageBackgroundColor(smush_image,exception);
3489 for (n=0; n < (MagickOffsetType) number_images; n++)
3491 SetGeometry(smush_image,&geometry);
3492 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3493 if (stack != MagickFalse)
3495 x_offset-=geometry.x;
3496 y_offset-=SmushYGap(smush_image,image,offset,exception);
3500 x_offset-=SmushXGap(smush_image,image,offset,exception);
3501 y_offset-=geometry.y;
3503 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3504 y_offset,exception);
3505 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3506 if (proceed == MagickFalse)
3508 if (stack == MagickFalse)
3510 x_offset+=(ssize_t) image->columns;
3516 y_offset+=(ssize_t) image->rows;
3518 image=GetNextImageInList(image);
3520 if (stack == MagickFalse)
3521 smush_image->columns=(size_t) x_offset;
3523 smush_image->rows=(size_t) y_offset;
3524 if (status == MagickFalse)
3525 smush_image=DestroyImage(smush_image);
3526 return(smush_image);
3530 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3534 % S t r i p I m a g e %
3538 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3540 % StripImage() strips an image of all profiles and comments.
3542 % The format of the StripImage method is:
3544 % MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3546 % A description of each parameter follows:
3548 % o image: the image.
3550 % o exception: return any errors or warnings in this structure.
3553 MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3558 assert(image != (Image *) NULL);
3559 if (image->debug != MagickFalse)
3560 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3562 DestroyImageProfiles(image);
3563 (void) DeleteImageProperty(image,"comment");
3564 (void) DeleteImageProperty(image,"date:create");
3565 (void) DeleteImageProperty(image,"date:modify");
3566 status=SetImageArtifact(image,"png:include-chunk","none,trns,gama");
3571 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3575 + S y n c I m a g e %
3579 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3581 % SyncImage() initializes the red, green, and blue intensities of each pixel
3582 % as defined by the colormap index.
3584 % The format of the SyncImage method is:
3586 % MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3588 % A description of each parameter follows:
3590 % o image: the image.
3592 % o exception: return any errors or warnings in this structure.
3596 static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3597 MagickBooleanType *range_exception)
3599 if ((size_t) index < image->colors)
3601 *range_exception=MagickTrue;
3602 return((Quantum) 0);
3605 MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3617 assert(image != (Image *) NULL);
3618 if (image->debug != MagickFalse)
3619 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3620 assert(image->signature == MagickSignature);
3621 if (image->storage_class == DirectClass)
3622 return(MagickFalse);
3623 range_exception=MagickFalse;
3625 image_view=AcquireAuthenticCacheView(image,exception);
3626 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3627 #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
3628 magick_threads(image,image,image->rows,1)
3630 for (y=0; y < (ssize_t) image->rows; y++)
3641 if (status == MagickFalse)
3643 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3644 if (q == (Quantum *) NULL)
3649 for (x=0; x < (ssize_t) image->columns; x++)
3651 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
3652 SetPixelInfoPixel(image,image->colormap+(ssize_t) index,q);
3653 q+=GetPixelChannels(image);
3655 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3658 image_view=DestroyCacheView(image_view);
3659 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3660 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
3661 "InvalidColormapIndex","`%s'",image->filename);
3666 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3670 % S y n c I m a g e S e t t i n g s %
3674 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3676 % SyncImageSettings() syncs any image_info global options into per-image
3679 % Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
3680 % that operations and coders can find such settings. In IMv7 if a desired
3681 % per-image artifact is not set, then it will directly look for a global
3682 % option as a fallback, as such this copy is no longer needed, only the
3685 % The format of the SyncImageSettings method is:
3687 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3688 % Image *image,ExceptionInfo *exception)
3689 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3690 % Image *image,ExceptionInfo *exception)
3692 % A description of each parameter follows:
3694 % o image_info: the image info.
3696 % o image: the image.
3698 % o exception: return any errors or warnings in this structure.
3702 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3703 Image *images,ExceptionInfo *exception)
3708 assert(image_info != (const ImageInfo *) NULL);
3709 assert(image_info->signature == MagickSignature);
3710 assert(images != (Image *) NULL);
3711 assert(images->signature == MagickSignature);
3712 if (images->debug != MagickFalse)
3713 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3715 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3716 (void) SyncImageSettings(image_info,image,exception);
3717 (void) DeleteImageOption(image_info,"page");
3721 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3722 Image *image,ExceptionInfo *exception)
3739 assert(image_info != (const ImageInfo *) NULL);
3740 assert(image_info->signature == MagickSignature);
3741 assert(image != (Image *) NULL);
3742 assert(image->signature == MagickSignature);
3743 if (image->debug != MagickFalse)
3744 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3745 option=GetImageOption(image_info,"background");
3746 if (option != (const char *) NULL)
3747 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
3749 option=GetImageOption(image_info,"black-point-compensation");
3750 if (option != (const char *) NULL)
3751 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3752 MagickBooleanOptions,MagickFalse,option);
3753 option=GetImageOption(image_info,"blue-primary");
3754 if (option != (const char *) NULL)
3756 flags=ParseGeometry(option,&geometry_info);
3757 image->chromaticity.blue_primary.x=geometry_info.rho;
3758 image->chromaticity.blue_primary.y=geometry_info.sigma;
3759 if ((flags & SigmaValue) == 0)
3760 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3762 option=GetImageOption(image_info,"bordercolor");
3763 if (option != (const char *) NULL)
3764 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
3766 option=GetImageOption(image_info,"channel");
3767 if (option != (const char *) NULL)
3768 (void) SetPixelChannelMask(image,(ChannelType)
3769 ParseChannelOption(option));
3770 /* FUTURE: do not sync compose to per-image compose setting here */
3771 option=GetImageOption(image_info,"compose");
3772 if (option != (const char *) NULL)
3773 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3774 MagickFalse,option);
3776 option=GetImageOption(image_info,"compress");
3777 if (option != (const char *) NULL)
3778 image->compression=(CompressionType) ParseCommandOption(
3779 MagickCompressOptions,MagickFalse,option);
3780 option=GetImageOption(image_info,"debug");
3781 if (option != (const char *) NULL)
3782 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3783 MagickFalse,option);
3784 option=GetImageOption(image_info,"density");
3785 if (option != (const char *) NULL)
3790 flags=ParseGeometry(option,&geometry_info);
3791 image->resolution.x=geometry_info.rho;
3792 image->resolution.y=geometry_info.sigma;
3793 if ((flags & SigmaValue) == 0)
3794 image->resolution.y=image->resolution.x;
3796 option=GetImageOption(image_info,"depth");
3797 if (option != (const char *) NULL)
3798 image->depth=StringToUnsignedLong(option);
3799 option=GetImageOption(image_info,"endian");
3800 if (option != (const char *) NULL)
3801 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3802 MagickFalse,option);
3803 option=GetImageOption(image_info,"filter");
3804 if (option != (const char *) NULL)
3805 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
3806 MagickFalse,option);
3807 option=GetImageOption(image_info,"fuzz");
3808 if (option != (const char *) NULL)
3809 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3810 option=GetImageOption(image_info,"gravity");
3811 if (option != (const char *) NULL)
3812 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3813 MagickFalse,option);
3814 option=GetImageOption(image_info,"green-primary");
3815 if (option != (const char *) NULL)
3817 flags=ParseGeometry(option,&geometry_info);
3818 image->chromaticity.green_primary.x=geometry_info.rho;
3819 image->chromaticity.green_primary.y=geometry_info.sigma;
3820 if ((flags & SigmaValue) == 0)
3821 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3823 option=GetImageOption(image_info,"intent");
3824 if (option != (const char *) NULL)
3825 image->rendering_intent=(RenderingIntent) ParseCommandOption(
3826 MagickIntentOptions,MagickFalse,option);
3827 option=GetImageOption(image_info,"intensity");
3828 if (option != (const char *) NULL)
3829 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3830 MagickPixelIntensityOptions,MagickFalse,option);
3831 option=GetImageOption(image_info,"interlace");
3832 if (option != (const char *) NULL)
3833 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3834 MagickFalse,option);
3835 option=GetImageOption(image_info,"interpolate");
3836 if (option != (const char *) NULL)
3837 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
3838 MagickInterpolateOptions,MagickFalse,option);
3839 option=GetImageOption(image_info,"loop");
3840 if (option != (const char *) NULL)
3841 image->iterations=StringToUnsignedLong(option);
3842 option=GetImageOption(image_info,"mattecolor");
3843 if (option != (const char *) NULL)
3844 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
3846 option=GetImageOption(image_info,"orient");
3847 if (option != (const char *) NULL)
3848 image->orientation=(OrientationType) ParseCommandOption(
3849 MagickOrientationOptions,MagickFalse,option);
3850 option=GetImageOption(image_info,"page");
3851 if (option != (const char *) NULL)
3856 geometry=GetPageGeometry(option);
3857 flags=ParseAbsoluteGeometry(geometry,&image->page);
3858 geometry=DestroyString(geometry);
3860 option=GetImageOption(image_info,"quality");
3861 if (option != (const char *) NULL)
3862 image->quality=StringToUnsignedLong(option);
3863 option=GetImageOption(image_info,"red-primary");
3864 if (option != (const char *) NULL)
3866 flags=ParseGeometry(option,&geometry_info);
3867 image->chromaticity.red_primary.x=geometry_info.rho;
3868 image->chromaticity.red_primary.y=geometry_info.sigma;
3869 if ((flags & SigmaValue) == 0)
3870 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3872 if (image_info->quality != UndefinedCompressionQuality)
3873 image->quality=image_info->quality;
3874 option=GetImageOption(image_info,"scene");
3875 if (option != (const char *) NULL)
3876 image->scene=StringToUnsignedLong(option);
3877 option=GetImageOption(image_info,"taint");
3878 if (option != (const char *) NULL)
3879 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3880 MagickFalse,option);
3881 option=GetImageOption(image_info,"tile-offset");
3882 if (option != (const char *) NULL)
3887 geometry=GetPageGeometry(option);
3888 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3889 geometry=DestroyString(geometry);
3891 option=GetImageOption(image_info,"transparent-color");
3892 if (option != (const char *) NULL)
3893 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
3895 option=GetImageOption(image_info,"type");
3896 if (option != (const char *) NULL)
3897 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3899 option=GetImageOption(image_info,"units");
3900 units=image_info->units;
3901 if (option != (const char *) NULL)
3902 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
3903 MagickFalse,option);
3904 if (units != UndefinedResolution)
3906 if (image->units != units)
3907 switch (image->units)
3909 case PixelsPerInchResolution:
3911 if (units == PixelsPerCentimeterResolution)
3913 image->resolution.x/=2.54;
3914 image->resolution.y/=2.54;
3918 case PixelsPerCentimeterResolution:
3920 if (units == PixelsPerInchResolution)
3922 image->resolution.x=(double) ((size_t) (100.0*2.54*
3923 image->resolution.x+0.5))/100.0;
3924 image->resolution.y=(double) ((size_t) (100.0*2.54*
3925 image->resolution.y+0.5))/100.0;
3934 option=GetImageOption(image_info,"virtual-pixel");
3935 if (option != (const char *) NULL)
3936 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
3937 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
3939 option=GetImageOption(image_info,"white-point");
3940 if (option != (const char *) NULL)
3942 flags=ParseGeometry(option,&geometry_info);
3943 image->chromaticity.white_point.x=geometry_info.rho;
3944 image->chromaticity.white_point.y=geometry_info.sigma;
3945 if ((flags & SigmaValue) == 0)
3946 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
3948 ResetImageOptionIterator(image_info);
3951 /* IMv6: Copy freeform global options into per-image artifacts, so
3952 * various operations and coders can access them.
3954 * This has a problem, as per-image artefacts may have been set in
3955 * parenthesis, but may not be unset when parenthesis ends.
3958 property[MaxTextExtent];
3963 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
3965 value=GetImageOption(image_info,option);
3966 if (value != (const char *) NULL)
3968 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
3969 (void) SetImageArtifact(image,property,value);
3971 option=GetNextImageOption(image_info);
3975 /* IMv7: pointer to allow the lookup of pre-image artefact will fallback to
3976 a global option setting/define. This saves a lot of duplication of
3977 global options into per-image artifacts, while ensuring only specifically
3978 set per-image artifacts are preverved when parenthesis ends.
3980 This pointer is never explictally freed, as it is only used as a back
3981 reference, not as the main pointer to the image_info structure. Images
3982 being removed from a image_info image list (or yet to be added to such),
3983 should have this pointer reset to NULL.
3985 image->image_info=image_info;