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-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/animate.h"
45 #include "MagickCore/artifact.h"
46 #include "MagickCore/attribute.h"
47 #include "MagickCore/blob.h"
48 #include "MagickCore/blob-private.h"
49 #include "MagickCore/cache.h"
50 #include "MagickCore/cache-private.h"
51 #include "MagickCore/cache-view.h"
52 #include "MagickCore/client.h"
53 #include "MagickCore/color.h"
54 #include "MagickCore/color-private.h"
55 #include "MagickCore/colormap.h"
56 #include "MagickCore/colorspace.h"
57 #include "MagickCore/colorspace-private.h"
58 #include "MagickCore/composite.h"
59 #include "MagickCore/composite-private.h"
60 #include "MagickCore/compress.h"
61 #include "MagickCore/constitute.h"
62 #include "MagickCore/display.h"
63 #include "MagickCore/draw.h"
64 #include "MagickCore/enhance.h"
65 #include "MagickCore/exception.h"
66 #include "MagickCore/exception-private.h"
67 #include "MagickCore/gem.h"
68 #include "MagickCore/geometry.h"
69 #include "MagickCore/histogram.h"
70 #include "MagickCore/image-private.h"
71 #include "MagickCore/list.h"
72 #include "MagickCore/magic.h"
73 #include "MagickCore/magick.h"
74 #include "MagickCore/magick-private.h"
75 #include "MagickCore/memory_.h"
76 #include "MagickCore/module.h"
77 #include "MagickCore/monitor.h"
78 #include "MagickCore/monitor-private.h"
79 #include "MagickCore/option.h"
80 #include "MagickCore/paint.h"
81 #include "MagickCore/pixel-accessor.h"
82 #include "MagickCore/profile.h"
83 #include "MagickCore/property.h"
84 #include "MagickCore/quantize.h"
85 #include "MagickCore/random_.h"
86 #include "MagickCore/segment.h"
87 #include "MagickCore/semaphore.h"
88 #include "MagickCore/signature-private.h"
89 #include "MagickCore/statistic.h"
90 #include "MagickCore/string_.h"
91 #include "MagickCore/string-private.h"
92 #include "MagickCore/thread-private.h"
93 #include "MagickCore/threshold.h"
94 #include "MagickCore/timer.h"
95 #include "MagickCore/utility.h"
96 #include "MagickCore/utility-private.h"
97 #include "MagickCore/version.h"
98 #include "MagickCore/xwindow-private.h"
101 Constant declaration.
104 BackgroundColor[] = "#ffffff", /* white */
105 BorderColor[] = "#dfdfdf", /* gray */
106 DefaultTileFrame[] = "15x15+3+3",
107 DefaultTileGeometry[] = "120x120+4+3>",
108 DefaultTileLabel[] = "%f\n%G\n%b",
109 ForegroundColor[] = "#000", /* black */
110 LoadImageTag[] = "Load/Image",
111 LoadImagesTag[] = "Load/Images",
112 MatteColor[] = "#bdbdbd", /* gray */
113 PSDensityGeometry[] = "72.0x72.0",
114 PSPageGeometry[] = "612x792",
115 SaveImageTag[] = "Save/Image",
116 SaveImagesTag[] = "Save/Images",
117 TransparentColor[] = "#00000000"; /* transparent black */
120 DefaultResolution = 72.0;
123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 % A c q u i r e I m a g e %
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 % AcquireImage() returns a pointer to an image structure initialized to
136 % The format of the AcquireImage method is:
138 % Image *AcquireImage(const ImageInfo *image_info)
140 % A description of each parameter follows:
142 % o image_info: Many of the image default values are set from this
143 % structure. For example, filename, compression, depth, background color,
147 MagickExport Image *AcquireImage(const ImageInfo *image_info)
159 Allocate image structure.
161 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
162 image=(Image *) AcquireMagickMemory(sizeof(*image));
163 if (image == (Image *) NULL)
164 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
165 (void) ResetMagickMemory(image,0,sizeof(*image));
167 Initialize Image structure.
169 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
170 image->storage_class=DirectClass;
171 image->depth=MAGICKCORE_QUANTUM_DEPTH;
172 image->colorspace=RGBColorspace;
173 image->interlace=NoInterlace;
174 image->ticks_per_second=UndefinedTicksPerSecond;
175 image->compose=OverCompositeOp;
177 GetExceptionInfo(&image->exception);
178 (void) QueryColorDatabase(BackgroundColor,&image->background_color,
180 (void) QueryColorDatabase(BorderColor,&image->border_color,&image->exception);
181 (void) QueryColorDatabase(MatteColor,&image->matte_color,&image->exception);
182 (void) QueryColorDatabase(TransparentColor,&image->transparent_color,
184 image->x_resolution=DefaultResolution;
185 image->y_resolution=DefaultResolution;
186 image->units=PixelsPerInchResolution;
187 GetTimerInfo(&image->timer);
188 image->ping=MagickFalse;
189 image->cache=AcquirePixelCache(0);
190 image->channel_mask=DefaultChannels;
191 image->channel_map=AcquirePixelChannelMap();
192 image->blob=CloneBlobInfo((BlobInfo *) NULL);
193 image->debug=IsEventLogging();
194 image->reference_count=1;
195 image->semaphore=AllocateSemaphoreInfo();
196 image->signature=MagickSignature;
197 if (image_info == (ImageInfo *) NULL)
202 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
204 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
205 (void) CopyMagickString(image->magick_filename,image_info->filename,
207 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
208 if (image_info->size != (char *) NULL)
210 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
211 image->columns=image->extract_info.width;
212 image->rows=image->extract_info.height;
213 image->offset=image->extract_info.x;
214 image->extract_info.x=0;
215 image->extract_info.y=0;
217 if (image_info->extract != (char *) NULL)
222 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
223 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
225 image->extract_info=geometry;
226 Swap(image->columns,image->extract_info.width);
227 Swap(image->rows,image->extract_info.height);
230 image->compression=image_info->compression;
231 image->quality=image_info->quality;
232 image->endian=image_info->endian;
233 image->interlace=image_info->interlace;
234 image->units=image_info->units;
235 if (image_info->density != (char *) NULL)
240 flags=ParseGeometry(image_info->density,&geometry_info);
241 image->x_resolution=geometry_info.rho;
242 image->y_resolution=geometry_info.sigma;
243 if ((flags & SigmaValue) == 0)
244 image->y_resolution=image->x_resolution;
246 if (image_info->page != (char *) NULL)
251 image->page=image->extract_info;
252 geometry=GetPageGeometry(image_info->page);
253 (void) ParseAbsoluteGeometry(geometry,&image->page);
254 geometry=DestroyString(geometry);
256 if (image_info->depth != 0)
257 image->depth=image_info->depth;
258 image->dither=image_info->dither;
259 image->background_color=image_info->background_color;
260 image->border_color=image_info->border_color;
261 image->matte_color=image_info->matte_color;
262 image->transparent_color=image_info->transparent_color;
263 image->ping=image_info->ping;
264 image->progress_monitor=image_info->progress_monitor;
265 image->client_data=image_info->client_data;
266 if (image_info->cache != (void *) NULL)
267 ClonePixelCacheMethods(image->cache,image_info->cache);
268 (void) SetImageVirtualPixelMethod(image,image_info->virtual_pixel_method);
269 (void) SyncImageSettings(image_info,image);
270 option=GetImageOption(image_info,"delay");
271 if (option != (const char *) NULL)
276 flags=ParseGeometry(option,&geometry_info);
277 if ((flags & GreaterValue) != 0)
279 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
280 image->delay=(size_t) floor(geometry_info.rho+0.5);
283 if ((flags & LessValue) != 0)
285 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
286 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
289 image->delay=(size_t) floor(geometry_info.rho+0.5);
290 if ((flags & SigmaValue) != 0)
291 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
293 option=GetImageOption(image_info,"dispose");
294 if (option != (const char *) NULL)
295 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305 % A c q u i r e I m a g e I n f o %
309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311 % AcquireImageInfo() allocates the ImageInfo structure.
313 % The format of the AcquireImageInfo method is:
315 % ImageInfo *AcquireImageInfo(void)
318 MagickExport ImageInfo *AcquireImageInfo(void)
323 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
324 if (image_info == (ImageInfo *) NULL)
325 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
326 GetImageInfo(image_info);
331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335 % A c q u i r e N e x t I m a g e %
339 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341 % AcquireNextImage() initializes the next image in a sequence to
342 % default values. The next member of image points to the newly allocated
343 % image. If there is a memory shortage, next is assigned NULL.
345 % The format of the AcquireNextImage method is:
347 % void AcquireNextImage(const ImageInfo *image_info,Image *image)
349 % A description of each parameter follows:
351 % o image_info: Many of the image default values are set from this
352 % structure. For example, filename, compression, depth, background color,
355 % o image: the image.
358 MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image)
361 Allocate image structure.
363 assert(image != (Image *) NULL);
364 assert(image->signature == MagickSignature);
365 if (image->debug != MagickFalse)
366 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
367 image->next=AcquireImage(image_info);
368 if (GetNextImageInList(image) == (Image *) NULL)
370 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
372 if (image_info != (ImageInfo *) NULL)
373 (void) CopyMagickString(GetNextImageInList(image)->filename,
374 image_info->filename,MaxTextExtent);
375 DestroyBlob(GetNextImageInList(image));
376 image->next->blob=ReferenceBlob(image->blob);
377 image->next->endian=image->endian;
378 image->next->scene=image->scene+1;
379 image->next->previous=image;
383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387 % A p p e n d I m a g e s %
391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
393 % AppendImages() takes all images from the current image pointer to the end
394 % of the image list and appends them to each other top-to-bottom if the
395 % stack parameter is true, otherwise left-to-right.
397 % The current gravity setting now effects how the image is justified in the
400 % The format of the AppendImages method is:
402 % Image *AppendImages(const Image *images,const MagickBooleanType stack,
403 % ExceptionInfo *exception)
405 % A description of each parameter follows:
407 % o images: the image sequence.
409 % o stack: A value other than 0 stacks the images top-to-bottom.
411 % o exception: return any errors or warnings in this structure.
414 MagickExport Image *AppendImages(const Image *images,
415 const MagickBooleanType stack,ExceptionInfo *exception)
417 #define AppendImageTag "Append/Image"
454 Compute maximum area of appended area.
456 assert(images != (Image *) NULL);
457 assert(images->signature == MagickSignature);
458 if (images->debug != MagickFalse)
459 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
460 assert(exception != (ExceptionInfo *) NULL);
461 assert(exception->signature == MagickSignature);
465 width=image->columns;
467 next=GetNextImageInList(image);
468 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
470 if (next->matte != MagickFalse)
473 if (stack != MagickFalse)
475 if (next->columns > width)
480 width+=next->columns;
481 if (next->rows > height)
487 append_image=CloneImage(image,width,height,MagickTrue,exception);
488 if (append_image == (Image *) NULL)
489 return((Image *) NULL);
490 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
492 append_image=DestroyImage(append_image);
493 return((Image *) NULL);
495 append_image->matte=matte;
496 (void) SetImageBackgroundColor(append_image);
500 append_view=AcquireCacheView(append_image);
501 for (n=0; n < (MagickOffsetType) number_images; n++)
503 SetGeometry(append_image,&geometry);
504 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
505 if (stack != MagickFalse)
506 x_offset-=geometry.x;
508 y_offset-=geometry.y;
509 image_view=AcquireCacheView(image);
510 #if defined(MAGICKCORE_OPENMP_SUPPORT)
511 #pragma omp parallel for schedule(dynamic,4) shared(status) omp_throttle(1)
513 for (y=0; y < (ssize_t) image->rows; y++)
518 register const Quantum
527 if (status == MagickFalse)
529 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
530 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
531 image->columns,1,exception);
532 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
537 for (x=0; x < (ssize_t) image->columns; x++)
539 SetPixelRed(append_image,GetPixelRed(image,p),q);
540 SetPixelGreen(append_image,GetPixelGreen(image,p),q);
541 SetPixelBlue(append_image,GetPixelBlue(image,p),q);
542 if ((image->colorspace == CMYKColorspace) &&
543 (append_image->colorspace == CMYKColorspace))
544 SetPixelBlack(append_image,GetPixelBlack(image,p),q);
545 SetPixelAlpha(append_image,OpaqueAlpha,q);
546 if (image->matte != MagickFalse)
547 SetPixelAlpha(append_image,GetPixelAlpha(image,p),q);
548 p+=GetPixelChannels(image);
549 q+=GetPixelChannels(append_image);
551 sync=SyncCacheViewAuthenticPixels(append_view,exception);
552 if (sync == MagickFalse)
555 image_view=DestroyCacheView(image_view);
556 proceed=SetImageProgress(image,AppendImageTag,n,number_images);
557 if (proceed == MagickFalse)
559 if (stack == MagickFalse)
561 x_offset+=(ssize_t) image->columns;
567 y_offset+=(ssize_t) image->rows;
569 image=GetNextImageInList(image);
571 append_view=DestroyCacheView(append_view);
572 if (status == MagickFalse)
573 append_image=DestroyImage(append_image);
574 return(append_image);
578 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
582 % C a t c h I m a g e E x c e p t i o n %
586 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
588 % CatchImageException() returns if no exceptions are found in the image
589 % sequence, otherwise it determines the most severe exception and reports
590 % it as a warning or error depending on the severity.
592 % The format of the CatchImageException method is:
594 % ExceptionType CatchImageException(Image *image)
596 % A description of each parameter follows:
598 % o image: An image sequence.
601 MagickExport ExceptionType CatchImageException(Image *image)
609 assert(image != (const Image *) NULL);
610 assert(image->signature == MagickSignature);
611 if (image->debug != MagickFalse)
612 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
613 exception=AcquireExceptionInfo();
614 GetImageException(image,exception);
615 CatchException(exception);
616 severity=exception->severity;
617 exception=DestroyExceptionInfo(exception);
622 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
626 % C l i p I m a g e P a t h %
630 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
632 % ClipImagePath() sets the image clip mask based any clipping path information
635 % The format of the ClipImagePath method is:
637 % MagickBooleanType ClipImagePath(Image *image,const char *pathname,
638 % const MagickBooleanType inside,ExceptionInfo *exception)
640 % A description of each parameter follows:
642 % o image: the image.
644 % o pathname: name of clipping path resource. If name is preceded by #, use
645 % clipping path numbered by name.
647 % o inside: if non-zero, later operations take effect inside clipping path.
648 % Otherwise later operations take effect outside clipping path.
650 % o exception: return any errors or warnings in this structure.
654 MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
656 return(ClipImagePath(image,"#1",MagickTrue,exception));
659 MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
660 const MagickBooleanType inside,ExceptionInfo *exception)
662 #define ClipImagePathTag "ClipPath/Image"
676 assert(image != (const Image *) NULL);
677 assert(image->signature == MagickSignature);
678 if (image->debug != MagickFalse)
679 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
680 assert(pathname != NULL);
681 property=AcquireString(pathname);
682 (void) FormatLocaleString(property,MaxTextExtent,"8BIM:1999,2998:%s",
684 value=GetImageProperty(image,property);
685 property=DestroyString(property);
686 if (value == (const char *) NULL)
688 ThrowFileException(&image->exception,OptionError,"NoClipPathDefined",
692 image_info=AcquireImageInfo();
693 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
694 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
695 clip_mask=BlobToImage(image_info,value,strlen(value),&image->exception);
696 image_info=DestroyImageInfo(image_info);
697 if (clip_mask == (Image *) NULL)
699 if (clip_mask->storage_class == PseudoClass)
701 (void) SyncImage(clip_mask);
702 if (SetImageStorageClass(clip_mask,DirectClass,&image->exception) == MagickFalse)
705 if (inside == MagickFalse)
706 (void) NegateImage(clip_mask,MagickFalse,&image->exception);
707 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
708 "8BIM:1999,2998:%s\nPS",pathname);
709 (void) SetImageClipMask(image,clip_mask,exception);
710 clip_mask=DestroyImage(clip_mask);
715 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
719 % C l o n e I m a g e %
723 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
725 % CloneImage() copies an image and returns the copy as a new image object.
727 % If the specified columns and rows is 0, an exact copy of the image is
728 % returned, otherwise the pixel data is undefined and must be initialized
729 % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
730 % failure, a NULL image is returned and exception describes the reason for the
733 % The format of the CloneImage method is:
735 % Image *CloneImage(const Image *image,const size_t columns,
736 % const size_t rows,const MagickBooleanType orphan,
737 % ExceptionInfo *exception)
739 % A description of each parameter follows:
741 % o image: the image.
743 % o columns: the number of columns in the cloned image.
745 % o rows: the number of rows in the cloned image.
747 % o detach: With a value other than 0, the cloned image is detached from
748 % its parent I/O stream.
750 % o exception: return any errors or warnings in this structure.
753 MagickExport Image *CloneImage(const Image *image,const size_t columns,
754 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
768 assert(image != (const Image *) NULL);
769 assert(image->signature == MagickSignature);
770 if (image->debug != MagickFalse)
771 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
772 assert(exception != (ExceptionInfo *) NULL);
773 assert(exception->signature == MagickSignature);
774 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
775 if (clone_image == (Image *) NULL)
776 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
777 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
778 clone_image->signature=MagickSignature;
779 clone_image->storage_class=image->storage_class;
780 clone_image->number_channels=image->number_channels;
781 clone_image->number_meta_channels=image->number_meta_channels;
782 clone_image->metacontent_extent=image->metacontent_extent;
783 clone_image->colorspace=image->colorspace;
784 clone_image->matte=image->matte;
785 clone_image->columns=image->columns;
786 clone_image->rows=image->rows;
787 clone_image->dither=image->dither;
788 if (image->colormap != (PixelPacket *) NULL)
791 Allocate and copy the image colormap.
793 clone_image->colors=image->colors;
794 length=(size_t) image->colors;
795 clone_image->colormap=(PixelPacket *) AcquireQuantumMemory(length,
796 sizeof(*clone_image->colormap));
797 if (clone_image->colormap == (PixelPacket *) NULL)
798 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
799 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
800 sizeof(*clone_image->colormap));
802 (void) CloneImageProfiles(clone_image,image);
803 (void) CloneImageProperties(clone_image,image);
804 (void) CloneImageArtifacts(clone_image,image);
805 GetTimerInfo(&clone_image->timer);
806 GetExceptionInfo(&clone_image->exception);
807 InheritException(&clone_image->exception,&image->exception);
808 if (image->ascii85 != (void *) NULL)
809 Ascii85Initialize(clone_image);
810 clone_image->magick_columns=image->magick_columns;
811 clone_image->magick_rows=image->magick_rows;
812 clone_image->type=image->type;
813 clone_image->sync=image->sync;
814 clone_image->channel_mask=image->channel_mask;
815 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
816 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
818 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
819 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
820 clone_image->progress_monitor=image->progress_monitor;
821 clone_image->client_data=image->client_data;
822 clone_image->reference_count=1;
823 clone_image->next=image->next;
824 clone_image->previous=image->previous;
825 clone_image->list=NewImageList();
826 clone_image->clip_mask=NewImageList();
827 clone_image->mask=NewImageList();
828 if (detach == MagickFalse)
829 clone_image->blob=ReferenceBlob(image->blob);
832 clone_image->next=NewImageList();
833 clone_image->previous=NewImageList();
834 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
836 clone_image->ping=image->ping;
837 clone_image->debug=IsEventLogging();
838 clone_image->semaphore=AllocateSemaphoreInfo();
839 if ((columns == 0) && (rows == 0))
841 if (image->montage != (char *) NULL)
842 (void) CloneString(&clone_image->montage,image->montage);
843 if (image->directory != (char *) NULL)
844 (void) CloneString(&clone_image->directory,image->directory);
845 if (image->clip_mask != (Image *) NULL)
846 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
848 if (image->mask != (Image *) NULL)
849 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
850 clone_image->cache=ReferencePixelCache(image->cache);
853 if ((columns == image->columns) && (rows == image->rows))
855 if (image->clip_mask != (Image *) NULL)
856 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
858 if (image->mask != (Image *) NULL)
859 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
861 scale=(MagickRealType) columns/(MagickRealType) image->columns;
862 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
863 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
864 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
865 scale=(MagickRealType) rows/(MagickRealType) image->rows;
866 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
867 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
868 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
869 clone_image->columns=columns;
870 clone_image->rows=rows;
871 clone_image->cache=ClonePixelCache(image->cache);
876 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
880 % C l o n e I m a g e I n f o %
884 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
886 % CloneImageInfo() makes a copy of the given image info structure. If
887 % NULL is specified, a new image info structure is created initialized to
890 % The format of the CloneImageInfo method is:
892 % ImageInfo *CloneImageInfo(const ImageInfo *image_info)
894 % A description of each parameter follows:
896 % o image_info: the image info.
899 MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
904 clone_info=AcquireImageInfo();
905 if (image_info == (ImageInfo *) NULL)
907 clone_info->compression=image_info->compression;
908 clone_info->temporary=image_info->temporary;
909 clone_info->adjoin=image_info->adjoin;
910 clone_info->antialias=image_info->antialias;
911 clone_info->scene=image_info->scene;
912 clone_info->number_scenes=image_info->number_scenes;
913 clone_info->depth=image_info->depth;
914 if (image_info->size != (char *) NULL)
915 (void) CloneString(&clone_info->size,image_info->size);
916 if (image_info->extract != (char *) NULL)
917 (void) CloneString(&clone_info->extract,image_info->extract);
918 if (image_info->scenes != (char *) NULL)
919 (void) CloneString(&clone_info->scenes,image_info->scenes);
920 if (image_info->page != (char *) NULL)
921 (void) CloneString(&clone_info->page,image_info->page);
922 clone_info->interlace=image_info->interlace;
923 clone_info->endian=image_info->endian;
924 clone_info->units=image_info->units;
925 clone_info->quality=image_info->quality;
926 if (image_info->sampling_factor != (char *) NULL)
927 (void) CloneString(&clone_info->sampling_factor,
928 image_info->sampling_factor);
929 if (image_info->server_name != (char *) NULL)
930 (void) CloneString(&clone_info->server_name,image_info->server_name);
931 if (image_info->font != (char *) NULL)
932 (void) CloneString(&clone_info->font,image_info->font);
933 if (image_info->texture != (char *) NULL)
934 (void) CloneString(&clone_info->texture,image_info->texture);
935 if (image_info->density != (char *) NULL)
936 (void) CloneString(&clone_info->density,image_info->density);
937 clone_info->pointsize=image_info->pointsize;
938 clone_info->fuzz=image_info->fuzz;
939 clone_info->background_color=image_info->background_color;
940 clone_info->border_color=image_info->border_color;
941 clone_info->matte_color=image_info->matte_color;
942 clone_info->transparent_color=image_info->transparent_color;
943 clone_info->dither=image_info->dither;
944 clone_info->monochrome=image_info->monochrome;
945 clone_info->colors=image_info->colors;
946 clone_info->colorspace=image_info->colorspace;
947 clone_info->type=image_info->type;
948 clone_info->orientation=image_info->orientation;
949 clone_info->preview_type=image_info->preview_type;
950 clone_info->group=image_info->group;
951 clone_info->ping=image_info->ping;
952 clone_info->verbose=image_info->verbose;
953 if (image_info->view != (char *) NULL)
954 (void) CloneString(&clone_info->view,image_info->view);
955 if (image_info->authenticate != (char *) NULL)
956 (void) CloneString(&clone_info->authenticate,image_info->authenticate);
957 (void) CloneImageOptions(clone_info,image_info);
958 clone_info->progress_monitor=image_info->progress_monitor;
959 clone_info->client_data=image_info->client_data;
960 clone_info->cache=image_info->cache;
961 if (image_info->cache != (void *) NULL)
962 clone_info->cache=ReferencePixelCache(image_info->cache);
963 if (image_info->profile != (void *) NULL)
964 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
965 image_info->profile);
966 SetImageInfoFile(clone_info,image_info->file);
967 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
968 clone_info->stream=image_info->stream;
969 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
970 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
971 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
972 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
973 (void) CopyMagickString(clone_info->filename,image_info->filename,
975 clone_info->channel=image_info->channel;
976 clone_info->debug=IsEventLogging();
977 clone_info->signature=image_info->signature;
982 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
986 % C o m b i n e I m a g e s %
990 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
992 % CombineImages() combines one or more images into a single image. The
993 % grayscale value of the pixels of each image in the sequence is assigned in
994 % order to the specified channels of the combined image. The typical
995 % ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
997 % The format of the CombineImages method is:
999 % Image *CombineImages(const Image *image,ExceptionInfo *exception)
1001 % A description of each parameter follows:
1003 % o image: the image.
1005 % o exception: return any errors or warnings in this structure.
1008 MagickExport Image *CombineImages(const Image *image,ExceptionInfo *exception)
1010 #define CombineImageTag "Combine/Image"
1031 Ensure the image are the same size.
1033 assert(image != (const Image *) NULL);
1034 assert(image->signature == MagickSignature);
1035 if (image->debug != MagickFalse)
1036 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1037 assert(exception != (ExceptionInfo *) NULL);
1038 assert(exception->signature == MagickSignature);
1039 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1041 if ((next->columns != image->columns) || (next->rows != image->rows))
1042 ThrowImageException(OptionError,"ImagesAreNotTheSameSize");
1044 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1045 if (combine_image == (Image *) NULL)
1046 return((Image *) NULL);
1047 if (SetImageStorageClass(combine_image,DirectClass,exception) == MagickFalse)
1049 combine_image=DestroyImage(combine_image);
1050 return((Image *) NULL);
1052 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
1053 combine_image->matte=MagickTrue;
1054 (void) SetImageBackgroundColor(combine_image);
1060 combine_view=AcquireCacheView(combine_image);
1061 for (y=0; y < (ssize_t) combine_image->rows; y++)
1072 register const Quantum
1081 if (status == MagickFalse)
1083 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1085 if (pixels == (Quantum *) NULL)
1091 if (((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) &&
1092 (next != (Image *) NULL))
1094 image_view=AcquireCacheView(next);
1095 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1096 if (p == (const Quantum *) NULL)
1099 for (x=0; x < (ssize_t) combine_image->columns; x++)
1101 SetPixelRed(image,GetPixelIntensity(image,p),q);
1102 p+=GetPixelChannels(image);
1103 q+=GetPixelChannels(combine_image);
1105 image_view=DestroyCacheView(image_view);
1106 next=GetNextImageInList(next);
1108 if (((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) &&
1109 (next != (Image *) NULL))
1111 image_view=AcquireCacheView(next);
1112 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1113 if (p == (const Quantum *) NULL)
1116 for (x=0; x < (ssize_t) combine_image->columns; x++)
1118 SetPixelGreen(image,GetPixelIntensity(image,p),q);
1119 p+=GetPixelChannels(image);
1120 q+=GetPixelChannels(combine_image);
1122 image_view=DestroyCacheView(image_view);
1123 next=GetNextImageInList(next);
1125 if (((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) &&
1126 (next != (Image *) NULL))
1128 image_view=AcquireCacheView(next);
1129 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1130 if (p == (const Quantum *) NULL)
1133 for (x=0; x < (ssize_t) combine_image->columns; x++)
1135 SetPixelBlue(image,GetPixelIntensity(image,p),q);
1136 p+=GetPixelChannels(image);
1137 q+=GetPixelChannels(combine_image);
1139 image_view=DestroyCacheView(image_view);
1140 next=GetNextImageInList(next);
1142 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
1143 (image->colorspace == CMYKColorspace) && (next != (Image *) NULL))
1145 image_view=AcquireCacheView(next);
1146 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1147 if (p == (const Quantum *) NULL)
1150 for (x=0; x < (ssize_t) combine_image->columns; x++)
1152 SetPixelBlack(image,GetPixelIntensity(image,p),q);
1153 p+=GetPixelChannels(image);
1154 q+=GetPixelChannels(combine_image);
1156 image_view=DestroyCacheView(image_view);
1157 next=GetNextImageInList(next);
1159 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
1160 (next != (Image *) NULL))
1162 image_view=AcquireCacheView(next);
1163 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1164 if (p == (const Quantum *) NULL)
1167 for (x=0; x < (ssize_t) combine_image->columns; x++)
1169 SetPixelAlpha(image,GetPixelIntensity(image,p),q);
1170 p+=GetPixelChannels(image);
1171 q+=GetPixelChannels(combine_image);
1173 image_view=DestroyCacheView(image_view);
1174 next=GetNextImageInList(next);
1176 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1178 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1183 proceed=SetImageProgress(image,CombineImageTag,progress++,
1184 combine_image->rows);
1185 if (proceed == MagickFalse)
1189 combine_view=DestroyCacheView(combine_view);
1190 if (status == MagickFalse)
1191 combine_image=DestroyImage(combine_image);
1192 return(combine_image);
1196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1200 % D e s t r o y I m a g e %
1204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1206 % DestroyImage() dereferences an image, deallocating memory associated with
1207 % the image if the reference count becomes zero.
1209 % The format of the DestroyImage method is:
1211 % Image *DestroyImage(Image *image)
1213 % A description of each parameter follows:
1215 % o image: the image.
1218 MagickExport Image *DestroyImage(Image *image)
1226 assert(image != (Image *) NULL);
1227 assert(image->signature == MagickSignature);
1228 if (image->debug != MagickFalse)
1229 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1230 destroy=MagickFalse;
1231 LockSemaphoreInfo(image->semaphore);
1232 image->reference_count--;
1233 if (image->reference_count == 0)
1235 UnlockSemaphoreInfo(image->semaphore);
1236 if (destroy == MagickFalse)
1237 return((Image *) NULL);
1241 DestroyImagePixels(image);
1242 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1243 if (image->clip_mask != (Image *) NULL)
1244 image->clip_mask=DestroyImage(image->clip_mask);
1245 if (image->mask != (Image *) NULL)
1246 image->mask=DestroyImage(image->mask);
1247 if (image->montage != (char *) NULL)
1248 image->montage=DestroyString(image->montage);
1249 if (image->directory != (char *) NULL)
1250 image->directory=DestroyString(image->directory);
1251 if (image->colormap != (PixelPacket *) NULL)
1252 image->colormap=(PixelPacket *) RelinquishMagickMemory(image->colormap);
1253 if (image->geometry != (char *) NULL)
1254 image->geometry=DestroyString(image->geometry);
1255 DestroyImageProfiles(image);
1256 DestroyImageProperties(image);
1257 DestroyImageArtifacts(image);
1258 if (image->ascii85 != (Ascii85Info*) NULL)
1259 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1261 (void) DestroyExceptionInfo(&image->exception);
1262 if (image->semaphore != (SemaphoreInfo *) NULL)
1263 DestroySemaphoreInfo(&image->semaphore);
1264 image->signature=(~MagickSignature);
1265 image=(Image *) RelinquishMagickMemory(image);
1270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1274 % D e s t r o y I m a g e I n f o %
1278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1280 % DestroyImageInfo() deallocates memory associated with an ImageInfo
1283 % The format of the DestroyImageInfo method is:
1285 % ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1287 % A description of each parameter follows:
1289 % o image_info: the image info.
1292 MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1294 assert(image_info != (ImageInfo *) NULL);
1295 assert(image_info->signature == MagickSignature);
1296 if (image_info->debug != MagickFalse)
1297 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1298 image_info->filename);
1299 if (image_info->size != (char *) NULL)
1300 image_info->size=DestroyString(image_info->size);
1301 if (image_info->extract != (char *) NULL)
1302 image_info->extract=DestroyString(image_info->extract);
1303 if (image_info->scenes != (char *) NULL)
1304 image_info->scenes=DestroyString(image_info->scenes);
1305 if (image_info->page != (char *) NULL)
1306 image_info->page=DestroyString(image_info->page);
1307 if (image_info->sampling_factor != (char *) NULL)
1308 image_info->sampling_factor=DestroyString(
1309 image_info->sampling_factor);
1310 if (image_info->server_name != (char *) NULL)
1311 image_info->server_name=DestroyString(
1312 image_info->server_name);
1313 if (image_info->font != (char *) NULL)
1314 image_info->font=DestroyString(image_info->font);
1315 if (image_info->texture != (char *) NULL)
1316 image_info->texture=DestroyString(image_info->texture);
1317 if (image_info->density != (char *) NULL)
1318 image_info->density=DestroyString(image_info->density);
1319 if (image_info->view != (char *) NULL)
1320 image_info->view=DestroyString(image_info->view);
1321 if (image_info->authenticate != (char *) NULL)
1322 image_info->authenticate=DestroyString(
1323 image_info->authenticate);
1324 DestroyImageOptions(image_info);
1325 if (image_info->cache != (void *) NULL)
1326 image_info->cache=DestroyPixelCache(image_info->cache);
1327 if (image_info->profile != (StringInfo *) NULL)
1328 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1329 image_info->profile);
1330 image_info->signature=(~MagickSignature);
1331 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1340 + D i s a s s o c i a t e I m a g e S t r e a m %
1344 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1346 % DisassociateImageStream() disassociates the image stream.
1348 % The format of the DisassociateImageStream method is:
1350 % MagickBooleanType DisassociateImageStream(const Image *image)
1352 % A description of each parameter follows:
1354 % o image: the image.
1357 MagickExport void DisassociateImageStream(Image *image)
1359 assert(image != (const Image *) NULL);
1360 assert(image->signature == MagickSignature);
1361 if (image->debug != MagickFalse)
1362 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1363 (void) DetachBlob(image->blob);
1367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1371 % G e t I m a g e A l p h a C h a n n e l %
1375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1377 % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1378 % not activated. That is, the image is RGB rather than RGBA or CMYK rather
1381 % The format of the GetImageAlphaChannel method is:
1383 % MagickBooleanType GetImageAlphaChannel(const Image *image)
1385 % A description of each parameter follows:
1387 % o image: the image.
1390 MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1392 assert(image != (const Image *) NULL);
1393 if (image->debug != MagickFalse)
1394 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1395 assert(image->signature == MagickSignature);
1396 return(image->matte);
1400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1404 % G e t I m a g e C l i p M a s k %
1408 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1410 % GetImageClipMask() returns the clip path associated with the image.
1412 % The format of the GetImageClipMask method is:
1414 % Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1416 % A description of each parameter follows:
1418 % o image: the image.
1421 MagickExport Image *GetImageClipMask(const Image *image,
1422 ExceptionInfo *exception)
1424 assert(image != (const Image *) NULL);
1425 if (image->debug != MagickFalse)
1426 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1427 assert(image->signature == MagickSignature);
1428 if (image->clip_mask == (Image *) NULL)
1429 return((Image *) NULL);
1430 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1434 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1438 % G e t I m a g e E x c e p t i o n %
1442 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1444 % GetImageException() traverses an image sequence and returns any
1445 % error more severe than noted by the exception parameter.
1447 % The format of the GetImageException method is:
1449 % void GetImageException(Image *image,ExceptionInfo *exception)
1451 % A description of each parameter follows:
1453 % o image: Specifies a pointer to a list of one or more images.
1455 % o exception: return the highest severity exception.
1458 MagickExport void GetImageException(Image *image,ExceptionInfo *exception)
1463 assert(image != (Image *) NULL);
1464 assert(image->signature == MagickSignature);
1465 if (image->debug != MagickFalse)
1466 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1467 assert(exception != (ExceptionInfo *) NULL);
1468 assert(exception->signature == MagickSignature);
1469 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1471 if (next->exception.severity == UndefinedException)
1473 if (next->exception.severity > exception->severity)
1474 InheritException(exception,&next->exception);
1475 next->exception.severity=UndefinedException;
1480 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1484 % G e t I m a g e I n f o %
1488 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1490 % GetImageInfo() initializes image_info to default values.
1492 % The format of the GetImageInfo method is:
1494 % void GetImageInfo(ImageInfo *image_info)
1496 % A description of each parameter follows:
1498 % o image_info: the image info.
1501 MagickExport void GetImageInfo(ImageInfo *image_info)
1510 File and image dimension members.
1512 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1513 assert(image_info != (ImageInfo *) NULL);
1514 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1515 image_info->adjoin=MagickTrue;
1516 image_info->interlace=NoInterlace;
1517 image_info->channel=DefaultChannels;
1518 image_info->quality=UndefinedCompressionQuality;
1519 image_info->antialias=MagickTrue;
1520 image_info->dither=MagickTrue;
1521 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1522 if (synchronize != (const char *) NULL)
1523 image_info->synchronize=IsMagickTrue(synchronize);
1524 exception=AcquireExceptionInfo();
1525 (void) QueryColorDatabase(BackgroundColor,&image_info->background_color,
1527 (void) QueryColorDatabase(BorderColor,&image_info->border_color,exception);
1528 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,exception);
1529 (void) QueryColorDatabase(TransparentColor,&image_info->transparent_color,
1531 exception=DestroyExceptionInfo(exception);
1532 image_info->debug=IsEventLogging();
1533 image_info->signature=MagickSignature;
1537 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1541 % G e t I m a g e I n f o F i l e %
1545 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1547 % GetImageInfoFile() returns the image info file member.
1549 % The format of the GetImageInfoFile method is:
1551 % FILE *GetImageInfoFile(const ImageInfo *image_info)
1553 % A description of each parameter follows:
1555 % o image_info: the image info.
1558 MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1560 return(image_info->file);
1564 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1568 % G e t I m a g e M a s k %
1572 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1574 % GetImageMask() returns the mask associated with the image.
1576 % The format of the GetImageMask method is:
1578 % Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1580 % A description of each parameter follows:
1582 % o image: the image.
1585 MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1587 assert(image != (const Image *) NULL);
1588 if (image->debug != MagickFalse)
1589 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1590 assert(image->signature == MagickSignature);
1591 if (image->mask == (Image *) NULL)
1592 return((Image *) NULL);
1593 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1597 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1601 + G e t I m a g e R e f e r e n c e C o u n t %
1605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1607 % GetImageReferenceCount() returns the image reference count.
1609 % The format of the GetReferenceCount method is:
1611 % ssize_t GetImageReferenceCount(Image *image)
1613 % A description of each parameter follows:
1615 % o image: the image.
1618 MagickExport ssize_t GetImageReferenceCount(Image *image)
1623 assert(image != (Image *) NULL);
1624 assert(image->signature == MagickSignature);
1625 if (image->debug != MagickFalse)
1626 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1627 LockSemaphoreInfo(image->semaphore);
1628 reference_count=image->reference_count;
1629 UnlockSemaphoreInfo(image->semaphore);
1630 return(reference_count);
1634 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1638 % 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 %
1642 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1644 % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1645 % image. A virtual pixel is any pixel access that is outside the boundaries
1646 % of the image cache.
1648 % The format of the GetImageVirtualPixelMethod() method is:
1650 % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1652 % A description of each parameter follows:
1654 % o image: the image.
1657 MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1659 assert(image != (Image *) NULL);
1660 assert(image->signature == MagickSignature);
1661 if (image->debug != MagickFalse)
1662 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1663 return(GetPixelCacheVirtualMethod(image));
1667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1671 % I n t e r p r e t I m a g e F i l e n a m e %
1675 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1677 % InterpretImageFilename() interprets embedded characters in an image filename.
1678 % The filename length is returned.
1680 % The format of the InterpretImageFilename method is:
1682 % size_t InterpretImageFilename(const ImageInfo *image_info,
1683 % Image *image,const char *format,int value,char *filename)
1685 % A description of each parameter follows.
1687 % o image_info: the image info..
1689 % o image: the image.
1691 % o format: A filename describing the format to use to write the numeric
1692 % argument. Only the first numeric format identifier is replaced.
1694 % o value: Numeric value to substitute into format filename.
1696 % o filename: return the formatted filename in this character buffer.
1699 MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1700 Image *image,const char *format,int value,char *filename)
1717 canonical=MagickFalse;
1719 (void) CopyMagickString(filename,format,MaxTextExtent);
1720 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1733 value=(ssize_t) strtol(q,&q,10);
1745 (void) FormatLocaleString(filename+(p-format),(size_t) (MaxTextExtent-
1746 (p-format)),p,value);
1748 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1749 canonical=MagickTrue;
1758 pattern[MaxTextExtent];
1775 if (strchr(p,']') == (char *) NULL)
1779 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1790 if (LocaleNCompare(pattern,"filename:",9) != 0)
1792 value=(const char *) NULL;
1793 if ((image_info != (const ImageInfo *) NULL) &&
1794 (image != (const Image *) NULL))
1795 value=GetMagickProperty(image_info,image,pattern);
1797 if (image != (Image *) NULL)
1798 value=GetImageProperty(image,pattern);
1800 if (image_info != (ImageInfo *) NULL)
1801 value=GetImageOption(image_info,pattern);
1802 if (value == (const char *) NULL)
1807 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1808 (MaxTextExtent-(p-format-length)));
1809 length+=strlen(pattern)-1;
1811 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1812 canonical=MagickTrue;
1822 for (q=filename; *q != '\0'; q++)
1823 if ((*q == '%') && (*(q+1) == '%'))
1825 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1826 canonical=MagickTrue;
1828 if (canonical == MagickFalse)
1829 (void) CopyMagickString(filename,format,MaxTextExtent);
1830 return(strlen(filename));
1834 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1838 % I s H i g h D y n a m i c R a n g e I m a g e %
1842 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1844 % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1845 % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1848 % The format of the IsHighDynamicRangeImage method is:
1850 % MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1851 % ExceptionInfo *exception)
1853 % A description of each parameter follows:
1855 % o image: the image.
1857 % o exception: return any errors or warnings in this structure.
1860 MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1861 ExceptionInfo *exception)
1863 #if !defined(MAGICKCORE_HDRI_SUPPORT)
1866 return(MagickFalse);
1880 assert(image != (Image *) NULL);
1881 assert(image->signature == MagickSignature);
1882 if (image->debug != MagickFalse)
1883 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1885 GetPixelInfo(image,&zero);
1886 image_view=AcquireCacheView(image);
1887 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1888 #pragma omp parallel for schedule(dynamic,4) shared(status)
1890 for (y=0; y < (ssize_t) image->rows; y++)
1895 register const Quantum
1901 if (status == MagickFalse)
1903 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1904 if (p == (const Quantum *) NULL)
1910 for (x=0; x < (ssize_t) image->columns; x++)
1912 SetPixelInfo(image,p,&pixel);
1913 if ((pixel.red < 0.0) || (pixel.red > QuantumRange) ||
1914 (pixel.red != (QuantumAny) pixel.red))
1916 if ((pixel.green < 0.0) || (pixel.green > QuantumRange) ||
1917 (pixel.green != (QuantumAny) pixel.green))
1919 if ((pixel.blue < 0.0) || (pixel.blue > QuantumRange) ||
1920 (pixel.blue != (QuantumAny) pixel.blue))
1922 if (pixel.colorspace == CMYKColorspace)
1924 if ((pixel.black < 0.0) || (pixel.black > QuantumRange) ||
1925 (pixel.black != (QuantumAny) pixel.black))
1928 if (pixel.matte != MagickFalse)
1930 if ((pixel.alpha < 0.0) || (pixel.alpha > QuantumRange) ||
1931 (pixel.alpha != (QuantumAny) pixel.alpha))
1934 p+=GetPixelChannels(image);
1936 if (x < (ssize_t) image->columns)
1939 image_view=DestroyCacheView(image_view);
1940 return(status != MagickFalse ? MagickFalse : MagickTrue);
1945 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1949 % I s I m a g e O b j e c t %
1953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1955 % IsImageObject() returns MagickTrue if the image sequence contains a valid
1956 % set of image objects.
1958 % The format of the IsImageObject method is:
1960 % MagickBooleanType IsImageObject(const Image *image)
1962 % A description of each parameter follows:
1964 % o image: the image.
1967 MagickExport MagickBooleanType IsImageObject(const Image *image)
1969 register const Image
1972 assert(image != (Image *) NULL);
1973 if (image->debug != MagickFalse)
1974 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1975 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1976 if (p->signature != MagickSignature)
1977 return(MagickFalse);
1982 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1986 % I s T a i n t I m a g e %
1990 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1992 % IsTaintImage() returns MagickTrue any pixel in the image has been altered
1993 % since it was first constituted.
1995 % The format of the IsTaintImage method is:
1997 % MagickBooleanType IsTaintImage(const Image *image)
1999 % A description of each parameter follows:
2001 % o image: the image.
2004 MagickExport MagickBooleanType IsTaintImage(const Image *image)
2007 magick[MaxTextExtent],
2008 filename[MaxTextExtent];
2010 register const Image
2013 assert(image != (Image *) NULL);
2014 if (image->debug != MagickFalse)
2015 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2016 assert(image->signature == MagickSignature);
2017 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
2018 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
2019 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
2021 if (p->taint != MagickFalse)
2023 if (LocaleCompare(p->magick,magick) != 0)
2025 if (LocaleCompare(p->filename,filename) != 0)
2028 return(MagickFalse);
2032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2036 % M o d i f y I m a g e %
2040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2042 % ModifyImage() ensures that there is only a single reference to the image
2043 % to be modified, updating the provided image pointer to point to a clone of
2044 % the original image if necessary.
2046 % The format of the ModifyImage method is:
2048 % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
2050 % A description of each parameter follows:
2052 % o image: the image.
2054 % o exception: return any errors or warnings in this structure.
2057 MagickExport MagickBooleanType ModifyImage(Image **image,
2058 ExceptionInfo *exception)
2063 assert(image != (Image **) NULL);
2064 assert(*image != (Image *) NULL);
2065 assert((*image)->signature == MagickSignature);
2066 if ((*image)->debug != MagickFalse)
2067 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
2068 if (GetImageReferenceCount(*image) <= 1)
2070 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2071 LockSemaphoreInfo((*image)->semaphore);
2072 (*image)->reference_count--;
2073 UnlockSemaphoreInfo((*image)->semaphore);
2079 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2083 % N e w M a g i c k I m a g e %
2087 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2089 % NewMagickImage() creates a blank image canvas of the specified size and
2092 % The format of the NewMagickImage method is:
2094 % Image *NewMagickImage(const ImageInfo *image_info,
2095 % const size_t width,const size_t height,
2096 % const PixelInfo *background)
2098 % A description of each parameter follows:
2100 % o image: the image.
2102 % o width: the image width.
2104 % o height: the image height.
2106 % o background: the image color.
2109 MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2110 const size_t width,const size_t height,
2111 const PixelInfo *background)
2128 assert(image_info != (const ImageInfo *) NULL);
2129 if (image_info->debug != MagickFalse)
2130 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2131 assert(image_info->signature == MagickSignature);
2132 assert(background != (const PixelInfo *) NULL);
2133 image=AcquireImage(image_info);
2134 image->columns=width;
2136 image->colorspace=background->colorspace;
2137 image->matte=background->matte;
2138 image->fuzz=background->fuzz;
2139 image->depth=background->depth;
2141 exception=(&image->exception);
2142 image_view=AcquireCacheView(image);
2143 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2144 #pragma omp parallel for schedule(dynamic,4) shared(status)
2146 for (y=0; y < (ssize_t) image->rows; y++)
2154 if (status == MagickFalse)
2156 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2157 if (q == (Quantum *) NULL)
2162 for (x=0; x < (ssize_t) image->columns; x++)
2164 SetPixelPixelInfo(image,background,q);
2165 q+=GetPixelChannels(image);
2167 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2170 image_view=DestroyCacheView(image_view);
2171 if (status == MagickFalse)
2172 image=DestroyImage(image);
2177 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2181 % R e f e r e n c e I m a g e %
2185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2187 % ReferenceImage() increments the reference count associated with an image
2188 % returning a pointer to the image.
2190 % The format of the ReferenceImage method is:
2192 % Image *ReferenceImage(Image *image)
2194 % A description of each parameter follows:
2196 % o image: the image.
2199 MagickExport Image *ReferenceImage(Image *image)
2201 assert(image != (Image *) NULL);
2202 if (image->debug != MagickFalse)
2203 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2204 assert(image->signature == MagickSignature);
2205 LockSemaphoreInfo(image->semaphore);
2206 image->reference_count++;
2207 UnlockSemaphoreInfo(image->semaphore);
2212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2216 % R e s e t I m a g e P a g e %
2220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2222 % ResetImagePage() resets the image page canvas and position.
2224 % The format of the ResetImagePage method is:
2226 % MagickBooleanType ResetImagePage(Image *image,const char *page)
2228 % A description of each parameter follows:
2230 % o image: the image.
2232 % o page: the relative page specification.
2235 MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2243 assert(image != (Image *) NULL);
2244 assert(image->signature == MagickSignature);
2245 if (image->debug != MagickFalse)
2246 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2247 flags=ParseAbsoluteGeometry(page,&geometry);
2248 if ((flags & WidthValue) != 0)
2250 if ((flags & HeightValue) == 0)
2251 geometry.height=geometry.width;
2252 image->page.width=geometry.width;
2253 image->page.height=geometry.height;
2255 if ((flags & AspectValue) != 0)
2257 if ((flags & XValue) != 0)
2258 image->page.x+=geometry.x;
2259 if ((flags & YValue) != 0)
2260 image->page.y+=geometry.y;
2264 if ((flags & XValue) != 0)
2266 image->page.x=geometry.x;
2267 if ((image->page.width == 0) && (geometry.x > 0))
2268 image->page.width=image->columns+geometry.x;
2270 if ((flags & YValue) != 0)
2272 image->page.y=geometry.y;
2273 if ((image->page.height == 0) && (geometry.y > 0))
2274 image->page.height=image->rows+geometry.y;
2281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2285 % S e p a r a t e I m a g e C h a n n e l %
2289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2291 % SeparateImage() separates a channel from the image and returns it as
2292 % a grayscale image. A channel is a particular color component of each pixel
2295 % The format of the SeparateImage method is:
2297 % MagickBooleanType SeparateImage(Image *image)
2299 % A description of each parameter follows:
2301 % o image: the image.
2304 MagickExport MagickBooleanType SeparateImage(Image *image)
2306 #define SeparateImageTag "Separate/Image"
2323 assert(image != (Image *) NULL);
2324 assert(image->signature == MagickSignature);
2325 if (image->debug != MagickFalse)
2326 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2327 exception=(&image->exception);
2328 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2329 return(MagickFalse);
2331 Separate image channels.
2335 image_view=AcquireCacheView(image);
2336 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2337 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2339 for (y=0; y < (ssize_t) image->rows; y++)
2347 if (status == MagickFalse)
2349 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2350 if (q == (Quantum *) NULL)
2355 for (x=0; x < (ssize_t) image->columns; x++)
2357 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2359 SetPixelGreen(image,GetPixelRed(image,q),q);
2360 SetPixelBlue(image,GetPixelRed(image,q),q);
2362 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2364 SetPixelRed(image,GetPixelGreen(image,q),q);
2365 SetPixelBlue(image,GetPixelGreen(image,q),q);
2367 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2369 SetPixelRed(image,GetPixelBlue(image,q),q);
2370 SetPixelGreen(image,GetPixelBlue(image,q),q);
2372 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
2373 (image->colorspace == CMYKColorspace))
2375 SetPixelRed(image,GetPixelBlack(image,q),q);
2376 SetPixelGreen(image,GetPixelBlack(image,q),q);
2377 SetPixelBlue(image,GetPixelBlack(image,q),q);
2379 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
2380 (image->matte != MagickFalse))
2382 SetPixelRed(image,GetPixelAlpha(image,q),q);
2383 SetPixelGreen(image,GetPixelAlpha(image,q),q);
2384 SetPixelBlue(image,GetPixelAlpha(image,q),q);
2386 q+=GetPixelChannels(image);
2388 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2390 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2395 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2396 #pragma omp critical (MagickCore_SeparateImage)
2398 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2399 if (proceed == MagickFalse)
2403 image_view=DestroyCacheView(image_view);
2404 (void) SetImageColorspace(image,RGBColorspace,exception);
2409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2413 % S e p a r a t e I m a g e s %
2417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2419 % SeparateImages() returns a separate grayscale image for each channel
2422 % The format of the SeparateImages method is:
2424 % MagickBooleanType SeparateImages(const Image *image,
2425 % ExceptionInfo *exception)
2427 % A description of each parameter follows:
2429 % o image: the image.
2431 % o exception: return any errors or warnings in this structure.
2434 MagickExport Image *SeparateImages(const Image *image,ExceptionInfo *exception)
2443 assert(image != (Image *) NULL);
2444 assert(image->signature == MagickSignature);
2445 if (image->debug != MagickFalse)
2446 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2447 images=NewImageList();
2448 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
2450 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2451 channel_mask=SetPixelChannelMask(separate_image,RedChannel);
2452 (void) SeparateImage(separate_image);
2453 (void) SetPixelChannelMap(separate_image,channel_mask);
2454 AppendImageToList(&images,separate_image);
2456 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
2458 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2459 channel_mask=SetPixelChannelMask(separate_image,GreenChannel);
2460 (void) SeparateImage(separate_image);
2461 (void) SetPixelChannelMap(separate_image,channel_mask);
2462 AppendImageToList(&images,separate_image);
2464 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
2466 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2467 channel_mask=SetPixelChannelMask(separate_image,BlueChannel);
2468 (void) SeparateImage(separate_image);
2469 (void) SetPixelChannelMap(separate_image,channel_mask);
2470 AppendImageToList(&images,separate_image);
2472 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
2473 (image->colorspace == CMYKColorspace))
2475 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2476 channel_mask=SetPixelChannelMask(separate_image,BlackChannel);
2477 (void) SeparateImage(separate_image);
2478 (void) SetPixelChannelMap(separate_image,channel_mask);
2479 AppendImageToList(&images,separate_image);
2481 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
2483 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2484 channel_mask=SetPixelChannelMask(separate_image,AlphaChannel);
2485 (void) SeparateImage(separate_image);
2486 (void) SetPixelChannelMap(separate_image,channel_mask);
2487 AppendImageToList(&images,separate_image);
2493 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2497 % S e t I m a g e A l p h a C h a n n e l %
2501 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2503 % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2506 % The format of the SetImageAlphaChannel method is:
2508 % MagickBooleanType SetImageAlphaChannel(Image *image,
2509 % const AlphaChannelType alpha_type,ExceptionInfo *exception)
2511 % A description of each parameter follows:
2513 % o image: the image.
2515 % o alpha_type: The alpha channel type: ActivateAlphaChannel,
2516 % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2517 % OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
2518 % TransparentAlphaChannel.
2520 % o exception: return any errors or warnings in this structure.
2523 MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2524 const AlphaChannelType alpha_type,ExceptionInfo *exception)
2532 assert(image != (Image *) NULL);
2533 if (image->debug != MagickFalse)
2534 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2535 assert(image->signature == MagickSignature);
2539 case ActivateAlphaChannel:
2541 image->matte=MagickTrue;
2544 case BackgroundAlphaChannel:
2559 Set transparent pixels to background color.
2561 if (image->matte == MagickFalse)
2563 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2565 GetPixelInfo(image,&background);
2566 SetPixelInfoPacket(image,&image->background_color,&background);
2567 if (image->colorspace == CMYKColorspace)
2568 ConvertRGBToCMYK(&background);
2569 SetPacketPixelInfo(image,&background,&pixel);
2570 image_view=AcquireCacheView(image);
2571 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2572 #pragma omp parallel for schedule(dynamic,4) shared(status)
2574 for (y=0; y < (ssize_t) image->rows; y++)
2582 if (status == MagickFalse)
2584 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2586 if (q == (Quantum *) NULL)
2591 for (x=0; x < (ssize_t) image->columns; x++)
2593 if (GetPixelAlpha(image,q) == TransparentAlpha)
2595 SetPixelRed(image,pixel.red,q);
2596 SetPixelGreen(image,pixel.green,q);
2597 SetPixelBlue(image,pixel.blue,q);
2598 if (image->colorspace == CMYKColorspace)
2599 SetPixelBlack(image,pixel.black,q);
2601 q+=GetPixelChannels(image);
2603 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2606 image_view=DestroyCacheView(image_view);
2609 case DeactivateAlphaChannel:
2611 image->matte=MagickFalse;
2614 case ShapeAlphaChannel:
2615 case CopyAlphaChannel:
2618 Special usage case for SeparateImage(): copy grayscale color to
2621 channel_mask=SetPixelChannelMask(image,GrayChannel);
2622 status=SeparateImage(image);
2623 (void) SetPixelChannelMask(image,channel_mask);
2624 image->matte=MagickTrue; /* make sure transparency is now on! */
2625 if (alpha_type == ShapeAlphaChannel)
2631 Reset all color channels to background color.
2633 GetPixelInfo(image,&background);
2634 SetPixelInfoPacket(image,&(image->background_color),&background);
2635 (void) LevelImageColors(image,&background,&background,MagickTrue,
2640 case ExtractAlphaChannel:
2642 channel_mask=SetPixelChannelMask(image,AlphaChannel);
2643 status=SeparateImage(image);
2644 (void) SetPixelChannelMask(image,channel_mask);
2645 image->matte=MagickFalse;
2648 case OpaqueAlphaChannel:
2650 status=SetImageOpacity(image,OpaqueAlpha);
2651 image->matte=MagickTrue;
2654 case TransparentAlphaChannel:
2656 status=SetImageOpacity(image,TransparentAlpha);
2657 image->matte=MagickTrue;
2660 case SetAlphaChannel:
2662 if (image->matte == MagickFalse)
2664 status=SetImageOpacity(image,OpaqueAlpha);
2665 image->matte=MagickTrue;
2669 case UndefinedAlphaChannel:
2672 if (status == MagickFalse)
2674 return(SyncImagePixelCache(image,exception));
2678 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2682 % S e t I m a g e B a c k g r o u n d C o l o r %
2686 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2688 % SetImageBackgroundColor() initializes the image pixels to the image
2689 % background color. The background color is defined by the background_color
2690 % member of the image structure.
2692 % The format of the SetImage method is:
2694 % MagickBooleanType SetImageBackgroundColor(Image *image)
2696 % A description of each parameter follows:
2698 % o image: the image.
2701 MagickExport MagickBooleanType SetImageBackgroundColor(Image *image)
2721 assert(image != (Image *) NULL);
2722 if (image->debug != MagickFalse)
2723 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2724 assert(image->signature == MagickSignature);
2725 exception=(&image->exception);
2726 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2727 return(MagickFalse);
2728 if (image->background_color.alpha != OpaqueAlpha)
2729 image->matte=MagickTrue;
2730 GetPixelInfo(image,&background);
2731 SetPixelInfoPacket(image,&image->background_color,&background);
2732 if (image->colorspace == CMYKColorspace)
2733 ConvertRGBToCMYK(&background);
2734 SetPacketPixelInfo(image,&background,&pixel);
2736 Set image background color.
2740 image_view=AcquireCacheView(image);
2741 for (y=0; y < (ssize_t) image->rows; y++)
2749 if (status == MagickFalse)
2751 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2752 if (q == (Quantum *) NULL)
2757 for (x=0; x < (ssize_t) image->columns; x++)
2759 SetPixelPacket(image,&pixel,q);
2760 if (image->colorspace == CMYKColorspace)
2761 SetPixelBlack(image,pixel.black,q);
2762 q+=GetPixelChannels(image);
2764 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2767 image_view=DestroyCacheView(image_view);
2772 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2776 % S e t I m a g e C o l o r %
2780 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2782 % SetImageColor() set the entire image canvas to the specified color.
2784 % The format of the SetImageColor method is:
2786 % MagickBooleanType SetImageColor(Image *image,const PixelInfo *color)
2788 % A description of each parameter follows:
2790 % o image: the image.
2792 % o background: the image color.
2795 MagickExport MagickBooleanType SetImageColor(Image *image,
2796 const PixelInfo *color)
2810 assert(image != (Image *) NULL);
2811 if (image->debug != MagickFalse)
2812 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2813 assert(image->signature == MagickSignature);
2814 assert(color != (const PixelInfo *) NULL);
2815 image->colorspace=color->colorspace;
2816 image->matte=color->matte;
2817 image->fuzz=color->fuzz;
2818 image->depth=color->depth;
2820 exception=(&image->exception);
2821 image_view=AcquireCacheView(image);
2822 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2823 #pragma omp parallel for schedule(dynamic,4) shared(status)
2825 for (y=0; y < (ssize_t) image->rows; y++)
2833 if (status == MagickFalse)
2835 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2836 if (q == (Quantum *) NULL)
2841 for (x=0; x < (ssize_t) image->columns; x++)
2843 SetPixelPixelInfo(image,color,q);
2844 q+=GetPixelChannels(image);
2846 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2849 image_view=DestroyCacheView(image_view);
2854 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2858 % S e t I m a g e S t o r a g e C l a s s %
2862 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2864 % SetImageStorageClass() sets the image class: DirectClass for true color
2865 % images or PseudoClass for colormapped images.
2867 % The format of the SetImageStorageClass method is:
2869 % MagickBooleanType SetImageStorageClass(Image *image,
2870 % const ClassType storage_class,ExceptionInfo *exception)
2872 % A description of each parameter follows:
2874 % o image: the image.
2876 % o storage_class: The image class.
2878 % o exception: return any errors or warnings in this structure.
2881 MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2882 const ClassType storage_class,ExceptionInfo *exception)
2884 image->storage_class=storage_class;
2885 return(SyncImagePixelCache(image,exception));
2889 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2893 % S e t I m a g e C l i p M a s k %
2897 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2899 % SetImageClipMask() associates a clip path with the image. The clip path
2900 % must be the same dimensions as the image. Set any pixel component of
2901 % the clip path to TransparentAlpha to prevent that corresponding image
2902 % pixel component from being updated when SyncAuthenticPixels() is applied.
2904 % The format of the SetImageClipMask method is:
2906 % MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask,
2907 % ExceptionInfo *exception)
2909 % A description of each parameter follows:
2911 % o image: the image.
2913 % o clip_mask: the image clip path.
2915 % o exception: return any errors or warnings in this structure.
2918 MagickExport MagickBooleanType SetImageClipMask(Image *image,
2919 const Image *clip_mask,ExceptionInfo *exception)
2921 assert(image != (Image *) NULL);
2922 if (image->debug != MagickFalse)
2923 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2924 assert(image->signature == MagickSignature);
2925 if (clip_mask != (const Image *) NULL)
2926 if ((clip_mask->columns != image->columns) ||
2927 (clip_mask->rows != image->rows))
2928 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
2929 if (image->clip_mask != (Image *) NULL)
2930 image->clip_mask=DestroyImage(image->clip_mask);
2931 image->clip_mask=NewImageList();
2932 if (clip_mask == (Image *) NULL)
2934 if (SetImageStorageClass(image,DirectClass,&image->exception) == MagickFalse)
2935 return(MagickFalse);
2936 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
2937 if (image->clip_mask == (Image *) NULL)
2938 return(MagickFalse);
2943 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2947 % S e t I m a g e E x t e n t %
2951 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2953 % SetImageExtent() sets the image size (i.e. columns & rows).
2955 % The format of the SetImageExtent method is:
2957 % MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2958 % const size_t rows,ExceptionInfo *exception)
2960 % A description of each parameter follows:
2962 % o image: the image.
2964 % o columns: The image width in pixels.
2966 % o rows: The image height in pixels.
2968 % o exception: return any errors or warnings in this structure.
2971 MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2972 const size_t rows,ExceptionInfo *exception)
2974 if ((columns == 0) || (rows == 0))
2975 return(MagickFalse);
2976 image->columns=columns;
2978 return(SyncImagePixelCache(image,exception));
2982 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2986 + S e t I m a g e I n f o %
2990 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2992 % SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2993 % It is set to a type of image format based on the prefix or suffix of the
2994 % filename. For example, `ps:image' returns PS indicating a Postscript image.
2995 % JPEG is returned for this filename: `image.jpg'. The filename prefix has
2996 % precendence over the suffix. Use an optional index enclosed in brackets
2997 % after a file name to specify a desired scene of a multi-resolution image
2998 % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2999 % indicates success.
3001 % The format of the SetImageInfo method is:
3003 % MagickBooleanType SetImageInfo(ImageInfo *image_info,
3004 % const unsigned int frames,ExceptionInfo *exception)
3006 % A description of each parameter follows:
3008 % o image_info: the image info.
3010 % o frames: the number of images you intend to write.
3012 % o exception: return any errors or warnings in this structure.
3015 MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
3016 const unsigned int frames,ExceptionInfo *exception)
3019 extension[MaxTextExtent],
3020 filename[MaxTextExtent],
3021 magic[MaxTextExtent],
3023 subimage[MaxTextExtent];
3047 magick[2*MaxTextExtent];
3050 Look for 'image.format' in filename.
3052 assert(image_info != (ImageInfo *) NULL);
3053 assert(image_info->signature == MagickSignature);
3054 if (image_info->debug != MagickFalse)
3055 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3056 image_info->filename);
3060 GetPathComponent(image_info->filename,SubimagePath,subimage);
3061 if (*subimage != '\0')
3064 Look for scene specification (e.g. img0001.pcd[4]).
3066 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
3068 if (IsGeometry(subimage) != MagickFalse)
3069 (void) CloneString(&image_info->extract,subimage);
3077 (void) CloneString(&image_info->scenes,subimage);
3078 image_info->scene=StringToUnsignedLong(image_info->scenes);
3079 image_info->number_scenes=image_info->scene;
3080 p=image_info->scenes;
3081 for (q=(char *) image_info->scenes; *q != '\0'; p++)
3083 while ((isspace((int) ((unsigned char) *p)) != 0) ||
3086 first=(size_t) strtol(p,&q,10);
3088 while (isspace((int) ((unsigned char) *q)) != 0)
3091 last=(size_t) strtol(q+1,&q,10);
3094 if (first < image_info->scene)
3095 image_info->scene=first;
3096 if (last > image_info->number_scenes)
3097 image_info->number_scenes=last;
3100 image_info->number_scenes-=image_info->scene-1;
3105 GetPathComponent(image_info->filename,ExtensionPath,extension);
3106 #if defined(MAGICKCORE_ZLIB_DELEGATE)
3107 if (*extension != '\0')
3108 if ((LocaleCompare(extension,"gz") == 0) ||
3109 (LocaleCompare(extension,"Z") == 0) ||
3110 (LocaleCompare(extension,"wmz") == 0))
3113 path[MaxTextExtent];
3115 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3116 path[strlen(path)-strlen(extension)-1]='\0';
3117 GetPathComponent(path,ExtensionPath,extension);
3120 #if defined(MAGICKCORE_BZLIB_DELEGATE)
3121 if (*extension != '\0')
3122 if (LocaleCompare(extension,"bz2") == 0)
3125 path[MaxTextExtent];
3127 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3128 path[strlen(path)-strlen(extension)-1]='\0';
3129 GetPathComponent(path,ExtensionPath,extension);
3132 image_info->affirm=MagickFalse;
3133 sans_exception=AcquireExceptionInfo();
3134 if (*extension != '\0')
3143 *format_type_formats[] =
3166 User specified image format.
3168 (void) CopyMagickString(magic,extension,MaxTextExtent);
3171 Look for explicit image formats.
3173 format_type=UndefinedFormatType;
3175 while ((format_type == UndefinedFormatType) &&
3176 (format_type_formats[i] != (char *) NULL))
3178 if ((*magic == *format_type_formats[i]) &&
3179 (LocaleCompare(magic,format_type_formats[i]) == 0))
3180 format_type=ExplicitFormatType;
3183 magick_info=GetMagickInfo(magic,sans_exception);
3184 if ((magick_info != (const MagickInfo *) NULL) &&
3185 (magick_info->format_type != UndefinedFormatType))
3186 format_type=magick_info->format_type;
3187 if (format_type == UndefinedFormatType)
3188 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3190 if (format_type == ExplicitFormatType)
3192 image_info->affirm=MagickTrue;
3193 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3195 if (LocaleCompare(magic,"RGB") == 0)
3196 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3199 Look for explicit 'format:image' in filename.
3202 GetPathComponent(image_info->filename,MagickPath,magic);
3204 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3208 User specified image format.
3211 if (IsMagickConflict(magic) == MagickFalse)
3213 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3214 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3215 image_info->affirm=MagickTrue;
3217 image_info->temporary=MagickTrue;
3220 magick_info=GetMagickInfo(magic,sans_exception);
3221 sans_exception=DestroyExceptionInfo(sans_exception);
3222 if ((magick_info == (const MagickInfo *) NULL) ||
3223 (GetMagickEndianSupport(magick_info) == MagickFalse))
3224 image_info->endian=UndefinedEndian;
3225 GetPathComponent(image_info->filename,CanonicalPath,filename);
3226 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3227 if ((image_info->adjoin != MagickFalse) && (frames > 1))
3230 Test for multiple image support (e.g. image%02d.png).
3232 (void) InterpretImageFilename(image_info,(Image *) NULL,
3233 image_info->filename,(int) image_info->scene,filename);
3234 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3235 (strchr(filename,'%') == (char *) NULL))
3236 image_info->adjoin=MagickFalse;
3238 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3241 Some image formats do not support multiple frames per file.
3243 magick_info=GetMagickInfo(magic,exception);
3244 if (magick_info != (const MagickInfo *) NULL)
3245 if (GetMagickAdjoin(magick_info) == MagickFalse)
3246 image_info->adjoin=MagickFalse;
3248 if (image_info->affirm != MagickFalse)
3253 Determine the image format from the first few bytes of the file.
3255 image=AcquireImage(image_info);
3256 (void) CopyMagickString(image->filename,image_info->filename,
3258 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3259 if (status == MagickFalse)
3261 image=DestroyImage(image);
3262 return(MagickFalse);
3264 if ((IsBlobSeekable(image) == MagickFalse) ||
3265 (IsBlobExempt(image) != MagickFalse))
3268 Copy standard input or pipe to temporary file.
3271 status=ImageToFile(image,filename,exception);
3272 (void) CloseBlob(image);
3273 if (status == MagickFalse)
3275 image=DestroyImage(image);
3276 return(MagickFalse);
3278 SetImageInfoFile(image_info,(FILE *) NULL);
3279 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3280 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3281 if (status == MagickFalse)
3283 image=DestroyImage(image);
3284 return(MagickFalse);
3286 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3287 image_info->temporary=MagickTrue;
3289 (void) ResetMagickMemory(magick,0,sizeof(magick));
3290 count=ReadBlob(image,2*MaxTextExtent,magick);
3291 (void) CloseBlob(image);
3292 image=DestroyImage(image);
3294 Check magic.xml configuration file.
3296 sans_exception=AcquireExceptionInfo();
3297 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3298 if ((magic_info != (const MagicInfo *) NULL) &&
3299 (GetMagicName(magic_info) != (char *) NULL))
3301 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3303 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3304 if ((magick_info == (const MagickInfo *) NULL) ||
3305 (GetMagickEndianSupport(magick_info) == MagickFalse))
3306 image_info->endian=UndefinedEndian;
3307 sans_exception=DestroyExceptionInfo(sans_exception);
3310 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3311 if ((magick_info == (const MagickInfo *) NULL) ||
3312 (GetMagickEndianSupport(magick_info) == MagickFalse))
3313 image_info->endian=UndefinedEndian;
3314 sans_exception=DestroyExceptionInfo(sans_exception);
3320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3324 % S e t I m a g e I n f o B l o b %
3328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3330 % SetImageInfoBlob() sets the image info blob member.
3332 % The format of the SetImageInfoBlob method is:
3334 % void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3335 % const size_t length)
3337 % A description of each parameter follows:
3339 % o image_info: the image info.
3343 % o length: the blob length.
3346 MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3347 const size_t length)
3349 assert(image_info != (ImageInfo *) NULL);
3350 assert(image_info->signature == MagickSignature);
3351 if (image_info->debug != MagickFalse)
3352 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3353 image_info->filename);
3354 image_info->blob=(void *) blob;
3355 image_info->length=length;
3359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3363 % S e t I m a g e I n f o F i l e %
3367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3369 % SetImageInfoFile() sets the image info file member.
3371 % The format of the SetImageInfoFile method is:
3373 % void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3375 % A description of each parameter follows:
3377 % o image_info: the image info.
3382 MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3384 assert(image_info != (ImageInfo *) NULL);
3385 assert(image_info->signature == MagickSignature);
3386 if (image_info->debug != MagickFalse)
3387 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3388 image_info->filename);
3389 image_info->file=file;
3393 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3397 % S e t I m a g e M a s k %
3401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3403 % SetImageMask() associates a mask with the image. The mask must be the same
3404 % dimensions as the image.
3406 % The format of the SetImageMask method is:
3408 % MagickBooleanType SetImageMask(Image *image,const Image *mask,
3409 % ExceptionInfo *exception)
3411 % A description of each parameter follows:
3413 % o image: the image.
3415 % o mask: the image mask.
3417 % o exception: return any errors or warnings in this structure.
3420 MagickExport MagickBooleanType SetImageMask(Image *image,
3421 const Image *mask,ExceptionInfo *exception)
3423 assert(image != (Image *) NULL);
3424 if (image->debug != MagickFalse)
3425 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3426 assert(image->signature == MagickSignature);
3427 if (mask != (const Image *) NULL)
3428 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3429 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3430 if (image->mask != (Image *) NULL)
3431 image->mask=DestroyImage(image->mask);
3432 image->mask=NewImageList();
3433 if (mask == (Image *) NULL)
3435 if (SetImageStorageClass(image,DirectClass,&image->exception) == MagickFalse)
3436 return(MagickFalse);
3437 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3438 if (image->mask == (Image *) NULL)
3439 return(MagickFalse);
3444 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3448 % S e t I m a g e O p a c i t y %
3452 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3454 % SetImageOpacity() sets the opacity levels of the image.
3456 % The format of the SetImageOpacity method is:
3458 % MagickBooleanType SetImageOpacity(Image *image,const Quantum opacity)
3460 % A description of each parameter follows:
3462 % o image: the image.
3464 % o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
3465 % fully transparent.
3468 MagickExport MagickBooleanType SetImageOpacity(Image *image,
3469 const Quantum opacity)
3483 assert(image != (Image *) NULL);
3484 if (image->debug != MagickFalse)
3485 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3486 assert(image->signature == MagickSignature);
3487 image->matte=opacity != OpaqueAlpha ? MagickTrue : MagickFalse;
3489 exception=(&image->exception);
3490 image_view=AcquireCacheView(image);
3491 #if defined(MAGICKCORE_OPENMP_SUPPORT)
3492 #pragma omp parallel for schedule(dynamic,4) shared(status)
3494 for (y=0; y < (ssize_t) image->rows; y++)
3502 if (status == MagickFalse)
3504 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3505 if (q == (Quantum *) NULL)
3510 for (x=0; x < (ssize_t) image->columns; x++)
3512 SetPixelAlpha(image,opacity,q);
3513 q+=GetPixelChannels(image);
3515 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3518 image_view=DestroyCacheView(image_view);
3523 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3527 % S e t I m a g e T y p e %
3531 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3533 % SetImageType() sets the type of image. Choose from these types:
3535 % Bilevel Grayscale GrayscaleMatte
3536 % Palette PaletteMatte TrueColor
3537 % TrueColorMatte ColorSeparation ColorSeparationMatte
3540 % The format of the SetImageType method is:
3542 % MagickBooleanType SetImageType(Image *image,const ImageType type,
3543 % ExceptionInfo *exception)
3545 % A description of each parameter follows:
3547 % o image: the image.
3549 % o type: Image type.
3551 % o exception: return any errors or warnings in this structure.
3554 MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type,
3555 ExceptionInfo *exception)
3569 assert(image != (Image *) NULL);
3570 if (image->debug != MagickFalse)
3571 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3572 assert(image->signature == MagickSignature);
3574 image_info=AcquireImageInfo();
3575 image_info->dither=image->dither;
3576 artifact=GetImageArtifact(image,"dither");
3577 if (artifact != (const char *) NULL)
3578 (void) SetImageOption(image_info,"dither",artifact);
3583 if (IsImageGray(image,&image->exception) == MagickFalse)
3584 status=TransformImageColorspace(image,GRAYColorspace);
3585 if (IsImageMonochrome(image,&image->exception) == MagickFalse)
3587 quantize_info=AcquireQuantizeInfo(image_info);
3588 quantize_info->number_colors=2;
3589 quantize_info->colorspace=GRAYColorspace;
3590 status=QuantizeImage(quantize_info,image,exception);
3591 quantize_info=DestroyQuantizeInfo(quantize_info);
3593 image->matte=MagickFalse;
3598 if (IsImageGray(image,&image->exception) == MagickFalse)
3599 status=TransformImageColorspace(image,GRAYColorspace);
3600 image->matte=MagickFalse;
3603 case GrayscaleMatteType:
3605 if (IsImageGray(image,&image->exception) == MagickFalse)
3606 status=TransformImageColorspace(image,GRAYColorspace);
3607 if (image->matte == MagickFalse)
3608 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3613 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3614 status=TransformImageColorspace(image,RGBColorspace);
3615 if ((image->storage_class == DirectClass) || (image->colors > 256))
3617 quantize_info=AcquireQuantizeInfo(image_info);
3618 quantize_info->number_colors=256;
3619 status=QuantizeImage(quantize_info,image,exception);
3620 quantize_info=DestroyQuantizeInfo(quantize_info);
3622 image->matte=MagickFalse;
3625 case PaletteBilevelMatteType:
3630 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3631 status=TransformImageColorspace(image,RGBColorspace);
3632 if (image->matte == MagickFalse)
3633 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3634 channel_mask=SetPixelChannelMask(image,AlphaChannel);
3635 (void) BilevelImage(image,(double) QuantumRange/2.0);
3636 (void) SetPixelChannelMask(image,channel_mask);
3637 quantize_info=AcquireQuantizeInfo(image_info);
3638 status=QuantizeImage(quantize_info,image,exception);
3639 quantize_info=DestroyQuantizeInfo(quantize_info);
3642 case PaletteMatteType:
3644 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3645 status=TransformImageColorspace(image,RGBColorspace);
3646 if (image->matte == MagickFalse)
3647 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3648 quantize_info=AcquireQuantizeInfo(image_info);
3649 quantize_info->colorspace=TransparentColorspace;
3650 status=QuantizeImage(quantize_info,image,exception);
3651 quantize_info=DestroyQuantizeInfo(quantize_info);
3656 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3657 status=TransformImageColorspace(image,RGBColorspace);
3658 if (image->storage_class != DirectClass)
3659 status=SetImageStorageClass(image,DirectClass,&image->exception);
3660 image->matte=MagickFalse;
3663 case TrueColorMatteType:
3665 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3666 status=TransformImageColorspace(image,RGBColorspace);
3667 if (image->storage_class != DirectClass)
3668 status=SetImageStorageClass(image,DirectClass,&image->exception);
3669 if (image->matte == MagickFalse)
3670 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3673 case ColorSeparationType:
3675 if (image->colorspace != CMYKColorspace)
3677 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3678 status=TransformImageColorspace(image,RGBColorspace);
3679 status=TransformImageColorspace(image,CMYKColorspace);
3681 if (image->storage_class != DirectClass)
3682 status=SetImageStorageClass(image,DirectClass,&image->exception);
3683 image->matte=MagickFalse;
3686 case ColorSeparationMatteType:
3688 if (image->colorspace != CMYKColorspace)
3690 if (IsRGBColorspace(image->colorspace) == MagickFalse)
3691 status=TransformImageColorspace(image,RGBColorspace);
3692 status=TransformImageColorspace(image,CMYKColorspace);
3694 if (image->storage_class != DirectClass)
3695 status=SetImageStorageClass(image,DirectClass,&image->exception);
3696 if (image->matte == MagickFalse)
3697 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
3705 image_info=DestroyImageInfo(image_info);
3710 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3714 % 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 %
3718 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3720 % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3721 % image and returns the previous setting. A virtual pixel is any pixel access
3722 % that is outside the boundaries of the image cache.
3724 % The format of the SetImageVirtualPixelMethod() method is:
3726 % VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3727 % const VirtualPixelMethod virtual_pixel_method)
3729 % A description of each parameter follows:
3731 % o image: the image.
3733 % o virtual_pixel_method: choose the type of virtual pixel.
3736 MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3737 const VirtualPixelMethod virtual_pixel_method)
3739 assert(image != (const Image *) NULL);
3740 assert(image->signature == MagickSignature);
3741 if (image->debug != MagickFalse)
3742 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3743 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3751 % S m u s h I m a g e s %
3755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3757 % SmushImages() takes all images from the current image pointer to the end
3758 % of the image list and smushes them to each other top-to-bottom if the
3759 % stack parameter is true, otherwise left-to-right.
3761 % The current gravity setting now effects how the image is justified in the
3764 % The format of the SmushImages method is:
3766 % Image *SmushImages(const Image *images,const MagickBooleanType stack,
3767 % ExceptionInfo *exception)
3769 % A description of each parameter follows:
3771 % o images: the image sequence.
3773 % o stack: A value other than 0 stacks the images top-to-bottom.
3775 % o offset: minimum distance in pixels between images.
3777 % o exception: return any errors or warnings in this structure.
3781 static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3782 const ssize_t offset,ExceptionInfo *exception)
3796 register const Quantum
3809 if (images->previous == (Image *) NULL)
3812 SetGeometry(smush_image,&right_geometry);
3813 GravityAdjustGeometry(right_image->columns,right_image->rows,
3814 right_image->gravity,&right_geometry);
3815 left_image=images->previous;
3816 SetGeometry(smush_image,&left_geometry);
3817 GravityAdjustGeometry(left_image->columns,left_image->rows,
3818 left_image->gravity,&left_geometry);
3819 gap=right_image->columns;
3820 left_view=AcquireCacheView(left_image);
3821 right_view=AcquireCacheView(right_image);
3822 for (y=0; y < (ssize_t) smush_image->rows; y++)
3824 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3826 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3827 if ((p == (const Quantum *) NULL) ||
3828 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3829 ((left_image->columns-x-1) >= gap))
3832 i=(ssize_t) left_image->columns-x-1;
3833 for (x=0; x < (ssize_t) right_image->columns; x++)
3835 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3837 if ((p == (const Quantum *) NULL) ||
3838 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3839 ((x+i) >= (ssize_t) gap))
3842 if ((x+i) < (ssize_t) gap)
3845 right_view=DestroyCacheView(right_view);
3846 left_view=DestroyCacheView(left_view);
3847 if (y < (ssize_t) smush_image->rows)
3849 return((ssize_t) gap-offset);
3852 static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3853 const ssize_t offset,ExceptionInfo *exception)
3867 register const Quantum
3880 if (images->previous == (Image *) NULL)
3882 bottom_image=images;
3883 SetGeometry(smush_image,&bottom_geometry);
3884 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3885 bottom_image->gravity,&bottom_geometry);
3886 top_image=images->previous;
3887 SetGeometry(smush_image,&top_geometry);
3888 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3890 gap=bottom_image->rows;
3891 top_view=AcquireCacheView(top_image);
3892 bottom_view=AcquireCacheView(bottom_image);
3893 for (x=0; x < (ssize_t) smush_image->columns; x++)
3895 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3897 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3898 if ((p == (const Quantum *) NULL) ||
3899 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3900 ((top_image->rows-y-1) >= gap))
3903 i=(ssize_t) top_image->rows-y-1;
3904 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3906 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3908 if ((p == (const Quantum *) NULL) ||
3909 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3910 ((y+i) >= (ssize_t) gap))
3913 if ((y+i) < (ssize_t) gap)
3916 bottom_view=DestroyCacheView(bottom_view);
3917 top_view=DestroyCacheView(top_view);
3918 if (x < (ssize_t) smush_image->columns)
3920 return((ssize_t) gap-offset);
3923 MagickExport Image *SmushImages(const Image *images,
3924 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3926 #define SmushImageTag "Smush/Image"
3948 register const Image
3961 Compute maximum area of smushed area.
3963 assert(images != (Image *) NULL);
3964 assert(images->signature == MagickSignature);
3965 if (images->debug != MagickFalse)
3966 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3967 assert(exception != (ExceptionInfo *) NULL);
3968 assert(exception->signature == MagickSignature);
3972 width=image->columns;
3974 next=GetNextImageInList(image);
3975 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3977 if (next->matte != MagickFalse)
3980 if (stack != MagickFalse)
3982 if (next->columns > width)
3983 width=next->columns;
3985 if (next->previous != (Image *) NULL)
3989 width+=next->columns;
3990 if (next->previous != (Image *) NULL)
3992 if (next->rows > height)
3998 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3999 if (smush_image == (Image *) NULL)
4000 return((Image *) NULL);
4001 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
4003 smush_image=DestroyImage(smush_image);
4004 return((Image *) NULL);
4006 smush_image->matte=matte;
4007 (void) SetImageBackgroundColor(smush_image);
4011 smush_view=AcquireCacheView(smush_image);
4012 for (n=0; n < (MagickOffsetType) number_images; n++)
4014 SetGeometry(smush_image,&geometry);
4015 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
4016 if (stack != MagickFalse)
4018 x_offset-=geometry.x;
4019 y_offset-=SmushYGap(smush_image,image,offset,exception);
4023 x_offset-=SmushXGap(smush_image,image,offset,exception);
4024 y_offset-=geometry.y;
4026 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset);
4027 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
4028 if (proceed == MagickFalse)
4030 if (stack == MagickFalse)
4032 x_offset+=(ssize_t) image->columns;
4038 y_offset+=(ssize_t) image->rows;
4040 image=GetNextImageInList(image);
4042 if (stack == MagickFalse)
4043 smush_image->columns=(size_t) x_offset;
4045 smush_image->rows=(size_t) y_offset;
4046 smush_view=DestroyCacheView(smush_view);
4047 if (status == MagickFalse)
4048 smush_image=DestroyImage(smush_image);
4049 return(smush_image);
4053 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4057 % S t r i p I m a g e %
4061 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4063 % StripImage() strips an image of all profiles and comments.
4065 % The format of the StripImage method is:
4067 % MagickBooleanType StripImage(Image *image)
4069 % A description of each parameter follows:
4071 % o image: the image.
4074 MagickExport MagickBooleanType StripImage(Image *image)
4076 assert(image != (Image *) NULL);
4077 if (image->debug != MagickFalse)
4078 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4079 DestroyImageProfiles(image);
4080 (void) DeleteImageProperty(image,"comment");
4081 (void) DeleteImageProperty(image,"date:create");
4082 (void) DeleteImageProperty(image,"date:modify");
4083 (void) SetImageArtifact(image,"png:include-chunk","none,trns,gama");
4088 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4092 + S y n c I m a g e %
4096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4098 % SyncImage() initializes the red, green, and blue intensities of each pixel
4099 % as defined by the colormap index.
4101 % The format of the SyncImage method is:
4103 % MagickBooleanType SyncImage(Image *image)
4105 % A description of each parameter follows:
4107 % o image: the image.
4111 static inline Quantum PushColormapIndex(Image *image,
4112 const size_t index,MagickBooleanType *range_exception)
4114 if (index < image->colors)
4115 return((Quantum) index);
4116 *range_exception=MagickTrue;
4117 return((Quantum) 0);
4120 MagickExport MagickBooleanType SyncImage(Image *image)
4135 assert(image != (Image *) NULL);
4136 if (image->debug != MagickFalse)
4137 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4138 assert(image->signature == MagickSignature);
4139 if (image->storage_class == DirectClass)
4140 return(MagickFalse);
4141 range_exception=MagickFalse;
4143 exception=(&image->exception);
4144 image_view=AcquireCacheView(image);
4145 #if defined(MAGICKCORE_OPENMP_SUPPORT)
4146 #pragma omp parallel for schedule(dynamic,4) shared(status)
4148 for (y=0; y < (ssize_t) image->rows; y++)
4159 if (status == MagickFalse)
4161 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4162 if (q == (Quantum *) NULL)
4167 for (x=0; x < (ssize_t) image->columns; x++)
4169 index=PushColormapIndex(image,(size_t) GetPixelIndex(image,q),
4171 SetPixelPacket(image,image->colormap+(ssize_t) index,q);
4172 q+=GetPixelChannels(image);
4174 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4177 image_view=DestroyCacheView(image_view);
4178 if (range_exception != MagickFalse)
4179 (void) ThrowMagickException(&image->exception,GetMagickModule(),
4180 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
4185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4189 % S y n c I m a g e S e t t i n g s %
4193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4195 % SyncImageSettings() sync the image info options to the image.
4197 % The format of the SyncImageSettings method is:
4199 % MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4201 % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4204 % A description of each parameter follows:
4206 % o image_info: the image info.
4208 % o image: the image.
4212 MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4218 assert(image_info != (const ImageInfo *) NULL);
4219 assert(image_info->signature == MagickSignature);
4220 assert(images != (Image *) NULL);
4221 assert(images->signature == MagickSignature);
4222 if (images->debug != MagickFalse)
4223 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4225 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4226 (void) SyncImageSettings(image_info,image);
4227 (void) DeleteImageOption(image_info,"page");
4231 MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4235 property[MaxTextExtent];
4253 assert(image_info != (const ImageInfo *) NULL);
4254 assert(image_info->signature == MagickSignature);
4255 assert(image != (Image *) NULL);
4256 assert(image->signature == MagickSignature);
4257 if (image->debug != MagickFalse)
4258 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4259 option=GetImageOption(image_info,"background");
4260 if (option != (const char *) NULL)
4261 (void) QueryColorDatabase(option,&image->background_color,
4263 option=GetImageOption(image_info,"bias");
4264 if (option != (const char *) NULL)
4265 image->bias=SiPrefixToDouble(option,QuantumRange);
4266 option=GetImageOption(image_info,"black-point-compensation");
4267 if (option != (const char *) NULL)
4268 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4269 MagickBooleanOptions,MagickFalse,option);
4270 option=GetImageOption(image_info,"blue-primary");
4271 if (option != (const char *) NULL)
4273 flags=ParseGeometry(option,&geometry_info);
4274 image->chromaticity.blue_primary.x=geometry_info.rho;
4275 image->chromaticity.blue_primary.y=geometry_info.sigma;
4276 if ((flags & SigmaValue) == 0)
4277 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4279 option=GetImageOption(image_info,"bordercolor");
4280 if (option != (const char *) NULL)
4281 (void) QueryColorDatabase(option,&image->border_color,&image->exception);
4282 option=GetImageOption(image_info,"colors");
4283 if (option != (const char *) NULL)
4284 image->colors=StringToUnsignedLong(option);
4285 option=GetImageOption(image_info,"compose");
4286 if (option != (const char *) NULL)
4287 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4288 MagickFalse,option);
4289 option=GetImageOption(image_info,"compress");
4290 if (option != (const char *) NULL)
4291 image->compression=(CompressionType) ParseCommandOption(
4292 MagickCompressOptions,MagickFalse,option);
4293 option=GetImageOption(image_info,"debug");
4294 if (option != (const char *) NULL)
4295 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4296 MagickFalse,option);
4297 option=GetImageOption(image_info,"density");
4298 if (option != (const char *) NULL)
4306 flags=ParseGeometry(option,&geometry_info);
4307 image->x_resolution=geometry_info.rho;
4308 image->y_resolution=geometry_info.sigma;
4309 if ((flags & SigmaValue) == 0)
4310 image->y_resolution=image->x_resolution;
4312 option=GetImageOption(image_info,"depth");
4313 if (option != (const char *) NULL)
4314 image->depth=StringToUnsignedLong(option);
4315 option=GetImageOption(image_info,"endian");
4316 if (option != (const char *) NULL)
4317 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4318 MagickFalse,option);
4319 option=GetImageOption(image_info,"filter");
4320 if (option != (const char *) NULL)
4321 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
4322 MagickFalse,option);
4323 option=GetImageOption(image_info,"fuzz");
4324 if (option != (const char *) NULL)
4325 image->fuzz=SiPrefixToDouble(option,QuantumRange);
4326 option=GetImageOption(image_info,"gravity");
4327 if (option != (const char *) NULL)
4328 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4329 MagickFalse,option);
4330 option=GetImageOption(image_info,"green-primary");
4331 if (option != (const char *) NULL)
4333 flags=ParseGeometry(option,&geometry_info);
4334 image->chromaticity.green_primary.x=geometry_info.rho;
4335 image->chromaticity.green_primary.y=geometry_info.sigma;
4336 if ((flags & SigmaValue) == 0)
4337 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4339 option=GetImageOption(image_info,"intent");
4340 if (option != (const char *) NULL)
4341 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4342 MagickIntentOptions,MagickFalse,option);
4343 option=GetImageOption(image_info,"interlace");
4344 if (option != (const char *) NULL)
4345 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4346 MagickFalse,option);
4347 option=GetImageOption(image_info,"interpolate");
4348 if (option != (const char *) NULL)
4349 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4350 MagickInterpolateOptions,MagickFalse,option);
4351 option=GetImageOption(image_info,"loop");
4352 if (option != (const char *) NULL)
4353 image->iterations=StringToUnsignedLong(option);
4354 option=GetImageOption(image_info,"mattecolor");
4355 if (option != (const char *) NULL)
4356 (void) QueryColorDatabase(option,&image->matte_color,&image->exception);
4357 option=GetImageOption(image_info,"orient");
4358 if (option != (const char *) NULL)
4359 image->orientation=(OrientationType) ParseCommandOption(
4360 MagickOrientationOptions,MagickFalse,option);
4361 option=GetImageOption(image_info,"page");
4362 if (option != (const char *) NULL)
4367 geometry=GetPageGeometry(option);
4368 flags=ParseAbsoluteGeometry(geometry,&image->page);
4369 geometry=DestroyString(geometry);
4371 option=GetImageOption(image_info,"quality");
4372 if (option != (const char *) NULL)
4373 image->quality=StringToUnsignedLong(option);
4374 option=GetImageOption(image_info,"red-primary");
4375 if (option != (const char *) NULL)
4377 flags=ParseGeometry(option,&geometry_info);
4378 image->chromaticity.red_primary.x=geometry_info.rho;
4379 image->chromaticity.red_primary.y=geometry_info.sigma;
4380 if ((flags & SigmaValue) == 0)
4381 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4383 if (image_info->quality != UndefinedCompressionQuality)
4384 image->quality=image_info->quality;
4385 option=GetImageOption(image_info,"scene");
4386 if (option != (const char *) NULL)
4387 image->scene=StringToUnsignedLong(option);
4388 option=GetImageOption(image_info,"taint");
4389 if (option != (const char *) NULL)
4390 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4391 MagickFalse,option);
4392 option=GetImageOption(image_info,"tile-offset");
4393 if (option != (const char *) NULL)
4398 geometry=GetPageGeometry(option);
4399 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4400 geometry=DestroyString(geometry);
4402 option=GetImageOption(image_info,"transparent-color");
4403 if (option != (const char *) NULL)
4404 (void) QueryColorDatabase(option,&image->transparent_color,
4406 option=GetImageOption(image_info,"type");
4407 if (option != (const char *) NULL)
4408 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4410 option=GetImageOption(image_info,"units");
4411 if (option != (const char *) NULL)
4412 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4413 MagickFalse,option);
4415 units = image_info->units;
4416 if (units != UndefinedResolution)
4418 if (image->units != units)
4419 switch (image->units)
4421 case PixelsPerInchResolution:
4423 if (units == PixelsPerCentimeterResolution)
4425 image->x_resolution/=2.54;
4426 image->y_resolution/=2.54;
4430 case PixelsPerCentimeterResolution:
4432 if (units == PixelsPerInchResolution)
4434 image->x_resolution=(double) ((size_t) (100.0*2.54*
4435 image->x_resolution+0.5))/100.0;
4436 image->y_resolution=(double) ((size_t) (100.0*2.54*
4437 image->y_resolution+0.5))/100.0;
4446 option=GetImageOption(image_info,"white-point");
4447 if (option != (const char *) NULL)
4449 flags=ParseGeometry(option,&geometry_info);
4450 image->chromaticity.white_point.x=geometry_info.rho;
4451 image->chromaticity.white_point.y=geometry_info.sigma;
4452 if ((flags & SigmaValue) == 0)
4453 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4455 ResetImageOptionIterator(image_info);
4456 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4458 value=GetImageOption(image_info,option);
4459 if (value != (const char *) NULL)
4461 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4462 (void) SetImageArtifact(image,property,value);
4464 option=GetNextImageOption(image_info);